[ { "problem_id": "1901A", "problem_name": "Line Trip\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1901/A", "problem_solution_link": "https://codeforces.com/problemset/status/1901/problem/A", "problem_statement": "A. Line Trip\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a road, which can be represented as a number line. You are located in the point $$$0$$$ of the number line, and you want to travel from the point $$$0$$$ to the point $$$x$$$, and back to the point $$$0$$$.\nYou travel by car, which spends $$$1$$$ liter of gasoline per $$$1$$$ unit of distance travelled. When you start at the point $$$0$$$, your car is fully fueled (its gas tank contains the maximum possible amount of fuel).\nThere are $$$n$$$ gas stations, located in points $$$a_1, a_2, \\dots, a_n$$$. When you arrive at a gas station, you fully refuel your car.\nNote that you can refuel only at gas stations, and there are no gas stations in points $$$0$$$ and $$$x$$$\n.\nYou have to calculate the minimum possible volume of the gas tank in your car (in liters) that will allow you to travel from the point $$$0$$$ to the point $$$x$$$ and back to the point $$$0$$$.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases.\nEach test case consists of two lines:\nthe first line contains two integers $$$n$$$ and $$$x$$$ ($$$1 \\le n \\le 50$$$; $$$2 \\le x \\le 100$$$);\nthe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$0 < a_1 < a_2 < \\dots < a_n < x$$$).\nOutput\nFor each test case, print one integer \u2014 the minimum possible volume of the gas tank in your car that will allow you to travel from the point $$$0$$$ to the point $$$x$$$ and back.\nExample\nInput\n3\n3 7\n1 2 5\n3 6\n1 2 5\n1 10\n7\nOutput\n4\n3\n7\nNote\nIn the first test case of the example, if the car has a gas tank of $$$4$$$ liters, you can travel to $$$x$$$ and back as follows:\ntravel to the point $$$1$$$, then your car's gas tank contains $$$3$$$ liters of fuel;\nrefuel at the point $$$1$$$, then your car's gas tank contains $$$4$$$ liters of fuel;\ntravel to the point $$$2$$$, then your car's gas tank contains $$$3$$$ liters of fuel;\nrefuel at the point $$$2$$$, then your car's gas tank contains $$$4$$$ liters of fuel;\ntravel to the point $$$5$$$, then your car's gas tank contains $$$1$$$ liter of fuel;\nrefuel at the point $$$5$$$, then your car's gas tank contains $$$4$$$ liters of fuel;\ntravel to the point $$$7$$$, then your car's gas tank contains $$$2$$$ liters of fuel;\ntravel to the point $$$5$$$, then your car's gas tank contains $$$0$$$ liters of fuel;\nrefuel at the point $$$5$$$, then your car's gas tank contains $$$4$$$ liters of fuel;\ntravel to the point $$$2$$$, then your car's gas tank contains $$$1$$$ liter of fuel;\nrefuel at the point $$$2$$$, then your car's gas tank contains $$$4$$$ liters of fuel;\ntravel to the point $$$1$$$, then your car's gas tank contains $$$3$$$ liters of fuel;\nrefuel at the point $$$1$$$, then your car's gas tank contains $$$4$$$ liters of fuel;\ntravel to the point $$$0$$$, then your car's gas tank contains $$$3$$$ liters of fuel.", "input": [ [ [ "3", "7" ], [ "1", "2", "5" ] ], [ [ "3", "6" ], [ "1", "2", "5" ] ], [ [ "1", "10" ], [ "7" ] ] ], "output": [ "4", "3", "7" ] }, { "problem_id": "1899A", "problem_name": "Game with Integers\ngames, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1899/A", "problem_solution_link": "https://codeforces.com/problemset/status/1899/problem/A", "problem_statement": "A. Game with Integers\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nVanya and Vova are playing a game. Players are given an integer $$$n$$$. On their turn, the player can add $$$1$$$ to the current integer or subtract $$$1$$$. The players take turns; Vanya starts. If\nafter\nVanya's move the integer is divisible by $$$3$$$, then he wins. If $$$10$$$ moves have passed and Vanya has not won, then Vova wins.\nWrite a program that, based on the integer $$$n$$$, determines who will win if both players play optimally.\nInput\nThe first line contains the integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases.\nThe single line of each test case contains the integer $$$n$$$ ($$$1 \\leq n \\leq 1000$$$).\nOutput\nFor each test case, print \"\nFirst\n\" without quotes if Vanya wins, and \"\nSecond\n\" without quotes if Vova wins.\nExample\nInput\n6\n1\n3\n5\n100\n999\n1000\nOutput\nFirst\nSecond\nFirst\nFirst\nSecond\nFirst", "input": [ [ [ "1" ] ], [ [ "3" ] ], [ [ "5" ] ], [ [ "100" ] ], [ [ "999" ] ], [ [ "1000" ] ] ], "output": [ "First", "Second", "First", "First", "Second", "First" ] }, { "problem_id": "1898A", "problem_name": "Milica and String\nbrute force, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1898/A", "problem_solution_link": "https://codeforces.com/problemset/status/1898/problem/A", "problem_statement": "A. Milica and String\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMilica has a string $$$s$$$ of length $$$n$$$, consisting only of characters\nA\nand\nB\n. She wants to modify $$$s$$$ so it contains\nexactly\n$$$k$$$ instances of\nB\n. In one operation, she can do the following:\nSelect an integer $$$i$$$ ($$$1 \\leq i \\leq n$$$) and a character $$$c$$$ ($$$c$$$ is equal to either\nA\nor\nB\n).\nThen, replace\neach\nof the first $$$i$$$ characters of string $$$s$$$ (that is, characters $$$s_1, s_2, \\ldots, s_i$$$) with $$$c$$$.\nMilica does not want to perform too many operations in order not to waste too much time on them.\nShe asks you to find the minimum number of operations required to modify $$$s$$$ so it contains exactly $$$k$$$ instances of\nB\n. She also wants you to find these operations (that is, integer $$$i$$$ and character $$$c$$$ selected in each operation).\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\leq t \\leq 500$$$). The description of test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$3 \\leq n \\leq 100$$$, $$$0 \\leq k \\leq n$$$)\u00a0\u2014 the length of the string $$$s$$$ and the number of characters\nB\nMilica wants to appear in $$$s$$$ in the end.\nThe second line of each test case contains the string $$$s$$$ of length $$$n$$$, consisting only of characters\nA\nand\nB\n.\nOutput\nFor each test case, in the first line output a single integer $$$m$$$\u00a0\u2014 the minimum number of operations Milica should perform.\nIn the $$$j$$$-th of the next $$$m$$$ lines output an integer $$$i$$$ ($$$1 \\le i \\le n$$$) and a character $$$c$$$ ($$$c$$$ is '\nA\n' or '\nB\n')\u00a0\u2014 the parameters of the $$$j$$$-th operation as described in the statement.\nIf there are multiple solutions with the minimum possible number of operations, output any of them.\nExample\nInput\n5\n5 2\nAAABB\n5 3\nAABAB\n5 0\nBBBBB\n3 0\nBAA\n10 3\nBBBABBBBAB\nOutput\n0\n1\n1 B\n1\n5 A\n1\n2 A\n1\n6 A\nNote\nIn the first test case, there are already $$$2$$$ characters\nB\nin $$$s$$$, so Milica does not have to perform any operations.\nIn the second test case, the only way to achieve $$$3$$$ characters\nB\nin $$$s$$$ in one operation is to replace the first character of $$$s$$$ by\nB\non the first operation:\nAABAB\n$$$\\rightarrow$$$\nB\nABAB\n.\nIn the third test case, the only way to achieve $$$0$$$ characters\nB\nin $$$s$$$ in one operation is to replace the first $$$5$$$ characters of $$$s$$$ by\nA\non the first operation:\nBBBBB\n$$$\\rightarrow$$$\nAAAAA\n.\nIn the fourth test case, one of the ways to achieve $$$0$$$ characters\nB\nin $$$s$$$ in one operation is to replace the first $$$2$$$ characters of $$$s$$$ by\nA\non the first operation:\nBAA\n$$$\\rightarrow$$$\nAA\nA\n. Note that \"\n1 A\n\" and \"\n3 A\n\" are also correct one-operation solutions.", "input": [ [ [ "5", "2" ], [ "AAABB" ] ], [ [ "5", "3" ], [ "AABAB" ] ], [ [ "5", "0" ], [ "BBBBB" ] ], [ [ "3", "0" ], [ "BAA" ] ], [ [ "10", "3" ], [ "BBBABBBBAB" ] ] ], "output": [ ["0"], ["1", "1 B"], ["1", "5 A"], ["1", "2 A"], ["1", "6 A"] ], "error": true }, { "problem_id": "1895B", "problem_name": "Points and Minimum Distance\ngreedy, math, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1895/B", "problem_solution_link": "https://codeforces.com/problemset/status/1895/problem/B", "problem_statement": "B. Points and Minimum Distance\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a sequence of integers $$$a$$$ of length $$$2n$$$. You have to split these $$$2n$$$ integers into $$$n$$$ pairs; each pair will represent the coordinates of a point on a plane. Each number from the sequence $$$a$$$ should become the $$$x$$$ or $$$y$$$ coordinate of exactly one point. Note that some points can be equal.\nAfter the points are formed, you have to choose a path $$$s$$$ that starts from one of these points, ends at one of these points, and visits all $$$n$$$ points at least once.\nThe length of path $$$s$$$ is the sum of distances between all adjacent points on the path. In this problem, the distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is defined as $$$|x_1-x_2| + |y_1-y_2|$$$.\nYour task is to form $$$n$$$ points and choose a path $$$s$$$ in such a way that the length of path $$$s$$$ is minimized.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of testcases.\nThe first line of each testcase contains a single integer $$$n$$$ ($$$2 \\le n \\le 100$$$)\u00a0\u2014 the number of points to be formed.\nThe next line contains $$$2n$$$ integers $$$a_1, a_2, \\dots, a_{2n}$$$ ($$$0 \\le a_i \\le 1\\,000$$$)\u00a0\u2014 the description of the sequence $$$a$$$.\nOutput\nFor each testcase, print the minimum possible length of path $$$s$$$ in the first line.\nIn the $$$i$$$-th of the following $$$n$$$ lines, print two integers $$$x_i$$$ and $$$y_i$$$ \u2014 the coordinates of the point that needs to be visited at the $$$i$$$-th position.\nIf there are multiple answers, print any of them.\nExample\nInput\n2\n2\n15 1 10 5\n3\n10 30 20 20 30 10\nOutput\n9\n10 1\n15 5\n20\n20 20\n10 30\n10 30\nNote\nIn the first testcase, for instance, you can form points $$$(10, 1)$$$ and $$$(15, 5)$$$ and start the path $$$s$$$ from the first point and end it at the second point. Then the length of the path will be $$$|10 - 15| + |1 - 5| = 5 + 4 = 9$$$.\nIn the second testcase, you can form points $$$(20, 20)$$$, $$$(10, 30)$$$, and $$$(10, 30)$$$, and visit them in that exact order. Then the length of the path will be $$$|20 - 10| + |20 - 30| + |10 - 10| + |30 - 30| = 10 + 10 + 0 + 0 = 20$$$.", "input": [ [ [ "2" ], [ "15", "1", "10", "5" ] ], [ [ "3" ], [ "10", "30", "20", "20", "30", "10" ] ] ], "output": [ ["9", "10 1", "15 5"], ["20", "20 20", "10 30", "10 30"] ], "error": true }, { "problem_id": "1895A", "problem_name": "Treasure Chest\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1895/A", "problem_solution_link": "https://codeforces.com/problemset/status/1895/problem/A", "problem_statement": "A. Treasure Chest\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nMonocarp has found a treasure map. The map represents the treasure location as an OX axis. Monocarp is at $$$0$$$, the treasure chest is at $$$x$$$, the key to the chest is at $$$y$$$.\nObviously, Monocarp wants to open the chest. He can perform the following actions:\ngo $$$1$$$ to the left or $$$1$$$ to the right (spending $$$1$$$ second);\npick the key or the chest up if he is in the same point as that object (spending $$$0$$$ seconds);\nput the chest down in his current point (spending $$$0$$$ seconds);\nopen the chest if he's in the same point as the chest and has picked the key up (spending $$$0$$$ seconds).\nMonocarp can carry the chest, but the chest is pretty heavy. He knows that he can carry it for at most $$$k$$$ seconds in total (putting it down and picking it back up doesn't reset his stamina).\nWhat's the smallest time required for Monocarp to open the chest?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of testcases.\nThe only line of each testcase contains three integers $$$x, y$$$ and $$$k$$$ ($$$1 \\le x, y \\le 100$$$; $$$x \\neq y$$$; $$$0 \\le k \\le 100$$$)\u00a0\u2014 the initial point of the chest, the point where the key is located, and the maximum time Monocarp can carry the chest for.\nOutput\nFor each testcase, print a single integer\u00a0\u2014 the smallest time required for Monocarp to open the chest.\nExample\nInput\n3\n5 7 2\n10 5 0\n5 8 2\nOutput\n7\n10\n9\nNote\nIn the first testcase, Monocarp can open the chest in $$$7$$$ seconds with the following sequence of moves:\ngo $$$5$$$ times to the right ($$$5$$$ seconds);\npick up the chest ($$$0$$$ seconds);\ngo $$$2$$$ times to the right ($$$2$$$ seconds);\npick up the key ($$$0$$$ seconds);\nput the chest down ($$$0$$$ seconds);\nopen the chest ($$$0$$$ seconds).\nHe only carries the chest for $$$2$$$ seconds, which he has the stamina for.\nIn the second testcase, Monocarp can pick up the key on his way to the chest.\nIn the third testcase, Monocarp can't use the strategy from the first testcase because he would have to carry the chest for $$$3$$$ seconds, while he only has the stamina for $$$2$$$ seconds. Thus, he carries the chest to $$$7$$$, puts it down, moves $$$1$$$ to the right to pick up the key and returns $$$1$$$ left to open the chest.", "input": [ [ [ "5", "7", "2" ] ], [ [ "10", "5", "0" ] ], [ [ "5", "8", "2" ] ] ], "output": [ "7", "10", "9" ] }, { "problem_id": "1894A", "problem_name": "Secret Sport\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1894/A", "problem_solution_link": "https://codeforces.com/problemset/status/1894/problem/A", "problem_statement": "A. Secret Sport\ntime limit per test\n3 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's consider a game in which two players, A and B, participate. This game is characterized by two positive integers, $$$X$$$ and $$$Y$$$.\nThe game consists of\nsets\n, and each\nset\nconsists of\nplays\n. In each\nplay\n,\nexactly one\nof the players, either A or B, wins. A\nset\nends\nexactly\nwhen one of the players reaches $$$X$$$ wins in the\nplays\nof that\nset\n. This player is declared the winner of the\nset\n. The players play\nsets\nuntil one of them reaches $$$Y$$$ wins in the\nsets\n. After that, the game ends, and this player is declared the winner of the entire game.\nYou have just watched a game but didn't notice who was declared the winner. You remember that during the game, $$$n$$$\nplays\nwere played, and you know which player won each\nplay\n. However, you\ndo not know\nthe values of $$$X$$$ and $$$Y$$$. Based on the available information, determine who won the entire game\u00a0\u2014 A or B. If there is not enough information to determine the winner, you should also report it.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \\leq t \\leq 10^4)$$$ - the number of test cases. The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ $$$(1 \\leq n \\leq 20)$$$ - the number of\nplays\nplayed during the game.\nThe second line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of characters $$$\\texttt{A}$$$ and $$$\\texttt{B}$$$. If $$$s_i = \\texttt{A}$$$, it means that player A won the $$$i$$$-th\nplay\n. If $$$s_i = \\texttt{B}$$$, it means that player B won the $$$i$$$-th\nplay\n.\nIt is guaranteed that the given sequence of\nplays\ncorresponds to at least one valid game scenario, for some values of $$$X$$$ and $$$Y$$$\n.\nOutput\nFor each test case, output:\n$$$\\texttt{A}$$$\u00a0\u2014 if player A is guaranteed to be the winner of the game.\n$$$\\texttt{B}$$$\u00a0\u2014 if player B is guaranteed to be the winner of the game.\n$$$\\texttt{?}$$$\u00a0\u2014 if it is\nimpossible\nto determine the winner of the game.\nExample\nInput\n7\n5\nABBAA\n3\nBBB\n7\nBBAAABA\n20\nAAAAAAAABBBAABBBBBAB\n1\nA\n13\nAAAABABBABBAB\n7\nBBBAAAA\nOutput\nA\nB\nA\nB\nA\nB\nA\nNote\nIn the first test case, the game could have been played with parameters $$$X = 3$$$, $$$Y = 1$$$. The game consisted of $$$1$$$ set, in which player A won, as they won the first $$$3$$$ plays. In this scenario, player A is the winner. The game could also have been played with parameters $$$X = 1$$$, $$$Y = 3$$$. It can be shown that there are no such $$$X$$$ and $$$Y$$$ values for which player B would be the winner.\nIn the second test case, player B won all the plays. It can be easily shown that in this case, player B is guaranteed to be the winner of the game.\nIn the fourth test case, the game could have been played with parameters $$$X = 3$$$, $$$Y = 3$$$:\nIn the first set, $$$3$$$ plays were played:\nAAA\n. Player A is declared the winner of the set.\nIn the second set, $$$3$$$ plays were played:\nAAA\n. Player A is declared the winner of the set.\nIn the third set, $$$5$$$ plays were played:\nAABBB\n. Player B is declared the winner of the set.\nIn the fourth set, $$$5$$$ plays were played:\nAABBB\n. Player B is declared the winner of the set.\nIn the fifth set, $$$4$$$ plays were played:\nBBAB\n. Player B is declared the winner of the set.\nIn total, player B was the first player to win $$$3$$$ sets. They are declared the winner of the game.", "input": [ [ [ "5" ], [ "ABBAA" ] ], [ [ "3" ], [ "BBB" ] ], [ [ "7" ], [ "BBAAABA" ] ], [ [ "20" ], [ "AAAAAAAABBBAABBBBBAB" ] ], [ [ "1" ], [ "A" ] ], [ [ "13" ], [ "AAAABABBABBAB" ] ], [ [ "7" ], [ "BBBAAAA" ] ] ], "output": [ "A", "B", "A", "B", "A", "B", "A" ] }, { "problem_id": "1891A", "problem_name": "Sorting with Twos\nconstructive algorithms, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1891/A", "problem_solution_link": "https://codeforces.com/problemset/status/1891/problem/A", "problem_statement": "A. Sorting with Twos\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array of integers $$$a_1, a_2, \\ldots, a_n$$$. In one operation, you do the following:\nChoose a non-negative integer $$$m$$$, such that $$$2^m \\leq n$$$.\nSubtract $$$1$$$ from $$$a_i$$$ for all integers $$$i$$$, such that $$$1 \\leq i \\leq 2^m$$$.\nCan you sort the array in non-decreasing order by performing some number (possibly zero) of operations?\nAn array is considered non-decreasing if $$$a_i \\leq a_{i + 1}$$$ for all integers $$$i$$$ such that $$$1 \\leq i \\leq n - 1$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$) \u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 20$$$) \u2014 the length of array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ \u2014 the integers in array $$$a$$$ ($$$0 \\leq a_i \\leq 1000$$$).\nOutput\nFor each test case, output \"YES\" if the array can be sorted, and \"NO\" otherwise.\nExample\nInput\n8\n5\n1 2 3 4 5\n5\n6 5 3 4 4\n9\n6 5 5 7 5 6 6 8 7\n4\n4 3 2 1\n6\n2 2 4 5 3 2\n8\n1 3 17 19 27 57 179 13\n5\n3 17 57 179 92\n10\n1 2 3 4 0 6 7 8 9 10\nOutput\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNote\nIn the first test case, the array is already sorted in non-decreasing order, so we don't have to perform any operations.\nIn the second test case, we can choose $$$m = 1$$$ twice to get the array $$$[4, 3, 3, 4, 4]$$$. Then, we can choose $$$m = 0$$$ once and get the sorted in non-decreasing order array $$$[3, 3, 3, 4, 4]$$$.\nIn the third test case, we can choose $$$m = 0$$$ once and get the array $$$[5, 5, 5, 7, 5, 6, 6, 8, 7]$$$. Then, we can choose $$$m = 2$$$ twice and get the array $$$[3, 3, 3, 5, 5, 6, 6, 8, 7]$$$. After that, we can choose $$$m = 3$$$ once and get the sorted in non-decreasing order array $$$[2, 2, 2, 4, 4, 5, 5, 7, 7]$$$.\nFor the fourth and fifth test case, it can be shown that the array could not be sorted using these operations.", "input": [ [ [ "5" ], [ "1", "2", "3", "4", "5" ] ], [ [ "5" ], [ "6", "5", "3", "4", "4" ] ], [ [ "9" ], [ "6", "5", "5", "7", "5", "6", "6", "8", "7" ] ], [ [ "4" ], [ "4", "3", "2", "1" ] ], [ [ "6" ], [ "2", "2", "4", "5", "3", "2" ] ], [ [ "8" ], [ "1", "3", "17", "19", "27", "57", "179", "13" ] ], [ [ "5" ], [ "3", "17", "57", "179", "92" ] ], [ [ "10" ], [ "1", "2", "3", "4", "0", "6", "7", "8", "9", "10" ] ] ], "output": [ "YES", "YES", "YES", "NO", "NO", "NO", "YES", "YES" ] }, { "problem_id": "1890B", "problem_name": "Qingshan Loves Strings\nconstructive algorithms, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1890/B", "problem_solution_link": "https://codeforces.com/problemset/status/1890/problem/B", "problem_statement": "B. Qingshan Loves Strings\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nQingshan has a string $$$s$$$, while Daniel has a string $$$t$$$. Both strings only contain $$$\\texttt{0}$$$ and $$$\\texttt{1}$$$.\nA string $$$a$$$ of length $$$k$$$ is good if and only if\n$$$a_i \\ne a_{i+1}$$$ for all $$$i=1,2,\\ldots,k-1$$$.\nFor example, $$$\\texttt{1}$$$, $$$\\texttt{101}$$$, $$$\\texttt{0101}$$$ are good, while $$$\\texttt{11}$$$, $$$\\texttt{1001}$$$, $$$\\texttt{001100}$$$ are not good.\nQingshan wants to make $$$s$$$ good. To do this, she can do the following operation any number of times (possibly, zero):\ninsert $$$t$$$ to any position of $$$s$$$ (getting a new $$$s$$$).\nPlease tell Qingshan if it is possible to make $$$s$$$ good.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$T$$$ ($$$1\\le T\\le 2000$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n,m \\le 50$$$)\u00a0\u2014 the length of the strings $$$s$$$ and $$$t$$$, respectively.\nThe second line of each test case contains a string $$$s$$$ of length $$$n$$$.\nThe third line of each test case contains a string $$$t$$$ of length $$$m$$$.\nIt is guaranteed that $$$s$$$ and $$$t$$$ only contain $$$\\texttt{0}$$$ and $$$\\texttt{1}$$$.\nOutput\nFor each test case, print \"\nYES\n\" (without quotes), if it is possible to make $$$s$$$ good, and \"\nNO\n\" (without quotes) otherwise.\nYou can print letters in any case (upper or lower).\nExample\nInput\n5\n1 1\n1\n0\n3 3\n111\n010\n3 2\n111\n00\n6 7\n101100\n1010101\n10 2\n1001001000\n10\nOutput\nYes\nYes\nNo\nNo\nNo\nNote\nIn the first test case, $$$s$$$ is good initially, so you can get a good $$$s$$$ by doing zero operations.\nIn the second test case, you can do the following two operations (the inserted string $$$t$$$ is underlined):\n$$$\\texttt{1}\\underline{\\texttt{010}}\\texttt{11}$$$\n$$$\\texttt{10101}\\underline{\\texttt{010}}\\texttt{1}$$$\nand get $$$s = \\texttt{101010101}$$$, which is good.\nIn the third test case, there is no way to make $$$s$$$ good after any number of operations.", "input": [ [ [ "1", "1" ], [ "1" ], [ "0" ] ], [ [ "3", "3" ], [ "111" ], [ "010" ] ], [ [ "3", "2" ], [ "111" ], [ "00" ] ], [ [ "6", "7" ], [ "101100" ], [ "1010101" ] ], [ [ "10", "2" ], [ "1001001000" ], [ "10" ] ] ], "output": [ "Yes", "Yes", "No", "No", "No" ] }, { "problem_id": "1890A", "problem_name": "Doremy's Paint 3\nconstructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1890/A", "problem_solution_link": "https://codeforces.com/problemset/status/1890/problem/A", "problem_statement": "A. Doremy's Paint 3\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAn array $$$b_1, b_2, \\ldots, b_n$$$ of positive integers is good if all the sums of two adjacent elements are equal to the same value. More formally, the array is good if there exists a $$$k$$$ such that $$$b_1 + b_2 = b_2 + b_3 = \\ldots = b_{n-1} + b_n = k$$$.\nDoremy has an array $$$a$$$ of length $$$n$$$. Now Doremy can permute its elements (change their order) however she wants. Determine if she can make the array good.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\\le t\\le 100$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 100$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe second line of each test case contains $$$ n $$$ integers $$$ a_1,a_2,\\ldots,a_n $$$ ($$$1 \\le a_i \\le 10^5$$$).\nThere are no constraints on the sum of $$$n$$$ over all test cases.\nOutput\nFor each test case, print \"\nYes\n\" (without quotes), if it is possible to make the array good, and \"\nNo\n\" (without quotes) otherwise.\nYou can output the answer in any case (upper or lower). For example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\", and \"\nYES\n\" will be recognized as positive responses.\nExample\nInput\n5\n2\n8 9\n3\n1 1 2\n4\n1 1 4 5\n5\n2 3 3 3 3\n4\n100000 100000 100000 100000\nOutput\nYes\nYes\nNo\nNo\nYes\nNote\nIn the first test case, $$$[8,9]$$$ and $$$[9,8]$$$ are good.\nIn the second test case, $$$[1,2,1]$$$ is good because $$$a_1+a_2=a_2+a_3=3$$$.\nIn the third test case, it can be shown that no permutation is good.", "input": [ [ [ "2" ], [ "8", "9" ] ], [ [ "3" ], [ "1", "1", "2" ] ], [ [ "4" ], [ "1", "1", "4", "5" ] ], [ [ "5" ], [ "2", "3", "3", "3", "3" ] ], [ [ "4" ], [ "100000", "100000", "100000", "100000" ] ] ], "output": [ "Yes", "Yes", "No", "No", "Yes" ] }, { "problem_id": "1886A", "problem_name": "Sum of Three\nbrute force, constructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1886/A", "problem_solution_link": "https://codeforces.com/problemset/status/1886/problem/A", "problem_statement": "A. Sum of Three\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMonocarp has an integer $$$n$$$.\nHe wants to represent his number as a sum of three\ndistinct\npositive integers $$$x$$$, $$$y$$$, and $$$z$$$. Additionally, Monocarp wants none of the numbers $$$x$$$, $$$y$$$, and $$$z$$$ to be divisible by $$$3$$$.\nYour task is to help Monocarp to find any valid triplet of distinct positive integers $$$x$$$, $$$y$$$, and $$$z$$$, or report that such a triplet does not exist.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of testcases.\nThe only line of each testcase contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^{9}$$$).\nOutput\nFor each testcase, if there is no valid triplet $$$x$$$, $$$y$$$, and $$$z$$$, print\nNO\non the first line.\nOtherwise, print\nYES\non the first line. On the second line, print any valid triplet of distinct positive integers $$$x$$$, $$$y$$$, and $$$z$$$ such that $$$x + y + z = n$$$, and none of the printed numbers are divisible by $$$3$$$. If there are multiple valid triplets, you can print any of them.\nExample\nInput\n4\n10\n4\n15\n9\nOutput\nYES\n4 5 1\nNO\nYES\n2 8 5\nNO\nNote\nIn the first testcase, one of the valid triplets is $$$x = 4$$$, $$$y = 5$$$, $$$z = 1$$$. None of these numbers are divisible by three, and $$$4 + 5 + 1 = 10$$$.\nIn the second testcase, there is no valid triplet.\nIn the third testcase, one of the valid triplets is $$$x = 2$$$, $$$y = 8$$$, $$$z = 5$$$. None of these numbers are divisible by three, and $$$2 + 8 + 5 = 15$$$.\nIn the fourth testcase, there is no valid triplet.", "input": [ [ [ "10" ] ], [ [ "4" ] ], [ [ "15" ] ], [ [ "9" ] ] ], "output": [ ["YES", "4 5 1"], ["NO"], ["YES", "2 8 5"], ["NO"] ], "error": true }, { "problem_id": "1884A", "problem_name": "Simple Design\nbrute force, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1884/A", "problem_solution_link": "https://codeforces.com/problemset/status/1884/problem/A", "problem_statement": "A. Simple Design\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA positive integer is called $$$k$$$-beautiful, if the digit sum of the decimal representation of this number is divisible by $$$k^{\\dagger}$$$. For example, $$$9272$$$ is $$$5$$$-beautiful, since the digit sum of $$$9272$$$ is $$$9 + 2 + 7 + 2 = 20$$$.\nYou are given two integers $$$x$$$ and $$$k$$$. Please find the smallest integer $$$y \\ge x$$$ which is $$$k$$$-beautiful.\n$$$^{\\dagger}$$$ An integer $$$n$$$ is divisible by $$$k$$$ if there exists an integer $$$m$$$ such that $$$n = k \\cdot m$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^4$$$). The description of the test cases follows.\nThe only line of each test case contains two integers $$$x$$$ and $$$k$$$ ($$$1 \\le x \\le 10^9$$$, $$$1 \\le k \\le 10$$$).\nOutput\nFor each test case, output the smallest integer $$$y \\ge x$$$ which is $$$k$$$-beautiful.\nExample\nInput\n6\n1 5\n10 8\n37 9\n777 3\n1235 10\n1 10\nOutput\n5\n17\n45\n777\n1243\n19\nNote\nIn the first test case, numbers from $$$1$$$ to $$$4$$$ consist of a single digit, thus the digit sum is equal to the number itself. None of the integers from $$$1$$$ to $$$4$$$ are divisible by $$$5$$$.\nIn the fourth test case, the digit sum of $$$777$$$ is $$$7 + 7 + 7 = 21$$$ which is already divisible by $$$3$$$.", "input": [ [ [ "1", "5" ] ], [ [ "10", "8" ] ], [ [ "37", "9" ] ], [ [ "777", "3" ] ], [ [ "1235", "10" ] ], [ [ "1", "10" ] ] ], "output": [ "5", "17", "45", "777", "1243", "19" ] }, { "problem_id": "1883A", "problem_name": "Morning\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1883/A", "problem_solution_link": "https://codeforces.com/problemset/status/1883/problem/A", "problem_statement": "A. Morning\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a four-digit pin code consisting of digits from $$$0$$$ to $$$9$$$ that needs to be entered. Initially, the cursor points to the digit $$$1$$$. In one second, you can perform exactly one of the following two actions:\nPress the cursor to display the current digit,\nMove the cursor to any adjacent digit.\nThe image above shows the device you are using to enter the pin code. For example, for the digit $$$5$$$, the adjacent digits are $$$4$$$ and $$$6$$$, and for the digit $$$0$$$, there is only one adjacent digit, $$$9$$$.\nDetermine the minimum number of seconds required to enter the given four-digit pin code.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$) - the number of the test cases. This is followed by their description.\nThe single line of each test case describes the pin code as a string of length $$$4$$$, consisting of digits from $$$0$$$ to $$$9$$$.\nOutput\nFor each test case, output the minimum number of seconds required to enter the given pin code.\nExample\nInput\n10\n1111\n1236\n1010\n1920\n9273\n0000\n7492\n8543\n0294\n8361\nOutput\n4\n9\n31\n27\n28\n13\n25\n16\n33\n24\nNote\nIn the first test case, the cursor needs to be pressed $$$4$$$ times.\nIn the second test case, it can be done in $$$9$$$ seconds as follows:\nPress the cursor.\nMove the cursor to the digit $$$2$$$.\nPress the cursor.\nMove the cursor to the digit $$$3$$$.\nPress the cursor.\nMove the cursor to the digit $$$4$$$.\nMove the cursor to the digit $$$5$$$.\nMove the cursor to the digit $$$6$$$.\nPress the cursor.", "input": [ [ [ "1111" ] ], [ [ "1236" ] ], [ [ "1010" ] ], [ [ "1920" ] ], [ [ "9273" ] ], [ [ "0000" ] ], [ [ "7492" ] ], [ [ "8543" ] ], [ [ "0294" ] ], [ [ "8361" ] ] ], "output": [ "4", "9", "31", "27", "28", "13", "25", "16", "33", "24" ] }, { "problem_id": "1882A", "problem_name": "Increasing Sequence\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1882/A", "problem_solution_link": "https://codeforces.com/problemset/status/1882/problem/A", "problem_statement": "A. Increasing Sequence\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a sequence $$$a_{1}, a_{2}, \\ldots, a_{n}$$$. A sequence $$$b_{1}, b_{2}, \\ldots, b_{n}$$$ is called\ngood\n, if it satisfies all of the following conditions:\n$$$b_{i}$$$ is a positive integer for $$$i = 1, 2, \\ldots, n$$$;\n$$$b_{i} \\neq a_{i}$$$ for $$$i = 1, 2, \\ldots, n$$$;\n$$$b_{1} < b_{2} < \\ldots < b_{n}$$$.\nFind the minimum value of $$$b_{n}$$$ among all good sequences $$$b_{1}, b_{2}, \\ldots, b_{n}$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$).\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 10^{9}$$$).\nOutput\nFor each test case, print a single integer\u00a0\u2014 the minimum value of $$$b_{n}$$$ among all good sequences $$$b$$$.\nExample\nInput\n3\n5\n1 3 2 6 7\n4\n2 3 4 5\n1\n1\nOutput\n8\n4\n2\nNote\nIn the first test case, $$$b = [2, 4, 5, 7, 8]$$$ is a good sequence. It can be proved that there is no good $$$b$$$ with $$$b_{5} < 8$$$.\nIn the second test case, $$$b = [1, 2, 3, 4]$$$ is an optimal good sequence.\nIn the third test case, $$$b = [2]$$$ is an optimal good sequence.", "input": [ [ [ "5" ], [ "1", "3", "2", "6", "7" ] ], [ [ "4" ], [ "2", "3", "4", "5" ] ], [ [ "1" ], [ "1" ] ] ], "output": [ "8", "4", "2" ] }, { "problem_id": "1881A", "problem_name": "Don't Try to Count\nbrute force, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1881/A", "problem_solution_link": "https://codeforces.com/problemset/status/1881/problem/A", "problem_statement": "A. Don't Try to Count\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven a string $$$x$$$ of length $$$n$$$ and a string $$$s$$$ of length $$$m$$$ ($$$n \\cdot m \\le 25$$$), consisting of lowercase Latin letters, you can apply any number of operations to the string $$$x$$$.\nIn one operation, you append the current value of $$$x$$$ to the end of the string $$$x$$$. Note that the value of $$$x$$$ will change after this.\nFor example, if $$$x =$$$\"\naba\n\", then after applying operations, $$$x$$$ will change as follows: \"\naba\n\" $$$\\rightarrow$$$ \"\nabaaba\n\" $$$\\rightarrow$$$ \"\nabaabaabaaba\n\".\nAfter what\nminimum\nnumber of operations $$$s$$$ will appear in $$$x$$$ as a substring? A substring of a string is defined as a\ncontiguous\nsegment of it.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains two numbers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\cdot m \\le 25$$$)\u00a0\u2014 the lengths of strings $$$x$$$ and $$$s$$$, respectively.\nThe second line of each test case contains the string $$$x$$$ of length $$$n$$$.\nThe third line of each test case contains the string $$$s$$$ of length $$$m$$$.\nOutput\nFor each test case, output a single number\u00a0\u2014 the\nminimum\nnumber of operations after which $$$s$$$ will appear in $$$x$$$ as a substring. If this is not possible, output $$$-1$$$.\nExample\nInput\n12\n1 5\na\naaaaa\n5 5\neforc\nforce\n2 5\nab\nababa\n3 5\naba\nababa\n4 3\nbabb\nbbb\n5 1\naaaaa\na\n4 2\naabb\nba\n2 8\nbk\nkbkbkbkb\n12 2\nfjdgmujlcont\ntf\n2 2\naa\naa\n3 5\nabb\nbabba\n1 19\nm\nmmmmmmmmmmmmmmmmmmm\nOutput\n3\n1\n2\n-1\n1\n0\n1\n3\n1\n0\n2\n5\nNote\nIn the first test case of the example, after $$$2$$$ operations, the string will become \"\naaaa\n\", and after $$$3$$$ operations, it will become \"\naaaaaaaa\n\", so the answer is $$$3$$$.\nIn the second test case of the example, after applying $$$1$$$ operation, the string will become \"$$$\\text{e}\\color{red}{\\text{force}}\\text{forc}$$$\", where the substring is highlighted in red.\nIn the fourth test case of the example, it can be shown that it is impossible to obtain the desired string as a substring.", "input": [ [ [ "1", "5" ], [ "a" ], [ "aaaaa" ] ], [ [ "5", "5" ], [ "eforc" ], [ "force" ] ], [ [ "2", "5" ], [ "ab" ], [ "ababa" ] ], [ [ "3", "5" ], [ "aba" ], [ "ababa" ] ], [ [ "4", "3" ], [ "babb" ], [ "bbb" ] ], [ [ "5", "1" ], [ "aaaaa" ], [ "a" ] ], [ [ "4", "2" ], [ "aabb" ], [ "ba" ] ], [ [ "2", "8" ], [ "bk" ], [ "kbkbkbkb" ] ], [ [ "12", "2" ], [ "fjdgmujlcont" ], [ "tf" ] ], [ [ "2", "2" ], [ "aa" ], [ "aa" ] ], [ [ "3", "5" ], [ "abb" ], [ "babba" ] ], [ [ "1", "19" ], [ "m" ], [ "mmmmmmmmmmmmmmmmmmm" ] ] ], "output": [ "3", "1", "2", "-1", "1", "0", "1", "3", "1", "0", "2", "5" ] }, { "problem_id": "1879A", "problem_name": "Rigged!\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1879/A", "problem_solution_link": "https://codeforces.com/problemset/status/1879/problem/A", "problem_statement": "A. Rigged!\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMonocarp organizes a weightlifting competition. There are $$$n$$$ athletes participating in the competition, the $$$i$$$-th athlete has strength $$$s_i$$$ and endurance $$$e_i$$$. The $$$1$$$-st athlete is Monocarp's friend Polycarp, and Monocarp really wants Polycarp to win.\nThe competition will be conducted as follows. The jury will choose a positive\n(greater than zero)\ninteger $$$w$$$, which denotes the weight of the barbell that will be used in the competition. The goal for each athlete is to lift the barbell as many times as possible. The athlete who lifts the barbell the most amount of times will be declared the winner\n(if there are multiple such athletes \u2014 there's no winner)\n.\nIf the barbell's weight $$$w$$$ is\nstrictly greater\nthan the strength of the $$$i$$$-th athlete $$$s_i$$$, then the $$$i$$$-th athlete will be unable to lift the barbell even one single time. Otherwise, the $$$i$$$-th athlete will be able to lift the barbell, and the number of times he does it will be equal to his endurance $$$e_i$$$.\nFor example, suppose there are $$$4$$$ athletes with parameters $$$s_1 = 7, e_1 = 4$$$; $$$s_2 = 9, e_2 = 3$$$; $$$s_3 = 4, e_3 = 6$$$; $$$s_4 = 2, e_4 = 2$$$. If the weight of the barbell is $$$5$$$, then:\nthe first athlete will be able to lift the barbell $$$4$$$ times;\nthe second athlete will be able to lift the barbell $$$3$$$ times;\nthe third athlete will be unable to lift the barbell;\nthe fourth athlete will be unable to lift the barbell.\nMonocarp wants to choose $$$w$$$ in such a way that Polycarp (the $$$1$$$-st athlete) wins the competition. Help him to choose the value of $$$w$$$, or report that it is impossible.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases.\nThe first line of each test case contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the number of athletes. Then $$$n$$$ lines follow, the $$$i$$$-th of them contains two integers $$$s_i$$$ and $$$e_i$$$ ($$$1 \\le s_i \\le 10^9$$$; $$$1 \\le e_i \\le 100$$$) \u2014 the strength and the endurance of the $$$i$$$-th athlete.\nOutput\nFor each test case, print the answer as follows:\nif the answer exists, print one integer \u2014 the value of $$$w$$$ meeting the constraints. The integer you print should satisfy $$$1 \\le w \\le 10^9$$$. It can be shown that if the answer exists, at least one such value of $$$w$$$ exists as well. If there are multiple answers, you can print any of them;\notherwise, print one integer $$$-1$$$.\nExample\nInput\n3\n4\n7 4\n9 3\n4 6\n2 2\n2\n4 6\n100 100\n2\n1337 3\n1337 3\nOutput\n5\n-1\n-1\nNote\nThe first test case of the example is described in the statement.", "input": [ [ [ "4" ], [ "7", "4", "9", "3", "4", "6", "2", "2" ] ], [ [ "2" ], [ "4", "6", "100", "100" ] ], [ [ "2" ], [ "1337", "3", "1337", "3" ] ] ], "output": [ "5", "-1", "-1" ] }, { "problem_id": "1878B", "problem_name": "Aleksa and Stack\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1878/B", "problem_solution_link": "https://codeforces.com/problemset/status/1878/problem/B", "problem_statement": "B. Aleksa and Stack\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAfter the Serbian Informatics Olympiad, Aleksa was very sad, because he didn't win a medal (he didn't know stack), so Vasilije came to give him an easy problem, just to make his day better.\nVasilije gave Aleksa a positive integer $$$n$$$ ($$$n \\ge 3$$$) and asked him to construct a strictly increasing array of size $$$n$$$ of positive integers, such that\n$$$3\\cdot a_{i+2}$$$ is not divisible by $$$a_i+a_{i+1}$$$ for each $$$i$$$ ($$$1\\le i \\le n-2$$$).\nNote that a strictly increasing array $$$a$$$ of size $$$n$$$ is an array where $$$a_i < a_{i+1}$$$ for each $$$i$$$ ($$$1 \\le i \\le n-1$$$).\nSince Aleksa thinks he is a bad programmer now, he asked you to help him find such an array.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. The description of test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$3 \\le n \\le 2 \\cdot 10^5$$$)\u00a0\u2014 the number of elements in array.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, output $$$n$$$ integers $$$a_1, a_2, a_3, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$).\nIt can be proved that the solution exists for any $$$n$$$. If there are multiple solutions, output any of them.\nExample\nInput\n3\n3\n6\n7\nOutput\n6 8 12\n7 11 14 20 22 100\n9 15 18 27 36 90 120\nNote\nIn the first test case, $$$a_1=6$$$, $$$a_2=8$$$, $$$a_3=12$$$, so $$$a_1+a_2=14$$$ and $$$3 \\cdot a_3=36$$$, so $$$3 \\cdot a_3$$$ is not divisible by $$$a_1+a_2$$$.", "input": [ [ [ "3" ] ], [ [ "6" ] ], [ [ "7" ] ] ], "output": [ "6 8 12", "7 11 14 20 22 100", "9 15 18 27 36 90 120" ] }, { "problem_id": "1878A", "problem_name": "How Much Does Daytona Cost?\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1878/A", "problem_solution_link": "https://codeforces.com/problemset/status/1878/problem/A", "problem_statement": "A. How Much Does Daytona Cost?\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nWe define an integer to be\nthe most common\non a subsegment, if its number of occurrences on that subsegment is larger than the number of occurrences of any other integer in that subsegment. A subsegment of an array is a consecutive segment of elements in the array $$$a$$$.\nGiven an array $$$a$$$ of size $$$n$$$, and an integer $$$k$$$, determine if there exists a non-empty subsegment of $$$a$$$ where $$$k$$$ is\nthe most common element\n.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases. The description of test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 100$$$, $$$1 \\le k \\le 100$$$)\u00a0\u2014 the number of elements in array and the element which must be\nthe most common\n.\nThe second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$a_3$$$, $$$\\dots$$$, $$$a_n$$$ ($$$1 \\le a_i \\le 100$$$)\u00a0\u2014 elements of the array.\nOutput\nFor each test case output \"\nYES\n\" if there exists a subsegment in which $$$k$$$ is\nthe most common\nelement, and \"\nNO\n\" otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\", and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n7\n5 4\n1 4 3 4 1\n4 1\n2 3 4 4\n5 6\n43 5 60 4 2\n2 5\n1 5\n4 1\n5 3 3 1\n1 3\n3\n5 3\n3 4 1 5 5\nOutput\nYES\nNO\nNO\nYES\nYES\nYES\nYES\nNote\nIn the first test case we need to check if there is a subsegment where the\nmost common element\nis $$$4$$$.\nOn the subsegment $$$[2,5]$$$ the elements are $$$4, \\ 3, \\ 4, \\ 1$$$.\n$$$4$$$ appears $$$2$$$ times;\n$$$1$$$ appears $$$1$$$ time;\n$$$3$$$ appears $$$1$$$ time.\nThis means that $$$4$$$ is the\nmost common element\non the subsegment $$$[2, 5]$$$, so there exists a subsegment where $$$4$$$ is the\nmost common element\n.", "input": [ [ [ "5", "4" ], [ "1", "4", "3", "4", "1" ] ], [ [ "4", "1" ], [ "2", "3", "4", "4" ] ], [ [ "5", "6" ], [ "43", "5", "60", "4", "2" ] ], [ [ "2", "5" ], [ "1", "5" ] ], [ [ "4", "1" ], [ "5", "3", "3", "1" ] ], [ [ "1", "3" ], [ "3" ] ], [ [ "5", "3" ], [ "3", "4", "1", "5", "5" ] ] ], "output": [ "YES", "NO", "NO", "YES", "YES", "YES", "YES" ] }, { "problem_id": "1877A", "problem_name": "Goals of Victory\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1877/A", "problem_solution_link": "https://codeforces.com/problemset/status/1877/problem/A", "problem_statement": "A. Goals of Victory\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ teams in a football tournament. Each pair of teams match up once. After every match, Pak Chanek receives two integers as the result of the match, the number of goals the two teams score during the match. The efficiency of a team is equal to the total number of goals the team scores in each of its matches minus the total number of goals scored by the opponent in each of its matches.\nAfter the tournament ends, Pak Dengklek counts the efficiency of every team. Turns out that he forgot about the efficiency of one of the teams. Given the efficiency of $$$n-1$$$ teams $$$a_1,a_2,a_3,\\ldots,a_{n-1}$$$. What is the efficiency of the missing team? It can be shown that the efficiency of the missing team can be uniquely determined.\nInput\nEach test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 500$$$) \u2014 the number of test cases. The following lines contain the description of each test case.\nThe first line contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$) \u2014 the number of teams.\nThe second line contains $$$n-1$$$ integers $$$a_1,a_2,a_3,\\ldots,a_{n-1}$$$ ($$$-100\\leq a_i\\leq100$$$) \u2014 the efficiency of $$$n-1$$$ teams.\nOutput\nFor each test case, output a line containing an integer representing the efficiency of the missing team.\nExample\nInput\n2\n4\n3 -4 5\n11\n-30 12 -57 7 0 -81 -68 41 -89 0\nOutput\n-4\n265\nNote\nIn the first test case, below is a possible tournament result:\nTeam $$$1$$$ vs. Team $$$2$$$: $$$1-2$$$\nTeam $$$1$$$ vs. Team $$$3$$$: $$$3-0$$$\nTeam $$$1$$$ vs. Team $$$4$$$: $$$3-2$$$\nTeam $$$2$$$ vs. Team $$$3$$$: $$$1-4$$$\nTeam $$$2$$$ vs. Team $$$4$$$: $$$1-3$$$\nTeam $$$3$$$ vs. Team $$$4$$$: $$$5-0$$$\nThe efficiency of each team is:\nTeam $$$1$$$: $$$(1+3+3)-(2+0+2)=7-4=3$$$\nTeam $$$2$$$: $$$(2+1+1)-(1+4+3)=4-8=-4$$$\nTeam $$$3$$$: $$$(0+4+5)-(3+1+0)=9-4=5$$$\nTeam $$$4$$$: $$$(2+3+0)-(3+1+5)=5-9=-4$$$\nTherefore, the efficiency of the missing team (team $$$4$$$) is $$$-4$$$.\nIt can be shown that any possible tournament of $$$4$$$ teams that has the efficiency of $$$3$$$ teams be $$$3$$$, $$$-4$$$, and $$$5$$$ will always have the efficiency of the $$$4$$$-th team be $$$-4$$$.", "input": [ [ [ "4" ], [ "3", "-4", "5" ] ], [ [ "11" ], [ "-30", "12", "-57", "7", "0", "-81", "-68", "41", "-89", "0" ] ] ], "output": [ "-4", "265" ] }, { "problem_id": "1873D", "problem_name": "1D Eraser\ngreedy, implementation, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1873/D", "problem_solution_link": "https://codeforces.com/problemset/status/1873/problem/D", "problem_statement": "D. 1D Eraser\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a strip of paper $$$s$$$ that is $$$n$$$ cells long. Each cell is either black or white. In an operation you can take any $$$k$$$ consecutive cells and make them all white.\nFind the minimum number of operations needed to remove all black cells.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\leq k \\leq n \\leq 2 \\cdot 10^5$$$)\u00a0\u2014 the length of the paper and the integer used in the operation.\nThe second line of each test case contains a string $$$s$$$ of length $$$n$$$ consisting of characters $$$\\texttt{B}$$$ (representing a black cell) or $$$\\texttt{W}$$$ (representing a white cell).\nThe sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the minimum number of operations needed to remove all black cells.\nExample\nInput\n8\n6 3\nWBWWWB\n7 3\nWWBWBWW\n5 4\nBWBWB\n5 5\nBBBBB\n8 2\nBWBWBBBB\n10 2\nWBBWBBWBBW\n4 1\nBBBB\n3 2\nWWW\nOutput\n2\n1\n2\n1\n4\n3\n4\n0\nNote\nIn the first test case you can perform the following operations: $$$$$$\\color{red}{\\texttt{WBW}}\\texttt{WWB} \\to \\texttt{WWW}\\color{red}{\\texttt{WWB}} \\to \\texttt{WWWWWW}$$$$$$\nIn the second test case you can perform the following operations: $$$$$$\\texttt{WW}\\color{red}{\\texttt{BWB}}\\texttt{WW} \\to \\texttt{WWWWWWW}$$$$$$\nIn the third test case you can perform the following operations: $$$$$$\\texttt{B}\\color{red}{\\texttt{WBWB}} \\to \\color{red}{\\texttt{BWWW}}\\texttt{W} \\to \\texttt{WWWWW}$$$$$$", "input": [ [ [ "6", "3" ], [ "WBWWWB" ] ], [ [ "7", "3" ], [ "WWBWBWW" ] ], [ [ "5", "4" ], [ "BWBWB" ] ], [ [ "5", "5" ], [ "BBBBB" ] ], [ [ "8", "2" ], [ "BWBWBBBB" ] ], [ [ "10", "2" ], [ "WBBWBBWBBW" ] ], [ [ "4", "1" ], [ "BBBB" ] ], [ [ "3", "2" ], [ "WWW" ] ] ], "output": [ "2", "1", "2", "1", "4", "3", "4", "0" ] }, { "problem_id": "1873C", "problem_name": "Target Practice\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1873/C", "problem_solution_link": "https://codeforces.com/problemset/status/1873/problem/C", "problem_statement": "C. Target Practice\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA $$$10 \\times 10$$$ target is made out of five \"rings\" as shown. Each ring has a different point value: the outermost ring\u00a0\u2014 1 point, the next ring\u00a0\u2014 2 points, ..., the center ring\u00a0\u2014 5 points.\nVlad fired several arrows at the target. Help him determine how many points he got.\nInput\nThe input consists of multiple test cases. The first line of the input contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of 10 lines, each containing 10 characters. Each character in the grid is either $$$\\texttt{X}$$$ (representing an arrow) or $$$\\texttt{.}$$$ (representing no arrow).\nOutput\nFor each test case, output a single integer\u00a0\u2014 the total number of points of the arrows.\nExample\nInput\n4\nX.........\n..........\n.......X..\n.....X....\n......X...\n..........\n.........X\n..X.......\n..........\n.........X\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n....X.....\n..........\n..........\n..........\n..........\n..........\nXXXXXXXXXX\nXXXXXXXXXX\nXXXXXXXXXX\nXXXXXXXXXX\nXXXXXXXXXX\nXXXXXXXXXX\nXXXXXXXXXX\nXXXXXXXXXX\nXXXXXXXXXX\nXXXXXXXXXX\nOutput\n17\n0\n5\n220\nNote\nIn the first test case, there are three arrows on the outer ring worth 1 point each, two arrows on the ring worth 3 points each, and two arrows on the ring worth 4 points each. The total score is $$$3 \\times 1 + 2 \\times 3 + 2 \\times 4 = 17$$$.\nIn the second test case, there aren't any arrows, so the score is $$$0$$$.", "input": [ [ [ "X........." ], [ ".........." ], [ ".......X.." ], [ ".....X...." ], [ "......X..." ], [ ".........." ], [ ".........X" ], [ "..X......." ], [ ".........." ], [ ".........X" ] ], [ [ ".........." ], [ ".........." ], [ ".........." ], [ ".........." ], [ ".........." ], [ ".........." ], [ ".........." ], [ ".........." ], [ ".........." ], [ ".........." ] ], [ [ ".........." ], [ ".........." ], [ ".........." ], [ ".........." ], [ "....X....." ], [ ".........." ], [ ".........." ], [ ".........." ], [ ".........." ], [ ".........." ] ], [ [ "XXXXXXXXXX" ], [ "XXXXXXXXXX" ], [ "XXXXXXXXXX" ], [ "XXXXXXXXXX" ], [ "XXXXXXXXXX" ], [ "XXXXXXXXXX" ], [ "XXXXXXXXXX" ], [ "XXXXXXXXXX" ], [ "XXXXXXXXXX" ], [ "XXXXXXXXXX" ] ] ], "output": [ "17", "0", "5", "220" ] }, { "problem_id": "1873B", "problem_name": "Good Kid\nbrute force, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1873/B", "problem_solution_link": "https://codeforces.com/problemset/status/1873/problem/B", "problem_statement": "B. Good Kid\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nSlavic is preparing a present for a friend's birthday. He has an array $$$a$$$ of $$$n$$$ digits and the present will be the product of all these digits. Because Slavic is a good kid who wants to make the biggest product possible, he wants to add $$$1$$$ to exactly one of his digits.\nWhat is the maximum product Slavic can make?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 9$$$)\u00a0\u2014 the number of digits.\nThe second line of each test case contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$0 \\leq a_i \\leq 9$$$)\u00a0\u2014 the digits in the array.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the maximum product Slavic can make, by adding $$$1$$$ to exactly one of his digits.\nExample\nInput\n4\n4\n2 2 1 2\n3\n0 1 2\n5\n4 3 2 3 4\n9\n9 9 9 9 9 9 9 9 9\nOutput\n16\n2\n432\n430467210", "input": [ [ [ "4" ], [ "2", "2", "1", "2" ] ], [ [ "3" ], [ "0", "1", "2" ] ], [ [ "5" ], [ "4", "3", "2", "3", "4" ] ], [ [ "9" ], [ "9", "9", "9", "9", "9", "9", "9", "9", "9" ] ] ], "output": [ "16", "2", "432", "430467210" ] }, { "problem_id": "1873A", "problem_name": "Short Sort\nbrute force, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1873/A", "problem_solution_link": "https://codeforces.com/problemset/status/1873/problem/A", "problem_statement": "A. Short Sort\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are three cards with letters $$$\\texttt{a}$$$, $$$\\texttt{b}$$$, $$$\\texttt{c}$$$ placed in a row in some order. You can do the following operation\nat most once\n:\nPick two cards, and swap them.\nIs it possible that the row becomes $$$\\texttt{abc}$$$ after the operation? Output \"\nYES\n\" if it is possible, and \"\nNO\n\" otherwise.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 6$$$)\u00a0\u2014 the number of test cases.\nThe only line of each test case contains a single string consisting of each of the three characters $$$\\texttt{a}$$$, $$$\\texttt{b}$$$, and $$$\\texttt{c}$$$ exactly once, representing the cards.\nOutput\nFor each test case, output \"\nYES\n\" if you can make the row $$$\\texttt{abc}$$$ with at most one operation, or \"\nNO\n\" otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n6\nabc\nacb\nbac\nbca\ncab\ncba\nOutput\nYES\nYES\nYES\nNO\nNO\nYES\nNote\nIn the first test case, we don't need to do any operations, since the row is already $$$\\texttt{abc}$$$.\nIn the second test case, we can swap $$$\\texttt{c}$$$ and $$$\\texttt{b}$$$: $$$\\texttt{acb} \\to \\texttt{abc}$$$.\nIn the third test case, we can swap $$$\\texttt{b}$$$ and $$$\\texttt{a}$$$: $$$\\texttt{bac} \\to \\texttt{abc}$$$.\nIn the fourth test case, it is impossible to make $$$\\texttt{abc}$$$ using\nat most one\noperation.", "input": [ [ [ "abc" ] ], [ [ "acb" ] ], [ [ "bac" ] ], [ [ "bca" ] ], [ [ "cab" ] ], [ [ "cba" ] ] ], "output": [ "YES", "YES", "YES", "NO", "NO", "YES" ] }, { "problem_id": "1872A", "problem_name": "Two Vessels\nbrute force, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1872/A", "problem_solution_link": "https://codeforces.com/problemset/status/1872/problem/A", "problem_statement": "A. Two Vessels\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have two vessels with water. The first vessel contains $$$a$$$ grams of water, and the second vessel contains $$$b$$$ grams of water. Both vessels are very large and can hold any amount of water.\nYou also have an empty cup that can hold\nup to\n$$$c$$$ grams of water.\nIn one move, you can scoop\nup to\n$$$c$$$ grams of water from any vessel and pour it into\nthe other\nvessel. Note that the mass of water poured in one move\ndoes not have to be an integer\n.\nWhat is the minimum number of moves required to make the masses of water in the vessels equal? Note that you cannot perform any actions other than the described moves.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$). The description of the test cases follows.\nEach test case consists of a single line containing three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \\le a, b, c \\le 100$$$)\u00a0\u2014 the mass of water in the vessels and the capacity of the cup, respectively.\nOutput\nFor each test case, output a single number\u00a0\u2014 the minimum number of moves required to make the masses of water in the vessels equal. It can be shown, that it is always possible.\nExample\nInput\n6\n3 7 2\n17 4 3\n17 17 1\n17 21 100\n1 100 1\n97 4 3\nOutput\n1\n3\n0\n1\n50\n16\nNote\nIn the first test case, only one move is enough: if we pour $$$2$$$ grams of water from the second vessel into the first one, both vessels will contain $$$5$$$ grams of water.\nIn the second example test case, three moves are enough:\nPour $$$3$$$ grams of water from the first vessel into the second one. After this move, the first vessel will contain $$$17 - 3 = 14$$$ grams of water, and the second vessel will contain $$$4 + 3 = 7$$$ grams.\nPour $$$2$$$ grams of water from the first vessel into the second one. After this move, the first vessel will contain $$$14 - 2 = 12$$$ grams of water, and the second vessel will contain $$$7 + 2 = 9$$$ grams.\nFinally, pour $$$1.5$$$ grams of water from the first vessel into the second one. After this move, the first vessel will contain $$$12 - 1.5 = 10.5$$$ grams of water, and the second vessel will contain $$$9 + 1.5 = 10.5$$$ grams.\nNote that this is not the only way to equalize the vessels in $$$3$$$ moves, but there is no way to do it in $$$2$$$ moves.\nIn the third example test case, the vessels initially contain the same amount of water, so no moves are needed. The answer is $$$0$$$.", "input": [ [ [ "3", "7", "2" ] ], [ [ "17", "4", "3" ] ], [ [ "17", "17", "1" ] ], [ [ "17", "21", "100" ] ], [ [ "1", "100", "1" ] ], [ [ "97", "4", "3" ] ] ], "output": [ "1", "3", "0", "1", "50", "16" ], "error": true }, { "problem_id": "1870A", "problem_name": "MEXanized Array\nconstructive algorithms, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1870/A", "problem_solution_link": "https://codeforces.com/problemset/status/1870/problem/A", "problem_statement": "A. MEXanized Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given three non-negative integers $$$n$$$, $$$k$$$, and $$$x$$$. Find the maximum possible sum of elements in an array consisting of non-negative integers, which has $$$n$$$ elements, its MEX is equal to $$$k$$$, and all its elements do not exceed $$$x$$$. If such an array does not exist, output $$$-1$$$.\nThe MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance:\nThe MEX of $$$[2,2,1]$$$ is $$$0$$$, because $$$0$$$ does not belong to the array.\nThe MEX of $$$[3,1,0,1]$$$ is $$$2$$$, because $$$0$$$ and $$$1$$$ belong to the array, but $$$2$$$ does not.\nThe MEX of $$$[0,3,1,2]$$$ is $$$4$$$, because $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$ belong to the array, but $$$4$$$ does not.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$) \u2014 the number of test cases. Then follows the description of the test cases.\nThe only line of each test case contains three integers $$$n$$$, $$$k$$$, and $$$x$$$ ($$$1 \\leq n, k, x \\leq 200$$$).\nOutput\nFor each test case, output a single number \u2014 the maximum sum of elements in a valid array, or $$$-1$$$, if such an array does not exist.\nExample\nInput\n9\n5 3 3\n4 7 5\n4 2 28\n12 10 6\n57 51 122\n200 1 200\n2 2 1\n3 2 1\n4 7 10\nOutput\n7\n-1\n57\n-1\n2007\n39800\n1\n2\n-1\nNote\nIn the first test case, the maximum sum is $$$7$$$, and one of the valid arrays is $$$[0, 1, 2, 2, 2]$$$.\nIn the second test case, there are no valid arrays of length $$$n$$$.\nIn the third test case, the maximum sum is $$$57$$$, and one of the valid arrays is $$$[0, 1, 28, 28]$$$.", "input": [ [ [ "5", "3", "3" ] ], [ [ "4", "7", "5" ] ], [ [ "4", "2", "28" ] ], [ [ "12", "10", "6" ] ], [ [ "57", "51", "122" ] ], [ [ "200", "1", "200" ] ], [ [ "2", "2", "1" ] ], [ [ "3", "2", "1" ] ], [ [ "4", "7", "10" ] ] ], "output": [ "7", "-1", "57", "-1", "2007", "39800", "1", "2", "-1" ] }, { "problem_id": "1866A", "problem_name": "Ambitious Kid\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1866/A", "problem_solution_link": "https://codeforces.com/problemset/status/1866/problem/A", "problem_statement": "A. Ambitious Kid\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nChaneka, Pak Chanek's child, is an ambitious kid, so Pak Chanek gives her the following problem to test her ambition.\nGiven an array of integers $$$[A_1, A_2, A_3, \\ldots, A_N]$$$. In one operation, Chaneka can choose one element, then increase or decrease the element's value by $$$1$$$. Chaneka can do that operation multiple times, even for different elements.\nWhat is the minimum number of operations that must be done to make it such that $$$A_1 \\times A_2 \\times A_3 \\times \\ldots \\times A_N = 0$$$?\nInput\nThe first line contains a single integer $$$N$$$ ($$$1 \\leq N \\leq 10^5$$$).\nThe second line contains $$$N$$$ integers $$$A_1, A_2, A_3, \\ldots, A_N$$$ ($$$-10^5 \\leq A_i \\leq 10^5$$$).\nOutput\nAn integer representing the minimum number of operations that must be done to make it such that $$$A_1 \\times A_2 \\times A_3 \\times \\ldots \\times A_N = 0$$$.\nExamples\nInput\n3\n2 -6 5\nOutput\n2\nInput\n1\n-3\nOutput\n3\nInput\n5\n0 -1 0 1 0\nOutput\n0\nNote\nIn the first example, initially, $$$A_1\\times A_2\\times A_3=2\\times(-6)\\times5=-60$$$. Chaneka can do the following sequence of operations:\nDecrease the value of $$$A_1$$$ by $$$1$$$. Then, $$$A_1\\times A_2\\times A_3=1\\times(-6)\\times5=-30$$$\nDecrease the value of $$$A_1$$$ by $$$1$$$. Then, $$$A_1\\times A_2\\times A_3=0\\times(-6)\\times5=0$$$\nIn the third example, Chaneka does not have to do any operations, because from the start, it already holds that $$$A_1\\times A_2\\times A_3\\times A_4\\times A_5=0\\times(-1)\\times0\\times1\\times0=0$$$", "input": [ [ [ "3" ], [ "2", "-6", "5" ] ], [ [ "1" ], [ "-3" ] ], [ [ "5" ], [ "0", "-1", "0", "1", "0" ] ] ], "output": [ "2", "3", "0" ] }, { "problem_id": "1867A", "problem_name": "green_gold_dog, array and permutation\nconstructive algorithms, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1867/A", "problem_solution_link": "https://codeforces.com/problemset/status/1867/problem/A", "problem_statement": "A. green_gold_dog, array and permutation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\ngreen_gold_dog has an array $$$a$$$ of length $$$n$$$, and he wants to find a permutation $$$b$$$ of length $$$n$$$ such that the number of distinct numbers in the element-wise difference between array $$$a$$$ and permutation $$$b$$$ is maximized.\nA permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in any order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation (as $$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation (as $$$n=3$$$, but $$$4$$$ appears in the array).\nThe element-wise difference between two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$ is an array $$$c$$$ of length $$$n$$$, where $$$c_i$$$ = $$$a_i - b_i$$$ ($$$1 \\leq i \\leq n$$$).\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 4 \\cdot 10^4$$$). The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 4 \\cdot 10^4$$$).\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$4 \\cdot 10^4$$$.\nOutput\nFor each test case, output $$$n$$$ numbers - a suitable permutation $$$b$$$. If there are multiple solutions, print any of them.\nExample\nInput\n3\n1\n100000\n2\n1 1\n3\n10 3 3\nOutput\n1 \n2 1 \n1 3 2\nNote\nIn the first set of input data, the element-wise difference of the arrays is [99999]. Here, there is one distinct number, and it is obvious that in an array of length one, there cannot be more than one different element.\nIn the second set of input data, the element-wise difference of the arrays is [-1, 0]. Here, there are two distinct numbers, and it is obvious that in an array of length two, there cannot be more than two different elements.\nIn the third set of input data, the element-wise difference of the arrays is [9, 0, 1]. Here, there are three distinct numbers, and it is obvious that in an array of length three, there cannot be more than three different elements.", "input": [ [ [ "1" ], [ "100000" ] ], [ [ "2" ], [ "1", "1" ] ], [ [ "3" ], [ "10", "3", "3" ] ] ], "output": [ "1 ", "2 1 ", "1 3 2" ] }, { "problem_id": "1864A", "problem_name": "Increasing and Decreasing\nconstructive algorithms, greedy, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1864/A", "problem_solution_link": "https://codeforces.com/problemset/status/1864/problem/A", "problem_statement": "A. Increasing and Decreasing\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given three integers $$$x$$$, $$$y$$$, and $$$n$$$.\nYour task is to construct an array $$$a$$$ consisting of $$$n$$$ integers which satisfies the following conditions:\n$$$a_1=x$$$, $$$a_n=y$$$;\n$$$a$$$ is\nstrictly\nincreasing (i.e. $$$a_1 < a_2 < \\ldots < a_n$$$);\nif we denote $$$b_i=a_{i+1}-a_{i}$$$ for $$$1 \\leq i \\leq n-1$$$, then $$$b$$$ is\nstrictly\ndecreasing (i.e. $$$b_1 > b_2 > \\ldots > b_{n-1}$$$).\nIf there is no such array $$$a$$$, print a single integer $$$-1$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$). The description of the test cases follows.\nThe only line of each test case contains three integers $$$x$$$, $$$y$$$, $$$n$$$ ($$$1 \\le x < y \\le 1000,3 \\le n \\le 1000$$$).\nOutput\nFor each test case, output $$$n$$$ integers $$$a_1,a_2,\\ldots,a_n$$$. If there are multiple solutions, print any of them.\nIf there is no solution, print a single integer $$$-1$$$.\nExample\nInput\n3\n1 4 3\n1 3 3\n100 200 4\nOutput\n1 3 4\n-1\n100 150 180 200\nNote\nIn the first test case, $$$a=[1,3,4]$$$, which is strictly increasing. Next, $$$b_1=a_2-a_1=3-1=2$$$, $$$b_2=a_3-a_2=4-3=1$$$, thus $$$b=[2,1]$$$, which is strictly decreasing.\nIn the second test case, there is no array $$$a$$$ that satisfies all the conditions above.", "input": [ [ [ "1", "4", "3" ] ], [ [ "1", "3", "3" ] ], [ [ "100", "200", "4" ] ] ], "output": [ "1 3 4", "-1", "100 150 180 200" ] }, { "problem_id": "1863A", "problem_name": "Channel\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1863/A", "problem_solution_link": "https://codeforces.com/problemset/status/1863/problem/A", "problem_statement": "A. Channel\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPetya is an administrator of a channel in one of the messengers. A total of $$$n$$$ people are subscribed to his channel, and Petya is not considered a subscriber.\nPetya has published a new post on the channel. At the moment of the publication, there were $$$a$$$ subscribers online. We assume that every subscriber always reads all posts in the channel if they are online.\nAfter this, Petya starts monitoring the number of subscribers online. He consecutively receives $$$q$$$ notifications of the form \"a subscriber went offline\" or \"a subscriber went online\". Petya does not know which exact subscriber goes online or offline. It is guaranteed that such a sequence of notifications could have indeed been received.\nPetya wonders if all of his subscribers have read the new post. Help him by determining one of the following:\nit is impossible that all $$$n$$$ subscribers have read the post;\nit is possible that all $$$n$$$ subscribers have read the post;\nit is guaranteed that all $$$n$$$ subscribers have read the post.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 500$$$). The description of the test cases follows.\nThe first line of each test case contains three integers $$$n$$$, $$$a$$$, and $$$q$$$ ($$$1 \\le n \\le 100$$$, $$$0 \\le a \\le n$$$, $$$1 \\le q \\le 100$$$)\u00a0\u2014 the number of subscribers of the channel, the initial number of subscribers online, and the number of notifications.\nThe second line of each test case contains a string of length $$$q$$$, consisting of characters '\n+\n' and '\n-\n'. The $$$i$$$-th of these characters is '\n+\n', if the $$$i$$$-th notification tells that a subscriber goes online, and it is '\n-\n' otherwise.\nOutput\nFor each test case, output a single line: \"\nYES\n\" if all $$$n$$$ subscribers are guaranteed to have read the post, \"\nNO\n\" if it is impossible for all $$$n$$$ subscribers to have read the post, and \"\nMAYBE\n\" otherwise.\nExample\nInput\n4\n5 5 3\n--+\n5 2 3\n++-\n5 4 2\n-+\n5 0 7\n++++-++\nOutput\nYES\nNO\nMAYBE\nYES\nNote\nIn the first test case, there are $$$5$$$ out of $$$5$$$ subscribers online in the very beginning, so they will all read the post no matter what. The answer is \"\nYES\n\".\nIn the second test case, the number of subscribers online becomes $$$4$$$ after the first two notifications, next someone goes offline, and thus the fifth subscriber has no chance of reading the post. It is impossible for all the subscribers to read the post, so the answer is \"\nNO\n\".\nIn the third test case, on the one hand, the same person may have gone offline and online (in this case only $$$4$$$ out of $$$5$$$ subscribers have read the post), on the other hand, the last notification may have told that the fifth subscriber has gone online (in this case all subscribers have read the post). We cannot deduce which of the two holds, so the answer is \"\nMAYBE\n\".\nIn the fourth test case, there have to be five subscribers online after all the notifications. All of them will read the post, so the answer is \"\nYES\n\".", "input": [ [ [ "5", "5", "3" ], [ "--+" ] ], [ [ "5", "2", "3" ], [ "++-" ] ], [ [ "5", "4", "2" ], [ "-+" ] ], [ [ "5", "0", "7" ], [ "++++-++" ] ] ], "output": [ "YES", "NO", "MAYBE", "YES" ] }, { "problem_id": "1862B", "problem_name": "Sequence Game\nconstructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1862/B", "problem_solution_link": "https://codeforces.com/problemset/status/1862/problem/B", "problem_statement": "B. Sequence Game\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTema and Vika are playing the following game.\nFirst, Vika comes up with a sequence of positive integers $$$a$$$ of length $$$m$$$ and writes it down on a piece of paper. Then she takes a new piece of paper and writes down the sequence $$$b$$$ according to the following rule:\nFirst, she writes down $$$a_1$$$.\nThen, she writes down only those $$$a_i$$$ ($$$2 \\le i \\le m$$$) such that $$$a_{i - 1} \\le a_i$$$. Let the length of this sequence be denoted as $$$n$$$.\nFor example, from the sequence $$$a=[4, 3, 2, 6, 3, 3]$$$, Vika will obtain the sequence $$$b=[4, 6, 3]$$$.\nShe then gives the piece of paper with the sequence $$$b$$$ to Tema. He, in turn, tries to guess the sequence $$$a$$$.\nTema considers winning in such a game highly unlikely, but still wants to find at least one sequence $$$a$$$ that could have been originally chosen by Vika. Help him and output any such sequence.\nNote that the length of the sequence you output should not exceed the input sequence length by more than two times.\nInput\nEach test consists of multiple test cases. The first line of input data contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. This is followed by a description of the test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$)\u00a0\u2014 the length of the sequence $$$b$$$.\nThe second line of each test case contains $$$n$$$ integers $$$b_1, b_2, b_3, \\dots, b_n$$$ ($$$1 \\le b_i \\le 10^9$$$)\u00a0\u2014 the elements of the sequence.\nThe sum of the values of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, output\ntwo lines\n. In the first line, output a single integer $$$m$$$\u00a0\u2014 the length of the sequence ($$$n \\le m \\le 2 \\cdot n$$$). In the second line, output $$$m$$$ integers $$$a_1, a_2, a_3, \\dots, a_m$$$ ($$$1 \\le a_i \\le 10^9$$$)\u00a0\u2014 the assumed sequence that Vika could have written on the first piece of paper.\nIf there are multiple suitable sequences, you can output any of them.\nExample\nInput\n6\n3\n4 6 3\n3\n1 2 3\n5\n1 7 9 5 7\n1\n144\n2\n1 1\n5\n1 2 2 1 1\nOutput\n6\n4 3 2 6 3 3\n3\n1 2 3\n6\n1 7 9 3 5 7\n1\n144\n2\n1 1\n6\n1 2 2 1 1 1\nNote\nThe first sample is explained in the problem statement.\nIn the second sample, Vika could have chosen the original sequence.", "input": [ [ [ "3" ], [ "4", "6", "3" ] ], [ [ "3" ], [ "1", "2", "3" ] ], [ [ "5" ], [ "1", "7", "9", "5", "7" ] ], [ [ "1" ], [ "144" ] ], [ [ "2" ], [ "1", "1" ] ], [ [ "5" ], [ "1", "2", "2", "1", "1" ] ] ], "output": [ ["6", "4 3 2 6 3 3"], ["3", "1 2 3"], ["6", "1 7 9 3 5 7"], ["1", "144"], ["2", "1 1"], ["6", "1 2 2 1 1 1"] ], "error": true }, { "problem_id": "1862A", "problem_name": "Gift Carpet\ndp, greedy, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1862/A", "problem_solution_link": "https://codeforces.com/problemset/status/1862/problem/A", "problem_statement": "A. Gift Carpet\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nRecently, Tema and Vika celebrated Family Day. Their friend Arina gave them a carpet, which can be represented as an $$$n \\cdot m$$$ table of lowercase Latin letters.\nVika hasn't seen the gift yet, but Tema knows what kind of carpets she likes. Vika will like the carpet if she can read her name on. She reads column by column from left to right and chooses one or zero letters from current column.\nFormally, the girl will like the carpet if it is possible to select four distinct columns in order from left to right such that the first column contains \"v\", the second one contains \"i\", the third one contains \"k\", and the fourth one contains \"a\".\nHelp Tema understand in advance whether Vika will like Arina's gift.\nInput\nEach test consists of multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases. Then follows the description of the test cases.\nThe first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \\le n, m \\le 20$$$)\u00a0\u2014 the sizes of the carpet.\nThe next $$$n$$$ lines contain $$$m$$$ lowercase Latin letters each, describing the given carpet.\nOutput\nFor each set of input data, output \"YES\" if Vika will like the carpet, otherwise output \"NO\".\nYou can output each letter in any case (lowercase or uppercase). For example, the strings \"yEs\", \"yes\", \"Yes\", and \"YES\" will be accepted as a positive answer.\nExample\nInput\n5\n1 4\nvika\n3 3\nbad\ncar\npet\n4 4\nvvvv\niiii\nkkkk\naaaa\n4 4\nvkak\niiai\navvk\nviaa\n4 7\nvbickda\nvbickda\nvbickda\nvbickda\nOutput\nYES\nNO\nYES\nNO\nYES\nNote\nIn the first sample, Vika can read her name from left to right.\nIn the second sample, Vika cannot read the character \"v\", so she will not like the carpet.", "input": [ [ [ "1", "4" ], [ "vika" ] ], [ [ "3", "3" ], [ "bad", "car", "pet" ] ], [ [ "4", "4" ], [ "vvvv", "iiii", "kkkk", "aaaa" ] ], [ [ "4", "4" ], [ "vkak", "iiai", "avvk", "viaa" ] ], [ [ "4", "7" ], [ "vbickda", "vbickda", "vbickda", "vbickda" ] ] ], "output": [ "YES", "NO", "YES", "NO", "YES" ] }, { "problem_id": "1861A", "problem_name": "Prime Deletion\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1861/A", "problem_solution_link": "https://codeforces.com/problemset/status/1861/problem/A", "problem_statement": "A. Prime Deletion\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nA\nprime\nnumber is a positive integer that has exactly two different positive divisors: $$$1$$$ and the integer itself. For example, $$$2$$$, $$$3$$$, $$$13$$$ and $$$101$$$ are prime numbers; $$$1$$$, $$$4$$$, $$$6$$$ and $$$42$$$ are not.\nYou are given a sequence of digits from $$$1$$$ to $$$9$$$, in which\nevery digit from $$$1$$$ to $$$9$$$ appears exactly once\n.\nYou are allowed to do the following operation\nseveral (maybe zero) times\n: choose any digit from the sequence and delete it.\nHowever, you cannot perform this operation if the sequence consists of only two digits.\nYour goal is to obtain a sequence which represents a prime number. Note that you cannot reorder the digits in the sequence.\nPrint the resulting sequence, or report that it is impossible to perform the operations so that the resulting sequence is a prime number.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 5000$$$) \u2014 the number of test cases.\nEach test case consists of one line containing a string of $$$9$$$ digits (without any characters between them). Each digit from $$$1$$$ to $$$9$$$ appears in this string exactly once.\nOutput\nFor each test case, print the answer on a separate line as follows:\nif it is impossible to perform the described operations, print $$$-1$$$;\notherwise, print any sequence that represents a prime number, which can be obtained from the given string performing several (maybe zero) operations described in the statement. If there are multiple such sequences, you can print any one of them.\nExample\nInput\n4\n123456789\n987654321\n243567918\n576318429\nOutput\n167\n53\n3571\n57638429", "input": [ [ [ "123456789" ] ], [ [ "987654321" ] ], [ [ "243567918" ] ], [ [ "576318429" ] ] ], "output": [ "167", "53", "3571", "57638429" ] }, { "problem_id": "1859A", "problem_name": "United We Stand\nconstructive algorithms, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1859/A", "problem_solution_link": "https://codeforces.com/problemset/status/1859/problem/A", "problem_statement": "A. United We Stand\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven an array $$$a$$$ of length $$$n$$$, containing integers. And there are two initially empty arrays $$$b$$$ and $$$c$$$. You need to add each element of array $$$a$$$ to\nexactly one\nof the arrays $$$b$$$ or $$$c$$$, in order to satisfy the following conditions:\nBoth arrays $$$b$$$ and $$$c$$$ are non-empty. More formally, let $$$l_b$$$ be the length of array $$$b$$$, and $$$l_c$$$ be the length of array $$$c$$$. Then $$$l_b, l_c \\ge 1$$$.\nFor any two indices $$$i$$$ and $$$j$$$ ($$$1 \\le i \\le l_b, 1 \\le j \\le l_c$$$), $$$c_j$$$\nis not\na divisor of $$$b_i$$$.\nOutput the arrays $$$b$$$ and $$$c$$$ that can be obtained, or output $$$-1$$$ if they do not exist.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 500$$$) \u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the length of array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$) \u2014 the elements of array $$$a$$$.\nOutput\nFor each test case, output a single integer $$$-1$$$ if a solution does not exist.\nOtherwise, in the first line, output two integers $$$l_b$$$ and $$$l_c$$$ \u2014 the lengths of arrays $$$b$$$ and $$$c$$$ respectively.\nIn the second line, output $$$l_b$$$ integers $$$b_1, b_2, \\ldots, b_{l_b}$$$ \u2014 the elements of array $$$b$$$.\nIn the third line, output $$$l_c$$$ integers $$$c_1, c_2, \\ldots, c_{l_c}$$$ \u2014 the elements of array $$$c$$$.\nIf there are multiple solutions, output any of them. You can output the elements of the arrays in any order.\nExample\nInput\n5\n3\n2 2 2\n5\n1 2 3 4 5\n3\n1 3 5\n7\n1 7 7 2 9 1 4\n5\n4 8 12 12 4\nOutput\n-1\n3 2\n1 3 5 \n2 4 \n1 2\n1 \n3 5 \n2 5\n1 1 \n2 4 7 7 9 \n3 2\n4 8 4 \n12 12\nNote\nIn the first test case, a solution does not exist.\nIn the second test case, we can obtain $$$b = [1, 3, 5]$$$ and $$$c = [2, 4]$$$. Then elements $$$2$$$ and $$$4$$$ do not divide elements $$$1, 3$$$ and $$$5$$$.\nIn the fifth test case, we can obtain $$$b = [4, 8, 4]$$$ and $$$c = [12, 12]$$$.", "input": [ [ [ "3" ], [ "2", "2", "2" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ] ], [ [ "3" ], [ "1", "3", "5" ] ], [ [ "7" ], [ "1", "7", "7", "2", "9", "1", "4" ] ], [ [ "5" ], [ "4", "8", "12", "12", "4" ] ] ], "output": [ ["-1"], ["3 2", "1 3 5", "2 4"], ["1 2", "1", "3 5"], ["2 5", "1 1", "2 4 7 7 9"], ["3 2", "4 8 4", "12 12"] ], "error": true }, { "problem_id": "1858A", "problem_name": "Buttons\ngames, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1858/A", "problem_solution_link": "https://codeforces.com/problemset/status/1858/problem/A", "problem_statement": "A. Buttons\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAnna and Katie ended up in a secret laboratory.\nThere are $$$a+b+c$$$ buttons in the laboratory. It turned out that $$$a$$$ buttons can only be pressed by Anna, $$$b$$$ buttons can only be pressed by Katie, and $$$c$$$ buttons can be pressed by either of them. Anna and Katie decided to play a game, taking turns pressing these buttons. Anna makes the first turn. Each button can be pressed at most once, so at some point, one of the girls will not be able to make her turn.\nThe girl who cannot press a button loses. Determine who will win if both girls play optimally.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \\le a, b, c \\le 10^9$$$)\u00a0\u2014 the number of buttons that can only be pressed by Anna, the number of buttons that can only be pressed by Katie, and the number of buttons that can be pressed by either of them, respectively.\nOutput\nFor each test case, output\nFirst\nif Anna wins, or\nSecond\nif Katie wins.\nExample\nInput\n5\n1 1 1\n9 3 3\n1 2 3\n6 6 9\n2 2 8\nOutput\nFirst\nFirst\nSecond\nFirst\nSecond\nNote\nFor the simplicity of the explanation, we will numerate the buttons by the numbers from $$$1$$$ to $$$a+b+c$$$: the first $$$a$$$ buttons can only be pressed by Anna, the next $$$b$$$ buttons can only be pressed by Katie, and the last $$$c$$$ buttons can be pressed by either of them.\nIn the first test case, Anna can press the $$$3$$$-rd button on the first turn. Then Katie will press the $$$2$$$-nd button (since it is the only possible turn for her). Then Anna will press the $$$1$$$-st button. Katie won't have a button to press, so Anna will win.\nIn the second test case, Anna can press the first nine buttons in some order on her turns. No matter what buttons Katie will press, all the buttons from the $$$10$$$-th to the $$$15$$$-th will be pressed after $$$12$$$ turns. On the $$$13$$$-th turn, Anna will press one of the first nine buttons and Katie will not have a button to press on her turn. Thus, Anna will win.\nIn the third test case, the game can proceed as follows:\nOn the $$$1$$$-st turn Anna presses the $$$5$$$-th button.\nOn the $$$2$$$-st turn Katie presses the $$$4$$$-th button.\nOn the $$$3$$$-st turn Anna presses the $$$6$$$-th button.\nOn the $$$4$$$-st turn Katie presses the $$$3$$$-th button.\nOn the $$$5$$$-st turn Anna presses the $$$1$$$-th button.\nOn the $$$6$$$-st turn Katie presses the $$$2$$$-th button.\nAnna cannot make the turn, so Katie wins.\nIt can be shown that Katie can win no matter what moves Anna takes.", "input": [ [ [ "1", "1", "1" ] ], [ [ "9", "3", "3" ] ], [ [ "1", "2", "3" ] ], [ [ "6", "6", "9" ] ], [ [ "2", "2", "8" ] ] ], "output": [ "First", "First", "Second", "First", "Second" ] }, { "problem_id": "1857A", "problem_name": "Array Coloring\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1857/A", "problem_solution_link": "https://codeforces.com/problemset/status/1857/problem/A", "problem_statement": "A. Array Coloring\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array consisting of $$$n$$$ integers. Your task is to determine whether it is possible to color all its elements in two colors in such a way that the sums of the elements of both colors have the same parity and each color has at least one element colored.\nFor example, if the array is [$$$1,2,4,3,2,3,5,4$$$], we can color it as follows: [$$$\\color{blue}{1},\\color{blue}{2},\\color{red}{4},\\color{blue}{3},\\color{red}{2},\\color{red}{3},\\color{red}{5},\\color{red}{4}$$$], where the sum of the blue elements is $$$6$$$ and the sum of the red elements is $$$18$$$.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases.\nEach test case begins with a line containing an integer $$$n$$$ ($$$2 \\le n \\le 50$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe next line contains $$$n$$$ integers $$$a_1,a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 50$$$)\u00a0\u2014 the elements of the array $$$a$$$.\nOutput\nFor each test case, output \"YES\" (without quotes) if it is possible to color the array in two colors in such a way that the sums of the elements of both colors have the same parity and each color has at least one element colored, and \"NO\" otherwise.\nYou can output \"Yes\" and \"No\" in any case (for example, the strings \"yES\", \"yes\", and \"Yes\" will be recognized as correct answers).\nExample\nInput\n7\n8\n1 2 4 3 2 3 5 4\n2\n4 7\n3\n3 9 8\n2\n1 7\n5\n5 4 3 2 1\n4\n4 3 4 5\n2\n50 48\nOutput\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nNote\nThe first sample is described in the statement.\nIn the second sample, there are only two colorings $$$[\\color{blue}{4},\\color{red}{7}]$$$ and $$$[\\color{red}{4},\\color{blue}{7}]$$$ , but in both cases the parity of sums is different.\nIn the third sample, you can color $$$[\\color{blue}{3},\\color{blue}{9},\\color{red}{8}]$$$ and $$$12$$$ and $$$8$$$ are both even.", "input": [ [ [ "8" ], [ "1", "2", "4", "3", "2", "3", "5", "4" ] ], [ [ "2" ], [ "4", "7" ] ], [ [ "3" ], [ "3", "9", "8" ] ], [ [ "2" ], [ "1", "7" ] ], [ [ "5" ], [ "5", "4", "3", "2", "1" ] ], [ [ "4" ], [ "4", "3", "4", "5" ] ], [ [ "2" ], [ "50", "48" ] ] ], "output": [ "YES", "NO", "YES", "YES", "NO", "YES", "YES" ] }, { "problem_id": "1856A", "problem_name": "Tales of a Sort\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1856/A", "problem_solution_link": "https://codeforces.com/problemset/status/1856/problem/A", "problem_statement": "A. Tales of a Sort\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAlphen has an array of positive integers $$$a$$$ of length $$$n$$$.\nAlphen can perform the following operation:\nFor\nall\n$$$i$$$ from $$$1$$$ to $$$n$$$, replace $$$a_i$$$ with $$$\\max(0, a_i - 1)$$$.\nAlphen will perform the above operation until $$$a$$$ is sorted, that is $$$a$$$ satisfies $$$a_1 \\leq a_2 \\leq \\ldots \\leq a_n$$$. How many operations will Alphen perform? Under the constraints of the problem, it can be proven that Alphen will perform a finite number of operations.\nInput\nEach test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \\le t \\le 500$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 50$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10 ^ 9$$$)\u00a0\u2014 the elements of the array $$$a$$$.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the number of operations that Alphen will perform.\nExample\nInput\n7\n3\n1 2 3\n5\n2 1 2 1 2\n4\n3 1 5 4\n2\n7 7\n5\n4 1 3 2 5\n5\n2 3 1 4 5\n3\n1000000000 1 2\nOutput\n0\n2\n5\n0\n4\n3\n1000000000\nNote\nIn the first test case, we have $$$a=[1,2,3]$$$. Since $$$a$$$ is already sorted, Alphen will not need to perform any operations. So, the answer is $$$0$$$.\nIn the second test case, we have $$$a=[2,1,2,1,2]$$$. Since $$$a$$$ is not initially sorted, Alphen will perform one operation to make $$$a=[1,0,1,0,1]$$$. After performing one operation, $$$a$$$ is still not sorted, so Alphen will perform another operation to make $$$a=[0,0,0,0,0]$$$. Since $$$a$$$ is sorted, Alphen will not perform any other operations. Since Alphen has performed two operations in total, the answer is $$$2$$$.", "input": [ [ [ "3" ], [ "1", "2", "3" ] ], [ [ "5" ], [ "2", "1", "2", "1", "2" ] ], [ [ "4" ], [ "3", "1", "5", "4" ] ], [ [ "2" ], [ "7", "7" ] ], [ [ "5" ], [ "4", "1", "3", "2", "5" ] ], [ [ "5" ], [ "2", "3", "1", "4", "5" ] ], [ [ "3" ], [ "1000000000", "1", "2" ] ] ], "output": [ "0", "2", "5", "0", "4", "3", "1000000000" ] }, { "problem_id": "1855A", "problem_name": "Dalton the Teacher\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1855/A", "problem_solution_link": "https://codeforces.com/problemset/status/1855/problem/A", "problem_statement": "A. Dalton the Teacher\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nDalton is the teacher of a class with $$$n$$$ students, numbered from $$$1$$$ to $$$n$$$. The classroom contains $$$n$$$ chairs, also numbered from $$$1$$$ to $$$n$$$. Initially student $$$i$$$ is seated on chair $$$p_i$$$. It is guaranteed that $$$p_1,p_2,\\dots, p_n$$$ is a permutation of length $$$n$$$.\nA student is happy if his/her number is different from the number of his/her chair. In order to make all of his students happy, Dalton can repeatedly perform the following operation: choose two distinct students and swap their chairs. What is the minimum number of moves required to make all the students happy? One can show that, under the constraints of this problem, it is possible to make all the students happy with a finite number of moves.\nA permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$). The description of the test cases follows.\nThe first line contains a single integer $$$n$$$ ($$$2 \\le n \\le 10^5$$$) \u2014 the number of students.\nThe second line contains $$$n$$$ integers $$$p_1, p_2, \\ldots, p_n$$$ ($$$1 \\le p_i \\le n$$$) \u2014 $$$p_i$$$ denotes the initial chair of student $$$i$$$. It is guaranteed that $$$p$$$ is a permutation.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each test case, output the minimum number of moves required.\nExample\nInput\n5\n2\n2 1\n3\n1 2 3\n5\n1 2 5 4 3\n4\n1 2 4 3\n10\n10 2 1 3 6 5 4 7 9 8\nOutput\n0\n2\n2\n1\n1\nNote\nIn the first test case, both students are already happy, so Dalton can perform $$$0$$$ moves.\nIn the second test case, Dalton can swap the chairs of students $$$1$$$ and $$$2$$$ to get the array $$$[2, 1, 3]$$$. Then he can swap chairs of students $$$2$$$ and $$$3$$$ to get the array $$$[2, 3, 1]$$$. At this point all the students are happy, and he performed $$$2$$$ moves. It is impossible to perform the task with fewer moves.\nIn the third test case, by swapping the chairs of students $$$1$$$ and $$$2$$$ and then swapping the chairs of students $$$4$$$ and $$$5$$$, Dalton gets the array $$$[2, 1, 5, 3, 4]$$$ in $$$2$$$ moves.", "input": [ [ [ "2" ], [ "2", "1" ] ], [ [ "3" ], [ "1", "2", "3" ] ], [ [ "5" ], [ "1", "2", "5", "4", "3" ] ], [ [ "4" ], [ "1", "2", "4", "3" ] ], [ [ "10" ], [ "10", "2", "1", "3", "6", "5", "4", "7", "9", "8" ] ] ], "output": [ "0", "2", "2", "1", "1" ] }, { "problem_id": "1853A", "problem_name": "Desorting\nbrute force, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1853/A", "problem_solution_link": "https://codeforces.com/problemset/status/1853/problem/A", "problem_statement": "A. Desorting\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nCall an array $$$a$$$ of length $$$n$$$\nsorted\nif $$$a_1 \\leq a_2 \\leq \\ldots \\leq a_{n-1} \\leq a_n$$$.\nNtarsis has an array $$$a$$$ of length $$$n$$$.\nHe is allowed to perform one type of operation on it (zero or more times):\nChoose an index $$$i$$$ ($$$1 \\leq i \\leq n-1$$$).\nAdd $$$1$$$ to $$$a_1, a_2, \\ldots, a_i$$$.\nSubtract $$$1$$$ from $$$a_{i+1}, a_{i+2}, \\ldots, a_n$$$.\nThe values of $$$a$$$ can be negative after an operation.\nDetermine the minimum operations needed to make $$$a$$$\nnot sorted\n.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 500$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe next line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 10^9$$$)\u00a0\u2014 the values of array $$$a$$$.\nIt is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$500$$$.\nOutput\nOutput the minimum number of operations needed to make the array\nnot sorted\n.\nExample\nInput\n4\n2\n1 1\n4\n1 8 10 13\n3\n1 3 2\n3\n1 9 14\nOutput\n1\n2\n0\n3\nNote\nIn the first case, we can perform $$$1$$$ operation to make the array not sorted:\nPick $$$i = 1$$$. The array $$$a$$$ then becomes $$$[2, 0]$$$, which is not sorted.\nIn the second case, we can perform $$$2$$$ operations to make the array not sorted:\nPick $$$i = 3$$$. The array $$$a$$$ then becomes $$$[2, 9, 11, 12]$$$.\nPick $$$i = 3$$$. The array $$$a$$$ then becomes $$$[3, 10, 12, 11]$$$, which is not sorted.\nIt can be proven that $$$1$$$ and $$$2$$$ operations are the minimal numbers of operations in the first and second test cases, respectively.\nIn the third case, the array is\nalready\nnot sorted, so we perform $$$0$$$ operations.", "input": [ [ [ "2" ], [ "1", "1" ] ], [ [ "4" ], [ "1", "8", "10", "13" ] ], [ [ "3" ], [ "1", "3", "2" ] ], [ [ "3" ], [ "1", "9", "14" ] ] ], "output": [ "1", "2", "0", "3" ] }, { "problem_id": "1851B", "problem_name": "Parity Sort\ngreedy, sortings, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1851/B", "problem_solution_link": "https://codeforces.com/problemset/status/1851/problem/B", "problem_statement": "B. Parity Sort\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have an array of integers $$$a$$$ of length $$$n$$$. You can apply the following operation to the given array:\nSwap two elements $$$a_i$$$ and $$$a_j$$$ such that $$$i \\neq j$$$, $$$a_i$$$ and $$$a_j$$$ are either\nboth\neven or\nboth\nodd.\nDetermine whether it is possible to sort the array in non-decreasing order by performing the operation any number of times (possibly zero).\nFor example, let $$$a$$$ = [$$$7, 10, 1, 3, 2$$$]. Then we can perform $$$3$$$ operations to sort the array:\nSwap $$$a_3 = 1$$$ and $$$a_1 = 7$$$, since $$$1$$$ and $$$7$$$ are odd. We get $$$a$$$ = [$$$1, 10, 7, 3, 2$$$];\nSwap $$$a_2 = 10$$$ and $$$a_5 = 2$$$, since $$$10$$$ and $$$2$$$ are even. We get $$$a$$$ = [$$$1, 2, 7, 3, 10$$$];\nSwap $$$a_4 = 3$$$ and $$$a_3 = 7$$$, since $$$3$$$ and $$$7$$$ are odd. We get $$$a$$$ = [$$$1, 2, 3, 7, 10$$$].\nInput\nThe first line of input data contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe description of the test cases follows.\nThe first line of each test case contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) \u2014 the length of array $$$a$$$.\nThe second line of each test case contains exactly $$$n$$$ positive integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$)\u00a0\u2014 the elements of array $$$a$$$.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, output on a separate line:\nYES\nif the array can be sorted by applying the operation to it some number of times;\nNO\notherwise.\nYou can output\nYES\nand\nNO\nin any case (for example, strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as positive response).\nExample\nInput\n6\n5\n7 10 1 3 2\n4\n11 9 3 5\n5\n11 3 15 3 2\n6\n10 7 8 1 2 3\n1\n10\n5\n6 6 4 1 6\nOutput\nYES\nYES\nNO\nNO\nYES\nNO\nNote\nThe first test case is explained in the problem statement.", "input": [ [ [ "5" ], [ "7", "10", "1", "3", "2" ] ], [ [ "4" ], [ "11", "9", "3", "5" ] ], [ [ "5" ], [ "11", "3", "15", "3", "2" ] ], [ [ "6" ], [ "10", "7", "8", "1", "2", "3" ] ], [ [ "1" ], [ "10" ] ], [ [ "5" ], [ "6", "6", "4", "1", "6" ] ] ], "output": [ "YES", "YES", "NO", "NO", "YES", "NO" ] }, { "problem_id": "1851A", "problem_name": "Escalator Conversations\nbrute force, constructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1851/A", "problem_solution_link": "https://codeforces.com/problemset/status/1851/problem/A", "problem_statement": "A. Escalator Conversations\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nOne day, Vlad became curious about who he can have a conversation with on the escalator in the subway. There are a total of $$$n$$$ passengers. The escalator has a total of $$$m$$$ steps, all steps indexed from $$$1$$$ to $$$m$$$ and $$$i$$$-th step has height $$$i \\cdot k$$$.\nVlad's height is $$$H$$$ centimeters. Two people with heights $$$a$$$ and $$$b$$$ can have a conversation on the escalator if they are standing on\ndifferent\nsteps and the height difference between them is equal to the height difference between the steps.\nFor example, if two people have heights $$$170$$$ and $$$180$$$ centimeters, and $$$m = 10, k = 5$$$, then they can stand on steps numbered $$$7$$$ and $$$5$$$, where the height difference between the steps is equal to the height difference between the two people: $$$k \\cdot 2 = 5 \\cdot 2 = 10 = 180 - 170$$$. There are other possible ways.\nGiven an array $$$h$$$ of size $$$n$$$, where $$$h_i$$$ represents the height of the $$$i$$$-th person. Vlad is interested in how many people he can have a conversation with on the escalator\nindividually\n.\nFor example, if $$$n = 5, m = 3, k = 3, H = 11$$$, and $$$h = [5, 4, 14, 18, 2]$$$, Vlad can have a conversation with the person with height $$$5$$$ (Vlad will stand on step $$$1$$$, and the other person will stand on step $$$3$$$) and with the person with height $$$14$$$ (for example, Vlad can stand on step $$$3$$$, and the other person will stand on step $$$2$$$). Vlad cannot have a conversation with the person with height $$$2$$$ because even if they stand on the extreme steps of the escalator, the height difference between them will be $$$6$$$, while their height difference is $$$9$$$. Vlad cannot have a conversation with the rest of the people on the escalator, so the answer for this example is $$$2$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases.\nThen the descriptions of the test cases follow.\nThe first line of each test case contains integers: $$$n, m, k, H$$$ ($$$1 \\le n,m \\le 50$$$, $$$1 \\le k,H \\le 10^6$$$). Here, $$$n$$$ is the number of people, $$$m$$$ is the number of steps, $$$k$$$ is the height difference between neighboring steps, and $$$H$$$ is Vlad's height.\nThe second line contains $$$n$$$ integers: $$$h_1, h_2, \\ldots, h_n$$$ ($$$1 \\le h_i \\le 10^6$$$). Here, $$$h_i$$$ represents the height of the $$$i$$$-th person.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the number of people Vlad can have a conversation with on the escalator\nindividually\n.\nExample\nInput\n7\n5 3 3 11\n5 4 14 18 2\n2 9 5 6\n11 9\n10 50 3 11\n43 44 74 98 62 60 99 4 11 73\n4 8 8 49\n68 58 82 73\n7 1 4 66\n18 66 39 83 48 99 79\n9 1 1 13\n26 23 84 6 60 87 40 41 25\n6 13 3 28\n30 70 85 13 1 55\nOutput\n2\n1\n4\n1\n0\n0\n3\nNote\nThe first example is explained in the problem statement.\nIn the second example, Vlad can have a conversation with the person with height $$$11$$$.\nIn the third example, Vlad can have a conversation with people with heights: $$$44, 74, 98, 62$$$. Therefore, the answer is $$$4$$$.\nIn the fourth example, Vlad can have a conversation with the person with height $$$73$$$.", "input": [ [ [ "5", "3", "3", "11" ], [ "5", "4", "14", "18", "2" ] ], [ [ "2", "9", "5", "6" ], [ "11", "9" ] ], [ [ "10", "50", "3", "11" ], [ "43", "44", "74", "98", "62", "60", "99", "4", "11", "73" ] ], [ [ "4", "8", "8", "49" ], [ "68", "58", "82", "73" ] ], [ [ "7", "1", "4", "66" ], [ "18", "66", "39", "83", "48", "99", "79" ] ], [ [ "9", "1", "1", "13" ], [ "26", "23", "84", "6", "60", "87", "40", "41", "25" ] ], [ [ "6", "13", "3", "28" ], [ "30", "70", "85", "13", "1", "55" ] ] ], "output": [ "2", "1", "4", "1", "0", "0", "3" ] }, { "problem_id": "1850C", "problem_name": "Word on the Paper\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1850/C", "problem_solution_link": "https://codeforces.com/problemset/status/1850/problem/C", "problem_statement": "C. Word on the Paper\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nOn an $$$8 \\times 8$$$ grid of dots, a word consisting of lowercase Latin letters is written vertically in one column, from top to bottom. What is it?\nInput\nThe input consists of multiple test cases. The first line of the input contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of $$$8$$$ lines, each containing $$$8$$$ characters. Each character in the grid is either $$$\\texttt{.}$$$ (representing a dot) or a lowercase Latin letter ($$$\\texttt{a}$$$\u2013$$$\\texttt{z}$$$).\nThe word lies entirely in a single column and is continuous from the beginning to the ending (without gaps). See the sample input for better understanding.\nOutput\nFor each test case, output a single line containing the word made up of lowercase Latin letters ($$$\\texttt{a}$$$\u2013$$$\\texttt{z}$$$) that is written vertically in one column from top to bottom.\nExample\nInput\n5\n........\n........\n........\n........\n...i....\n........\n........\n........\n........\n.l......\n.o......\n.s......\n.t......\n........\n........\n........\n........\n........\n........\n........\n......t.\n......h.\n......e.\n........\n........\n........\n........\n........\n.......g\n.......a\n.......m\n.......e\na.......\na.......\na.......\na.......\na.......\na.......\na.......\na.......\nOutput\ni\nlost\nthe\ngame\naaaaaaaa", "input": [ [ [ "........" ], [ "........" ], [ "........" ], [ "........" ], [ "...i...." ], [ "........" ], [ "........" ], [ "........" ] ], [ [ "........" ], [ ".l......" ], [ ".o......" ], [ ".s......" ], [ ".t......" ], [ "........" ], [ "........" ], [ "........" ] ], [ [ "........" ], [ "........" ], [ "........" ], [ "........" ], [ "......t." ], [ "......h." ], [ "......e." ], [ "........" ] ], [ [ "........" ], [ "........" ], [ "........" ], [ "........" ], [ ".......g" ], [ ".......a" ], [ ".......m" ], [ ".......e" ] ], [ [ "a......." ], [ "a......." ], [ "a......." ], [ "a......." ], [ "a......." ], [ "a......." ], [ "a......." ], [ "a......." ] ] ], "output": [ "i", "lost", "the", "game", "aaaaaaaa" ] }, { "problem_id": "1850B", "problem_name": "Ten Words of Wisdom\nimplementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1850/B", "problem_solution_link": "https://codeforces.com/problemset/status/1850/problem/B", "problem_statement": "B. Ten Words of Wisdom\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIn the game show \"Ten Words of Wisdom\", there are $$$n$$$ participants numbered from $$$1$$$ to $$$n$$$, each of whom submits one response. The $$$i$$$-th response is $$$a_i$$$ words long and has quality $$$b_i$$$. No two responses have the same quality, and at least one response has length at most $$$10$$$.\nThe winner of the show is the response which has the highest quality out of all responses that are not longer than $$$10$$$ words. Which response is the winner?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 50$$$)\u00a0\u2014 the number of responses.\nThen $$$n$$$ lines follow, the $$$i$$$-th of which contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \\leq a_i, b_i \\leq 50$$$)\u00a0\u2014 the number of words and the quality of the $$$i$$$-th response, respectively.\nAdditional constraints on the input:\nin each test case, at least one value of $$$i$$$ satisfies $$$a_i \\leq 10$$$, and all values of $$$b_i$$$ are distinct.\nOutput\nFor each test case, output a single line containing one integer $$$x$$$ ($$$1 \\leq x \\leq n$$$)\u00a0\u2014 the winner of the show, according to the rules given in the statement.\nIt can be shown that, according to the constraints in the statement, exactly one winner exists for each test case.\nExample\nInput\n3\n5\n7 2\n12 5\n9 3\n9 4\n10 1\n3\n1 2\n3 4\n5 6\n1\n1 43\nOutput\n4\n3\n1\nNote\nIn the first test case, the responses provided are as follows:\nResponse 1: $$$7$$$ words, quality $$$2$$$\nResponse 2: $$$12$$$ words, quality $$$5$$$\nResponse 3: $$$9$$$ words, quality $$$3$$$\nResponse 4: $$$9$$$ words, quality $$$4$$$\nResponse 5: $$$10$$$ words, quality $$$1$$$\nWe can see that the responses with indices $$$1$$$, $$$3$$$, $$$4$$$, and $$$5$$$ have lengths not exceeding $$$10$$$ words. Out of these responses, the winner is the one with the highest quality.\nComparing the qualities, we find that:\nResponse 1 has quality $$$2$$$.\nResponse 3 has quality $$$3$$$.\nResponse 4 has quality $$$4$$$.\nResponse 5 has quality $$$1$$$.\nAmong these responses, Response 4 has the highest quality.", "input": [ [ [ "5" ], [ "7", "2" ], [ "12", "5" ], [ "9", "3" ] ], [ [ "9", "4" ], [ "10", "1" ], [ "3" ], [ "1", "2" ] ], [ [ "3", "4" ], [ "5", "6" ], [ "1" ], [ "1", "43" ] ] ], "output": [ "4", "3", "1" ] }, { "problem_id": "1850A", "problem_name": "To My Critics\nimplementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1850/A", "problem_solution_link": "https://codeforces.com/problemset/status/1850/problem/A", "problem_statement": "A. To My Critics\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nSuneet has three digits $$$a$$$, $$$b$$$, and $$$c$$$.\nSince math isn't his strongest point, he asks you to determine if you can choose any two digits to make a sum greater or equal to $$$10$$$.\nOutput \"\nYES\n\" if there is such a pair, and \"\nNO\n\" otherwise.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nThe only line of each test case contains three digits $$$a$$$, $$$b$$$, $$$c$$$ ($$$0 \\leq a, b, c \\leq 9$$$).\nOutput\nFor each test case, output \"\nYES\n\" if such a pair exists, and \"\nNO\n\" otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n5\n8 1 2\n4 4 5\n9 9 9\n0 0 0\n8 5 3\nOutput\nYES\nNO\nYES\nNO\nYES\nNote\nFor the first test case, by choosing the digits $$$8$$$ and $$$2$$$ we can obtain a sum of $$$8 + 2 = 10$$$ which satisfies the condition, thus the output should be \"\nYES\n\".\nFor the second test case, any combination of chosen digits won't be at least $$$10$$$, thus the output should be \"\nNO\n\" (note that we can not choose the digit on the same position twice).\nFor the third test case, any combination of chosen digits will have a sum equal to $$$18$$$, thus the output should be \"\nYES\n\".", "input": [ [ [ "8", "1", "2" ] ], [ [ "4", "4", "5" ] ], [ [ "9", "9", "9" ] ], [ [ "0", "0", "0" ] ], [ [ "8", "5", "3" ] ] ], "output": [ "YES", "NO", "YES", "NO", "YES" ] }, { "problem_id": "1849A", "problem_name": "Morning Sandwich\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1849/A", "problem_solution_link": "https://codeforces.com/problemset/status/1849/problem/A", "problem_statement": "A. Morning Sandwich\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMonocarp always starts his morning with a good ol' sandwich. Sandwiches Monocarp makes always consist of bread, cheese and/or ham.\nA sandwich always follows the formula:\na piece of bread\na slice of cheese or ham\na piece of bread\n$$$\\dots$$$\na slice of cheese or ham\na piece of bread\nSo it always has bread on top and at the bottom, and it alternates between bread and filling, where filling is a slice of either cheese or ham. Each piece of bread and each slice of cheese or ham is called a layer.\nToday Monocarp woke up and discovered that he has $$$b$$$ pieces of bread, $$$c$$$ slices of cheese and $$$h$$$ slices of ham. What is the maximum number of layers his morning sandwich can have?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of testcases.\nEach testcase consists of three integers $$$b, c$$$ and $$$h$$$ ($$$2 \\le b \\le 100$$$; $$$1 \\le c, h \\le 100$$$)\u00a0\u2014 the number of pieces of bread, slices of cheese and slices of ham, respectively.\nOutput\nFor each testcase, print a single integer\u00a0\u2014 the maximum number of layers Monocarp's morning sandwich can have.\nExample\nInput\n3\n2 1 1\n10 1 2\n3 7 8\nOutput\n3\n7\n5\nNote\nIn the first testcase, Monocarp can arrange a sandwich with three layers: either a piece of bread, a slice of cheese and another piece of bread, or a piece of bread, a slice of ham and another piece of bread.\nIn the second testcase, Monocarp has a lot of bread, but not too much filling. He can arrange a sandwich with four pieces of bread, one slice of cheese and two slices of ham.\nIn the third testcase, it's the opposite\u00a0\u2014 Monocarp has a lot of filling, but not too much bread. He can arrange a sandwich with three pieces of bread and two slices of cheese, for example.", "input": [ [ [ "2", "1", "1" ] ], [ [ "10", "1", "2" ] ], [ [ "3", "7", "8" ] ] ], "output": [ "3", "7", "5" ] }, { "problem_id": "1847A", "problem_name": "The Man who became a God\ngreedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1847/A", "problem_solution_link": "https://codeforces.com/problemset/status/1847/problem/A", "problem_statement": "A. The Man who became a God\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nKars\nis tired and resentful of the narrow mindset of his village since they are content with staying where they are and are not trying to become the perfect life form. Being a top-notch inventor,\nKars\nwishes to enhance his body and become the perfect life form. Unfortunately, $$$n$$$ of the villagers have become suspicious of his ideas. The $$$i$$$-th villager has a suspicion of $$$a_i$$$ on him. Individually each villager is scared of Kars, so they form into groups to be more powerful.\nThe power of the group of villagers from $$$l$$$ to $$$r$$$ be defined as $$$f(l,r)$$$ where\n$$$$$$f(l,r) = |a_l - a_{l+1}| + |a_{l + 1} - a_{l + 2}| + \\ldots + |a_{r-1} - a_r|.$$$$$$\nHere $$$|x-y|$$$ is the absolute value of $$$x-y$$$. A group with only one villager has a power of $$$0$$$.\nKars\nwants to break the villagers into exactly $$$k$$$ contiguous subgroups so that the sum of their power is minimized. Formally, he must find $$$k - 1$$$ positive integers $$$1 \\le r_1 < r_2 < \\ldots < r_{k - 1} < n$$$ such that $$$f(1, r_1) + f(r_1 + 1, r_2) + \\ldots + f(r_{k-1} + 1, n)$$$ is minimised. Help\nKars\nin finding the minimum value of $$$f(1, r_1) + f(r_1 + 1, r_2) + \\ldots + f(r_{k-1} + 1, n)$$$.\nInput\nThe first line contains a single integer $$$t$$$ $$$(1 \\leq t \\leq 100)$$$\u00a0\u2014 the number of test cases. The description of test cases follows.\nThe first line of each test case contains two integers $$$n,k$$$ $$$(1 \\leq k \\leq n \\leq 100)$$$\u00a0\u2014 the number of villagers and the number of groups they must be split into.\nThe second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \\ldots, a_n$$$ $$$(1 \\leq a_i \\leq 500)$$$\u00a0\u2014 the suspicion of each of the villagers.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the minimum possible value of sum of power of all the groups i.\u00a0e. the minimum possible value of $$$f(1,r_1) + f(r_1 + 1, r_2) + \\ldots + f(r_{k-1} + 1, n)$$$.\nExample\nInput\n3\n4 2\n1 3 5 2\n6 3\n1 9 12 4 7 2\n12 8\n1 9 8 2 3 3 1 8 7 7 9 2\nOutput\n4\n11\n2\nNote\nIn the first test case, we will group the villagers with suspicion $$$(1,3,5,2)$$$ into $$$(1,3,5)$$$ and $$$(2)$$$. So, $$$f(1,3) + f(4,4) = (|1 - 3| + |3 - 5|) + 0 = 4 + 0 = 4$$$.\nIn the second test case, we will group the villagers with suspicion $$$(1,9,12,4,7,2)$$$ into $$$(1),(9,12),(4,7,2)$$$. So, $$$f(1,1) + f(2,3) + f(4,6) = 0 + 3 + 8 = 11$$$.", "input": [ [ [ "4", "2" ], [ "1", "3", "5", "2" ] ], [ [ "6", "3" ], [ "1", "9", "12", "4", "7", "2" ] ], [ [ "12", "8" ], [ "1", "9", "8", "2", "3", "3", "1", "8", "7", "7", "9", "2" ] ] ], "output": [ "4", "11", "2" ] }, { "problem_id": "1846A", "problem_name": "Rudolph and Cut the Rope\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1846/A", "problem_solution_link": "https://codeforces.com/problemset/status/1846/problem/A", "problem_statement": "A. Rudolph and Cut the Rope\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ nails driven into the wall, the $$$i$$$-th nail is driven $$$a_i$$$ meters above the ground, one end of the $$$b_i$$$ meters long rope is tied to it. All nails hang at different heights one above the other. One candy is tied to all ropes at once. Candy is tied to end of a rope that is not tied to a nail.\nTo take the candy, you need to lower it to the ground. To do this, Rudolph can cut some ropes, one at a time. Help Rudolph find the minimum number of ropes that must be cut to get the candy.\nThe figure shows an example of the first test:\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains one integer $$$n$$$ ($$$1 \\le n \\le 50$$$)\u00a0\u2014 the number of nails.\nThe $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \\le a_i, b_i \\le 200$$$)\u00a0\u2014 the height of the $$$i$$$-th nail and the length of the rope tied to it, all $$$a_i$$$ are different.\nIt is guaranteed that the data is not contradictory, it is possible to build a configuration described in the statement.\nOutput\nFor each test case print one integer\u00a0\u2014 the minimum number of ropes that need to be cut to make the candy fall to the ground.\nExample\nInput\n4\n3\n4 3\n3 1\n1 2\n4\n9 2\n5 2\n7 7\n3 4\n5\n11 7\n5 10\n12 9\n3 2\n1 5\n3\n5 6\n4 5\n7 7\nOutput\n2\n2\n3\n0", "input": [ [ [ "3" ], [ "4", "3", "1", "2" ] ], [ [ "4" ], [ "9", "2", "5", "2", "7", "7", "3", "4" ] ], [ [ "5" ], [ "11", "7", "5", "10", "12", "9", "3", "2", "1", "5" ] ], [ [ "3" ], [ "5", "6", "4", "5", "7", "7" ] ] ], "output": [ "2", "2", "3", "0" ] }, { "problem_id": "1846B", "problem_name": "Rudolph and Tic-Tac-Toe\nbrute force, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1846/B", "problem_solution_link": "https://codeforces.com/problemset/status/1846/problem/B", "problem_statement": "B. Rudolph and Tic-Tac-Toe\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nRudolph invented the game of tic-tac-toe for three players. It has classic rules, except for the third player who plays with pluses. Rudolf has a $$$3 \\times 3$$$ field \u00a0\u2014 the result of the completed game. Each field cell contains either a cross, or a nought, or a plus sign, or nothing. The game is won by the player who makes a horizontal, vertical or diagonal row of $$$3$$$'s of their symbols.\nRudolph wants to find the result of the game. Either exactly one of the three players won or it ended in a draw. It is guaranteed that multiple players cannot win at the same time.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases.\nEach test case consists of three lines, each of which consists of three characters. The symbol can be one of four: \"X\" means a cross, \"O\" means a nought, \"+\" means a plus, \".\" means an empty cell.\nOutput\nFor each test case, print the string \"X\" if the crosses won, \"O\" if the noughts won, \"+\" if the pluses won, \"DRAW\" if there was a draw.\nExample\nInput\n5\n+X+\nOXO\nOX.\nO+.\n+OX\nX+O\n.XO\nOX.\n+++\nO.+\nX.O\n+..\n.++\nX.O\n+..\nOutput\nX\nO\n+\nDRAW\nDRAW", "input": [ [ [ "+X+" ], [ "OXO" ], [ "OX." ] ], [ [ "O+." ], [ "+OX" ], [ "X+O" ] ], [ [ ".XO" ], [ "OX." ], [ "+++" ] ], [ [ "O.+" ], [ "X.O" ], [ "+.." ] ], [ [ ".++" ], [ "X.O" ], [ "+.." ] ] ], "output": [ "X", "O", "+", "DRAW", "DRAW" ] }, { "problem_id": "1845A", "problem_name": "Forbidden Integer\nconstructive algorithms, implementation, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1845/A", "problem_solution_link": "https://codeforces.com/problemset/status/1845/problem/A", "problem_statement": "A. Forbidden Integer\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an integer $$$n$$$, which you want to obtain. You have an unlimited supply of every integer from $$$1$$$ to $$$k$$$, except integer $$$x$$$ (there are no integer $$$x$$$ at all).\nYou are allowed to take an arbitrary amount of each of these integers (possibly, zero). Can you make the sum of taken integers equal to $$$n$$$?\nIf there are multiple answers, print any of them.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of testcases.\nThe only line of each testcase contains three integers $$$n, k$$$ and $$$x$$$ ($$$1 \\le x \\le k \\le n \\le 100$$$).\nOutput\nFor each test case, in the first line, print \"\nYES\n\" or \"\nNO\n\"\u00a0\u2014 whether you can take an arbitrary amount of each integer from $$$1$$$ to $$$k$$$, except integer $$$x$$$, so that their sum is equal to $$$n$$$.\nIf you can, the second line should contain a single integer $$$m$$$\u00a0\u2014 the total amount of taken integers. The third line should contain $$$m$$$ integers\u00a0\u2014 each of them from $$$1$$$ to $$$k$$$, not equal to $$$x$$$, and their sum is $$$n$$$.\nIf there are multiple answers, print any of them.\nExample\nInput\n5\n10 3 2\n5 2 1\n4 2 1\n7 7 3\n6 1 1\nOutput\nYES\n6\n3 1 1 1 1 3\nNO\nYES\n2\n2 2\nYES\n1\n7\nNO\nNote\nAnother possible answer for the first testcase is $$$[3, 3, 3, 1]$$$. Note that you don't have to minimize the amount of taken integers. There also exist other answers.\nIn the second testcase, you only have an unlimited supply of integer $$$2$$$. There is no way to get sum $$$5$$$ using only them.\nIn the fifth testcase, there are no integers available at all, so you can't get any positive sum.", "input": [ [ [ "10", "3", "2" ] ], [ [ "5", "2", "1" ] ], [ [ "4", "2", "1" ] ], [ [ "7", "7", "3" ] ], [ [ "6", "1", "1" ] ] ], "output": [ ["YES", "6", "3 1 1 1 1 3"], ["NO"], ["YES", "2", "2 2"], ["YES", "1", "7"], ["NO"] ], "error": true }, { "problem_id": "1844A", "problem_name": "Subtraction Game\nconstructive algorithms, games", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1844/A", "problem_solution_link": "https://codeforces.com/problemset/status/1844/problem/A", "problem_statement": "A. Subtraction Game\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two positive integers, $$$a$$$ and $$$b$$$ ($$$a < b$$$).\nFor some positive integer $$$n$$$, two players will play a game starting with a pile of $$$n$$$ stones. They take turns removing exactly $$$a$$$ or exactly $$$b$$$ stones from the pile. The player who is unable to make a move loses.\nFind a positive integer $$$n$$$ such that the second player to move in this game has a winning strategy. This means that no matter what moves the first player makes, the second player can carefully choose their moves (possibly depending on the first player's moves) to ensure they win.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). The description of the test cases follows.\nThe only line of each test case contains two integers, $$$a$$$ and $$$b$$$ ($$$1 \\le a < b \\le 100$$$).\nOutput\nFor each test case, output any positive integer $$$n$$$ ($$$1 \\le n \\le 10^6$$$) such that the second player to move wins.\nIt can be proven that such an $$$n$$$ always exists under the constraints of the problem.\nExample\nInput\n3\n1 4\n1 5\n9 26\nOutput\n2\n6\n3\nNote\nIn the first test case, when $$$n = 2$$$, the first player must remove $$$a = 1$$$ stone. Then, the second player can respond by removing $$$a = 1$$$ stone. The first player can no longer make a move, so the second player wins.\nIn the second test case, when $$$n = 6$$$, the first player has two options:\nIf they remove $$$b = 5$$$ stones, then the second player can respond by removing $$$a = 1$$$ stone. The first player can no longer make a move, so the second player wins.\nIf they remove $$$a = 1$$$ stone, then the second player can respond by removing $$$a = 1$$$ stone. Afterwards, the players can only alternate removing exactly $$$a = 1$$$ stone. The second player will take the last stone and win.\nSince the second player has a winning strategy no matter what the first player does, this is an acceptable output.\nIn the third test case, the first player cannot make any moves when $$$n = 3$$$, so the second player immediately wins.", "input": [ [ [ "1", "4" ] ], [ [ "1", "5" ] ], [ [ "9", "26" ] ] ], "output": [ "2", "6", "3" ] }, { "problem_id": "1843C", "problem_name": "Sum in Binary Tree\nbitmasks, combinatorics, math, trees", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1843/C", "problem_solution_link": "https://codeforces.com/problemset/status/1843/problem/C", "problem_statement": "C. Sum in Binary Tree\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nVanya really likes math. One day when he was solving another math problem, he came up with an interesting tree. This tree is built as follows.\nInitially, the tree has only one vertex with the number $$$1$$$\u00a0\u2014 the root of the tree. Then, Vanya adds two children to it, assigning them consecutive numbers\u00a0\u2014 $$$2$$$ and $$$3$$$, respectively. After that, he will add children to the vertices in increasing order of their numbers, starting from $$$2$$$, assigning their children the minimum unused indices. As a result, Vanya will have an infinite tree with the root in the vertex $$$1$$$, where each vertex will have exactly two children, and the vertex numbers will be arranged sequentially by layers.\nPart of Vanya's tree.\nVanya wondered what the sum of the vertex numbers on the path from the vertex with number $$$1$$$ to the vertex with number $$$n$$$ in such a tree is equal to. Since Vanya doesn't like counting, he asked you to help him find this sum.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThis is followed by $$$t$$$ lines\u00a0\u2014 the description of the test cases. Each line contains one integer $$$n$$$ ($$$1 \\le n \\le 10^{16}$$$)\u00a0\u2014 the number of vertex for which Vanya wants to count the sum of vertex numbers on the path from the root to that vertex.\nOutput\nFor each test case, print one integer\u00a0\u2014 the desired sum.\nExample\nInput\n6\n3\n10\n37\n1\n10000000000000000\n15\nOutput\n4\n18\n71\n1\n19999999999999980\n26\nNote\nIn the first test case of example on the path from the root to the vertex $$$3$$$ there are two vertices $$$1$$$ and $$$3$$$, their sum equals $$$4$$$.\nIn the second test case of example on the path from the root to the vertex with number $$$10$$$ there are vertices $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, sum of their numbers equals $$$1+2+5+10 = 18$$$.", "input": [ [ [ "3" ] ], [ [ "10" ] ], [ [ "37" ] ], [ [ "1" ] ], [ [ "10000000000000000" ] ], [ [ "15" ] ] ], "output": [ "4", "18", "71", "1", "19999999999999980", "26" ] }, { "problem_id": "1843B", "problem_name": "Long Long\ngreedy, math, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1843/B", "problem_solution_link": "https://codeforces.com/problemset/status/1843/problem/B", "problem_statement": "B. Long Long\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nToday Alex was brought array $$$a_1, a_2, \\dots, a_n$$$ of length $$$n$$$. He can apply as many operations as he wants (including zero operations) to change the array elements.\nIn $$$1$$$ operation Alex can choose any $$$l$$$ and $$$r$$$ such that $$$1 \\leq l \\leq r \\leq n$$$, and multiply all elements of the array from $$$l$$$ to $$$r$$$ inclusive by $$$-1$$$. In other words, Alex can replace the subarray $$$[a_l, a_{l + 1}, \\dots, a_r]$$$ by $$$[-a_l, -a_{l + 1}, \\dots, -a_r]$$$ in $$$1$$$ operation.\nFor example, let $$$n = 5$$$, the array is $$$[1, -2, 0, 3, -1]$$$, $$$l = 2$$$ and $$$r = 4$$$, then after the operation the array will be $$$[1, 2, 0, -3, -1]$$$.\nAlex is late for school, so you should help him find the maximum possible sum of numbers in the array, which can be obtained by making any number of operations, as well as the minimum number of operations that must be done for this.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$)\u00a0\u2014 number of test cases. Then the descriptions of the test cases follow.\nThe first line of each test case contains one integer $$$n$$$ ($$$1 \\leq n \\leq 2 \\cdot 10^5$$$)\u00a0\u2014 length of the array.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$-10^9 \\leq a_i \\leq 10^9$$$)\u00a0\u2014 elements of the array.\nIt is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case output two space-separated numbers: the maximum possible sum of numbers in the array and the minimum number of operations to get this sum.\nPay attention that an answer may not fit in a standard integer type, so do not forget to use 64-bit integer type.\nExample\nInput\n5\n6\n-1 7 -4 -2 5 -8\n8\n-1 0 0 -2 1 0 -3 0\n5\n2 -1 0 -3 -7\n5\n0 -17 0 1 0\n4\n-1 0 -2 -1\nOutput\n27 3\n7 2\n13 1\n18 1\n4 1\nNote\nBelow, for each test case, only one of the possible shortest sequences of operations is provided among many. There are others that have the same length and lead to the maximum sum of elements.\nIn the first test case, Alex can make operations: $$$(1, 4)$$$, $$$(2, 2)$$$, $$$(6, 6)$$$.\nIn the second test case, to get the largest sum you need to make operations: $$$(1, 8)$$$, $$$(5, 6)$$$.\nIn the fourth test case, it is necessary to make only one operation: $$$(2, 3)$$$.", "input": [ [ [ "6" ], [ "-1", "7", "-4", "-2", "5", "-8" ] ], [ [ "8" ], [ "-1", "0", "0", "-2", "1", "0", "-3", "0" ] ], [ [ "5" ], [ "2", "-1", "0", "-3", "-7" ] ], [ [ "5" ], [ "0", "-17", "0", "1", "0" ] ], [ [ "4" ], [ "-1", "0", "-2", "-1" ] ] ], "output": [ "27 3", "7 2", "13 1", "18 1", "4 1" ] }, { "problem_id": "1843A", "problem_name": "Sasha and Array Coloring\ngreedy, sortings, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1843/A", "problem_solution_link": "https://codeforces.com/problemset/status/1843/problem/A", "problem_statement": "A. Sasha and Array Coloring\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nSasha found an array $$$a$$$ consisting of $$$n$$$ integers and asked you to paint elements.\nYou have to paint each element of the array. You can use as many colors as you want, but each element should be painted into exactly one color, and for each color, there should be at least one element of that color.\nThe\ncost\nof one color is the value of $$$\\max(S) - \\min(S)$$$, where $$$S$$$ is the sequence of elements of that color. The\ncost\nof the whole coloring is the\nsum\nof costs over all colors.\nFor example, suppose you have an array $$$a = [\\color{red}{1}, \\color{red}{5}, \\color{blue}{6}, \\color{blue}{3}, \\color{red}{4}]$$$, and you painted its elements into two colors as follows: elements on positions $$$1$$$, $$$2$$$ and $$$5$$$ have color $$$1$$$; elements on positions $$$3$$$ and $$$4$$$ have color $$$2$$$. Then:\nthe cost of the color $$$1$$$ is $$$\\max([1, 5, 4]) - \\min([1, 5, 4]) = 5 - 1 = 4$$$;\nthe cost of the color $$$2$$$ is $$$\\max([6, 3]) - \\min([6, 3]) = 6 - 3 = 3$$$;\nthe total cost of the coloring is $$$7$$$.\nFor the given array $$$a$$$, you have to calculate the\nmaximum\npossible cost of the coloring.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 50$$$)\u00a0\u2014 length of $$$a$$$.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\leq a_i \\leq 50$$$)\u00a0\u2014 array $$$a$$$.\nOutput\nFor each test case output the maximum possible cost of the coloring.\nExample\nInput\n6\n5\n1 5 6 3 4\n1\n5\n4\n1 6 3 9\n6\n1 13 9 3 7 2\n4\n2 2 2 2\n5\n4 5 2 2 3\nOutput\n7\n0\n11\n23\n0\n5\nNote\nIn the first example one of the optimal coloring is $$$[\\color{red}{1}, \\color{red}{5}, \\color{blue}{6}, \\color{blue}{3}, \\color{red}{4}]$$$. The answer is $$$(5 - 1) + (6 - 3) = 7$$$.\nIn the second example, the only possible coloring is $$$[\\color{blue}{5}]$$$, for which the answer is $$$5 - 5 = 0$$$.\nIn the third example, the optimal coloring is $$$[\\color{blue}{1}, \\color{red}{6}, \\color{red}{3}, \\color{blue}{9}]$$$, the answer is $$$(9 - 1) + (6 - 3) = 11$$$.", "input": [ [ [ "5" ], [ "1", "5", "6", "3", "4" ] ], [ [ "1" ], [ "5" ] ], [ [ "4" ], [ "1", "6", "3", "9" ] ], [ [ "6" ], [ "1", "13", "9", "3", "7", "2" ] ], [ [ "4" ], [ "2", "2", "2", "2" ] ], [ [ "5" ], [ "4", "5", "2", "2", "3" ] ] ], "output": [ "7", "0", "11", "23", "0", "5" ] }, { "problem_id": "1842A", "problem_name": "Tenzing and Tsondu\ngames, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1842/A", "problem_solution_link": "https://codeforces.com/problemset/status/1842/problem/A", "problem_statement": "A. Tenzing and Tsondu\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTsondu always runs first! ! !\nTsondu and Tenzing are playing a card game. Tsondu has $$$n$$$ monsters with ability values $$$a_1, a_2, \\ldots, a_n$$$ while Tenzing has $$$m$$$ monsters with ability values $$$b_1, b_2, \\ldots, b_m$$$.\nTsondu and Tenzing take turns making moves, with Tsondu going first. In each move, the current player chooses two monsters: one on their side and one on the other side. Then, these monsters will fight each other. Suppose the ability values for the chosen monsters are $$$x$$$ and $$$y$$$ respectively, then the ability values of the monsters will become $$$x-y$$$ and $$$y-x$$$ respectively. If the ability value of any monster is smaller than or equal to $$$0$$$, the monster dies.\nThe game ends when at least one player has no monsters left alive. The winner is the player with at least one monster left alive. If both players have no monsters left alive, the game ends in a draw.\nFind the result of the game when both players play optimally.\nInput\nEach test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \\le t \\le 2 \\cdot 10^3$$$)\u00a0\u2014 the number of test cases. The description of test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\leq n,m \\leq 50$$$)\u00a0\u2014 the number of monsters Tsondu and Tenzing have respectively.\nThe second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\\ldots,a_n$$$ $$$(1 \\leq a_i \\leq 10^9$$$)\u00a0\u2014 the ability values of Tsondu's monsters.\nThe third line of each test case contains $$$m$$$ integers $$$b_1,b_2,\\ldots,b_m$$$ $$$(1 \\leq b_i \\leq 10^9$$$)\u00a0\u2014 the ability values of Tenzing's monsters.\nOutput\nFor each test case, output \"\nTsondu\n\" if Tsondu wins, \"\nTenzing\n\" if Tenzing wins, and \"\nDraw\n\" if the game ends in a draw. (Output without quotes.)\nNote that the output is case-sensitive. For example, if the answer is \"\nTsondu\n\", the outputs \"\ntsondu\n\", \"\nTSONDU\n\", and \"\ntSonDu\n\" will all be recognized as\nincorrect\noutputs.\nExample\nInput\n6\n1 3\n9\n1 2 3\n2 3\n1 2\n1 1 1\n3 2\n1 2 3\n1 1\n3 3\n1 1 1\n2 2 2\n10 10\n1 2 3 3 2 2 1 1 2 2\n3 3 3 3 2 1 1 1 1 1\n10 10\n1 2 3 4 5 6 7 8 9 10\n6 7 8 9 10 11 1 1 1 1\nOutput\nTsondu\nDraw\nTsondu\nTenzing\nDraw\nDraw\nNote\nConsider the first test case. It can be shown that Tsondu has a winning strategy. The following is a possible way that Tsondu can win (note that the players may not be playing optimally in this example):\nIn the first move, Tsondu chooses a monster with ability value $$$9$$$ on his side to fight against a monster with ability value $$$1$$$ on Tenzing's side, the ability value of both monsters become $$$8$$$ and $$$-8$$$ respectively. The monster with ability value $$$-8$$$ on Tenzing's side dies.\nIn the second move, Tenzing chooses a monster with ability value $$$2$$$ on his side to fight against a monster with ability value $$$8$$$ on Tsondu's side, the ability value of both monsters become $$$-6$$$ and $$$6$$$ respectively. The monster with ability value $$$-6$$$ on Tenzing's side dies.\nIn the third move, Tsondu chooses a monster with ability value $$$6$$$ on his side to fight against a monster with ability value $$$3$$$ onTenzing's side, the ability value of both monsters become $$$3$$$ and $$$-3$$$ respectively. The monster with ability value $$$-3$$$ on Tenzing's side dies.\nNow, Tenzing has no monsters left alive. Since Tsondu still has monsters left alive, Tsondu wins.", "input": [ [ [ "1", "3" ], [ "9" ], [ "1", "2", "3" ] ], [ [ "2", "3" ], [ "1", "2" ], [ "1", "1", "1" ] ], [ [ "3", "2" ], [ "1", "2", "3" ], [ "1", "1" ] ], [ [ "3", "3" ], [ "1", "1", "1" ], [ "2", "2", "2" ] ], [ [ "10", "10" ], [ "1", "2", "3", "3", "2", "2", "1", "1", "2", "2" ], [ "3", "3", "3", "3", "2", "1", "1", "1", "1", "1" ] ], [ [ "10", "10" ], [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ], [ "6", "7", "8", "9", "10", "11", "1", "1", "1", "1" ] ] ], "output": [ "Tsondu", "Draw", "Tsondu", "Tenzing", "Draw", "Draw" ] }, { "problem_id": "1841A", "problem_name": "Game with Board\nconstructive algorithms, games", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1841/A", "problem_solution_link": "https://codeforces.com/problemset/status/1841/problem/A", "problem_statement": "A. Game with Board\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nAlice and Bob play a game. They have a blackboard; initially, there are $$$n$$$ integers written on it, and each integer is equal to $$$1$$$.\nAlice and Bob take turns; Alice goes first. On their turn, the player has to choose several (\nat least two\n)\nequal\nintegers on the board, wipe them and write a new integer which is equal to their sum.\nFor example, if the board currently contains integers $$$\\{1, 1, 2, 2, 2, 3\\}$$$, then the following moves are possible:\nchoose two integers equal to $$$1$$$, wipe them and write an integer $$$2$$$, then the board becomes $$$\\{2, 2, 2, 2, 3\\}$$$;\nchoose two integers equal to $$$2$$$, wipe them and write an integer $$$4$$$, then the board becomes $$$\\{1, 1, 2, 3, 4\\}$$$;\nchoose three integers equal to $$$2$$$, wipe them and write an integer $$$6$$$, then the board becomes $$$\\{1, 1, 3, 6\\}$$$.\nIf a player cannot make a move (all integers on the board are different), that player\nwins the game\n.\nDetermine who wins if both players play optimally.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 99$$$) \u2014 the number of test cases.\nEach test case consists of one line containing one integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the number of integers equal to $$$1$$$ on the board.\nOutput\nFor each test case, print\nAlice\nif Alice wins when both players play optimally. Otherwise, print\nBob\n.\nExample\nInput\n2\n3\n6\nOutput\nBob\nAlice\nNote\nIn the first test case, $$$n = 3$$$, so the board initially contains integers $$$\\{1, 1, 1\\}$$$. We can show that Bob can always win as follows: there are two possible first moves for Alice.\nif Alice chooses two integers equal to $$$1$$$, wipes them and writes $$$2$$$, the board becomes $$$\\{1, 2\\}$$$. Bob cannot make a move, so he wins;\nif Alice chooses three integers equal to $$$1$$$, wipes them and writes $$$3$$$, the board becomes $$$\\{3\\}$$$. Bob cannot make a move, so he wins.\nIn the second test case, $$$n = 6$$$, so the board initially contains integers $$$\\{1, 1, 1, 1, 1, 1\\}$$$. Alice can win by, for example, choosing two integers equal to $$$1$$$, wiping them and writing $$$2$$$ on the first turn. Then the board becomes $$$\\{1, 1, 1, 1, 2\\}$$$, and there are three possible responses for Bob:\nif Bob chooses four integers equal to $$$1$$$, wipes them and writes $$$4$$$, the board becomes $$$\\{2,4\\}$$$. Alice cannot make a move, so she wins;\nif Bob chooses three integers equal to $$$1$$$, wipes them and writes $$$3$$$, the board becomes $$$\\{1,2,3\\}$$$. Alice cannot make a move, so she wins;\nif Bob chooses two integers equal to $$$1$$$, wipes them and writes $$$2$$$, the board becomes $$$\\{1, 1, 2, 2\\}$$$. Alice can continue by, for example, choosing two integers equal to $$$2$$$, wiping them and writing $$$4$$$. Then the board becomes $$$\\{1,1,4\\}$$$. The only possible response for Bob is to choose two integers equal to $$$1$$$ and write $$$2$$$ instead of them; then the board becomes $$$\\{2,4\\}$$$, Alice cannot make a move, so she wins.", "input": [ [ [ "3" ] ], [ [ "6" ] ] ], "output": [ "Bob", "Alice" ] }, { "problem_id": "1840A", "problem_name": "Cipher Shifer\nimplementation, strings, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1840/A", "problem_solution_link": "https://codeforces.com/problemset/status/1840/problem/A", "problem_statement": "A. Cipher Shifer\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a string $$$a$$$ (unknown to you), consisting of lowercase Latin letters, encrypted according to the following rule into string $$$s$$$:\nafter each character of string $$$a$$$, an arbitrary (possibly zero) number of any lowercase Latin letters, different from the character itself, is added;\nafter each such addition, the character that we supplemented is added.\nYou are given string $$$s$$$, and you need to output the initial string $$$a$$$. In other words, you need to decrypt string $$$s$$$.\nNote that each string encrypted in this way is decrypted\nuniquely\n.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases.\nThe descriptions of the test cases follow.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 100$$$)\u00a0\u2014 the length of the encrypted message.\nThe second line of each test case contains a string $$$s$$$ of length $$$n$$$\u00a0\u2014 the encrypted message obtained from some string $$$a$$$.\nOutput\nFor each test case, output the decrypted message $$$a$$$ on a separate line.\nExample\nInput\n3\n8\nabacabac\n5\nqzxcq\n20\nccooddeeffoorrcceess\nOutput\nac\nq\ncodeforces\nNote\nIn the first encrypted message, the letter $$$a$$$ is encrypted as $$$aba$$$, and the letter $$$c$$$ is encrypted as $$$cabac$$$.\nIn the second encrypted message, only one letter $$$q$$$ is encrypted as $$$qzxcq$$$.\nIn the third encrypted message, zero characters are added to each letter.", "input": [ [ [ "8" ], [ "abacabac" ] ], [ [ "5" ], [ "qzxcq" ] ], [ [ "20" ], [ "ccooddeeffoorrcceess" ] ] ], "output": [ "ac", "q", "codeforces" ] }, { "problem_id": "1839A", "problem_name": "The Good Array\ngreedy, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1839/A", "problem_solution_link": "https://codeforces.com/problemset/status/1839/problem/A", "problem_statement": "A. The Good Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two integers $$$n$$$ and $$$k$$$.\nAn array $$$a_1, a_2, \\ldots, a_n$$$ of length $$$n$$$, consisting of zeroes and ones is\ngood\nif for\nall\nintegers $$$i$$$ from $$$1$$$ to $$$n$$$\nboth\nof the following conditions are satisfied:\nat least $$$\\lceil \\frac{i}{k} \\rceil$$$ of the first $$$i$$$ elements of $$$a$$$ are equal to $$$1$$$,\nat least $$$\\lceil \\frac{i}{k} \\rceil$$$ of the last $$$i$$$ elements of $$$a$$$ are equal to $$$1$$$.\nHere, $$$\\lceil \\frac{i}{k} \\rceil$$$ denotes the result of division of $$$i$$$ by $$$k$$$, rounded up. For example, $$$\\lceil \\frac{6}{3} \\rceil = 2$$$, $$$\\lceil \\frac{11}{5} \\rceil = \\lceil 2.2 \\rceil = 3$$$ and $$$\\lceil \\frac{7}{4} \\rceil = \\lceil 1.75 \\rceil = 2$$$.\nFind the minimum possible number of ones in a good array.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe only line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$2 \\le n \\le 100$$$, $$$1 \\le k \\le n$$$)\u00a0\u2014 the length of array and parameter $$$k$$$ from the statement.\nOutput\nFor each test case output one integer\u00a0\u2014 the minimum possible number of ones in a good array.\nIt can be shown that under the given constraints at least one good array always exists.\nExample\nInput\n7\n3 2\n5 2\n9 3\n7 1\n10 4\n9 5\n8 8\nOutput\n2\n3\n4\n7\n4\n3\n2\nNote\nIn the first test case, $$$n = 3$$$ and $$$k = 2$$$:\nArray $$$[ \\, 1, 0, 1 \\, ]$$$ is good and the number of ones in it is $$$2$$$.\nArrays $$$[ \\, 0, 0, 0 \\, ]$$$, $$$[ \\, 0, 1, 0 \\, ]$$$ and $$$[ \\, 0, 0, 1 \\, ]$$$ are not good since for $$$i=1$$$ the first condition from the statement is not satisfied.\nArray $$$[ \\, 1, 0, 0 \\, ]$$$ is not good since for $$$i=1$$$ the second condition from the statement is not satisfied.\nAll other arrays of length $$$3$$$ contain at least $$$2$$$ ones.\nThus, the answer is $$$2$$$.\nIn the second test case, $$$n = 5$$$ and $$$k = 2$$$:\nArray $$$[ \\, 1, 1, 0, 0, 1 \\, ]$$$ is not good since for $$$i=3$$$ the second condition is not satisfied.\nArray $$$[ \\, 1, 0, 1, 0, 1 \\, ]$$$ is good and the number of ones in it is $$$3$$$.\nIt can be shown that there is no good array with less than $$$3$$$ ones, so the answer is $$$3$$$.\nIn the third test case, $$$n = 9$$$ and $$$k = 3$$$:\nArray $$$[ \\, 1, 0, 1, 0, 0, 0, 1, 0, 1 \\, ]$$$ is good and the number of ones in it is $$$4$$$.\nIt can be shown that there is no good array with less than $$$4$$$ ones, so the answer is $$$4$$$.\nIn the fourth test case, $$$n = 7$$$ and $$$k = 1$$$. The only good array is $$$[ \\, 1, 1, 1, 1, 1, 1, 1\\, ]$$$, so the answer is $$$7$$$.", "input": [ [ [ "3", "2" ] ], [ [ "5", "2" ] ], [ [ "9", "3" ] ], [ [ "7", "1" ] ], [ [ "10", "4" ] ], [ [ "9", "5" ] ], [ [ "8", "8" ] ] ], "output": [ "2", "3", "4", "7", "4", "3", "2" ] }, { "problem_id": "1838A", "problem_name": "Blackboard List\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1838/A", "problem_solution_link": "https://codeforces.com/problemset/status/1838/problem/A", "problem_statement": "A. Blackboard List\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTwo integers were written on a blackboard. After that, the following step was carried out $$$n-2$$$ times:\nSelect any two integers on the board, and write the absolute value of their difference on the board.\nAfter this process was complete, the list of $$$n$$$ integers was shuffled. You are given the final list. Recover\none\nof the initial two numbers. You do\nnot\nneed to recover the other one.\nYou are guaranteed that the input can be generated using the above process.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$3 \\le n \\le 100$$$)\u00a0\u2014 the size of the final list.\nThe next line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots a_n$$$ ($$$-10^9 \\le a_i \\le 10^9$$$)\u00a0\u2014 the shuffled list of numbers written on the blackboard.\nIt is guaranteed that the input was generated using the process described above.\nOutput\nFor each test case, output a single integer $$$x$$$\u00a0\u2014 one of the two initial numbers on the blackboard.\nIf there are multiple solutions, print any of them.\nExample\nInput\n9\n3\n9 2 7\n3\n15 -4 11\n4\n-9 1 11 -10\n5\n3 0 0 0 3\n7\n8 16 8 0 8 16 8\n4\n0 0 0 0\n10\n27 1 24 28 2 -1 26 25 28 27\n6\n600000000 800000000 0 -200000000 1000000000 800000000\n3\n0 -1000000000 1000000000\nOutput\n9\n11\n-9\n3\n8\n0\n-1\n600000000\n0\nNote\nFor the first test case, $$$a$$$ can be produced by starting with either $$$9$$$ and $$$2$$$, and then writing down $$$|9-2|=7$$$, or starting with $$$9$$$ and $$$7$$$ and writing down $$$|9-7|=2$$$. So $$$2$$$, $$$7$$$, and $$$9$$$ are all valid answers, because they all appear in at least one valid pair.\nFor the second test case, we can show that the two initial numbers must have been $$$-4$$$ and $$$11$$$.\nFor the fourth test case, the starting numbers could have been either $$$3$$$ and $$$3$$$, or $$$3$$$ and $$$0$$$, so $$$3$$$ and $$$0$$$ are both valid answers.\nFor the fifth test case, we can show that the starting numbers were $$$8$$$ and $$$16$$$.", "input": [ [ [ "3" ], [ "9", "2", "7" ] ], [ [ "3" ], [ "15", "-4", "11" ] ], [ [ "4" ], [ "-9", "1", "11", "-10" ] ], [ [ "5" ], [ "3", "0", "0", "0", "3" ] ], [ [ "7" ], [ "8", "16", "8", "0", "8", "16", "8" ] ], [ [ "4" ], [ "0", "0", "0", "0" ] ], [ [ "10" ], [ "27", "1", "24", "28", "2", "-1", "26", "25", "28", "27" ] ], [ [ "6" ], [ "600000000", "800000000", "0", "-200000000", "1000000000", "800000000" ] ], [ [ "3" ], [ "0", "-1000000000", "1000000000" ] ] ], "output": [ "9", "11", "-9", "3", "8", "0", "-1", "600000000", "0" ] }, { "problem_id": "1837A", "problem_name": "Grasshopper on a Line\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1837/A", "problem_solution_link": "https://codeforces.com/problemset/status/1837/problem/A", "problem_statement": "A. Grasshopper on a Line\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two integers $$$x$$$ and $$$k$$$. Grasshopper starts in a point $$$0$$$ on an OX axis. In one move, it can jump some integer distance,\nthat is not divisible by $$$k$$$\n, to the left or to the right.\nWhat's the smallest number of moves it takes the grasshopper to reach point $$$x$$$? What are these moves? If there are multiple answers, print any of them.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of testcases.\nThe only line of each testcase contains two integers $$$x$$$ and $$$k$$$ ($$$1 \\le x \\le 100$$$; $$$2 \\le k \\le 100$$$)\u00a0\u2014 the endpoint and the constraint on the jumps, respectively.\nOutput\nFor each testcase, in the first line, print a single integer $$$n$$$\u00a0\u2014 the smallest number of moves it takes the grasshopper to reach point $$$x$$$.\nIn the second line, print $$$n$$$ integers, each of them not divisible by $$$k$$$. A positive integer would mean jumping to the right, a negative integer would mean jumping to the left. The endpoint after the jumps should be exactly $$$x$$$.\nEach jump distance should be from $$$-10^9$$$ to $$$10^9$$$. In can be shown that, for any solution with the smallest number of jumps, there exists a solution with the same number of jumps such that each jump is from $$$-10^9$$$ to $$$10^9$$$.\nIt can be shown that the answer always exists under the given constraints. If there are multiple answers, print any of them.\nExample\nInput\n3\n10 2\n10 3\n3 4\nOutput\n2\n7 3\n1\n10\n1\n3", "input": [ [ [ "10", "2" ] ], [ [ "10", "3" ] ], [ [ "3", "4" ] ] ], "output": [ ["2", "7 3"], ["1", "10"], ["1", "3"] ], "error": true }, { "problem_id": "1836A", "problem_name": "Destroyer\nimplementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1836/A", "problem_solution_link": "https://codeforces.com/problemset/status/1836/problem/A", "problem_statement": "A. Destroyer\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nJohn is a lead programmer on a destroyer belonging to the space navy of the Confederacy of Independent Operating Systems. One of his tasks is checking if the electronic brains of robots were damaged during battles.\nA standard test is to order the robots to form one or several lines, in each line the robots should stand one after another. After that, each robot reports the number of robots standing in front of it\nin its line\n.\nAn example of robots' arrangement (the front of the lines is on the left). The robots report the numbers above.\nThe $$$i$$$-th robot reported number $$$l_i$$$. Unfortunately, John does not know which line each robot stands in, and can't check the reported numbers. Please determine if it is possible to form the lines in such a way that all reported numbers are correct, or not.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$), denoting the number of test cases.\nThe first line in each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the number of robots.\nThe second line in each test case contains $$$n$$$ integers $$$l_1, l_2, \\ldots, l_n$$$ ($$$0 \\leq l_i < 100$$$), $$$l_i$$$ is equal to the number of robots in front of the $$$i$$$-th robot in its line.\nThe sum of $$$n$$$ over all test cases won't exceed $$$200$$$.\nOutput\nFor each test case, output \"\nYES\n\", if there exists a robot arrangement consistent with robots' reports. Otherwise, output \"\nNO\n\".\nYou can output the answer in any case (upper or lower). For example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\", and \"\nYES\n\" will be recognized as positive responses.\nExample\nInput\n5\n6\n0 1 2 0 1 0\n9\n0 0 0 0 1 1 1 2 2\n3\n0 0 2\n1\n99\n5\n0 1 2 3 4\nOutput\nYES\nYES\nNO\nNO\nYES\nNote\nExample arrangement consistent with robot statements from the first example test case:\nExample arrangement consistent with robot statements from the second example is shown in the statement.\nIn the third test case, the third robot claims that there are two machines in front of it. In such a case, the robot directly in front of it would have one machine in front. No robot claims that, so there is no valid arrangement.", "input": [ [ [ "6" ], [ "0", "1", "2", "0", "1", "0" ] ], [ [ "9" ], [ "0", "0", "0", "0", "1", "1", "1", "2", "2" ] ], [ [ "3" ], [ "0", "0", "2" ] ], [ [ "1" ], [ "99" ] ], [ [ "5" ], [ "0", "1", "2", "3", "4" ] ] ], "output": [ "YES", "YES", "NO", "NO", "YES" ] }, { "problem_id": "1834A", "problem_name": "Unit Array\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1834/A", "problem_solution_link": "https://codeforces.com/problemset/status/1834/problem/A", "problem_statement": "A. Unit Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven an array $$$a$$$ of length $$$n$$$, which elements are equal to $$$-1$$$ and $$$1$$$. Let's call the array $$$a$$$\ngood\nif the following conditions are held at the same time:\n$$$a_1 + a_2 + \\ldots + a_n \\ge 0$$$;\n$$$a_1 \\cdot a_2 \\cdot \\ldots \\cdot a_n = 1$$$.\nIn one operation, you can select an arbitrary element of the array $$$a_i$$$ and change its value to the opposite. In other words, if $$$a_i = -1$$$, you can assign the value to $$$a_i := 1$$$, and if $$$a_i = 1$$$, then assign the value to $$$a_i := -1$$$.\nDetermine the minimum number of operations you need to perform to make the array $$$a$$$ good. It can be shown that this is always possible.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 500$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the length of the array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$a_i = \\pm 1$$$) \u2014 the elements of the array $$$a$$$.\nOutput\nFor each test case, output a single integer \u2014 the minimum number of operations that need to be done to make the $$$a$$$ array good.\nExample\nInput\n7\n4\n-1 -1 1 -1\n5\n-1 -1 -1 1 1\n4\n-1 1 -1 1\n3\n-1 -1 -1\n5\n1 1 1 1 1\n1\n-1\n2\n-1 -1\nOutput\n1\n1\n0\n3\n0\n1\n2\nNote\nIn the first test case, we can assign the value $$$a_1 := 1$$$. Then $$$a_1 + a_2 + a_3 + a_4 = 1 + (-1) + 1 + (-1) = 0 \\ge 0$$$ and $$$a_1 \\cdot a_2 \\cdot a_3 \\cdot a_4 = 1 \\cdot (-1) \\cdot 1 \\cdot (-1) = 1$$$. Thus, we performed $$$1$$$ operation.\nIn the second test case, we can assign $$$a_1 := 1$$$. Then $$$a_1 + a_2 + a_3 + a_4 + a_5 = 1 + (-1) + (-1) + 1 + 1 = 1 \\ge 0$$$ and $$$a_1 \\cdot a_2 \\cdot a_3 \\cdot a_4 \\cdot a_5 = 1 \\cdot (-1) \\cdot (-1) \\cdot 1 \\cdot 1 = 1$$$. Thus, we performed $$$1$$$ operation.\nIn the third test case, $$$a_1 + a_2 + a_3 + a_4 = (-1) + 1 + (-1) + 1 = 0 \\ge 0$$$ and $$$a_1 \\cdot a_2 \\cdot a_3 \\cdot a_4 = (-1) \\cdot 1 \\cdot (-1) \\cdot 1 = 1$$$. Thus, all conditions are already satisfied and no operations are needed.\nIn the fourth test case, we can assign the values $$$a_1 := 1, a_2 := 1, a_3 := 1$$$. Then $$$a_1 + a_2 + a_3 = 1 + 1 + 1 = 3 \\ge 0$$$ and $$$a_1 \\cdot a_2 \\cdot a_3 = 1 \\cdot 1 \\cdot 1 = 1$$$. Thus, we performed $$$3$$$ operations.", "input": [ [ [ "4" ], [ "-1", "-1", "1", "-1" ] ], [ [ "5" ], [ "-1", "-1", "-1", "1", "1" ] ], [ [ "4" ], [ "-1", "1", "-1", "1" ] ], [ [ "3" ], [ "-1", "-1", "-1" ] ], [ [ "5" ], [ "1", "1", "1", "1", "1" ] ], [ [ "1" ], [ "-1" ] ], [ [ "2" ], [ "-1", "-1" ] ] ], "output": [ "1", "1", "0", "3", "0", "1", "2" ] }, { "problem_id": "1833C", "problem_name": "Vlad Building Beautiful Array\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1833/C", "problem_solution_link": "https://codeforces.com/problemset/status/1833/problem/C", "problem_statement": "C. Vlad Building Beautiful Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nVlad was given an array $$$a$$$ of $$$n$$$ positive integers. Now he wants to build a\nbeautiful\narray $$$b$$$ of length $$$n$$$ from it.\nVlad considers an array\nbeautiful\nif all the numbers in it are positive and have the same parity. That is, all numbers in the\nbeautiful\narray are\ngreater\nthan zero and are either all even or all odd.\nTo build the array $$$b$$$, Vlad can assign each $$$b_i$$$ either the value $$$a_i$$$ or $$$a_i - a_j$$$, where any $$$j$$$ from $$$1$$$ to $$$n$$$ can be chosen.\nTo avoid trying to do the impossible, Vlad asks you to determine whether it is possible to build a\nbeautiful\narray $$$b$$$ of length $$$n$$$ using his array $$$a$$$.\nInput\nThe first line of input contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThen follow the descriptions of the test cases.\nThe first line of each case contains a single integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe second line of each case contains $$$n$$$ positive integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$)\u00a0\u2014 the elements of the array $$$a$$$.\nIt is guaranteed that the sum of $$$n$$$ over all cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nOutput $$$t$$$ strings, each of which is the answer to the corresponding test case. As the answer, output \"\nYES\n\" if Vlad can build a\nbeautiful\narray $$$b$$$, and \"\nNO\n\" otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n7\n5\n2 6 8 4 3\n5\n1 4 7 6 9\n4\n2 6 4 10\n7\n5 29 13 9 10000001 11 3\n5\n2 1 2 4 2\n5\n2 4 5 4 3\n4\n2 5 5 4\nOutput\nNO\nYES\nYES\nYES\nYES\nNO\nNO", "input": [ [ [ "5" ], [ "2", "6", "8", "4", "3" ] ], [ [ "5" ], [ "1", "4", "7", "6", "9" ] ], [ [ "4" ], [ "2", "6", "4", "10" ] ], [ [ "7" ], [ "5", "29", "13", "9", "10000001", "11", "3" ] ], [ [ "5" ], [ "2", "1", "2", "4", "2" ] ], [ [ "5" ], [ "2", "4", "5", "4", "3" ] ], [ [ "4" ], [ "2", "5", "5", "4" ] ] ], "output": [ "NO", "YES", "YES", "YES", "YES", "NO", "NO" ] }, { "problem_id": "1833A", "problem_name": "Musical Puzzle\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1833/A", "problem_solution_link": "https://codeforces.com/problemset/status/1833/problem/A", "problem_statement": "A. Musical Puzzle\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nVlad decided to compose a melody on his guitar. Let's represent the melody as a sequence of notes corresponding to the characters 'a', 'b', 'c', 'd', 'e', 'f', and 'g'.\nHowever, Vlad is not very experienced in playing the guitar and can only record\nexactly two\nnotes at a time. Vlad wants to obtain the melody $$$s$$$, and to do this, he can merge the recorded melodies together. In this case, the last sound of the first melody must match the first sound of the second melody.\nFor example, if Vlad recorded the melodies\n\"ab\"\nand\n\"ba\"\n, he can merge them together and obtain the melody\n\"aba\"\n, and then merge the result with\n\"ab\"\nto get\n\"abab\"\n.\nHelp Vlad determine the\nminimum\nnumber of melodies consisting of two notes that he needs to record in order to obtain the melody $$$s$$$.\nInput\nThe first line of input contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nFollowing that are the descriptions of the test cases.\nThe first line of each test case contains an integer $$$n$$$ ($$$2 \\le n \\le 50$$$)\u00a0\u2014 the length of the melody $$$s$$$.\nThe second line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of characters 'a', 'b', 'c', 'd', 'e', 'f', 'g'.\nOutput\nOutput $$$t$$$ integers, each representing the answer for the corresponding test case. As the answer output\nminimum\nnumber of melodies consisting of two notes that Vlad needs to record.\nExample\nInput\n5\n4\nabab\n7\nabacaba\n6\naaaaaa\n7\nabcdefg\n5\nbabdd\nOutput\n2\n4\n1\n6\n4\nNote\nIn the first sample, you need to record the melodies\n\"ab\"\nand\n\"ba\"\n, as described in the problem statement.\nIn the second sample, you need to record the melodies\n\"ab\"\n,\n\"ba\"\n,\n\"ac\"\n, and\n\"ca\"\n.\nIn the third sample, the only necessary melody is\n\"aa\"\n.", "input": [ [ [ "4" ], [ "abab" ] ], [ [ "7" ], [ "abacaba" ] ], [ [ "6" ], [ "aaaaaa" ] ], [ [ "7" ], [ "abcdefg" ] ], [ [ "5" ], [ "babdd" ] ] ], "output": [ "2", "4", "1", "6", "4" ] }, { "problem_id": "1832A", "problem_name": "New Palindrome\nstrings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1832/A", "problem_solution_link": "https://codeforces.com/problemset/status/1832/problem/A", "problem_statement": "A. New Palindrome\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA palindrome is a string that reads the same from left to right as from right to left. For example,\nabacaba\n,\naaaa\n,\nabba\n,\nracecar\nare palindromes.\nYou are given a string $$$s$$$ consisting of lowercase Latin letters. The string $$$s$$$ is a palindrome.\nYou have to check whether it is possible to rearrange the letters in it to get\nanother\npalindrome (not equal to the given string $$$s$$$).\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases.\nThe only line of each test case contains a string $$$s$$$ ($$$2 \\le |s| \\le 50$$$) consisting of lowercase Latin letters. This string is a palindrome.\nOutput\nFor each test case, print\nYES\nif it is possible to rearrange the letters in the given string to get\nanother\npalindrome. Otherwise, print\nNO\n.\nYou may print each letter in any case (\nYES\n,\nyes\n,\nYes\nwill all be recognized as positive answer,\nNO\n,\nno\nand\nnO\nwill all be recognized as negative answer).\nExample\nInput\n3\ncodedoc\ngg\naabaa\nOutput\nYES\nNO\nNO\nNote\nIn the first test case, it is possible to rearrange the letters in the palindrome\ncodedoc\nto obtain the string\nocdedco\n, which is different from the given string, but also a palindrome.", "input": [ [ [ "codedoc" ] ], [ [ "gg" ] ], [ [ "aabaa" ] ] ], "output": [ "YES", "NO", "NO" ] }, { "problem_id": "1831A", "problem_name": "Twin Permutations\nconstructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1831/A", "problem_solution_link": "https://codeforces.com/problemset/status/1831/problem/A", "problem_statement": "A. Twin Permutations\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a permutation$$$^\\dagger$$$ $$$a$$$ of length $$$n$$$.\nFind any permutation $$$b$$$ of length $$$n$$$ such that $$$a_1+b_1 \\le a_2+b_2 \\le a_3+b_3 \\le \\ldots \\le a_n+b_n$$$.\nIt can be proven that a permutation $$$b$$$ that satisfies the condition above always exists.\n$$$^\\dagger$$$ A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).\nInput\nEach test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \\le t \\le 2000$$$)\u00a0\u2014 the number of test cases. The description of test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the length of permutations $$$a$$$ and $$$b$$$.\nThe second line of each test case contains $$$n$$$ distinct integers $$$a_1,a_2,\\ldots,a_n$$$ ($$$1 \\le a_i \\le n$$$)\u00a0\u2014 the elements of permutation $$$a$$$. All elements of $$$a$$$ are distinct.\nNote that there is no bound on the sum of $$$n$$$ over all test cases.\nOutput\nFor each test case, output\nany\npermutation $$$b$$$ which satisfies the constraints mentioned in the statement. It can be proven that a permutation $$$b$$$ that satisfies the condition above always exists.\nExample\nInput\n5\n5\n1 2 4 5 3\n2\n1 2\n1\n1\n3\n3 2 1\n4\n1 4 3 2\nOutput\n1 2 4 3 5\n2 1\n1\n1 2 3\n1 2 3 4\nNote\nIn the first test case $$$a=[1, 2, 4, 5, 3]$$$. Then the permutation $$$b=[1, 2, 4, 3, 5]$$$ satisfies the condition because $$$1 + 1 \\le 2 + 2 \\le 4 + 4 \\le 5 + 3 \\le 3 + 5$$$.", "input": [ [ [ "5" ], [ "1", "2", "4", "5", "3" ] ], [ [ "2" ], [ "1", "2" ] ], [ [ "1" ], [ "1" ] ], [ [ "3" ], [ "3", "2", "1" ] ], [ [ "4" ], [ "1", "4", "3", "2" ] ] ], "output": [ "1 2 4 3 5", "2 1", "1", "1 2 3", "1 2 3 4" ] }, { "problem_id": "1829B", "problem_name": "Blank Space\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1829/B", "problem_solution_link": "https://codeforces.com/problemset/status/1829/problem/B", "problem_statement": "B. Blank Space\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a binary array $$$a$$$ of $$$n$$$ elements, a binary array is an array consisting only of $$$0$$$s and $$$1$$$s.\nA blank space is a segment of\nconsecutive\nelements consisting of only $$$0$$$s.\nYour task is to find the length of the longest blank space.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the length of the array.\nThe second line of each test case contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$0 \\leq a_i \\leq 1$$$)\u00a0\u2014 the elements of the array.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the length of the longest blank space.\nExample\nInput\n5\n5\n1 0 0 1 0\n4\n0 1 1 1\n1\n0\n3\n1 1 1\n9\n1 0 0 0 1 0 0 0 1\nOutput\n2\n1\n1\n0\n3", "input": [ [ [ "5" ], [ "1", "0", "0", "1", "0" ] ], [ [ "4" ], [ "0", "1", "1", "1" ] ], [ [ "1" ], [ "0" ] ], [ [ "3" ], [ "1", "1", "1" ] ], [ [ "9" ], [ "1", "0", "0", "0", "1", "0", "0", "0", "1" ] ] ], "output": [ "2", "1", "1", "0", "3" ] }, { "problem_id": "1829C", "problem_name": "Mr. Perfectly Fine\nbitmasks, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1829/C", "problem_solution_link": "https://codeforces.com/problemset/status/1829/problem/C", "problem_statement": "C. Mr. Perfectly Fine\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nVictor wants to become \"\nMr. Perfectly Fine\n\". For that, he needs to acquire a certain set of skills. More precisely, he has $$$2$$$ skills he needs to acquire.\nVictor has $$$n$$$ books. Reading book $$$i$$$ takes him $$$m_i$$$ minutes and will give him some (possibly none) of the required two skills, represented by a binary string of length $$$2$$$.\nWhat is the minimum amount of time required so that Victor acquires all of the two skills?\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 2 \\cdot 10^5$$$)\u00a0\u2014 the number of books available.\nThen $$$n$$$ lines follow. Line $$$i$$$ contains a positive integer $$$m_i$$$ ($$$1 \\leq m_i \\leq 2 \\cdot 10^5$$$) and a binary string of length $$$2$$$, where $$$s_{i1} = 1$$$ if reading book $$$i$$$ acquires Victor skill $$$1$$$, and $$$s_{i1} = 0$$$ otherwise, and $$$s_{i2} = 1$$$ if reading book $$$i$$$ acquires Victor skill $$$2$$$, and $$$s_{i2} = 0$$$ otherwise.\nIt is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, output a single integer denoting the minimum amount of minutes required for Victor to obtain both needed skills and $$$-1$$$ in case it's impossible to obtain the two skills after reading any amount of books.\nExample\nInput\n6\n4\n2 00\n3 10\n4 01\n4 00\n5\n3 01\n3 01\n5 01\n2 10\n9 10\n1\n5 11\n3\n9 11\n8 01\n7 10\n6\n4 01\n6 01\n7 01\n8 00\n9 01\n1 00\n4\n8 00\n9 10\n9 11\n8 11\nOutput\n7\n5\n5\n9\n-1\n8\nNote\nIn the first test case, we can use books $$$2$$$ and $$$3$$$, with a total amount of minutes spent equal to $$$3 + 4 = 7$$$.\nIn the second test case, we can use the books $$$1$$$ and $$$4$$$, with a total amount of minutes spent equal to $$$3 + 2 = 5$$$.\nIn the third test case, we have only one option and that is reading book $$$1$$$ for a total amount of minutes spent equal to $$$5$$$.", "input": [ [ [ "4" ], [ "2", "00", "3", "10", "4", "01", "4", "00" ] ], [ [ "5" ], [ "3", "01", "3", "01", "5", "01", "2", "10", "9", "10" ] ], [ [ "1" ], [ "5", "11" ] ], [ [ "3" ], [ "9", "11", "8", "01", "7", "10" ] ], [ [ "6" ], [ "4", "01", "6", "01", "7", "01", "8", "00", "9", "01", "1", "00" ] ], [ [ "4" ], [ "8", "00", "9", "10", "9", "11", "8", "11" ] ] ], "output": [ "7", "5", "5", "9", "-1", "8" ] }, { "problem_id": "1829A", "problem_name": "Love Story\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1829/A", "problem_solution_link": "https://codeforces.com/problemset/status/1829/problem/A", "problem_statement": "A. Love Story\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTimur loves codeforces. That's why he has a string $$$s$$$ having length $$$10$$$ made containing only lowercase Latin letters. Timur wants to know how many indices string $$$s$$$\ndiffers\nfrom the string \"\ncodeforces\n\".\nFor example string $$$s =$$$ \"\nco\nol\nfor\ns\ne\nz\n\" differs from \"\ncodeforces\n\" in $$$4$$$ indices, shown in bold.\nHelp Timur by finding the number of indices where string $$$s$$$ differs from \"\ncodeforces\n\".\nNote that you can't reorder the characters in the string $$$s$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nEach test case is one line and contains the string $$$s$$$, consisting of exactly $$$10$$$ lowercase Latin characters.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the number of indices where string $$$s$$$ differs.\nExample\nInput\n5\ncoolforsez\ncadafurcie\ncodeforces\npaiuforces\nforcescode\nOutput\n4\n5\n0\n4\n9", "input": [ [ [ "coolforsez" ] ], [ [ "cadafurcie" ] ], [ [ "codeforces" ] ], [ [ "paiuforces" ] ], [ [ "forcescode" ] ] ], "output": [ "4", "5", "0", "4", "9" ] }, { "problem_id": "1828A", "problem_name": "Divisible Array\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1828/A", "problem_solution_link": "https://codeforces.com/problemset/status/1828/problem/A", "problem_statement": "A. Divisible Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a positive integer $$$n$$$. Please find an array $$$a_1, a_2, \\ldots, a_n$$$ that is perfect.\nA perfect array $$$a_1, a_2, \\ldots, a_n$$$ satisfies the following criteria:\n$$$1 \\le a_i \\le 1000$$$ for all $$$1 \\le i \\le n$$$.\n$$$a_i$$$ is divisible by $$$i$$$ for all $$$1 \\le i \\le n$$$.\n$$$a_1 + a_2 + \\ldots + a_n$$$ is divisible by $$$n$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 200$$$). The description of the test cases follows.\nThe only line of each test case contains a single positive integer $$$n$$$ ($$$1 \\le n \\le 200$$$)\u00a0\u2014 the length of the array $$$a$$$.\nOutput\nFor each test case, output an array $$$a_1, a_2, \\ldots, a_n$$$ that is perfect.\nWe can show that an answer always exists. If there are multiple solutions, print any.\nExample\nInput\n7\n1\n2\n3\n4\n5\n6\n7\nOutput\n1\n2 4\n1 2 3\n2 8 6 4\n3 4 9 4 5\n1 10 18 8 5 36\n3 6 21 24 10 6 14\nNote\nIn the third test case:\n$$$a_1 = 1$$$ is divisible by $$$1$$$.\n$$$a_2 = 2$$$ is divisible by $$$2$$$.\n$$$a_3 = 3$$$ is divisible by $$$3$$$.\n$$$a_1 + a_2 + a_3 = 1 + 2 + 3 = 6$$$ is divisible by $$$3$$$.\nIn the fifth test case:\n$$$a_1 = 3$$$ is divisible by $$$1$$$.\n$$$a_2 = 4$$$ is divisible by $$$2$$$.\n$$$a_3 = 9$$$ is divisible by $$$3$$$.\n$$$a_4 = 4$$$ is divisible by $$$4$$$.\n$$$a_5 = 5$$$ is divisible by $$$5$$$.\n$$$a_1 + a_2 + a_3 + a_4 + a_5 = 3 + 4 + 9 + 4 + 5 = 25$$$ is divisible by $$$5$$$.", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "3" ] ], [ [ "4" ] ], [ [ "5" ] ], [ [ "6" ] ], [ [ "7" ] ] ], "output": [ "1", "2 4", "1 2 3", "2 8 6 4", "3 4 9 4 5", "1 10 18 8 5 36", "3 6 21 24 10 6 14" ] }, { "problem_id": "1825A", "problem_name": "LuoTianyi and the Palindrome String\ngreedy, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1825/A", "problem_solution_link": "https://codeforces.com/problemset/status/1825/problem/A", "problem_statement": "A. LuoTianyi and the Palindrome String\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLuoTianyi gives you\na palindrome\n$$$^{\\dagger}$$$ string $$$s$$$, and she wants you to find out the length of the longest non-empty subsequence$$$^{\\ddagger}$$$ of $$$s$$$ which is not a palindrome string. If there is no such subsequence, output $$$-1$$$ instead.\n$$$^{\\dagger}$$$ A palindrome is a string that reads the same backward as forward. For example, strings \"\nz\n\", \"\naaa\n\", \"\naba\n\", \"\nabccba\n\" are palindromes, but strings \"\ncodeforces\n\", \"\nreality\n\", \"\nab\n\" are not.\n$$$^{\\ddagger}$$$ A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from $$$b$$$. For example, strings \"\na\n\", \"\naaa\n\", \"\nbab\n\" are subsequences of string \"\nabaab\n\", but strings \"\ncodeforces\n\", \"\nbbb\n\", \"\nh\n\" are not.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases. The description of test cases follows.\nThe first and the only line of each test case contains a single string $$$s$$$ ($$$1 \\le |s| \\le 50$$$) consisting of lowercase English letters \u2014 the string that LuoTianyi gives you. It's guaranteed that $$$s$$$ is a palindrome string.\nOutput\nFor each test case, output a single integer \u2014 the length of the longest non-empty subsequence which is not a palindrome string. If there is no such subsequence, output $$$-1$$$.\nExample\nInput\n4\nabacaba\naaa\ncodeforcesecrofedoc\nlol\nOutput\n6\n-1\n18\n2\nNote\nIn the first test case, \"\nabcaba\n\" is a subsequence of \"\nabacaba\n\" as we can delete the third letter of \"\nabacaba\n\" to get \"\nabcaba\n\", and \"\nabcaba\n\" is not a palindrome string. We can prove that \"\nabcaba\n\" is an example of the longest subsequences of \"\nabacaba\n\" that isn't palindrome, so that the answer is $$$6$$$.\nIn the second test case, we can only get \"\na\n\" and \"\naa\n\", but they are all palindrome strings, so the answer is $$$-1$$$.", "input": [ [ [ "abacaba" ] ], [ [ "aaa" ] ], [ [ "codeforcesecrofedoc" ] ], [ [ "lol" ] ] ], "output": [ "6", "-1", "18", "2" ] }, { "problem_id": "1823A", "problem_name": "A-characteristic\ncombinatorics, constructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1823/A", "problem_solution_link": "https://codeforces.com/problemset/status/1823/problem/A", "problem_statement": "A. A-characteristic\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nConsider an array $$$a_1, a_2, \\dots, a_n$$$ consisting of numbers $$$1$$$ and $$$-1$$$. Define $$$A$$$-characteristic of this array as a number of pairs of indices $$$1 \\le i < j \\le n$$$, such that $$$a_i \\cdot a_j = 1$$$.\nFind any array $$$a$$$ with given length $$$n$$$ with $$$A$$$-characteristic equal to the given value $$$k$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). The description of the test cases follows.\nThe only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\le n \\le 100$$$; $$$0 \\le k \\le \\frac{(n-1) n}{2}$$$)\u00a0\u2014 the length of required array and required $$$A$$$-characteristic.\nOutput\nFor each test case, if there is no array $$$a$$$ with given $$$A$$$-characteristic $$$k$$$, print\nNO\n.\nOtherwise, print\nYES\nand $$$n$$$ numbers $$$1$$$ and $$$-1$$$, which form the required array $$$a$$$. If there are multiple answers, print any of them.\nExample\nInput\n7\n2 0\n2 1\n3 1\n3 2\n3 3\n5 4\n5 5\nOutput\nYES\n1 -1 \nYES\n1 1 \nYES\n1 -1 1 \nNO\nYES\n1 1 1 \nYES\n-1 1 -1 1 1 \nNO\nNote\nIn the first test case, there is only one pair of different elements in the array, and their product is $$$a_1 \\cdot a_2 = -1 \\neq 1$$$, hence its $$$A$$$-characteristic is $$$0$$$.\nIn the second test case, there is only one pair of different elements in the array, and their product is $$$a_1 \\cdot a_2 = 1$$$, hence its $$$A$$$-characteristic is $$$1$$$.\nIn the third test case, there are three pairs of different elements in the array, and their product are: $$$a_1 \\cdot a_2 = -1$$$, $$$a_1 \\cdot a_3 = 1$$$, $$$a_2 \\cdot a_3 = -1$$$, hence its $$$A$$$-characteristic is $$$1$$$.\nIn the fourth test case, we can show, that there is no array with length $$$3$$$, which $$$A$$$-characteristic is $$$2$$$.", "input": [ [ [ "2", "0" ] ], [ [ "2", "1" ] ], [ [ "3", "1" ] ], [ [ "3", "2" ] ], [ [ "3", "3" ] ], [ [ "5", "4" ] ], [ [ "5", "5" ] ] ], "output": [ ["YES", "1 -1"], ["YES", "1 1"], ["YES", "1 -1 1"], ["NO"], ["YES", "1 1 1"], ["YES", "-1 1 -1 1 1"], ["NO"] ], "error": true }, { "problem_id": "1822C", "problem_name": "Bun Lover\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1822/C", "problem_solution_link": "https://codeforces.com/problemset/status/1822/problem/C", "problem_statement": "C. Bun Lover\ntime limit per test\n3 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTema loves cinnabon rolls \u2014 buns with cinnabon and chocolate in the shape of a \"snail\".\nCinnabon rolls come in different sizes and are square when viewed from above. The most delicious part of a roll is the chocolate, which is poured in a thin layer over the cinnabon roll in the form of a spiral and around the bun, as in the following picture:\nCinnabon rolls of sizes 4, 5, 6\nFor a cinnabon roll of size $$$n$$$, the length of the outer side of the square is $$$n$$$, and the length of the shortest vertical chocolate segment in the central part is one.\nFormally, the bun consists of two dough spirals separated by chocolate. A cinnabon roll of size $$$n + 1$$$ is obtained from a cinnabon roll of size $$$n$$$ by wrapping each of the dough spirals around the cinnabon roll for another layer.\nIt is important that a cinnabon roll of size $$$n$$$ is defined in a unique way.\nTema is interested in how much chocolate is in his cinnabon roll of size $$$n$$$. Since Tema has long stopped buying small cinnabon rolls, it is guaranteed that $$$n \\ge 4$$$.\nAnswer this non-obvious question by calculating the total length of the chocolate layer.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^5$$$)\u00a0\u2014 the number of test cases.\nThe following $$$t$$$ lines describe the test cases.\nEach test case is described by a single integer $$$n$$$ ($$$4 \\le n \\le 10^9$$$)\u00a0\u2014 the size of the cinnabon roll.\nOutput\nOutput $$$t$$$ integers. The $$$i$$$-th of them should be equal to the total length of the chocolate layer in the $$$i$$$-th test case.\nExample\nInput\n4\n4\n5\n6\n179179179\nOutput\n26\n37\n50\n32105178545472401", "input": [ [ [ "4" ] ], [ [ "5" ] ], [ [ "6" ] ], [ [ "179179179" ] ] ], "output": [ "26", "37", "50", "32105178545472401" ] }, { "problem_id": "1822B", "problem_name": "Karina and Array\ngreedy, math, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1822/B", "problem_solution_link": "https://codeforces.com/problemset/status/1822/problem/B", "problem_statement": "B. Karina and Array\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nKarina has an array of $$$n$$$ integers $$$a_1, a_2, a_3, \\dots, a_n$$$. She loves multiplying numbers, so she decided that the\nbeauty\nof a pair of numbers is their product. And the\nbeauty\nof an array is the maximum\nbeauty\nof a pair of\nadjacent\nelements in the array.\nFor example, for $$$n = 4$$$, $$$a=[3, 5, 7, 4]$$$, the\nbeauty\nof the array is $$$\\max$$$($$$3 \\cdot 5$$$, $$$5 \\cdot 7$$$, $$$7 \\cdot 4$$$) = $$$\\max$$$($$$15$$$, $$$35$$$, $$$28$$$) = $$$35$$$.\nKarina wants her array to be as\nbeautiful\nas possible. In order to achieve her goal, she can remove some elements (possibly zero) from the array. After Karina removes all elements she wants to, the array must contain at least two elements.\nUnfortunately, Karina doesn't have enough time to do all her tasks, so she asks you to calculate the maximum\nbeauty\nof the array that she can get by removing any number of elements (possibly zero).\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe description of the test cases follows.\nThe first line of a test case contains an integer $$$n$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe second line of a test case contains $$$n$$$ integers $$$a_1, a_2, a_3, \\dots, a_n$$$ ($$$-10^9 \\le a_i \\le 10^9$$$)\u00a0\u2014 the elements of the array $$$a$$$.\nThe sum of all values of $$$n$$$ across all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nOutput $$$t$$$ integers, each of which is the answer to the corresponding test case\u00a0\u2014 the maximum\nbeauty\nof the array that Karina can get.\nExample\nInput\n7\n4\n5 0 2 1\n3\n-1 1 0\n5\n2 0 -1 -4 0\n6\n-8 4 3 7 1 -9\n6\n0 3 -2 5 -4 -4\n2\n1000000000 910000000\n7\n-1 -7 -2 -5 -4 -6 -3\nOutput\n10\n0\n4\n72\n16\n910000000000000000\n42\nNote\nIn the first test case of the example, to get the maximum beauty, you need to remove the $$$2$$$-nd element.\nIn the second and third test cases of the example, there is no need to remove any elements to achieve maximum beauty.\nIn the fourth test case of the example, you need to leave only the first and last elements.", "input": [ [ [ "4" ], [ "5", "0", "2", "1" ] ], [ [ "3" ], [ "-1", "1", "0" ] ], [ [ "5" ], [ "2", "0", "-1", "-4", "0" ] ], [ [ "6" ], [ "-8", "4", "3", "7", "1", "-9" ] ], [ [ "6" ], [ "0", "3", "-2", "5", "-4", "-4" ] ], [ [ "2" ], [ "1000000000", "910000000" ] ], [ [ "7" ], [ "-1", "-7", "-2", "-5", "-4", "-6", "-3" ] ] ], "output": [ "10", "0", "4", "72", "16", "910000000000000000", "42" ] }, { "problem_id": "1822A", "problem_name": "TubeTube Feed\nbrute force, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1822/A", "problem_solution_link": "https://codeforces.com/problemset/status/1822/problem/A", "problem_statement": "A. TubeTube Feed\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMushroom Filippov cooked himself a meal and while having his lunch, he decided to watch a video on\nTubeTube\n. He can not spend more than $$$t$$$ seconds for lunch, so he asks you for help with the selection of video.\nThe\nTubeTube\nfeed is a list of $$$n$$$ videos, indexed from $$$1$$$ to $$$n$$$. The $$$i$$$-th video lasts $$$a_i$$$ seconds and has an entertainment value $$$b_i$$$. Initially, the feed is opened on the first video, and Mushroom can skip to the next video in $$$1$$$ second (if the next video exists). Mushroom can skip videos any number of times (including zero).\nHelp Mushroom choose\none\nvideo that he can open and watch in $$$t$$$ seconds. If there are several of them, he wants to choose the most entertaining one. Print the index of any appropriate video, or $$$-1$$$ if there is no such.\nInput\nThe first line of the input data contains a single integer $$$q$$$ ($$$1 \\le q \\le 1000$$$)\u00a0\u2014 the number of test cases in the test.\nThe description of the test cases follows.\nThe first line of a test case contains two integers $$$n$$$ and $$$t$$$ ($$$1 \\le n \\le 50$$$, $$$1 \\le t \\le 200$$$)\u00a0\u2014 the number of videos in the feed and seconds for lunch, respectively.\nThe second line of a test case contains $$$n$$$ integers $$$a_1, a_2, a_3, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$)\u00a0\u2014 durations of videos.\nThe third line of a test case contains $$$n$$$ integers $$$b_1, b_2, b_3, \\dots, b_n$$$ ($$$1 \\le b_i \\le 100$$$)\u00a0\u2014 entertainment values of videos.\nOutput\nOutput $$$q$$$ integers, each of which is the answer to the corresponding test case. As an answer, output the\nindex\nof the most entertaining video that Mushroom will have time to watch. If there are several answers, you are allowed to output any of them. Output $$$-1$$$, if there is no video he can watch during his lunch break.\nExample\nInput\n5\n5 9\n1 5 7 6 6\n3 4 7 1 9\n4 4\n4 3 3 2\n1 2 3 4\n5 7\n5 5 5 5 5\n2 1 3 9 7\n4 33\n54 71 69 96\n42 24 99 1\n2 179\n55 66\n77 88\nOutput\n3\n2\n3\n-1\n2", "input": [ [ [ "5", "9" ], [ "1", "5", "7", "6", "6" ], [ "3", "4", "7", "1", "9" ] ], [ [ "4", "4" ], [ "4", "3", "3", "2" ], [ "1", "2", "3", "4" ] ], [ [ "5", "7" ], [ "5", "5", "5", "5", "5" ], [ "2", "1", "3", "9", "7" ] ], [ [ "4", "33" ], [ "54", "71", "69", "96" ], [ "42", "24", "99", "1" ] ], [ [ "2", "179" ], [ "55", "66" ], [ "77", "88" ] ] ], "output": [ "3", "2", "3", "-1", "2" ] }, { "problem_id": "1821A", "problem_name": "Matching\ncombinatorics, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1821/A", "problem_solution_link": "https://codeforces.com/problemset/status/1821/problem/A", "problem_statement": "A. Matching\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nAn\ninteger template\nis a string consisting of digits and/or question marks.\nA positive (strictly greater than $$$0$$$) integer matches the integer template if it is possible to replace every question mark in the template with a digit in such a way that we get the decimal representation of that integer\nwithout any leading zeroes\n.\nFor example:\n$$$42$$$ matches\n4?\n;\n$$$1337$$$ matches\n????\n;\n$$$1337$$$ matches\n1?3?\n;\n$$$1337$$$ matches\n1337\n;\n$$$3$$$ does not match\n??\n;\n$$$8$$$ does not match\n???8\n;\n$$$1337$$$ does not match\n1?7\n.\nYou are given an integer template consisting of\nat most $$$5$$$ characters\n. Calculate the number of positive (strictly greater than $$$0$$$) integers that match it.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 2 \\cdot 10^4$$$) \u2014 the number of test cases.\nEach test case consists of one line containing the string $$$s$$$ ($$$1 \\le |s| \\le 5$$$) consisting of digits and/or question marks \u2014 the integer template for the corresponding test case.\nOutput\nFor each test case, print one integer \u2014 the number of positive (strictly greater than $$$0$$$) integers that match the template.\nExample\nInput\n8\n??\n?\n0\n9\n03\n1??7\n?5?\n9??99\nOutput\n90\n9\n0\n1\n0\n100\n90\n100", "input": [ [ [ "??" ] ], [ [ "?" ] ], [ [ "0" ] ], [ [ "9" ] ], [ [ "03" ] ], [ [ "1??7" ] ], [ [ "?5?" ] ], [ [ "9??99" ] ] ], "output": [ "90", "9", "0", "1", "0", "100", "90", "100" ] }, { "problem_id": "1820A", "problem_name": "Yura's New Name\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1820/A", "problem_solution_link": "https://codeforces.com/problemset/status/1820/problem/A", "problem_statement": "A. Yura's New Name\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAfter holding one team contest, boy Yura got very tired and wanted to change his life and move to Japan. In honor of such a change, Yura changed his name to something nice.\nFascinated by this idea he already thought up a name $$$s$$$ consisting only of characters \"\n_\n\" and \"\n^\n\". But there's a problem \u2014 Yura likes smiley faces \"\n^_^\n\" and \"\n^^\n\". Therefore any character of the name must be a part of at least one such smiley. Note that only the\nconsecutive\ncharacters of the name can be a smiley face.\nMore formally, consider all occurrences of the strings \"\n^_^\n\" and \"\n^^\n\" in the string $$$s$$$. Then all such occurrences must cover the whole string $$$s$$$, possibly with intersections. For example, in the string \"\n^^__^_^^__^\n\" the characters at positions $$$3,4,9,10$$$ and $$$11$$$ are not contained inside any smileys, and the other characters at positions $$$1,2,5,6,7$$$ and $$$8$$$ are contained inside smileys.\nIn one operation Jura can insert one of the characters \"\n_\n\" and \"\n^\n\" into his name $$$s$$$ (you can insert it at any position in the string). He asks you to tell him the minimum number of operations you need to do to make the name fit Yura's criteria.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014the number of test cases. The description of test cases follows.\nThe first and only line of each test case contains a single string $$$s$$$ ($$$1 \\leq |s| \\leq 100$$$), consisting of characters \"\n_\n\" and \"\n^\n\", \u00a0\u2014 the name to change.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the minimum number of characters you need to add to the name to make it fit for Yura. If you don't need to change anything in the name, print $$$0$$$.\nExample\nInput\n7\n^______^\n___^_^^^_^___^\n^_\n^\n^_^^^^^_^_^^\n___^^\n_\nOutput\n5\n5\n1\n1\n0\n3\n2\nNote\nIn the first test case, you can get the following name by adding $$$5$$$ characters:\n^_\n^\n_\n^\n_\n^\n_\n^\n_\n^\n_^\nIn the third test case, we can add one character \"\n^\n\" to the end of the name, then we get the name:\n^_\n^\nIn the fourth test case, we can add one character \"\n^\n\" to the end of the name, then we get the name:\n^\n^\nIn the fifth test case, all of the characters are already contained in smiley faces, so the answer is $$$0$$$.\nIn the seventh test case, you can add one character \"\n^\n\" at the beginning of the name and one character \"\n^\n\" at the end of the name, then you get the name:\n^\n_\n^", "input": [ [ [ "^______^" ] ], [ [ "___^_^^^_^___^" ] ], [ [ "^_" ] ], [ [ "^" ] ], [ [ "^_^^^^^_^_^^" ] ], [ [ "___^^" ] ], [ [ "_" ] ] ], "output": [ "5", "5", "1", "1", "0", "3", "2" ] }, { "problem_id": "1816A", "problem_name": "Ian Visits Mary\nconstructive algorithms, geometry, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1816/A", "problem_solution_link": "https://codeforces.com/problemset/status/1816/problem/A", "problem_statement": "A. Ian Visits Mary\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIan and Mary are frogs living on lattice points of the Cartesian coordinate plane, with Ian living on $$$(0,0)$$$ and Mary living on $$$(a,b)$$$.\nIan would like to visit Mary by jumping around the Cartesian coordinate plane. Every second, he jumps from his current position $$$(x_p, y_p)$$$ to another lattice point $$$(x_q, y_q)$$$, such that no lattice point other than $$$(x_p, y_p)$$$ and $$$(x_q, y_q)$$$ lies on the segment between point $$$(x_p, y_p)$$$ and point $$$(x_q, y_q)$$$.\nAs Ian wants to meet Mary as soon as possible, he wants to jump towards point $$$(a,b)$$$ using\nat most $$$2$$$ jumps\n. Unfortunately, Ian is not good at maths. Can you help him?\nA lattice point is defined as a point with both the $$$x$$$-coordinate and $$$y$$$-coordinate being integers.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 500$$$) \u2014 the number of test cases. The description of test cases follows.\nThe first and only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1\\le a,b\\le 10^9$$$) \u2014 the coordinates of the lattice point where Mary lives.\nOutput\nFor each test case, print an integer $$$n$$$ ($$$1 \\le n \\le 2$$$) on the first line, denoting the number of jumps Ian uses in order to meet Mary. Note that you do not need to minimize the number of jumps.\nOn the $$$i$$$-th line of the next $$$n$$$ lines, print two integers $$$0 \\le x_i,y_i \\le 10^9$$$ separated by a space, denoting Ian's location $$$(x_i,y_i)$$$ after the $$$i$$$-th jump. $$$x_n = a$$$, $$$y_n = b$$$ must hold.\nIan's initial location and his locations after each of the $$$n$$$ jumps\nneed not\nbe distinct.\nIf there are multiple solutions, output any.\nExample\nInput\n8\n3 4\n4 4\n3 6\n2 2\n1 1\n7 3\n2022 2023\n1000000000 1000000000\nOutput\n1\n3 4\n2\n3 2\n4 4\n2\n5 3\n3 6\n2\n1 0\n2 2\n1\n1 1\n1\n7 3\n1\n2022 2023\n2\n69420420 469696969\n1000000000 1000000000\nNote\nIn the first test case:\n$$$(0,0) \\to (3,4)$$$\nIn the second test case:\n$$$(0,0) \\to (3,2) \\to (4,4)$$$\nIn the third test case:\n$$$(0,0) \\to (5,3) \\to (3,6)$$$", "input": [ [ [ "3", "4" ] ], [ [ "4", "4" ] ], [ [ "3", "6" ] ], [ [ "2", "2" ] ], [ [ "1", "1" ] ], [ [ "7", "3" ] ], [ [ "2022", "2023" ] ], [ [ "1000000000", "1000000000" ] ] ], "output": [ ["1", "3 4"], ["2", "3 2", "4 4"], ["2", "5 3", "3 6"], ["2", "1 0", "2 2"], ["1", "1 1"], ["1", "7 3"], ["1", "2022 2023"], ["2", "69420420 469696969", "1000000000 1000000000"] ], "error": true }, { "problem_id": "1818A", "problem_name": "Politics\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1818/A", "problem_solution_link": "https://codeforces.com/problemset/status/1818/problem/A", "problem_statement": "A. Politics\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIn a debate club with $$$n$$$ members, including yourself (member $$$1$$$), there are $$$k$$$ opinions to be discussed in sequence. During each discussion, members express their agreement or disagreement with the opinion. Let's define $$$Y$$$ as the number of members who agree and $$$N$$$ as the number of members who disagree. After each discussion, members leave the club based on the following criteria:\nIf more members agree than disagree ($$$Y > N$$$), all members who disagreed leave the club.\nIf more members disagree than agree ($$$Y < N$$$), all members who agreed leave the club.\nIf there is a tie ($$$Y = N$$$), all members leave the club.\nAs the club president, your goal is to stay in the club and maximize the number of members remaining after the meeting. You have access to each member's stance on all $$$k$$$ opinions before the meeting starts, and you can expel any number of members (excluding yourself) before the meeting begins.\nDetermine the maximum number of members, including yourself, who can remain in the club after the meeting. You don't need to provide the specific expulsion strategy but only the maximum number of members that can stay. Ensure that you remain in the club after the meeting as well.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$). Description of the test cases follows.\nThe first line of each test case contains two positive integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 100$$$) \u2014 the number of members and the number of discussions.\nThe $$$i$$$-th of the following $$$n$$$ lines contains a string $$$t_i$$$ of length $$$k$$$. The $$$j$$$-th character in the string $$$t_i$$$ indicates whether the $$$i$$$-th member agrees or disagrees with the $$$j$$$-th opinion if they are present during that discussion. A \"\n+\n\" symbol means the member agrees, while a \"\n-\n\" symbol means the member disagrees.\nIt is guaranteed that the sum of $$$n \\cdot k$$$ over all test cases does not exceed $$$5 \\cdot 10^4$$$.\nOutput\nFor each test case, output the maximum number of members, including yourself, who can remain in the club after the meeting.\nExample\nInput\n5\n2 2\n++\n+-\n1 3\n+-+\n4 1\n+\n-\n-\n+\n5 4\n++++\n+--+\n++-+\n+-++\n++++\n4 2\n++\n--\n--\n-+\nOutput\n1\n1\n2\n2\n1\nNote\nFor convenience, we will analyze the examples based on who actually attended the meeting (i.\u00a0e. was\nnot\nexpelled) rather than who was expelled.\nExample 1:\nOnly the first member could have attended the meeting, otherwise both members would have left after the second opinion is discussed.\nExample 2:\nThere is only a single member that attends the meeting and stays till the end.\nExample 3:\nThe club has $$$4$$$ members and only one opinion will be discussed during the meeting. Let's analyze the possible outcomes based on the participants in the meeting:\nIf only the first member attends, they'll be the only one left after the meeting.\nIf the first member attends with the second or third member, they will be a tie in the discussion, making them both leave.\nIf the first member attends with the second and third members, the first member will be in the minority and will leave after the discussion, which contradicts the statement.\nIf the first and fourth members attend, they will agree during the discussion and both remain till the end.\nIf the first, second, and fourth members attend, the second member will be in the minority during the discussion, and only the first and fourth members will remain at the end. The same happens if the second member is replaced by the third member.\nIf all four members attend, there will be a tie during the discussion, making everyone leave.\nThe maximum number of members remaining after the meeting is $$$2$$$.\nExample 4:\nThe club has $$$5$$$ members and $$$4$$$ opinions will be discussed during the meeting.\nOne way to achieve the maximum number of members is if only the first, third, and fifth members attend the meeting. In this case, they all agree during the first two discussions, after which the third member is in the minority during the third discussion. Then, the first and fifth members agree in the last discussion, and those two members stay till the end of the meeting.\nExample 5:\nThe club has $$$4$$$ members and $$$2$$$ opinions will be discussed.\nIf the first three members attend the meeting, the first member will be in the minority during the first discussion and will leave the club. After that, the second and third members will both disagree with the second opinion, and they both will stay till the end of the meeting. In this way, there will be 2 members left after the meeting, but it is an invalid outcome, as it forces the first member to leave. Therefore, the maximum number of 1 member is achieved if only the first member attends the meeting.", "input": [ [ [ "2", "2" ], [ "++", "+-" ] ], [ [ "1", "3" ], [ "+-+" ] ], [ [ "4", "1" ], [ "+", "-", "-", "+" ] ], [ [ "5", "4" ], [ "++++", "+--+", "++-+", "+-++", "++++" ] ], [ [ "4", "2" ], [ "++", "--", "--", "-+" ] ] ], "output": [ "1", "1", "2", "2", "1" ] }, { "problem_id": "1811A", "problem_name": "Insert Digit\ngreedy, math, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1811/A", "problem_solution_link": "https://codeforces.com/problemset/status/1811/problem/A", "problem_statement": "A. Insert Digit\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have a\npositive\nnumber of length $$$n$$$ and one additional digit.\nYou can insert this digit anywhere in the number, including at the beginning or at the end.\nYour task is to make the result as large as possible.\nFor example, you have the number $$$76543$$$, and the additional digit is $$$4$$$. Then the maximum number you can get is $$$765443$$$, and it can be obtained in two ways \u2014 by inserting a digit after the $$$3$$$th or after the $$$4$$$th digit of the number.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases.\nThe descriptions of the test cases follow.\nThe first line of the description of each test case contains two integers $$$n$$$ and $$$d$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$; $$$0 \\le d \\le 9$$$) \u2014 the length of the number and an additional digit, respectively.\nThe second line of the description of each test case contains a string consisting of $$$n$$$ digits \u2014 the number that you have initially. It is guaranteed that the number does not contain leading zeros.\nIt is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, output a string consisting of $$$n + 1$$$ digits \u2014 the maximum possible number that can be obtained.\nExample\nInput\n11\n5 4\n76543\n1 0\n1\n2 5\n44\n3 6\n666\n5 6\n13579\n5 8\n97531\n19 4\n9876543210123456789\n5 7\n73737\n8 1\n20000000\n7 0\n7058959\n12 1\n828127127732\nOutput\n765443\n10\n544\n6666\n613579\n987531\n98765443210123456789\n773737\n210000000\n70589590\n8281271277321", "input": [ [ [ "5", "4" ], [ "76543" ] ], [ [ "1", "0" ], [ "1" ] ], [ [ "2", "5" ], [ "44" ] ], [ [ "3", "6" ], [ "666" ] ], [ [ "5", "6" ], [ "13579" ] ], [ [ "5", "8" ], [ "97531" ] ], [ [ "19", "4" ], [ "9876543210123456789" ] ], [ [ "5", "7" ], [ "73737" ] ], [ [ "8", "1" ], [ "20000000" ] ], [ [ "7", "0" ], [ "7058959" ] ], [ [ "12", "1" ], [ "828127127732" ] ] ], "output": [ "765443", "10", "544", "6666", "613579", "987531", "98765443210123456789", "773737", "210000000", "70589590", "8281271277321" ] }, { "problem_id": "1814A", "problem_name": "Coins\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1814/A", "problem_solution_link": "https://codeforces.com/problemset/status/1814/problem/A", "problem_statement": "A. Coins\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIn Berland, there are two types of coins, having denominations of $$$2$$$ and $$$k$$$ burles.\nYour task is to determine whether it is possible to represent $$$n$$$ burles in coins, i.\u2009e. whether there exist non-negative integers $$$x$$$ and $$$y$$$ such that $$$2 \\cdot x + k \\cdot y = n$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 10^{18}$$$; $$$k \\ne 2$$$).\nOutput\nFor each test case, print\nYES\nif it is possible to represent $$$n$$$ burles in coins; otherwise, print\nNO\n. You may print each letter in any case (\nYES\n,\nyes\n,\nYes\nwill all be recognized as positive answer,\nNO\n,\nno\nand\nnO\nwill all be recognized as negative answer).\nExample\nInput\n4\n5 3\n6 1\n7 4\n8 8\nOutput\nYES\nYES\nNO\nYES\nNote\nIn the first test case, you can take one coin with denomination $$$2$$$ and one coin with denomination $$$k = 3$$$.\nIn the second test case, you can take three coins with denomination $$$2$$$. Alternatively, you can take six coins with denomination $$$k = 1$$$.\nIn the third test case, there is no way to represent $$$7$$$ burles.\nIn the fourth test case, you can take one coin with denomination $$$k = 8$$$.", "input": [ [ [ "5", "3" ] ], [ [ "6", "1" ] ], [ [ "7", "4" ] ], [ [ "8", "8" ] ] ], "output": [ "YES", "YES", "NO", "YES" ] }, { "problem_id": "1810B", "problem_name": "Candies\nconstructive algorithms, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1810/B", "problem_solution_link": "https://codeforces.com/problemset/status/1810/problem/B", "problem_statement": "B. Candies\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThis problem is about candy. Initially, you only have $$$1$$$ candy, and you want to have exactly $$$n$$$ candies.\nYou can use the two following spells in any order at most $$$40$$$ times in total.\nAssume you have $$$x$$$ candies now. If you use the first spell, then $$$x$$$ candies become $$$2x-1$$$ candies.\nAssume you have $$$x$$$ candies now. If you use the second spell, then $$$x$$$ candies become $$$2x+1$$$ candies.\nConstruct a sequence of spells, such that after using them in order, you will have\nexactly\n$$$n$$$ candies, or determine it's impossible.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Their description follows.\nEach test case contains one line with a single integer $$$n$$$ ($$$2 \\le n \\le 10^9$$$) \u2014 the required final number of candies.\nOutput\nFor each test case, output the following.\nIf it's possible to eventually have $$$n$$$ candies within $$$40$$$ spells, in the first line print an integer $$$m$$$ ($$$1 \\le m \\le 40$$$), representing the total number of spells you use.\nIn the second print $$$m$$$ integers $$$a_{1}, a_{2}, \\ldots, a_{m}$$$ ($$$a_{i}$$$ is $$$1$$$ or $$$2$$$) separated by spaces, where $$$a_{i} = 1$$$ means that you use the first spell in the $$$i$$$-th step, while $$$a_{i} = 2$$$ means that you use the second spell in the $$$i$$$-th step.\nNote that you\ndo not\nhave to minimize $$$m$$$, and if there are multiple solutions, you may output any one of them.\nIf it's impossible, output $$$-1$$$ in one line.\nExample\nInput\n4\n2\n3\n7\n17\nOutput\n-1\n1\n2 \n2\n2 2 \n4\n2 1 1 1\nNote\nFor $$$n=3$$$, you can just use the second spell once, and then have $$$2 \\cdot 1 + 1 = 3$$$ candies.\nFor $$$n=7$$$, you can use the second spell twice. After the first step, you will have $$$3$$$ candies. And after the second step, you will have $$$2 \\cdot 3 + 1 = 7$$$ candies.", "input": [ [ [ "2" ] ], [ [ "3" ] ], [ [ "7" ] ], [ [ "17" ] ] ], "output": [ ["-1"], ["1", "2"], ["2", "2 2"], ["4", "2 1 1 1"] ], "error": true }, { "problem_id": "1810A", "problem_name": "Beautiful Sequence\nbrute force, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1810/A", "problem_solution_link": "https://codeforces.com/problemset/status/1810/problem/A", "problem_statement": "A. Beautiful Sequence\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA sequence of $$$m$$$ integers $$$a_{1}, a_{2}, \\ldots, a_{m}$$$ is\ngood\n, if and only if there exists at least one $$$i$$$ ($$$1 \\le i \\le m$$$) such that $$$a_{i} = i$$$. For example, $$$[3,2,3]$$$ is a good sequence, since $$$a_{2} = 2$$$, $$$a_{3} = 3$$$, while $$$[3,1,1]$$$ is not a good sequence, since there is no $$$i$$$ such that $$$a_{i} = i$$$.\nA sequence $$$a$$$ is\nbeautiful\n, if and only if there exists at least one subsequence of $$$a$$$ satisfying that this subsequence is good. For example, $$$[4,3,2]$$$ is a beautiful sequence, since its subsequence $$$[4,2]$$$ is good, while $$$[5,3,4]$$$ is not a beautiful sequence.\nA sequence $$$b$$$ is a subsequence of a sequence $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by the deletion of several (possibly, zero or all) elements.\nNow you are given a sequence, check whether it is beautiful or not.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 500$$$) \u2014 the number of test cases. Their description follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the length of the given sequence.\nThe second line of each test case contains $$$n$$$ integers $$$a_{1}, a_{2}, \\ldots, a_{n}$$$ ($$$1 \\le a_{i} \\le 10^9$$$), representing the sequence.\nOutput\nFor each test case, output \"\nYES\n\" or \"\nNO\n\"(without quotes) in one line, representing whether the given sequence is beautiful.\nYou can output the answer in any case (upper or lower). For example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\", and \"\nYES\n\" will be recognized as positive responses.\nExample\nInput\n7\n3\n3 2 1\n4\n2 4 3 5\n5\n2 3 5 5 6\n2\n3 1\n5\n2 4 5 2 3\n4\n5 6 7 8\n6\n6 5 4 3 2 1\nOutput\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nNote\nIn the first test case, the good subsequence is $$$b=[3,2]$$$, where $$$b_{2} = 2$$$.\nIn the second test case, the good subsequence is $$$b=[2,4,3]$$$, where $$$b_{3} = 3$$$.\nIn the fourth test case, the good subsequence is $$$b=[1]$$$, where $$$b_{1} = 1$$$.\nIn the fifth test case, the good subsequence is $$$b=[2,2]$$$, where $$$b_{2} = 2$$$.", "input": [ [ [ "3" ], [ "3", "2", "1" ] ], [ [ "4" ], [ "2", "4", "3", "5" ] ], [ [ "5" ], [ "2", "3", "5", "5", "6" ] ], [ [ "2" ], [ "3", "1" ] ], [ [ "5" ], [ "2", "4", "5", "2", "3" ] ], [ [ "4" ], [ "5", "6", "7", "8" ] ], [ [ "6" ], [ "6", "5", "4", "3", "2", "1" ] ] ], "output": [ "YES", "YES", "NO", "YES", "YES", "NO", "YES" ] }, { "problem_id": "1809A", "problem_name": "Garland\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1809/A", "problem_solution_link": "https://codeforces.com/problemset/status/1809/problem/A", "problem_statement": "A. Garland\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have a garland consisting of $$$4$$$ colored light bulbs, the color of the $$$i$$$-th light bulb is $$$s_i$$$.\nInitially, all the light bulbs are turned off. Your task is to turn all the light bulbs on. You can perform the following operation any number of times: select a light bulb and switch its state (turn it on if it was off, and turn it off if it was on). The only restriction on the above operation is that you can apply the operation to a light bulb only if the previous operation was applied to a light bulb of a different color (the first operation can be applied to any light bulb).\nCalculate the minimum number of operations to turn all the light bulbs on, or report that this is impossible.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe single line of each test case contains $$$s$$$\u00a0\u2014 a sequence of $$$4$$$ characters, where each character is a decimal digit. The $$$i$$$-th character denotes the color of the $$$i$$$-th light bulb.\nOutput\nFor each test case, print one integer\u00a0\u2014 the minimum number of operations to turn all the light bulbs on. If it is impossible to turn all the bulbs on, print\n-1\n.\nExample\nInput\n3\n9546\n0000\n3313\nOutput\n4\n-1\n6\nNote\nIn the first example, all the colors are different, so you can just turn all the bulbs on in $$$4$$$ operations.\nIn the second example, it is impossible to turn all the bulbs on, because after you switch one light bulb, it is impossible to turn the others on.\nIn the third example, you can proceed as follows: turn the first light bulb on, turn the third light bulb on, turn the fourth light bulb on, turn the third light bulb off, turn the second light bulb on, turn the third light bulb on.", "input": [ [ [ "9546" ] ], [ [ "0000" ] ], [ [ "3313" ] ] ], "output": [ "4", "-1", "6" ] }, { "problem_id": "1807A", "problem_name": "Plus or Minus\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1807/A", "problem_solution_link": "https://codeforces.com/problemset/status/1807/problem/A", "problem_statement": "A. Plus or Minus\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given three integers $$$a$$$, $$$b$$$, and $$$c$$$ such that\nexactly one\nof these two equations is true:\n$$$a+b=c$$$\n$$$a-b=c$$$\nOutput\n+\nif the first equation is true, and\n-\notherwise.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 162$$$)\u00a0\u2014 the number of test cases.\nThe description of each test case consists of three integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \\leq a, b \\leq 9$$$, $$$-8 \\leq c \\leq 18$$$). The additional constraint on the input: it will be generated so that\nexactly\none of the two equations will be true.\nOutput\nFor each test case, output either\n+\nor\n-\non a new line, representing the correct equation.\nExample\nInput\n11\n1 2 3\n3 2 1\n2 9 -7\n3 4 7\n1 1 2\n1 1 0\n3 3 6\n9 9 18\n9 9 0\n1 9 -8\n1 9 10\nOutput\n+\n-\n-\n+\n+\n-\n+\n+\n-\n-\n+\nNote\nIn the first test case, $$$1+2=3$$$.\nIn the second test case, $$$3-2=1$$$.\nIn the third test case, $$$2-9=-7$$$. Note that $$$c$$$ can be negative.", "input": [ [ [ "1", "2", "3" ] ], [ [ "3", "2", "1" ] ], [ [ "2", "9", "-7" ] ], [ [ "3", "4", "7" ] ], [ [ "1", "1", "2" ] ], [ [ "1", "1", "0" ] ], [ [ "3", "3", "6" ] ], [ [ "9", "9", "18" ] ], [ [ "9", "9", "0" ] ], [ [ "1", "9", "-8" ] ], [ [ "1", "9", "10" ] ] ], "output": [ "+", "-", "-", "+", "+", "-", "+", "+", "-", "-", "+" ] }, { "problem_id": "1807C", "problem_name": "Find and Replace\ngreedy, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1807/C", "problem_solution_link": "https://codeforces.com/problemset/status/1807/problem/C", "problem_statement": "C. Find and Replace\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a string $$$s$$$ consisting of lowercase Latin characters. In an operation, you can take a character and replace\nall\noccurrences of this character with $$$\\texttt{0}$$$ or replace\nall\noccurrences of this character with $$$\\texttt{1}$$$.\nIs it possible to perform some number of moves so that the resulting string is an alternating binary string$$$^{\\dagger}$$$?\nFor example, consider the string $$$\\texttt{abacaba}$$$. You can perform the following moves:\nReplace $$$\\texttt{a}$$$ with $$$\\texttt{0}$$$. Now the string is $$$\\color{red}{\\texttt{0}}\\texttt{b}\\color{red}{\\texttt{0}}\\texttt{c}\\color{red}{\\texttt{0}}\\texttt{b}\\color{red}{\\texttt{0}}$$$.\nReplace $$$\\texttt{b}$$$ with $$$\\texttt{1}$$$. Now the string is $$${\\texttt{0}}\\color{red}{\\texttt{1}}{\\texttt{0}}\\texttt{c}{\\texttt{0}}\\color{red}{\\texttt{1}}{\\texttt{0}}$$$.\nReplace $$$\\texttt{c}$$$ with $$$\\texttt{1}$$$. Now the string is $$${\\texttt{0}}{\\texttt{1}}{\\texttt{0}}\\color{red}{\\texttt{1}}{\\texttt{0}}{\\texttt{1}}{\\texttt{0}}$$$. This is an alternating binary string.\n$$$^{\\dagger}$$$An\nalternating binary string\nis a string of $$$\\texttt{0}$$$s and $$$\\texttt{1}$$$s such that no two adjacent bits are equal. For example, $$$\\texttt{01010101}$$$, $$$\\texttt{101}$$$, $$$\\texttt{1}$$$ are alternating binary strings, but $$$\\texttt{0110}$$$, $$$\\texttt{0a0a0}$$$, $$$\\texttt{10100}$$$ are not.\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 2000$$$)\u00a0\u2014 the length of the string $$$s$$$.\nThe second line of each test case contains a string consisting of $$$n$$$ lowercase Latin characters\u00a0\u2014 the string $$$s$$$.\nOutput\nFor each test case, output \"\nYES\n\" (without quotes) if you can make the string into an alternating binary string, and \"\nNO\n\" (without quotes) otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n8\n7\nabacaba\n2\naa\n1\ny\n4\nbkpt\n6\nninfia\n6\nbanana\n10\ncodeforces\n8\ntestcase\nOutput\nYES\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNote\nThe first test case is explained in the statement.\nIn the second test case, the only possible binary strings you can make are $$$\\texttt{00}$$$ and $$$\\texttt{11}$$$, neither of which are alternating.\nIn the third test case, you can make $$$\\texttt{1}$$$, which is an alternating binary string.", "input": [ [ [ "7" ], [ "abacaba" ] ], [ [ "2" ], [ "aa" ] ], [ [ "1" ], [ "y" ] ], [ [ "4" ], [ "bkpt" ] ], [ [ "6" ], [ "ninfia" ] ], [ [ "6" ], [ "banana" ] ], [ [ "10" ], [ "codeforces" ] ], [ [ "8" ], [ "testcase" ] ] ], "output": [ "YES", "NO", "YES", "YES", "NO", "YES", "NO", "NO" ] }, { "problem_id": "1807B", "problem_name": "Grab the Candies\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1807/B", "problem_solution_link": "https://codeforces.com/problemset/status/1807/problem/B", "problem_statement": "B. Grab the Candies\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMihai and Bianca are playing with bags of candies. They have a row $$$a$$$ of $$$n$$$ bags of candies. The $$$i$$$-th bag has $$$a_i$$$ candies. The bags are given to the players in the order from the first bag to the $$$n$$$-th bag.\nIf a bag has an even number of candies, Mihai grabs the bag. Otherwise, Bianca grabs the bag. Once a bag is grabbed, the number of candies in it gets added to the total number of candies of the player that took it.\nMihai wants to show off, so he wants to reorder the array so that at any moment (except at the start when they both have no candies), Mihai will have\nstrictly more\ncandies than Bianca. Help Mihai find out if such a reordering exists.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the number of bags in the array.\nThe second line of each test case contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \\leq a_i \\leq 100$$$)\u00a0\u2014 the number of candies in each bag.\nOutput\nFor each test case, output \"\nYES\n\" (without quotes) if such a reordering exists, and \"\nNO\n\" (without quotes) otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n3\n4\n1 2 3 4\n4\n1 1 1 2\n3\n1 4 3\nOutput\nYES\nNO\nNO\nNote\nIn the first test case, Mihai can reorder the array as follows: $$$[4, 1, 2, 3]$$$. Then the process proceeds as follows:\nthe first bag has $$$4$$$ candies, which is even, so Mihai takes it\u00a0\u2014 Mihai has $$$4$$$ candies, and Bianca has $$$0$$$.\nthe second bag has $$$1$$$ candies, which is odd, so Bianca takes it\u00a0\u2014 Mihai has $$$4$$$ candies, and Bianca has $$$1$$$.\nthe third bag has $$$2$$$ candies, which is even, so Mihai takes it\u00a0\u2014 Mihai has $$$6$$$ candies, and Bianca has $$$1$$$.\nthe fourth bag has $$$3$$$ candies, which is odd, so Bianca takes it\u00a0\u2014 Mihai has $$$6$$$ candies, and Bianca has $$$4$$$.\nSince Mihai always has more candies than Bianca, this reordering works.", "input": [ [ [ "4" ], [ "1", "2", "3", "4" ] ], [ [ "4" ], [ "1", "1", "1", "2" ] ], [ [ "3" ], [ "1", "4", "3" ] ] ], "output": [ "YES", "NO", "NO" ] }, { "problem_id": "1806A", "problem_name": "Walking Master\ngeometry, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1806/A", "problem_solution_link": "https://codeforces.com/problemset/status/1806/problem/A", "problem_statement": "A. Walking Master\ntime limit per test\n1 second\nmemory limit per test\n1024 megabytes\ninput\nstandard input\noutput\nstandard output\nYunQian is standing on an infinite plane with the Cartesian coordinate system on it. In one move, she can move to the diagonally adjacent point on the top right or the adjacent point on the left.\nThat is, if she is standing on point $$$(x,y)$$$, she can either move to point $$$(x+1,y+1)$$$ or point $$$(x-1,y)$$$.\nYunQian initially stands at point $$$(a,b)$$$ and wants to move to point $$$(c,d)$$$. Find the minimum number of moves she needs to make or declare that it is impossible.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1\\le t\\le 10^4$$$)\u00a0\u2014 the number of test cases. The description of test cases follows.\nThe first line and only line of each test case contain four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$-10^8\\le a,b,c,d\\le 10^8$$$).\nOutput\nFor each test case, if it is possible to move from point $$$(a,b)$$$ to point $$$(c,d)$$$, output the minimum number of moves. Otherwise, output $$$-1$$$.\nExample\nInput\n6\n-1 0 -1 2\n0 0 4 5\n-2 -1 1 1\n-3 2 -3 2\n2 -1 -1 -1\n1 1 0 2\nOutput\n4\n6\n-1\n0\n3\n3\nNote\nIn the first test case, one possible way using $$$4$$$ moves is $$$(-1,0)\\to (0,1)\\to (-1,1)\\to (0,2)\\to (-1,2)$$$. It can be proven that it is impossible to move from point $$$(-1,0)$$$ to point $$$(-1,2)$$$ in less than $$$4$$$ moves.", "input": [ [ [ "-1", "0", "-1", "2" ] ], [ [ "0", "0", "4", "5" ] ], [ [ "-2", "-1", "1", "1" ] ], [ [ "-3", "2", "-3", "2" ] ], [ [ "2", "-1", "-1", "-1" ] ], [ [ "1", "1", "0", "2" ] ] ], "output": [ "4", "6", "-1", "0", "3", "3" ] }, { "problem_id": "1805B", "problem_name": "The String Has a Target\ngreedy, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1805/B", "problem_solution_link": "https://codeforces.com/problemset/status/1805/problem/B", "problem_statement": "B. The String Has a Target\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a string $$$s$$$. You can apply this operation to the string exactly once: choose index $$$i$$$ and move character $$$s_i$$$ to the beginning of the string (removing it at the old position). For example, if you apply the operation with index $$$i=4$$$ to the string \"\nabaacd\n\" with numbering from $$$1$$$, you get the string \"\naabacd\n\". What is the lexicographically minimal$$$^{\\dagger}$$$ string you can obtain by this operation?\n$$$^{\\dagger}$$$A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ of the same length if and only if the following holds:\nin the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^4$$$). The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10 ^ 5$$$)\u00a0\u2014 the length of the string.\nThe second line of each test case contains the string $$$s$$$ of length $$$n$$$, consisting of lowercase English letters.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10 ^ 5$$$.\nOutput\nFor each test case, on a separate line print the lexicographically smallest string that can be obtained after applying the operation to the original string exactly once.\nExample\nInput\n4\n3\ncba\n4\nacac\n5\nabbcb\n4\naaba\nOutput\nacb\naacc\nabbcb\naaab\nNote\nIn the first test case, you need to move the last character to the beginning.\nIn the second case, you need to move the second letter \"\na\n\".\nIn the third set you need to apply the operation with $$$i=1$$$, then the string will not change.", "input": [ [ [ "3" ], [ "cba" ] ], [ [ "4" ], [ "acac" ] ], [ [ "5" ], [ "abbcb" ] ], [ [ "4" ], [ "aaba" ] ] ], "output": [ "acb", "aacc", "abbcb", "aaab" ] }, { "problem_id": "1805A", "problem_name": "We Need the Zero\nbitmasks, brute force", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1805/A", "problem_solution_link": "https://codeforces.com/problemset/status/1805/problem/A", "problem_statement": "A. We Need the Zero\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is an array $$$a$$$ consisting of non-negative integers. You can choose an integer $$$x$$$ and denote $$$b_i=a_i \\oplus x$$$ for all $$$1 \\le i \\le n$$$, where $$$\\oplus$$$ denotes the\nbitwise XOR operation\n. Is it possible to choose such a number $$$x$$$ that the value of the expression $$$b_1 \\oplus b_2 \\oplus \\ldots \\oplus b_n$$$ equals $$$0$$$?\nIt can be shown that if a valid number $$$x$$$ exists, then there also exists $$$x$$$ such that ($$$0 \\le x < 2^8$$$).\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$). The description of the test cases follows.\nThe first line of the test case contains one integer $$$n$$$ ($$$1 \\le n \\le 10^3$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe second line of the test case contains $$$n$$$ integers\u00a0\u2014 array $$$a$$$ ($$$0 \\le a_i < 2^8$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^3$$$.\nOutput\nFor each set test case, print the integer $$$x$$$ ($$$0 \\le x < 2^8$$$) if it exists, or $$$-1$$$ otherwise.\nExample\nInput\n5\n3\n1 2 5\n3\n1 2 3\n4\n0 1 2 3\n4\n1 2 2 3\n1\n1\nOutput\n6\n0\n3\n-1\n1\nNote\nIn the first test case, after applying the operation with the number $$$6$$$ the array $$$b$$$ becomes $$$[7, 4, 3]$$$, $$$7 \\oplus 4 \\oplus 3 = 0$$$.\nThere are other answers in the third test case, such as the number $$$0$$$.", "input": [ [ [ "3" ], [ "1", "2", "5" ] ], [ [ "3" ], [ "1", "2", "3" ] ], [ [ "4" ], [ "0", "1", "2", "3" ] ], [ [ "4" ], [ "1", "2", "2", "3" ] ], [ [ "1" ], [ "1" ] ] ], "output": [ "6", "0", "3", "-1", "1" ] }, { "problem_id": "1804A", "problem_name": "Lame King\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1804/A", "problem_solution_link": "https://codeforces.com/problemset/status/1804/problem/A", "problem_statement": "A. Lame King\ntime limit per test\n1 second\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a checkerboard of size $$$201 \\times 201$$$, i.\u00a0e. it has $$$201$$$ rows and $$$201$$$ columns. The rows of this checkerboard are numbered from $$$-100$$$ to $$$100$$$ from bottom to top. The columns of this checkerboard are numbered from $$$-100$$$ to $$$100$$$ from left to right. The notation $$$(r, c)$$$ denotes the cell located in the $$$r$$$-th row and the $$$c$$$-th column.\nThere is a king piece at position $$$(0, 0)$$$ and it wants to get to position $$$(a, b)$$$ as soon as possible. In this problem our king is lame. Each second, the king makes exactly one of the following five moves.\nSkip move. King's position remains unchanged.\nGo up. If the current position of the king is $$$(r, c)$$$ he goes to position $$$(r + 1, c)$$$.\nGo down. Position changes from $$$(r, c)$$$ to $$$(r - 1, c)$$$.\nGo right. Position changes from $$$(r, c)$$$ to $$$(r, c + 1)$$$.\nGo left. Position changes from $$$(r, c)$$$ to $$$(r, c - 1)$$$.\nKing is\nnot allowed\nto make moves that put him outside of the board. The important consequence of the king being lame is that he is\nnot allowed\nto make the same move during two consecutive seconds. For example, if the king goes right, the next second he can only skip, go up, down, or left.\nWhat is the minimum number of seconds the lame king needs to reach position $$$(a, b)$$$?\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$)\u00a0\u2014 the number of test cases. Then follow $$$t$$$ lines containing one test case description each.\nEach test case consists of two integers $$$a$$$ and $$$b$$$ ($$$-100 \\leq a, b \\leq 100$$$)\u00a0\u2014 the position of the cell that the king wants to reach. It is guaranteed that either $$$a \\ne 0$$$ or $$$b \\ne 0$$$.\nOutput\nPrint $$$t$$$ integers. The $$$i$$$-th of these integers should be equal to the minimum number of seconds the lame king needs to get to the position he wants to reach in the $$$i$$$-th test case. The king always starts at position $$$(0, 0)$$$.\nExample\nInput\n5\n-4 1\n4 4\n0 -6\n-5 -4\n7 -8\nOutput\n7\n8\n11\n9\n15\nNote\nOne of the possible solutions for the first example is: go down, go right, go down, go right, go down, go left, go down.\nOne of the possible solutions for the second example is to alternate \"go right\" and \"go up\" moves $$$4$$$ times each.\nOne of the possible solutions for the third example is to alternate \"go left\" and \"skip\" moves starting with \"go left\". Thus, \"go left\" will be used $$$6$$$ times, and \"skip\" will be used $$$5$$$ times.", "input": [ [ [ "-4", "1" ] ], [ [ "4", "4" ] ], [ [ "0", "-6" ] ], [ [ "-5", "-4" ] ], [ [ "7", "-8" ] ] ], "output": [ "7", "8", "11", "9", "15" ] }, { "problem_id": "1802A", "problem_name": "Likes\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1802/A", "problem_solution_link": "https://codeforces.com/problemset/status/1802/problem/A", "problem_statement": "A. Likes\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nNikita recently held a very controversial round, after which his contribution changed very quickly.\nThe announcement hung on the main page for $$$n$$$ seconds. In the $$$i$$$th second $$$|a_i|$$$th person either liked or removed the like (Nikita was lucky in this task and there are no dislikes). If $$$a_i > 0$$$, then the $$$a_i$$$th person put a like. If $$$a_i < 0$$$, then the person $$$-a_i$$$ removed the like.\nEach person put and removed the like no more than once. A person could not remove a like if he had not put it before.\nSince Nikita's contribution became very bad after the round, he wanted to analyze how his contribution changed while the announcement was on the main page. He turned to the creator of the platform with a request to give him the sequence $$$a_1, a_2, \\ldots, a_n$$$. But due to the imperfection of the platform, the sequence $$$a$$$ was shuffled.\nYou are given a shuffled sequence of $$$a$$$ that describes user activity. You need to tell for each moment from $$$1$$$ to $$$n$$$ what the maximum and minimum number of likes could be on the post at that moment.\nInput\nThe first line of input data contains one number $$$t$$$ ($$$1 \\leqslant t \\leqslant 1000$$$) \u2014 the number of test cases.\nIn the first line of test case, one number is given $$$n$$$ ($$$1 \\leqslant n \\leqslant 100$$$) \u2014 the number of seconds during which Nikita's announcement hung on the main page.\nThe next line contains $$$n$$$ numbers $$$b_1, b_2, b_3, \\ldots, b_n$$$ ($$$1 \\leqslant |b_i| \\leqslant n$$$) \u2014 mixed array $$$a$$$. It is guaranteed that there exists such a permutation of $$$b$$$ that it is a correct sequence of events described in the condition.\nIt is guaranteed that the sum of $$$n$$$ for all input test cases does not exceed $$$10^4$$$.\nOutput\nFor each test case, output two lines, each of which contains $$$n$$$ numbers.\nIn the first line, for each test case, output the maximum number of likes that Nikita could have at the announcement at the $$$i$$$th second.\nIn the second line, for each test case, output the minimum number of likes that Nikita could have at the announcement at the $$$i$$$th second.\nExample\nInput\n5\n3\n1 2 -2\n2\n1 -1\n6\n4 3 -1 2 1 -2\n5\n4 2 -2 1 3\n7\n-1 6 -4 3 2 4 1\nOutput\n1 2 1 \n1 0 1 \n1 0 \n1 0 \n1 2 3 4 3 2 \n1 0 1 0 1 2 \n1 2 3 4 3 \n1 0 1 2 3 \n1 2 3 4 5 4 3 \n1 0 1 0 1 2 3\nNote\nIn the first test case, the maximum values are reached with the following permutation: $$$1, 2, -2$$$. And the minimum values for such: $$$2, -2, 1$$$.\nIn the third test case, all maximal values are reached with the following permutation: $$$4, 2, 3, 1, -1, -2$$$. And the minimum values for the next permutation: $$$2, -2, 1, -1, 3, 4$$$.", "input": [ [ [ "3" ], [ "1", "2", "-2" ] ], [ [ "2" ], [ "1", "-1" ] ], [ [ "6" ], [ "4", "3", "-1", "2", "1", "-2" ] ], [ [ "5" ], [ "4", "2", "-2", "1", "3" ] ], [ [ "7" ], [ "-1", "6", "-4", "3", "2", "4", "1" ] ] ], "output": [ ["1 2 1", "1 0 1"], ["1 0", "1 0"], ["1 2 3 4 3 2", "1 0 1 0 1 2"], ["1 2 3 4 3", "1 0 1 2 3"], ["1 2 3 4 5 4 3", "1 0 1 0 1 2 3"] ], "error": true }, { "problem_id": "1800A", "problem_name": "Is It a Cat?\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1800/A", "problem_solution_link": "https://codeforces.com/problemset/status/1800/problem/A", "problem_statement": "A. Is It a Cat?\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou were walking down the street and heard a sound. The sound was described by the string $$$s$$$ consisting of lowercase and uppercase Latin characters. Now you want to find out if the sound was a cat meowing.\nFor the sound to be a meowing, the string can only contain the letters '\nm\n', '\ne\n', '\no\n' and '\nw\n', in either uppercase or lowercase. Also:\nstring must start with non-empty sequence consisting only of characters '\nm\n' or '\nM\n'\nit must be immediately followed by non-empty sequence consisting only of characters '\ne\n' or '\nE\n'\nit must be immediately followed by non-empty sequence consisting only of characters '\no\n' or '\nO\n'\nit must be immediately followed by non-empty sequence consisting only of characters '\nw\n' or '\nW\n', this sequence ends the string, after it immediately comes the string end\nFor example, strings \"\nmeow\n\", \"\nmmmEeOWww\n\", \"\nMeOooOw\n\" describe a meowing, but strings \"\nMweo\n\", \"\nMeO\n\", \"\nmoew\n\", \"\nMmEW\n\", \"\nmeowmeow\n\" do not.\nDetermine whether the sound you heard was a cat meowing or something else.\nInput\nThe first line of input data contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 50$$$) \u2014 the length of the string describing the sound.\nThe second line of each test case contains a string $$$s$$$ of $$$n$$$ characters. The string describes the sound you heard and consists only of lowercase and uppercase Latin letters.\nOutput\nFor each test case, output on a separate line:\nYES\nif the sound was a cat meowing;\nNO\notherwise.\nYou can output\nYES\nand\nNO\nin any case (for example, strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as positive response).\nExample\nInput\n7\n4\nmeOw\n14\nmMmeoOoWWWwwwW\n3\nmew\n7\nMmeEeUw\n4\nMEOW\n6\nMmyaVW\n5\nmeowA\nOutput\nYES\nYES\nNO\nNO\nYES\nNO\nNO\nNote\nIn the first test case, the string consists of a sequence of characters '\nm\n', '\ne\n', '\nO\n', '\nw\n', which satisfies the definition of meowing.\nIn the second test case, the string consists of a sequence of $$$3$$$ characters '\nm\n' and '\nM\n', one '\ne\n', a sequence of $$$3$$$ characters '\no\n' and '\nO\n' and a sequence of $$$7$$$ characters '\nw\n' and '\nW\n', which satisfies the definition of meowing.\nIn the third test case, the string does not describe a meowing because it lacks a sequence of '\no\n' or '\nO\n' characters between '\ne\n' and '\nw\n'.\nIn the fourth test case, the string contains the character '\nU\n', so it does not describe a meowing.", "input": [ [ [ "4" ], [ "meOw" ] ], [ [ "14" ], [ "mMmeoOoWWWwwwW" ] ], [ [ "3" ], [ "mew" ] ], [ [ "7" ], [ "MmeEeUw" ] ], [ [ "4" ], [ "MEOW" ] ], [ [ "6" ], [ "MmyaVW" ] ], [ [ "5" ], [ "meowA" ] ] ], "output": [ "YES", "YES", "NO", "NO", "YES", "NO", "NO" ] }, { "problem_id": "1799A", "problem_name": "Recent Actions\ndata structures, greedy, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1799/A", "problem_solution_link": "https://codeforces.com/problemset/status/1799/problem/A", "problem_statement": "A. Recent Actions\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nOn Codeforces the \"Recent Actions\" field shows the last $$$n$$$ posts with recent actions.\nInitially, there are posts $$$1, 2, \\ldots, n$$$ in the field (this is in order from top to down). Also there are infinitely many posts not in the field, numbered with integers $$$n + 1, n + 2, \\ldots$$$.\nWhen recent action happens in the post $$$p$$$:\nIf it is in the \"Recent Actions\" field, it moves from its position to the top position.\nOtherwise, it is added to the top position, and the post on the down position is removed from the \"Recent Actions\" field.\nYou know, that the next $$$m$$$ recent actions will happen in the posts $$$p_1, p_2, \\ldots, p_m$$$ ($$$n + 1 \\leq p_i \\leq n + m$$$) in the moments of time $$$1, 2, \\ldots, m$$$.\nNote\n, that recent actions only happen with posts with numbers $$$\\geq n + 1$$$.\nFor each post $$$i$$$ ($$$1 \\leq i \\leq n$$$), find the first time it will be removed from the \"Recent Actions\" field or say, that it won't be removed.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$) \u2014 the number of test cases. Descriptions of test cases follow.\nThe first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \\leq n, m \\leq 5 \\cdot 10^4$$$) \u2014 the size of the \"Recent Actions\" field and the number of actions.\nThe next line contains $$$m$$$ integers $$$p_1, p_2, \\ldots, p_m$$$ ($$$n + 1 \\leq p_i \\leq n + m$$$).\nIt is guaranteed, that the sum of $$$n$$$ and the sum of $$$m$$$ for all test cases does not exceed $$$5 \\cdot 10^4$$$.\nOutput\nFor each test case print $$$n$$$ integers $$$t_1, t_2, \\ldots, t_n$$$, where $$$t_i=-1$$$ if the post $$$i$$$ won't be removed or $$$t_i$$$ equals to the first moment of time the post $$$i$$$ will be removed ($$$1 \\leq t_i \\leq m$$$).\nExample\nInput\n10\n1 1\n2\n3 2\n5 4\n4 5\n5 9 9 5 7\n5 5\n6 7 8 9 10\n3 4\n4 4 4 4\n4 4\n5 5 6 6\n3 5\n4 5 5 5 4\n4 20\n5 5 24 24 24 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20\n5 7\n7 8 7 11 7 12 10\n6 7\n8 11 7 8 8 8 12\nOutput\n1 \n-1 2 1 \n-1 5 2 1 \n5 4 3 2 1 \n-1 -1 1 \n-1 -1 3 1 \n-1 2 1 \n8 7 3 1 \n7 6 4 2 1 \n-1 -1 7 3 2 1\nNote\nIn the first test case, the only post $$$1$$$ will be removed at the moment $$$1$$$ and replaced by the post $$$2$$$.\nIn the second test case the \"Recent Actions\" field will be (given an order from top to down):\nBefore moment $$$1$$$: $$$[1, 2, 3]$$$, after moment $$$1$$$: $$$[5, 1, 2]$$$. Post number $$$3$$$ was removed.\nBefore moment $$$2$$$: $$$[5, 1, 2]$$$, after moment $$$2$$$: $$$[4, 5, 1]$$$. Post number $$$2$$$ was removed.\nPost number $$$1$$$ won't be removed.\nIn the third test case the \"Recent Actions\" field will be (given an order from top to down):\nBefore moment $$$1$$$: $$$[1, 2, 3, 4]$$$, after moment $$$1$$$: $$$[5, 1, 2, 3]$$$. Post number $$$4$$$ was removed.\nBefore moment $$$2$$$: $$$[5, 1, 2, 3]$$$, after moment $$$2$$$: $$$[9, 5, 1, 2]$$$. Post number $$$3$$$ was removed.\nBefore moment $$$3$$$: $$$[9, 5, 1, 2]$$$, after moment $$$3$$$: $$$[9, 5, 1, 2]$$$. Nothing was changed.\nBefore moment $$$4$$$: $$$[9, 5, 1, 2]$$$, after moment $$$4$$$: $$$[5, 9, 1, 2]$$$. The order was changed.\nBefore moment $$$5$$$: $$$[5, 9, 1, 2]$$$, after moment $$$5$$$: $$$[7, 5, 9, 1]$$$. Post number $$$2$$$ was removed.\nPost number $$$1$$$ won't be removed.", "input": [ [ [ "1", "1" ], [ "2" ] ], [ [ "3", "2" ], [ "5", "4" ] ], [ [ "4", "5" ], [ "5", "9", "9", "5", "7" ] ], [ [ "5", "5" ], [ "6", "7", "8", "9", "10" ] ], [ [ "3", "4" ], [ "4", "4", "4", "4" ] ], [ [ "4", "4" ], [ "5", "5", "6", "6" ] ], [ [ "3", "5" ], [ "4", "5", "5", "5", "4" ] ], [ [ "4", "20" ], [ "5", "5", "24", "24", "24", "5", "6", "7", "8", "9", "10", "12", "13", "14", "15", "16", "17", "18", "19", "20" ] ], [ [ "5", "7" ], [ "7", "8", "7", "11", "7", "12", "10" ] ], [ [ "6", "7" ], [ "8", "11", "7", "8", "8", "8", "12" ] ] ], "output": [ "1", "-1 2 1", "-1 5 2 1", "5 4 3 2 1", "-1 -1 1", "-1 -1 3 1", "-1 2 1", "8 7 3 1", "7 6 4 2 1", "-1 -1 7 3 2 1" ] }, { "problem_id": "1798A", "problem_name": "Showstopper\ngreedy, implementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1798/A", "problem_solution_link": "https://codeforces.com/problemset/status/1798/problem/A", "problem_statement": "A. Showstopper\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two arrays $$$a_1, a_2, \\ldots, a_n$$$ and $$$b_1, b_2, \\ldots, b_n$$$.\nIn one operation, you can choose any integer $$$i$$$ from $$$1$$$ to $$$n$$$ and swap the numbers $$$a_i$$$ and $$$b_i$$$.\nDetermine whether, after using any (possibly zero) number of operations, the following two conditions can be satisfied simultaneously:\n$$$a_n = \\max(a_1, a_2, \\ldots, a_n)$$$,\n$$$b_n = \\max(b_1, b_2, \\ldots, b_n)$$$.\nHere $$$\\max(c_1, c_2, \\ldots, c_k)$$$ denotes the maximum number among $$$c_1, c_2, \\ldots, c_k$$$. For example, $$$\\max(3, 5, 4) = 5$$$, $$$\\max(1, 7, 7) = 7$$$, $$$\\max(6, 2) = 6$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 200$$$). The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the length of the arrays.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 100$$$)\u00a0\u2014 elements of the first array.\nThe third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \\ldots, b_n$$$ ($$$1 \\le b_i \\le 100$$$)\u00a0\u2014 elements of the second array.\nOutput\nFor each test case, print \"\nYes\n\" if after using any (possibly zero) number of operations the conditions described above are satisfied. Otherwise, print \"\nNo\n\".\nYou can output the answer in any case (upper or lower). For example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\", and \"\nYES\n\" will be recognized as positive responses.\nExample\nInput\n7\n3\n7 9 7\n7 6 9\n4\n10 10 15 15\n10 16 15 15\n2\n100 99\n99 100\n1\n1\n1\n9\n1 2 3 4 5 6 7 8 9\n9 9 9 9 9 9 6 6 6\n7\n1 1 2 2 1 1 2\n1 2 1 2 1 2 1\n2\n30 4\n5 30\nOutput\nYes\nNo\nYes\nYes\nYes\nNo\nNo\nNote\nIn the first test case, you can swap the numbers $$$a_3$$$ and $$$b_3$$$, after which the array $$$a$$$ becomes equal to $$$[7, 9, 9]$$$, and the array $$$b$$$ becomes equal to $$$[7, 6, 7]$$$, and both conditions are met.\nIn the second test case, it can be proved that it is impossible to satisfy both conditions.\nIn the third test case, you can swap the numbers $$$a_1$$$ and $$$b_1$$$, after which the array $$$a$$$ becomes equal to $$$[99, 99]$$$, and the array $$$b$$$ becomes equal to $$$[100, 100]$$$, and both conditions are satisfied.\nIn fifth test case, you can swap $$$a_7$$$ and $$$b_7$$$, $$$a_8$$$ and $$$b_8$$$, $$$a_9$$$ and $$$b_9$$$, after which the array $$$a$$$ becomes equal to $$$[1, 2, 3, 4, 5, 6, 6, 6, 6]$$$, and the array $$$b$$$ becomes equal to $$$[9, 9, 9, 9, 9, 9, 7, 8, 9]$$$, and both conditions are satisfied.", "input": [ [ [ "3" ], [ "7", "9", "7" ], [ "7", "6", "9" ] ], [ [ "4" ], [ "10", "10", "15", "15" ], [ "10", "16", "15", "15" ] ], [ [ "2" ], [ "100", "99" ], [ "99", "100" ] ], [ [ "1" ], [ "1" ], [ "1" ] ], [ [ "9" ], [ "1", "2", "3", "4", "5", "6", "7", "8", "9" ], [ "9", "9", "9", "9", "9", "9", "6", "6", "6" ] ], [ [ "7" ], [ "1", "1", "2", "2", "1", "1", "2" ], [ "1", "2", "1", "2", "1", "2", "1" ] ], [ [ "2" ], [ "30", "4" ], [ "5", "30" ] ] ], "output": [ "Yes", "No", "Yes", "Yes", "Yes", "No", "No" ] }, { "problem_id": "1797A", "problem_name": "Li Hua and Maze\nconstructive algorithms, flows, graphs, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1797/A", "problem_solution_link": "https://codeforces.com/problemset/status/1797/problem/A", "problem_statement": "A. Li Hua and Maze\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a rectangular maze of size $$$n\\times m$$$. Denote $$$(r,c)$$$ as the cell on the $$$r$$$-th row from the top and the $$$c$$$-th column from the left. Two cells are\nadjacent\nif they share an edge. A\npath\nis a sequence of\nadjacent\nempty cells.\nEach cell is initially empty. Li Hua can choose some cells (except $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$) and place an obstacle in each of them. He wants to know the minimum number of obstacles needed to be placed so that there isn't a\npath\nfrom $$$(x_1, y_1)$$$ to $$$(x_2, y_2)$$$.\nSuppose you were Li Hua, please solve this problem.\nInput\nThe first line contains the single integer $$$t$$$ ($$$1 \\le t \\le 500$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains two integers $$$n,m$$$ ($$$4\\le n,m\\le 10^9$$$)\u00a0\u2014 the size of the maze.\nThe second line of each test case contains four integers $$$x_1,y_1,x_2,y_2$$$ ($$$1\\le x_1,x_2\\le n, 1\\le y_1,y_2\\le m$$$)\u00a0\u2014 the coordinates of the start and the end.\nIt is guaranteed that $$$|x_1-x_2|+|y_1-y_2|\\ge 2$$$.\nOutput\nFor each test case print the minimum number of obstacles you need to put on the field so that there is no\npath\nfrom $$$(x_1, y_1)$$$ to $$$(x_2, y_2)$$$.\nExample\nInput\n3\n4 4\n2 2 3 3\n6 7\n1 1 2 3\n9 9\n5 1 3 6\nOutput\n4\n2\n3\nNote\nIn test case 1, you can put obstacles on $$$(1,3), (2,3), (3,2), (4,2)$$$. Then the path from $$$(2,2)$$$ to $$$(3,3)$$$ will not exist.", "input": [ [ [ "4", "4" ], [ "2", "2", "3", "3" ] ], [ [ "6", "7" ], [ "1", "1", "2", "3" ] ], [ [ "9", "9" ], [ "5", "1", "3", "6" ] ] ], "output": [ "4", "2", "3" ] }, { "problem_id": "1796A", "problem_name": "Typical Interview Problem\nbrute force, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1796/A", "problem_solution_link": "https://codeforces.com/problemset/status/1796/problem/A", "problem_statement": "A. Typical Interview Problem\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nThe FB-string is formed as follows. Initially, it is empty. We go through all positive integers, starting from $$$1$$$, in ascending order, and do the following for each integer:\nif the current integer is divisible by $$$3$$$, append\nF\nto the end of the FB-string;\nif the current integer is divisible by $$$5$$$, append\nB\nto the end of the FB-string.\nNote that if an integer is divisible by both $$$3$$$ and $$$5$$$, we append\nF\n, and then\nB\n, not in the opposite order.\nThe first $$$10$$$ characters of the FB-string are\nFBFFBFFBFB\n: the first\nF\ncomes from the integer $$$3$$$, the next character (\nB\n) comes from $$$5$$$, the next\nF\ncomes from the integer $$$6$$$, and so on. It's easy to see that this string is infinitely long. Let $$$f_i$$$ be the $$$i$$$-th character of FB-string; so, $$$f_1$$$ is\nF\n, $$$f_2$$$ is\nB\n, $$$f_3$$$ is\nF\n, $$$f_4$$$ is\nF\n, and so on.\nYou are given a string $$$s$$$, consisting of characters\nF\nand/or\nB\n. You have to determine whether it is a substring (contiguous subsequence) of the FB-string. In other words, determine if it is possible to choose two integers $$$l$$$ and $$$r$$$ ($$$1 \\le l \\le r$$$) so that the string $$$f_l f_{l+1} f_{l+2} \\dots f_r$$$ is exactly $$$s$$$.\nFor example:\nFFB\nis a substring of the FB-string: if we pick $$$l = 3$$$ and $$$r = 5$$$, the string $$$f_3 f_4 f_5$$$ is exactly\nFFB\n;\nBFFBFFBF\nis a substring of the FB-string: if we pick $$$l = 2$$$ and $$$r = 9$$$, the string $$$f_2 f_3 f_4 \\dots f_9$$$ is exactly\nBFFBFFBF\n;\nBBB\nis not a substring of the FB-string.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 2046$$$) \u2014 the number of test cases.\nEach test case consists of two lines. The first line contains one integer $$$k$$$ ($$$1 \\le k \\le 10$$$) \u2014 the number of characters in $$$s$$$. The second line contains $$$s$$$, which is a string of exactly $$$k$$$ characters. Each character of $$$s$$$ is either\nF\nor\nB\n.\nOutput\nFor each test case, print\nYES\nif $$$s$$$ is a substring of the FB-string, or\nNO\notherwise.\nYou may print each letter in any case (\nYES\n,\nyes\n,\nYes\nwill all be recognized as positive answer,\nNO\n,\nno\nand\nnO\nwill all be recognized as negative answer).\nExample\nInput\n3\n3\nFFB\n8\nBFFBFFBF\n3\nBBB\nOutput\nYES\nYES\nNO", "input": [ [ [ "3" ], [ "FFB" ] ], [ [ "8" ], [ "BFFBFFBF" ] ], [ [ "3" ], [ "BBB" ] ] ], "output": [ "YES", "YES", "NO" ] }, { "problem_id": "1795A", "problem_name": "Two Towers\nbrute force, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1795/A", "problem_solution_link": "https://codeforces.com/problemset/status/1795/problem/A", "problem_statement": "A. Two Towers\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are two towers consisting of blocks of two colors: red and blue. Both towers are represented by strings of characters\nB\nand/or\nR\ndenoting the order of blocks in them\nfrom the bottom to the top\n, where\nB\ncorresponds to a blue block, and\nR\ncorresponds to a red block.\nThese two towers are represented by strings\nBRBB\nand\nRBR\n.\nYou can perform the following operation any number of times: choose a tower with\nat least two blocks\n, and move its\ntop\nblock to the\ntop\nof the other tower.\nThe pair of towers is\nbeautiful\nif no pair of touching blocks has the same color; i.\u2009e. no red block stands on top of another red block, and no blue block stands on top of another blue block.\nYou have to check if it is possible to perform any number of operations (possibly zero) to make the pair of towers beautiful.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of three lines:\nthe first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 20$$$)\u00a0\u2014 the number of blocks in the first tower and the number of blocks in the second tower, respectively;\nthe second line contains $$$s$$$\u00a0\u2014 a string of exactly $$$n$$$ characters\nB\nand/or\nR\n, denoting the first tower;\nthe third line contains $$$t$$$\u00a0\u2014 a string of exactly $$$m$$$ characters\nB\nand/or\nR\n, denoting the second tower.\nOutput\nFor each test case, print\nYES\nif it is possible to perform several (possibly zero) operations in such a way that the pair of towers becomes beautiful; otherwise print\nNO\n.\nYou may print each letter in any case (\nYES\n,\nyes\n,\nYes\nwill all be recognized as positive answer,\nNO\n,\nno\nand\nnO\nwill all be recognized as negative answer).\nExample\nInput\n4\n4 3\nBRBB\nRBR\n4 7\nBRBR\nRRBRBRB\n3 4\nRBR\nBRBR\n5 4\nBRBRR\nBRBR\nOutput\nYES\nYES\nYES\nNO\nNote\nIn the first test case, you can move the top block from the first tower to the second tower (see the third picture).\nIn the second test case, you can move the top block from the second tower to the first tower $$$6$$$ times.\nIn the third test case, the pair of towers is already beautiful.", "input": [ [ [ "4", "3" ], [ "BRBB" ], [ "RBR" ] ], [ [ "4", "7" ], [ "BRBR" ], [ "RRBRBRB" ] ], [ [ "3", "4" ], [ "RBR" ], [ "BRBR" ] ], [ [ "5", "4" ], [ "BRBRR" ], [ "BRBR" ] ] ], "output": [ "YES", "YES", "YES", "NO" ] }, { "problem_id": "1794A", "problem_name": "Prefix and Suffix Array\nstrings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1794/A", "problem_solution_link": "https://codeforces.com/problemset/status/1794/problem/A", "problem_statement": "A. Prefix and Suffix Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMarcos loves strings a lot, so he has a favorite string $$$s$$$ consisting of lowercase English letters. For this string, he wrote down all its non-empty prefixes and suffixes (except for $$$s$$$) on a piece of paper in arbitrary order. You see all these strings and wonder if Marcos' favorite string is a palindrome or not. So, your task is to decide whether $$$s$$$ is a palindrome by just looking at the piece of paper.\nA string $$$a$$$ is a prefix of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the end.\nA string $$$a$$$ is a suffix of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning.\nA palindrome is a string that reads the same backward as forward, for example, strings \"\ngg\n\", \"\nioi\n\", \"\nabba\n\", \"\nicpci\n\" are palindromes, but strings \"\ncodeforces\n\", \"\nabcd\n\", \"\nalt\n\" are not.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 120$$$)\u00a0\u2014 the number of test cases. The description of test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2\\le n \\le 20$$$)\u00a0\u2014 the length of the string $$$s$$$.\nThe second line of each test case contains $$$2n-2$$$ strings $$$a_1, a_2, \\cdots, a_{2n-2}$$$\u00a0\u2014 all non-empty prefixes and suffixes of $$$s$$$, not including itself, in arbitrary order.\nIt is guaranteed that these strings are all the non-empty prefixes and suffixes of some string consisting of lowercase English letters.\nOutput\nFor each test case, output \"\nYES\n\" if $$$s$$$ is a palindrome, and \"\nNO\n\" otherwise.\nYou can output the answer in any case (upper or lower). For example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\", and \"\nYES\n\" will be recognized as positive responses.\nExample\nInput\n5\n4\nbcd cd a d abc ab\n3\ni io i oi\n2\ng g\n3\nt al lt a\n4\nbba a ab a abb ba\nOutput\nNO\nYES\nYES\nNO\nYES\nNote\nIn the first test case, $$$s$$$ is \"\nabcd\n\". Its prefixes are \"\na\n\", \"\nab\n\" and \"\nabc\n\", and its suffixes are \"\nd\n\", \"\ncd\n\" and \"\nbcd\n\". As the string \"\nabcd\n\" is not a palindrome, the answer is\nNO\n.\nIn the second test case, $$$s$$$ is \"\nioi\n\". Its prefixes are \"\ni\n\" and \"\nio\n\", and its suffixes are \"\ni\n\" and \"\noi\n\". As the string \"\nioi\n\" is a palindrome, the answer is\nYES\n.\nIn the third test case, $$$s$$$ is \"\ngg\n\" which is a palindrome.\nIn the fourth test case, $$$s$$$ is \"\nalt\n\" which is not a palindrome.", "input": [ [ [ "4" ], [ "bcd", "cd", "a", "d", "abc", "ab" ] ], [ [ "3" ], [ "i", "io", "i", "oi" ] ], [ [ "2" ], [ "g", "g" ] ], [ [ "3" ], [ "t", "al", "lt", "a" ] ], [ [ "4" ], [ "bba", "a", "ab", "a", "abb", "ba" ] ] ], "output": [ "NO", "YES", "YES", "NO", "YES" ] }, { "problem_id": "1793A", "problem_name": "Yet Another Promotion\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1793/A", "problem_solution_link": "https://codeforces.com/problemset/status/1793/problem/A", "problem_statement": "A. Yet Another Promotion\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThe famous store \"Second Food\" sells groceries only two days a month. And the prices in each of days differ. You wanted to buy $$$n$$$ kilos of potatoes for a month. You know that on the first day of the month $$$1$$$ kilo of potatoes costs $$$a$$$ coins, and on the second day $$$b$$$ coins. In \"Second Food\" you can buy any\ninteger\nkilograms of potatoes.\nFortunately, \"Second Food\" has announced a promotion for potatoes, which is valid only on the first day of the month \u2014 for each $$$m$$$ kilos of potatoes you buy, you get $$$1$$$ kilo as a gift! In other words, you can get $$$m + 1$$$ kilograms by paying for $$$m$$$ kilograms.\nFind the minimum number of coins that you have to spend to buy\nat least\n$$$n$$$ kilos of potatoes.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10\\,000$$$). Description of the test cases follows.\nThe first line of each test case contains two integers $$$a$$$ and $$$b$$$ $$$(1 \\leq a, b \\leq 10^9)$$$ \u2014 the prices of $$$1$$$ kilo of potatoes on the first and second days, respectively.\nThe second line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \\leq n, m \\leq 10^9)$$$ \u2014 the required amount of potatoes to buy and the amount of potatoes to use the promotion.\nOutput\nFor each test case print one integer \u2014 the minimum number of coins that you have to pay to buy at least $$$n$$$ kilos of potatoes.\nExample\nInput\n5\n5 4\n3 1\n5 4\n3 2\n3 4\n3 5\n20 15\n10 2\n1000000000 900000000\n1000000000 8\nOutput\n9\n10\n9\n135\n888888888900000000\nNote\nIn the first test case, on the first day you buy $$$1$$$ kilo and get $$$1$$$ more for a promotion. On the second day, you can buy $$$1$$$ kilo of potatoes. Thus, you will spend $$$5+4=9$$$ coins in total.\nIn the second test case, on the first day you buy $$$2$$$ kilo and get another $$$1$$$ more for a promotion. This way you will spend $$$2 \\cdot 5 = 10$$$ coins.", "input": [ [ [ "5", "4" ], [ "3", "1" ] ], [ [ "5", "4" ], [ "3", "2" ] ], [ [ "3", "4" ], [ "3", "5" ] ], [ [ "20", "15" ], [ "10", "2" ] ], [ [ "1000000000", "900000000" ], [ "1000000000", "8" ] ] ], "output": [ "9", "10", "9", "135", "888888888900000000" ] }, { "problem_id": "1792A", "problem_name": "GamingForces\ngreedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1792/A", "problem_solution_link": "https://codeforces.com/problemset/status/1792/problem/A", "problem_statement": "A. GamingForces\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMonocarp is playing a computer game. He's going to kill $$$n$$$ monsters, the $$$i$$$-th of them has $$$h_i$$$ health.\nMonocarp's character has two spells, either of which he can cast an arbitrary number of times (possibly, zero) and in an arbitrary order:\nchoose exactly two alive monsters and decrease their health by $$$1$$$;\nchoose a single monster and kill it.\nWhen a monster's health becomes $$$0$$$, it dies.\nWhat's the minimum number of spell casts Monocarp should perform in order to kill all monsters?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of testcases.\nThe first line of each testcase contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the number of monsters.\nThe second line contains $$$n$$$ integers $$$h_1, h_2, \\dots, h_n$$$ ($$$1 \\le h_i \\le 100$$$)\u00a0\u2014 the health of each monster.\nThe sum of $$$n$$$ over all testcases doesn't exceed $$$2 \\cdot 10^4$$$.\nOutput\nFor each testcase, print a single integer\u00a0\u2014 the minimum number of spell casts Monocarp should perform in order to kill all monsters.\nExample\nInput\n3\n4\n1 2 1 2\n3\n2 4 2\n5\n1 2 3 4 5\nOutput\n3\n3\n5\nNote\nIn the first testcase, the initial health list is $$$[1, 2, 1, 2]$$$. Three spells are casted:\nthe first spell on monsters $$$1$$$ and $$$2$$$\u00a0\u2014 monster $$$1$$$ dies, monster $$$2$$$ has now health $$$1$$$, new health list is $$$[0, 1, 1, 2]$$$;\nthe first spell on monsters $$$3$$$ and $$$4$$$\u00a0\u2014 monster $$$3$$$ dies, monster $$$4$$$ has now health $$$1$$$, new health list is $$$[0, 1, 0, 1]$$$;\nthe first spell on monsters $$$2$$$ and $$$4$$$\u00a0\u2014 both monsters $$$2$$$ and $$$4$$$ die.\nIn the second testcase, the initial health list is $$$[2, 4, 2]$$$. Three spells are casted:\nthe first spell on monsters $$$1$$$ and $$$3$$$\u00a0\u2014 both monsters have health $$$1$$$ now, new health list is $$$[1, 4, 1]$$$;\nthe second spell on monster $$$2$$$\u00a0\u2014 monster $$$2$$$ dies, new health list is $$$[1, 0, 1]$$$;\nthe first spell on monsters $$$1$$$ and $$$3$$$\u00a0\u2014 both monsters $$$1$$$ and $$$3$$$ die.\nIn the third testcase, the initial health list is $$$[1, 2, 3, 4, 5]$$$. Five spells are casted. The $$$i$$$-th of them kills the $$$i$$$-th monster with the second spell. Health list sequence: $$$[1, 2, 3, 4, 5]$$$ $$$\\rightarrow$$$ $$$[0, 2, 3, 4, 5]$$$ $$$\\rightarrow$$$ $$$[0, 0, 3, 4, 5]$$$ $$$\\rightarrow$$$ $$$[0, 0, 0, 4, 5]$$$ $$$\\rightarrow$$$ $$$[0, 0, 0, 0, 5]$$$ $$$\\rightarrow$$$ $$$[0, 0, 0, 0, 0]$$$.", "input": [ [ [ "4" ], [ "1", "2", "1", "2" ] ], [ [ "3" ], [ "2", "4", "2" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ] ] ], "output": [ "3", "3", "5" ] }, { "problem_id": "1791A", "problem_name": "Codeforces Checking\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1791/A", "problem_solution_link": "https://codeforces.com/problemset/status/1791/problem/A", "problem_statement": "A. Codeforces Checking\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven a lowercase Latin character (letter), check if it appears in the string $$$\\texttt{codeforces}$$$.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\leq t \\leq 26$$$)\u00a0\u2014 the number of test cases.\nThe only line of each test case contains a character $$$c$$$\u00a0\u2014 a single lowercase Latin character (letter).\nOutput\nFor each test case, output \"\nYES\n\" (without quotes) if $$$c$$$ satisfies the condition, and \"\nNO\n\" (without quotes) otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n10\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nOutput\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO", "input": [ [ [ "a" ] ], [ [ "b" ] ], [ [ "c" ] ], [ [ "d" ] ], [ [ "e" ] ], [ [ "f" ] ], [ [ "g" ] ], [ [ "h" ] ], [ [ "i" ] ], [ [ "j" ] ] ], "output": [ "NO", "NO", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "NO" ] }, { "problem_id": "1791C", "problem_name": "Prepend and Append\nimplementation, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1791/C", "problem_solution_link": "https://codeforces.com/problemset/status/1791/problem/C", "problem_statement": "C. Prepend and Append\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTimur initially had a binary string$$$^{\\dagger}$$$ $$$s$$$ (possibly of length $$$0$$$). He performed the following operation several (possibly zero) times:\nAdd $$$\\texttt{0}$$$ to one end of the string and $$$\\texttt{1}$$$ to the other end of the string. For example, starting from the string $$$\\texttt{1011}$$$, you can obtain either $$$\\color{red}{\\texttt{0}}\\texttt{1011}\\color{red}{\\texttt{1}}$$$ or $$$\\color{red}{\\texttt{1}}\\texttt{1011}\\color{red}{\\texttt{0}}$$$.\nYou are given Timur's final string. What is the length of the\nshortest\npossible string he could have started with?\n$$$^{\\dagger}$$$ A binary string is a string (possibly the empty string) whose characters are either $$$\\texttt{0}$$$ or $$$\\texttt{1}$$$.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of testcases.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 2000$$$)\u00a0\u2014 the length of Timur's final string.\nThe second line of each test case contains a string $$$s$$$ of length $$$n$$$ consisting of characters $$$\\texttt{0}$$$ or $$$\\texttt{1}$$$, denoting the final string.\nOutput\nFor each test case, output a single nonnegative integer\u00a0\u2014 the shortest possible length of Timur's original string. Note that Timur's original string could have been empty, in which case you should output $$$0$$$.\nExample\nInput\n9\n3\n100\n4\n0111\n5\n10101\n6\n101010\n7\n1010110\n1\n1\n2\n10\n2\n11\n10\n1011011010\nOutput\n1\n2\n5\n0\n3\n1\n0\n2\n4\nNote\nIn the first test case, the shortest possible string Timur started with is $$$\\texttt{0}$$$, and he performed the following operation: $$$\\texttt{0} \\to \\color{red}{\\texttt{1}}\\texttt{0}\\color{red}{\\texttt{0}}$$$.\nIn the second test case, the shortest possible string Timur started with is $$$\\texttt{11}$$$, and he performed the following operation: $$$\\texttt{11} \\to \\color{red}{\\texttt{0}}\\texttt{11}\\color{red}{\\texttt{1}}$$$.\nIn the third test case, the shortest possible string Timur started with is $$$\\texttt{10101}$$$, and he didn't perform any operations.\nIn the fourth test case, the shortest possible string Timur started with is the empty string (which we denote by $$$\\varepsilon$$$), and he performed the following operations: $$$\\varepsilon \\to \\color{red}{\\texttt{1}}\\texttt{}\\color{red}{\\texttt{0}} \\to \\color{red}{\\texttt{0}}\\texttt{10}\\color{red}{\\texttt{1}} \\to \\color{red}{\\texttt{1}}\\texttt{0101}\\color{red}{\\texttt{0}}$$$.\nIn the fifth test case, the shortest possible string Timur started with is $$$\\texttt{101}$$$, and he performed the following operations: $$$\\texttt{101} \\to \\color{red}{\\texttt{0}}\\texttt{101}\\color{red}{\\texttt{1}} \\to \\color{red}{\\texttt{1}}\\texttt{01011}\\color{red}{\\texttt{0}}$$$.", "input": [ [ [ "3" ], [ "100" ] ], [ [ "4" ], [ "0111" ] ], [ [ "5" ], [ "10101" ] ], [ [ "6" ], [ "101010" ] ], [ [ "7" ], [ "1010110" ] ], [ [ "1" ], [ "1" ] ], [ [ "2" ], [ "10" ] ], [ [ "2" ], [ "11" ] ], [ [ "10" ], [ "1011011010" ] ] ], "output": [ "1", "2", "5", "0", "3", "1", "0", "2", "4" ] }, { "problem_id": "1791B", "problem_name": "Following Directions\ngeometry, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1791/B", "problem_solution_link": "https://codeforces.com/problemset/status/1791/problem/B", "problem_statement": "B. Following Directions\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAlperen is standing at the point $$$(0,0)$$$. He is given a string $$$s$$$ of length $$$n$$$ and performs $$$n$$$ moves. The $$$i$$$-th move is as follows:\nif $$$s_i = \\texttt{L}$$$, then move one unit left;\nif $$$s_i = \\texttt{R}$$$, then move one unit right;\nif $$$s_i = \\texttt{U}$$$, then move one unit up;\nif $$$s_i = \\texttt{D}$$$, then move one unit down.\nIf Alperen starts at the center point, he can make the four moves shown.\nThere is a candy at $$$(1,1)$$$ (that is, one unit above and one unit to the right of Alperen's starting point). You need to determine if Alperen ever passes the candy.\nAlperen's path in the first test case.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of testcases.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 50$$$)\u00a0\u2014 the length of the string.\nThe second line of each test case contains a string $$$s$$$ of length $$$n$$$ consisting of characters $$$\\texttt{L}$$$, $$$\\texttt{R}$$$, $$$\\texttt{D}$$$, and $$$\\texttt{U}$$$, denoting the moves Alperen makes.\nOutput\nFor each test case, output \"\nYES\n\" (without quotes) if Alperen passes the candy, and \"\nNO\n\" (without quotes) otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n7\n7\nUUURDDL\n2\nUR\n8\nRRRUUDDD\n3\nLLL\n4\nDUUR\n5\nRUDLL\n11\nLLLLDDRUDRD\nOutput\nYES\nYES\nNO\nNO\nYES\nYES\nNO\nNote\nIn the first test case, Alperen follows the path $$$$$$(0,0) \\overset{\\texttt{U}}{\\to} (0,1) \\overset{\\texttt{U}}{\\to} (0,2) \\overset{\\texttt{U}}{\\to} (0,3) \\overset{\\texttt{R}}{\\to} (1,3) \\overset{\\texttt{D}}{\\to} (1,2) \\overset{\\texttt{D}}{\\to} \\color{green}{\\mathbf{(1,1)}} \\overset{\\texttt{L}}{\\to} (0,1).$$$$$$ Note that Alperen doesn't need to end at the candy's location of $$$(1,1)$$$, he just needs to pass it at some point.\nIn the second test case, Alperen follows the path $$$$$$(0,0) \\overset{\\texttt{U}}{\\to} (0,1) \\overset{\\texttt{R}}{\\to} \\color{green}{\\mathbf{(1,1)}}.$$$$$$\nIn the third test case, Alperen follows the path $$$$$$(0,0) \\overset{\\texttt{R}}{\\to} (1,0) \\overset{\\texttt{R}}{\\to} (2,0) \\overset{\\texttt{R}}{\\to} (3,0) \\overset{\\texttt{U}}{\\to} (3,1) \\overset{\\texttt{U}}{\\to} (3,2) \\overset{\\texttt{D}}{\\to} (3,1) \\overset{\\texttt{D}}{\\to} (3,0) \\overset{\\texttt{D}}{\\to} (3,-1).$$$$$$\nIn the fourth test case, Alperen follows the path $$$$$$(0,0) \\overset{\\texttt{L}}{\\to} (-1,0) \\overset{\\texttt{L}}{\\to} (-2,0) \\overset{\\texttt{L}}{\\to} (-3,0).$$$$$$", "input": [ [ [ "7" ], [ "UUURDDL" ] ], [ [ "2" ], [ "UR" ] ], [ [ "8" ], [ "RRRUUDDD" ] ], [ [ "3" ], [ "LLL" ] ], [ [ "4" ], [ "DUUR" ] ], [ [ "5" ], [ "RUDLL" ] ], [ [ "11" ], [ "LLLLDDRUDRD" ] ] ], "output": [ "YES", "YES", "NO", "NO", "YES", "YES", "NO" ] }, { "problem_id": "1790B", "problem_name": "Taisia and Dice\ngreedy, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1790/B", "problem_solution_link": "https://codeforces.com/problemset/status/1790/problem/B", "problem_statement": "B. Taisia and Dice\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTaisia has $$$n$$$ six-sided dice. Each face of the die is marked with a number from $$$1$$$ to $$$6$$$, each number from $$$1$$$ to $$$6$$$ is used once.\nTaisia rolls all $$$n$$$ dice at the same time and gets a sequence of values $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 6$$$), where $$$a_i$$$ is the value on the upper face of the $$$i$$$-th dice. The sum of this sequence is equal to $$$s$$$.\nSuddenly, Taisia's pet cat steals exactly\none\ndice with\nmaximum\nvalue $$$a_i$$$ and calculates the sum of the values on the remaining $$$n-1$$$ dice, which is equal to $$$r$$$.\nYou only know the number of dice $$$n$$$ and the values of $$$s$$$, $$$r$$$. Restore a possible sequence $$$a$$$ that fulfills the constraints.\nInput\nThe first line contains the integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of testcases.\nEach testcase is given on a separate line and contains three integers $$$n$$$, $$$s$$$, $$$r$$$ ($$$2 \\le n \\le 50$$$, $$$1 \\le r < s \\le 300$$$).\nIt is guaranteed that a solution exists.\nOutput\nFor each testcase, print: $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ in any order. It is guaranteed that such sequence exists.\nIf there are multiple solutions, print any.\nExample\nInput\n7\n2 2 1\n2 4 2\n4 9 5\n5 17 11\n3 15 10\n4 4 3\n5 20 15\nOutput\n1 1\n2 2 \n1 2 2 4\n6 4 2 3 2\n5 5 5\n1 1 1 1\n1 4 5 5 5", "input": [ [ [ "2", "2", "1" ] ], [ [ "2", "4", "2" ] ], [ [ "4", "9", "5" ] ], [ [ "5", "17", "11" ] ], [ [ "3", "15", "10" ] ], [ [ "4", "4", "3" ] ], [ [ "5", "20", "15" ] ] ], "output": [ "1 1", "2 2 ", "1 2 2 4", "6 4 2 3 2", "5 5 5", "1 1 1 1", "1 4 5 5 5" ] }, { "problem_id": "1790A", "problem_name": "Polycarp and the Day of Pi\nimplementation, math, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1790/A", "problem_solution_link": "https://codeforces.com/problemset/status/1790/problem/A", "problem_statement": "A. Polycarp and the Day of Pi\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nOn March 14, the day of the number $$$\\pi$$$ is celebrated all over the world. This is a very important mathematical constant equal to the ratio of the circumference of a circle to its diameter.\nPolycarp was told at school that the number $$$\\pi$$$ is irrational, therefore it has an infinite number of digits in decimal notation. He wanted to prepare for the Day of the number $$$\\pi$$$ by memorizing this number as accurately as possible.\nPolycarp wrote out all the digits that he managed to remember. For example, if Polycarp remembered $$$\\pi$$$ as $$$3.1415$$$, he wrote out\n31415\n.\nPolycarp was in a hurry and could have made a mistake, so you decided to check how many first digits of the number $$$\\pi$$$ Polycarp actually remembers correctly.\nInput\nThe first line of the input data contains the single integer $$$t$$$ ($$$1 \\le t \\le 10^3$$$)\u00a0\u2014 the number of test cases in the test.\nEach test case is described by a single string of digits $$$n$$$, which was written out by Polycarp.\nThe string $$$n$$$ contains up to $$$30$$$ digits.\nOutput\nOutput $$$t$$$ integers, each of which is the answer to the corresponding test case, that is how many first digits of the number $$$\\pi$$$ Polycarp remembers correctly.\nExample\nInput\n9\n000\n3\n4141592653\n141592653589793238462643383279\n31420\n31415\n314159265358\n27182\n314159265358979323846264338327\nOutput\n0\n1\n0\n0\n3\n5\n12\n0\n30", "input": [ [ [ "000" ] ], [ [ "3" ] ], [ [ "4141592653" ] ], [ [ "141592653589793238462643383279" ] ], [ [ "31420" ] ], [ [ "31415" ] ], [ [ "314159265358" ] ], [ [ "27182" ] ], [ [ "314159265358979323846264338327" ] ] ], "output": [ "0", "1", "0", "0", "3", "5", "12", "0", "30" ] }, { "problem_id": "1789B", "problem_name": "Serval and Inversion Magic\nbrute force, implementation, strings, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1789/B", "problem_solution_link": "https://codeforces.com/problemset/status/1789/problem/B", "problem_statement": "B. Serval and Inversion Magic\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nServal has a string $$$s$$$ that only consists of\n0\nand\n1\nof length $$$n$$$. The $$$i$$$-th character of $$$s$$$ is denoted as $$$s_i$$$, where $$$1\\leq i\\leq n$$$.\nServal can perform the following operation called Inversion Magic on the string $$$s$$$:\nChoose an segment $$$[l, r]$$$ ($$$1\\leq l\\leq r\\leq n$$$). For $$$l\\leq i\\leq r$$$, change $$$s_i$$$ into\n1\nif $$$s_i$$$ is\n0\n, and change $$$s_i$$$ into\n0\nif $$$s_i$$$ is\n1\n.\nFor example, let $$$s$$$ be\n010100\nand the segment $$$[2,5]$$$ is chosen. The string $$$s$$$ will be\n001010\nafter performing the Inversion Magic.\nServal wants to make $$$s$$$ a palindrome after performing Inversion Magic\nexactly once\n. Help him to determine whether it is possible.\nA string is a palindrome iff it reads the same backwards as forwards. For example,\n010010\nis a palindrome but\n10111\nis not.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1\\leq t\\leq 10^4$$$). The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2\\leq n\\leq 10^5$$$) \u2014 the length of string $$$s$$$.\nThe second line of each test case contains a binary string $$$s$$$ of length $$$n$$$. Only characters\n0\nand\n1\ncan appear in $$$s$$$.\nIt's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\\cdot 10^5$$$.\nOutput\nFor each test case, print\nYes\nif $$$s$$$ can be a palindrome after performing Inversion Magic exactly once, and print\nNo\nif not.\nYou can output\nYes\nand\nNo\nin any case (for example, strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as a positive response).\nExample\nInput\n3\n4\n1001\n5\n10010\n7\n0111011\nOutput\nYes\nYes\nNo\nNote\nIn the first test case, Serval can perform Inversion Magic on the segment $$$[1,4]$$$. The string $$$s$$$ will be\n0110\nafter the magic.\nIn the second test case, Serval can perform Inversion Magic on the segment $$$[1,3]$$$. The string $$$s$$$ will be\n01110\nafter the magic.\nIn the third test case, Serval can't make $$$s$$$ a palindrome by performing Inversion Magic exactly once.", "input": [ [ [ "4" ], [ "1001" ] ], [ [ "5" ], [ "10010" ] ], [ [ "7" ], [ "0111011" ] ] ], "output": [ "Yes", "Yes", "No" ] }, { "problem_id": "1789A", "problem_name": "Serval and Mocha's Array\nbrute force, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1789/A", "problem_solution_link": "https://codeforces.com/problemset/status/1789/problem/A", "problem_statement": "A. Serval and Mocha's Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMocha likes arrays, and Serval gave her an array consisting of positive integers as a gift.\nMocha thinks that for an array of positive integers $$$a$$$, it is\ngood\niff the\ngreatest common divisor\nof all the elements in $$$a$$$ is no more than its length. And for an array of at least $$$2$$$ positive integers, it is\nbeautiful\niff all of its prefixes whose length is no less than $$$2$$$ are good.\nFor example:\n$$$[3,6]$$$ is not good, because $$$\\gcd(3,6)=3$$$ is greater than its length $$$2$$$.\n$$$[1,2,4]$$$ is both good and beautiful, because all of its prefixes whose length is no less than $$$2$$$, which are $$$[1,2]$$$ and $$$[1,2,4]$$$, are both good.\n$$$[3,6,1]$$$ is good but not beautiful, because $$$[3,6]$$$ is not good.\nNow Mocha gives you the gift array $$$a$$$ of $$$n$$$ positive integers, and she wants to know whether array $$$a$$$ could become beautiful by reordering the elements in $$$a$$$. It is allowed to keep the array $$$a$$$ unchanged.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1\\leq t\\leq 500$$$). The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2\\leq n\\leq 100$$$) \u2014 the length of array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\\ldots,a_n$$$ ($$$1\\leq a_1,a_2,\\ldots,a_n\\leq 10^6$$$) \u2014 the elements of array $$$a$$$.\nOutput\nFor each test case, print\nYes\nif it is possible to reorder the elements in $$$a$$$ to make it beautiful, and print\nNo\nif not.\nYou can output\nYes\nand\nNo\nin any case (for example, strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as a positive response).\nExample\nInput\n6\n2\n3 6\n3\n1 2 4\n3\n3 6 1\n3\n15 35 21\n4\n35 10 35 14\n5\n1261 227821 143 4171 1941\nOutput\nNo\nYes\nYes\nNo\nYes\nYes\nNote\nIn the first test case, neither $$$[3,6]$$$ nor $$$[6,3]$$$ are beautiful, so it's impossible to obtain a beautiful array by reordering the elements in $$$a$$$.\nIn the second test case, $$$[1,2,4]$$$ is already beautiful. Keeping the array $$$a$$$ unchanged can obtain a beautiful array.", "input": [ [ [ "2" ], [ "3", "6" ] ], [ [ "3" ], [ "1", "2", "4" ] ], [ [ "3" ], [ "3", "6", "1" ] ], [ [ "3" ], [ "15", "35", "21" ] ], [ [ "4" ], [ "35", "10", "35", "14" ] ], [ [ "5" ], [ "1261", "227821", "143", "4171", "1941" ] ] ], "output": [ "No", "Yes", "Yes", "No", "Yes", "Yes" ] }, { "problem_id": "1788A", "problem_name": "One and Two\nbrute force, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1788/A", "problem_solution_link": "https://codeforces.com/problemset/status/1788/problem/A", "problem_statement": "A. One and Two\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a sequence $$$a_1, a_2, \\ldots, a_n$$$. Each element of $$$a$$$ is $$$1$$$ or $$$2$$$.\nFind out if an integer $$$k$$$ exists so that the following conditions are met.\n$$$1 \\leq k \\leq n-1$$$, and\n$$$a_1 \\cdot a_2 \\cdot \\ldots \\cdot a_k = a_{k+1} \\cdot a_{k+2} \\cdot \\ldots \\cdot a_n$$$.\nIf there exist multiple $$$k$$$ that satisfy the given condition, print the smallest.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). Description of the test cases follows.\nThe first line of each test case contains one integer $$$n$$$ ($$$2 \\leq n \\leq 1000$$$).\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 2$$$).\nOutput\nFor each test case, if there is no such $$$k$$$, print $$$-1$$$.\nOtherwise, print the smallest possible $$$k$$$.\nExample\nInput\n3\n6\n2 2 1 2 1 2\n3\n1 2 1\n4\n1 1 1 1\nOutput\n2\n-1\n1\nNote\nFor the first test case, $$$k=2$$$ satisfies the condition since $$$a_1 \\cdot a_2 = a_3 \\cdot a_4 \\cdot a_5 \\cdot a_6 = 4$$$. $$$k=3$$$ also satisfies the given condition, but the smallest should be printed.\nFor the second test case, there is no $$$k$$$ that satisfies $$$a_1 \\cdot a_2 \\cdot \\ldots \\cdot a_k = a_{k+1} \\cdot a_{k+2} \\cdot \\ldots \\cdot a_n$$$\nFor the third test case, $$$k=1$$$, $$$2$$$, and $$$3$$$ satisfy the given condition, so the answer is $$$1$$$.", "input": [ [ [ "6" ], [ "2", "2", "1", "2", "1", "2" ] ], [ [ "3" ], [ "1", "2", "1" ] ], [ [ "4" ], [ "1", "1", "1", "1" ] ] ], "output": [ "2", "-1", "1" ] }, { "problem_id": "1787A", "problem_name": "Exponential Equation\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1787/A", "problem_solution_link": "https://codeforces.com/problemset/status/1787/problem/A", "problem_statement": "A. Exponential Equation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an integer $$$n$$$.\nFind any pair of integers $$$(x,y)$$$ ($$$1\\leq x,y\\leq n$$$) such that $$$x^y\\cdot y+y^x\\cdot x = n$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1\\leq t\\leq 10^4$$$) \u2014 the number of test cases.\nEach test case contains one line with a single integer $$$n$$$ ($$$1\\leq n\\leq 10^9$$$).\nOutput\nFor each test case, if possible, print two integers $$$x$$$ and $$$y$$$ ($$$1\\leq x,y\\leq n$$$). If there are multiple answers, print any.\nOtherwise, print $$$-1$$$.\nExample\nInput\n5\n3\n7\n42\n31250\n20732790\nOutput\n-1\n-1\n2 3\n5 5\n3 13\nNote\nIn the third test case, $$$2^3 \\cdot 3+3^2 \\cdot 2 = 42$$$, so $$$(2,3),(3,2)$$$ will be considered as legal solutions.\nIn the fourth test case, $$$5^5 \\cdot 5+5^5 \\cdot 5 = 31250$$$, so $$$(5,5)$$$ is a legal solution.", "input": [ [ [ "3" ] ], [ [ "7" ] ], [ [ "42" ] ], [ [ "31250" ] ], [ [ "20732790" ] ] ], "output": [ "-1", "-1", "2 3", "5 5", "3 13" ] }, { "problem_id": "1786A2", "problem_name": "Alternating Deck (hard version)\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1786/A2", "problem_solution_link": "https://codeforces.com/problemset/status/1786/problem/A2", "problem_statement": "A2. Alternating Deck (hard version)\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThis is a hard version of the problem. In this version, there are two colors of the cards.\nAlice has $$$n$$$ cards, each card is either black or white. The cards are stacked in a deck in such a way that the card colors alternate, starting from a white card. Alice deals the cards to herself and to Bob, dealing at once several cards from the top of the deck in the following order: one card to herself, two cards to Bob, three cards to Bob, four cards to herself, five cards to herself, six cards to Bob, seven cards to Bob, eight cards to herself, and so on. In other words, on the $$$i$$$-th step, Alice deals $$$i$$$ top cards from the deck to one of the players; on the first step, she deals the cards to herself and then alternates the players every two steps. When there aren't enough cards at some step, Alice deals all the remaining cards to the current player, and the process stops.\nFirst Alice's steps in a deck of many cards.\nHow many cards of each color will Alice and Bob have at the end?\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 200$$$). The description of the test cases follows\nThe only line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^6$$$)\u00a0\u2014 the number of cards.\nOutput\nFor each test case print four integers\u00a0\u2014 the number of cards in the end for each player\u00a0\u2014 in this order: white cards Alice has, black cards Alice has, white cards Bob has, black cards Bob has.\nExample\nInput\n5\n10\n6\n17\n8\n1000000\nOutput\n3 2 2 3\n1 0 2 3\n6 4 3 4\n2 1 2 3\n250278 249924 249722 250076", "input": [ [ [ "10" ] ], [ [ "6" ] ], [ [ "17" ] ], [ [ "8" ] ], [ [ "1000000" ] ] ], "output": [ "3 2 2 3", "1 0 2 3", "6 4 3 4", "2 1 2 3", "250278 249924 249722 250076" ] }, { "problem_id": "1786A1", "problem_name": "Non-alternating Deck (easy version)\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1786/A1", "problem_solution_link": "https://codeforces.com/problemset/status/1786/problem/A1", "problem_statement": "A1. Non-alternating Deck (easy version)\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThis is an easy version of the problem. In this version, all cards have the same color.\nAlice has $$$n$$$ cards, each card is white, and the cards are stacked in a deck. Alice deals the cards to herself and to Bob, dealing at once several cards from the top of the deck in the following order: one card to herself, two cards to Bob, three cards to Bob, four cards to herself, five cards to herself, six cards to Bob, seven cards to Bob, eight cards to herself, and so on. In other words, on the $$$i$$$-th step, Alice deals $$$i$$$ top cards from the deck to one of the players; on the first step, she deals the cards to herself and then alternates the players every two steps. When there aren't enough cards at some step, Alice deals all the remaining cards to the current player, and the process stops.\nFirst Alice's steps in a deck of many cards.\nHow many cards will Alice and Bob have at the end?\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 200$$$). The description of the test cases follows\nThe only line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^6$$$)\u00a0\u2014 the number of cards.\nOutput\nFor each test case print two integers\u00a0\u2014 the number of cards in the end for each player\u00a0\u2014 in this order: cards Alice has, cards Bob has.\nExample\nInput\n5\n10\n6\n17\n8\n1000000\nOutput\n5 5\n1 5\n10 7\n3 5\n500202 499798", "input": [ [ [ "10" ] ], [ [ "6" ] ], [ [ "17" ] ], [ [ "8" ] ], [ [ "1000000" ] ] ], "output": [ "5 5", "1 5", "10 7", "3 5", "500202 499798" ] }, { "problem_id": "1783A", "problem_name": "Make it Beautiful\nconstructive algorithms, math, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1783/A", "problem_solution_link": "https://codeforces.com/problemset/status/1783/problem/A", "problem_statement": "A. Make it Beautiful\ntime limit per test\n3 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nAn array $$$a$$$ is called\nugly\nif it contains\nat least one\nelement which is equal to the\nsum of all elements before it\n. If the array is not ugly, it is\nbeautiful\n.\nFor example:\nthe array $$$[6, 3, 9, 6]$$$ is ugly: the element $$$9$$$ is equal to $$$6 + 3$$$;\nthe array $$$[5, 5, 7]$$$ is ugly: the element $$$5$$$ (the second one) is equal to $$$5$$$;\nthe array $$$[8, 4, 10, 14]$$$ is beautiful: $$$8 \\ne 0$$$, $$$4 \\ne 8$$$, $$$10 \\ne 8 + 4$$$, $$$14 \\ne 8 + 4 + 10$$$, so there is no element which is equal to the sum of all elements before it.\nYou are given an array $$$a$$$ such that $$$1 \\le a_1 \\le a_2 \\le \\dots \\le a_n \\le 100$$$. You have to\nreorder\nthe elements of $$$a$$$ in such a way that the resulting array is beautiful. Note that you are not allowed to insert new elements or erase existing ones, you can only change the order of elements of $$$a$$$. You are allowed to keep the array $$$a$$$ unchanged, if it is beautiful.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 2000$$$) \u2014 the number of test cases.\nEach test case consists of two lines. The first line contains one integer $$$n$$$ ($$$2 \\le n \\le 50$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_1 \\le a_2 \\le \\dots \\le a_n \\le 100$$$).\nOutput\nFor each test case, print the answer as follows:\nif it is impossible to reorder the elements of $$$a$$$ in such a way that it becomes beautiful, print\nNO\n;\notherwise, in the first line, print\nYES\n. In the second line, print $$$n$$$ integers \u2014 any beautiful array which can be obtained from $$$a$$$ by reordering its elements. If there are multiple such arrays, print any of them.\nExample\nInput\n4\n4\n3 3 6 6\n2\n10 10\n5\n1 2 3 4 5\n3\n1 4 4\nOutput\nYES\n3 6 3 6\nNO\nYES\n2 4 1 5 3\nYES\n1 4 4", "input": [ [ [ "4" ], [ "3", "3", "6", "6" ] ], [ [ "2" ], [ "10", "10" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ] ], [ [ "3" ], [ "1", "4", "4" ] ] ], "output": [ ["YES", "3 6 3 6"], ["NO"], ["YES", "2 4 1 5 3"], ["YES", "1 4 4"] ], "error": true }, { "problem_id": "1781A", "problem_name": "Parallel Projection\ngeometry, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1781/A", "problem_solution_link": "https://codeforces.com/problemset/status/1781/problem/A", "problem_statement": "A. Parallel Projection\ntime limit per test\n1 second\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nVika's house has a room in a shape of a rectangular parallelepiped (also known as a rectangular cuboid). Its floor is a rectangle of size $$$w \\times d$$$, and the ceiling is right above at the constant height of $$$h$$$. Let's introduce a coordinate system on the floor so that its corners are at points $$$(0, 0)$$$, $$$(w, 0)$$$, $$$(w, d)$$$, and $$$(0, d)$$$.\nA laptop is standing on the floor at point $$$(a, b)$$$. A projector is hanging on the ceiling right above point $$$(f, g)$$$. Vika wants to connect the laptop and the projector with a cable in such a way that the cable always goes along the walls, ceiling, or floor (i.\u00a0e. does not go inside the cuboid). Additionally, the cable should always run\nparallel\nto one of the cuboid's edges (i.\u00a0e. it can not go diagonally).\nWhat is the minimum length of a cable that can connect the laptop to the projector?\nIllustration for the first test case. One of the optimal ways to put the cable is shown in green.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^4$$$). The description of the test cases follows.\nThe first line of each test case contains three integers $$$w$$$, $$$d$$$, and $$$h$$$ ($$$2 \\le w, d, h \\le 1000$$$)\u00a0\u2014 the size of the room.\nThe second line contains four integers $$$a$$$, $$$b$$$, $$$f$$$, $$$g$$$ ($$$0 < a, f < w$$$; $$$0 < b, g < d$$$): the laptop is located on the floor at point $$$(a, b)$$$, while the projector is hanging on the ceiling right above point $$$(f, g)$$$.\nOutput\nFor each test case, print a single integer\u00a0\u2014 the minimum length of the cable connecting the laptop and the projector that runs only along the walls, floor, and ceiling parallel to cuboid's edges.\nExample\nInput\n5\n55 20 29\n23 10 18 3\n20 10 5\n1 5 2 5\n15 15 4\n7 13 10 10\n2 1000 2\n1 1 1 999\n10 4 10\n7 1 2 1\nOutput\n47\n8\n14\n1002\n17\nNote\nThe picture in the statement illustrates the first test case.", "input": [ [ [ "55", "20", "29" ], [ "23", "10", "18", "3" ] ], [ [ "20", "10", "5" ], [ "1", "5", "2", "5" ] ], [ [ "15", "15", "4" ], [ "7", "13", "10", "10" ] ], [ [ "2", "1000", "2" ], [ "1", "1", "1", "999" ] ], [ [ "10", "4", "10" ], [ "7", "1", "2", "1" ] ] ], "output": [ "47", "8", "14", "1002", "17" ] }, { "problem_id": "1780A", "problem_name": "Hayato and School\nconstructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1780/A", "problem_solution_link": "https://codeforces.com/problemset/status/1780/problem/A", "problem_statement": "A. Hayato and School\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nToday Hayato came home from school with homework.\nIn the assignment, Hayato was given an array $$$a$$$ of length $$$n$$$. The task was to find $$$3$$$ numbers in this array whose sum is\nodd\n. At school, he claimed that there are such $$$3$$$ numbers, but Hayato was not sure, so he asked you for help.\nAnswer if there are such three numbers, and if so, output indices $$$i$$$, $$$j$$$, and $$$k$$$ such that $$$a_i + a_j + a_k$$$ is odd.\nThe odd numbers are integers that are not divisible by $$$2$$$: $$$1$$$, $$$3$$$, $$$5$$$, and so on.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases.\nFor each test case, the first line contains one integer $$$n$$$ ($$$3 \\le n \\le 300$$$) \u2014 the length of $$$a$$$.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 10^5$$$) \u2014 the array $$$a$$$.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\\cdot10^5$$$.\nOutput\nFor each test case, in the first line print one word \"\nYES\n\" (without quotes) if there are $$$3$$$ numbers with an odd sum or \"\nNO\n\" (without quotes) if there are no such $$$3$$$ numbers.\nIf the answer exists, then on the second line print $$$3$$$ distinct integers $$$i, j, k$$$ ($$$1 \\le i, j, k \\le n$$$) \u2014 the indices of the numbers. If there are several answers, output any.\nExample\nInput\n6\n3\n1 1 1\n4\n1 1 2 2\n3\n1 2 3\n5\n1 4 5 1 2\n4\n2 6 2 4\n5\n5 6 3 2 1\nOutput\nYES\n1 2 3\nYES\n3 4 1\nNO\nYES\n1 3 4\nNO\nYES\n1 3 5\nNote\nIn the first test case, there is one way to choose $$$3$$$ numbers, and since $$$1 + 1 + 1 = 3$$$, this triple is fine for us.\nIn the second test case, you need to choose the numbers $$$1, 2, 2$$$, since $$$1 + 2 + 2 = 5$$$.\nIn the third test case, there is one way to choose three numbers, but $$$1 + 2 + 3 = 6$$$ is an even number, so the required triple does not exist.\nIn the fifth test case, no matter what three numbers we choose, their sum is even.", "input": [ [ [ "3" ], [ "1", "1", "1" ] ], [ [ "4" ], [ "1", "1", "2", "2" ] ], [ [ "3" ], [ "1", "2", "3" ] ], [ [ "5" ], [ "1", "4", "5", "1", "2" ] ], [ [ "4" ], [ "2", "6", "2", "4" ] ], [ [ "5" ], [ "5", "6", "3", "2", "1" ] ] ], "output": [ ["YES", "1 2 3"], ["YES", "3 4 1"], ["NO"], ["YES", "1 3 4"], ["NO"], ["YES", "1 3 5"] ], "error": true }, { "problem_id": "1779A", "problem_name": "Hall of Fame\nconstructive algorithms, greedy, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1779/A", "problem_solution_link": "https://codeforces.com/problemset/status/1779/problem/A", "problem_statement": "A. Hall of Fame\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThalia is a Legendary Grandmaster in chess. She has $$$n$$$ trophies in a line numbered from $$$1$$$ to $$$n$$$ (from left to right) and a lamp standing next to each of them (the lamps are numbered as the trophies).\nA lamp can be directed either to the left or to the right, and it illuminates all trophies in that direction (but not the one it is next to). More formally, Thalia has a string $$$s$$$ consisting only of characters '\nL\n' and '\nR\n' which represents the lamps' current directions. The lamp $$$i$$$ illuminates:\ntrophies $$$1,2,\\ldots, i-1$$$ if $$$s_i$$$ is '\nL\n';\ntrophies $$$i+1,i+2,\\ldots, n$$$ if $$$s_i$$$ is '\nR\n'.\nShe can perform the following operation\nat most\nonce:\nChoose an index $$$i$$$ ($$$1 \\leq i < n$$$);\nSwap the lamps $$$i$$$ and $$$i+1$$$ (without changing their directions). That is, swap $$$s_i$$$ with $$$s_{i+1}$$$.\nThalia asked you to illuminate all her trophies (make each trophy illuminated by at least one lamp), or to tell her that it is impossible to do so. If it is possible, you can choose to perform an operation or to do nothing. Notice that lamps\ncannot\nchange direction, it is only allowed to swap adjacent ones.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\leq t \\leq 10\\,000$$$). The description of the test cases follows.\nThe first line of each test case contains a positive integer $$$n$$$ ($$$2 \\leq n \\leq 100\\,000$$$) \u00a0\u2014 the number of trophies.\nThe second line of each test case contains a string $$$s$$$ of length $$$n$$$ consisting only of characters '\nL\n' and '\nR\n' \u00a0\u2014 the $$$i$$$-th character describes the direction of the $$$i$$$-th lamp.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$100\\,000$$$.\nOutput\nFor each test case print $$$-1$$$ if it is impossible to illuminate all trophies by performing one operation (or doing nothing). Otherwise, print $$$0$$$ if you choose not to perform the operation (i.e., the trophies are illuminated by the initial positioning of the lamps), or an index $$$i$$$ ($$$1 \\leq i < n$$$) if you choose to swap lamps $$$i$$$ and $$$i+1$$$.\nIf there are multiple answers, print any.\nExample\nInput\n6\n2\nLL\n2\nLR\n2\nRL\n2\nRR\n7\nLLRLLLR\n7\nRRLRRRL\nOutput\n-1\n1\n0\n-1\n3\n6\nNote\nIn the first example, it is possible to swap lamps $$$1$$$ and $$$2$$$, or do nothing. In any case, the string \"\nLL\n\" is obtained. Not all trophies are illuminated since trophy $$$2$$$ is not illuminated by any lamp \u00a0\u2014 lamp $$$1$$$ illuminates nothing and lamp $$$2$$$ illuminates only the trophy $$$1$$$.\nIn the second example, it is necessary to swap lamps $$$1$$$ and $$$2$$$. The string becomes \"\nRL\n\". Trophy $$$1$$$ is illuminated by lamp $$$2$$$ and trophy $$$2$$$ is illuminated by lamp $$$1$$$, hence it is possible to illuminate all trophies.\nIn the third example, all trophies are initially illuminated \u00a0\u2014 hence, not performing any operation is a valid solution.\nIn the last two examples performing swaps is not necessary as all trophies are illuminated initially. But, the presented solutions are also valid.", "input": [ [ [ "2" ], [ "LL" ] ], [ [ "2" ], [ "LR" ] ], [ [ "2" ], [ "RL" ] ], [ [ "2" ], [ "RR" ] ], [ [ "7" ], [ "LLRLLLR" ] ], [ [ "7" ], [ "RRLRRRL" ] ] ], "output": [ "-1", "1", "0", "-1", "3", "6" ] }, { "problem_id": "1778A", "problem_name": "Flip Flop Sum\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1778/A", "problem_solution_link": "https://codeforces.com/problemset/status/1778/problem/A", "problem_statement": "A. Flip Flop Sum\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array of $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$. The integers are either $$$1$$$ or $$$-1$$$. You have to perform the following operation\nexactly once\non the array $$$a$$$:\nChoose an index $$$i$$$ ($$$1 \\leq i < n$$$) and flip the signs of $$$a_i$$$ and $$$a_{i+1}$$$. Here, flipping the sign means $$$-1$$$ will be $$$1$$$ and $$$1$$$ will be $$$-1$$$.\nWhat is the maximum possible value of $$$a_1 + a_2 + \\ldots + a_n$$$ after applying the above operation?\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 500$$$). Description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 10^5$$$), the length of the array $$$a$$$.\nThe next line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$a_i = 1$$$ or $$$a_i = -1$$$).\nThe sum of $$$n$$$ over all cases doesn't exceed $$$10^5$$$.\nOutput\nFor each test case, print the maximum possible sum of the array $$$a$$$ you can get in a separate line.\nExample\nInput\n4\n5\n-1 1 1 -1 -1\n5\n1 1 -1 -1 -1\n2\n1 1\n4\n1 -1 -1 1\nOutput\n3\n3\n-2\n4\nNote\nIn the first case, we can choose index $$$4$$$ and flip the signs of $$$a_4$$$ and $$$a_5$$$. After this operation, the sum will be $$$-1+1+1+1+1 = 3$$$. We can't make the sum larger than this.\nIn the third case, the only option is to choose the index $$$1$$$.", "input": [ [ [ "5" ], [ "-1", "1", "1", "-1", "-1" ] ], [ [ "5" ], [ "1", "1", "-1", "-1", "-1" ] ], [ [ "2" ], [ "1", "1" ] ], [ [ "4" ], [ "1", "-1", "-1", "1" ] ] ], "output": [ "3", "3", "-2", "4" ] }, { "problem_id": "1777A", "problem_name": "Everybody Likes Good Arrays!\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1777/A", "problem_solution_link": "https://codeforces.com/problemset/status/1777/problem/A", "problem_statement": "A. Everybody Likes Good Arrays!\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAn array $$$a$$$ is\ngood\nif for all pairs of adjacent elements, $$$a_i$$$ and $$$a_{i+1}$$$ ($$$1\\le i \\lt n$$$) are of\ndifferent\nparity. Note that an array of size $$$1$$$ is trivially good.\nYou are given an array of size $$$n$$$.\nIn one operation you can select any pair of adjacent elements in which both elements are of the\nsame\nparity, delete them, and insert their product in the same position.\nFind the minimum number of operations to form a good array.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 500$$$). The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 100$$$).\nThe second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\\ldots,a_n$$$ ($$$1 \\le a_i \\le 10^{9}$$$).\nOutput\nFor each test case print an integer, the minimum number of operations required to form a good array.\nExample\nInput\n3\n5\n1 7 11 2 13\n4\n1 2 3 4\n6\n1 1 1 2 2 3\nOutput\n2\n0\n3\nNote\nConsider the first test case. Select the $$$2$$$-nd and the $$$3$$$-rd integers and apply the operation on them. The array changes from $$$[1, \\color{red}{7}, \\color{red}{11}, 2, 13]$$$ to $$$[1, \\color{red}{77}, 2, 13]$$$. Next, select the $$$1$$$-st and the $$$2$$$-nd integers, array changes from $$$[\\color{red}{1}, \\color{red}{77}, 2, 13]$$$ to $$$[\\color{red}{77}, 2, 13]$$$. Thus we require $$$2$$$ operations. It can be proved that this is the minimum number of operations.\nIn the second test case, the given array is already good. So we require $$$0$$$ operations.", "input": [ [ [ "5" ], [ "1", "7", "11", "2", "13" ] ], [ [ "4" ], [ "1", "2", "3", "4" ] ], [ [ "6" ], [ "1", "1", "1", "2", "2", "3" ] ] ], "output": [ "2", "0", "3" ] }, { "problem_id": "1776A", "problem_name": "Walking Boy\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1776/A", "problem_solution_link": "https://codeforces.com/problemset/status/1776/problem/A", "problem_statement": "A. Walking Boy\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nOne of the SWERC judges has a dog named Boy. Besides being a good competitive programmer, Boy loves fresh air, so she wants to be walked at least twice a day. Walking Boy requires $$$120$$$\nconsecutive\nminutes. Two walks cannot overlap, but one can start as soon as the previous one has finished.\nBoy before and after getting ACCEPTED on this problem.\nToday, the judge sent $$$n$$$ messages to the SWERC Discord server. The $$$i$$$-th message was sent $$$a_i$$$ minutes after midnight. You know that, when walking Boy, the judge does not send any messages, but he can send a message right before or right after a walk. Is it possible that the judge walked Boy at least twice today?\nNote that a day has $$$1440$$$ minutes, and a walk is considered to happen\ntoday\nif it starts at a minute $$$s \\ge 0$$$ and ends right before a minute $$$e \\le 1440$$$. In that case, it must hold that $$$e - s = 120$$$ and, for every $$$i = 1, \\, 2 \\, \\dots, \\, n$$$, either $$$a_i \\le s$$$ or $$$a_i \\ge e$$$.\nInput\nEach test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases. The descriptions of the $$$t$$$ test cases follow.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the number of messages sent by the judge.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, \\, a_2, \\, \\dots, \\, a_n$$$ ($$$0 \\le a_1 < a_2 < \\cdots < a_n < 1440$$$) \u2014 the times at which the messages have been sent (in minutes elapsed from midnight).\nOutput\nFor each test case, output one line containing $$$\\texttt{YES}$$$ if it is possible that Boy has been walked at least twice, and $$$\\texttt{NO}$$$ otherwise.\nExample\nInput\n6\n14\n100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400\n12\n100 200 300 400 600 700 800 900 1100 1200 1300 1400\n13\n100 200 300 400 500 600 700 800 900 1100 1200 1300 1400\n13\n101 189 272 356 463 563 659 739 979 1071 1170 1274 1358\n1\n42\n5\n0 1 2 3 4\nOutput\nNO\nYES\nNO\nYES\nYES\nYES\nNote\nIn the\nfirst test case\n, the judge has sent a message at each time multiple of $$$100$$$ (excluding $$$0$$$). It is impossible that he has walked Boy even once.\nIn the\nsecond test case\n, the times are the same as above, but $$$500$$$ and $$$1000$$$ are missing. The judge could have walked Boy, for instance, during the time intervals $$$[440, 560]$$$ and $$$[980, 1100]$$$. The situation is illustrated in the picture below, where the walks are represented by green intervals.\n$$$$$$$$$$$$\nIn the\nthird test case\n, the times are the same as in the first test case, but $$$1000$$$ is missing. The judge could have walked Boy at most once.\nIn the\nfourth test case\n, Boy could have been walked during the time intervals $$$[739, 859]$$$ and $$$[859, 979]$$$.", "input": [ [ [ "14" ], [ "100", "200", "300", "400", "500", "600", "700", "800", "900", "1000", "1100", "1200", "1300", "1400" ] ], [ [ "12" ], [ "100", "200", "300", "400", "600", "700", "800", "900", "1100", "1200", "1300", "1400" ] ], [ [ "13" ], [ "100", "200", "300", "400", "500", "600", "700", "800", "900", "1100", "1200", "1300", "1400" ] ], [ [ "13" ], [ "101", "189", "272", "356", "463", "563", "659", "739", "979", "1071", "1170", "1274", "1358" ] ], [ [ "1" ], [ "42" ] ], [ [ "5" ], [ "0", "1", "2", "3", "4" ] ] ], "output": [ "NO", "YES", "NO", "YES", "YES", "YES" ] }, { "problem_id": "1775A1", "problem_name": "Gardener and the Capybaras (easy version)\nbrute force, constructive algorithms, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1775/A1", "problem_solution_link": "https://codeforces.com/problemset/status/1775/problem/A1", "problem_statement": "A1. Gardener and the Capybaras (easy version)\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThis is an easy version of the problem. The difference between the versions is that the string can be longer than in the easy version. You can only do hacks if both versions of the problem are passed.\nKazimir Kazimirovich is a Martian gardener. He has a huge orchard of binary balanced apple trees.\nRecently Casimir decided to get himself three capybaras. The gardener even came up with their names and wrote them down on a piece of paper. The name of each capybara is a non-empty line consisting of letters \"\na\n\" and \"\nb\n\".\nDenote the names of the capybaras by the lines $$$a$$$, $$$b$$$, and $$$c$$$. Then Casimir wrote the nonempty lines $$$a$$$, $$$b$$$, and $$$c$$$ in a row without spaces. For example, if the capybara's name was \"\naba\n\", \"\nab\n\", and \"\nbb\n\", then the string the gardener wrote down would look like \"\nabaabbb\n\".\nThe gardener remembered an interesting property: either the string $$$b$$$ is lexicographically not smaller than the strings $$$a$$$ and $$$c$$$ at the same time, or the string $$$b$$$ is lexicographically not greater than the strings $$$a$$$ and $$$c$$$ at the same time. In other words, either $$$a \\le b$$$ and $$$c \\le b$$$ are satisfied, or $$$b \\le a$$$ and $$$b \\le c$$$ are satisfied (or possibly both conditions simultaneously). Here $$$\\le$$$ denotes the lexicographic \"less than or equal to\" for strings. Thus, $$$a \\le b$$$ means that the strings must either be equal, or the string $$$a$$$ must stand earlier in the dictionary than the string $$$b$$$. For a more detailed explanation of this operation, see \"Notes\" section.\nToday the gardener looked at his notes and realized that he cannot recover the names because they are written without spaces. He is no longer sure if he can recover the original strings $$$a$$$, $$$b$$$, and $$$c$$$, so he wants to find any triplet of names that satisfy the above property.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 500$$$). The description of the test cases follows.\nThe only line of a test case contains the string $$$s$$$ ($$$3 \\le |s| \\le 100$$$)\u00a0\u2014 the names of the capybaras, written together. The string consists of English letters '\na\n' and '\nb\n' only.\nIt is guaranteed that the sum of string lengths over all test cases does not exceed $$$500$$$.\nOutput\nFor each test case, print three strings $$$a$$$, $$$b$$$ and $$$c$$$ on a single line, separated by spaces\u00a0\u2014 names of capybaras, such that writing them without spaces results in a line $$$s$$$. Either $$$a \\le b$$$ and $$$c \\le b$$$, or $$$b \\le a$$$ and $$$b \\le c$$$ must be satisfied.\nIf there are several ways to restore the names, print any of them. If the names cannot be recovered, print \"\n:(\n\" (without quotes).\nExample\nInput\n5\nbbba\naba\naaa\nabba\nabbb\nOutput\nb bb a\na b a\na a a\nab b a\na bb b\nNote\nA string $$$x$$$ is lexicographically smaller than a string $$$y$$$ if and only if one of the following holds:\n$$$x$$$ is a prefix of $$$y$$$, but $$$x \\ne y$$$;\nin the first position where $$$x$$$ and $$$y$$$ differ, the string $$$x$$$ has the letter '\na\n', and the string $$$y$$$ has the letter '\nb\n'.\nNow let's move on to the examples.\nIn the first test case, one of the possible ways to split the line $$$s$$$ into three lines\u00a0\u2014 \"\nb\n\", \"\nbb\n\", \"\na\n\".\nIn the third test case, we can see that the split satisfies two conditions at once (i.\u00a0e., $$$a \\le b$$$, $$$c \\le b$$$, $$$b \\le a$$$, and $$$b \\le c$$$ are true simultaneously).", "input": [ [ [ "bbba" ] ], [ [ "aba" ] ], [ [ "aaa" ] ], [ [ "abba" ] ], [ [ "abbb" ] ] ], "output": [ "b bb a", "a b a", "a a a", "ab b a", "a bb b" ] }, { "problem_id": "1774A", "problem_name": "Add Plus Minus Sign\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1774/A", "problem_solution_link": "https://codeforces.com/problemset/status/1774/problem/A", "problem_statement": "A. Add Plus Minus Sign\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAquaMoon has a string $$$a$$$ consisting of only $$$0$$$ and $$$1$$$. She wants to add $$$+$$$ and $$$-$$$ between all pairs of consecutive positions to make the absolute value of the resulting expression as small as possible. Can you help her?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 2\\,000$$$) \u00a0\u2013 the number of test cases. The description of test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$) \u2014 the length of $$$a$$$.\nThe second line of each test case contains a string $$$a$$$ of length $$$n$$$, consisting of only $$$0$$$ and $$$1$$$.\nOutput\nFor each test case, output a string of length $$$n - 1$$$ consisting of $$$-$$$ and $$$+$$$ on a separate line. If there is more than one assignment of signs that produces the smallest possible absolute value, any of them is accepted.\nExample\nInput\n3\n2\n11\n5\n01101\n5\n10001\nOutput\n-\n+-++\n+++-\nNote\nIn the first test case, we can get the expression $$$1 - 1 = 0$$$, with absolute value $$$0$$$.\nIn the second test case, we can get the expression $$$0 + 1 - 1 + 0 + 1 = 1$$$, with absolute value $$$1$$$.\nIn the third test case, we can get the expression $$$1 + 0 + 0 + 0 - 1 = 0$$$, with absolute value $$$0$$$.", "input": [ [ [ "2" ], [ "11" ] ], [ [ "5" ], [ "01101" ] ], [ [ "5" ], [ "10001" ] ] ], "output": [ "-", "+-++", "+++-" ] }, { "problem_id": "1772B", "problem_name": "Matrix Rotation\nbrute force, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1772/B", "problem_solution_link": "https://codeforces.com/problemset/status/1772/problem/B", "problem_statement": "B. Matrix Rotation\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have a matrix $$$2 \\times 2$$$ filled with\ndistinct\nintegers. You want your matrix to become beautiful. The matrix is beautiful if the following two conditions are satisfied:\nin each row, the first element is smaller than the second element;\nin each column, the first element is smaller than the second element.\nYou can perform the following operation on the matrix any number of times: rotate it clockwise by $$$90$$$ degrees, so the top left element shifts to the top right cell, the top right element shifts to the bottom right cell, and so on:\nDetermine if it is possible to make the matrix beautiful by applying zero or more operations.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases.\nEach test case consists of two lines. Each of those lines contains two integers \u2014 the elements of the corresponding row of the matrix. In each matrix, all four elements are distinct integers from $$$1$$$ to $$$100$$$.\nOutput\nFor each test case, print\nYES\nif the matrix can become beautiful, or\nNO\notherwise. You may print each letter in any case (\nYES\n,\nyes\n,\nYes\nwill all be recognized as positive answer,\nNO\n,\nno\nand\nnO\nwill all be recognized as negative answer).\nExample\nInput\n6\n1 3\n5 7\n8 10\n3 4\n8 10\n4 3\n6 1\n9 2\n7 5\n4 2\n1 2\n4 3\nOutput\nYES\nYES\nNO\nYES\nYES\nNO", "input": [ [ [ "1", "3" ], [ "5", "7" ] ], [ [ "8", "10" ], [ "3", "4" ] ], [ [ "8", "10" ], [ "4", "3" ] ], [ [ "6", "1" ], [ "9", "2" ] ], [ [ "7", "5" ], [ "4", "2" ] ], [ [ "1", "2" ], [ "4", "3" ] ] ], "output": [ "YES", "YES", "NO", "YES", "YES", "NO" ] }, { "problem_id": "1772A", "problem_name": "A+B?\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1772/A", "problem_solution_link": "https://codeforces.com/problemset/status/1772/problem/A", "problem_statement": "A. A+B?\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an expression of the form $$$a{+}b$$$, where $$$a$$$ and $$$b$$$ are integers from $$$0$$$ to $$$9$$$. You have to evaluate it and print the result.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases.\nEach test case consists of one line containing an expression of the form $$$a{+}b$$$ ($$$0 \\le a, b \\le 9$$$, both $$$a$$$ and $$$b$$$ are integers). The integers are\nnot\nseparated from the $$$+$$$ sign.\nOutput\nFor each test case, print one integer \u2014 the result of the expression.\nExample\nInput\n4\n4+2\n0+0\n3+7\n8+9\nOutput\n6\n0\n10\n17", "input": [ [ [ "4+2" ] ], [ [ "0+0" ] ], [ [ "3+7" ] ], [ [ "8+9" ] ] ], "output": [ "6", "0", "10", "17" ] }, { "problem_id": "1768A", "problem_name": "Greatest Convex\ngreedy, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1768/A", "problem_solution_link": "https://codeforces.com/problemset/status/1768/problem/A", "problem_statement": "A. Greatest Convex\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an integer $$$k$$$. Find the largest integer $$$x$$$, where $$$1 \\le x < k$$$, such that $$$x! + (x - 1)!^\\dagger$$$ is a multiple of $$$^\\ddagger$$$ $$$k$$$, or determine that no such $$$x$$$ exists.\n$$$^\\dagger$$$ $$$y!$$$ denotes the factorial of $$$y$$$, which is defined recursively as $$$y! = y \\cdot (y-1)!$$$ for $$$y \\geq 1$$$ with the base case of $$$0! = 1$$$. For example, $$$5! = 5 \\cdot 4 \\cdot 3 \\cdot 2 \\cdot 1 \\cdot 0! = 120$$$.\n$$$^\\ddagger$$$ If $$$a$$$ and $$$b$$$ are integers, then $$$a$$$ is a multiple of $$$b$$$ if there exists an integer $$$c$$$ such that $$$a = b \\cdot c$$$. For example, $$$10$$$ is a multiple of $$$5$$$ but $$$9$$$ is not a multiple of $$$6$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. The description of test cases follows.\nThe only line of each test case contains a single integer $$$k$$$ ($$$2 \\le k \\le 10^9$$$).\nOutput\nFor each test case output a single integer\u00a0\u2014 the largest possible integer $$$x$$$ that satisfies the conditions above.\nIf no such $$$x$$$ exists, output $$$-1$$$.\nExample\nInput\n4\n3\n6\n8\n10\nOutput\n2\n5\n7\n9\nNote\nIn the first test case, $$$2! + 1! = 2 + 1 = 3$$$, which is a multiple of $$$3$$$.\nIn the third test case, $$$7! + 6! = 5040 + 720 = 5760$$$, which is a multiple of $$$8$$$.", "input": [ [ [ "3" ] ], [ [ "6" ] ], [ [ "8" ] ], [ [ "10" ] ] ], "output": [ "2", "5", "7", "9" ] }, { "problem_id": "1767B", "problem_name": "Block Towers\ndata structures, greedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1767/B", "problem_solution_link": "https://codeforces.com/problemset/status/1767/problem/B", "problem_statement": "B. Block Towers\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ block towers, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th tower consists of $$$a_i$$$ blocks.\nIn one move, you can move one block from tower $$$i$$$ to tower $$$j$$$, but only if $$$a_i > a_j$$$. That move increases $$$a_j$$$ by $$$1$$$ and decreases $$$a_i$$$ by $$$1$$$. You can perform as many moves as you would like (possibly, zero).\nWhat's the largest amount of blocks you can have on the tower $$$1$$$ after the moves?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of testcases.\nThe first line of each testcase contains a single integer $$$n$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$)\u00a0\u2014 the number of towers.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$)\u00a0\u2014 the number of blocks on each tower.\nThe sum of $$$n$$$ over all testcases doesn't exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each testcase, print the largest amount of blocks you can have on the tower $$$1$$$ after you make any number of moves (possibly, zero).\nExample\nInput\n4\n3\n1 2 3\n3\n1 2 2\n2\n1 1000000000\n10\n3 8 6 7 4 1 2 4 10 1\nOutput\n3\n2\n500000001\n9\nNote\nIn the first testcase, you can move a block from tower $$$2$$$ to tower $$$1$$$, making the block counts $$$[2, 1, 3]$$$. Then move a block from tower $$$3$$$ to tower $$$1$$$, making the block counts $$$[3, 1, 2]$$$. Tower $$$1$$$ has $$$3$$$ blocks in it, and you can't obtain a larger amount.\nIn the second testcase, you can move a block from any of towers $$$2$$$ or $$$3$$$ to tower $$$1$$$, so that it has $$$2$$$ blocks in it.\nIn the third testcase, you can $$$500000000$$$ times move a block from tower $$$2$$$ to tower $$$1$$$. After that the block countes will be $$$[500000001, 500000000]$$$.", "input": [ [ [ "3" ], [ "1", "2", "3" ] ], [ [ "3" ], [ "1", "2", "2" ] ], [ [ "2" ], [ "1", "1000000000" ] ], [ [ "10" ], [ "3", "8", "6", "7", "4", "1", "2", "4", "10", "1" ] ] ], "output": [ "3", "2", "500000001", "9" ] }, { "problem_id": "1767A", "problem_name": "Cut the Triangle\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1767/A", "problem_solution_link": "https://codeforces.com/problemset/status/1767/problem/A", "problem_statement": "A. Cut the Triangle\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a non-degenerate triangle (a non-degenerate triangle is a triangle with positive area). The vertices of the triangle have coordinates $$$(x_1, y_1)$$$, $$$(x_2, y_2)$$$ and $$$(x_3, y_3)$$$.\nYou want to draw a straight line to cut the triangle into\ntwo non-degenerate triangles\n. Furthermore, the line you draw should be\neither horizontal or vertical\n.\nCan you draw the line to meet all the constraints?\nHere are some suitable ways to draw the line:\nHowever, these ways to draw the line are not suitable (the first line cuts the triangle into a triangle and a quadrangle; the second line doesn't cut the triangle at all; the third line is neither horizontal nor vertical):\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases.\nEach test case consists of four lines. The first of them is empty. The $$$i$$$-th of the next three lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \\le x_i, y_i \\le 10^8$$$) \u2014 the coordinates of the $$$i$$$-th vertex of the triangle.\nAdditional constraint on the input: in each test case, the triangle formed by three vertices has positive area (i.\u2009e. it is non-degenerate).\nOutput\nFor each test case, print\nYES\nif it is possible to cut the triangle according to the statement, or\nNO\notherwise. You may print each letter in any case (\nYES\n,\nyes\n,\nYes\nwill all be recognized as positive answer,\nNO\n,\nno\nand\nnO\nwill all be recognized as negative answer).\nExample\nInput\n4\n4 7\n6 8\n3 5\n4 5\n4 7\n6 8\n5 8\n1 8\n2 5\n3 6\n6 6\n6 3\nOutput\nYES\nYES\nYES\nNO", "input": [ [ [ "4", "7" ], [ "6", "8" ], [ "3", "5" ] ], [ [ "4", "5" ], [ "4", "7" ], [ "6", "8" ] ], [ [ "5", "8" ], [ "1", "8" ], [ "2", "5" ] ], [ [ "3", "6" ], [ "6", "6" ], [ "6", "3" ] ] ], "output": [ "YES", "YES", "YES", "NO" ] }, { "problem_id": "1766A", "problem_name": "Extremely Round\nbrute force, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1766/A", "problem_solution_link": "https://codeforces.com/problemset/status/1766/problem/A", "problem_statement": "A. Extremely Round\ntime limit per test\n3 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's call a positive integer\nextremely round\nif it has only one non-zero digit. For example, $$$5000$$$, $$$4$$$, $$$1$$$, $$$10$$$, $$$200$$$ are extremely round integers; $$$42$$$, $$$13$$$, $$$666$$$, $$$77$$$, $$$101$$$ are not.\nYou are given an integer $$$n$$$. You have to calculate the number of extremely round integers $$$x$$$ such that $$$1 \\le x \\le n$$$.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases.\nThen, $$$t$$$ lines follow. The $$$i$$$-th of them contains one integer $$$n$$$ ($$$1 \\le n \\le 999999$$$) \u2014 the description of the $$$i$$$-th test case.\nOutput\nFor each test case, print one integer \u2014 the number of extremely round integers $$$x$$$ such that $$$1 \\le x \\le n$$$.\nExample\nInput\n5\n9\n42\n13\n100\n111\nOutput\n9\n13\n10\n19\n19", "input": [ [ [ "9" ] ], [ [ "42" ] ], [ [ "13" ] ], [ [ "100" ] ], [ [ "111" ] ] ], "output": [ "9", "13", "10", "19", "19" ] }, { "problem_id": "1765B", "problem_name": "Broken Keyboard\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1765/B", "problem_solution_link": "https://codeforces.com/problemset/status/1765/problem/B", "problem_statement": "B. Broken Keyboard\ntime limit per test\n1 second\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nRecently, Mishka started noticing that his keyboard malfunctions \u2014 maybe it's because he was playing rhythm games too much. Empirically, Mishka has found out that every other time he presses a key, it is registered as if the key was pressed twice. For example, if Mishka types text, the first time he presses a key, exactly one letter is printed; the second time he presses a key, two same letters are printed; the third time he presses a key, one letter is printed; the fourth time he presses a key, two same letters are printed, and so on. Note that the number of times a key was pressed is counted for the whole keyboard, not for each key separately. For example, if Mishka tries to type the word\nosu\n, it will be printed on the screen as\nossu\n.\nYou are given a word consisting of $$$n$$$ lowercase Latin letters. You have to determine if it can be printed on Mishka's keyboard or not. You may assume that Mishka cannot delete letters from the word, and every time he presses a key, the new letter (or letters) is appended to the end of the word.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases.\nThe first line of the test case contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the length of the word.\nThe second line of the test case contains a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters \u2014 the word that should be checked.\nOutput\nFor each test case, print\nYES\nif the word $$$s$$$ can be printed on Mishka's keyboard, and\nNO\notherwise.\nExample\nInput\n4\n4\nossu\n2\naa\n6\naddonn\n3\nqwe\nOutput\nYES\nNO\nYES\nNO\nNote\nIn the first test case, Mishka can type the word as follows: press\no\n(one letter\no\nappears at the end of the word), then presses\ns\n(two letters\ns\nappear at the end of the word), and, finally, press\nu\n(one letter appears at the end of the word, making the resulting word\nossu\n).\nIn the second test case, Mishka can try typing the word as follows: press\na\n(one letter\na\nappears at the end of the word). But if he tries to press\na\none more time, two letters\na\nwill appear at the end of the word, so it is impossible to print the word using his keyboard.\nIn the fourth test case, Mishka has to start by pressing\nq\n. Then, if he presses\nw\n, two copies of\nw\nwill appear at the end of the word, but the third letter should be\ne\ninstead of\nw\n, so the answer is\nNO\n.", "input": [ [ [ "4" ], [ "ossu" ] ], [ [ "2" ], [ "aa" ] ], [ [ "6" ], [ "addonn" ] ], [ [ "3" ], [ "qwe" ] ] ], "output": [ "YES", "NO", "YES", "NO" ] }, { "problem_id": "1764A", "problem_name": "Doremy's Paint\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1764/A", "problem_solution_link": "https://codeforces.com/problemset/status/1764/problem/A", "problem_statement": "A. Doremy's Paint\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nDoremy has $$$n$$$ buckets of paint which is represented by an array $$$a$$$ of length $$$n$$$. Bucket $$$i$$$ contains paint with color $$$a_i$$$.\nLet $$$c(l,r)$$$ be the number of distinct elements in the subarray $$$[a_l,a_{l+1},\\ldots,a_r]$$$. Choose $$$2$$$ integers $$$l$$$ and $$$r$$$ such that $$$l \\leq r$$$ and $$$r-l-c(l,r)$$$ is maximized.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\\le t\\le 10^4$$$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^5$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\\ldots,a_n$$$ ($$$1 \\le a_i \\le n$$$).\nIt is guaranteed that the sum of $$$n$$$ does not exceed $$$10^5$$$.\nOutput\nFor each test case, output $$$l$$$ and $$$r$$$ such that $$$l \\leq r$$$ and $$$r-l-c(l,r)$$$ is maximized.\nIf there are multiple solutions, you may output any.\nExample\nInput\n7\n5\n1 3 2 2 4\n5\n1 2 3 4 5\n4\n2 1 2 1\n3\n2 3 3\n2\n2 2\n1\n1\n9\n9 8 5 2 1 1 2 3 3\nOutput\n2 4\n1 5\n1 4\n2 3\n1 2\n1 1\n3 9\nNote\nIn the first test case, $$$a=[1,3,2,2,4]$$$.\nWhen $$$l=1$$$ and $$$r=3$$$, $$$c(l,r)=3$$$ (there are $$$3$$$ distinct elements in $$$[1,3,2]$$$).\nWhen $$$l=2$$$ and $$$r=4$$$, $$$c(l,r)=2$$$ (there are $$$2$$$ distinct elements in $$$[3,2,2]$$$).\nIt can be shown that choosing $$$l=2$$$ and $$$r=4$$$ maximizes the value of $$$r-l-c(l,r)$$$ at $$$0$$$.\nFor the second test case, $$$a=[1,2,3,4,5]$$$.\nWhen $$$l=1$$$ and $$$r=5$$$, $$$c(l,r)=5$$$ (there are $$$5$$$ distinct elements in $$$[1,2,3,4,5]$$$).\nWhen $$$l=3$$$ and $$$r=3$$$, $$$c(l,r)=1$$$ (there is $$$1$$$ distinct element in $$$[3]$$$).\nIt can be shown that choosing $$$l=1$$$ and $$$r=5$$$ maximizes the value of $$$r-l-c(l,r)$$$ at $$$-1$$$. Choosing $$$l=3$$$ and $$$r=3$$$ is also acceptable.", "input": [ [ [ "5" ], [ "1", "3", "2", "2", "4" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ] ], [ [ "4" ], [ "2", "1", "2", "1" ] ], [ [ "3" ], [ "2", "3", "3" ] ], [ [ "2" ], [ "2", "2" ] ], [ [ "1" ], [ "1" ] ], [ [ "9" ], [ "9", "8", "5", "2", "1", "1", "2", "3", "3" ] ] ], "output": [ "2 4", "1 5", "1 4", "2 3", "1 2", "1 1", "3 9" ] }, { "problem_id": "1763A", "problem_name": "Absolute Maximization\nbitmasks, constructive algorithms, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1763/A", "problem_solution_link": "https://codeforces.com/problemset/status/1763/problem/A", "problem_statement": "A. Absolute Maximization\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ of length $$$n$$$. You can perform the following operation several (possibly, zero) times:\nChoose $$$i$$$, $$$j$$$, $$$b$$$: Swap the $$$b$$$-th digit in the binary representation of $$$a_i$$$ and $$$a_j$$$.\nFind the maximum possible value of $$$\\max(a) - \\min(a)$$$.\nIn a binary representation, bits are numbered from right (least significant) to left (most significant). Consider that there are an infinite number of leading zero bits at the beginning of any binary representation.\nFor example, swap the $$$0$$$-th bit for $$$4=100_2$$$ and $$$3=11_2$$$ will result $$$101_2=5$$$ and $$$10_2=2$$$. Swap the $$$2$$$-nd bit for $$$4=100_2$$$ and $$$3=11_2$$$ will result $$$000_2=0_2=0$$$ and $$$111_2=7$$$.\nHere, $$$\\max(a)$$$ denotes the maximum element of array $$$a$$$ and $$$\\min(a)$$$ denotes the minimum element of array $$$a$$$.\nThe binary representation of $$$x$$$ is $$$x$$$ written in base $$$2$$$. For example, $$$9$$$ and $$$6$$$ written in base $$$2$$$ are $$$1001$$$ and $$$110$$$, respectively.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 128$$$) \u2014 the number of testcases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$3 \\le n \\le 512$$$) \u2014 the length of array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i < 1024$$$) \u2014 the elements of array $$$a$$$.\nIt's guaranteed that the sum of $$$n$$$ over all testcases does not exceed $$$512$$$.\nOutput\nFor each testcase, print one integer \u2014 the maximum possible value of $$$\\max(a) - \\min(a)$$$.\nExample\nInput\n4\n3\n1 0 1\n4\n5 5 5 5\n5\n1 2 3 4 5\n7\n20 85 100 41 76 49 36\nOutput\n1\n0\n7\n125\nNote\nIn the first example, it can be shown that we do not need to perform any operations \u2014 the maximum value of $$$\\max(a) - \\min(a)$$$ is $$$1 - 0 = 1$$$.\nIn the second example, no operation can change the array \u2014 the maximum value of $$$\\max(a) - \\min(a)$$$ is $$$5 - 5 = 0$$$.\nIn the third example, initially $$$a = [1, 2, 3, 4, 5]$$$, we can perform one operation taking $$$i = 2$$$, $$$j = 5$$$, $$$b = 1$$$. The array now becomes $$$a = [1, 0, 3, 4, 7]$$$. It can be shown that any further operations do not lead to a better answer \u2014 therefore the answer is $$$\\max(a) - \\min(a) = 7 - 0 = 7$$$.", "input": [ [ [ "3" ], [ "1", "0", "1" ] ], [ [ "4" ], [ "5", "5", "5", "5" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ] ], [ [ "7" ], [ "20", "85", "100", "41", "76", "49", "36" ] ] ], "output": [ "1", "0", "7", "125" ] }, { "problem_id": "1762A", "problem_name": "Divide and Conquer\ngreedy, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1762/A", "problem_solution_link": "https://codeforces.com/problemset/status/1762/problem/A", "problem_statement": "A. Divide and Conquer\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAn array $$$b$$$ is\ngood\nif the sum of elements of $$$b$$$ is even.\nYou are given an array $$$a$$$ consisting of $$$n$$$ positive integers. In one operation, you can select an index $$$i$$$ and change $$$a_i := \\lfloor \\frac{a_i}{2} \\rfloor$$$. $$$^\\dagger$$$\nFind the minimum number of operations (possibly $$$0$$$) needed to make $$$a$$$ good. It can be proven that it is\nalways\npossible to make $$$a$$$ good.\n$$$^\\dagger$$$ $$$\\lfloor x \\rfloor$$$ denotes the floor function \u2014 the largest integer less than or equal to $$$x$$$. For example, $$$\\lfloor 2.7 \\rfloor = 2$$$, $$$\\lfloor \\pi \\rfloor = 3$$$ and $$$\\lfloor 5 \\rfloor =5$$$.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$) \u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 50$$$) \u2014 the length of the array $$$a$$$.\nThe second line of each test case contains $$$n$$$ space-separated integers $$$a_1,a_2,\\ldots,a_n$$$ ($$$1 \\leq a_i \\leq 10^6$$$) \u2014 representing the array $$$a$$$.\nDo note that the sum of $$$n$$$ over all test cases is not bounded.\nOutput\nFor each test case, output the minimum number of operations needed to make $$$a$$$ good.\nExample\nInput\n4\n4\n1 1 1 1\n2\n7 4\n3\n1 2 4\n1\n15\nOutput\n0\n2\n1\n4\nNote\nIn the first test case, array $$$a$$$ is already\ngood\n.\nIn the second test case, we can perform on index $$$2$$$ twice. After the first operation, array $$$a$$$ becomes $$$[7,2]$$$. After performing on index $$$2$$$ again, $$$a$$$ becomes $$$[7,1]$$$, which is\ngood\n. It can be proved that it is not possible to make $$$a$$$\ngood\nin less number of operations.\nIn the third test case, $$$a$$$ becomes $$$[0,2,4]$$$ if we perform the operation on index $$$1$$$ once. As $$$[0,2,4]$$$ is\ngood\n, answer is $$$1$$$.\nIn the fourth test case, we need to perform the operation on index $$$1$$$ four times. After all operations, $$$a$$$ becomes $$$[0]$$$. It can be proved that it is not possible to make $$$a$$$\ngood\nin less number of operations.", "input": [ [ [ "4" ], [ "1", "1", "1", "1" ] ], [ [ "2" ], [ "7", "4" ] ], [ [ "3" ], [ "1", "2", "4" ] ], [ [ "1" ], [ "15" ] ] ], "output": [ "0", "2", "1", "4" ] }, { "problem_id": "1761A", "problem_name": "Two Permutations\nbrute force, constructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1761/A", "problem_solution_link": "https://codeforces.com/problemset/status/1761/problem/A", "problem_statement": "A. Two Permutations\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given three integers $$$n$$$, $$$a$$$, and $$$b$$$. Determine if there exist two permutations $$$p$$$ and $$$q$$$ of length $$$n$$$, for which the following conditions hold:\nThe length of the longest common prefix of $$$p$$$ and $$$q$$$ is $$$a$$$.\nThe length of the longest common suffix of $$$p$$$ and $$$q$$$ is $$$b$$$.\nA permutation of length $$$n$$$ is an array containing each integer from $$$1$$$ to $$$n$$$ exactly once. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\\leq t\\leq 10^4$$$)\u00a0\u2014 the number of test cases. The description of test cases follows.\nThe only line of each test case contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$1\\leq a,b\\leq n\\leq 100$$$).\nOutput\nFor each test case, if such a pair of permutations exists, output \"\nYes\n\"; otherwise, output \"\nNo\n\". You can output each letter in any case (upper or lower).\nExample\nInput\n4\n1 1 1\n2 1 2\n3 1 1\n4 1 1\nOutput\nYes\nNo\nNo\nYes\nNote\nIn the first test case, $$$[1]$$$ and $$$[1]$$$ form a valid pair.\nIn the second test case and the third case, we can show that such a pair of permutations doesn't exist.\nIn the fourth test case, $$$[1,2,3,4]$$$ and $$$[1,3,2,4]$$$ form a valid pair.", "input": [ [ [ "1", "1", "1" ] ], [ [ "2", "1", "2" ] ], [ [ "3", "1", "1" ] ], [ [ "4", "1", "1" ] ] ], "output": [ "Yes", "No", "No", "Yes" ] }, { "problem_id": "1760C", "problem_name": "Advantage\ndata structures, implementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1760/C", "problem_solution_link": "https://codeforces.com/problemset/status/1760/problem/C", "problem_statement": "C. Advantage\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ participants in a competition, participant $$$i$$$ having a strength of $$$s_i$$$.\nEvery participant wonders how much of an advantage they have over the other best participant. In other words, each participant $$$i$$$ wants to know the difference between $$$s_i$$$ and $$$s_j$$$, where $$$j$$$ is the strongest participant in the competition, not counting $$$i$$$ (a difference can be negative).\nSo, they ask you for your help! For each $$$i$$$ ($$$1 \\leq i \\leq n$$$) output the difference between $$$s_i$$$ and the maximum strength of any participant other than participant $$$i$$$.\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases. The descriptions of the test cases follow.\nThe first line of each test case contains an integer $$$n$$$ ($$$2 \\leq n \\leq 2\\cdot10^5$$$)\u00a0\u2014 the length of the array.\nThe following line contains $$$n$$$ space-separated positive integers $$$s_1$$$, $$$s_2$$$, ..., $$$s_n$$$ ($$$1 \\leq s_i \\leq 10^9$$$)\u00a0\u2014 the strengths of the participants.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\\cdot10^5$$$.\nOutput\nFor each test case, output $$$n$$$ space-separated integers. For each $$$i$$$ ($$$1 \\leq i \\leq n$$$) output the difference between $$$s_i$$$ and the maximum strength of any other participant.\nExample\nInput\n5\n4\n4 7 3 5\n2\n1 2\n5\n1 2 3 4 5\n3\n4 9 4\n4\n4 4 4 4\nOutput\n-3 2 -4 -2 \n-1 1 \n-4 -3 -2 -1 1 \n-5 5 -5 \n0 0 0 0\nNote\nFor the first test case:\nThe first participant has a strength of $$$4$$$ and the largest strength of a participant different from the first one is $$$7$$$, so the answer for the first participant is $$$4 - 7 = -3$$$.\nThe second participant has a strength of $$$7$$$ and the largest strength of a participant different from the second one is $$$5$$$, so the answer for the second participant is $$$7 - 5 = 2$$$.\nThe third participant has a strength of $$$3$$$ and the largest strength of a participant different from the third one is $$$7$$$, so the answer for the third participant is $$$3 - 7 = -4$$$.\nThe fourth participant has a strength of $$$5$$$ and the largest strength of a participant different from the fourth one is $$$7$$$, so the answer for the fourth participant is $$$5 - 7 = -2$$$.", "input": [ [ [ "4" ], [ "4", "7", "3", "5" ] ], [ [ "2" ], [ "1", "2" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ] ], [ [ "3" ], [ "4", "9", "4" ] ], [ [ "4" ], [ "4", "4", "4", "4" ] ] ], "output": [ "-3 2 -4 -2 ", "-1 1 ", "-4 -3 -2 -1 1 ", "-5 5 -5 ", "0 0 0 0" ] }, { "problem_id": "1760B", "problem_name": "Atilla's Favorite Problem\ngreedy, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1760/B", "problem_solution_link": "https://codeforces.com/problemset/status/1760/problem/B", "problem_statement": "B. Atilla's Favorite Problem\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIn order to write a string, Atilla needs to first learn all letters that are contained in the string.\nAtilla needs to write a message which can be represented as a string $$$s$$$. He asks you what is the minimum alphabet size required so that one can write this message.\nThe alphabet of size $$$x$$$ ($$$1 \\leq x \\leq 26$$$) contains\nonly the first\n$$$x$$$ Latin letters. For example an alphabet of size $$$4$$$ contains\nonly\nthe characters $$$\\texttt{a}$$$, $$$\\texttt{b}$$$, $$$\\texttt{c}$$$ and $$$\\texttt{d}$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the length of the string.\nThe second line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of lowercase Latin letters.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the minimum alphabet size required to so that Atilla can write his message $$$s$$$.\nExample\nInput\n5\n1\na\n4\ndown\n10\ncodeforces\n3\nbcf\n5\nzzzzz\nOutput\n1\n23\n19\n6\n26\nNote\nFor the first test case, Atilla needs to know only the character $$$\\texttt{a}$$$, so the alphabet of size $$$1$$$ which only contains $$$\\texttt{a}$$$ is enough.\nFor the second test case, Atilla needs to know the characters $$$\\texttt{d}$$$, $$$\\texttt{o}$$$, $$$\\texttt{w}$$$, $$$\\texttt{n}$$$. The smallest alphabet size that contains all of them is $$$23$$$ (such alphabet can be represented as the string $$$\\texttt{abcdefghijklmnopqrstuvw}$$$).", "input": [ [ [ "1" ], [ "a" ] ], [ [ "4" ], [ "down" ] ], [ [ "10" ], [ "codeforces" ] ], [ [ "3" ], [ "bcf" ] ], [ [ "5" ], [ "zzzzz" ] ] ], "output": [ "1", "23", "19", "6", "26" ] }, { "problem_id": "1760A", "problem_name": "Medium Number\nimplementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1760/A", "problem_solution_link": "https://codeforces.com/problemset/status/1760/problem/A", "problem_statement": "A. Medium Number\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven three\ndistinct\nintegers $$$a$$$, $$$b$$$, and $$$c$$$, find the medium number between all of them.\nThe medium number is the number that is neither the minimum nor the maximum of the given three numbers.\nFor example, the median of $$$5,2,6$$$ is $$$5$$$, since the minimum is $$$2$$$ and the maximum is $$$6$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 6840$$$)\u00a0\u2014 the number of test cases.\nThe description of each test case consists of three\ndistinct\nintegers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \\leq a, b, c \\leq 20$$$).\nOutput\nFor each test case, output a single integer\u00a0\u2014 the medium number of the three numbers.\nExample\nInput\n9\n5 2 6\n14 3 4\n20 2 1\n1 2 3\n11 19 12\n10 8 20\n6 20 3\n4 1 3\n19 8 4\nOutput\n5\n4\n2\n2\n12\n10\n6\n3\n8", "input": [ [ [ "5", "2", "6" ] ], [ [ "14", "3", "4" ] ], [ [ "20", "2", "1" ] ], [ [ "1", "2", "3" ] ], [ [ "11", "19", "12" ] ], [ [ "10", "8", "20" ] ], [ [ "6", "20", "3" ] ], [ [ "4", "1", "3" ] ], [ [ "19", "8", "4" ] ] ], "output": [ "5", "4", "2", "2", "12", "10", "6", "3", "8" ] }, { "problem_id": "1759A", "problem_name": "Yes-Yes?\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1759/A", "problem_solution_link": "https://codeforces.com/problemset/status/1759/problem/A", "problem_statement": "A. Yes-Yes?\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou talked to Polycarp and asked him a question. You know that when he wants to answer \"yes\", he repeats\nYes\nmany times in a row.\nBecause of the noise, you only heard part of the answer\u00a0\u2014 some substring of it. That is, if he answered\nYesYes\n, then you could hear\nesY\n,\nYesYes\n,\nsYes\n,\ne\n, but you couldn't\nYess\n,\nYES\nor\nse\n.\nDetermine if it is true that the given string $$$s$$$ is a substring of\nYesYesYes...\n(\nYes\nrepeated many times in a row).\nInput\nThe first line of input data contains the singular $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases in the test.\nEach test case is described by a single string of Latin letters $$$s$$$ ($$$1 \\le |s| \\le 50$$$)\u00a0\u2014 the part of Polycarp's answer that you heard, where $$$|s|$$$ \u2014 is the length of the string $$$s$$$.\nOutput\nOutput $$$t$$$ lines, each of which is the answer to the corresponding test case. As an answer, output \"\nYES\n\" if the specified string $$$s$$$ is a substring of the string\nYesYesYes...Yes\n(the number of words\nYes\nis arbitrary), and \"\nNO\n\" otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n12\nYES\nesYes\ncodeforces\nes\nse\nYesY\nesYesYesYesYesYesYe\nseY\nYess\nsY\no\nYes\nOutput\nNO\nYES\nNO\nYES\nNO\nYES\nYES\nNO\nNO\nYES\nNO\nYES", "input": [ [ [ "12", "YES" ] ], [ [ "esYes" ] ], [ [ "codeforces" ] ], [ [ "es" ] ], [ [ "se" ] ], [ [ "YesY" ] ], [ [ "esYesYesYesYesYesYe" ] ], [ [ "seY" ] ], [ [ "Yess" ] ], [ [ "sY" ] ], [ [ "o" ] ], [ [ "Yes" ] ] ], "output": [ "NO", "YES", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES" ] }, { "problem_id": "1759B", "problem_name": "Lost Permutation\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1759/B", "problem_solution_link": "https://codeforces.com/problemset/status/1759/problem/B", "problem_statement": "B. Lost Permutation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA sequence of $$$n$$$ numbers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once. For example, the sequences [$$$3, 1, 4, 2$$$], [$$$1$$$] and [$$$2,1$$$] are permutations, but [$$$1,2,1$$$], [$$$0,1$$$] and [$$$1,3,4$$$]\u00a0\u2014 are not.\nPolycarp lost his favorite permutation and found only some of its elements \u2014 the numbers $$$b_1, b_2, \\dots b_m$$$. He is sure that the sum of the lost elements equals $$$s$$$.\nDetermine whether one or more numbers can be appended to the given sequence $$$b_1, b_2, \\dots b_m$$$ such that the sum of the added numbers equals $$$s$$$, and the resulting new array is a permutation?\nInput\nThe first line of input contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014the number of test cases.\nThen the descriptions of the test cases follow.\nThe first line of each test set contains two integers $$$m$$$ and $$$s$$$ ($$$1 \\le m \\le 50$$$, $$$1 \\le s \\le 1000$$$)\u2014-the number of found elements and the sum of forgotten numbers.\nThe second line of each test set contains $$$m$$$ different integers $$$b_1, b_2 \\dots b_m$$$ ($$$1 \\le b_i \\le 50$$$) \u2014 the elements Polycarp managed to find.\nOutput\nPrint $$$t$$$ lines, each of which is the answer to the corresponding test set. Print as the answer\nYES\nif you can append several elements to the array $$$b$$$, that their sum equals $$$s$$$ and the result will be a permutation. Output\nNO\notherwise.\nYou can output the answer in any case (for example,\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as positive answer).\nExample\nInput\n5\n3 13\n3 1 4\n1 1\n1\n3 3\n1 4 2\n2 1\n4 3\n5 6\n1 2 3 4 5\nOutput\nYES\nNO\nYES\nNO\nYES\nNote\nIn the test case of the example, $$$m=3, s=13, b=[3,1,4]$$$. You can append to $$$b$$$ the numbers $$$6,2,5$$$, the sum of which is $$$6+2+5=13$$$. Note that the final array will become $$$[3,1,4,6,2,5]$$$, which is a permutation.\nIn the second test case of the example, $$$m=1, s=1, b=[1]$$$. You cannot append one or more numbers to $$$[1]$$$ such that their sum equals $$$1$$$ and the result is a permutation.\nIn the third test case of the example, $$$m=3, s=3, b=[1,4,2]$$$. You can append the number $$$3$$$ to $$$b$$$. Note that the resulting array will be $$$[1,4,2,3]$$$, which is a permutation.", "input": [ [ [ "3", "13" ], [ "3", "1", "4" ] ], [ [ "1", "1" ], [ "1" ] ], [ [ "3", "3" ], [ "1", "4", "2" ] ], [ [ "2", "1" ], [ "4", "3" ] ], [ [ "5", "6" ], [ "1", "2", "3", "4", "5" ] ] ], "output": [ "YES", "NO", "YES", "NO", "YES" ] }, { "problem_id": "1758A", "problem_name": "SSeeeeiinngg DDoouubbllee\nconstructive algorithms, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1758/A", "problem_solution_link": "https://codeforces.com/problemset/status/1758/problem/A", "problem_statement": "A. SSeeeeiinngg DDoouubbllee\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA\npalindrome\nis a string that reads the same backward as forward. For example, the strings $$$\\texttt{z}$$$, $$$\\texttt{aaa}$$$, $$$\\texttt{aba}$$$, and $$$\\texttt{abccba}$$$ are palindromes, but $$$\\texttt{codeforces}$$$ and $$$\\texttt{ab}$$$ are not.\nThe\ndouble\nof a string $$$s$$$ is obtained by writing each character twice. For example, the double of $$$\\texttt{seeing}$$$ is $$$\\texttt{sseeeeiinngg}$$$.\nGiven a string $$$s$$$, rearrange its double to form a palindrome. Output the rearranged string. It can be proven that such a rearrangement always exists.\nInput\nThe first line of input contains $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nThe only line of each test case contains a single string $$$s$$$ ($$$1 \\leq |s| \\leq 100$$$) consisting only of lowercase English letters.\nNote that the sum of $$$|s|$$$ over all test cases is not bounded.\nOutput\nFor each test case, output a palindromic string of length $$$2 \\cdot |s|$$$ that is a rearrangement of the double of $$$s$$$.\nExample\nInput\n4\na\nsururu\nerrorgorn\nanutforajaroftuna\nOutput\naa\nsuurruurruus\nrgnororerrerorongr\naannuuttffoorraajjaarrooffttuunnaa\nNote\nIn the first test case, the double of $$$\\texttt{a}$$$ is $$$\\texttt{aa}$$$, which is already a palindrome.\nIn the second test case, the double of $$$\\texttt{sururu}$$$ is $$$\\texttt{ssuurruurruu}$$$. If we move the first $$$\\texttt{s}$$$ to the end, we get $$$\\texttt{suurruurruus}$$$, which is a palindrome.\nIn the third test case, the double of $$$\\texttt{errorgorn}$$$ is $$$\\texttt{eerrrroorrggoorrnn}$$$. We can rearrange the characters to form $$$\\texttt{rgnororerrerorongr}$$$, which is a palindrome.", "input": [ [ [ "a" ] ], [ [ "sururu" ] ], [ [ "errorgorn" ] ], [ [ "anutforajaroftuna" ] ] ], "output": [ "aa", "suurruurruus", "rgnororerrerorongr", "aannuuttffoorraajjaarrooffttuunnaa" ] }, { "problem_id": "1754B", "problem_name": "Kevin and Permutation\nconstructive algorithms, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1754/B", "problem_solution_link": "https://codeforces.com/problemset/status/1754/problem/B", "problem_statement": "B. Kevin and Permutation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nFor his birthday, Kevin received the set of pairwise distinct numbers $$$1, 2, 3, \\ldots, n$$$ as a gift.\nHe is going to arrange these numbers in a way such that the minimum absolute difference between two consecutive numbers be maximum possible. More formally, if he arranges numbers in order $$$p_1, p_2, \\ldots, p_n$$$, he wants to maximize the value $$$$$$\\min \\limits_{i=1}^{n - 1} \\lvert p_{i + 1} - p_i \\rvert,$$$$$$ where $$$|x|$$$ denotes the absolute value of $$$x$$$.\nHelp Kevin to do that.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases. Description of the test cases follows.\nThe only line of each test case contains an integer $$$n$$$ ($$$2 \\le n \\leq 1\\,000$$$)\u00a0\u2014 the size of the set.\nOutput\nFor each test case print a single line containing $$$n$$$ distinct integers $$$p_1, p_2, \\ldots, p_n$$$ ($$$1 \\le p_i \\le n$$$) describing the arrangement that maximizes the minimum absolute difference of consecutive elements.\nFormally, you have to print a permutation $$$p$$$ which maximizes the value $$$\\min \\limits_{i=1}^{n - 1} \\lvert p_{i + 1} - p_i \\rvert$$$.\nIf there are multiple optimal solutions, print any of them.\nExample\nInput\n2\n4\n3\nOutput\n2 4 1 3\n1 2 3\nNote\nIn the first test case the minimum absolute difference of consecutive elements equals $$$\\min \\{\\lvert 4 - 2 \\rvert, \\lvert 1 - 4 \\rvert, \\lvert 3 - 1 \\rvert \\} = \\min \\{2, 3, 2\\} = 2$$$. It's easy to prove that this answer is optimal.\nIn the second test case each permutation of numbers $$$1, 2, 3$$$ is an optimal answer. The minimum absolute difference of consecutive elements equals to $$$1$$$.", "input": [ [ [ "4" ] ], [ [ "3" ] ] ], "output": [ "2 4 1 3", "1 2 3" ] }, { "problem_id": "1754A", "problem_name": "Technical Support\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1754/A", "problem_solution_link": "https://codeforces.com/problemset/status/1754/problem/A", "problem_statement": "A. Technical Support\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou work in the quality control department of technical support for a large company. Your job is to make sure all client issues have been resolved.\nToday you need to check a copy of a dialog between a client and a technical support manager. According to the rules of work, each message of the client must be followed by\none or several\nmessages, which are the answer of a support manager. However, sometimes clients ask questions so quickly that some of the manager's answers to old questions appear after the client has asked some new questions.\nDue to the privacy policy, the full text of messages is not available to you, only the order of messages is visible, as well as the type of each message: a customer question or a response from the technical support manager.\nIt is guaranteed that the dialog begins with the question of the client.\nYou have to determine, if this dialog may correspond to the rules of work described above, or the rules are certainly breached.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 500$$$). Description of the test cases follows.\nThe first line of each test case contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the total number of messages in the dialog.\nThe second line of each test case consists of $$$n$$$ characters \"\nQ\n\" and \"\nA\n\", describing types of messages in the dialog in chronological order. Character \"\nQ\n\" denotes the message with client question, and character \"\nA\n\"\u00a0\u2014 the message with technical support manager answer. It is guaranteed that the first character in the line equals to \"\nQ\n\".\nOutput\nFor each test case print \"\nYes\n\" (without quotes) if dialog may correspond to the rules of work, or \"\nNo\n\" (without quotes) otherwise.\nExample\nInput\n5\n4\nQQAA\n4\nQQAQ\n3\nQAA\n1\nQ\n14\nQAQQAQAAQQQAAA\nOutput\nYes\nNo\nYes\nNo\nYes\nNote\nIn the first test case the two questions from the client are followed with two specialist's answers. So this dialog may correspond to the rules of work.\nIn the second test case one of the first two questions was not answered.\nIn the third test case the technical support manager sent two messaged as the answer to the only message of the client.", "input": [ [ [ "4" ], [ "QQAA" ] ], [ [ "4" ], [ "QQAQ" ] ], [ [ "3" ], [ "QAA" ] ], [ [ "1" ], [ "Q" ] ], [ [ "14" ], [ "QAQQAQAAQQQAAA" ] ] ], "output": [ "Yes", "No", "Yes", "No", "Yes" ] }, { "problem_id": "1750B", "problem_name": "Maximum Substring\nbrute force, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1750/B", "problem_solution_link": "https://codeforces.com/problemset/status/1750/problem/B", "problem_statement": "B. Maximum Substring\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA binary string is a string consisting only of the characters\n0\nand\n1\n. You are given a binary string $$$s$$$.\nFor some non-empty substring$$$^\\dagger$$$ $$$t$$$ of string $$$s$$$ containing $$$x$$$ characters\n0\nand $$$y$$$ characters\n1\n, define its\ncost\nas:\n$$$x \\cdot y$$$, if $$$x > 0$$$ and $$$y > 0$$$;\n$$$x^2$$$, if $$$x > 0$$$ and $$$y = 0$$$;\n$$$y^2$$$, if $$$x = 0$$$ and $$$y > 0$$$.\nGiven a binary string $$$s$$$ of length $$$n$$$, find the maximum cost across all its non-empty substrings.\n$$$^\\dagger$$$ A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^5$$$) \u2014 the number of test cases. The description of test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) \u2014 the length of the string $$$s$$$.\nThe second line of each test case contains a binary string $$$s$$$ of length $$$n$$$.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print a single integer \u2014 the maximum cost across all substrings.\nExample\nInput\n6\n5\n11100\n7\n1100110\n6\n011110\n7\n1001010\n4\n1000\n1\n0\nOutput\n9\n12\n16\n12\n9\n1\nNote\nIn the first test case, we can take a substring $$$111$$$. It contains $$$3$$$ characters\n1\nand $$$0$$$ characters\n0\n. So $$$a = 3$$$, $$$b = 0$$$ and its cost is $$$3^2 = 9$$$.\nIn the second test case, we can take the whole string. It contains $$$4$$$ characters\n1\nand $$$3$$$ characters\n0\n. So $$$a = 4$$$, $$$b = 3$$$ and its cost is $$$4 \\cdot 3 = 12$$$.\nIn the third test case, we can can take a substring $$$1111$$$ and its cost is $$$4^2 = 16$$$.\nIn the fourth test case, we can take the whole string and cost is $$$4 \\cdot 3 = 12$$$.\nIn the fifth test case, we can take a substring $$$000$$$ and its cost is $$$3 \\cdot 3 = 9$$$.\nIn the sixth test case, we can only take the substring $$$0$$$ and its cost is $$$1 \\cdot 1 = 1$$$.", "input": [ [ [ "5" ], [ "11100" ] ], [ [ "7" ], [ "1100110" ] ], [ [ "6" ], [ "011110" ] ], [ [ "7" ], [ "1001010" ] ], [ [ "4" ], [ "1000" ] ], [ [ "1" ], [ "0" ] ] ], "output": [ "9", "12", "16", "12", "9", "1" ] }, { "problem_id": "1750A", "problem_name": "Indirect Sort\nconstructive algorithms, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1750/A", "problem_solution_link": "https://codeforces.com/problemset/status/1750/problem/A", "problem_statement": "A. Indirect Sort\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a permutation $$$a_1, a_2, \\ldots, a_n$$$ of size $$$n$$$, where each integer from $$$1$$$ to $$$n$$$ appears\nexactly once\n.\nYou can do the following operation any number of times (possibly, zero):\nChoose any three indices $$$i, j, k$$$ ($$$1 \\le i < j < k \\le n$$$).\nIf $$$a_i > a_k$$$, replace $$$a_i$$$ with $$$a_i + a_j$$$. Otherwise, swap $$$a_j$$$ and $$$a_k$$$.\nDetermine whether you can make the array $$$a$$$ sorted in non-descending order.\nInput\nEach test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 5000$$$) \u2014 the number of test cases. The description of test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$3 \\le n \\le 10$$$) \u2014 the length of the array $$$a$$$.\nThe second line contains $$$n$$$ integers $$$a_1,a_2,\\dots,a_n$$$ ($$$1 \\le a_i \\le n$$$, $$$a_i \\neq a_j$$$ if $$$i \\neq j$$$) \u2014 the elements of the array $$$a$$$.\nOutput\nFor each test case, output \"\nYes\n\" (without quotes) if the array can be sorted in non-descending order, and \"\nNo\n\" (without quotes) otherwise.\nYou can output \"\nYes\n\" and \"\nNo\n\" in any case (for example, strings \"\nYES\n\", \"\nyEs\n\" and \"\nyes\n\" will be recognized as a positive response).\nExample\nInput\n7\n3\n1 2 3\n3\n1 3 2\n7\n5 3 4 7 6 2 1\n7\n7 6 5 4 3 2 1\n5\n2 1 4 5 3\n5\n2 1 3 4 5\n7\n1 2 6 7 4 3 5\nOutput\nYes\nYes\nNo\nNo\nNo\nNo\nYes\nNote\nIn the first test case, $$$[1,2,3]$$$ is already sorted in non-descending order.\nIn the second test case, we can choose $$$i = 1,j = 2,k = 3$$$. Since $$$a_1 \\le a_3$$$, swap $$$a_2$$$ and $$$a_3$$$, the array then becomes $$$[1,2,3]$$$, which is sorted in non-descending order.\nIn the seventh test case, we can do the following operations successively:\nChoose $$$i = 5,j = 6,k = 7$$$. Since $$$a_5 \\le a_7$$$, swap $$$a_6$$$ and $$$a_7$$$, the array then becomes $$$[1,2,6,7,4,5,3]$$$.\nChoose $$$i = 5,j = 6,k = 7$$$. Since $$$a_5 > a_7$$$, replace $$$a_5$$$ with $$$a_5+a_6=9$$$, the array then becomes $$$[1,2,6,7,9,5,3]$$$.\nChoose $$$i = 2,j = 5,k = 7$$$. Since $$$a_2 \\le a_7$$$, swap $$$a_5$$$ and $$$a_7$$$, the array then becomes $$$[1,2,6,7,3,5,9]$$$.\nChoose $$$i = 2,j = 4,k = 6$$$. Since $$$a_2 \\le a_6$$$, swap $$$a_4$$$ and $$$a_6$$$, the array then becomes $$$[1,2,6,5,3,7,9]$$$.\nChoose $$$i = 1,j = 3,k = 5$$$. Since $$$a_1 \\le a_5$$$, swap $$$a_3$$$ and $$$a_5$$$, the array then becomes $$$[1,2,3,5,6,7,9]$$$, which is sorted in non-descending order.\nIn the third, the fourth, the fifth and the sixth test cases, it can be shown that the array cannot be sorted in non-descending order.", "input": [ [ [ "3" ], [ "1", "2", "3" ] ], [ [ "3" ], [ "1", "3", "2" ] ], [ [ "7" ], [ "5", "3", "4", "7", "6", "2", "1" ] ], [ [ "7" ], [ "7", "6", "5", "4", "3", "2", "1" ] ], [ [ "5" ], [ "2", "1", "4", "5", "3" ] ], [ [ "5" ], [ "2", "1", "3", "4", "5" ] ], [ [ "7" ], [ "1", "2", "6", "7", "4", "3", "5" ] ] ], "output": [ "Yes", "Yes", "No", "No", "No", "No", "Yes" ] }, { "problem_id": "1749A", "problem_name": "Cowardly Rooks\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1749/A", "problem_solution_link": "https://codeforces.com/problemset/status/1749/problem/A", "problem_statement": "A. Cowardly Rooks\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere's a chessboard of size $$$n \\times n$$$. $$$m$$$ rooks are placed on it in such a way that:\nno two rooks occupy the same cell;\nno two rooks attack each other.\nA rook attacks all cells that are in its row or column.\nIs it possible to move\nexactly one\nrook (you can choose which one to move) into a different cell so that no two rooks still attack each other? A rook can move into any cell in its row or column if no other rook stands on its path.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 2000$$$)\u00a0\u2014 the number of testcases.\nThe first line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 8$$$)\u00a0\u2014 the size of the chessboard and the number of the rooks.\nThe $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \\le x_i, y_i \\le n$$$)\u00a0\u2014 the position of the $$$i$$$-th rook: $$$x_i$$$ is the row and $$$y_i$$$ is the column.\nNo two rooks occupy the same cell. No two rooks attack each other.\nOutput\nFor each testcase, print \"\nYES\n\" if it's possible to move exactly one rook into a different cell so that no two rooks still attack each other. Otherwise, print \"\nNO\n\".\nExample\nInput\n2\n2 2\n1 2\n2 1\n3 1\n2 2\nOutput\nNO\nYES\nNote\nIn the first testcase, the rooks are in the opposite corners of a $$$2 \\times 2$$$ board. Each of them has a move into a neighbouring corner, but moving there means getting attacked by another rook.\nIn the second testcase, there's a single rook in a middle of a $$$3 \\times 3$$$ board. It has $$$4$$$ valid moves, and every move is fine because there's no other rook to attack it.", "input": [ [ [ "2" ], [ "2", "2", "1 2", "2 1" ] ], [ [ "3", "1", "2", "2" ] ] ], "output": [ "NO", "YES" ] }, { "problem_id": "1748A", "problem_name": "The Ultimate Square\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1748/A", "problem_solution_link": "https://codeforces.com/problemset/status/1748/problem/A", "problem_statement": "A. The Ultimate Square\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have $$$n$$$ rectangular wooden blocks, which are numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th block is $$$1$$$ unit high and $$$\\lceil \\frac{i}{2} \\rceil$$$ units long.\nHere, $$$\\lceil \\frac{x}{2} \\rceil$$$ denotes the result of division of $$$x$$$ by $$$2$$$, rounded\nup\n. For example, $$$\\lceil \\frac{4}{2} \\rceil = 2$$$ and $$$\\lceil \\frac{5}{2} \\rceil = \\lceil 2.5 \\rceil = 3$$$.\nFor example, if $$$n=5$$$, then the blocks have the following sizes: $$$1 \\times 1$$$, $$$1 \\times 1$$$, $$$1 \\times 2$$$, $$$1 \\times 2$$$, $$$1 \\times 3$$$.\nThe available blocks for $$$n=5$$$\nFind the maximum possible side length of a square you can create using these blocks,\nwithout rotating any of them\n. Note that you don't have to use all of the blocks.\nOne of the ways to create $$$3 \\times 3$$$ square using blocks $$$1$$$ through $$$5$$$\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$)\u00a0\u2014 the number of blocks.\nOutput\nFor each test case, print one integer\u00a0\u2014 the maximum possible side length of a square you can create.\nExample\nInput\n3\n2\n5\n197654321\nOutput\n1\n3\n98827161\nNote\nIn the first test case, you can create a $$$1 \\times 1$$$ square using only one of the blocks.\nIn the second test case, one of the possible ways to create a $$$3 \\times 3$$$ square is shown in the statement. It is impossible to create a $$$4 \\times 4$$$ or larger square, so the answer is $$$3$$$.", "input": [ [ [ "2" ] ], [ [ "5" ] ], [ [ "197654321" ] ] ], "output": [ "1", "3", "98827161" ] }, { "problem_id": "1747A", "problem_name": "Two Groups\nconstructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1747/A", "problem_solution_link": "https://codeforces.com/problemset/status/1747/problem/A", "problem_statement": "A. Two Groups\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ consisting of $$$n$$$ integers. You want to distribute these $$$n$$$ integers into two groups $$$s_1$$$ and $$$s_2$$$ (groups can be empty) so that the following conditions are satisfied:\nFor each $$$i$$$ $$$(1 \\leq i \\leq n)$$$, $$$a_i$$$ goes into exactly one group.\nThe value $$$|sum(s_1)| - |sum(s_2)|$$$ is the maximum possible among all such ways to distribute the integers.\nHere $$$sum(s_1)$$$ denotes the sum of the numbers in the group $$$s_1$$$, and $$$sum(s_2)$$$ denotes the sum of the numbers in the group $$$s_2$$$.\nDetermine the maximum possible value of $$$|sum(s_1)| - |sum(s_2)|$$$.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \\leq t \\leq 2 \\cdot 10^4)$$$ \u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ $$$(1 \\leq n \\leq 10^5)$$$ \u00a0\u2014 the length of the array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1,a_2 \\ldots a_n$$$ $$$(-10^9 \\leq a_i \\leq 10^9)$$$ \u00a0\u2014 elements of the array $$$a$$$.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\\cdot 10^5$$$.\nOutput\nFor each test case, output a single integer \u00a0\u2014 the maximum possible value of $$$|sum(s_1)| - |sum(s_2)|$$$.\nExample\nInput\n4\n2\n10 -10\n4\n-2 -1 11 0\n3\n2 3 2\n5\n-9 2 0 0 -4\nOutput\n0\n8\n7\n11\nNote\nIn the\nfirst testcase\n, we can distribute as $$$s_1 = \\{10\\}$$$, $$$s_2 = \\{-10\\}$$$. Then the value will be $$$|10| - |-10| = 0$$$.\nIn the\nsecond testcase\n, we can distribute as $$$s_1 = \\{0, 11, -1\\}$$$, $$$s_2 = \\{-2\\}$$$. Then the value will be $$$|0 + 11 - 1| - |-2| = 10 - 2 = 8$$$.\nIn the\nthird testcase\n, we can distribute as $$$s_1 = \\{2, 3, 2\\}$$$, $$$s_2 = \\{\\}$$$. Then the value will be $$$|2 + 3 + 2| - |0| = 7$$$.\nIn the\nfourth testcase\n, we can distribute as $$$s_1 = \\{-9, -4, 0\\}$$$, $$$s_2 = \\{2, 0\\}$$$. Then the value will be $$$|-9 - 4 + 0| - |2 + 0| = 13 - 2 = 11$$$.", "input": [ [ [ "2" ], [ "10", "-10" ] ], [ [ "4" ], [ "-2", "-1", "11", "0" ] ], [ [ "3" ], [ "2", "3", "2" ] ], [ [ "5" ], [ "-9", "2", "0", "0", "-4" ] ] ], "output": [ "0", "8", "7", "11" ] }, { "problem_id": "1746B", "problem_name": "Rebellion\nconstructive algorithms, greedy, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1746/B", "problem_solution_link": "https://codeforces.com/problemset/status/1746/problem/B", "problem_statement": "B. Rebellion\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have an array $$$a$$$ of size $$$n$$$ consisting only of zeroes and ones. You can do the following operation:\nchoose two indices $$$1 \\le i , j \\le n$$$, $$$i \\ne j$$$,\nadd $$$a_{i}$$$ to $$$a_{j}$$$,\nremove $$$a_{i}$$$ from $$$a$$$.\nNote that elements of $$$a$$$ can become bigger than $$$1$$$ after performing some operations. Also note that $$$n$$$ becomes $$$1$$$ less after the operation.\nWhat is the minimum number of operations needed to make $$$a$$$ non-decreasing, i.\u00a0e. that each element is not less than the previous element?\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^4$$$). The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 10^5$$$), the size of array $$$a$$$.\nNext line contains $$$n$$$ integers $$$a_{1}, a_{2}, \\ldots a_{n}$$$ ($$$a_i$$$ is $$$0$$$ or $$$1$$$), elements of array $$$a$$$.\nIt's guaranteed that sum of $$$n$$$ over all test cases doesn't exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case print a single integer, minimum number of operations needed to make $$$a$$$ non-decreasing.\nExample\nInput\n4\n8\n0 0 1 1 1 1 1 1\n5\n1 0 0 1 1\n2\n1 0\n11\n1 1 0 0 1 0 0 1 1 1 0\nOutput\n0\n1\n1\n3\nNote\nIn the first test case, $$$a$$$ is already non-decreasing, so you don't need to do any operations and the answer is $$$0$$$.\nIn the second test case, you can perform an operation for $$$i = 1$$$ and $$$j = 5$$$, so $$$a$$$ will be equal to $$$[0, 0, 1, 2]$$$ and it becomes non-decreasing.\nIn the third test case, you can perform an operation for $$$i = 2$$$ and $$$j = 1$$$, so $$$a$$$ will be equal to $$$[1]$$$ and it becomes non-decreasing.", "input": [ [ [ "8" ], [ "0", "0", "1", "1", "1", "1", "1", "1" ] ], [ [ "5" ], [ "1", "0", "0", "1", "1" ] ], [ [ "2" ], [ "1", "0" ] ], [ [ "11" ], [ "1", "1", "0", "0", "1", "0", "0", "1", "1", "1", "0" ] ] ], "output": [ "0", "1", "1", "3" ] }, { "problem_id": "1746A", "problem_name": "Maxmina\nconstructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1746/A", "problem_solution_link": "https://codeforces.com/problemset/status/1746/problem/A", "problem_statement": "A. Maxmina\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have an array $$$a$$$ of size $$$n$$$ consisting only of zeroes and ones and an integer $$$k$$$. In one operation you can do one of the following:\nSelect $$$2$$$ consecutive elements of $$$a$$$ and replace them with their minimum (that is, let $$$a := [a_{1}, a_{2}, \\ldots, a_{i-1}, \\min(a_{i}, a_{i+1}), a_{i+2}, \\ldots, a_{n}]$$$ for some $$$1 \\le i \\le n-1$$$). This operation decreases the size of $$$a$$$ by $$$1$$$.\nSelect $$$k$$$ consecutive elements of $$$a$$$ and replace them with their maximum (that is, let $$$a := [a_{1}, a_{2}, \\ldots, a_{i-1}, \\max(a_{i}, a_{i+1}, \\ldots, a_{i+k-1}), a_{i+k}, \\ldots, a_{n}]$$$ for some $$$1 \\le i \\le n-k+1$$$). This operation decreases the size of $$$a$$$ by $$$k-1$$$.\nDetermine if it's possible to turn $$$a$$$ into $$$[1]$$$ after several (possibly zero) operations.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$). The description of the test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\le k \\le n \\le 50$$$), the size of array $$$a$$$ and the length of segments that you can perform second type operation on.\nThe second line contains $$$n$$$ integers $$$a_{1}, a_{2}, \\ldots, a_{n}$$$ ($$$a_i$$$ is $$$0$$$ or $$$1$$$), elements of array $$$a$$$.\nOutput\nFor each test case, if it is possible to turn $$$a$$$ into $$$[1]$$$, print \"\nYES\n\", otherwise print \"\nNO\n\".\nExample\nInput\n7\n3 2\n0 1 0\n5 3\n1 0 1 1 0\n2 2\n1 1\n4 4\n0 0 0 0\n6 3\n0 0 1 0 0 1\n7 5\n1 1 1 1 1 1 1\n5 3\n0 0 1 0 0\nOutput\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nNote\nIn the first test case, you can perform the second type operation on second and third elements so $$$a$$$ becomes $$$[0, 1]$$$, then you can perform the second type operation on first and second elements, so $$$a$$$ turns to $$$[1]$$$.\nIn the fourth test case, it's obvious to see that you can't make any $$$1$$$, no matter what you do.\nIn the fifth test case, you can first perform a type 2 operation on the first three elements so that $$$a$$$ becomes $$$[1, 0, 0, 1]$$$, then perform a type 2 operation on the elements in positions two through four, so that $$$a$$$ becomes $$$[1, 1]$$$, and finally perform the first type operation on the remaining elements, so that $$$a$$$ becomes $$$[1]$$$.", "input": [ [ [ "3", "2" ], [ "0", "1", "0" ] ], [ [ "5", "3" ], [ "1", "0", "1", "1", "0" ] ], [ [ "2", "2" ], [ "1", "1" ] ], [ [ "4", "4" ], [ "0", "0", "0", "0" ] ], [ [ "6", "3" ], [ "0", "0", "1", "0", "0", "1" ] ], [ [ "7", "5" ], [ "1", "1", "1", "1", "1", "1", "1" ] ], [ [ "5", "3" ], [ "0", "0", "1", "0", "0" ] ] ], "output": [ "YES", "YES", "YES", "NO", "YES", "YES", "YES" ] }, { "problem_id": "1744B", "problem_name": "Even-Odd Increments\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1744/B", "problem_solution_link": "https://codeforces.com/problemset/status/1744/problem/B", "problem_statement": "B. Even-Odd Increments\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given $$$n$$$ of integers $$$a_1, a_2, \\ldots, a_n$$$. Process $$$q$$$ queries of two types:\nquery of the form \"\n0 $$$x_j$$$\n\": add the value $$$x_j$$$ to all even elements of the array $$$a$$$,\nquery of the form \"\n1 $$$x_j$$$\n\": add the value $$$x_j$$$ to all odd elements of the array $$$a$$$.\nNote that when processing the query, we look specifically at the odd/even value of $$$a_i$$$, not its index.\nAfter processing each query, print the sum of the elements of the array $$$a$$$.\nPlease note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like\nlong long\nfor C++).\nInput\nThe first line of the input contains an integer $$$t$$$ $$$(1 \\leq t \\leq 10^4$$$) \u2014 the number of test cases.\nThe descriptions of the test cases follow.\nThe first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \\leq n$$$, $$$q \\leq 10^5$$$) \u2014 the length of array $$$a$$$ and the number of queries.\nThe second line of each test case contains exactly $$$n$$$ integers: $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 10^9$$$) \u2014 elements of the array $$$a$$$.\nThe following $$$q$$$ lines contain queries as two integers $$$type_j$$$ and $$$x_j$$$ $$$(0 \\leq type_j \\leq 1$$$, $$$1 \\leq x_j \\leq 10^4$$$).\nIt is guaranteed that the sum of values $$$n$$$ over all test cases in a test does not exceed $$$10^5$$$. Similarly, the sum of values $$$q$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each test case, print $$$q$$$ numbers: the sum of the elements of the array $$$a$$$ after processing a query.\nExample\nInput\n4\n1 1\n1\n1 1\n3 3\n1 2 4\n0 2\n1 3\n0 5\n6 7\n1 3 2 4 10 48\n1 6\n0 5\n0 4\n0 5\n1 3\n0 12\n0 1\n6 7\n1000000000 1000000000 1000000000 11 15 17\n0 17\n1 10000\n1 51\n0 92\n0 53\n1 16\n0 1\nOutput\n2\n11\n14\n29\n80\n100\n100\n100\n118\n190\n196\n3000000094\n3000060094\n3000060400\n3000060952\n3000061270\n3000061366\n3000061366\nNote\nIn the first test case, the array $$$a = [2]$$$ after the first query.\nIn the third test case, the array $$$a$$$ is modified as follows: $$$[1, 3, 2, 4, 10, 48]$$$ $$$\\rightarrow$$$ $$$[7, 9, 2, 4, 10, 48]$$$ $$$\\rightarrow$$$ $$$[7, 9, 7, 9, 15, 53]$$$ $$$\\rightarrow$$$ $$$[7, 9, 7, 9, 15, 53]$$$ $$$\\rightarrow$$$ $$$[10, 12, 10, 12, 18, 56]$$$ $$$\\rightarrow$$$ $$$[22, 24, 22, 24, 30, 68]$$$ $$$\\rightarrow$$$ $$$[23, 25, 23, 25, 31, 69]$$$.", "input": [ [ [ "1", "1" ], [ "1", "1", "1" ] ], [ [ "3", "3" ], [ "1", "2", "4", "0", "2", "1", "3", "0", "5" ] ], [ [ "6", "7" ], [ "1", "3", "2", "4", "10", "48", "1", "6", "0", "5", "0", "4", "0", "5", "1", "3", "0", "12", "0", "1" ] ], [ [ "6", "7" ], [ "1000000000", "1000000000", "1000000000", "11", "15", "17", "0", "17", "1", "10000", "1", "51", "0", "92", "0", "53", "1", "16", "0", "1" ] ] ], "output": [ "2\n11\n14", "29\n80\n100\n100", "100\n118\n190\n196\n3000000094\n3000060094\n3000060400", "3000060952\n3000061270\n3000061366\n3000061366" ] }, { "problem_id": "1744A", "problem_name": "Number Replacement\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1744/A", "problem_solution_link": "https://codeforces.com/problemset/status/1744/problem/A", "problem_statement": "A. Number Replacement\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAn integer array $$$a_1, a_2, \\ldots, a_n$$$ is being transformed into an array of lowercase English letters using the following prodecure:\nWhile there is at least one number in the array:\nChoose any number $$$x$$$ from the array $$$a$$$, and any letter of the English alphabet $$$y$$$.\nReplace all occurrences of number $$$x$$$ with the letter $$$y$$$.\nFor example, if we initially had an array $$$a = [2, 3, 2, 4, 1]$$$, then we could transform it the following way:\nChoose the number $$$2$$$ and the letter\nc\n. After that $$$a = [c, 3, c, 4, 1]$$$.\nChoose the number $$$3$$$ and the letter\na\n. After that $$$a = [c, a, c, 4, 1]$$$.\nChoose the number $$$4$$$ and the letter\nt\n. After that $$$a = [c, a, c, t, 1]$$$.\nChoose the number $$$1$$$ and the letter\na\n. After that $$$a = [c, a, c, t, a]$$$.\nAfter the transformation all letters are united into a string, in our example we get the string \"\ncacta\n\".\nHaving the array $$$a$$$ and the string $$$s$$$ determine if the string $$$s$$$ could be got from the array $$$a$$$ after the described transformation?\nInput\nThe first line contains a single integer $$$t$$$ $$$(1 \\leq t \\leq 10^3$$$) \u2014 the number of test cases.\nThen the description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 50$$$) \u2014 the length of the array $$$a$$$ and the string $$$s$$$.\nThe second line of each test case contains exactly $$$n$$$ integers: $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 50$$$) \u2014 the elements of the array $$$a$$$.\nThe third line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of lowercase English letters.\nOutput\nFor each test case, output \"\nYES\n\", if we can get the string $$$s$$$ from the array $$$a$$$, and \"\nNO\n\" otherwise. You can output each letter in any case.\nExample\nInput\n7\n5\n2 3 2 4 1\ncacta\n1\n50\na\n2\n11 22\nab\n4\n1 2 2 1\naaab\n5\n1 2 3 2 1\naaaaa\n6\n1 10 2 9 3 8\nazzfdb\n7\n1 2 3 4 1 1 2\nabababb\nOutput\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nNote\nThe first test case corresponds to the sample described in the statement.\nIn the second test case we can choose the number $$$50$$$ and the letter\na\n.\nIn the third test case we can choose the number $$$11$$$ and the letter\na\n, after that $$$a = [a, 22]$$$. Then we choose the number $$$22$$$ and the letter\nb\nand get $$$a = [a, b]$$$.\nIn the fifth test case we can change all numbers one by one to the letter\na\n.", "input": [ [ [ "5" ], [ "2", "3", "2", "4", "1" ], [ "cacta" ] ], [ [ "1" ], [ "50" ], [ "a" ] ], [ [ "2" ], [ "11", "22" ], [ "ab" ] ], [ [ "4" ], [ "1", "2", "2", "1" ], [ "aaab" ] ], [ [ "5" ], [ "1", "2", "3", "2", "1" ], [ "aaaaa" ] ], [ [ "6" ], [ "1", "10", "2", "9", "3", "8" ], [ "azzfdb" ] ], [ [ "7" ], [ "1", "2", "3", "4", "1", "1", "2" ], [ "abababb" ] ] ], "output": [ "YES", "YES", "YES", "NO", "YES", "YES", "NO" ] }, { "problem_id": "1743B", "problem_name": "Permutation Value\nconstructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1743/B", "problem_solution_link": "https://codeforces.com/problemset/status/1743/problem/B", "problem_statement": "B. Permutation Value\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an integer $$$n$$$. You have to construct a permutation of size $$$n$$$.\nA\npermutation\nis an array where each integer from $$$1$$$ to $$$s$$$ (where $$$s$$$ is the size of permutation) occurs exactly once. For example, $$$[2, 1, 4, 3]$$$ is a permutation of size $$$4$$$; $$$[1, 2, 4, 5, 3]$$$ is a permutation of size $$$5$$$; $$$[1, 4, 3]$$$ is not a permutation (the integer $$$2$$$ is absent), $$$[2, 1, 3, 1]$$$ is not a permutation (the integer $$$1$$$ appears twice).\nA\nsubsegment\nof a permutation is a contiguous subsequence of that permutation. For example, the permutation $$$[2, 1, 4, 3]$$$ has $$$10$$$ subsegments: $$$[2]$$$, $$$[2, 1]$$$, $$$[2, 1, 4]$$$, $$$[2, 1, 4, 3]$$$, $$$[1]$$$, $$$[1, 4]$$$, $$$[1, 4, 3]$$$, $$$[4]$$$, $$$[4, 3]$$$ and $$$[3]$$$.\nThe\nvalue\nof the permutation is the number of its subsegments which are also permutations. For example, the value of $$$[2, 1, 4, 3]$$$ is $$$3$$$ since the subsegments $$$[2, 1]$$$, $$$[1]$$$ and $$$[2, 1, 4, 3]$$$ are permutations.\nYou have to construct a permutation of size $$$n$$$ with\nminimum possible value\namong all permutations of size $$$n$$$.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 48$$$) \u2014 the number of test cases.\nThen, $$$t$$$ lines follow. The $$$i$$$-th of them contains one integer $$$n$$$ ($$$3 \\le n \\le 50$$$) representing the $$$i$$$-th test case.\nOutput\nFor each test case, print $$$n$$$ integers \u2014 the permutation of size $$$n$$$ with\nminimum possible value\n. If there are multiple such permutations, print any of them.\nExample\nInput\n2\n5\n6\nOutput\n1 4 3 5 2\n4 1 6 2 5 3\nNote\nIn the first example, the permutation $$$[1, 4, 3, 5, 2]$$$ is one of the possible answers; its value is $$$2$$$.\nIn the second example, the permutation $$$[4, 1, 6, 2, 5, 3]$$$ is one of the possible answers; its value is $$$2$$$.", "input": [ [ [ "5" ] ], [ [ "6" ] ] ], "output": [ "1 4 3 5 2", "4 1 6 2 5 3" ] }, { "problem_id": "1743A", "problem_name": "Password\nbrute force, combinatorics, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1743/A", "problem_solution_link": "https://codeforces.com/problemset/status/1743/problem/A", "problem_statement": "A. Password\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMonocarp has forgotten the password to his mobile phone. The password consists of $$$4$$$ digits from $$$0$$$ to $$$9$$$ (note that it can start with the digit $$$0$$$).\nMonocarp remembers that his password had exactly two different digits, and each of these digits appeared exactly two times in the password. Monocarp also remembers some digits which were definitely not used in the password.\nYou have to calculate the number of different sequences of $$$4$$$ digits that could be the password for Monocarp's mobile phone (i.\u2009e. these sequences should meet all constraints on Monocarp's password).\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 200$$$)\u00a0\u2014 the number of testcases.\nThe first line of each testcase contains a single integer $$$n$$$ ($$$1 \\le n \\le 8$$$)\u00a0\u2014 the number of digits for which Monocarp remembers that they were not used in the password.\nThe second line contains $$$n$$$ different integers $$$a_1, a_2, \\dots a_n$$$ ($$$0 \\le a_i \\le 9$$$) representing the digits that were not used in the password. Note that the digits $$$a_1, a_2, \\dots, a_n$$$ are given in ascending order.\nOutput\nFor each testcase, print one integer\u00a0\u2014 the number of different $$$4$$$-digit sequences that meet the constraints.\nExample\nInput\n2\n8\n0 1 2 4 5 6 8 9\n1\n8\nOutput\n6\n216\nNote\nIn the first example, all possible passwords are: \"\n3377\n\", \"\n3737\n\", \"\n3773\n\", \"\n7337\n\", \"\n7373\n\", \"\n7733\n\".", "input": [ [ [ "8" ], [ "0", "1", "2", "4", "5", "6", "8", "9" ] ], [ [ "1" ], [ "8" ] ] ], "output": [ "6", "216" ] }, { "problem_id": "1742B", "problem_name": "Increasing\ngreedy, implementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1742/B", "problem_solution_link": "https://codeforces.com/problemset/status/1742/problem/B", "problem_statement": "B. Increasing\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ of $$$n$$$ positive integers. Determine if, by rearranging the elements, you can make the array strictly increasing. In other words, determine if it is possible to rearrange the elements such that $$$a_1 < a_2 < \\dots < a_n$$$ holds.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the length of the array.\nThe second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \\leq a_i \\leq 10^9$$$)\u00a0\u2014 the elements of the array.\nOutput\nFor each test case, output \"\nYES\n\" (without quotes) if the array satisfies the condition, and \"\nNO\n\" (without quotes) otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n3\n4\n1 1 1 1\n5\n8 7 1 3 4\n1\n5\nOutput\nNO\nYES\nYES\nNote\nIn the first test case any rearrangement will keep the array $$$[1,1,1,1]$$$, which is not strictly increasing.\nIn the second test case, you can make the array $$$[1,3,4,7,8]$$$.", "input": [ [ [ "4" ], [ "1", "1", "1", "1" ] ], [ [ "5" ], [ "8", "7", "1", "3", "4" ] ], [ [ "1" ], [ "5" ] ] ], "output": [ "NO", "YES", "YES" ] }, { "problem_id": "1742A", "problem_name": "Sum\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1742/A", "problem_solution_link": "https://codeforces.com/problemset/status/1742/problem/A", "problem_statement": "A. Sum\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given three integers $$$a$$$, $$$b$$$, and $$$c$$$. Determine if one of them is the sum of the other two.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 9261$$$)\u00a0\u2014 the number of test cases.\nThe description of each test case consists of three integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$0 \\leq a, b, c \\leq 20$$$).\nOutput\nFor each test case, output \"\nYES\n\" if one of the numbers is the sum of the other two, and \"\nNO\n\" otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n7\n1 4 3\n2 5 8\n9 11 20\n0 0 0\n20 20 20\n4 12 3\n15 7 8\nOutput\nYES\nNO\nYES\nYES\nNO\nNO\nYES\nNote\nIn the first test case, $$$1 + 3 = 4$$$.\nIn the second test case, none of the numbers is the sum of the other two.\nIn the third test case, $$$9 + 11 = 20$$$.", "input": [ [ [ "1", "4", "3" ] ], [ [ "2", "5", "8" ] ], [ [ "9", "11", "20" ] ], [ [ "0", "0", "0" ] ], [ [ "20", "20", "20" ] ], [ [ "4", "12", "3" ] ], [ [ "15", "7", "8" ] ] ], "output": [ "YES", "NO", "YES", "YES", "NO", "NO", "YES" ] }, { "problem_id": "1741B", "problem_name": "Funny Permutation\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1741/B", "problem_solution_link": "https://codeforces.com/problemset/status/1741/problem/B", "problem_statement": "B. Funny Permutation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA sequence of $$$n$$$ numbers is called\npermutation\nif it contains all numbers from $$$1$$$ to $$$n$$$ exactly once. For example, the sequences $$$[3, 1, 4, 2]$$$, [$$$1$$$] and $$$[2,1]$$$ are permutations, but $$$[1,2,1]$$$, $$$[0,1]$$$ and $$$[1,3,4]$$$ are not.\nFor a given number $$$n$$$ you need to make a permutation $$$p$$$ such that two requirements are satisfied at the same time:\nFor each element $$$p_i$$$, at least one of its neighbors has a value that differs from the value of $$$p_i$$$ by one. That is, for each element $$$p_i$$$ ($$$1 \\le i \\le n$$$), at least one of its neighboring elements (standing to the left or right of $$$p_i$$$) must be $$$p_i + 1$$$, or $$$p_i - 1$$$.\nthe permutation must have no fixed points. That is, for every $$$i$$$ ($$$1 \\le i \\le n$$$), $$$p_i \\neq i$$$ must be satisfied.\nLet's call the permutation that satisfies these requirements\nfunny\n.\nFor example, let $$$n = 4$$$. Then [$$$4, 3, 1, 2$$$] is a\nfunny\npermutation, since:\nto the right of $$$p_1=4$$$ is $$$p_2=p_1-1=4-1=3$$$;\nto the left of $$$p_2=3$$$ is $$$p_1=p_2+1=3+1=4$$$;\nto the right of $$$p_3=1$$$ is $$$p_4=p_3+1=1+1=2$$$;\nto the left of $$$p_4=2$$$ is $$$p_3=p_4-1=2-1=1$$$.\nfor all $$$i$$$ is $$$p_i \\ne i$$$.\nFor a given positive integer $$$n$$$, output\nany\nfunny\npermutation of length $$$n$$$, or output\n-1\nif\nfunny\npermutation of length $$$n$$$ does not exist.\nInput\nThe first line of input data contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe description of the test cases follows.\nEach test case consists of f single line containing one integer $$$n$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print on a separate line:\nany\nfunny\npermutation $$$p$$$ of length $$$n$$$;\nor the number\n-1\nif the permutation you are looking for does not exist.\nExample\nInput\n5\n4\n3\n7\n5\n2\nOutput\n3 4 2 1\n-1\n6 7 4 5 3 2 1\n5 4 1 2 3\n2 1\nNote\nThe first test case is explained in the problem statement.\nIn the second test case, it is not possible to make the required permutation: permutations $$$[1, 2, 3]$$$, $$$[1, 3, 2]$$$, $$$[2, 1, 3]$$$, $$$[3, 2, 1]$$$ have fixed points, and in $$$[2, 3, 1]$$$ and $$$[3, 1, 2]$$$ the first condition is met not for all positions.", "input": [ [ [ "4" ] ], [ [ "3" ] ], [ [ "7" ] ], [ [ "5" ] ], [ [ "2" ] ] ], "output": [ "3 4 2 1", "-1", "6 7 4 5 3 2 1", "5 4 1 2 3", "2 1" ] }, { "problem_id": "1741A", "problem_name": "Compare T-Shirt Sizes\nimplementation, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1741/A", "problem_solution_link": "https://codeforces.com/problemset/status/1741/problem/A", "problem_statement": "A. Compare T-Shirt Sizes\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTwo T-shirt sizes are given: $$$a$$$ and $$$b$$$. The T-shirt size is either a string\nM\nor a string consisting of several (possibly zero) characters\nX\nand one of the characters\nS\nor\nL\n.\nFor example, strings\nM\n,\nXXL\n,\nS\n,\nXXXXXXXS\ncould be the size of some T-shirts. And the strings\nXM\n,\nLL\n,\nSX\nare not sizes.\nThe letter\nM\nstands for medium,\nS\nfor small,\nL\nfor large. The letter\nX\nrefers to the degree of size (from eXtra). For example,\nXXL\nis extra-extra-large (bigger than\nXL\n, and smaller than\nXXXL\n).\nYou need to compare two given sizes of T-shirts $$$a$$$ and $$$b$$$.\nThe T-shirts are compared as follows:\nany small size (no matter how many letters\nX\n) is smaller than the medium size and any large size;\nany large size (regardless of the number of letters\nX\n) is larger than the medium size and any small size;\nthe more letters\nX\nbefore\nS\n, the smaller the size;\nthe more letters\nX\nin front of\nL\n, the larger the size.\nFor example:\nXXXS\n<\nXS\nXXXL\n>\nXL\nXL\n>\nM\nXXL\n=\nXXL\nXXXXXS\n<\nM\nXL\n>\nXXXS\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of one line, in which $$$a$$$ and $$$b$$$ T-shirt sizes are written. The lengths of the strings corresponding to the T-shirt sizes do not exceed $$$50$$$. It is guaranteed that all sizes are correct.\nOutput\nFor each test case, print on a separate line the result of comparing $$$a$$$ and $$$b$$$ T-shirt sizes (lines \"\n<\n\", \"\n>\n\" or \"\n=\n\" without quotes).\nExample\nInput\n6\nXXXS XS\nXXXL XL\nXL M\nXXL XXL\nXXXXXS M\nL M\nOutput\n<\n>\n>\n=\n<\n>", "input": [ [ [ "XXXS", "XS" ] ], [ [ "XXXL", "XL" ] ], [ [ "XL", "M" ] ], [ [ "XXL", "XXL" ] ], [ [ "XXXXXS", "M" ] ], [ [ "L", "M" ] ] ], "output": [ "<", ">", ">", "=", "<", ">" ] }, { "problem_id": "1740B", "problem_name": "Jumbo Extra Cheese 2\ngeometry, greedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1740/B", "problem_solution_link": "https://codeforces.com/problemset/status/1740/problem/B", "problem_statement": "B. Jumbo Extra Cheese 2\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPak Chanek has $$$n$$$ two-dimensional slices of cheese. The $$$i$$$-th slice of cheese can be represented as a rectangle of dimensions $$$a_i \\times b_i$$$. We want to arrange them on the two-dimensional plane such that:\nEach edge of each cheese is parallel to either the x-axis or the y-axis.\nThe bottom edge of each cheese is a segment of the x-axis.\nNo two slices of cheese overlap, but their sides can touch.\nThey form one connected shape.\nNote that we can arrange them in any order (the leftmost slice of cheese is not necessarily the first slice of cheese). Also note that we can rotate each slice of cheese in any way as long as all conditions still hold.\nFind the minimum possible perimeter of the constructed shape.\nInput\nEach test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 2 \\cdot 10^4$$$) \u2014 the number of test cases. The following lines contain the description of each test case.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 2 \\cdot 10^5$$$) \u2014 the number of slices of cheese Pak Chanek has.\nThe $$$i$$$-th of the next $$$n$$$ lines of each test case contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \\leq a_i,b_i \\leq 10^9$$$) \u2014 the dimensions of the $$$i$$$-th slice of cheese.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, output a line containing an integer representing the minimum possible perimeter of the constructed shape.\nExample\nInput\n3\n4\n4 1\n4 5\n1 1\n2 3\n3\n2 4\n2 6\n2 3\n1\n2 65\nOutput\n26\n24\n134\nNote\nIn the first test case, a way of getting the minimum possible perimeter is to arrange the slices of cheese as follows.\nWe can calculate that the perimeter of the constructed shape is $$$2+5+1+1+1+1+3+1+5+1+2+3=26$$$. It can be shown that we cannot get a smaller perimeter.\nConsider the following\ninvalid\narrangement.\nEven though the perimeter of the shape above is $$$24$$$, it does not satisfy all conditions of the problem. The bottom edge of the $$$1 \\times 1$$$ slice of cheese is not a segment of the x-axis.\nIn the second test case, a way of getting the minimum possible perimeter is to arrange the slices of cheese as follows.\nWe can calculate that the perimeter of the constructed shape is $$$2+2+2+3+2+3+2+2+2+4=24$$$. It can be shown that we cannot get a smaller perimeter.", "input": [ [ [ "4" ], [ "4", "1" ], [ "4", "5" ], [ "1", "1" ], "2", "3" ], [ [ "3" ], [ "2", "4" ], [ "2", "6" ], [ "2", "3" ] ], [ [ "1" ], [ "2", "65" ] ] ], "output": [ "26", "24", "134" ] }, { "problem_id": "1740A", "problem_name": "Factorise N+M\nconstructive algorithms, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1740/A", "problem_solution_link": "https://codeforces.com/problemset/status/1740/problem/A", "problem_statement": "A. Factorise N+M\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPak Chanek has a prime number$$$^\\dagger$$$ $$$n$$$. Find a prime number $$$m$$$ such that $$$n + m$$$ is not prime.\n$$$^\\dagger$$$ A prime number is a number with\nexactly\n$$$2$$$ factors. The first few prime numbers are $$$2,3,5,7,11,13,\\ldots$$$. In particular, $$$1$$$ is\nnot\na prime number.\nInput\nEach test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$) \u2014 the number of test cases. The following lines contain the description of each test case.\nThe only line of each test case contains a prime number $$$n$$$ ($$$2 \\leq n \\leq 10^5$$$).\nOutput\nFor each test case, output a line containing a prime number $$$m$$$ ($$$2 \\leq m \\leq 10^5$$$) such that $$$n + m$$$ is not prime. It can be proven that under the constraints of the problem, such $$$m$$$ always exists.\nIf there are multiple solutions, you can output any of them.\nExample\nInput\n3\n7\n2\n75619\nOutput\n2\n7\n47837\nNote\nIn the first test case, $$$m = 2$$$, which is prime, and $$$n + m = 7 + 2 = 9$$$, which is not prime.\nIn the second test case, $$$m = 7$$$, which is prime, and $$$n + m = 2 + 7 = 9$$$, which is not prime.\nIn the third test case, $$$m = 47837$$$, which is prime, and $$$n + m = 75619 + 47837 = 123456$$$, which is not prime.", "input": [ [ [ "7" ] ], [ [ "2" ] ], [ [ "75619" ] ] ], "output": [ "2", "7", "47837" ] }, { "problem_id": "1730A", "problem_name": "Planets\ndata structures, greedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1730/A", "problem_solution_link": "https://codeforces.com/problemset/status/1730/problem/A", "problem_statement": "A. Planets\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nOne day, Vogons wanted to build a new hyperspace highway through a distant system with $$$n$$$ planets. The $$$i$$$-th planet is on the orbit $$$a_i$$$, there could be multiple planets on the same orbit. It's a pity that all the planets are on the way and need to be destructed.\nVogons have two machines to do that.\nThe first machine in one operation can destroy any planet at cost of $$$1$$$ Triganic Pu.\nThe second machine in one operation can destroy all planets on a single orbit in this system at the cost of $$$c$$$ Triganic Pus.\nVogons can use each machine as many times as they want.\nVogons are very greedy, so they want to destroy all planets with minimum amount of money spent. Can you help them to know the minimum cost of this project?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases. Then the test cases follow.\nEach test case consists of two lines.\nThe first line contains two integers $$$n$$$ and $$$c$$$ ($$$1 \\le n, c \\le 100$$$) \u2014 the number of planets and the cost of the second machine usage.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the orbit of the $$$i$$$-th planet.\nOutput\nFor each test case print a single integer \u2014 the minimum cost of destroying all planets.\nExamples\nInput\n4\n10 1\n2 1 4 5 2 4 5 5 1 2\n5 2\n3 2 1 2 2\n2 2\n1 1\n2 2\n1 2\nOutput\n4\n4\n2\n2\nInput\n1\n1 100\n1\nOutput\n1\nNote\nIn the first test case, the cost of using both machines is the same, so you can always use the second one and destroy all planets in orbit $$$1$$$, all planets in orbit $$$2$$$, all planets in orbit $$$4$$$, all planets in orbit $$$5$$$.\nIn the second test case, it is advantageous to use the second machine for $$$2$$$ Triganic Pus to destroy all the planets in orbit $$$2$$$, then destroy the remaining two planets using the first machine.\nIn the third test case, you can use the first machine twice or the second machine once.\nIn the fourth test case, it is advantageous to use the first machine twice.", "input": [ [ [ "10", "1" ], [ "2", "1", "4", "5", "2", "4", "5", "5", "1", "2" ] ], [ [ "5", "2" ], [ "3", "2", "1", "2", "2" ] ], [ [ "2", "2" ], [ "1", "1" ] ], [ [ "2", "2" ], [ "1", "2" ] ], [ [ "1", "100" ], [ "1" ] ] ], "output": [ "4", "4", "2", "2", "1" ] }, { "problem_id": "1739A", "problem_name": "Immobile Knight\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1739/A", "problem_solution_link": "https://codeforces.com/problemset/status/1739/problem/A", "problem_statement": "A. Immobile Knight\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a chess board of size $$$n \\times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.\nLet's call a cell\nisolated\nif a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction:\nFind any\nisolated\ncell on the board. If there are no such cells, print any cell on the board.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 64$$$)\u00a0\u2014 the number of testcases.\nThe only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 8$$$)\u00a0\u2014 the number of rows and columns of the board.\nOutput\nFor each testcase, print two integers\u00a0\u2014 the row and the column of any\nisolated\ncell on the board. If there are no such cells, print any cell on the board.\nExample\nInput\n3\n1 7\n8 8\n3 3\nOutput\n1 7\n7 2\n2 2\nNote\nIn the first testcase, all cells are\nisolated\n. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.\nIn the second testcase, there are no\nisolated\ncells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.\nIn the third testcase, only the middle cell of the board is\nisolated\n. The knight can move freely around the border of the board, but can't escape the middle.", "input": [ [ [ "1", "7" ] ], [ [ "8", "8" ] ], [ [ "3", "3" ] ] ], "output": [ "1 7", "7 2", "2 2" ] }, { "problem_id": "1738A", "problem_name": "Glory Addicts\ngreedy, implementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1738/A", "problem_solution_link": "https://codeforces.com/problemset/status/1738/problem/A", "problem_statement": "A. Glory Addicts\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nThe hero is addicted to glory, and is fighting against a monster.\nThe hero has $$$n$$$ skills. The $$$i$$$-th skill is of type $$$a_i$$$ (either\nfire\nor\nfrost\n) and has initial damage $$$b_i$$$.\nThe hero can perform all of the $$$n$$$ skills in any order (with each skill performed exactly\nonce\n). When performing each skill, the hero can play a magic as follows:\nIf the current skill immediately follows another skill of a different type, then its damage is\ndoubled\n.\nIn other words,\nIf a skill of type fire and with initial damage $$$c$$$ is performed immediately after a skill of type fire, then it will deal $$$c$$$ damage;\nIf a skill of type fire and with initial damage $$$c$$$ is performed immediately after a skill of type frost, then it will deal $$$2c$$$ damage;\nIf a skill of type frost and with initial damage $$$c$$$ is performed immediately after a skill of type fire, then it will deal $$$2c$$$ damage;\nIf a skill of type frost and with initial damage $$$c$$$ is performed immediately after a skill of type frost , then it will deal $$$c$$$ damage.\nYour task is to find the\nmaximum\ndamage the hero can deal.\nInput\nEach test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 10^5$$$) \u2014 the number of test cases. The following lines contain the description of each test case.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 10^5$$$), indicating the number of skills.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$0 \\leq a_i \\leq 1$$$), where $$$a_i$$$ indicates the type of the $$$i$$$-th skill. Specifically, the $$$i$$$-th skill is of type fire if $$$a_i = 0$$$, and of type frost if $$$a_i = 1$$$.\nThe third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \\dots, b_n$$$ ($$$1 \\leq b_i \\leq 10^9$$$), where $$$b_i$$$ indicates the initial damage of the $$$i$$$-th skill.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each test case, output the maximum damage the hero can deal.\nExample\nInput\n4\n4\n0 1 1 1\n1 10 100 1000\n6\n0 0 0 1 1 1\n3 4 5 6 7 8\n3\n1 1 1\n1000000000 1000000000 1000000000\n1\n1\n1\nOutput\n2112\n63\n3000000000\n1\nNote\nIn the first test case, we can order the skills by $$$[3, 1, 4, 2]$$$, and the total damage is $$$100 + 2 \\times 1 + 2 \\times 1000 + 10 = 2112$$$.\nIn the second test case, we can order the skills by $$$[1, 4, 2, 5, 3, 6]$$$, and the total damage is $$$3 + 2 \\times 6 + 2 \\times 4 + 2 \\times 7 + 2 \\times 5 + 2 \\times 8 = 63$$$.\nIn the third test case, we can order the skills by $$$[1, 2, 3]$$$, and the total damage is $$$1000000000 + 1000000000 + 1000000000 = 3000000000$$$.\nIn the fourth test case, there is only one skill with initial damage $$$1$$$, so the total damage is $$$1$$$.", "input": [ [ [ "4" ], [ "0", "1", "1", "1" ], [ "1", "10", "100", "1000" ] ], [ [ "6" ], [ "0", "0", "0", "1", "1", "1" ], [ "3", "4", "5", "6", "7", "8" ] ], [ [ "3" ], [ "1", "1", "1" ], [ "1000000000", "1000000000", "1000000000" ] ], [ [ "1" ], [ "1" ], [ "1" ] ] ], "output": [ "2112", "63", "3000000000", "1" ] }, { "problem_id": "1736A", "problem_name": "Make A Equal to B\nbrute force, greedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1736/A", "problem_solution_link": "https://codeforces.com/problemset/status/1736/problem/A", "problem_statement": "A. Make A Equal to B\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two arrays $$$a$$$ and $$$b$$$ of $$$n$$$ elements, each element is either $$$0$$$ or $$$1$$$.\nYou can make operations of $$$2$$$ kinds.\nPick an index $$$i$$$ and change $$$a_i$$$ to $$$1-a_i$$$.\nRearrange the array $$$a$$$ however you want.\nFind the minimum number of operations required to make $$$a$$$ equal to $$$b$$$.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 400$$$) \u2014 the number of test cases. Description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$) \u2014 the length of the arrays $$$a$$$ and $$$b$$$.\nThe second line of each test case contains $$$n$$$ space-separated integers $$$a_1,a_2,\\ldots,a_n$$$ ($$$a_i$$$ is $$$0$$$ or $$$1$$$), representing the array $$$a$$$.\nThe third line of each test case contains $$$n$$$ space-separated integers $$$b_1,b_2,\\ldots,b_n$$$ ($$$b_i$$$ is $$$0$$$ or $$$1$$$), representing the array $$$b$$$.\nOutput\nFor each test case, print the minimum number of operations required to make $$$a$$$ equal to $$$b$$$.\nExample\nInput\n5\n3\n1 0 1\n0 0 1\n4\n1 1 0 0\n0 1 1 1\n2\n1 1\n1 1\n4\n1 0 0 1\n0 1 1 0\n1\n0\n1\nOutput\n1\n2\n0\n1\n1\nNote\nIn the first case, we need only one operation: change $$$a_1$$$ to $$$1-a_i$$$. Now $$$a = [0, 0]$$$ which is equal to $$$b$$$.\nIn the second case, the optimal way is to rearrange $$$a$$$ to get the array $$$[0, 1, 11$$$. Now $$$a = [0, 0, 1]$$$ which is equal to $$$b$$$.\nIn the second case, one of optimal ways would be to first change $$$a_3$$$ to $$$1 - a_3$$$, then rearrange $$$a$$$.\nIn the third case, no operation is needed.\nIn the fourth case, the optimal way is to rearrange $$$a$$$ to get the array $$$[0, 1, 1, 0]$$$.", "input": [ [ [ "3" ], [ "1", "0", "1" ], [ "0", "0", "1" ] ], [ [ "4" ], [ "1", "1", "0", "0" ], [ "0", "1", "1", "1" ] ], [ [ "2" ], [ "1", "1" ], [ "1", "1" ] ], [ [ "4" ], [ "1", "0", "0", "1" ], [ "0", "1", "1", "0" ] ], [ [ "1" ], [ "0" ], [ "1" ] ] ], "output": [ "1", "2", "0", "1", "1" ] }, { "problem_id": "1735A", "problem_name": "Working Week\nconstructive algorithms, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1735/A", "problem_solution_link": "https://codeforces.com/problemset/status/1735/problem/A", "problem_statement": "A. Working Week\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYour working week consists of $$$n$$$ days numbered from $$$1$$$ to $$$n$$$, after day $$$n$$$ goes day $$$1$$$ again. And $$$3$$$ of them are days off. One of the days off is the last day, day $$$n$$$. You have to decide when the other two are.\nChoosing days off, you pursue two goals:\nNo two days should go one after the other. Note that you can't make day $$$1$$$ a day off because it follows day $$$n$$$.\nWorking segments framed by days off should be as dissimilar as possible in duration. More specifically, if the segments are of size $$$l_1$$$, $$$l_2$$$, and $$$l_3$$$ days long, you want to maximize $$$\\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$$$.\nOutput the maximum value of $$$\\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$$$ that can be obtained.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases. The description of test cases follows.\nThe only line of each test case contains the integer $$$n$$$ ($$$6 \\le n \\le 10^9$$$).\nOutput\nFor each test case, output one integer \u2014 the maximum possible obtained value.\nExample\nInput\n3\n6\n10\n1033\nOutput\n0\n1\n342\nNote\nIn the image below you can see the example solutions for the first two test cases. Chosen days off are shown in purple. Working segments are underlined in green.\nIn test case $$$1$$$, the only options for days off are days $$$2$$$, $$$3$$$, and $$$4$$$ (because $$$1$$$ and $$$5$$$ are next to day $$$n$$$). So the only way to place them without selecting neighboring days is to choose days $$$2$$$ and $$$4$$$. Thus, $$$l_1 = l_2 = l_3 = 1$$$, and the answer $$$\\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|) = 0$$$.\nFor test case $$$2$$$, one possible way to choose days off is shown. The working segments have the lengths of $$$2$$$, $$$1$$$, and $$$4$$$ days. So the minimum difference is $$$1 = \\min(1, 3, 2) = \\min(|2 - 1|, |1 - 4|, |4 - 2|)$$$. It can be shown that there is no way to make it larger.", "input": [ [ [ "6" ] ], [ [ "10" ] ], [ [ "1033" ] ] ], "output": [ "0", "1", "342" ] }, { "problem_id": "1734B", "problem_name": "Bright, Nice, Brilliant\nconstructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1734/B", "problem_solution_link": "https://codeforces.com/problemset/status/1734/problem/B", "problem_statement": "B. Bright, Nice, Brilliant\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a pyramid which consists of $$$n$$$ floors. The floors are numbered from top to bottom in increasing order. In the pyramid, the $$$i$$$-th floor consists of $$$i$$$ rooms.\nDenote the $$$j$$$-th room on the $$$i$$$-th floor as $$$(i,j)$$$. For all positive integers $$$i$$$ and $$$j$$$ such that $$$1 \\le j \\le i < n$$$, there are $$$2$$$\none-way\nstaircases which lead from $$$(i,j)$$$ to $$$(i+1,j)$$$ and from $$$(i,j)$$$ to $$$(i+1,j+1)$$$ respectively.\nIn each room you can either put a torch or leave it empty. Define the\nbrightness\nof a room $$$(i, j)$$$ to be the number of rooms with a torch from which you can reach the room $$$(i, j)$$$ through a non-negative number of staircases.\nFor example, when $$$n=5$$$ and torches are placed in the rooms $$$(1,1)$$$, $$$(2,1)$$$, $$$(3,2)$$$, $$$(4,1)$$$, $$$(4,3)$$$, and $$$(5,3)$$$, the pyramid can be illustrated as follows:\nIn the above picture, rooms with torches are colored in yellow, and empty rooms are white. The blue numbers in the bottom-right corner indicate the brightness of the rooms.\nThe room $$$(4,2)$$$ (the room with a star) has brightness $$$3$$$. In the picture below, the rooms from where you can reach $$$(4,2)$$$ have red border. The brightness is $$$3$$$ since there are three torches among these rooms.\nThe pyramid is called\nnice\nif and only if for all floors, all rooms in the floor have the same brightness.\nDefine the\nbrilliance\nof a nice pyramid to be the sum of brightness over the rooms $$$(1,1)$$$, $$$(2,1)$$$, $$$(3,1)$$$, ..., $$$(n,1)$$$.\nFind an arrangement of torches in the pyramid, such that the resulting pyramid is nice and its brilliance is maximized.\nWe can show that an answer always exists. If there are multiple answers, output any one of them.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe only line of each test case contains a single positive integer $$$n$$$ ($$$1 \\le n \\le 500$$$)\u00a0\u2014 the number of floors in the pyramid.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$500$$$.\nOutput\nFor each test case, output $$$n$$$ lines, the arrangement of torches in the pyramid.\nThe $$$i$$$-th line should contain $$$i$$$ integers, each separated with a space. The $$$j$$$-th integer on the $$$i$$$-th line should be $$$1$$$ if room $$$(i,j)$$$ has a torch, and $$$0$$$ otherwise.\nWe can show that an answer always exists. If there are multiple answers, output any one of them.\nExample\nInput\n3\n1\n2\n3\nOutput\n1 \n1 \n1 1 \n1 \n1 1 \n1 0 1\nNote\nIn the third test case, torches are placed in $$$(1,1)$$$, $$$(2,1)$$$, $$$(2,2)$$$, $$$(3,1)$$$, and $$$(3,3)$$$.\nThe pyramid is nice as rooms on each floor have the same brightness. For example, all rooms on the third floor have brightness $$$3$$$.\nThe brilliance of the pyramid is $$$1+2+3 = 6$$$. It can be shown that no arrangements with $$$n=3$$$ will have a greater brilliance.", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "3" ] ] ], "output": [ ["1", "1"], ["1 1", "1"], ["1 1", "1 0 1"] ], "error": true }, { "problem_id": "1734A", "problem_name": "Select Three Sticks\nbrute force, greedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1734/A", "problem_solution_link": "https://codeforces.com/problemset/status/1734/problem/A", "problem_statement": "A. Select Three Sticks\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given $$$n$$$ sticks with positive integral length $$$a_1, a_2, \\ldots, a_n$$$.\nYou can perform the following operation any number of times (possibly zero):\nchoose one stick, then either increase or decrease its length by $$$1$$$. After each operation, all sticks should have positive lengths.\nWhat is the minimum number of operations that you have to perform such that it is possible to select three of the $$$n$$$ sticks and use them without breaking to form an\nequilateral triangle\n?\nAn\nequilateral triangle\nis a triangle where all of its three sides have the same length.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$3 \\le n \\le 300$$$)\u00a0\u2014 the number of sticks.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$)\u00a0\u2014 the lengths of the sticks.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$300$$$.\nOutput\nFor each test case, print one integer on a single line\u00a0\u2014 the minimum number of operations to be made.\nExample\nInput\n4\n3\n1 2 3\n4\n7 3 7 3\n5\n3 4 2 1 1\n8\n3 1 4 1 5 9 2 6\nOutput\n2\n4\n1\n1\nNote\nIn the first test case, you can increase the length of the first stick by $$$1$$$, then decrease the length of the third stick by $$$1$$$. In total, you perform $$$2$$$ operations, such that the three sticks form an equilateral triangle of side length $$$2$$$.\nIn the fourth test case, you can decrease the length of the seventh stick by $$$1$$$. An equilateral triangle of side length $$$1$$$ can be selected and formed by the second, fourth, and seventh sticks.", "input": [ [ [ "3" ], [ "1", "2", "3" ] ], [ [ "4" ], [ "7", "3", "7", "3" ] ], [ [ "5" ], [ "3", "4", "2", "1", "1" ] ], [ [ "8" ], [ "3", "1", "4", "1", "5", "9", "2", "6" ] ] ], "output": [ "2", "4", "1", "1" ] }, { "problem_id": "1733A", "problem_name": "Consecutive Sum\ngreedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1733/A", "problem_solution_link": "https://codeforces.com/problemset/status/1733/problem/A", "problem_statement": "A. Consecutive Sum\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ with $$$n$$$ integers. You can perform the following operation at most $$$k$$$ times:\nChoose two indices $$$i$$$ and $$$j$$$, in which $$$i \\,\\bmod\\, k = j \\,\\bmod\\, k$$$ ($$$1 \\le i < j \\le n$$$).\nSwap $$$a_i$$$ and $$$a_j$$$.\nAfter performing all operations, you have to select $$$k$$$ consecutive elements, and the sum of the $$$k$$$ elements becomes your score. Find the maximum score you can get.\nHere $$$x \\bmod y$$$ denotes the remainder from dividing $$$x$$$ by $$$y$$$.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 600$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of two lines.\nThe first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 100$$$)\u00a0\u2014 the length of the array and the number in the statement above.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i \\le 10^9$$$) \u00a0\u2014 the array itself.\nOutput\nFor each test case, print the maximum score you can get, one per line.\nExample\nInput\n5\n3 2\n5 6 0\n1 1\n7\n5 3\n7 0 4 0 4\n4 2\n2 7 3 4\n3 3\n1000000000 1000000000 999999997\nOutput\n11\n7\n15\n10\n2999999997\nNote\nIn the first test case, we can get a score of $$$11$$$ if we select $$$a_1, a_2$$$ without performing any operations.\nIn the third test case, we can get a score of $$$15$$$ if we first swap $$$a_1$$$ with $$$a_4$$$ and then select $$$a_3, a_4, a_5$$$.", "input": [ [ [ "3", "2" ], [ "5", "6", "0" ] ], [ [ "1", "1" ], [ "7" ] ], [ [ "5", "3" ], [ "7", "0", "4", "0", "4" ] ], [ [ "4", "2" ], [ "2", "7", "3", "4" ] ], [ [ "3", "3" ], [ "1000000000", "1000000000", "999999997" ] ] ], "output": [ "11", "7", "15", "10", "2999999997" ] }, { "problem_id": "1731A", "problem_name": "Joey Takes Money\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1731/A", "problem_solution_link": "https://codeforces.com/problemset/status/1731/problem/A", "problem_statement": "A. Joey Takes Money\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nJoey is low on money. His friend Chandler wants to lend Joey some money, but can't give him directly, as Joey is too proud of himself to accept it. So, in order to trick him, Chandler asks Joey to play a game.\nIn this game, Chandler gives Joey an array $$$a_1, a_2, \\dots, a_n$$$ ($$$n \\geq 2$$$) of positive integers ($$$a_i \\ge 1$$$).\nJoey can perform the following operation on the array any number of times:\nTake two indices $$$i$$$ and $$$j$$$ ($$$1 \\le i < j \\le n)$$$.\nChoose two\nintegers\n$$$x$$$ and $$$y$$$ ($$$x, y \\ge 1$$$) such that $$$x \\cdot y = a_i \\cdot a_j$$$.\nReplace $$$a_i$$$ by $$$x$$$ and $$$a_j$$$ by $$$y$$$.\nIn the end, Joey will get the money equal to\nthe sum\nof elements of the final array.\nFind the maximum amount of money $$$\\mathrm{ans}$$$ Joey can get\nbut print\n$$$2022 \\cdot \\mathrm{ans}$$$. Why multiplied by $$$2022$$$? Because we are never gonna see it again!\nIt is guaranteed that the product of all the elements of the array $$$a$$$ doesn't exceed $$$10^{12}$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\leq t \\leq 4000$$$). Description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 50$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\leq a_i \\leq 10^6$$$)\u00a0\u2014 the array itself.\nIt's guaranteed that the product of all $$$a_i$$$ doesn't exceed $$$10^{12}$$$ (i.\u00a0e. $$$a_1 \\cdot a_2 \\cdot \\ldots \\cdot a_n \\le 10^{12}$$$).\nOutput\nFor each test case, print the maximum money Joey can get\nmultiplied by\n$$$2022$$$.\nExample\nInput\n3\n3\n2 3 2\n2\n1 3\n3\n1000000 1000000 1\nOutput\n28308\n8088\n2022000000004044\nNote\nIn the first test case, Joey can do the following:\nHe chooses $$$i = 1$$$ and $$$j = 2$$$ (so he has $$$a[i] \\cdot a[j] = 6$$$), chooses $$$x = 6$$$ and $$$y = 1$$$ and makes $$$a[i] = 6$$$ and $$$a[j] = 1$$$. $$$$$$[2, 3, 2] \\xrightarrow[x = 6,\\; y = 1]{i = 1,\\; j = 2} [6, 1, 2]$$$$$$\nHe chooses $$$i = 1$$$ and $$$j = 3$$$ (so he has $$$a[i] \\cdot a[j] = 12$$$), chooses $$$x = 12$$$ and $$$y = 1$$$ and makes $$$a[i] = 12$$$ and $$$a[j] = 1$$$. $$$$$$[6, 1, 2] \\xrightarrow[x = 12,\\; y = 1]{i = 1,\\; j = 3} [12, 1, 1]$$$$$$\nThe sum is $$$14$$$ which is the maximum of all possible sums. The answer is $$$2022 \\cdot 14 = 28308$$$.", "input": [ [ [ "3" ], [ "2", "3", "2" ] ], [ [ "2" ], [ "1", "3" ] ], [ [ "3" ], [ "1000000", "1000000", "1" ] ] ], "output": [ "28308", "8088", "2022000000004044" ] }, { "problem_id": "1725A", "problem_name": "Accumulation of Dominoes\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1725/A", "problem_solution_link": "https://codeforces.com/problemset/status/1725/problem/A", "problem_statement": "A. Accumulation of Dominoes\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPak Chanek has a grid that has $$$N$$$ rows and $$$M$$$ columns. Each row is numbered from $$$1$$$ to $$$N$$$ from top to bottom. Each column is numbered from $$$1$$$ to $$$M$$$ from left to right.\nEach tile in the grid contains a number. The numbers are arranged as follows:\nRow $$$1$$$ contains integers from $$$1$$$ to $$$M$$$ from left to right.\nRow $$$2$$$ contains integers from $$$M+1$$$ to $$$2 \\times M$$$ from left to right.\nRow $$$3$$$ contains integers from $$$2 \\times M+1$$$ to $$$3 \\times M$$$ from left to right.\nAnd so on until row $$$N$$$.\nA domino is defined as two different tiles in the grid that touch\nby their sides\n. A domino is said to be\ntight\nif and only if the two numbers in the domino have a difference of exactly $$$1$$$. Count the number of distinct\ntight\ndominoes in the grid.\nTwo dominoes are said to be distinct if and only if there exists at least one tile that is in one domino, but not in the other.\nInput\nThe only line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \\leq N, M \\leq 10^9$$$) \u2014 the number of rows and columns in the grid.\nOutput\nAn integer representing the number of distinct\ntight\ndominoes in the grid.\nExamples\nInput\n3 4\nOutput\n9\nInput\n2 1\nOutput\n1\nNote\nThe picture below is the grid that Pak Chanek has in the first example.\nThe picture below is an example of a\ntight\ndomino in the grid.", "input": [ [ [ "3", "4" ] ], [ [ "2", "1" ] ] ], "output": [ "9", "1" ] }, { "problem_id": "1729B", "problem_name": "Decode String\ngreedy, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1729/B", "problem_solution_link": "https://codeforces.com/problemset/status/1729/problem/B", "problem_statement": "B. Decode String\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp has a string $$$s$$$ consisting of lowercase Latin letters.\nHe encodes it using the following algorithm.\nHe goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet:\nif the letter number is single-digit number (less than $$$10$$$), then just writes it out;\nif the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number\n0\nafter.\nFor example, if the string $$$s$$$ is\ncode\n, then Polycarp will encode this string as follows:\n'\nc\n'\u00a0\u2014 is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds\n3\nto the code (the code becomes equal to\n3\n);\n'\no\n'\u00a0\u2014 is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds\n15\nto the code and also\n0\n(the code becomes\n3150\n);\n'\nd\n'\u00a0\u2014 is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds\n4\nto the code (the code becomes\n31504\n);\n'\ne\n'\u00a0\u2014 is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds\n5\nto the code (the code becomes\n315045\n).\nThus, code of string\ncode\nis\n315045\n.\nYou are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$).\nInput\nThe first line of the input contains an integer $$$q$$$ ($$$1 \\le q \\le 10^4$$$) \u2014 the number of test cases in the input.\nThe descriptions of the test cases follow.\nThe first line of description of each test case contains one integer $$$n$$$ ($$$1 \\le n \\le 50$$$) \u2014 the length of the given code.\nThe second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ \u2014 the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained.\nOutput\nFor each test case output the required string $$$s$$$ \u2014 the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique.\nExample\nInput\n9\n6\n315045\n4\n1100\n7\n1213121\n6\n120120\n18\n315045615018035190\n7\n1111110\n7\n1111100\n5\n11111\n4\n2606\nOutput\ncode\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf\nNote\nThe first test case is explained above.\nIn the second test case, the answer is\naj\n. Indeed, the number of the letter\na\nis equal to $$$1$$$, so\n1\nwill be appended to the code. The number of the letter\nj\nis $$$10$$$, so\n100\nwill be appended to the code. The resulting code is\n1100\n.\nThere are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is\nabacaba\n.\nIn the fourth test case, the string $$$s$$$ is equal to\nll\n. The letter\nl\nhas the number $$$12$$$ and is encoded as\n120\n. So\nll\nis indeed\n120120\n.", "input": [ [ [ "6" ], [ "315045" ] ], [ [ "4" ], [ "1100" ] ], [ [ "7" ], [ "1213121" ] ], [ [ "6" ], [ "120120" ] ], [ [ "18" ], [ "315045615018035190" ] ], [ [ "7" ], [ "1111110" ] ], [ [ "7" ], [ "1111100" ] ], [ [ "5" ], [ "11111" ] ], [ [ "4" ], [ "2606" ] ] ], "output": [ "code", "aj", "abacaba", "ll", "codeforces", "aaaak", "aaaaj", "aaaaa", "zf" ] }, { "problem_id": "1729A", "problem_name": "Two Elevators\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1729/A", "problem_solution_link": "https://codeforces.com/problemset/status/1729/problem/A", "problem_statement": "A. Two Elevators\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nVlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.\nThere are only two elevators in his house. Vlad knows for sure that:\nthe first elevator is currently on the floor $$$a$$$ (it is currently motionless),\nthe second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \\ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it.\nIf you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.\nVlad wants to call an elevator that will come to him faster. Help him choose such an elevator.\nInput\nThe first line of the input contains the only $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThis is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \\le a, b, c \\le 10^8$$$, $$$b \\ne c$$$)\u00a0\u2014 floor numbers described in the statement.\nOutput\nOutput $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output:\n$$$1$$$, if it is better to call the first elevator;\n$$$2$$$, if it is better to call the second one;\n$$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).\nExample\nInput\n3\n1 2 3\n3 1 2\n3 2 1\nOutput\n1\n3\n2\nNote\nIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.\nIn the second test case of the example, when called, the elevators would move as follows:\nAt the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor;\nin $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$;\nin $$$2$$$ seconds, any elevator would reach the floor $$$1$$$.\nIn the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.", "input": [ [ [ "1", "2", "3" ] ], [ [ "3", "1", "2" ] ], [ [ "3", "2", "1" ] ] ], "output": [ "1", "3", "2" ] }, { "problem_id": "1728B", "problem_name": "Best Permutation\nconstructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1728/B", "problem_solution_link": "https://codeforces.com/problemset/status/1728/problem/B", "problem_statement": "B. Best Permutation\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's define the value of the permutation $$$p$$$ of $$$n$$$ integers $$$1$$$, $$$2$$$, ..., $$$n$$$ (a permutation is an array where each element from $$$1$$$ to $$$n$$$ occurs exactly once) as follows:\ninitially, an integer variable $$$x$$$ is equal to $$$0$$$;\nif $$$x < p_1$$$, then add $$$p_1$$$ to $$$x$$$ (set $$$x = x + p_1$$$), otherwise assign $$$0$$$ to $$$x$$$;\nif $$$x < p_2$$$, then add $$$p_2$$$ to $$$x$$$ (set $$$x = x + p_2$$$), otherwise assign $$$0$$$ to $$$x$$$;\n...\nif $$$x < p_n$$$, then add $$$p_n$$$ to $$$x$$$ (set $$$x = x + p_n$$$), otherwise assign $$$0$$$ to $$$x$$$;\nthe value of the permutation is $$$x$$$ at the end of this process.\nFor example, for $$$p = [4, 5, 1, 2, 3, 6]$$$, the value of $$$x$$$ changes as follows: $$$0, 4, 9, 0, 2, 5, 11$$$, so the value of the permutation is $$$11$$$.\nYou are given an integer $$$n$$$. Find a permutation $$$p$$$ of size $$$n$$$ with the maximum possible value among all permutations of size $$$n$$$. If there are several such permutations, you can print any of them.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 97$$$)\u00a0\u2014 the number of test cases.\nThe only line of each test case contains one integer $$$n$$$ ($$$4 \\le n \\le 100$$$).\nOutput\nFor each test case, print $$$n$$$ integers\u00a0\u2014 the permutation $$$p$$$ of size $$$n$$$ with the maximum possible value among all permutations of size $$$n$$$.\nExample\nInput\n3\n4\n5\n6\nOutput\n2 1 3 4\n1 2 3 4 5\n4 5 1 2 3 6", "input": [ [ [ "4" ] ], [ [ "5" ] ], [ [ "6" ] ] ], "output": [ "2 1 3 4", "1 2 3 4 5", "4 5 1 2 3 6" ] }, { "problem_id": "1728A", "problem_name": "Colored Balls: Revisited\nbrute force, greedy, implementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1728/A", "problem_solution_link": "https://codeforces.com/problemset/status/1728/problem/A", "problem_statement": "A. Colored Balls: Revisited\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThe title is a reference to the very first Educational Round from our writers team, Educational Round 18.\nThere is a bag, containing colored balls. There are $$$n$$$ different colors of balls, numbered from $$$1$$$ to $$$n$$$. There are $$$\\mathit{cnt}_i$$$ balls of color $$$i$$$ in the bag. The total amount of balls in the bag is odd (e.\u2009g. $$$\\mathit{cnt}_1 + \\mathit{cnt}_2 + \\dots + \\mathit{cnt}_n$$$ is odd).\nIn one move, you can choose two balls\nwith different colors\nand take them out of the bag.\nAt some point, all the remaining balls in the bag will have the same color. That's when you can't make moves anymore.\nFind any possible color of the remaining balls.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of testcases.\nThe first line of each testcase contains a single integer $$$n$$$ ($$$1 \\le n \\le 20$$$)\u00a0\u2014 the number of colors.\nThe second line contains $$$n$$$ integers $$$\\mathit{cnt}_1, \\mathit{cnt}_2, \\dots, \\mathit{cnt}_n$$$ ($$$1 \\le \\mathit{cnt}_i \\le 100$$$)\u00a0\u2014 the amount of balls of each color in the bag.\nThe total amount of balls in the bag is odd (e.\u2009g. $$$\\mathit{cnt}_1 + \\mathit{cnt}_2 + \\dots + \\mathit{cnt}_n$$$ is odd).\nOutput\nFor each testcase, print a single integer\u00a0\u2014 any possible color of the remaining balls, after you made some moves and can't make moves anymore.\nExample\nInput\n3\n3\n1 1 1\n1\n9\n2\n4 7\nOutput\n3\n1\n2\nNote\nIn the first testcase, your first and only move can be one of the following:\ntake balls with colors $$$1$$$ and $$$2$$$;\ntake balls with colors $$$1$$$ and $$$3$$$;\ntake balls with colors $$$2$$$ and $$$3$$$.\nAfter the move, exactly one ball will remain. Its color can be $$$3, 2$$$ or $$$1$$$ depending on the move.\nIn the second testcase, you can't make moves at all\u00a0\u2014 there is only color of balls already. This color is $$$1$$$.\nIn the third testcase, you can keep removing one ball of color $$$1$$$ and one ball of color $$$2$$$ until there are no more balls of color $$$1$$$. At the end, three balls of color $$$2$$$ remain.", "input": [ [ [ "3" ], [ "1", "1", "1" ] ], [ [ "1" ], [ "9" ] ], [ [ "2" ], [ "4", "7" ] ] ], "output": [ "3", "1", "2" ] }, { "problem_id": "1722A", "problem_name": "Spell Check\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1722/A", "problem_solution_link": "https://codeforces.com/problemset/status/1722/problem/A", "problem_statement": "A. Spell Check\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTimur likes his name. As a spelling of his name, he allows any permutation of the letters of the name. For example, the following strings are valid spellings of his name:\nTimur\n,\nmiurT\n,\nTrumi\n,\nmriTu\n. Note that the correct spelling must have uppercased\nT\nand lowercased other letters.\nToday he wrote string $$$s$$$ of length $$$n$$$ consisting only of uppercase or lowercase Latin letters. He asks you to check if $$$s$$$ is the correct spelling of his name.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\leq t \\leq 10^3$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains an integer $$$n$$$ $$$(1 \\leq n \\leq 10)$$$\u00a0\u2014 the length of string $$$s$$$.\nThe second line of each test case contains a string $$$s$$$ consisting of only uppercase or lowercase Latin characters.\nOutput\nFor each test case, output \"\nYES\n\" (without quotes) if $$$s$$$ satisfies the condition, and \"\nNO\n\" (without quotes) otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n10\n5\nTimur\n5\nmiurT\n5\nTrumi\n5\nmriTu\n5\ntimur\n4\nTimr\n6\nTimuur\n10\ncodeforces\n10\nTimurTimur\n5\nTIMUR\nOutput\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO", "input": [ [ [ "5" ], [ "Timur" ] ], [ [ "5" ], [ "miurT" ] ], [ [ "5" ], [ "Trumi" ] ], [ [ "5" ], [ "mriTu" ] ], [ [ "5" ], [ "timur" ] ] ], "output": [ "YES", "YES", "YES", "YES", "NO" ] }, { "problem_id": "1722C", "problem_name": "Word Game\ndata structures, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1722/C", "problem_solution_link": "https://codeforces.com/problemset/status/1722/problem/C", "problem_statement": "C. Word Game\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThree guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows:\nif a word was written by one person\u00a0\u2014 that person gets 3 points,\nif a word was written by two people\u00a0\u2014 each of the two gets 1 point,\nif a word was written by all\u00a0\u2014 nobody gets any points.\nIn the end, how many points does each player have?\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 1000$$$)\u00a0\u2014 the number of words written by each person.\nThe following three lines each contain $$$n$$$\ndistinct\nstrings\u00a0\u2014 the words written by each person. Each string consists of $$$3$$$ lowercase English characters.\nOutput\nFor each test case, output three space-separated integers\u00a0\u2014 the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.\nExample\nInput\n3\n1\nabc\ndef\nabc\n3\norz for qaq\nqaq orz for\ncod for ces\n5\niat roc hem ica lly\nbac ter iol ogi sts\nbac roc lly iol iat\nOutput\n1 3 1 \n2 2 6 \n9 11 5\nNote\nIn the first test case:\nThe word $$$\\texttt{abc}$$$ was written by the first and third guys\u00a0\u2014 they each get $$$1$$$ point.\nThe word $$$\\texttt{def}$$$ was written by the second guy only\u00a0\u2014 he gets $$$3$$$ points.", "input": [ [ [ "1" ], [ "abc" ], [ "def" ], [ "abc" ] ], [ [ "3" ], [ "orz", "for", "qaq" ], [ "qaq", "orz", "for" ], [ "cod", "for", "ces" ] ], [ [ "5" ], [ "iat", "roc", "hem", "ica", "lly" ], [ "bac", "ter", "iol", "ogi", "sts" ], [ "bac", "roc", "lly", "iol", "iat" ] ] ], "output": [ "1 3 1 ", "2 2 6 ", "9 11 5" ] }, { "problem_id": "1722B", "problem_name": "Colourblindness\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1722/B", "problem_solution_link": "https://codeforces.com/problemset/status/1722/problem/B", "problem_statement": "B. Colourblindness\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nVasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.\nVasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the number of columns of the grid.\nThe following two lines each contain a string consisting of $$$n$$$ characters, each of which is either\nR\n,\nG\n, or\nB\n, representing a red, green, or blue cell, respectively\u00a0\u2014 the description of the grid.\nOutput\nFor each test case, output \"\nYES\n\" if Vasya considers the grid's two rows to be identical, and \"\nNO\n\" otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n6\n2\nRG\nRB\n4\nGRBG\nGBGB\n5\nGGGGG\nBBBBB\n7\nBBBBBBB\nRRRRRRR\n8\nRGBRRGBR\nRGGRRBGR\n1\nG\nG\nOutput\nYES\nNO\nYES\nNO\nYES\nYES\nNote\nIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.\nIn the second test case, Vasya can see that the two rows are different.\nIn the third test case, every cell is green or blue, so Vasya will think they are the same.", "input": [ [ [ "2" ], [ "RG" ], [ "RB" ] ], [ [ "4" ], [ "GRBG" ], [ "GBGB" ] ], [ [ "5" ], [ "GGGGG" ], [ "BBBBB" ] ], [ [ "7" ], [ "BBBBBBB" ], [ "RRRRRRR" ] ], [ [ "8" ], [ "RGBRRGBR" ], [ "RGGRRBGR" ] ], [ [ "1" ], [ "G" ], [ "G" ] ] ], "output": [ "YES", "NO", "YES", "NO", "YES", "YES" ] }, { "problem_id": "1721A", "problem_name": "Image\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1721/A", "problem_solution_link": "https://codeforces.com/problemset/status/1721/problem/A", "problem_statement": "A. Image\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have an image file of size $$$2 \\times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters.\nYou want to recolor some of the pixels of the image\nso that all $$$4$$$ pixels have the same color\n. In one move, you can choose\nno more than two\npixels\nof the same color\nand paint them into some other color\n(if you choose two pixels, both should be painted into the same color)\n.\nWhat is the minimum number of moves you have to make in order to fulfill your goal?\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases.\nEach test case consists of two lines. Each of these lines contains two lowercase letters of Latin alphabet\nwithout any separators\n, denoting a row of pixels in the image.\nOutput\nFor each test case, print one integer \u2014 the minimum number of moves you have to make so that all $$$4$$$ pixels of the image have the same color.\nExample\nInput\n5\nrb\nbr\ncc\nwb\naa\naa\nab\ncd\nyy\nxx\nOutput\n1\n2\n0\n3\n1\nNote\nLet's analyze the test cases of the example.\nIn the first test case, you can paint the bottom left pixel and the top right pixel (which share the same color) into the color\nr\n, so all pixels have this color.\nIn the second test case, two moves are enough:\npaint both top pixels, which have the same color\nc\n, into the color\nb\n;\npaint the bottom left pixel into the color\nb\n.\nIn the third test case, all pixels already have the same color.\nIn the fourth test case, you may leave any of the pixels unchanged, and paint all three other pixels into the color of that pixel in three moves.\nIn the fifth test case, you can paint both top pixels into the color\nx\n.", "input": [ [ [ "rb" ], [ "br" ] ], [ [ "cc" ], [ "wb" ] ], [ [ "aa" ], [ "aa" ] ], [ [ "ab" ], [ "cd" ] ], [ [ "yy" ], [ "xx" ] ] ], "output": [ "1", "2", "0", "3", "1" ] }, { "problem_id": "1720B", "problem_name": "Interesting Sum\nbrute force, data structures, greedy, math, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1720/B", "problem_solution_link": "https://codeforces.com/problemset/status/1720/problem/B", "problem_statement": "B. Interesting Sum\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ that contains $$$n$$$ integers. You can choose any proper subsegment $$$a_l, a_{l + 1}, \\ldots, a_r$$$ of this array, meaning you can choose any two integers $$$1 \\le l \\le r \\le n$$$, where $$$r - l + 1 < n$$$. We define the\nbeauty\nof a given subsegment as the value of the following expression:\n$$$$$$\\max(a_{1}, a_{2}, \\ldots, a_{l-1}, a_{r+1}, a_{r+2}, \\ldots, a_{n}) - \\min(a_{1}, a_{2}, \\ldots, a_{l-1}, a_{r+1}, a_{r+2}, \\ldots, a_{n}) + \\max(a_{l}, \\ldots, a_{r}) - \\min(a_{l}, \\ldots, a_{r}).$$$$$$\nPlease find the maximum beauty among all proper subsegments.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$) \u2014 the number of test cases. Then follow the descriptions of each test case.\nThe first line of each test case contains a single integer $$$n$$$ $$$(4 \\leq n \\leq 10^5)$$$ \u2014 the length of the array.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_{i} \\leq 10^9$$$) \u2014 the elements of the given array.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each testcase print a single integer \u2014 the maximum beauty of a proper subsegment.\nExample\nInput\n4\n8\n1 2 2 3 1 5 6 1\n5\n1 2 3 100 200\n4\n3 3 3 3\n6\n7 8 3 1 1 8\nOutput\n9\n297\n0\n14\nNote\nIn the first test case, the optimal segment is $$$l = 7$$$, $$$r = 8$$$. The beauty of this segment equals to $$$(6 - 1) + (5 - 1) = 9$$$.\nIn the second test case, the optimal segment is $$$l = 2$$$, $$$r = 4$$$. The beauty of this segment equals $$$(100 - 2) + (200 - 1) = 297$$$.", "input": [ [ [ "8" ], [ "1", "2", "2", "3", "1", "5", "6", "1" ] ], [ [ "5" ], [ "1", "2", "3", "100", "200" ] ], [ [ "4" ], [ "3", "3", "3", "3" ] ], [ [ "6" ], [ "7", "8", "3", "1", "1", "8" ] ] ], "output": [ "9", "297", "0", "14" ] }, { "problem_id": "1719B", "problem_name": "Mathematical Circus\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1719/B", "problem_solution_link": "https://codeforces.com/problemset/status/1719/problem/B", "problem_statement": "B. Mathematical Circus\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA new entertainment has appeared in Buryatia \u2014 a mathematical circus! The magician shows two numbers to the audience \u2014 $$$n$$$ and $$$k$$$,\nwhere $$$n$$$ is even\n. Next, he takes all the integers from $$$1$$$ to $$$n$$$, and splits them all into pairs $$$(a, b)$$$ (each integer must be in exactly one pair) so that for each pair the integer $$$(a + k) \\cdot b$$$ is divisible by $$$4$$$ (\nnote that the order of the numbers in the pair matters\n), or reports that, unfortunately for viewers, such a split is impossible.\nBurenka really likes such performances, so she asked her friend Tonya to be a magician, and also gave him the numbers $$$n$$$ and $$$k$$$.\nTonya is a wolf, and as you know, wolves do not perform in the circus, even in a mathematical one. Therefore, he asks you to help him. Let him know if a suitable splitting into pairs is possible, and if possible, then tell it.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$) \u2014 the number of test cases. The following is a description of the input data sets.\nThe single line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\leq n \\leq 2 \\cdot 10^5$$$, $$$0 \\leq k \\leq 10^9$$$, $$$n$$$ is even) \u2014 the number of integers and the number being added $$$k$$$.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, first output the string \"\nYES\n\" if there is a split into pairs, and \"\nNO\n\" if there is none.\nIf there is a split, then in the following $$$\\frac{n}{2}$$$ lines output pairs of the split, in each line print $$$2$$$ numbers \u2014 first the integer $$$a$$$, then the integer $$$b$$$.\nExample\nInput\n4\n4 1\n2 0\n12 10\n14 11\nOutput\nYES\n1 2\n3 4\nNO\nYES\n3 4\n7 8\n11 12\n2 1\n6 5\n10 9\nYES\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\nNote\nIn the first test case, splitting into pairs $$$(1, 2)$$$ and $$$(3, 4)$$$ is suitable, same as splitting into $$$(1, 4)$$$ and $$$(3, 2)$$$.\nIn the second test case, $$$(1 + 0) \\cdot 2 = 1 \\cdot (2 + 0) = 2$$$ is not divisible by $$$4$$$, so there is no partition.", "input": [ [ [ "4", "1" ] ], [ [ "2", "0" ] ], [ [ "12", "10" ] ], [ [ "14", "11" ] ] ], "output": [ ["YES", "1 2", "3 4"], ["NO"], ["YES", "3 4", "7 8", "11 12", "2 1", "6 5", "10 9"], ["YES", "1 2", "3 4", "5 6", "7 8", "9 10", "11 12", "13 14"] ], "error": true }, { "problem_id": "1719A", "problem_name": "Chip Game\ngames, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1719/A", "problem_solution_link": "https://codeforces.com/problemset/status/1719/problem/A", "problem_statement": "A. Chip Game\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nBurenka and Tonya are playing an old Buryat game with a chip on a board of $$$n \\times m$$$ cells.\nAt the beginning of the game, the chip is located in the lower left corner of the board. In one move, the player can move the chip to the right or up by any\nodd\nnumber of cells (but you cannot move the chip both to the right and up in one move). The one who cannot make a move loses.\nBurenka makes the first move, the players take turns. Burenka really wants to win the game, but she is too lazy to come up with a strategy, so you are invited to solve the difficult task of finding it. Name the winner of the game (it is believed that Burenka and Tonya are masters of playing with chips, so they always move in the optimal way).\nChip's starting cell is green, the only cell from which chip can't move is red. if the chip is in the yellow cell, then blue cells are all options to move the chip in one move.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$) \u2014 the number of test cases. The following is a description of the input data sets.\nThe only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\leq n, m \\leq 10^9$$$) \u2014 the dimensions of the game board.\nOutput\nFor each test case print a single line \u2014 the name of the winner of the game (\"\nBurenka\n\" or \"\nTonya\n\").\nExample\nInput\n6\n1 1\n1 4\n5 6\n2 2\n6 3\n999999999 1000000000\nOutput\nTonya\nBurenka\nBurenka\nTonya\nBurenka\nBurenka\nNote\nIn the first case, Burenka has no move, so Tonya wins.\nIn the second case, Burenka can move $$$3$$$ cells to the right, after which Tony will not be able to make a move, which means that Burenka wins.\nIn the third case, Burenka can move $$$5$$$ squares to the right. Then we can say that we have a game on a board of $$$1 \\times 5$$$ cells, and Tonya is the first player. In such game the second player wins, so in the original one Burenka will win.", "input": [ [ [ "1", "1" ] ], [ [ "1", "4" ] ], [ [ "5", "6" ] ], [ [ "2", "2" ] ], [ [ "6", "3" ] ], [ [ "999999999", "1000000000" ] ] ], "output": [ "Tonya", "Burenka", "Burenka", "Tonya", "Burenka", "Burenka" ] }, { "problem_id": "1717A", "problem_name": "Madoka and Strange Thoughts\nmath, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1717/A", "problem_solution_link": "https://codeforces.com/problemset/status/1717/problem/A", "problem_statement": "A. Madoka and Strange Thoughts\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMadoka is a very strange girl, and therefore she suddenly wondered how many pairs of integers $$$(a, b)$$$ exist, where $$$1 \\leq a, b \\leq n$$$, for which $$$\\frac{\\operatorname{lcm}(a, b)}{\\operatorname{gcd}(a, b)} \\leq 3$$$.\nIn this problem, $$$\\operatorname{gcd}(a, b)$$$ denotes\nthe greatest common divisor\nof the numbers $$$a$$$ and $$$b$$$, and $$$\\operatorname{lcm}(a, b)$$$ denotes\nthe smallest common multiple\nof the numbers $$$a$$$ and $$$b$$$.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. Description of the test cases follows.\nThe first and the only line of each test case contains the integer $$$n$$$ ($$$1 \\le n \\le 10^8$$$).\nOutput\nFor each test case output a single integer \u2014 the number of pairs of integers satisfying the condition.\nExample\nInput\n6\n1\n2\n3\n4\n5\n100000000\nOutput\n1\n4\n7\n10\n11\n266666666\nNote\nFor $$$n = 1$$$ there is exactly one pair of numbers\u00a0\u2014 $$$(1, 1)$$$ and it fits.\nFor $$$n = 2$$$, there are only $$$4$$$ pairs\u00a0\u2014 $$$(1, 1)$$$, $$$(1, 2)$$$, $$$(2, 1)$$$, $$$(2, 2)$$$ and they all fit.\nFor $$$n = 3$$$, all $$$9$$$ pair are suitable, except $$$(2, 3)$$$ and $$$(3, 2)$$$, since their $$$\\operatorname{lcm}$$$ is $$$6$$$, and $$$\\operatorname{gcd}$$$ is $$$1$$$, which doesn't fit the condition.", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "3" ] ], [ [ "4" ] ], [ [ "5" ] ], [ [ "100000000" ] ] ], "output": [ "1", "4", "7", "10", "11", "266666666" ] }, { "problem_id": "1716B", "problem_name": "Permutation Chain\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1716/B", "problem_solution_link": "https://codeforces.com/problemset/status/1716/problem/B", "problem_statement": "B. Permutation Chain\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ such that each integer appears in it exactly once.\nLet the fixedness of a permutation $$$p$$$ be the number of fixed points in it\u00a0\u2014 the number of positions $$$j$$$ such that $$$p_j = j$$$, where $$$p_j$$$ is the $$$j$$$-th element of the permutation $$$p$$$.\nYou are asked to build a sequence of permutations $$$a_1, a_2, \\dots$$$, starting from the identity permutation (permutation $$$a_1 = [1, 2, \\dots, n]$$$). Let's call it a permutation chain. Thus, $$$a_i$$$ is the $$$i$$$-th permutation of length $$$n$$$.\nFor every $$$i$$$ from $$$2$$$ onwards, the permutation $$$a_i$$$ should be obtained from the permutation $$$a_{i-1}$$$ by swapping any two elements in it (not necessarily neighboring). The fixedness of the permutation $$$a_i$$$ should be strictly lower than the fixedness of the permutation $$$a_{i-1}$$$.\nConsider some chains for $$$n = 3$$$:\n$$$a_1 = [1, 2, 3]$$$, $$$a_2 = [1, 3, 2]$$$\u00a0\u2014 that is a valid chain of length $$$2$$$. From $$$a_1$$$ to $$$a_2$$$, the elements on positions $$$2$$$ and $$$3$$$ get swapped, the fixedness decrease from $$$3$$$ to $$$1$$$.\n$$$a_1 = [2, 1, 3]$$$, $$$a_2 = [3, 1, 2]$$$\u00a0\u2014 that is not a valid chain. The first permutation should always be $$$[1, 2, 3]$$$ for $$$n = 3$$$.\n$$$a_1 = [1, 2, 3]$$$, $$$a_2 = [1, 3, 2]$$$, $$$a_3 = [1, 2, 3]$$$\u00a0\u2014 that is not a valid chain. From $$$a_2$$$ to $$$a_3$$$, the elements on positions $$$2$$$ and $$$3$$$ get swapped but the fixedness increase from $$$1$$$ to $$$3$$$.\n$$$a_1 = [1, 2, 3]$$$, $$$a_2 = [3, 2, 1]$$$, $$$a_3 = [3, 1, 2]$$$\u00a0\u2014 that is a valid chain of length $$$3$$$. From $$$a_1$$$ to $$$a_2$$$, the elements on positions $$$1$$$ and $$$3$$$ get swapped, the fixedness decrease from $$$3$$$ to $$$1$$$. From $$$a_2$$$ to $$$a_3$$$, the elements on positions $$$2$$$ and $$$3$$$ get swapped, the fixedness decrease from $$$1$$$ to $$$0$$$.\nFind the longest permutation chain. If there are multiple longest answers, print any of them.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 99$$$)\u00a0\u2014 the number of testcases.\nThe only line of each testcase contains a single integer $$$n$$$ ($$$2 \\le n \\le 100$$$)\u00a0\u2014 the required length of permutations in the chain.\nOutput\nFor each testcase, first, print the length of a permutation chain $$$k$$$.\nThen print $$$k$$$ permutations $$$a_1, a_2, \\dots, a_k$$$. $$$a_1$$$ should be an identity permutation of length $$$n$$$ ($$$[1, 2, \\dots, n]$$$). For each $$$i$$$ from $$$2$$$ to $$$k$$$, $$$a_i$$$ should be obtained by swapping two elements in $$$a_{i-1}$$$. It should also have a strictly lower fixedness than $$$a_{i-1}$$$.\nExample\nInput\n2\n2\n3\nOutput\n2\n1 2\n2 1\n3\n1 2 3\n3 2 1\n3 1 2", "input": [ [ [ "2" ] ], [ [ "3" ] ] ], "output": [ ["2", "1 2", "2 1"], ["3", "1 2 3", "3 2 1", "3 1 2"] ], "error": true }, { "problem_id": "1716A", "problem_name": "2-3 Moves\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1716/A", "problem_solution_link": "https://codeforces.com/problemset/status/1716/problem/A", "problem_statement": "A. 2-3 Moves\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i.\u2009e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.\nYour task is to find the\nminimum\nnumber of minutes required to get from the point $$$0$$$ to the point $$$n$$$.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ lines describing the test cases follow.\nThe $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$) \u2014 the goal of the $$$i$$$-th test case.\nOutput\nFor each test case, print one integer \u2014 the\nminimum\nnumber of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.\nExample\nInput\n4\n1\n3\n4\n12\nOutput\n2\n1\n2\n4", "input": [ [ [ "1" ] ], [ [ "3" ] ], [ [ "4" ] ], [ [ "12" ] ] ], "output": [ "2", "1", "2", "4" ] }, { "problem_id": "1715A", "problem_name": "Crossmarket\nconstructive algorithms, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1715/A", "problem_solution_link": "https://codeforces.com/problemset/status/1715/problem/A", "problem_statement": "A. Crossmarket\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nStanley and Megan decided to shop in the \"Crossmarket\" grocery store, which can be represented as a matrix with $$$n$$$ rows and $$$m$$$ columns.\nStanley and Megan can move to an adjacent cell using $$$1$$$ unit of power. Two cells are considered adjacent if they share an edge. To speed up the shopping process, Megan brought her portals with her, and she leaves one in each cell she visits (if there is no portal yet). If a person (Stanley or Megan) is in a cell with a portal, that person can use $$$1$$$ unit of power to teleport to any other cell with a portal, including Megan's starting cell.\nThey decided to split up: Stanley will go from the upper-left cell (cell with coordinates $$$(1, 1)$$$) to the lower-right cell (cell with coordinates $$$(n, m)$$$), whilst Megan needs to get from the lower-left cell (cell with coordinates $$$(n, 1)$$$) to the upper-right cell (cell with coordinates $$$(1, m)$$$).\nWhat is the minimum total energy needed for them both to do that?\nNote that they can choose the time they move. Time does not affect energy.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$). Description of the test cases follows.\nThe only line in the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 10^5$$$).\nOutput\nFor each test case print a single integer on a new line \u2013 the answer.\nExample\nInput\n7\n7 5\n5 7\n1 1\n100000 100000\n57 228\n1 5\n5 1\nOutput\n15\n15\n0\n299998\n340\n5\n5\nNote\nIn the first test case they can stick to the following plan:\nMegan (red circle) moves to the cell $$$(7, 3)$$$. Then she goes to the cell $$$(1, 3)$$$, and Stanley (blue circle) does the same.\nStanley uses the portal in that cell (cells with portals are grey) to get to the cell $$$(7, 3)$$$. Then he moves to his destination\u00a0\u2014 cell $$$(7, 5)$$$.\nMegan also finishes her route and goes to the cell $$$(1, 5)$$$.\nThe total energy spent is $$$(2 + 6) + (2 + 1 + 2) + (2)= 15$$$, which is our final answer.", "input": [ [ [ "7", "5" ] ], [ [ "5", "7" ] ], [ [ "1", "1" ] ], [ [ "100000", "100000" ] ], [ [ "57", "228" ] ], [ [ "1", "5" ] ], [ [ "5", "1" ] ] ], "output": [ "15", "15", "0", "299998", "340", "5", "5" ] }, { "problem_id": "1714C", "problem_name": "Minimum Varied Number\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1714/C", "problem_solution_link": "https://codeforces.com/problemset/status/1714/problem/C", "problem_statement": "C. Minimum Varied Number\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nFind the minimum number with the given sum of digits $$$s$$$ such that\nall\ndigits in it are distinct (i.e. all digits are unique).\nFor example, if $$$s=20$$$, then the answer is $$$389$$$. This is the minimum number in which all digits are different and the sum of the digits is $$$20$$$ ($$$3+8+9=20$$$).\nFor the given $$$s$$$ print the required number.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 45$$$) \u2014 the number of test cases.\nEach test case is specified by a line that contains the only integer $$$s$$$ ($$$1 \\le s \\le 45$$$).\nOutput\nPrint $$$t$$$ integers \u2014 the answers to the given test cases.\nExample\nInput\n4\n20\n8\n45\n10\nOutput\n389\n8\n123456789\n19", "input": [ [ [ "20" ] ], [ [ "8" ] ], [ [ "45" ] ], [ [ "10" ] ] ], "output": [ "389", "8", "123456789", "19" ] }, { "problem_id": "1714B", "problem_name": "Remove Prefix\ndata structures, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1714/B", "problem_solution_link": "https://codeforces.com/problemset/status/1714/problem/B", "problem_statement": "B. Remove Prefix\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp was presented with some sequence of integers $$$a$$$ of length $$$n$$$ ($$$1 \\le a_i \\le n$$$). A sequence can make Polycarp happy only if it consists of\ndifferent\nnumbers (i.e. distinct numbers).\nIn order to make his sequence like this, Polycarp is going to make some (possibly zero) number of moves.\nIn one move, he can:\nremove the first (leftmost) element of the sequence.\nFor example, in one move, the sequence $$$[3, 1, 4, 3]$$$ will produce the sequence $$$[1, 4, 3]$$$, which consists of different numbers.\nDetermine the minimum number of moves he needs to make so that in the remaining sequence all elements are different. In other words, find the length of the smallest prefix of the given sequence $$$a$$$, after removing which all values in the sequence will be unique.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of two lines.\nThe first line contains an integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) \u2014 the length of the given sequence $$$a$$$.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le n$$$) \u2014 elements of the given sequence $$$a$$$.\nIt is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case print your answer on a separate line\u00a0\u2014 the minimum number of elements that must be removed from the beginning of the sequence so that all remaining elements are different.\nExample\nInput\n5\n4\n3 1 4 3\n5\n1 1 1 1 1\n1\n1\n6\n6 5 4 3 2 1\n7\n1 2 1 7 1 2 1\nOutput\n1\n4\n0\n0\n5\nNote\nThe following are the sequences that will remain after the removal of prefixes:\n$$$[1, 4, 3]$$$;\n$$$[1]$$$;\n$$$[1]$$$;\n$$$[6, 5, 4, 3, 2, 1]$$$;\n$$$[2, 1]$$$.\nIt is easy to see that all the remaining sequences contain only distinct elements. In each test case, the shortest matching prefix was removed.", "input": [ [ [ "4" ], [ "3", "1", "4", "3" ] ], [ [ "5" ], [ "1", "1", "1", "1", "1" ] ], [ [ "1" ], [ "1" ] ], [ [ "6" ], [ "6", "5", "4", "3", "2", "1" ] ], [ [ "7" ], [ "1", "2", "1", "7", "1", "2", "1" ] ] ], "output": [ "1", "4", "0", "0", "5" ] }, { "problem_id": "1713A", "problem_name": "Traveling Salesman Problem\ngeometry, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1713/A", "problem_solution_link": "https://codeforces.com/problemset/status/1713/problem/A", "problem_statement": "A. Traveling Salesman Problem\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are living on an infinite plane with the Cartesian coordinate system on it. In one move you can go to any of the four adjacent points (left, right, up, down).\nMore formally, if you are standing at the point $$$(x, y)$$$, you can:\ngo left, and move to $$$(x - 1, y)$$$, or\ngo right, and move to $$$(x + 1, y)$$$, or\ngo up, and move to $$$(x, y + 1)$$$, or\ngo down, and move to $$$(x, y - 1)$$$.\nThere are $$$n$$$ boxes on this plane. The $$$i$$$-th box has coordinates $$$(x_i,y_i)$$$. It is guaranteed that the boxes are either on the $$$x$$$-axis or the $$$y$$$-axis. That is, either $$$x_i=0$$$ or $$$y_i=0$$$.\nYou can collect a box if you and the box are at the same point. Find the minimum number of moves you have to perform to collect all of these boxes if you have to\nstart and finish\nat the point $$$(0,0)$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the number of boxes.\nThe $$$i$$$-th line of the following $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-100 \\le x_i, y_i \\le 100$$$) \u2014 the coordinate of the $$$i$$$-th box. It is guaranteed that either $$$x_i=0$$$ or $$$y_i=0$$$.\nDo note that the sum of $$$n$$$ over all test cases is not bounded.\nOutput\nFor each test case output a single integer \u2014 the minimum number of moves required.\nExample\nInput\n3\n4\n0 -2\n1 0\n-1 0\n0 2\n3\n0 2\n-3 0\n0 -1\n1\n0 0\nOutput\n12\n12\n0\nNote\nIn the first test case, a possible sequence of moves that uses the minimum number of moves required is shown below.\n$$$$$$(0,0) \\to (1,0) \\to (1,1) \\to (1, 2) \\to (0,2) \\to (-1,2) \\to (-1,1) \\to (-1,0) \\to (-1,-1) \\to (-1,-2) \\to (0,-2) \\to (0,-1) \\to (0,0)$$$$$$\nIn the second test case, a possible sequence of moves that uses the minimum number of moves required is shown below.\n$$$$$$(0,0) \\to (0,1) \\to (0,2) \\to (-1, 2) \\to (-2,2) \\to (-3,2) \\to (-3,1) \\to (-3,0) \\to (-3,-1) \\to (-2,-1) \\to (-1,-1) \\to (0,-1) \\to (0,0)$$$$$$\nIn the third test case, we can collect all boxes without making any moves.", "input": [ [["4"], ["0", "-2", "1", "0", "-1", "0"]], [["3"], ["0", "2", "-3", "0", "0", "-1"]], [["1"], ["0", "0"]] ], "output": [ "12", "12", "0" ] }, { "problem_id": "1712B", "problem_name": "Woeful Permutation\nconstructive algorithms, greedy, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1712/B", "problem_solution_link": "https://codeforces.com/problemset/status/1712/problem/B", "problem_statement": "B. Woeful Permutation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nI wonder, does the falling rain\nForever yearn for it's disdain?\nEffluvium of the Mind\nYou are given a positive integer $$$n$$$.\nFind any permutation $$$p$$$ of length $$$n$$$ such that the sum $$$\\operatorname{lcm}(1,p_1) + \\operatorname{lcm}(2, p_2) + \\ldots + \\operatorname{lcm}(n, p_n)$$$ is as large as possible.\nHere $$$\\operatorname{lcm}(x, y)$$$ denotes the\nleast common multiple (LCM)\nof integers $$$x$$$ and $$$y$$$.\nA permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1\\,000$$$). Description of the test cases follows.\nThe only line for each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^5$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each test case print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\\ldots$$$, $$$p_n$$$\u00a0\u2014 the permutation with the maximum possible value of $$$\\operatorname{lcm}(1,p_1) + \\operatorname{lcm}(2, p_2) + \\ldots + \\operatorname{lcm}(n, p_n)$$$.\nIf there are multiple answers, print any of them.\nExample\nInput\n2\n1\n2\nOutput\n1 \n2 1\nNote\nFor $$$n = 1$$$, there is only one permutation, so the answer is $$$[1]$$$.\nFor $$$n = 2$$$, there are two permutations:\n$$$[1, 2]$$$\u00a0\u2014 the sum is $$$\\operatorname{lcm}(1,1) + \\operatorname{lcm}(2, 2) = 1 + 2 = 3$$$.\n$$$[2, 1]$$$\u00a0\u2014 the sum is $$$\\operatorname{lcm}(1,2) + \\operatorname{lcm}(2, 1) = 2 + 2 = 4$$$.", "input": [ [ [ "1" ] ], [ [ "2" ] ] ], "output": [ "1 ", "2 1" ] }, { "problem_id": "1712A", "problem_name": "Wonderful Permutation\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1712/A", "problem_solution_link": "https://codeforces.com/problemset/status/1712/problem/A", "problem_statement": "A. Wonderful Permutation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGod's Blessing on This PermutationForces!\nA Random Pebble\nYou are given a permutation $$$p_1,p_2,\\ldots,p_n$$$ of length $$$n$$$ and a positive integer $$$k \\le n$$$.\nIn one operation you can choose two indices $$$i$$$ and $$$j$$$ ($$$1 \\le i < j \\le n$$$) and swap $$$p_i$$$ with $$$p_j$$$.\nFind the minimum number of operations needed to make the sum $$$p_1 + p_2 + \\ldots + p_k$$$ as small as possible.\nA permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). Description of the test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 100$$$).\nThe second line of each test case contains $$$n$$$ integers $$$p_1,p_2,\\ldots,p_n$$$ ($$$1 \\le p_i \\le n$$$). It is guaranteed that the given numbers form a permutation of length $$$n$$$.\nOutput\nFor each test case print one integer\u00a0\u2014 the minimum number of operations needed to make the sum $$$p_1 + p_2 + \\ldots + p_k$$$ as small as possible.\nExample\nInput\n4\n3 1\n2 3 1\n3 3\n1 2 3\n4 2\n3 4 1 2\n1 1\n1\nOutput\n1\n0\n2\n0\nNote\nIn the first test case, the value of $$$p_1 + p_2 + \\ldots + p_k$$$ is initially equal to $$$2$$$, but the smallest possible value is $$$1$$$. You can achieve it by swapping $$$p_1$$$ with $$$p_3$$$, resulting in the permutation $$$[1, 3, 2]$$$.\nIn the second test case, the sum is already as small as possible, so the answer is $$$0$$$.", "input": [ [ [ "3", "1" ], [ "2", "3", "1" ] ], [ [ "3", "3" ], [ "1", "2", "3" ] ], [ [ "4", "2" ], [ "3", "4", "1", "2" ] ], [ [ "1", "1" ], [ "1" ] ] ], "output": [ "1", "0", "2", "0" ] }, { "problem_id": "1711A", "problem_name": "Perfect Permutation\nconstructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1711/A", "problem_solution_link": "https://codeforces.com/problemset/status/1711/problem/A", "problem_statement": "A. Perfect Permutation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a positive integer $$$n$$$.\nThe weight of a permutation $$$p_1, p_2, \\ldots, p_n$$$ is the number of indices $$$1\\le i\\le n$$$ such that $$$i$$$ divides $$$p_i$$$. Find a permutation $$$p_1,p_2,\\dots, p_n$$$ with the minimum possible weight (among all permutations of length $$$n$$$).\nA permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$). The description of the test cases follows.\nThe only line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^5$$$) \u2014 the length of permutation.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each test case, print a line containing $$$n$$$ integers $$$p_1, p_2,\\dots, p_n$$$ so that the permutation $$$p$$$ has the minimum possible weight.\nIf there are several possible answers, you can print any of them.\nExample\nInput\n2\n1\n4\nOutput\n1\n2 1 4 3\nNote\nIn the first test case, the only valid permutation is $$$p=[1]$$$. Its weight is $$$1$$$.\nIn the second test case, one possible answer is the permutation $$$p=[2,1,4,3]$$$. One can check that $$$1$$$ divides $$$p_1$$$ and $$$i$$$ does not divide $$$p_i$$$ for $$$i=2,3,4$$$, so the weight of this permutation is $$$1$$$. It is impossible to find a permutation of length $$$4$$$ with a strictly smaller weight.", "input": [ [ [ "1" ] ], [ [ "4" ] ] ], "output": [ "1", "2 1 4 3" ] }, { "problem_id": "1709A", "problem_name": "Three Doors\nbrute force, greedy, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1709/A", "problem_solution_link": "https://codeforces.com/problemset/status/1709/problem/A", "problem_statement": "A. Three Doors\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are three doors in front of you, numbered from $$$1$$$ to $$$3$$$ from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door.\nThere are three keys\u00a0\u2014 one for each door. Two of them are hidden behind the doors, so that there is no more than one key behind each door. So two doors have one key behind them, one door doesn't have a key behind it. To obtain a key hidden behind a door, you should first unlock that door. The remaining key is in your hands.\nCan you open all the doors?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 18$$$)\u00a0\u2014 the number of testcases.\nThe first line of each testcase contains a single integer $$$x$$$ ($$$1 \\le x \\le 3$$$)\u00a0\u2014 the number on the key in your hands.\nThe second line contains three integers $$$a, b$$$ and $$$c$$$ ($$$0 \\le a, b, c \\le 3$$$)\u00a0\u2014 the number on the key behind each of the doors. If there is no key behind the door, the number is equal to $$$0$$$.\nValues $$$1, 2$$$ and $$$3$$$ appear exactly once among $$$x, a, b$$$ and $$$c$$$.\nOutput\nFor each testcase, print \"\nYES\n\" if you can open all the doors. Otherwise, print \"\nNO\n\".\nExample\nInput\n4\n3\n0 1 2\n1\n0 3 2\n2\n3 1 0\n2\n1 3 0\nOutput\nYES\nNO\nYES\nNO", "input": [ [ [ "3" ], [ "0", "1", "2" ] ], [ [ "1" ], [ "0", "3", "2" ] ], [ [ "2" ], [ "3", "1", "0" ] ], [ [ "2" ], [ "1", "3", "0" ] ] ], "output": [ "YES", "NO", "YES", "NO" ] }, { "problem_id": "1708A", "problem_name": "Difference Operations\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1708/A", "problem_solution_link": "https://codeforces.com/problemset/status/1708/problem/A", "problem_statement": "A. Difference Operations\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ consisting of $$$n$$$ positive integers.\nYou are allowed to perform this operation any number of times (possibly, zero):\nchoose an index $$$i$$$ ($$$2 \\le i \\le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$.\nIs it possible to make $$$a_i=0$$$ for all $$$2\\le i\\le n$$$?\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\\le t\\le 100$$$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$)\u00a0\u2014 the length of array $$$a$$$.\nThe second line contains $$$n$$$ integers $$$a_1,a_2,\\ldots,a_n$$$ ($$$1 \\le a_i \\le 10^9$$$).\nOutput\nFor each test case, print \"\nYES\n\" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \\le i \\le n$$$, and \"\nNO\n\" (without quotes) otherwise.\nYou can print letters in any case (upper or lower).\nExample\nInput\n4\n2\n5 10\n3\n1 2 3\n4\n1 1 1 1\n9\n9 9 8 2 4 4 3 5 3\nOutput\nYES\nYES\nYES\nNO\nNote\nIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal:\nChoose $$$i=2$$$, and the array becomes $$$[5,5]$$$.\nChoose $$$i=2$$$, and the array becomes $$$[5,0]$$$.\nIn the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal:\nChoose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$.\nChoose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$.\nChoose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$.\nChoose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$.\nIn the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$.", "input": [ [ [ "2" ], [ "5", "10" ] ], [ [ "3" ], [ "1", "2", "3" ] ], [ [ "4" ], [ "1", "1", "1", "1" ] ], [ [ "9" ], [ "9", "9", "8", "2", "4", "4", "3", "5", "3" ] ] ], "output": [ "YES", "YES", "YES", "NO" ] }, { "problem_id": "1706A", "problem_name": "Another String Minimization Problem\n2-sat, constructive algorithms, greedy, string suffix structures, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1706/A", "problem_solution_link": "https://codeforces.com/problemset/status/1706/problem/A", "problem_statement": "A. Another String Minimization Problem\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have a sequence $$$a_1, a_2, \\ldots, a_n$$$ of length $$$n$$$, consisting of integers between $$$1$$$ and $$$m$$$. You also have a string $$$s$$$, consisting of $$$m$$$ characters\nB\n.\nYou are going to perform the following $$$n$$$ operations.\nAt the $$$i$$$-th ($$$1 \\le i \\le n$$$) operation, you replace either the $$$a_i$$$-th\nor\nthe $$$(m + 1 - a_i)$$$-th character of $$$s$$$ with\nA\n. You can replace the character at any position multiple times through the operations.\nFind the lexicographically smallest string you can get after these operations.\nA string $$$x$$$ is lexicographically smaller than a string $$$y$$$ of the same length if and only if in the first position where $$$x$$$ and $$$y$$$ differ, the string $$$x$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$y$$$.\nInput\nThe first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 2000$$$).\nThe first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 50$$$)\u00a0\u2014 the length of the sequence $$$a$$$ and the length of the string $$$s$$$ respectively.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le m$$$)\u00a0\u2014 the sequence $$$a$$$.\nOutput\nFor each test case, print a string of length $$$m$$$\u00a0\u2014 the lexicographically smallest string you can get. Each character of the string should be either capital English letter\nA\nor capital English letter\nB\n.\nExample\nInput\n6\n4 5\n1 1 3 1\n1 5\n2\n4 1\n1 1 1 1\n2 4\n1 3\n2 7\n7 5\n4 5\n5 5 3 5\nOutput\nABABA\nBABBB\nA\nAABB\nABABBBB\nABABA\nNote\nIn the first test case, the sequence $$$a = [1, 1, 3, 1]$$$. One of the possible solutions is the following.\nAt the $$$1$$$-st operation, you can replace the $$$1$$$-st character of $$$s$$$ with\nA\n. After it, $$$s$$$ becomes\nA\nBBBB\n.\nAt the $$$2$$$-nd operation, you can replace the $$$5$$$-th character of $$$s$$$ with\nA\n(since $$$m+1-a_2=5$$$). After it, $$$s$$$ becomes\nABBB\nA\n.\nAt the $$$3$$$-rd operation, you can replace the $$$3$$$-rd character of $$$s$$$ with\nA\n. After it, $$$s$$$ becomes\nAB\nA\nBA\n.\nAt the $$$4$$$-th operation, you can replace the $$$1$$$-st character of $$$s$$$ with\nA\n. After it, $$$s$$$ remains equal to\nABABA\n.\nThe resulting string is\nABABA\n. It is impossible to produce a lexicographically smaller string.\nIn the second test case, you are going to perform only one operation. You can replace either the $$$2$$$-nd character or $$$4$$$-th character of $$$s$$$ with\nA\n. You can get strings\nBABBB\nand\nBBBAB\nafter the operation. The string\nBABBB\nis the lexicographically smallest among these strings.\nIn the third test case, the only string you can get is\nA\n.\nIn the fourth test case, you can replace the $$$1$$$-st and $$$2$$$-nd characters of $$$s$$$ with\nA\nto get\nAABB\n.\nIn the fifth test case, you can replace the $$$1$$$-st and $$$3$$$-rd characters of $$$s$$$ with\nA\nto get\nABABBBB\n.", "input": [ [ [ "4", "5" ], [ "1", "1", "3", "1" ] ], [ [ "1", "5" ], [ "2" ] ], [ [ "4", "1" ], [ "1", "1", "1", "1" ] ], [ [ "2", "4" ], [ "1", "3" ] ], [ [ "2", "7" ], [ "7", "5" ] ], [ [ "4", "5" ], [ "5", "5", "3", "5" ] ] ], "output": [ "ABABA", "BABBB", "A", "AABB", "ABABBBB", "ABABA" ] }, { "problem_id": "1705A", "problem_name": "Mark the Photographer\ngreedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1705/A", "problem_solution_link": "https://codeforces.com/problemset/status/1705/problem/A", "problem_statement": "A. Mark the Photographer\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMark is asked to take a group photo of $$$2n$$$ people. The $$$i$$$-th person has height $$$h_i$$$ units.\nTo do so, he ordered these people into two rows, the front row and the back row, each consisting of $$$n$$$ people. However, to ensure that everyone is seen properly, the $$$j$$$-th person of the back row must be at least $$$x$$$ units taller than the $$$j$$$-th person of the front row for each $$$j$$$ between $$$1$$$ and $$$n$$$, inclusive.\nHelp Mark determine if this is possible.\nInput\nThe first line contains one integer $$$t$$$ ($$$1\\leq t\\leq 100$$$) \u2014 the number of test cases. Each test case consists of two lines.\nThe first line of each test case contains two positive integers $$$n$$$ and $$$x$$$ ($$$1\\leq n\\leq 100$$$, $$$1\\leq x\\leq 10^3$$$) \u2014 the number of people in each row and the minimum difference Mark wants.\nThe second line of each test case contains $$$2n$$$ positive integers $$$h_1,h_2,\\ldots,h_{2n}$$$ ($$$1\\leq h_i\\leq 10^3$$$) \u2014 the height of each person in units.\nNote that the sum of $$$n$$$ over all test cases is not bounded.\nOutput\nFor each test case, print a single line containing \"\nYES\n\" if Mark could arrange people satisfying his condition and \"\nNO\n\" otherwise.\nYou may print each letter in any case (for example,\nYES\n,\nYes\n,\nyes\n,\nyEs\nwill all be recognized as positive answers).\nExample\nInput\n3\n3 6\n1 3 9 10 12 16\n3 1\n2 5 2 2 2 5\n1 2\n8 6\nOutput\nYES\nNO\nYES\nNote\nIn the first test case, one possible order is to have the third, fifth, and sixth person on the back row and the second, first, and fourth on the front row. The heights of the people will look like this.\nBack\n$$$9$$$\n$$$12$$$\n$$$16$$$\nFront\n$$$3$$$\n$$$1$$$\n$$$10$$$\nIt works because\n$$$h_3-h_2 = 9-3 \\geq 6$$$,\n$$$h_5-h_1 = 12-1\\geq 6$$$, and\n$$$h_6-h_4 = 16-10\\geq 6$$$.\nIn the second test case, it can be shown there is no way to order people in a way that satisfies the condition.\nIn the third test case, the only way to arrange people to satisfy the condition is to have the first person on the back row and the second person on the front row.", "input": [ [ [ "3", "6" ], [ "1", "3", "9", "10", "12", "16" ] ], [ [ "3", "1" ], [ "2", "5", "2", "2", "2", "5" ] ], [ [ "1", "2" ], [ "8", "6" ] ] ], "output": [ "YES", "NO", "YES" ] }, { "problem_id": "1704A", "problem_name": "Two 0-1 Sequences\nconstructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1704/A", "problem_solution_link": "https://codeforces.com/problemset/status/1704/problem/A", "problem_statement": "A. Two 0-1 Sequences\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAquaMoon has two binary sequences $$$a$$$ and $$$b$$$, which contain only $$$0$$$ and $$$1$$$. AquaMoon can perform the following two operations any number of times ($$$a_1$$$ is the first element of $$$a$$$, $$$a_2$$$ is the second element of $$$a$$$, and so on):\nOperation 1\n: if $$$a$$$ contains at least two elements, change $$$a_2$$$ to $$$\\operatorname{min}(a_1,a_2)$$$, and remove the first element of $$$a$$$.\nOperation 2\n: if $$$a$$$ contains at least two elements, change $$$a_2$$$ to $$$\\operatorname{max}(a_1,a_2)$$$, and remove the first element of $$$a$$$.\nNote that after a removal of the first element of $$$a$$$, the former $$$a_2$$$ becomes the first element of $$$a$$$, the former $$$a_3$$$ becomes the second element of $$$a$$$ and so on, and the length of $$$a$$$ reduces by one.\nDetermine if AquaMoon can make $$$a$$$ equal to $$$b$$$ by using these operations.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 2\\,000$$$) \u2014 the number of test cases. Description of test cases follows.\nThe first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \\leq n,m \\leq 50$$$, $$$m \\leq n$$$) \u2014 the lengths of $$$a$$$ and $$$b$$$ respectively.\nThe second line of each test case contains a string $$$a$$$ of length $$$n$$$, consisting only $$$0$$$ and $$$1$$$.\nThe third line of each test case contains a string $$$b$$$ of length $$$m$$$, consisting only $$$0$$$ and $$$1$$$.\nOutput\nFor each test case, output \"YES\" if AquaMoon can change $$$a$$$ to $$$b$$$ by using these options; otherwise, output \"NO\".\nYou may print each letter in any case (for example, \"YES\", \"Yes\", \"yes\", \"yEs\" will all be recognized as a positive answer).\nExample\nInput\n10\n6 2\n001001\n11\n6 2\n110111\n01\n6 2\n000001\n11\n6 2\n111111\n01\n8 5\n10000101\n11010\n7 4\n1010001\n1001\n8 6\n01010010\n010010\n8 4\n01010101\n1001\n8 4\n10101010\n0110\n7 5\n1011100\n11100\nOutput\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nNote\nIn the first test case, you can use\nOperation 2\nfour times to make $$$a$$$ equals to $$$b$$$.\nIn the second test case, you can use\nOperation 1\nfour times to make $$$a$$$ equals to $$$b$$$.\nIn the third test case, it can be proved that no matter how we use the operations, it is impossible to make $$$a$$$ equal to $$$b$$$.\nIn the fourth test case, it can be proved that no matter how we use the operations, it is impossible to make $$$a$$$ equal to $$$b$$$.\nIn the fifth test case, you can use\nOperation 2\nthree times to make $$$a$$$ become $$$10101$$$, so the first element of $$$a$$$ equals to the first element of $$$b$$$, but it can be proved that no matter how to operate, the second to the fifth elements of $$$a$$$ can't be the same as $$$b$$$.", "input": [ [ [ "6", "2" ], [ "001001", "11" ] ], [ [ "6", "2" ], [ "110111", "01" ] ], [ [ "6", "2" ], [ "000001", "11" ] ], [ [ "6", "2" ], [ "111111", "01" ] ], [ [ "8", "5" ], [ "10000101", "11010" ] ], [ [ "7", "4" ], [ "1010001", "1001" ] ], [ [ "8", "6" ], [ "01010010", "010010" ] ], [ [ "8", "4" ], [ "01010101", "1001" ] ], [ [ "8", "4" ], [ "10101010", "0110" ] ], [ [ "7", "5" ], [ "1011100", "11100" ] ] ], "output": [ "YES", "YES", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "YES" ] }, { "problem_id": "1703C", "problem_name": "Cypher\nbrute force, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1703/C", "problem_solution_link": "https://codeforces.com/problemset/status/1703/problem/C", "problem_statement": "C. Cypher\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLuca has a cypher made up of a sequence of $$$n$$$ wheels, each with a digit $$$a_i$$$ written on it. On the $$$i$$$-th wheel, he made $$$b_i$$$ moves. Each move is one of two types:\nup\nmove (denoted by $$$\\texttt{U}$$$): it increases the $$$i$$$-th digit by $$$1$$$. After applying the up move on $$$9$$$, it becomes $$$0$$$.\ndown\nmove (denoted by $$$\\texttt{D}$$$): it decreases the $$$i$$$-th digit by $$$1$$$. After applying the down move on $$$0$$$, it becomes $$$9$$$.\nExample for $$$n=4$$$. The current sequence is\n0 0 0 0\n.\nLuca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the number of wheels.\nThe second line contains $$$n$$$ integers $$$a_i$$$ ($$$0 \\leq a_i \\leq 9$$$)\u00a0\u2014 the digit shown on the $$$i$$$-th wheel after all moves have been performed.\nThen $$$n$$$ lines follow, the $$$i$$$-th of which contains the integer $$$b_i$$$ ($$$1 \\leq b_i \\leq 10$$$) and $$$b_i$$$ characters that are either $$$\\texttt{U}$$$ or $$$\\texttt{D}$$$\u00a0\u2014 the number of moves performed on the $$$i$$$-th wheel, and the moves performed. $$$\\texttt{U}$$$ and $$$\\texttt{D}$$$ represent an\nup\nmove and a\ndown\nmove respectively.\nOutput\nFor each test case, output $$$n$$$ space-separated digits \u00a0\u2014 the initial sequence of the cypher.\nExample\nInput\n3\n3\n9 3 1\n3 DDD\n4 UDUU\n2 DU\n2\n0 9\n9 DDDDDDDDD\n9 UUUUUUUUU\n5\n0 5 9 8 3\n10 UUUUUUUUUU\n3 UUD\n8 UUDUUDDD\n10 UUDUUDUDDU\n4 UUUU\nOutput\n2 1 1 \n9 0 \n0 4 9 6 9\nNote\nIn the first test case, we can prove that initial sequence was $$$[2,1,1]$$$. In that case, the following moves were performed:\nOn the first wheel: $$$2 \\xrightarrow[\\texttt{D}]{} 1 \\xrightarrow[\\texttt{D}]{} 0 \\xrightarrow[\\texttt{D}]{} 9$$$.\nOn the second wheel: $$$1 \\xrightarrow[\\texttt{U}]{} 2 \\xrightarrow[\\texttt{D}]{} 1 \\xrightarrow[\\texttt{U}]{} 2 \\xrightarrow[\\texttt{U}]{} 3$$$.\nOn the third wheel: $$$1 \\xrightarrow[\\texttt{D}]{} 0 \\xrightarrow[\\texttt{U}]{} 1$$$.\nThe final sequence was $$$[9,3,1]$$$, which matches the input.", "input": [ [ [ "3" ], [ "9 3 1", "3 DDD", "4 UDUU", "2 DU" ] ] ], "output": [ "2 1 1" ] }, { "problem_id": "1703B", "problem_name": "ICPC Balloons\ndata structures, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1703/B", "problem_solution_link": "https://codeforces.com/problemset/status/1703/problem/B", "problem_statement": "B. ICPC Balloons\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIn an ICPC contest, balloons are distributed as follows:\nWhenever a team solves a problem, that team gets a balloon.\nThe first team to solve a problem gets an additional balloon.\nA contest has 26 problems, labelled $$$\\textsf{A}$$$, $$$\\textsf{B}$$$, $$$\\textsf{C}$$$, ..., $$$\\textsf{Z}$$$. You are given the order of solved problems in the contest, denoted as a string $$$s$$$, where the $$$i$$$-th character indicates that the problem $$$s_i$$$ has been solved by some team. No team will solve the same problem twice.\nDetermine the total number of balloons that the teams received. Note that some problems may be solved by none of the teams.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of testcases.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 50$$$)\u00a0\u2014 the length of the string.\nThe second line of each test case contains a string $$$s$$$ of length $$$n$$$ consisting of uppercase English letters, denoting the order of solved problems.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the total number of balloons that the teams received.\nExample\nInput\n6\n3\nABA\n1\nA\n3\nORZ\n5\nBAAAA\n4\nBKPT\n10\nCODEFORCES\nOutput\n5\n2\n6\n7\n8\n17\nNote\nIn the first test case, $$$5$$$ balloons are given out:\nProblem $$$\\textsf{A}$$$ is solved. That team receives $$$2$$$ balloons: one because they solved the problem, an an additional one because they are the first team to solve problem $$$\\textsf{A}$$$.\nProblem $$$\\textsf{B}$$$ is solved. That team receives $$$2$$$ balloons: one because they solved the problem, an an additional one because they are the first team to solve problem $$$\\textsf{B}$$$.\nProblem $$$\\textsf{A}$$$ is solved. That team receives only $$$1$$$ balloon, because they solved the problem. Note that they don't get an additional balloon because they are\nnot\nthe first team to solve problem $$$\\textsf{A}$$$.\nThe total number of balloons given out is $$$2+2+1=5$$$.\nIn the second test case, there is only one problem solved. The team who solved it receives $$$2$$$ balloons: one because they solved the problem, an an additional one because they are the first team to solve problem $$$\\textsf{A}$$$.", "input": [ [ [ "3" ], [ "ABA" ] ], [ [ "1" ], [ "A" ] ], [ [ "3" ], [ "ORZ" ] ], [ [ "5" ], [ "BAAAA" ] ], [ [ "4" ], [ "BKPT" ] ], [ [ "10" ], [ "CODEFORCES" ] ] ], "output": [ "5", "2", "6", "7", "8", "17" ] }, { "problem_id": "1703A", "problem_name": "YES or YES?\nbrute force, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1703/A", "problem_solution_link": "https://codeforces.com/problemset/status/1703/problem/A", "problem_statement": "A. YES or YES?\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a string $$$s$$$ of length $$$3$$$, consisting of uppercase and lowercase English letters. Check if it is equal to \"\nYES\n\" (without quotes), where each letter can be in any case. For example, \"\nyES\n\", \"\nYes\n\", \"\nyes\n\" are all allowable.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\leq t \\leq 10^3$$$)\u00a0\u2014 the number of testcases.\nThe description of each test consists of one line containing one string $$$s$$$ consisting of three characters. Each character of $$$s$$$ is either an uppercase or lowercase English letter.\nOutput\nFor each test case, output \"\nYES\n\" (without quotes) if $$$s$$$ satisfies the condition, and \"\nNO\n\" (without quotes) otherwise.\nYou can output \"\nYES\n\" and \"\nNO\n\" in any case (for example, strings \"\nyES\n\", \"\nyes\n\" and \"\nYes\n\" will be recognized as a positive response).\nExample\nInput\n10\nYES\nyES\nyes\nYes\nYeS\nNoo\norZ\nyEz\nYas\nXES\nOutput\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNote\nThe first five test cases contain the strings \"\nYES\n\", \"\nyES\n\", \"\nyes\n\", \"\nYes\n\", \"\nYeS\n\". All of these are equal to \"\nYES\n\", where each character is either uppercase or lowercase.", "input": [ [ [ "YES" ] ], [ [ "yES" ] ], [ [ "yes" ] ], [ [ "Yes" ] ], [ [ "YeS" ] ], [ [ "Noo" ] ], [ [ "orZ" ] ], [ [ "yEz" ] ], [ [ "Yas" ] ], [ [ "XES" ] ] ], "output": [ "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "NO", "NO" ] }, { "problem_id": "1702B", "problem_name": "Polycarp Writes a String from Memory\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1702/B", "problem_solution_link": "https://codeforces.com/problemset/status/1702/problem/B", "problem_statement": "B. Polycarp Writes a String from Memory\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp has a poor memory. Each day he can remember no more than $$$3$$$ of different letters.\nPolycarp wants to write a non-empty string of $$$s$$$ consisting of lowercase Latin letters, taking\nminimum\nnumber of days. In how many days will he be able to do it?\nPolycarp initially has an empty string and can only add characters to the end of that string.\nFor example, if Polycarp wants to write the string\nlollipops\n, he will do it in $$$2$$$ days:\non the first day Polycarp will memorize the letters\nl\n,\no\n,\ni\nand write\nlolli\n;\nOn the second day Polycarp will remember the letters\np\n,\no\n,\ns\n, add\npops\nto the resulting line and get the line\nlollipops\n.\nIf Polycarp wants to write the string\nstringology\n, he will do it in $$$4$$$ days:\nin the first day will be written part\nstr\n;\non day two will be written part\ning\n;\non the third day, part of\nolog\nwill be written;\non the fourth day, part of\ny\nwill be written.\nFor a given string $$$s$$$, print the minimum number of days it will take Polycarp to write it.\nInput\nThe first line of input data contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of a non-empty string $$$s$$$ consisting of lowercase Latin letters (the length of the string $$$s$$$ does not exceed $$$2 \\cdot 10^5$$$)\u00a0\u2014 the string Polycarp wants to construct.\nIt is guaranteed that the sum of string lengths $$$s$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print a single number\u00a0\u2014\nminimum\nnumber of days it will take Polycarp to write the string $$$s$$$ from memory.\nExample\nInput\n6\nlollipops\nstringology\nabracadabra\ncodeforces\ntest\nf\nOutput\n2\n4\n3\n4\n1\n1", "input": [ [ [ "lollipops" ] ], [ [ "stringology" ] ], [ [ "abracadabra" ] ], [ [ "codeforces" ] ], [ [ "test" ] ], [ [ "f" ] ] ], "output": [ "2", "4", "3", "4", "1", "1" ] }, { "problem_id": "1702A", "problem_name": "Round Down the Price\nconstructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1702/A", "problem_solution_link": "https://codeforces.com/problemset/status/1702/problem/A", "problem_statement": "A. Round Down the Price\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAt the store, the salespeople want to make all prices\nround\n.\nIn this problem, a number that is a power of $$$10$$$ is called a\nround\nnumber. For example, the numbers $$$10^0 = 1$$$, $$$10^1 = 10$$$, $$$10^2 = 100$$$ are\nround\nnumbers, but $$$20$$$, $$$110$$$ and $$$256$$$ are not\nround\nnumbers.\nSo, if an item is worth $$$m$$$ bourles (the value of the item is not greater than $$$10^9$$$), the sellers want to change its value to the nearest\nround\nnumber that is not greater than $$$m$$$. They ask you: by how many bourles should you\ndecrease\nthe value of the item to make it worth exactly $$$10^k$$$ bourles, where the value of $$$k$$$\u00a0\u2014 is the maximum possible ($$$k$$$\u00a0\u2014 any non-negative integer).\nFor example, let the item have a value of $$$178$$$-bourles. Then the new price of the item will be $$$100$$$, and the answer will be $$$178-100=78$$$.\nInput\nThe first line of input data contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases .\nEach test case is a string containing a single integer $$$m$$$ ($$$1 \\le m \\le 10^9$$$)\u00a0\u2014 the price of the item.\nOutput\nFor each test case, output on a separate line a single integer $$$d$$$ ($$$0 \\le d < m$$$) such that if you reduce the cost of the item by $$$d$$$ bourles, the cost of the item will be the maximal possible\nround\nnumber. More formally: $$$m - d = 10^k$$$, where $$$k$$$\u00a0\u2014 the maximum possible non-negative integer.\nExample\nInput\n7\n1\n2\n178\n20\n999999999\n9000\n987654321\nOutput\n0\n1\n78\n10\n899999999\n8000\n887654321\nNote\nIn the example:\n$$$1 - 0 = 10^0$$$,\n$$$2 - 1 = 10^0$$$,\n$$$178 - 78 = 10^2$$$,\n$$$20 - 10 = 10^1$$$,\n$$$999999999 - 899999999 = 10^8$$$,\n$$$9000 - 8000 = 10^3$$$,\n$$$987654321 - 887654321 = 10^8$$$.\nNote that in each test case, we get the maximum possible\nround\nnumber.", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "178" ] ], [ [ "20" ] ], [ [ "999999999" ] ], [ [ "9000" ] ], [ [ "987654321" ] ] ], "output": [ "0", "1", "78", "10", "899999999", "8000", "887654321" ], "error": true }, { "problem_id": "1701B", "problem_name": "Permutation\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1701/B", "problem_solution_link": "https://codeforces.com/problemset/status/1701/problem/B", "problem_statement": "B. Permutation\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nRecall that a permutation of length $$$n$$$ is an array where each element from $$$1$$$ to $$$n$$$ occurs exactly once.\nFor a fixed positive integer $$$d$$$, let's define the cost of the permutation $$$p$$$ of length $$$n$$$ as the number of indices $$$i$$$ $$$(1 \\le i < n)$$$ such that $$$p_i \\cdot d = p_{i + 1}$$$.\nFor example, if $$$d = 3$$$ and $$$p = [5, 2, 6, 7, 1, 3, 4]$$$, then the cost of such a permutation is $$$2$$$, because $$$p_2 \\cdot 3 = p_3$$$ and $$$p_5 \\cdot 3 = p_6$$$.\nYour task is the following one: for a given value $$$n$$$, find the permutation of length $$$n$$$ and the value $$$d$$$ with maximum possible cost (over all ways to choose the permutation and $$$d$$$). If there are multiple answers, then print any of them.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 500$$$)\u00a0\u2014 the number of test cases.\nThe single line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$).\nThe sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print the value $$$d$$$ in the first line, and $$$n$$$ integers in the second line\u00a0\u2014 the permutation itself. If there are multiple answers, then print any of them.\nExample\nInput\n2\n2\n3\nOutput\n2\n1 2\n3\n2 1 3", "input": [ [ [ "2" ] ], [ [ "3" ] ] ], "output": [ ["2", "1 2"], ["3", "2 1 3"] ], "error": true }, { "problem_id": "1701A", "problem_name": "Grass Field\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1701/A", "problem_solution_link": "https://codeforces.com/problemset/status/1701/problem/A", "problem_statement": "A. Grass Field\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a field of size $$$2 \\times 2$$$. Each cell of this field can either contain grass or be empty. The value $$$a_{i, j}$$$ is $$$1$$$ if the cell $$$(i, j)$$$ contains grass, or $$$0$$$ otherwise.\nIn one move, you can choose\none row\nand\none column\nand cut all the grass in this row and this column. In other words, you choose the row $$$x$$$ and the column $$$y$$$, then you cut the grass in all cells $$$a_{x, i}$$$ and all cells $$$a_{i, y}$$$ for all $$$i$$$ from $$$1$$$ to $$$2$$$. After you cut the grass from a cell, it becomes empty (i.\u2009e. its value is replaced by $$$0$$$).\nYour task is to find the minimum number of moves required to cut the grass in all non-empty cells of the field (i.\u2009e. make all $$$a_{i, j}$$$ zeros).\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 16$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe test case consists of two lines, each of these lines contains two integers. The $$$j$$$-th integer in the $$$i$$$-th row is $$$a_{i, j}$$$. If $$$a_{i, j} = 0$$$ then the cell $$$(i, j)$$$ is empty, and if $$$a_{i, j} = 1$$$ the cell $$$(i, j)$$$ contains grass.\nOutput\nFor each test case, print one integer \u2014 the minimum number of moves required to cut the grass in all non-empty cells of the field (i.\u2009e. make all $$$a_{i, j}$$$ zeros) in the corresponding test case.\nExample\nInput\n3\n0 0\n0 0\n1 0\n0 1\n1 1\n1 1\nOutput\n0\n1\n2", "input": [ [ [ "0", "0" ], [ "0", "0" ] ], [ [ "1", "0" ], [ "0", "1" ] ], [ [ "1", "1" ], [ "1", "1" ] ] ], "output": [ "0", "1", "2" ] }, { "problem_id": "1700A", "problem_name": "Optimal Path\nconstructive algorithms, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1700/A", "problem_solution_link": "https://codeforces.com/problemset/status/1700/problem/A", "problem_statement": "A. Optimal Path\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a table $$$a$$$ of size $$$n \\times m$$$. We will consider the table rows numbered from top to bottom from $$$1$$$ to $$$n$$$, and the columns numbered from left to right from $$$1$$$ to $$$m$$$. We will denote a cell that is in the $$$i$$$-th row and in the $$$j$$$-th column as $$$(i, j)$$$. In the cell $$$(i, j)$$$ there is written a number $$$(i - 1) \\cdot m + j$$$, that is $$$a_{ij} = (i - 1) \\cdot m + j$$$.\nA turtle initially stands in the cell $$$(1, 1)$$$ and it wants to come to the cell $$$(n, m)$$$. From the cell $$$(i, j)$$$ it can in one step go to one of the cells $$$(i + 1, j)$$$ or $$$(i, j + 1)$$$, if it exists. A path is a sequence of cells in which for every two adjacent in the sequence cells the following satisfies: the turtle can reach from the first cell to the second cell in one step. A cost of a path is the sum of numbers that are written in the cells of the path.\nFor example, with $$$n = 2$$$ and $$$m = 3$$$ the table will look as shown above. The turtle can take the following path: $$$(1, 1) \\rightarrow (1, 2) \\rightarrow (1, 3) \\rightarrow (2, 3)$$$. The cost of such way is equal to $$$a_{11} + a_{12} + a_{13} + a_{23} = 12$$$. On the other hand, the paths $$$(1, 1) \\rightarrow (1, 2) \\rightarrow (2, 2) \\rightarrow (2, 1)$$$ and $$$(1, 1) \\rightarrow (1, 3)$$$ are incorrect, because in the first path the turtle can't make a step $$$(2, 2) \\rightarrow (2, 1)$$$, and in the second path it can't make a step $$$(1, 1) \\rightarrow (1, 3)$$$.\nYou are asked to tell the turtle a minimal possible cost of a path from the cell $$$(1, 1)$$$ to the cell $$$(n, m)$$$. Please note that the cells $$$(1, 1)$$$ and $$$(n, m)$$$ are a part of the way.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$) \u2014 the number of test cases. The description of test cases follows.\nA single line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\leq n, m \\leq 10^4$$$) \u2014 the number of rows and columns of the table $$$a$$$ respectively.\nOutput\nFor each test case output a single integer \u2014 a minimal possible cost of a path from the cell $$$(1, 1)$$$ to the cell $$$(n, m)$$$.\nExample\nInput\n7\n1 1\n2 3\n3 2\n7 1\n1 10\n5 5\n10000 10000\nOutput\n1\n12\n13\n28\n55\n85\n500099995000\nNote\nIn the first test case the only possible path consists of a single cell $$$(1, 1)$$$.\nThe path with the minimal cost in the second test case is shown in the statement.\nIn the fourth and the fifth test cases there is only one path from $$$(1, 1)$$$ to $$$(n, m)$$$. Both paths visit every cell in the table.", "input": [ [ [ "1", "1" ] ], [ [ "2", "3" ] ], [ [ "3", "2" ] ], [ [ "7", "1" ] ], [ [ "1", "10" ] ], [ [ "5", "5" ] ], [ [ "10000", "10000" ] ] ], "output": [ "1", "12", "13", "28", "55", "85", "500099995000" ] }, { "problem_id": "1699A", "problem_name": "The Third Three Number Problem\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1699/A", "problem_solution_link": "https://codeforces.com/problemset/status/1699/problem/A", "problem_statement": "A. The Third Three Number Problem\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a positive integer $$$n$$$. Your task is to find\nany\nthree integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$0 \\le a, b, c \\le 10^9$$$) for which $$$(a\\oplus b)+(b\\oplus c)+(a\\oplus c)=n$$$, or determine that there are no such integers.\nHere $$$a \\oplus b$$$ denotes the\nbitwise XOR\nof $$$a$$$ and $$$b$$$. For example, $$$2 \\oplus 4 = 6$$$ and $$$3 \\oplus 1=2$$$.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. The following lines contain the descriptions of the test cases.\nThe only line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$).\nOutput\nFor each test case, print\nany\nthree integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$0 \\le a, b, c \\le 10^9$$$) for which $$$(a\\oplus b)+(b\\oplus c)+(a\\oplus c)=n$$$. If no such integers exist, print $$$-1$$$.\nExample\nInput\n5\n4\n1\n12\n2046\n194723326\nOutput\n3 3 1\n-1\n2 4 6\n69 420 666\n12345678 87654321 100000000\nNote\nIn the first test case, $$$a=3$$$, $$$b=3$$$, $$$c=1$$$, so $$$(3 \\oplus 3)+(3 \\oplus 1) + (3 \\oplus 1)=0+2+2=4$$$.\nIn the second test case, there are no solutions.\nIn the third test case, $$$(2 \\oplus 4)+(4 \\oplus 6) + (2 \\oplus 6)=6+2+4=12$$$.", "input": [ [ [ "4" ] ], [ [ "1" ] ], [ [ "12" ] ], [ [ "2046" ] ], [ [ "194723326" ] ] ], "output": [ "3 3 1", "-1", "2 4 6", "69 420 666", "12345678 87654321 100000000" ] }, { "problem_id": "1698B", "problem_name": "Rising Sand\nconstructive algorithms, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1698/B", "problem_solution_link": "https://codeforces.com/problemset/status/1698/problem/B", "problem_statement": "B. Rising Sand\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ piles of sand where the $$$i$$$-th pile has $$$a_i$$$ blocks of sand. The $$$i$$$-th pile is called\ntoo tall\nif $$$1 < i < n$$$ and $$$a_i > a_{i-1} + a_{i+1}$$$. That is, a pile is too tall if it has more sand than its two neighbours combined. (Note that piles on the ends of the array cannot be too tall.)\nYou are given an integer $$$k$$$. An operation consists of picking $$$k$$$ consecutive piles of sand and adding one unit of sand to them all. Formally, pick $$$1 \\leq l,r \\leq n$$$ such that $$$r-l+1=k$$$. Then for all $$$l \\leq i \\leq r$$$, update $$$a_i \\gets a_i+1$$$.\nWhat is the\nmaximum\nnumber of piles that can simultaneously be too tall after some (possibly zero) operations?\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$3 \\leq n \\leq 2 \\cdot 10^5$$$; $$$1 \\leq k \\leq n$$$)\u00a0\u2014 the number of piles of sand and the size of the operation, respectively.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$)\u00a0\u2014 the sizes of the piles.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the maximum number of piles that are simultaneously too tall after some (possibly zero) operations.\nExample\nInput\n3\n5 2\n2 9 2 4 1\n4 4\n1 3 2 1\n3 1\n1 3 1\nOutput\n2\n0\n1\nNote\nIn the first test case, we can perform the following three operations:\nAdd one unit of sand to piles $$$1$$$ and $$$2$$$: $$$[\\color{red}{3}, \\color{red}{10}, 2, 4, 1]$$$.\nAdd one unit of sand to piles $$$4$$$ and $$$5$$$: $$$[3, 10, 2, \\color{red}{5}, \\color{red}{2}]$$$.\nAdd one unit of sand to piles $$$3$$$ and $$$4$$$: $$$[3, 10, \\color{red}{3}, \\color{red}{6}, 2]$$$.\nNow piles $$$2$$$ and $$$4$$$ are too tall, so in this case the answer is $$$2$$$. It can be shown that it is impossible to make more than $$$2$$$ piles too tall.\nIn the second test case, any operation will increase all piles by $$$1$$$ unit, so the number of too tall piles will always be $$$0$$$.\nIn the third test case, we can increase any pile by $$$1$$$ unit of sand. It can be shown that the maximum number of too tall piles is $$$1$$$.", "input": [ [ [ "5", "2" ], [ "2", "9", "2", "4", "1" ] ], [ [ "4", "4" ], [ "1", "3", "2", "1" ] ], [ [ "3", "1" ], [ "1", "3", "1" ] ] ], "output": [ "2", "0", "1" ] }, { "problem_id": "1698A", "problem_name": "XOR Mixup\nbitmasks, brute force", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1698/A", "problem_solution_link": "https://codeforces.com/problemset/status/1698/problem/A", "problem_statement": "A. XOR Mixup\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is an array $$$a$$$ with $$$n-1$$$ integers. Let $$$x$$$ be the\nbitwise XOR\nof all elements of the array. The number $$$x$$$ is added to the end of the array $$$a$$$ (now it has length $$$n$$$), and then the elements are shuffled.\nYou are given the newly formed array $$$a$$$. What is $$$x$$$? If there are multiple possible values of $$$x$$$, you can output any of them.\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$)\u00a0\u2014 the number of integers in the resulting array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i \\le 127$$$)\u00a0\u2014 the elements of the newly formed array $$$a$$$.\nAdditional constraint on the input:\nthe array $$$a$$$ is made by the process described in the statement; that is, some value of $$$x$$$ exists.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the value of $$$x$$$, as described in the statement. If there are multiple possible values of $$$x$$$, output any of them.\nExample\nInput\n4\n4\n4 3 2 5\n5\n6 1 10 7 10\n6\n6 6 6 6 6 6\n3\n100 100 0\nOutput\n3\n7\n6\n0\nNote\nIn the first test case, one possible array $$$a$$$ is $$$a=[2, 5, 4]$$$. Then $$$x = 2 \\oplus 5 \\oplus 4 = 3$$$ ($$$\\oplus$$$ denotes the bitwise XOR), so the new array is $$$[2, 5, 4, 3]$$$. Afterwards, the array is shuffled to form $$$[4, 3, 2, 5]$$$.\nIn the second test case, one possible array $$$a$$$ is $$$a=[1, 10, 6, 10]$$$. Then $$$x = 1 \\oplus 10 \\oplus 6 \\oplus 10 = 7$$$, so the new array is $$$[1, 10, 6, 10, 7]$$$. Afterwards, the array is shuffled to form $$$[6, 1, 10, 7, 10]$$$.\nIn the third test case, all elements of the array are equal to $$$6$$$, so $$$x=6$$$.\nIn the fourth test case, one possible array $$$a$$$ is $$$a=[100, 100]$$$. Then $$$x = 100 \\oplus 100 = 0$$$, so the new array is $$$[100, 100, 0]$$$. Afterwards, the array is shuffled to form $$$[100, 100, 0]$$$. (Note that after the shuffle, the array can remain the same.)", "input": [ [ [ "4" ], [ "4", "3", "2", "5" ] ], [ [ "5" ], [ "6", "1", "10", "7", "10" ] ], [ [ "6" ], [ "6", "6", "6", "6", "6", "6" ] ], [ [ "3" ], [ "100", "100", "0" ] ] ], "output": [ "3", "7", "6", "0" ] }, { "problem_id": "1697A", "problem_name": "Parkway Walk\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1697/A", "problem_solution_link": "https://codeforces.com/problemset/status/1697/problem/A", "problem_statement": "A. Parkway Walk\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are walking through a parkway near your house. The parkway has $$$n+1$$$ benches in a row numbered from $$$1$$$ to $$$n+1$$$ from left to right. The distance between the bench $$$i$$$ and $$$i+1$$$ is $$$a_i$$$ meters.\nInitially, you have $$$m$$$ units of energy. To walk $$$1$$$ meter of distance, you spend $$$1$$$ unit of your energy. You can't walk if you have no energy. Also, you can restore your energy by\nsitting on benches\n(and this is the only way to restore the energy). When you are sitting, you can restore any integer amount of energy you want (if you sit longer, you restore more energy). Note that the amount of your energy\ncan exceed\n$$$m$$$.\nYour task is to find the\nminimum\namount of energy you have to\nrestore\n(by sitting on benches) to reach the bench $$$n+1$$$ from the bench $$$1$$$ (and end your walk).\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 100$$$; $$$1 \\le m \\le 10^4$$$).\nThe second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the distance between benches $$$i$$$ and $$$i+1$$$.\nOutput\nFor each test case, print one integer \u2014 the\nminimum\namount of energy you have to\nrestore\n(by sitting on benches) to reach the bench $$$n+1$$$ from the bench $$$1$$$ (and end your walk) in the corresponding test case.\nExample\nInput\n3\n3 1\n1 2 1\n4 5\n3 3 5 2\n5 16\n1 2 3 4 5\nOutput\n3\n8\n0\nNote\nIn the first test case of the example, you can walk to the bench $$$2$$$, spending $$$1$$$ unit of energy, then restore $$$2$$$ units of energy on the second bench, walk to the bench $$$3$$$, spending $$$2$$$ units of energy, restore $$$1$$$ unit of energy and go to the bench $$$4$$$.\nIn the third test case of the example, you have enough energy to just go to the bench $$$6$$$ without sitting at all.", "input": [ [ [ "3", "1" ], [ "1", "2", "1" ] ], [ [ "4", "5" ], [ "3", "3", "5", "2" ] ], [ [ "5", "16" ], [ "1", "2", "3", "4", "5" ] ] ], "output": [ "3", "8", "0" ] }, { "problem_id": "1696A", "problem_name": "NIT orz!\nbitmasks, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1696/A", "problem_solution_link": "https://codeforces.com/problemset/status/1696/problem/A", "problem_statement": "A. NIT orz!\ntime limit per test\n1 second\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nNIT, the cleaver, is new in town! Thousands of people line up to orz him. To keep his orzers entertained, NIT decided to let them solve the following problem related to $$$\\operatorname{or} z$$$. Can you solve this problem too?\nYou are given a 1-indexed array of $$$n$$$ integers, $$$a$$$, and an integer $$$z$$$. You can do the following operation any number (possibly zero) of times:\nSelect a positive integer $$$i$$$ such that $$$1\\le i\\le n$$$. Then,\nsimutaneously\nset $$$a_i$$$ to $$$(a_i\\operatorname{or} z)$$$ and set $$$z$$$ to $$$(a_i\\operatorname{and} z)$$$. In other words, let $$$x$$$ and $$$y$$$ respectively be the current values of $$$a_i$$$ and $$$z$$$. Then set $$$a_i$$$ to $$$(x\\operatorname{or}y)$$$ and set $$$z$$$ to $$$(x\\operatorname{and}y)$$$.\nHere $$$\\operatorname{or}$$$ and $$$\\operatorname{and}$$$ denote the\nbitwise operations OR and AND\nrespectively.\nFind the maximum possible value of the maximum value in $$$a$$$ after any number (possibly zero) of operations.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). Description of the test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$z$$$ ($$$1\\le n\\le 2000$$$, $$$0\\le z<2^{30}$$$).\nThe second line of each test case contains $$$n$$$ integers $$$a_1$$$,$$$a_2$$$,$$$\\ldots$$$,$$$a_n$$$ ($$$0\\le a_i<2^{30}$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$.\nOutput\nFor each test case, print one integer \u2014 the answer to the problem.\nExample\nInput\n5\n2 3\n3 4\n5 5\n0 2 4 6 8\n1 9\n10\n5 7\n7 15 30 29 27\n3 39548743\n10293834 10284344 13635445\nOutput\n7\n13\n11\n31\n48234367\nNote\nIn the first test case of the sample, one optimal sequence of operations is:\nDo the operation with $$$i=1$$$. Now $$$a_1$$$ becomes $$$(3\\operatorname{or}3)=3$$$ and $$$z$$$ becomes $$$(3\\operatorname{and}3)=3$$$.\nDo the operation with $$$i=2$$$. Now $$$a_2$$$ becomes $$$(4\\operatorname{or}3)=7$$$ and $$$z$$$ becomes $$$(4\\operatorname{and}3)=0$$$.\nDo the operation with $$$i=1$$$. Now $$$a_1$$$ becomes $$$(3\\operatorname{or}0)=3$$$ and $$$z$$$ becomes $$$(3\\operatorname{and}0)=0$$$.\nAfter these operations, the sequence $$$a$$$ becomes $$$[3,7]$$$, and the maximum value in it is $$$7$$$. We can prove that the maximum value in $$$a$$$ can never exceed $$$7$$$, so the answer is $$$7$$$.\nIn the fourth test case of the sample, one optimal sequence of operations is:\nDo the operation with $$$i=1$$$. Now $$$a_1$$$ becomes $$$(7\\operatorname{or}7)=7$$$ and $$$z$$$ becomes $$$(7\\operatorname{and}7)=7$$$.\nDo the operation with $$$i=3$$$. Now $$$a_3$$$ becomes $$$(30\\operatorname{or}7)=31$$$ and $$$z$$$ becomes $$$(30\\operatorname{and}7)=6$$$.\nDo the operation with $$$i=5$$$. Now $$$a_5$$$ becomes $$$(27\\operatorname{or}6)=31$$$ and $$$z$$$ becomes $$$(27\\operatorname{and}6)=2$$$.", "input": [ [ [ "2", "3" ], [ "3", "4" ] ], [ [ "5", "5" ], [ "0", "2", "4", "6", "8" ] ], [ [ "1", "9" ], [ "10" ] ], [ [ "5", "7" ], [ "7", "15", "30", "29", "27" ] ], [ [ "3", "39548743" ], [ "10293834", "10284344", "13635445" ] ] ], "output": [ "7", "13", "11", "31", "48234367" ] }, { "problem_id": "1695A", "problem_name": "Subrectangle Guess\ngames", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1695/A", "problem_solution_link": "https://codeforces.com/problemset/status/1695/problem/A", "problem_statement": "A. Subrectangle Guess\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMichael and Joe are playing a game. The game is played on a grid with $$$n$$$ rows and $$$m$$$ columns,\nfilled with distinct integers\n. We denote the square on the $$$i$$$-th ($$$1\\le i\\le n$$$) row and $$$j$$$-th ($$$1\\le j\\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$.\nMichael starts by saying two numbers $$$h$$$ ($$$1\\le h \\le n$$$) and $$$w$$$ ($$$1\\le w \\le m$$$). Then Joe picks any $$$h\\times w$$$ subrectangle of the board (without Michael seeing).\nFormally, an $$$h\\times w$$$ subrectangle starts at some square $$$(a,b)$$$ where $$$1 \\le a \\le n-h+1$$$ and $$$1 \\le b \\le m-w+1$$$. It contains all squares $$$(i,j)$$$ for $$$a \\le i \\le a+h-1$$$ and $$$b \\le j \\le b+w-1$$$.\nPossible move by Joe if Michael says $$$3\\times 2$$$ (with maximum of $$$15$$$).\nFinally, Michael has to guess the maximum number in the subrectangle. He wins if he gets it right.\nBecause Michael doesn't like big numbers, he wants the area of the chosen subrectangle (that is, $$$h \\cdot w$$$), to be as small as possible, while still ensuring that he wins, not depending on Joe's choice. Help Michael out by finding this minimum possible area.\nIt can be shown that Michael can always choose $$$h, w$$$ for which he can ensure that he wins.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 20$$$). Description of the test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 40$$$) \u00a0\u2014 the size of the grid.\nEach of the following $$$n$$$ lines contains $$$m$$$ integers. The $$$j$$$-th integer on the $$$i$$$-th line is $$$a_{ij}$$$ ($$$-10^9 \\le a_{ij} \\le 10^9$$$) \u00a0\u2014 the element in the cell $$$(i, j)$$$.\nIt is guaranteed that all the numbers are\ndistinct\n(that is, if $$$a_{i_1j_1} = a_{i_2j_2}$$$, then $$$i_1 = i_2, j_1 = j_2$$$).\nOutput\nFor each test case print a single positive integer \u00a0\u2014 the minimum possible area the subrectangle can have while still ensuring that Michael can guarantee the victory.\nExample\nInput\n3\n1 1\n3\n4 4\n2 12 6 10\n3 15 16 4\n1 13 8 11\n14 7 9 5\n2 3\n-7 5 2\n0 8 -3\nOutput\n1\n9\n4\nNote\nIn the first test case, the grid is $$$1\\times 1$$$, so the only possible choice for $$$h, w$$$ is $$$h = 1, w = 1$$$, giving an area of $$$h\\cdot w = 1$$$.\nThe grid from the second test case is drawn in the statement. It can be shown that with $$$h = 3, w = 3$$$ Michael can guarantee the victory and that any choice with $$$h\\cdot w \\le 8$$$ doesn't.", "input": [ [ "4", "4" ], [ "2", "12", "6", "10", "3", "15", "16", "4", "1", "13", "8", "11", "14", "7", "9", "5" ] ], "output": [ "9" ] }, { "problem_id": "1694A", "problem_name": "Creep\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1694/A", "problem_solution_link": "https://codeforces.com/problemset/status/1694/problem/A", "problem_statement": "A. Creep\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nDefine the score of some binary string $$$T$$$ as the absolute difference between the number of zeroes and ones in it. (for example, $$$T=$$$\n010001\ncontains $$$4$$$ zeroes and $$$2$$$ ones, so the score of $$$T$$$ is $$$|4-2| = 2$$$).\nDefine the creepiness of some binary string $$$S$$$ as the maximum score among all of its prefixes (for example, the creepiness of $$$S=$$$\n01001\nis equal to $$$2$$$ because the score of the prefix $$$S[1 \\ldots 4]$$$ is $$$2$$$ and the rest of the prefixes have a score of $$$2$$$ or less).\nGiven two integers $$$a$$$ and $$$b$$$, construct a binary string consisting of $$$a$$$ zeroes and $$$b$$$ ones with the minimum possible creepiness.\nInput\nThe first line contains a single integer $$$t$$$ $$$(1\\le t\\le 1000)$$$ \u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$ 1 \\le a, b \\le 100$$$) \u00a0\u2014 the numbers of zeroes and ones correspondingly.\nOutput\nFor each test case, print a binary string consisting of $$$a$$$ zeroes and $$$b$$$ ones with the minimum possible creepiness. If there are multiple answers, print any of them.\nExample\nInput\n5\n1 1\n1 2\n5 2\n4 5\n3 7\nOutput\n10\n011\n0011000\n101010101\n0001111111\nNote\nIn the first test case, the score of $$$S[1 \\ldots 1]$$$ is $$$1$$$, and the score of $$$S[1 \\ldots 2]$$$ is $$$0$$$.\nIn the second test case, the minimum possible creepiness is $$$1$$$ and one of the other answers is\n101\n.\nIn the third test case, the minimum possible creepiness is $$$3$$$ and one of the other answers is\n0001100\n.", "input": [ [ [ "1", "1" ] ], [ [ "1", "2" ] ], [ [ "5", "2" ] ], [ [ "4", "5" ] ], [ [ "3", "7" ] ] ], "output": [ "10", "011", "0011000", "101010101", "0001111111" ] }, { "problem_id": "1692C", "problem_name": "Where's the Bishop?\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1692/C", "problem_solution_link": "https://codeforces.com/problemset/status/1692/problem/C", "problem_statement": "C. Where's the Bishop?\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMihai has an $$$8 \\times 8$$$ chessboard whose rows are numbered from $$$1$$$ to $$$8$$$ from top to bottom and whose columns are numbered from $$$1$$$ to $$$8$$$ from left to right.\nMihai has placed exactly one bishop on the chessboard.\nThe bishop is not placed on the edges of the board.\n(In other words, the row and column of the bishop are between $$$2$$$ and $$$7$$$, inclusive.)\nThe bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked.\nAn example of a bishop on a chessboard. The squares it attacks are marked in red.\nMihai has marked all squares the bishop attacks, but forgot where the bishop was! Help Mihai find the position of the bishop.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 36$$$)\u00a0\u2014 the number of test cases. The description of test cases follows. There is an empty line before each test case.\nEach test case consists of $$$8$$$ lines, each containing $$$8$$$ characters. Each of these characters is either '\n#\n' or '\n.\n', denoting a square under attack and a square not under attack, respectively.\nOutput\nFor each test case, output two integers $$$r$$$ and $$$c$$$ ($$$2 \\leq r, c \\leq 7$$$)\u00a0\u2014 the row and column of the bishop.\nThe input is generated in such a way that there is always exactly one possible location of the bishop that is not on the edge of the board.\nExample\nInput\n3\n\n.....#..\n#...#...\n.#.#....\n..#.....\n.#.#....\n#...#...\n.....#..\n......#.\n\n#.#.....\n.#......\n#.#.....\n...#....\n....#...\n.....#..\n......#.\n.......#\n\n.#.....#\n..#...#.\n...#.#..\n....#...\n...#.#..\n..#...#.\n.#.....#\n#.......\nOutput\n4 3\n2 2\n4 5\nNote\nThe first test case is pictured in the statement. Since the bishop lies in the intersection row $$$4$$$ and column $$$3$$$, the correct output is\n4 3\n.", "input": [ [ [ "" ], [ ".....#.." ], [ "#...#..." ], [ ".#.#...." ], [ "..#....." ], [ ".#.#...." ], [ "#...#..." ], [ ".....#.." ], [ "......#." ] ], [ [ "" ], [ "#.#....." ], [ ".#......" ], [ "#.#....." ], [ "...#...." ], [ "....#..." ], [ ".....#.." ], [ "......#." ], [ ".......#" ] ], [ [ "" ], [ ".#.....#" ], [ "..#...#." ], [ "...#.#.." ], [ "....#..." ], [ "...#.#.." ], [ "..#...#." ], [ ".#.....#" ], [ "#......." ] ] ], "output": [ "4 3", "2 2", "4 5" ] }, { "problem_id": "1692B", "problem_name": "All Distinct\ngreedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1692/B", "problem_solution_link": "https://codeforces.com/problemset/status/1692/problem/B", "problem_statement": "B. All Distinct\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nSho has an array $$$a$$$ consisting of $$$n$$$ integers. An operation consists of choosing two distinct indices $$$i$$$ and $$$j$$$ and removing $$$a_i$$$ and $$$a_j$$$ from the array.\nFor example, for the array $$$[2, 3, 4, 2, 5]$$$, Sho can choose to remove indices $$$1$$$ and $$$3$$$. After this operation, the array becomes $$$[3, 2, 5]$$$. Note that after any operation, the length of the array is reduced by two.\nAfter he made some operations, Sho has an array that has only\ndistinct\nelements. In addition, he made operations such that the resulting array is the\nlongest\npossible.\nMore formally, the array after Sho has made his operations respects these criteria:\nNo pairs such that ($$$i < j$$$) and $$$a_i = a_j$$$ exist.\nThe length of $$$a$$$ is maximized.\nOutput the length of the final array.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^3$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 50$$$)\u00a0\u2014 the length of the array.\nThe second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \\leq a_i \\leq 10^4$$$)\u00a0\u2014 the elements of the array.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the length of the final array. Remember that in the final array, all elements are different, and its length is maximum.\nExample\nInput\n4\n6\n2 2 2 3 3 3\n5\n9 1 9 9 1\n4\n15 16 16 15\n4\n10 100 1000 10000\nOutput\n2\n1\n2\n4\nNote\nFor the first test case Sho can perform operations as follows:\nChoose indices $$$1$$$ and $$$5$$$ to remove. The array becomes $$$[2, 2, 2, 3, 3, 3] \\rightarrow [2, 2, 3, 3]$$$.\nChoose indices $$$1$$$ and $$$4$$$ to remove. The array becomes $$$[2, 2, 3, 3] \\rightarrow [2, 3]$$$.\nThe final array has a length of $$$2$$$, so the answer is $$$2$$$. It can be proven that Sho cannot obtain an array with a longer length.\nFor the second test case Sho can perform operations as follows:\nChoose indices $$$3$$$ and $$$4$$$ to remove. The array becomes $$$[9, 1, 9, 9, 1] \\rightarrow [9, 1, 1]$$$.\nChoose indices $$$1$$$ and $$$3$$$ to remove. The array becomes $$$[9, 1, 1] \\rightarrow [1]$$$.\nThe final array has a length of $$$1$$$, so the answer is $$$1$$$. It can be proven that Sho cannot obtain an array with a longer length.", "input": [ [ [ "6" ], [ "2", "2", "2", "3", "3", "3" ] ], [ [ "5" ], [ "9", "1", "9", "9", "1" ] ], [ [ "4" ], [ "15", "16", "16", "15" ] ], [ [ "4" ], [ "10", "100", "1000", "10000" ] ] ], "output": [ "2", "1", "2", "4" ] }, { "problem_id": "1692A", "problem_name": "Marathon\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1692/A", "problem_solution_link": "https://codeforces.com/problemset/status/1692/problem/A", "problem_statement": "A. Marathon\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given four\ndistinct\nintegers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$.\nTimur and three other people are running a marathon. The value $$$a$$$ is the distance that Timur has run and $$$b$$$, $$$c$$$, $$$d$$$ correspond to the distances the other three participants ran.\nOutput the number of participants in front of Timur.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$)\u00a0\u2014 the number of test cases.\nThe description of each test case consists of four\ndistinct\nintegers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$0 \\leq a, b, c, d \\leq 10^4$$$).\nOutput\nFor each test case, output a single integer\u00a0\u2014 the number of participants in front of Timur.\nExample\nInput\n4\n2 3 4 1\n10000 0 1 2\n500 600 400 300\n0 9999 10000 9998\nOutput\n2\n0\n1\n3\nNote\nFor the first test case, there are $$$2$$$ people in front of Timur, specifically the participants who ran distances of $$$3$$$ and $$$4$$$. The other participant is not in front of Timur because he ran a shorter distance than Timur.\nFor the second test case, no one is in front of Timur, since he ran a distance of $$$10000$$$ while all others ran a distance of $$$0$$$, $$$1$$$, and $$$2$$$ respectively.\nFor the third test case, only the second person is in front of Timur, who ran a total distance of $$$600$$$ while Timur ran a distance of $$$500$$$.", "input": [ [ [ "2", "3", "4", "1" ] ], [ [ "10000", "0", "1", "2" ] ], [ [ "500", "600", "400", "300" ] ], [ [ "0", "9999", "10000", "9998" ] ] ], "output": [ "2", "0", "1", "3" ] }, { "problem_id": "1691A", "problem_name": "Beat The Odds\nbrute force, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1691/A", "problem_solution_link": "https://codeforces.com/problemset/status/1691/problem/A", "problem_statement": "A. Beat The Odds\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven a sequence $$$a_1, a_2, \\ldots, a_n$$$, find the minimum number of elements to remove from the sequence such that after the removal, the sum of every $$$2$$$ consecutive elements is even.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases. Description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$3 \\le n \\le 10^5$$$).\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2,\\dots,a_n$$$ ($$$1\\leq a_i\\leq10^9$$$) \u2014 elements of the sequence.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each test case, print a single integer \u2014 the minimum number of elements to remove from the sequence such that the sum of every $$$2$$$ consecutive elements is even.\nExample\nInput\n2\n5\n2 4 3 6 8\n6\n3 5 9 7 1 3\nOutput\n1\n0\nNote\nIn the first test case, after removing $$$3$$$, the sequence becomes $$$[2,4,6,8]$$$. The pairs of consecutive elements are $$$\\{[2, 4], [4, 6], [6, 8]\\}$$$. Each consecutive pair has an even sum now. Hence, we only need to remove $$$1$$$ element to satisfy the condition asked.\nIn the second test case, each consecutive pair already has an even sum so we need not remove any element.", "input": [ [ [ "5" ], [ "2", "4", "3", "6", "8" ] ], [ [ "6" ], [ "3", "5", "9", "7", "1", "3" ] ] ], "output": [ "1", "0" ] }, { "problem_id": "1690C", "problem_name": "Restoring the Duration of Tasks\ndata structures, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1690/C", "problem_solution_link": "https://codeforces.com/problemset/status/1690/problem/C", "problem_statement": "C. Restoring the Duration of Tasks\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nRecently, Polycarp completed $$$n$$$ successive tasks.\nFor each completed task, the time $$$s_i$$$ is known when it was given, no two tasks were given at the same time. Also given is the time $$$f_i$$$ when the task was completed. For each task, there is an unknown value $$$d_i$$$ ($$$d_i>0$$$)\u00a0\u2014\nduration of task execution\n.\nIt is known that the tasks were completed in the order in which they came. Polycarp performed the tasks as follows:\nAs soon as the very first task came, Polycarp immediately began to carry it out.\nIf a new task arrived before Polycarp finished the previous one, he put the new task at the end of the queue.\nWhen Polycarp finished executing the next task and the queue was not empty, he\nimmediately\ntook a new task from the head of the queue (if the queue is empty \u2014 he just waited for the next task).\nFind $$$d_i$$$ (duration) of each task.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe descriptions of the input data sets follow.\nThe first line of each test case contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$).\nThe second line of each test case contains exactly $$$n$$$ integers $$$s_1 < s_2 < \\dots < s_n$$$ ($$$0 \\le s_i \\le 10^9$$$).\nThe third line of each test case contains exactly $$$n$$$ integers $$$f_1 < f_2 < \\dots < f_n$$$ ($$$s_i < f_i \\le 10^9$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each of $$$t$$$ test cases print $$$n$$$ positive integers $$$d_1, d_2, \\dots, d_n$$$\u00a0\u2014 the duration of each task.\nExample\nInput\n4\n3\n0 3 7\n2 10 11\n2\n10 15\n11 16\n9\n12 16 90 195 1456 1569 3001 5237 19275\n13 199 200 260 9100 10000 10914 91066 5735533\n1\n0\n1000000000\nOutput\n2 7 1 \n1 1 \n1 183 1 60 7644 900 914 80152 5644467 \n1000000000\nNote\nFirst test case:\nThe queue is empty at the beginning: $$$[ ]$$$. And that's where the first task comes in. At time $$$2$$$, Polycarp finishes doing the first task, so the duration of the first task is $$$2$$$. The queue is empty so Polycarp is just waiting.\nAt time $$$3$$$, the second task arrives. And at time $$$7$$$, the third task arrives, and now the queue looks like this: $$$[7]$$$.\nAt the time $$$10$$$, Polycarp finishes doing the second task, as a result, the duration of the second task is $$$7$$$.\nAnd at time $$$10$$$, Polycarp immediately starts doing the third task and finishes at time $$$11$$$. As a result, the duration of the third task is $$$1$$$.\nAn example of the first test case.", "input": [ [ [ "3" ], [ "0", "3", "7" ], [ "2", "10", "11" ] ], [ [ "2" ], [ "10", "15" ], [ "11", "16" ] ], [ [ "9" ], [ "12", "16", "90", "195", "1456", "1569", "3001", "5237", "19275" ], [ "13", "199", "200", "260", "9100", "10000", "10914", "91066", "5735533" ] ], [ [ "1" ], [ "0" ], [ "1000000000" ] ] ], "output": [ "2 7 1 ", "1 1 ", "1 183 1 60 7644 900 914 80152 5644467 ", "1000000000" ] }, { "problem_id": "1690B", "problem_name": "Array Decrements\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1690/B", "problem_solution_link": "https://codeforces.com/problemset/status/1690/problem/B", "problem_statement": "B. Array Decrements\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nKristina has two arrays $$$a$$$ and $$$b$$$, each containing $$$n$$$ non-negative integers. She can perform the following operation on array $$$a$$$ any number of times:\napply a decrement to each non-zero element of the array, that is, replace the value of each element $$$a_i$$$ such that $$$a_i > 0$$$ with the value $$$a_i - 1$$$ ($$$1 \\le i \\le n$$$). If $$$a_i$$$ was $$$0$$$, its value does not change.\nDetermine whether Kristina can get an array $$$b$$$ from an array $$$a$$$ in some number of operations (probably zero). In other words, can she make $$$a_i = b_i$$$ after some number of operations for each $$$1 \\le i \\le n$$$?\nFor example, let $$$n = 4$$$, $$$a = [3, 5, 4, 1]$$$ and $$$b = [1, 3, 2, 0]$$$. In this case, she can apply the operation twice:\nafter the first application of the operation she gets $$$a = [2, 4, 3, 0]$$$;\nafter the second use of the operation she gets $$$a = [1, 3, 2, 0]$$$.\nThus, in two operations, she can get an array $$$b$$$ from an array $$$a$$$.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014the number of test cases in the test.\nThe descriptions of the test cases follow.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 5 \\cdot 10^4$$$).\nThe second line of each test case contains exactly $$$n$$$ non-negative integers $$$a_1, a_2, \\dots, a_n$$$ ($$$0 \\le a_i \\le 10^9$$$).\nThe third line of each test case contains exactly $$$n$$$ non-negative integers $$$b_1, b_2, \\dots, b_n$$$ ($$$0 \\le b_i \\le 10^9$$$).\nIt is guaranteed that the sum of $$$n$$$ values over all test cases in the test does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, output on a separate line:\nYES\n, if by doing some number of operations it is possible to get an array $$$b$$$ from an array $$$a$$$;\nNO\notherwise.\nYou can output\nYES\nand\nNO\nin any case (for example, strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as a positive response).\nExample\nInput\n6\n4\n3 5 4 1\n1 3 2 0\n3\n1 2 1\n0 1 0\n4\n5 3 7 2\n1 1 1 1\n5\n1 2 3 4 5\n1 2 3 4 6\n1\n8\n0\n1\n4\n6\nOutput\nYES\nYES\nNO\nNO\nYES\nNO\nNote\nThe first test case is analyzed in the statement.\nIn the second test case, it is enough to apply the operation to array $$$a$$$ once.\nIn the third test case, it is impossible to get array $$$b$$$ from array $$$a$$$.", "input": [ [ [ "4" ], [ "3", "5", "4", "1" ], [ "1", "3", "2", "0" ] ], [ [ "3" ], [ "1", "2", "1" ], [ "0", "1", "0" ] ], [ [ "4" ], [ "5", "3", "7", "2" ], [ "1", "1", "1", "1" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ], [ "1", "2", "3", "4", "6" ] ], [ [ "1" ], [ "8" ], [ "0" ] ], [ [ "1" ], [ "4" ], [ "6" ] ] ], "output": [ "YES", "YES", "NO", "NO", "YES", "NO" ] }, { "problem_id": "1690A", "problem_name": "Print a Pedestal (Codeforces logo?)\nconstructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1690/A", "problem_solution_link": "https://codeforces.com/problemset/status/1690/problem/A", "problem_statement": "A. Print a Pedestal (Codeforces logo?)\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven the integer $$$n$$$\u00a0\u2014 the number of available blocks. You must use\nall\nblocks to build a\npedestal\n.\nThe\npedestal\nconsists of $$$3$$$ platforms for $$$2$$$-nd, $$$1$$$-st and $$$3$$$-rd places respectively. The platform for the $$$1$$$-st place must be\nstrictly\nhigher than for the $$$2$$$-nd place, and the platform for the $$$2$$$-nd place must be\nstrictly\nhigher than for the $$$3$$$-rd place. Also, the height of each platform must be greater than zero (that is, each platform must contain at least one block).\nExample pedestal of $$$n=11$$$ blocks: second place height equals $$$4$$$ blocks, first place height equals $$$5$$$ blocks, third place height equals $$$2$$$ blocks.\nAmong all possible pedestals of $$$n$$$ blocks, deduce one such that the platform height for the $$$1$$$-st place\nminimum\nas possible. If there are several of them, output any of them.\nInput\nThe first line of input data contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nEach test case contains a single integer $$$n$$$ ($$$6 \\le n \\le 10^5$$$)\u00a0\u2014 the total number of blocks for the pedestal. All $$$n$$$ blocks must be used.\nIt is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^6$$$.\nOutput\nFor each test case, output $$$3$$$ numbers $$$h_2, h_1, h_3$$$\u00a0\u2014 the platform heights for $$$2$$$-nd, $$$1$$$-st and $$$3$$$-rd places on a pedestal consisting of $$$n$$$ blocks ($$$h_1+h_2+h_3=n$$$, $$$0 < h_3 < h_2 < h_1$$$).\nAmong all possible pedestals, output the one for which the value of $$$h_1$$$\nminimal\n. If there are several of them, output any of them.\nExample\nInput\n6\n11\n6\n10\n100000\n7\n8\nOutput\n4 5 2\n2 3 1\n4 5 1\n33334 33335 33331\n2 4 1\n3 4 1\nNote\nIn the first test case we can not get the height of the platform for the first place less than $$$5$$$, because if the height of the platform for the first place is not more than $$$4$$$, then we can use at most $$$4 + 3 + 2 = 9$$$ blocks. And we should use $$$11 = 4 + 5 + 2$$$ blocks. Therefore, the answer\n4 5 2\nfits.\nIn the second set, the only suitable answer is:\n2 3 1\n.", "input": [ [ [ "11" ] ], [ [ "6" ] ], [ [ "10" ] ], [ [ "100000" ] ], [ [ "7" ] ], [ [ "8" ] ] ], "output": [ "4 5 2", "2 3 1", "4 5 1", "33334 33335 33331", "2 4 1", "3 4 1" ] }, { "problem_id": "1689A", "problem_name": "Lex String\nbrute force, greedy, implementation, sortings, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1689/A", "problem_solution_link": "https://codeforces.com/problemset/status/1689/problem/A", "problem_statement": "A. Lex String\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nKuznecov likes art, poetry, and music. And strings consisting of lowercase English letters.\nRecently, Kuznecov has found two strings, $$$a$$$ and $$$b$$$, of lengths $$$n$$$ and $$$m$$$ respectively. They consist of lowercase English letters and\nno character is contained in both strings\n.\nLet another string $$$c$$$ be initially empty. Kuznecov can do the following two types of operations:\nChoose any character from the string $$$a$$$, remove it from $$$a$$$, and add it to the end of $$$c$$$.\nChoose any character from the string $$$b$$$, remove it from $$$b$$$, and add it to the end of $$$c$$$.\nBut, he can not do more than $$$k$$$ operations of the same type in a row. He must perform operations until either $$$a$$$ or $$$b$$$ becomes empty. What is the lexicographically smallest possible value of $$$c$$$ after he finishes?\nA string $$$x$$$ is lexicographically smaller than a string $$$y$$$ if and only if one of the following holds:\n$$$x$$$ is a prefix of $$$y$$$, but $$$x \\neq y$$$;\nin the first position where $$$x$$$ and $$$y$$$ differ, the string $$$x$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$y$$$.\nInput\nThere are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. This is followed by the test cases description.\nThe first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1\\leq n,m,k \\leq 100$$$)\u00a0\u2014 parameters from the statement.\nThe second line of each test case contains the string $$$a$$$ of length $$$n$$$.\nThe third line of each test case contains the string $$$b$$$ of length $$$m$$$.\nThe strings contain only lowercase English letters. It is guaranteed that no symbol appears in $$$a$$$ and $$$b$$$ simultaneously.\nOutput\nIn each test case, output a single string $$$c$$$\u00a0\u2014 the answer to the problem.\nExample\nInput\n3\n6 4 2\naaaaaa\nbbbb\n5 9 3\ncaaca\nbedededeb\n7 7 1\nnoskill\nwxhtzdy\nOutput\naabaabaa\naaabbcc\ndihktlwlxnyoz\nNote\nIn the first test case, it is optimal to take two '\na\n's from the string $$$a$$$ and add them to the string $$$c$$$. Then it is forbidden to take more characters from $$$a$$$, hence one character '\nb\n' from the string $$$b$$$ has to be taken. Following that logic, we end up with $$$c$$$ being '\naabaabaa\n' when string $$$a$$$ is emptied.\nIn the second test case it is optimal to take as many '\na\n's from string $$$a$$$ as possible, then take as many '\nb\n's as possible from string $$$b$$$. In the end, we take two '\nc\n's from the string $$$a$$$ emptying it.", "input": [ [ [ "6", "4", "2" ], [ "aaaaaa" ], [ "bbbb" ] ], [ [ "5", "9", "3" ], [ "caaca" ], [ "bedededeb" ] ], [ [ "7", "7", "1" ], [ "noskill" ], [ "wxhtzdy" ] ] ], "output": [ "aabaabaa", "aaabbcc", "dihktlwlxnyoz" ] }, { "problem_id": "1688B", "problem_name": "Patchouli's Magical Talisman\nbitmasks, constructive algorithms, greedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1688/B", "problem_solution_link": "https://codeforces.com/problemset/status/1688/problem/B", "problem_statement": "B. Patchouli's Magical Talisman\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nShe is skilled in all kinds of magics, and is keen on inventing new one.\n\u2014\nPerfect Memento in Strict Sense\nPatchouli is making a magical talisman. She initially has $$$n$$$ magical tokens. Their magical power can be represented with\npositive\nintegers $$$a_1, a_2, \\ldots, a_n$$$.\nPatchouli may perform the following two operations on the tokens.\nFusion:\nPatchouli chooses two tokens, removes them, and creates a new token with magical power equal to the sum of the two chosen tokens.\nReduction:\nPatchouli chooses a token with an\neven\nvalue of magical power $$$x$$$, removes it and creates a new token with magical power equal to $$$\\frac{x}{2}$$$.\nTokens are more effective when their magical powers are\nodd\nvalues. Please help Patchouli to find the minimum number of operations she needs to make magical powers of all tokens\nodd\nvalues.\nInput\nEach test contains multiple test cases.\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^3$$$) \u2014 the number of test cases. The description of the test cases follows.\nFor each test case, the first line contains one integer $$$n$$$ ($$$1 \\leq n\\leq 2\\cdot 10^5$$$) \u2014 the initial number of tokens.\nThe second line contains $$$n$$$ intergers $$$a_1,a_2,\\ldots,a_n$$$ ($$$1 \\leq a_i \\leq 10^9$$$) \u2014 the initial magical power of the $$$n$$$ tokens.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print a single integer \u2014 the minimum number of operations Patchouli needs to make all tokens have an\nodd\nvalue of magical power.\nIt can be shown that under such restrictions the required sequence of operations exists.\nExample\nInput\n4\n2\n1 9\n3\n1 1 2\n3\n2 4 8\n3\n1049600 33792 1280\nOutput\n0\n1\n3\n10\nNote\nTest case 1:\n$$$a$$$ consists solely of odd numbers initially.\nTest case 2:\nChoose the tokens with magical power of $$$1$$$ and $$$2$$$ and perform Fusion. Now $$$a=[1,3]$$$, both are odd numbers.\nTest case 3:\nChoose the tokens with magical power of $$$2$$$ and $$$8$$$ and perform Fusion. Now $$$a=[4,10]$$$.\nChoose the token with magical power of $$$10$$$ and perform Reduction. Now $$$a=[4,5]$$$.\nChoose the tokens with magical power of $$$4$$$ and $$$5$$$ and perform Fusion. Now $$$a=[9]$$$, and $$$9$$$ is an odd number.\nIt can be shown that you can not make all the magical powers\nodd\nnumbers in less than $$$3$$$ moves, so the answer is $$$3$$$.", "input": [ [ [ "2" ], [ "1", "9" ] ], [ [ "3" ], [ "1", "1", "2" ] ], [ [ "3" ], [ "2", "4", "8" ] ], [ [ "3" ], [ "1049600", "33792", "1280" ] ] ], "output": [ "0", "1", "3", "10" ] }, { "problem_id": "1688A", "problem_name": "Cirno's Perfect Bitmasks Classroom\nbitmasks, brute force", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1688/A", "problem_solution_link": "https://codeforces.com/problemset/status/1688/problem/A", "problem_statement": "A. Cirno's Perfect Bitmasks Classroom\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nEven if it's a really easy question, she won't be able to answer it\n\u2014\nPerfect Memento in Strict Sense\nCirno's perfect bitmasks classroom has just started!\nCirno gave her students a positive integer $$$x$$$. As an assignment, her students need to find the\nminimum positive\ninteger $$$y$$$, which satisfies the following two conditions:\n$$$$$$x\\ \\texttt{and}\\ y > 0$$$$$$ $$$$$$x\\ \\texttt{xor}\\ y > 0$$$$$$\nWhere $$$\\texttt{and}$$$ is the\nbitwise AND operation\n, and $$$\\texttt{xor}$$$ is the\nbitwise XOR operation\n.\nAmong the students was Mystia, who was truly baffled by all these new operators. Please help her!\nInput\nThe first line of input contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^3$$$) \u2014 the number of input test cases.\nFor each test case, the only line of input contains one integer $$$x$$$ ($$$1 \\leq x \\leq 2^{30}$$$).\nOutput\nFor each test case, print a single integer \u2014 the minimum number of $$$y$$$.\nExample\nInput\n7\n1\n2\n5\n9\n16\n114514\n1000000\nOutput\n3\n3\n1\n1\n17\n2\n64\nNote\nTest case 1:\n$$$1\\; \\texttt{and}\\; 3=1>0$$$, $$$1\\; \\texttt{xor}\\; 3=2>0$$$.\nTest case 2:\n$$$2\\; \\texttt{and}\\; 3=2>0$$$, $$$2\\; \\texttt{xor}\\; 3=1>0$$$.", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "5" ] ], [ [ "9" ] ], [ [ "16" ] ], [ [ "114514" ] ], [ [ "1000000" ] ] ], "output": [ "3", "3", "1", "1", "17", "2", "64" ] }, { "problem_id": "1686B", "problem_name": "Odd Subarrays\ndp, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1686/B", "problem_solution_link": "https://codeforces.com/problemset/status/1686/problem/B", "problem_statement": "B. Odd Subarrays\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nFor an array $$$[b_1, b_2, \\ldots, b_m]$$$ define its number of inversions as the number of pairs $$$(i, j)$$$ of integers such that $$$1 \\le i < j \\le m$$$ and $$$b_i>b_j$$$. Let's call array $$$b$$$\nodd\nif its number of inversions is odd.\nFor example, array $$$[4, 2, 7]$$$ is odd, as its number of inversions is $$$1$$$, while array $$$[2, 1, 4, 3]$$$ isn't, as its number of inversions is $$$2$$$.\nYou are given a permutation $$$[p_1, p_2, \\ldots, p_n]$$$ of integers from $$$1$$$ to $$$n$$$ (each of them appears exactly once in the permutation). You want to split it into several consecutive subarrays (maybe just one), so that the number of the\nodd\nsubarrays among them is as large as possible.\nWhat largest number of these subarrays may be\nodd\n?\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^5$$$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^5$$$) \u00a0\u2014 the size of the permutation.\nThe second line of each test case contains $$$n$$$ integers $$$p_1, p_2, \\ldots, p_n$$$ ($$$1 \\le p_i \\le n$$$, all $$$p_i$$$ are distinct) \u00a0\u2014 the elements of the permutation.\nThe sum of $$$n$$$ over all test cases doesn't exceed $$$2\\cdot 10^5$$$.\nOutput\nFor each test case output a single integer \u00a0\u2014 the largest possible number of\nodd\nsubarrays that you can get after splitting the permutation into several consecutive subarrays.\nExample\nInput\n5\n3\n1 2 3\n4\n4 3 2 1\n2\n1 2\n2\n2 1\n6\n4 5 6 1 2 3\nOutput\n0\n2\n0\n1\n1\nNote\nIn the first and third test cases, no matter how we split our permutation, there won't be any odd subarrays.\nIn the second test case, we can split our permutation into subarrays $$$[4, 3], [2, 1]$$$, both of which are odd since their numbers of inversions are $$$1$$$.\nIn the fourth test case, we can split our permutation into a single subarray $$$[2, 1]$$$, which is odd.\nIn the fifth test case, we can split our permutation into subarrays $$$[4, 5], [6, 1, 2, 3]$$$. The first subarray has $$$0$$$ inversions, and the second has $$$3$$$, so it is odd.", "input": [ [ [ "3" ], [ "1", "2", "3" ] ], [ [ "4" ], [ "4", "3", "2", "1" ] ], [ [ "2" ], [ "1", "2" ] ], [ [ "2" ], [ "2", "1" ] ], [ [ "6" ], [ "4", "5", "6", "1", "2", "3" ] ] ], "output": [ "0", "2", "0", "1", "1" ] }, { "problem_id": "1686A", "problem_name": "Everything Everywhere All But One\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1686/A", "problem_solution_link": "https://codeforces.com/problemset/status/1686/problem/A", "problem_statement": "A. Everything Everywhere All But One\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array of $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$. After you watched the amazing film \"Everything Everywhere All At Once\", you came up with the following operation.\nIn one operation, you choose $$$n-1$$$ elements of the array and replace each of them with their arithmetic mean (which doesn't have to be an integer). For example, from the array $$$[1, 2, 3, 1]$$$ we can get the array $$$[2, 2, 2, 1]$$$, if we choose the first three elements, or we can get the array $$$[\\frac{4}{3}, \\frac{4}{3}, 3, \\frac{4}{3}]$$$, if we choose all elements except the third.\nIs it possible to make all elements of the array equal by performing a finite number of such operations?\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 200$$$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$3 \\le n \\le 50$$$) \u00a0\u2014 the number of integers.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i \\le 100$$$).\nOutput\nFor each test case, if it is possible to make all elements equal after some number of operations, output $$$\\texttt{YES}$$$. Otherwise, output $$$\\texttt{NO}$$$.\nYou can output $$$\\texttt{YES}$$$ and $$$\\texttt{NO}$$$ in any case (for example, strings $$$\\texttt{yEs}$$$, $$$\\texttt{yes}$$$, $$$\\texttt{Yes}$$$ will be recognized as a positive response).\nExample\nInput\n4\n3\n42 42 42\n5\n1 2 3 4 5\n4\n4 3 2 1\n3\n24 2 22\nOutput\nYES\nYES\nNO\nNO\nNote\nIn the first test case, all elements are already equal.\nIn the second test case, you can choose all elements except the third, their average is $$$\\frac{1 + 2 + 4 + 5}{4} = 3$$$, so the array will become $$$[3, 3, 3, 3, 3]$$$.\nIt's possible to show that it's impossible to make all elements equal in the third and fourth test cases.", "input": [ [ [ "3" ], [ "42", "42", "42" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ] ], [ [ "4" ], [ "4", "3", "2", "1" ] ], [ [ "3" ], [ "24", "2", "22" ] ] ], "output": [ "YES", "YES", "NO", "NO" ] }, { "problem_id": "1684B", "problem_name": "Z mod X = C\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1684/B", "problem_solution_link": "https://codeforces.com/problemset/status/1684/problem/B", "problem_statement": "B. Z mod X = C\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given three positive integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$a < b < c$$$). You have to find three positive integers $$$x$$$, $$$y$$$, $$$z$$$ such that:\n$$$$$$x \\bmod y = a,$$$$$$ $$$$$$y \\bmod z = b,$$$$$$ $$$$$$z \\bmod x = c.$$$$$$\nHere $$$p \\bmod q$$$ denotes the remainder from dividing $$$p$$$ by $$$q$$$. It is possible to show that for such constraints the answer always exists.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10\\,000$$$)\u00a0\u2014 the number of test cases. Description of the test cases follows.\nEach test case contains a single line with three integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \\le a < b < c \\le 10^8$$$).\nOutput\nFor each test case output three positive integers $$$x$$$, $$$y$$$, $$$z$$$ ($$$1 \\le x, y, z \\le 10^{18}$$$) such that $$$x \\bmod y = a$$$, $$$y \\bmod z = b$$$, $$$z \\bmod x = c$$$.\nYou can output any correct answer.\nExample\nInput\n4\n1 3 4\n127 234 421\n2 7 8\n59 94 388\nOutput\n12 11 4\n1063 234 1484\n25 23 8\n2221 94 2609\nNote\nIn the first test case:\n$$$$$$x \\bmod y = 12 \\bmod 11 = 1;$$$$$$\n$$$$$$y \\bmod z = 11 \\bmod 4 = 3;$$$$$$\n$$$$$$z \\bmod x = 4 \\bmod 12 = 4.$$$$$$", "input": [ [ [ "1", "3", "4" ] ], [ [ "127", "234", "421" ] ], [ [ "2", "7", "8" ] ], [ [ "59", "94", "388" ] ] ], "output": [ "12 11 4", "1063 234 1484", "25 23 8", "2221 94 2609" ] }, { "problem_id": "1684A", "problem_name": "Digit Minimization\nconstructive algorithms, games, math, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1684/A", "problem_solution_link": "https://codeforces.com/problemset/status/1684/problem/A", "problem_statement": "A. Digit Minimization\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is an integer $$$n$$$\nwithout zeros\nin its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns.\nOn her turn, Alice\nmust\nswap any two digits of the integer that are on different positions. Bob on his turn always removes the last digit of the integer. The game ends when there is only one digit left.\nYou have to find the smallest integer Alice can get in the end, if she plays optimally.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. Description of the test cases follows.\nThe first and the only line of each test case contains the integer $$$n$$$ ($$$10 \\le n \\le 10^9$$$) \u2014 the integer for the game. $$$n$$$ does not have zeros in its decimal representation.\nOutput\nFor each test case output a single integer \u2014 the smallest integer Alice can get in the end of the game.\nExample\nInput\n3\n12\n132\n487456398\nOutput\n2\n1\n3\nNote\nIn the first test case Alice has to swap $$$1$$$ and $$$2$$$. After that Bob removes the last digit, $$$1$$$, so the answer is $$$2$$$.\nIn the second test case Alice can swap $$$3$$$ and $$$1$$$: $$$312$$$. After that Bob deletes the last digit: $$$31$$$. Then Alice swaps $$$3$$$ and $$$1$$$: $$$13$$$ and Bob deletes $$$3$$$, so the answer is $$$1$$$.", "input": [ [ [ "12" ] ], [ [ "132" ] ], [ [ "487456398" ] ] ], "output": [ "2", "1", "3" ] }, { "problem_id": "1682A", "problem_name": "Palindromic Indices\ngreedy, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1682/A", "problem_solution_link": "https://codeforces.com/problemset/status/1682/problem/A", "problem_statement": "A. Palindromic Indices\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a\npalindromic\nstring $$$s$$$ of length $$$n$$$.\nYou have to count the number of indices $$$i$$$ $$$(1 \\le i \\le n)$$$ such that the string after removing $$$s_i$$$ from $$$s$$$ still remains a palindrome.\nFor example, consider $$$s$$$ = \"\naba\n\"\nIf we remove $$$s_1$$$ from $$$s$$$, the string becomes \"\nba\n\" which is not a palindrome.\nIf we remove $$$s_2$$$ from $$$s$$$, the string becomes \"\naa\n\" which is a palindrome.\nIf we remove $$$s_3$$$ from $$$s$$$, the string becomes \"\nab\n\" which is not a palindrome.\nA palindrome is a string that reads the same backward as forward. For example, \"\nabba\n\", \"\na\n\", \"\nfef\n\" are palindromes whereas \"\ncodeforces\n\", \"\nacd\n\", \"\nxy\n\" are not.\nInput\nThe input consists of multiple test cases. The first line of the input contains a single integer $$$t$$$ $$$(1 \\leq t \\leq 10^3)$$$ \u00a0\u2014 the number of test cases. Description of the test cases follows.\nThe first line of each testcase contains a single integer $$$n$$$ $$$(2 \\leq n \\leq 10^5)$$$ \u00a0\u2014 the length of string $$$s$$$.\nThe second line of each test case contains a string $$$s$$$ consisting of lowercase English letters.\nIt is guaranteed that $$$s$$$ is a palindrome\n.\nIt is guaranteed that sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, output a single integer \u00a0\u2014 the number of indices $$$i$$$ $$$(1 \\le i \\le n)$$$ such that the string after removing $$$s_i$$$ from $$$s$$$ still remains a palindrome.\nExample\nInput\n3\n3\naba\n8\nacaaaaca\n2\ndd\nOutput\n1\n4\n2\nNote\nThe first test case is described in the statement.\nIn the second test case, the indices $$$i$$$ that result in palindrome after removing $$$s_i$$$ are $$$3, 4, 5, 6$$$. Hence the answer is $$$4$$$.\nIn the third test case, removal of any of the indices results in \"\nd\n\" which is a palindrome. Hence the answer is $$$2$$$.", "input": [ [ [ "3" ], [ "aba" ] ], [ [ "8" ], [ "acaaaaca" ] ], [ [ "2" ], [ "dd" ] ] ], "output": [ "1", "4", "2" ] }, { "problem_id": "1681B", "problem_name": "Card Trick\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1681/B", "problem_solution_link": "https://codeforces.com/problemset/status/1681/problem/B", "problem_statement": "B. Card Trick\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMonocarp has just learned a new card trick, and can't wait to present it to you. He shows you the entire deck of $$$n$$$ cards. You see that the values of cards from the topmost to the bottommost are integers $$$a_1, a_2, \\dots, a_n$$$, and all values are different.\nThen he asks you to shuffle the deck $$$m$$$ times. With the $$$j$$$-th shuffle, you should take $$$b_j$$$ topmost cards and move them under the remaining $$$(n - b_j)$$$ cards without changing the order.\nAnd then, using some magic, Monocarp tells you the topmost card of the deck. However, you are not really buying that magic. You tell him that you know the topmost card yourself. Can you surprise Monocarp and tell him the topmost card before he shows it?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of testcases.\nThe first line of each testcase contains a single integer $$$n$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$)\u00a0\u2014 the number of cards in the deck.\nThe second line contains $$$n$$$ pairwise distinct integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le n$$$)\u00a0\u2014 the values of the cards.\nThe third line contains a single integer $$$m$$$ ($$$1 \\le m \\le 2 \\cdot 10^5$$$)\u00a0\u2014 the number of shuffles.\nThe fourth line contains $$$m$$$ integers $$$b_1, b_2, \\dots, b_m$$$ ($$$1 \\le b_j \\le n - 1$$$)\u00a0\u2014 the amount of cards that are moved on the $$$j$$$-th shuffle.\nThe sum of $$$n$$$ over all testcases doesn't exceed $$$2 \\cdot 10^5$$$. The sum of $$$m$$$ over all testcases doesn't exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each testcase, print a single integer\u00a0\u2014 the value of the card on the top of the deck after the deck is shuffled $$$m$$$ times.\nExample\nInput\n3\n2\n1 2\n3\n1 1 1\n4\n3 1 4 2\n2\n3 1\n5\n2 1 5 4 3\n5\n3 2 1 2 1\nOutput\n2\n3\n3\nNote\nIn the first testcase, each shuffle effectively swaps two cards. After three swaps, the deck will be $$$[2, 1]$$$.\nIn the second testcase, the second shuffle cancels what the first shuffle did. First, three topmost cards went underneath the last card, then that card went back below the remaining three cards. So the deck remained unchanged from the initial one\u00a0\u2014 the topmost card has value $$$3$$$.", "input": [ [ [ "2" ], [ "1", "2" ], [ "3" ], [ "1", "1", "1" ] ], [ [ "4" ], [ "3", "1", "4", "2" ], [ "2" ], [ "3", "1" ] ], [ [ "5" ], [ "2", "1", "5", "4", "3" ], [ "5" ], [ "3", "2", "1", "2", "1" ] ] ], "output": [ "2", "3", "3" ] }, { "problem_id": "1681A", "problem_name": "Game with Cards\ngames, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1681/A", "problem_solution_link": "https://codeforces.com/problemset/status/1681/problem/A", "problem_statement": "A. Game with Cards\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAlice and Bob play a game. Alice has $$$n$$$ cards, the $$$i$$$-th of them has the integer $$$a_i$$$ written on it. Bob has $$$m$$$ cards, the $$$j$$$-th of them has the integer $$$b_j$$$ written on it.\nOn the first turn of the game,\nthe first player\nchooses one of his/her cards and puts it on the table (plays it). On the second turn,\nthe second player\nchooses one of his/her cards\nsuch that the integer on it is greater than the integer on the card played on the first turn\n, and plays it. On the third turn,\nthe first player\nchooses one of his/her cards\nsuch that the integer on it is greater than the integer on the card played on the second turn\n, and plays it, and so on \u2014 the players take turns, and each player has to choose one of his/her cards with greater integer than the card played by the other player on the last turn.\nIf some player cannot make a turn, he/she loses.\nFor example, if Alice has $$$4$$$ cards with numbers $$$[10, 5, 3, 8]$$$, and Bob has $$$3$$$ cards with numbers $$$[6, 11, 6]$$$, the game may go as follows:\nAlice can choose any of her cards. She chooses the card with integer $$$5$$$ and plays it.\nBob can choose any of his cards with number greater than $$$5$$$. He chooses a card with integer $$$6$$$ and plays it.\nAlice can choose any of her cards with number greater than $$$6$$$. She chooses the card with integer $$$10$$$ and plays it.\nBob can choose any of his cards with number greater than $$$10$$$. He chooses a card with integer $$$11$$$ and plays it.\nAlice can choose any of her cards with number greater than $$$11$$$, but she has no such cards, so she loses.\nBoth Alice and Bob play\noptimally (if a player is able to win the game no matter how the other player plays, the former player will definitely win the game)\n.\nYou have to answer two questions:\nwho wins if Alice is the first player?\nwho wins if Bob is the first player?\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases. Each test case consists of four lines.\nThe first line of a test case contains one integer $$$n$$$ ($$$1 \\le n \\le 50$$$) \u2014 the number of cards Alice has.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 50$$$) \u2014 the numbers written on the cards that Alice has.\nThe third line contains one integer $$$m$$$ ($$$1 \\le m \\le 50$$$) \u2014 the number of Bob's cards.\nThe fourth line contains $$$m$$$ integers $$$b_1, b_2, \\dots, b_m$$$ ($$$1 \\le b_i \\le 50$$$) \u2014 the numbers on Bob's cards.\nOutput\nFor each test case, print two lines. The first line should be\nAlice\nif Alice wins when she is the first player; otherwise, the first line should be\nBob\n. The second line should contain the name of the winner if Bob is the first player, in the same format.\nExample\nInput\n4\n1\n6\n2\n6 8\n4\n1 3 3 7\n2\n4 2\n1\n50\n2\n25 50\n10\n1 2 3 4 5 6 7 8 9 10\n2\n5 15\nOutput\nBob\nBob\nAlice\nAlice\nAlice\nBob\nBob\nBob\nNote\nLet's consider the first test case of the example.\nAlice has one card with integer $$$6$$$, Bob has two cards with numbers $$$[6, 8]$$$.\nIf Alice is the first player, she has to play the card with number $$$6$$$. Bob then has to play the card with number $$$8$$$. Alice has no cards left, so she loses.\nIf Bob is the first player, then no matter which of his cards he chooses on the first turn, Alice won't be able to play her card on the second turn, so she will lose.", "input": [ [ [ "1" ], [ "6" ], [ "2" ], [ "6", "8" ] ], [ [ "4" ], [ "1", "3", "3", "7" ], [ "2" ], [ "4", "2" ] ], [ [ "1" ], [ "50" ], [ "2" ], [ "25", "50" ] ], [ [ "10" ], [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ], [ "2" ], [ "5", "15" ] ] ], "output": [ ["Bob", "Bob"], ["Alice", "Alice"], ["Alice", "Bob"], ["Bob", "Bob"] ], "error": true }, { "problem_id": "1680B", "problem_name": "Robots\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1680/B", "problem_solution_link": "https://codeforces.com/problemset/status/1680/problem/B", "problem_statement": "B. Robots\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a field divided into $$$n$$$ rows and $$$m$$$ columns. Some cells are empty (denoted as\nE\n), other cells contain robots (denoted as\nR\n).\nYou can send a command to\nall robots\nat the same time. The command can be of one of the four types:\nmove up;\nmove right;\nmove down;\nmove left.\nWhen you send a command,\nall robots at the same time\nattempt to take one step in the direction you picked. If a robot tries to move outside the field, it explodes; otherwise,\nevery robot\nmoves to an adjacent cell in the chosen direction.\nYou can send as many commands as you want (possibly, zero), in any order. Your goal is to make at least one robot reach the upper left corner of the field. Can you do this without forcing any of the robots to explode?\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 5000$$$)\u00a0\u2014 the number of test cases.\nEach test case starts with a line containing two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 5$$$)\u00a0\u2014 the number of rows and the number of columns, respectively. Then $$$n$$$ lines follow; each of them contains a string of $$$m$$$ characters. Each character is either\nE\n(empty cell} or\nR\n(robot).\nAdditional constraint on the input: in each test case, there is at least one robot on the field.\nOutput\nIf it is possible to make at least one robot reach the upper left corner of the field so that no robot explodes, print\nYES\n. Otherwise, print\nNO\n.\nExample\nInput\n6\n1 3\nERR\n2 2\nER\nRE\n2 2\nER\nER\n1 1\nR\n4 3\nEEE\nEEE\nERR\nEER\n3 3\nEEE\nEER\nREE\nOutput\nYES\nNO\nYES\nYES\nYES\nNO\nNote\nExplanations for test cases of the example:\nin the first test case, it is enough to send a command to move left.\nin the second test case, if you try to send any command, at least one robot explodes.\nin the third test case, it is enough to send a command to move left.\nin the fourth test case, there is already a robot in the upper left corner.\nin the fifth test case, the sequence \"move up, move left, move up\" leads one robot to the upper left corner;\nin the sixth test case, if you try to move any robot to the upper left corner, at least one other robot explodes.", "input": [ [ [ "4", "3" ], [ "EEE", "EEE", "ERR", "EER" ] ] ], "output": [ "YES" ] }, { "problem_id": "1680A", "problem_name": "Minimums and Maximums\nbrute force, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1680/A", "problem_solution_link": "https://codeforces.com/problemset/status/1680/problem/A", "problem_statement": "A. Minimums and Maximums\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nAn array is\nbeautiful\nif both of the following two conditions meet:\nthere are\nat least\n$$$l_1$$$ and\nat most\n$$$r_1$$$ elements in the array equal to its minimum;\nthere are\nat least\n$$$l_2$$$ and\nat most\n$$$r_2$$$ elements in the array equal to its maximum.\nFor example, the array $$$[2, 3, 2, 4, 4, 3, 2]$$$ has $$$3$$$ elements equal to its minimum ($$$1$$$-st, $$$3$$$-rd and $$$7$$$-th) and $$$2$$$ elements equal to its maximum ($$$4$$$-th and $$$5$$$-th).\nAnother example: the array $$$[42, 42, 42]$$$ has $$$3$$$ elements equal to its minimum and $$$3$$$ elements equal to its maximum.\nYour task is to calculate the\nminimum\npossible number of elements in a\nbeautiful\narray.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 5000$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of one line containing four integers $$$l_1$$$, $$$r_1$$$, $$$l_2$$$ and $$$r_2$$$ ($$$1 \\le l_1 \\le r_1 \\le 50$$$; $$$1 \\le l_2 \\le r_2 \\le 50$$$).\nOutput\nFor each test case, print one integer\u00a0\u2014 the minimum possible number of elements in a beautiful array.\nExample\nInput\n7\n3 5 4 6\n5 8 5 5\n3 3 10 12\n1 5 3 3\n1 1 2 2\n2 2 1 1\n6 6 6 6\nOutput\n4\n5\n13\n3\n3\n3\n6\nNote\nOptimal arrays in the test cases of the example:\n$$$[1, 1, 1, 1]$$$, it has $$$4$$$ minimums and $$$4$$$ maximums;\n$$$[4, 4, 4, 4, 4]$$$, it has $$$5$$$ minimums and $$$5$$$ maximums;\n$$$[1, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2]$$$, it has $$$3$$$ minimums and $$$10$$$ maximums;\n$$$[8, 8, 8]$$$, it has $$$3$$$ minimums and $$$3$$$ maximums;\n$$$[4, 6, 6]$$$, it has $$$1$$$ minimum and $$$2$$$ maximums;\n$$$[3, 4, 3]$$$, it has $$$2$$$ minimums and $$$1$$$ maximum;\n$$$[5, 5, 5, 5, 5, 5]$$$, it has $$$6$$$ minimums and $$$6$$$ maximums.", "input": [ [ [ "3", "5", "4", "6" ] ], [ [ "5", "8", "5", "5" ] ], [ [ "3", "3", "10", "12" ] ], [ [ "1", "5", "3", "3" ] ], [ [ "1", "1", "2", "2" ] ], [ [ "2", "2", "1", "1" ] ], [ [ "6", "6", "6", "6" ] ] ], "output": [ "4", "5", "13", "3", "3", "3", "6" ] }, { "problem_id": "1678B1", "problem_name": "Tokitsukaze and Good 01-String (easy version)\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1678/B1", "problem_solution_link": "https://codeforces.com/problemset/status/1678/problem/B1", "problem_statement": "B1. Tokitsukaze and Good 01-String (easy version)\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThis is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.\nTokitsukaze has a binary string $$$s$$$ of length $$$n$$$, consisting only of zeros and ones, $$$n$$$ is\neven\n.\nNow Tokitsukaze divides $$$s$$$ into\nthe minimum number\nof\ncontiguous\nsubsegments, and for each subsegment, all bits in each subsegment are the same. After that, $$$s$$$ is considered good if the lengths of all subsegments are even.\nFor example, if $$$s$$$ is \"\n11001111\n\", it will be divided into \"\n11\n\", \"\n00\n\" and \"\n1111\n\". Their lengths are $$$2$$$, $$$2$$$, $$$4$$$ respectively, which are all even numbers, so \"\n11001111\n\" is good. Another example, if $$$s$$$ is \"\n1110011000\n\", it will be divided into \"\n111\n\", \"\n00\n\", \"\n11\n\" and \"\n000\n\", and their lengths are $$$3$$$, $$$2$$$, $$$2$$$, $$$3$$$. Obviously, \"\n1110011000\n\" is not good.\nTokitsukaze wants to make $$$s$$$ good by changing the values of some positions in $$$s$$$. Specifically, she can perform the operation any number of times: change the value of $$$s_i$$$ to '\n0\n' or '\n1\n'($$$1 \\leq i \\leq n$$$). Can you tell her the minimum number of operations to make $$$s$$$ good?\nInput\nThe first contains a single positive integer $$$t$$$ ($$$1 \\leq t \\leq 10\\,000$$$)\u00a0\u2014 the number of test cases.\nFor each test case, the first line contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 2 \\cdot 10^5$$$)\u00a0\u2014 the length of $$$s$$$, it is guaranteed that $$$n$$$ is even.\nThe second line contains a binary string $$$s$$$ of length $$$n$$$, consisting only of zeros and ones.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print a single line with one integer\u00a0\u2014 the minimum number of operations to make $$$s$$$ good.\nExample\nInput\n5\n10\n1110011000\n8\n11001111\n2\n00\n2\n11\n6\n100110\nOutput\n3\n0\n0\n0\n3\nNote\nIn the first test case, one of the ways to make $$$s$$$ good is the following.\nChange $$$s_3$$$, $$$s_6$$$ and $$$s_7$$$ to '\n0\n', after that $$$s$$$ becomes \"\n1100000000\n\", it can be divided into \"\n11\n\" and \"\n00000000\n\", which lengths are $$$2$$$ and $$$8$$$ respectively. There are other ways to operate $$$3$$$ times to make $$$s$$$ good, such as \"\n1111110000\n\", \"\n1100001100\n\", \"\n1111001100\n\".\nIn the second, third and fourth test cases, $$$s$$$ is good initially, so no operation is required.", "input": [ [ [ "10" ], [ "1110011000" ] ], [ [ "8" ], [ "11001111" ] ], [ [ "2" ], [ "00" ] ], [ [ "2" ], [ "11" ] ], [ [ "6" ], [ "100110" ] ] ], "output": [ "3", "0", "0", "0", "3" ] }, { "problem_id": "1678A", "problem_name": "Tokitsukaze and All Zero Sequence\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1678/A", "problem_solution_link": "https://codeforces.com/problemset/status/1678/problem/A", "problem_statement": "A. Tokitsukaze and All Zero Sequence\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \\ne j$$$; $$$1 \\leq i,j \\leq n$$$).\nIf $$$a_i = a_j$$$, change one of them to $$$0$$$.\nOtherwise change both of them to $$$\\min(a_i, a_j)$$$.\nTokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.\nInput\nThe first line contains a single positive integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nFor each test case, the first line contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$)\u00a0\u2014 the length of the sequence $$$a$$$.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\leq a_i \\leq 100$$$)\u00a0\u2014 the sequence $$$a$$$.\nOutput\nFor each test case, print a single integer\u00a0\u2014 the minimum number of operations to change all numbers in the sequence to $$$0$$$.\nExample\nInput\n3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0\nOutput\n4\n3\n2\nNote\nIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:\nIn the $$$1$$$-st operation, $$$a_1 < a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.\nIn the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.\nIn the $$$3$$$-rd operation, $$$a_1 < a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.\nIn the $$$4$$$-th operation, $$$a_2 < a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.\nSo the minimum number of operations is $$$4$$$.", "input": [ [ [ "3" ], [ "1", "2", "3" ] ], [ [ "3" ], [ "1", "2", "2" ] ], [ [ "3" ], [ "1", "2", "0" ] ] ], "output": [ "4", "3", "2" ] }, { "problem_id": "1676C", "problem_name": "Most Similar Words\nbrute force, greedy, implementation, implementation, math, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1676/C", "problem_solution_link": "https://codeforces.com/problemset/status/1676/problem/C", "problem_statement": "C. Most Similar Words\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given $$$n$$$ words of\nequal\nlength $$$m$$$, consisting of lowercase Latin alphabet letters. The $$$i$$$-th word is denoted $$$s_i$$$.\nIn one move you can choose\nany position in any single word\nand change the letter at that position to the previous or next letter in alphabetical order. For example:\nyou can change '\ne\n' to '\nd\n' or to '\nf\n';\n'\na\n' can only be changed to '\nb\n';\n'\nz\n' can only be changed to '\ny\n'.\nThe\ndifference\nbetween two words is the\nminimum\nnumber of moves required to make them equal. For example, the\ndifference\nbetween \"\nbest\n\" and \"\ncost\n\" is $$$1 + 10 + 0 + 0 = 11$$$.\nFind the minimum\ndifference\nof $$$s_i$$$ and $$$s_j$$$ such that $$$(i < j)$$$. In other words, find the minimum\ndifference\nover all possible pairs of the $$$n$$$ words.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases. The description of test cases follows.\nThe first line of each test case contains $$$2$$$ integers $$$n$$$ and $$$m$$$ ($$$2 \\leq n \\leq 50$$$, $$$1 \\leq m \\leq 8$$$) \u2014 the number of strings and their length respectively.\nThen follows $$$n$$$ lines, the $$$i$$$-th of which containing a single string $$$s_i$$$ of length $$$m$$$, consisting of lowercase Latin letters.\nOutput\nFor each test case, print a single integer \u2014 the minimum\ndifference\nover all possible pairs of the given strings.\nExample\nInput\n6\n2 4\nbest\ncost\n6 3\nabb\nzba\nbef\ncdu\nooo\nzzz\n2 7\naaabbbc\nbbaezfe\n3 2\nab\nab\nab\n2 8\naaaaaaaa\nzzzzzzzz\n3 1\na\nu\ny\nOutput\n11\n8\n35\n0\n200\n4\nNote\nFor the second test case, one can show that the best pair is (\"\nabb\n\",\"\nbef\n\"), which has\ndifference\nequal to $$$8$$$, which can be obtained in the following way: change the first character of the first string to '\nb\n' in one move, change the second character of the second string to '\nb\n' in $$$3$$$ moves and change the third character of the second string to '\nb\n' in $$$4$$$ moves, thus making in total $$$1 + 3 + 4 = 8$$$ moves.\nFor the third test case, there is only one possible pair and it can be shown that the minimum amount of moves necessary to make the strings equal is $$$35$$$.\nFor the fourth test case, there is a pair of strings which is already equal, so the answer is $$$0$$$.", "input": [ [ [ "2", "4" ], [ "best" ], [ "cost" ], [ "6", "3" ] ], [ [ "abb" ], [ "zba" ], [ "bef" ], [ "cdu" ] ], [ [ "ooo" ], [ "zzz" ], [ "2", "7" ], [ "aaabbbc" ] ], [ [ "bbaezfe" ], [ "3", "2" ], [ "ab" ], [ "ab" ] ], [ [ "ab" ], [ "2", "8" ], [ "aaaaaaaa" ], [ "zzzzzzzz" ] ], [ [ "3", "1" ], [ "a" ], [ "u" ], [ "y" ] ] ], "output": [ "11", "8", "35", "0", "200", "4" ] }, { "problem_id": "1676B", "problem_name": "Equal Candies\ngreedy, math, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1676/B", "problem_solution_link": "https://codeforces.com/problemset/status/1676/problem/B", "problem_statement": "B. Equal Candies\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ boxes with different quantities of candies in each of them. The $$$i$$$-th box has $$$a_i$$$ candies inside.\nYou also have $$$n$$$ friends that you want to give the candies to, so you decided to give each friend a box of candies. But, you don't want any friends to get upset so you decided to eat some (possibly none) candies from each box so that all boxes have the same quantity of candies in them. Note that you may eat a different number of candies from different boxes and you cannot add candies to any of the boxes.\nWhat's the minimum total number of candies you have to eat to satisfy the requirements?\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 50$$$)\u00a0\u2014 the number of boxes you have.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\leq a_i \\leq 10^7$$$)\u00a0\u2014 the quantity of candies in each box.\nOutput\nFor each test case, print a single integer denoting the minimum number of candies you have to eat to satisfy the requirements.\nExample\nInput\n5\n5\n1 2 3 4 5\n6\n1000 1000 5 1000 1000 1000\n10\n1 2 3 5 1 2 7 9 13 5\n3\n8 8 8\n1\n10000000\nOutput\n10\n4975\n38\n0\n0\nNote\nFor the first test case, you can eat $$$1$$$ candy from the second box, $$$2$$$ candies from the third box, $$$3$$$ candies from the fourth box and $$$4$$$ candies from the fifth box. Now the boxes have $$$[1, 1, 1, 1, 1]$$$ candies in them and you ate $$$0 + 1 + 2 + 3 + 4 = 10$$$ candies in total so the answer is $$$10$$$.\nFor the second test case, the best answer is obtained by making all boxes contain $$$5$$$ candies in them, thus eating $$$995 + 995 + 0 + 995 + 995 + 995 = 4975$$$ candies in total.", "input": [ [ [ "5" ], [ "1", "2", "3", "4", "5" ] ], [ [ "6" ], [ "1000", "1000", "5", "1000", "1000", "1000" ] ], [ [ "10" ], [ "1", "2", "3", "5", "1", "2", "7", "9", "13", "5" ] ], [ [ "3" ], [ "8", "8", "8" ] ], [ [ "1" ], [ "10000000" ] ] ], "output": [ "10", "4975", "38", "0", "0" ] }, { "problem_id": "1676A", "problem_name": "Lucky?\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1676/A", "problem_solution_link": "https://codeforces.com/problemset/status/1676/problem/A", "problem_statement": "A. Lucky?\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading zeroes.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\leq t \\leq 10^3$$$)\u00a0\u2014 the number of testcases.\nThe description of each test consists of one line containing one string consisting of six digits.\nOutput\nOutput $$$t$$$ lines, each of which contains the answer to the corresponding test case. Output \"\nYES\n\" if the given ticket is lucky, and \"\nNO\n\" otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n5\n213132\n973894\n045207\n000000\n055776\nOutput\nYES\nNO\nYES\nYES\nNO\nNote\nIn the first test case, the sum of the first three digits is $$$2 + 1 + 3 = 6$$$ and the sum of the last three digits is $$$1 + 3 + 2 = 6$$$, they are equal so the answer is \"\nYES\n\".\nIn the second test case, the sum of the first three digits is $$$9 + 7 + 3 = 19$$$ and the sum of the last three digits is $$$8 + 9 + 4 = 21$$$, they are not equal so the answer is \"\nNO\n\".\nIn the third test case, the sum of the first three digits is $$$0 + 4 + 5 = 9$$$ and the sum of the last three digits is $$$2 + 0 + 7 = 9$$$, they are equal so the answer is \"\nYES\n\".", "input": [ [ [ "213132" ] ], [ [ "973894" ] ], [ [ "045207" ] ], [ [ "000000" ] ], [ [ "055776" ] ] ], "output": [ "YES", "NO", "YES", "YES", "NO" ] }, { "problem_id": "1675A", "problem_name": "Food for Animals\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1675/A", "problem_solution_link": "https://codeforces.com/problemset/status/1675/problem/A", "problem_statement": "A. Food for Animals\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIn the pet store on sale there are:\n$$$a$$$ packs of dog food;\n$$$b$$$ packs of cat food;\n$$$c$$$ packs of universal food (such food is suitable for both dogs and cats).\nPolycarp has $$$x$$$ dogs and $$$y$$$ cats. Is it possible that he will be able to buy food for all his animals in the store? Each of his dogs and each of his cats should receive one pack of suitable food for it.\nInput\nThe first line of input contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases in the input.\nThen $$$t$$$ lines are given, each containing a description of one test case. Each description consists of five integers $$$a, b, c, x$$$ and $$$y$$$ ($$$0 \\le a,b,c,x,y \\le 10^8$$$).\nOutput\nFor each test case in a separate line, output:\nYES\n, if suitable food can be bought for each of $$$x$$$ dogs and for each of $$$y$$$ cats;\nNO\nelse.\nYou can output\nYES\nand\nNO\nin any case (for example, strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as a positive response).\nExample\nInput\n7\n1 1 4 2 3\n0 0 0 0 0\n5 5 0 4 6\n1 1 1 1 1\n50000000 50000000 100000000 100000000 100000000\n0 0 0 100000000 100000000\n1 3 2 2 5\nOutput\nYES\nYES\nNO\nYES\nYES\nNO\nNO", "input": [ [ [ "1", "1", "4", "2", "3" ] ], [ [ "0", "0", "0", "0", "0" ] ], [ [ "5", "5", "0", "4", "6" ] ], [ [ "1", "1", "1", "1", "1" ] ], [ [ "50000000", "50000000", "100000000", "100000000", "100000000" ] ], [ [ "0", "0", "0", "100000000", "100000000" ] ], [ [ "1", "3", "2", "2", "5" ] ] ], "output": [ "YES", "YES", "NO", "YES", "YES", "NO", "NO" ] }, { "problem_id": "1674B", "problem_name": "Dictionary\ncombinatorics, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1674/B", "problem_solution_link": "https://codeforces.com/problemset/status/1674/problem/B", "problem_statement": "B. Dictionary\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nThe Berland language consists of words having\nexactly two letters\n. Moreover,\nthe first letter of a word is different from the second letter\n. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.\nThe Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold:\nthe first letter of $$$a$$$ is less than the first letter of $$$b$$$;\nthe first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$.\nSo, the dictionary looks like that:\nWord $$$1$$$:\nab\nWord $$$2$$$:\nac\n...\nWord $$$25$$$:\naz\nWord $$$26$$$:\nba\nWord $$$27$$$:\nbc\n...\nWord $$$649$$$:\nzx\nWord $$$650$$$:\nzy\nYou are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 650$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of one line containing $$$s$$$\u00a0\u2014 a string consisting of\nexactly two different lowercase Latin letters\n(i.\u2009e. a correct word of the Berland language).\nOutput\nFor each test case, print one integer\u00a0\u2014 the index of the word $$$s$$$ in the dictionary.\nExample\nInput\n7\nab\nac\naz\nba\nbc\nzx\nzy\nOutput\n1\n2\n25\n26\n27\n649\n650", "input": [ [ [ "ab" ] ], [ [ "ac" ] ], [ [ "az" ] ], [ [ "ba" ] ], [ [ "bc" ] ], [ [ "zx" ] ], [ [ "zy" ] ] ], "output": [ "1", "2", "25", "26", "27", "649", "650" ] }, { "problem_id": "1674A", "problem_name": "Number Transformation\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1674/A", "problem_solution_link": "https://codeforces.com/problemset/status/1674/problem/A", "problem_statement": "A. Number Transformation\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two integers $$$x$$$ and $$$y$$$. You want to choose two\nstrictly positive\n(greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$\nexactly\n$$$a$$$ times: replace $$$x$$$ with $$$b \\cdot x$$$.\nYou want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose\nany of them\n. If there is no such pair, report it.\nFor example:\nif $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \\cdot 5 \\cdot 5 = 75$$$;\nif $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \\cdot 1 \\cdot 1 \\cdot 1 = 100$$$;\nif $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases.\nEach test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \\le x, y \\le 100$$$).\nOutput\nIf it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers.\nThe integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$\n(it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them.\nIf it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.\nExample\nInput\n3\n3 75\n100 100\n42 13\nOutput\n2 5\n3 1\n0 0", "input": [ [ [ "3", "75" ] ], [ [ "100", "100" ] ], [ [ "42", "13" ] ] ], "output": [ "2 5", "3 1", "0 0" ] }, { "problem_id": "1673A", "problem_name": "Subtle Substring Subtraction\ngames, greedy, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1673/A", "problem_solution_link": "https://codeforces.com/problemset/status/1673/problem/A", "problem_statement": "A. Subtle Substring Subtraction\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAlice and Bob are playing a game with strings. There will be $$$t$$$ rounds in the game. In each round, there will be a string $$$s$$$ consisting of lowercase English letters.\nAlice moves first and both the players take alternate turns.\nAlice is allowed to remove any substring of even length (possibly empty) and Bob is allowed to remove any substring of odd length from $$$s$$$\n.\nMore formally, if there was a string $$$s = s_1s_2 \\ldots s_k$$$ the player can choose a substring $$$s_ls_{l+1} \\ldots s_{r-1}s_r$$$ with length of corresponding parity and remove it. After that the string will become $$$s = s_1 \\ldots s_{l-1}s_{r+1} \\ldots s_k$$$.\nAfter the string becomes empty, the round ends and each player calculates his/her score for this round. The score of a player is the sum of values of all characters removed by him/her. The value of $$$\\texttt{a}$$$ is $$$1$$$, the value of $$$\\texttt{b}$$$ is $$$2$$$, the value of $$$\\texttt{c}$$$ is $$$3$$$, $$$\\ldots$$$, and the value of $$$\\texttt{z}$$$ is $$$26$$$. The player with higher score wins the round. For each round, determine the winner and the difference between winner's and loser's scores. Assume that both players play optimally to maximize their score. It can be proved that a draw is impossible.\nInput\nThe first line of input contains a single integer $$$t$$$ ($$$1\\leq t\\leq 5\\cdot 10^4$$$) denoting the number of rounds.\nEach of the next $$$t$$$ lines contain a single string $$$s$$$ ($$$1\\leq |s|\\leq 2\\cdot 10^5$$$) consisting of lowercase English letters, denoting the string used for the round. Here $$$|s|$$$ denotes the length of the string $$$s$$$.\nIt is guaranteed that the sum of $$$|s|$$$ over all rounds does not exceed $$$2\\cdot 10^5$$$.\nOutput\nFor each round, print a single line containing a string and an integer. If Alice wins the round, the string must be \"\nAlice\n\". If Bob wins the round, the string must be \"\nBob\n\". The integer must be the difference between their scores assuming both players play optimally.\nExample\nInput\n5\naba\nabc\ncba\nn\ncodeforces\nOutput\nAlice 2\nAlice 4\nAlice 4\nBob 14\nAlice 93\nNote\nFor the first round, $$$\\texttt{\"aba\"}\\xrightarrow{\\texttt{Alice}}\\texttt{\"}{\\color{red}{\\texttt{ab}}}\\texttt{a\"}\\xrightarrow{} \\texttt{\"a\"}\\xrightarrow{\\texttt{Bob}}\\texttt{\"}{\\color{red}{\\texttt{a}}}\\texttt{\"}\\xrightarrow{}\\texttt{\"\"}$$$. Alice's total score is $$$1+2=3$$$. Bob's total score is $$$1$$$.\nFor the second round, $$$\\texttt{\"abc\"}\\xrightarrow{\\texttt{Alice}}\\texttt{\"a}{\\color{red}{\\texttt{bc}}}\\texttt{\"}\\xrightarrow{} \\texttt{\"a\"}\\xrightarrow{\\texttt{Bob}}\\texttt{\"}{\\color{red}{\\texttt{a}}}\\texttt{\"}\\xrightarrow{}\\texttt{\"\"}$$$. Alice's total score is $$$2+3=5$$$. Bob's total score is $$$1$$$.\nFor the third round, $$$\\texttt{\"cba\"}\\xrightarrow{\\texttt{Alice}}\\texttt{\"}{\\color{red}{\\texttt{cb}}}\\texttt{a\"}\\xrightarrow{} \\texttt{\"a\"}\\xrightarrow{\\texttt{Bob}}\\texttt{\"}{\\color{red}{\\texttt{a}}}\\texttt{\"}\\xrightarrow{}\\texttt{\"\"}$$$. Alice's total score is $$$3+2=5$$$. Bob's total score is $$$1$$$.\nFor the fourth round, $$$\\texttt{\"n\"}\\xrightarrow{\\texttt{Alice}}\\texttt{\"n\"}\\xrightarrow{} \\texttt{\"n\"}\\xrightarrow{\\texttt{Bob}}\\texttt{\"}{\\color{red}{\\texttt{n}}}\\texttt{\"}\\xrightarrow{}\\texttt{\"\"}$$$. Alice's total score is $$$0$$$. Bob's total score is $$$14$$$.\nFor the fifth round, $$$\\texttt{\"codeforces\"}\\xrightarrow{\\texttt{Alice}}\\texttt{\"}{\\color{red}{\\texttt{codeforces}}}\\texttt{\"}\\xrightarrow{} \\texttt{\"\"}$$$. Alice's total score is $$$3+15+4+5+6+15+18+3+5+19=93$$$. Bob's total score is $$$0$$$.", "input": [ [ [ "aba" ] ], [ [ "abc" ] ], [ [ "cba" ] ], [ [ "n" ] ], [ [ "codeforces" ] ] ], "output": [ "Alice 2", "Alice 4", "Alice 4", "Bob 14", "Alice 93" ] }, { "problem_id": "1672B", "problem_name": "I love AAAB\nconstructive algorithms, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1672/B", "problem_solution_link": "https://codeforces.com/problemset/status/1672/problem/B", "problem_statement": "B. I love AAAB\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's call a string\ngood\nif its length is at least $$$2$$$ and all of its characters are $$$\\texttt{A}$$$ except for the last character which is $$$\\texttt{B}$$$. The good strings are $$$\\texttt{AB},\\texttt{AAB},\\texttt{AAAB},\\ldots$$$. Note that $$$\\texttt{B}$$$ is\nnot\na good string.\nYou are given an initially empty string $$$s_1$$$.\nYou can perform the following operation any number of times:\nChoose any position of $$$s_1$$$ and insert some good string in that position.\nGiven a string $$$s_2$$$, can we turn $$$s_1$$$ into $$$s_2$$$ after some number of operations?\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$) \u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single string $$$s_2$$$ ($$$1 \\leq |s_2| \\leq 2 \\cdot 10^5$$$).\nIt is guaranteed that $$$s_2$$$ consists of only the characters $$$\\texttt{A}$$$ and $$$\\texttt{B}$$$.\nIt is guaranteed that the sum of $$$|s_2|$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print \"\nYES\n\" (without quotes) if we can turn $$$s_1$$$ into $$$s_2$$$ after some number of operations, and \"\nNO\n\" (without quotes) otherwise.\nYou can output \"\nYES\n\" and \"\nNO\n\" in any case (for example, strings \"\nyEs\n\", \"\nyes\n\" and \"\nYes\n\" will be recognized as a positive response).\nExample\nInput\n4\nAABAB\nABB\nAAAAAAAAB\nA\nOutput\nYES\nNO\nYES\nNO\nNote\nIn the first test case, we transform $$$s_1$$$ as such: $$$\\varnothing \\to \\color{red}{\\texttt{AAB}} \\to \\texttt{A}\\color{red}{\\texttt{AB}}\\texttt{AB}$$$.\nIn the third test case, we transform $$$s_1$$$ as such: $$$\\varnothing \\to \\color{red}{\\texttt{AAAAAAAAB}}$$$.\nIn the second and fourth test case, it can be shown that it is impossible to turn $$$s_1$$$ into $$$s_2$$$.", "input": [ [ [ "AABAB" ] ], [ [ "ABB" ] ], [ [ "AAAAAAAAB" ] ], [ [ "A" ] ] ], "output": [ "YES", "NO", "YES", "NO" ] }, { "problem_id": "1672A", "problem_name": "Log Chopping\ngames, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1672/A", "problem_solution_link": "https://codeforces.com/problemset/status/1672/problem/A", "problem_statement": "A. Log Chopping\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.\nerrorgorn and maomao90 will take turns chopping the logs with\nerrorgorn chopping first\n. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be\npositive integers\n, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.\nThe player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 50$$$) \u00a0\u2014 the number of logs.\nThe second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 50$$$) \u00a0\u2014 the lengths of the logs.\nNote that there is no bound on the sum of $$$n$$$ over all test cases.\nOutput\nFor each test case, print \"\nerrorgorn\n\" if errorgorn wins or \"\nmaomao90\n\" if maomao90 wins. (Output without quotes).\nExample\nInput\n2\n4\n2 4 2 1\n1\n1\nOutput\nerrorgorn\nmaomao90\nNote\nIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.\nAfter this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.\nIn the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.", "input": [ [ [ "4" ], [ "2", "4", "2", "1" ] ], [ [ "1" ], [ "1" ] ] ], "output": [ "errorgorn", "maomao90" ] }, { "problem_id": "1671A", "problem_name": "String Building\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1671/A", "problem_solution_link": "https://codeforces.com/problemset/status/1671/problem/A", "problem_statement": "A. String Building\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a string $$$s$$$. You have to determine whether it is possible to build the string $$$s$$$ out of strings\naa\n,\naaa\n,\nbb\nand/or\nbbb\nby concatenating them. You can use the strings\naa\n,\naaa\n,\nbb\nand/or\nbbb\nany number of times and in any order.\nFor example:\naaaabbb\ncan be built as\naa\n$$$+$$$\naa\n$$$+$$$\nbbb\n;\nbbaaaaabbb\ncan be built as\nbb\n$$$+$$$\naaa\n$$$+$$$\naa\n$$$+$$$\nbbb\n;\naaaaaa\ncan be built as\naa\n$$$+$$$\naa\n$$$+$$$\naa\n;\nabab\ncannot be built from\naa\n,\naaa\n,\nbb\nand/or\nbbb\n.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases.\nEach test case consists of one line containing the string $$$s$$$ ($$$1 \\le |s| \\le 50$$$), consisting of characters\na\nand/or\nb\n.\nOutput\nFor each test case, print\nYES\nif it is possible to build the string $$$s$$$. Otherwise, print\nNO\n.\nYou may print each letter in any case (for example,\nYES\n,\nyes\n,\nYes\nwill all be recognized as positive answer,\nNO\n,\nno\nand\nnO\nwill all be recognized as negative answer).\nExample\nInput\n8\naaaabbb\nbbaaaaabbb\naaaaaa\nabab\na\nb\naaaab\nbbaaa\nOutput\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNote\nThe first four test cases of the example are described in the statement.", "input": [ [ [ "aaaabbb" ] ], [ [ "bbaaaaabbb" ] ], [ [ "aaaaaa" ] ], [ [ "abab" ] ], [ [ "a" ] ], [ [ "b" ] ], [ [ "aaaab" ] ], [ [ "bbaaa" ] ] ], "output": [ "YES", "YES", "YES", "NO", "NO", "NO", "NO", "YES" ] }, { "problem_id": "1670A", "problem_name": "Prof. Slim\ngreedy, implementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1670/A", "problem_solution_link": "https://codeforces.com/problemset/status/1670/problem/A", "problem_statement": "A. Prof. Slim\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nOne day Prof. Slim decided to leave the kingdom of the GUC to join the kingdom of the GIU. He was given an easy online assessment to solve before joining the GIU. Citizens of the GUC were\nhappy\nsad to see the prof leaving, so they decided to hack into the system and change the online assessment into a harder one so that he stays at the GUC. After a long argument, they decided to change it into the following problem.\nGiven an array of $$$n$$$ integers $$$a_1,a_2,\\ldots,a_n$$$,\nwhere $$$a_{i} \\neq 0$$$\n, check if you can make this array sorted by using the following operation any number of times (possibly zero). An array is sorted if its elements are arranged in a non-decreasing order.\nselect two indices $$$i$$$ and $$$j$$$ ($$$1 \\le i,j \\le n$$$) such that $$$a_i$$$ and $$$a_j$$$ have\ndifferent signs\n. In other words, one must be positive and one must be negative.\nswap the\nsigns\nof $$$a_{i}$$$ and $$$a_{j}$$$. For example if you select $$$a_i=3$$$ and $$$a_j=-2$$$, then they will change to $$$a_i=-3$$$ and $$$a_j=2$$$.\nProf. Slim saw that the problem is still too easy and isn't worth his time, so he decided to give it to you to solve.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^{5}$$$) \u2014 the length of the array $$$a$$$.\nThe next line contain $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$-10^9 \\le a_{i} \\le 10^9$$$, $$$a_{i} \\neq 0$$$) separated by spaces describing elements of the array $$$a$$$.\nIt is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.\nOutput\nFor each test case, print \"\nYES\n\" if the array can be sorted in the non-decreasing order, otherwise print \"\nNO\n\". You can print each letter in any case (upper or lower).\nExample\nInput\n4\n7\n7 3 2 -11 -13 -17 -23\n6\n4 10 25 47 71 96\n6\n71 -35 7 -4 -11 -25\n6\n-45 9 -48 -67 -55 7\nOutput\nNO\nYES\nYES\nNO\nNote\nIn the first test case, there is no way to make the array sorted using the operation any number of times.\nIn the second test case, the array is already sorted.\nIn the third test case, we can swap the sign of the $$$1$$$-st element with the sign of the $$$5$$$-th element, and the sign of the $$$3$$$-rd element with the sign of the $$$6$$$-th element, this way the array will be sorted.\nIn the fourth test case, there is no way to make the array sorted using the operation any number of times.", "input": [ [ [ "7" ], [ "7", "3", "2", "-11", "-13", "-17", "-23" ] ], [ [ "6" ], [ "4", "10", "25", "47", "71", "96" ] ], [ [ "6" ], [ "71", "-35", "7", "-4", "-11", "-25" ] ], [ [ "6" ], [ "-45", "9", "-48", "-67", "-55", "7" ] ] ], "output": [ "NO", "YES", "YES", "NO" ] }, { "problem_id": "1669C", "problem_name": "Odd/Even Increments\ngreedy, greedy, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1669/C", "problem_solution_link": "https://codeforces.com/problemset/status/1669/problem/C", "problem_statement": "C. Odd/Even Increments\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven an array $$$a=[a_1,a_2,\\dots,a_n]$$$ of $$$n$$$ positive integers, you can do operations of two types on it:\nAdd $$$1$$$ to\nevery\nelement with an\nodd\nindex. In other words change the array as follows: $$$a_1 := a_1 +1, a_3 := a_3 + 1, a_5 := a_5+1, \\dots$$$.\nAdd $$$1$$$ to\nevery\nelement with an\neven\nindex. In other words change the array as follows: $$$a_2 := a_2 +1, a_4 := a_4 + 1, a_6 := a_6+1, \\dots$$$.\nDetermine if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers. In other words, determine if you can make all elements of the array have the same parity after any number of operations.\nNote that you can do operations of both types any number of times (even none). Operations of different types can be performed a different number of times.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains an integer $$$n$$$ ($$$2 \\leq n \\leq 50$$$)\u00a0\u2014 the length of the array.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\leq a_i \\leq 10^3$$$)\u00a0\u2014 the elements of the array.\nNote that after the performed operations the elements in the array can become greater than $$$10^3$$$.\nOutput\nOutput $$$t$$$ lines, each of which contains the answer to the corresponding test case. As an answer, output \"\nYES\n\" if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers, and \"\nNO\n\" otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n4\n3\n1 2 1\n4\n2 2 2 3\n4\n2 2 2 2\n5\n1000 1 1000 1 1000\nOutput\nYES\nNO\nYES\nYES\nNote\nFor the first test case, we can increment the elements with an even index, obtaining the array $$$[1, 3, 1]$$$, which contains only odd numbers, so the answer is \"\nYES\n\".\nFor the second test case, we can show that after performing any number of operations we won't be able to make all elements have the same parity, so the answer is \"\nNO\n\".\nFor the third test case, all elements already have the same parity so the answer is \"\nYES\n\".\nFor the fourth test case, we can perform one operation and increase all elements at odd positions by $$$1$$$, thus obtaining the array $$$[1001, 1, 1001, 1, 1001]$$$, and all elements become odd so the answer is \"\nYES\n\".", "input": [ [ [ "3" ], [ "1", "2", "1" ] ], [ [ "4" ], [ "2", "2", "2", "3" ] ], [ [ "4" ], [ "2", "2", "2", "2" ] ], [ [ "5" ], [ "1000", "1", "1000", "1", "1000" ] ] ], "output": [ "YES", "NO", "YES", "YES" ] }, { "problem_id": "1669B", "problem_name": "Triple\nimplementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1669/B", "problem_solution_link": "https://codeforces.com/problemset/status/1669/problem/B", "problem_statement": "B. Triple\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven an array $$$a$$$ of $$$n$$$ elements, print any value that appears at least three times or print\n-1\nif there is no such value.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 2\\cdot10^5$$$)\u00a0\u2014 the length of the array.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\leq a_i \\leq n$$$)\u00a0\u2014 the elements of the array.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\\cdot10^5$$$.\nOutput\nFor each test case, print any value that appears at least three times or print\n-1\nif there is no such value.\nExample\nInput\n7\n1\n1\n3\n2 2 2\n7\n2 2 3 3 4 2 2\n8\n1 4 3 4 3 2 4 1\n9\n1 1 1 2 2 2 3 3 3\n5\n1 5 2 4 3\n4\n4 4 4 4\nOutput\n-1\n2\n2\n4\n3\n-1\n4\nNote\nIn the first test case there is just a single element, so it can't occur at least three times and the answer is\n-1\n.\nIn the second test case, all three elements of the array are equal to $$$2$$$, so $$$2$$$ occurs three times, and so the answer is $$$2$$$.\nFor the third test case, $$$2$$$ occurs four times, so the answer is $$$2$$$.\nFor the fourth test case, $$$4$$$ occurs three times, so the answer is $$$4$$$.\nFor the fifth test case, $$$1$$$, $$$2$$$ and $$$3$$$ all occur at least three times, so they are all valid outputs.\nFor the sixth test case, all elements are distinct, so none of them occurs at least three times and the answer is\n-1\n.", "input": [ [ [ "1" ], [ "1" ] ], [ [ "3" ], [ "2", "2", "2" ] ], [ [ "7" ], [ "2", "2", "3", "3", "4", "2", "2" ] ], [ [ "8" ], [ "1", "4", "3", "4", "3", "2", "4", "1" ] ], [ [ "9" ], [ "1", "1", "1", "2", "2", "2", "3", "3", "3" ] ], [ [ "5" ], [ "1", "5", "2", "4", "3" ] ], [ [ "4" ], [ "4", "4", "4", "4" ] ] ], "output": [ "-1", "2", "2", "4", "3", "-1", "4" ] }, { "problem_id": "1669A", "problem_name": "Division?\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1669/A", "problem_solution_link": "https://codeforces.com/problemset/status/1669/problem/A", "problem_statement": "A. Division?\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nCodeforces separates its users into $$$4$$$ divisions by their rating:\nFor Division 1: $$$1900 \\leq \\mathrm{rating}$$$\nFor Division 2: $$$1600 \\leq \\mathrm{rating} \\leq 1899$$$\nFor Division 3: $$$1400 \\leq \\mathrm{rating} \\leq 1599$$$\nFor Division 4: $$$\\mathrm{rating} \\leq 1399$$$\nGiven a $$$\\mathrm{rating}$$$, print in which division the $$$\\mathrm{rating}$$$ belongs.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$) \u2014 the number of testcases.\nThe description of each test consists of one line containing one integer $$$\\mathrm{rating}$$$ ($$$-5000 \\leq \\mathrm{rating} \\leq 5000$$$).\nOutput\nFor each test case, output a single line containing the correct division in the format \"\nDivision X\n\", where $$$X$$$ is an integer between $$$1$$$ and $$$4$$$ representing the division for the corresponding rating.\nExample\nInput\n7\n-789\n1299\n1300\n1399\n1400\n1679\n2300\nOutput\nDivision 4\nDivision 4\nDivision 4\nDivision 4\nDivision 3\nDivision 2\nDivision 1\nNote\nFor test cases $$$1-4$$$, the corresponding ratings are $$$-789$$$, $$$1299$$$, $$$1300$$$, $$$1399$$$, so all of them are in division $$$4$$$.\nFor the fifth test case, the corresponding rating is $$$1400$$$, so it is in division $$$3$$$.\nFor the sixth test case, the corresponding rating is $$$1679$$$, so it is in division $$$2$$$.\nFor the seventh test case, the corresponding rating is $$$2300$$$, so it is in division $$$1$$$.", "input": [ [ [ "-789" ] ], [ [ "1299" ] ], [ [ "1300" ] ], [ [ "1399" ] ], [ [ "1400" ] ], [ [ "1679" ] ], [ [ "2300" ] ] ], "output": [ "Division 4", "Division 4", "Division 4", "Division 4", "Division 3", "Division 2", "Division 1" ] }, { "problem_id": "1668A", "problem_name": "Direction Change\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1668/A", "problem_solution_link": "https://codeforces.com/problemset/status/1668/problem/A", "problem_statement": "A. Direction Change\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a grid with $$$n$$$ rows and $$$m$$$ columns. Rows and columns are numbered from $$$1$$$ to $$$n$$$, and from $$$1$$$ to $$$m$$$. The intersection of the $$$a$$$-th row and $$$b$$$-th column is denoted by $$$(a, b)$$$.\nInitially, you are standing in the top left corner $$$(1, 1)$$$. Your goal is to reach the bottom right corner $$$(n, m)$$$.\nYou can move in four directions from $$$(a, b)$$$: up to $$$(a-1, b)$$$, down to $$$(a+1, b)$$$, left to $$$(a, b-1)$$$ or right to $$$(a, b+1)$$$.\nYou cannot move in the same direction in two consecutive moves, and you cannot leave the grid. What is the minimum number of moves to reach $$$(n, m)$$$?\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^3$$$) \u2014 the number of the test cases. The description of the test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 10^9$$$) \u2014 the size of the grid.\nOutput\nFor each test case, print a single integer: $$$-1$$$ if it is impossible to reach $$$(n, m)$$$ under the given conditions, otherwise the minimum number of moves.\nExample\nInput\n6\n1 1\n2 1\n1 3\n4 2\n4 6\n10 5\nOutput\n0\n1\n-1\n6\n10\n17\nNote\nTest case $$$1$$$: $$$n=1$$$, $$$m=1$$$, and initially you are standing in $$$(1, 1)$$$ so $$$0$$$ move is required to reach $$$(n, m) = (1, 1)$$$.\nTest case $$$2$$$: you should go down to reach $$$(2, 1)$$$.\nTest case $$$3$$$: it is impossible to reach $$$(1, 3)$$$ without moving right two consecutive times, or without leaving the grid.\nTest case $$$4$$$: an optimal moving sequence could be: $$$(1, 1) \\to (1, 2) \\to (2, 2) \\to (2, 1) \\to (3, 1) \\to (3, 2) \\to (4, 2)$$$. It can be proved that this is the optimal solution. So the answer is $$$6$$$.", "input": [ [ [ "1", "1" ] ], [ [ "2", "1" ] ], [ [ "1", "3" ] ], [ [ "4", "2" ] ], [ [ "4", "6" ] ], [ [ "10", "5" ] ] ], "output": [ "0", "1", "-1", "6", "10", "17" ] }, { "problem_id": "1665A", "problem_name": "GCD vs LCM\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1665/A", "problem_solution_link": "https://codeforces.com/problemset/status/1665/problem/A", "problem_statement": "A. GCD vs LCM\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a positive integer $$$n$$$. You have to find $$$4$$$\npositive\nintegers $$$a, b, c, d$$$ such that\n$$$a + b + c + d = n$$$, and\n$$$\\gcd(a, b) = \\operatorname{lcm}(c, d)$$$.\nIf there are several possible answers you can output any of them. It is possible to show that the answer always exists.\nIn this problem $$$\\gcd(a, b)$$$ denotes the\ngreatest common divisor\nof $$$a$$$ and $$$b$$$, and $$$\\operatorname{lcm}(c, d)$$$ denotes the\nleast common multiple\nof $$$c$$$ and $$$d$$$.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. Description of the test cases follows.\nEach test case contains a single line with integer $$$n$$$ ($$$4 \\le n \\le 10^9$$$)\u00a0\u2014 the sum of $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$.\nOutput\nFor each test case output $$$4$$$\npositive\nintegers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ such that $$$a + b + c + d = n$$$ and $$$\\gcd(a, b) = \\operatorname{lcm}(c, d)$$$.\nExample\nInput\n5\n4\n7\n8\n9\n10\nOutput\n1 1 1 1\n2 2 2 1\n2 2 2 2\n2 4 2 1\n3 5 1 1\nNote\nIn the first test case $$$\\gcd(1, 1) = \\operatorname{lcm}(1, 1) = 1$$$, $$$1 + 1 + 1 + 1 = 4$$$.\nIn the second test case $$$\\gcd(2, 2) = \\operatorname{lcm}(2, 1) = 2$$$, $$$2 + 2 + 2 + 1 = 7$$$.\nIn the third test case $$$\\gcd(2, 2) = \\operatorname{lcm}(2, 2) = 2$$$, $$$2 + 2 + 2 + 2 = 8$$$.\nIn the fourth test case $$$\\gcd(2, 4) = \\operatorname{lcm}(2, 1) = 2$$$, $$$2 + 4 + 2 + 1 = 9$$$.\nIn the fifth test case $$$\\gcd(3, 5) = \\operatorname{lcm}(1, 1) = 1$$$, $$$3 + 5 + 1 + 1 = 10$$$.", "input": [ [ [ "4" ] ], [ [ "7" ] ], [ [ "8" ] ], [ [ "9" ] ], [ [ "10" ] ] ], "output": [ "1 1 1 1", "2 2 2 1", "2 2 2 2", "2 4 2 1", "3 5 1 1" ] }, { "problem_id": "1661A", "problem_name": "Array Balancing\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1661/A", "problem_solution_link": "https://codeforces.com/problemset/status/1661/problem/A", "problem_statement": "A. Array Balancing\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two arrays of length $$$n$$$: $$$a_1, a_2, \\dots, a_n$$$ and $$$b_1, b_2, \\dots, b_n$$$.\nYou can perform the following operation any number of times:\nChoose integer index $$$i$$$ ($$$1 \\le i \\le n$$$);\nSwap $$$a_i$$$ and $$$b_i$$$.\nWhat is the minimum possible sum $$$|a_1 - a_2| + |a_2 - a_3| + \\dots + |a_{n-1} - a_n|$$$ $$$+$$$ $$$|b_1 - b_2| + |b_2 - b_3| + \\dots + |b_{n-1} - b_n|$$$ (in other words, $$$\\sum\\limits_{i=1}^{n - 1}{\\left(|a_i - a_{i+1}| + |b_i - b_{i+1}|\\right)}$$$) you can achieve after performing several (possibly, zero) operations?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 4000$$$)\u00a0\u2014 the number of test cases. Then, $$$t$$$ test cases follow.\nThe first line of each test case contains the single integer $$$n$$$ ($$$2 \\le n \\le 25$$$)\u00a0\u2014 the length of arrays $$$a$$$ and $$$b$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$)\u00a0\u2014 the array $$$a$$$.\nThe third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \\dots, b_n$$$ ($$$1 \\le b_i \\le 10^9$$$)\u00a0\u2014 the array $$$b$$$.\nOutput\nFor each test case, print one integer\u00a0\u2014 the minimum possible sum $$$\\sum\\limits_{i=1}^{n-1}{\\left(|a_i - a_{i+1}| + |b_i - b_{i+1}|\\right)}$$$.\nExample\nInput\n3\n4\n3 3 10 10\n10 10 3 3\n5\n1 2 3 4 5\n6 7 8 9 10\n6\n72 101 108 108 111 44\n10 87 111 114 108 100\nOutput\n0\n8\n218\nNote\nIn the first test case, we can, for example, swap $$$a_3$$$ with $$$b_3$$$ and $$$a_4$$$ with $$$b_4$$$. We'll get arrays $$$a = [3, 3, 3, 3]$$$ and $$$b = [10, 10, 10, 10]$$$ with sum $$$3 \\cdot |3 - 3| + 3 \\cdot |10 - 10| = 0$$$.\nIn the second test case, arrays already have minimum sum (described above) equal to $$$|1 - 2| + \\dots + |4 - 5| + |6 - 7| + \\dots + |9 - 10|$$$ $$$= 4 + 4 = 8$$$.\nIn the third test case, we can, for example, swap $$$a_5$$$ and $$$b_5$$$.", "input": [ [ [ "4" ], [ "3", "3", "10", "10" ], [ "10", "10", "3", "3" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ], [ "6", "7", "8", "9", "10" ] ], [ [ "6" ], [ "72", "101", "108", "108", "111", "44" ], [ "10", "87", "111", "114", "108", "100" ] ] ], "output": [ "0", "8", "218" ] }, { "problem_id": "1660B", "problem_name": "Vlad and Candies\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1660/B", "problem_solution_link": "https://codeforces.com/problemset/status/1660/problem/B", "problem_statement": "B. Vlad and Candies\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nNot so long ago, Vlad had a birthday, for which he was presented with a package of candies. There were $$$n$$$ types of candies, there are $$$a_i$$$ candies of the type $$$i$$$ ($$$1 \\le i \\le n$$$).\nVlad decided to eat exactly one candy every time, choosing any of the candies of a type that is currently the most frequent (if there are several such types, he can choose\nany\nof them). To get the maximum pleasure from eating, Vlad\ndoes not want\nto eat two candies of the same type in a row.\nHelp him figure out if he can eat all the candies without eating two identical candies in a row.\nInput\nThe first line of input data contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of input test cases.\nThe following is a description of $$$t$$$ test cases of input, two lines for each.\nThe first line of the case contains the single number $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) \u2014 the number of types of candies in the package.\nThe second line of the case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \\le a_i \\le 10^9$$$) \u2014 the number of candies of the type $$$i$$$.\nIt is guaranteed that the sum of $$$n$$$ for all cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nOutput $$$t$$$ lines, each of which contains the answer to the corresponding test case of input. As an answer, output \"\nYES\n\" if Vlad can eat candy as planned, and \"\nNO\n\" otherwise.\nYou can output the answer in any case (for example, the strings \"\nyEs\n\", \"\nyes\n\", \"\nYes\n\" and \"\nYES\n\" will be recognized as a positive answer).\nExample\nInput\n6\n2\n2 3\n1\n2\n5\n1 6 2 4 3\n4\n2 2 2 1\n3\n1 1000000000 999999999\n1\n1\nOutput\nYES\nNO\nNO\nYES\nYES\nYES\nNote\nIn the first example, it is necessary to eat sweets in this order:\na candy of the type $$$2$$$, it is the most frequent, now $$$a = [2, 2]$$$;\na candy of the type $$$1$$$, there are the same number of candies of the type $$$2$$$, but we just ate one, now $$$a = [1, 2]$$$;\na candy of the type $$$2$$$, it is the most frequent, now $$$a = [1, 1]$$$;\na candy of the type $$$1$$$, now $$$a = [0, 1]$$$;\na candy of the type $$$2$$$, now $$$a = [0, 0]$$$ and the candy has run out.\nIn the second example, all the candies are of the same type and it is impossible to eat them without eating two identical ones in a row.\nIn the third example, first of all, a candy of the type $$$2$$$ will be eaten, after which this kind will remain the only kind that is the most frequent, and you will have to eat a candy of the type $$$2$$$ again.", "input": [ [ [ "2" ], [ "2", "3" ] ], [ [ "1" ], [ "2" ] ], [ [ "5" ], [ "1", "6", "2", "4", "3" ] ], [ [ "4" ], [ "2", "2", "2", "1" ] ], [ [ "3" ], [ "1", "1000000000", "999999999" ] ], [ [ "1" ], [ "1" ] ] ], "output": [ "YES", "NO", "NO", "YES", "YES", "YES" ] }, { "problem_id": "1660A", "problem_name": "Vasya and Coins\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1660/A", "problem_solution_link": "https://codeforces.com/problemset/status/1660/problem/A", "problem_statement": "A. Vasya and Coins\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nVasya decided to go to the grocery store. He found in his wallet $$$a$$$ coins of $$$1$$$ burle and $$$b$$$ coins of $$$2$$$ burles. He does not yet know the total cost of all goods, so help him find out $$$s$$$ ($$$s > 0$$$): the\nminimum\npositive integer amount of money he\ncannot\npay without change or pay at all using only his coins.\nFor example, if $$$a=1$$$ and $$$b=1$$$ (he has one $$$1$$$-burle coin and one $$$2$$$-burle coin), then:\nhe can pay $$$1$$$ burle without change, paying with one $$$1$$$-burle coin,\nhe can pay $$$2$$$ burle without change, paying with one $$$2$$$-burle coin,\nhe can pay $$$3$$$ burle without change by paying with one $$$1$$$-burle coin and one $$$2$$$-burle coin,\nhe cannot pay $$$4$$$ burle without change (moreover, he cannot pay this amount at all).\nSo for $$$a=1$$$ and $$$b=1$$$ the answer is $$$s=4$$$.\nInput\nThe first line of the input contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases in the test.\nThe description of each test case consists of one line containing two integers $$$a_i$$$ and $$$b_i$$$ ($$$0 \\le a_i, b_i \\le 10^8$$$)\u00a0\u2014 the number of $$$1$$$-burle coins and $$$2$$$-burles coins Vasya has respectively.\nOutput\nFor each test case, on a separate line print one integer $$$s$$$ ($$$s > 0$$$): the minimum positive integer amount of money that Vasya cannot pay without change or pay at all.\nExample\nInput\n5\n1 1\n4 0\n0 2\n0 0\n2314 2374\nOutput\n4\n5\n1\n1\n7063\nNote\nThe first test case of the example is clarified into the main part of the statement.\nIn the second test case, Vasya has only $$$1$$$ burle coins, and he can collect either any amount from $$$1$$$ to $$$4$$$, but $$$5$$$ can't.\nIn the second test case, Vasya has only $$$2$$$ burle coins, and he cannot pay $$$1$$$ burle without change.\nIn the fourth test case you don't have any coins, and he can't even pay $$$1$$$ burle.", "input": [ [ [ "1", "1" ] ], [ [ "4", "0" ] ], [ [ "0", "2" ] ], [ [ "0", "0" ] ], [ [ "2314", "2374" ] ] ], "output": [ "4", "5", "1", "1", "7063" ] }, { "problem_id": "1658B", "problem_name": "Marin and Anti-coprime Permutation\ncombinatorics, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1658/B", "problem_solution_link": "https://codeforces.com/problemset/status/1658/problem/B", "problem_statement": "B. Marin and Anti-coprime Permutation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMarin wants you to count number of permutations that are\nbeautiful\n. A\nbeautiful\npermutation of length $$$n$$$ is a permutation that has the following property: $$$$$$ \\gcd (1 \\cdot p_1, \\, 2 \\cdot p_2, \\, \\dots, \\, n \\cdot p_n) > 1, $$$$$$ where $$$\\gcd$$$ is the\ngreatest common divisor\n.\nA permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3, 4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^3$$$) \u2014 the number of test cases.\nEach test case consists of one line containing one integer $$$n$$$ ($$$1 \\le n \\le 10^3$$$).\nOutput\nFor each test case, print one integer \u2014 number of\nbeautiful\npermutations. Because the answer can be very big, please print the answer modulo $$$998\\,244\\,353$$$.\nExample\nInput\n7\n1\n2\n3\n4\n5\n6\n1000\nOutput\n0\n1\n0\n4\n0\n36\n665702330\nNote\nIn first test case, we only have one permutation which is $$$[1]$$$ but it is not beautiful because $$$\\gcd(1 \\cdot 1) = 1$$$.\nIn second test case, we only have one beautiful permutation which is $$$[2, 1]$$$ because $$$\\gcd(1 \\cdot 2, 2 \\cdot 1) = 2$$$.", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "3" ] ], [ [ "4" ] ], [ [ "5" ] ], [ [ "6" ] ], [ [ "1000" ] ] ], "output": [ "0", "1", "0", "4", "0", "36", "665702330" ] }, { "problem_id": "1658A", "problem_name": "Marin and Photoshoot\nconstructive algorithms, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1658/A", "problem_solution_link": "https://codeforces.com/problemset/status/1658/problem/A", "problem_statement": "A. Marin and Photoshoot\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nToday, Marin is at a cosplay exhibition and is preparing for a group photoshoot!\nFor the group picture, the cosplayers form a horizontal line. A group picture is considered\nbeautiful\nif for every contiguous segment of at least $$$2$$$ cosplayers, the number of males does not exceed the number of females (obviously).\nCurrently, the line has $$$n$$$ cosplayers which can be described by a binary string $$$s$$$. The $$$i$$$-th cosplayer is male if $$$s_i = 0$$$ and female if $$$s_i = 1$$$. To ensure that the line is\nbeautiful\n, you can invite some additional cosplayers (possibly zero) to join the line at any position. You can't remove any cosplayer from the line.\nMarin wants to know the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is\nbeautiful\n. She can't do this on her own, so she's asking you for help. Can you help her?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^3$$$) \u2014 the number of test cases.\nThe first line of each test case contains a positive integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$) \u2014 the number of cosplayers in the initial line.\nThe second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ \u2014 describing the cosplayers already in line. Each character of the string is either\n0\ndescribing a male, or\n1\ndescribing a female.\nNote that there is no limit on the sum of $$$n$$$.\nOutput\nFor each test case, print the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is\nbeautiful\n.\nExample\nInput\n9\n3\n000\n3\n001\n3\n010\n3\n011\n3\n100\n3\n101\n3\n110\n3\n111\n19\n1010110000100000101\nOutput\n4\n2\n1\n0\n2\n0\n0\n0\n17\nNote\nIn the first test case, for each pair of adjacent cosplayers, you can invite two female cosplayers to stand in between them. Then, $$$000 \\rightarrow 0110110$$$.\nIn the third test case, you can invite one female cosplayer to stand next to the second cosplayer. Then, $$$010 \\rightarrow 0110$$$.", "input": [ [ [ "3" ], [ "000" ] ], [ [ "3" ], [ "001" ] ], [ [ "3" ], [ "010" ] ], [ [ "3" ], [ "011" ] ], [ [ "3" ], [ "100" ] ], [ [ "3" ], [ "101" ] ], [ [ "3" ], [ "110" ] ], [ [ "3" ], [ "111" ] ], [ [ "19" ], [ "1010110000100000101" ] ] ], "output": [ "4", "2", "1", "0", "2", "0", "0", "0", "17" ] }, { "problem_id": "1657B", "problem_name": "XY Sequence\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1657/B", "problem_solution_link": "https://codeforces.com/problemset/status/1657/problem/B", "problem_statement": "B. XY Sequence\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \\dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \\ge 1$$$ you can choose:\neither $$$a_i = a_{i - 1} + x$$$\nor $$$a_i = a_{i - 1} - y$$$.\nYour goal is to build such a sequence $$$a$$$ that $$$a_i \\le B$$$ for all $$$i$$$ and $$$\\sum\\limits_{i=0}^{n}{a_i}$$$ is maximum possible.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. Next $$$t$$$ cases follow.\nThe first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$; $$$1 \\le B, x, y \\le 10^9$$$).\nIt's guaranteed that the total sum of $$$n$$$ doesn't exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print one integer\u00a0\u2014 the maximum possible $$$\\sum\\limits_{i=0}^{n}{a_i}$$$.\nExample\nInput\n3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3\nOutput\n15\n4000000000\n-10\nNote\nIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.\nIn the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.\nIn the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.", "input": [ [ [ "5", "100", "1", "30" ] ], [ [ "7", "1000000000", "1000000000", "1000000000" ] ], [ [ "4", "1", "7", "3" ] ] ], "output": [ "15", "4000000000", "-10" ] }, { "problem_id": "1657A", "problem_name": "Integer Moves\nbrute force, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1657/A", "problem_solution_link": "https://codeforces.com/problemset/status/1657/problem/A", "problem_statement": "A. Integer Moves\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an\ninteger\n(i.e. $$$\\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).\nYour task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 3000$$$)\u00a0\u2014 number of test cases.\nThe single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \\le x, y \\le 50$$$)\u00a0\u2014 the coordinates of the destination point.\nOutput\nFor each test case, print one integer\u00a0\u2014 the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.\nExample\nInput\n3\n8 6\n0 0\n9 15\nOutput\n1\n0\n2\nNote\nIn the first example, one operation $$$(0, 0) \\rightarrow (8, 6)$$$ is enough. $$$\\sqrt{(0-8)^2+(0-6)^2}=\\sqrt{64+36}=\\sqrt{100}=10$$$ is an integer.\nIn the second example, the chip is already at the destination point.\nIn the third example, the chip can be moved as follows: $$$(0, 0) \\rightarrow (5, 12) \\rightarrow (9, 15)$$$. $$$\\sqrt{(0-5)^2+(0-12)^2}=\\sqrt{25+144}=\\sqrt{169}=13$$$ and $$$\\sqrt{(5-9)^2+(12-15)^2}=\\sqrt{16+9}=\\sqrt{25}=5$$$ are integers.", "input": [ [ [ "8", "6" ] ], [ [ "0", "0" ] ], [ [ "9", "15" ] ] ], "output": [ "1", "0", "2" ] }, { "problem_id": "1656A", "problem_name": "Good Pairs\nmath, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1656/A", "problem_solution_link": "https://codeforces.com/problemset/status/1656/problem/A", "problem_statement": "A. Good Pairs\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a_1, a_2, \\ldots, a_n$$$ of positive integers. A\ngood pair\nis a pair of indices $$$(i, j)$$$ with $$$1 \\leq i, j \\leq n$$$ such that, for all $$$1 \\leq k \\leq n$$$, the following equality holds:\n$$$$$$ |a_i - a_k| + |a_k - a_j| = |a_i - a_j|, $$$$$$ where $$$|x|$$$ denotes the absolute value of $$$x$$$.\nFind a good pair. Note that $$$i$$$ can be equal to $$$j$$$.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$) \u2014 the number of test cases. Description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 10^5$$$) \u2014 the length of the array.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 10^9$$$) where $$$a_i$$$ is the $$$i$$$-th element of the array.\nThe sum of $$$n$$$ for all test cases is at most $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print a single line with two space-separated indices $$$i$$$ and $$$j$$$ which form a good pair of the array. The case $$$i=j$$$ is allowed. It can be shown that such a pair always exists. If there are multiple good pairs, print any of them.\nExample\nInput\n3\n3\n5 2 7\n5\n1 4 2 2 3\n1\n2\nOutput\n2 3\n1 2\n1 1\nNote\nIn the first case, for $$$i = 2$$$ and $$$j = 3$$$ the equality holds true for all $$$k$$$:\n$$$k = 1$$$: $$$|a_2 - a_1| + |a_1 - a_3| = |2 - 5| + |5 - 7| = 5 = |2 - 7| = |a_2-a_3|$$$,\n$$$k = 2$$$: $$$|a_2 - a_2| + |a_2 - a_3| = |2 - 2| + |2 - 7| = 5 = |2 - 7| = |a_2-a_3|$$$,\n$$$k = 3$$$: $$$|a_2 - a_3| + |a_3 - a_3| = |2 - 7| + |7 - 7| = 5 = |2 - 7| = |a_2-a_3|$$$.", "input": [ [ [ "3" ], [ "5", "2", "7" ] ], [ [ "5" ], [ "1", "4", "2", "2", "3" ] ], [ [ "1" ], [ "2" ] ] ], "output": [ "2 3", "1 2", "1 1" ] }, { "problem_id": "1654B", "problem_name": "Prefix Removals\nstrings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1654/B", "problem_solution_link": "https://codeforces.com/problemset/status/1654/problem/B", "problem_statement": "B. Prefix Removals\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a string $$$s$$$ consisting of lowercase letters of the English alphabet. You must perform the following algorithm on $$$s$$$:\nLet $$$x$$$ be the length of the longest prefix of $$$s$$$ which occurs somewhere else in $$$s$$$ as a contiguous substring (the other occurrence may also intersect the prefix). If $$$x = 0$$$, break. Otherwise, remove the first $$$x$$$ characters of $$$s$$$, and repeat.\nA prefix is a string consisting of several first letters of a given string, without any reorders. An empty prefix is also a valid prefix. For example, the string \"\nabcd\n\" has 5 prefixes: empty string, \"\na\n\", \"\nab\n\", \"\nabc\n\" and \"\nabcd\n\".\nFor instance, if we perform the algorithm on $$$s =$$$ \"\nabcabdc\n\",\nInitially, \"\nab\n\" is the longest prefix that also appears somewhere else as a substring in $$$s$$$, so $$$s =$$$ \"\ncabdc\n\" after $$$1$$$ operation.\nThen, \"\nc\n\" is the longest prefix that also appears somewhere else as a substring in $$$s$$$, so $$$s =$$$ \"\nabdc\n\" after $$$2$$$ operations.\nNow $$$x=0$$$ (because there are no non-empty prefixes of \"\nabdc\n\" that also appear somewhere else as a substring in $$$s$$$), so the algorithm terminates.\nFind the final state of the string after performing the algorithm.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases.\nThis is followed by $$$t$$$ lines, each containing a description of one test case. Each line contains a string $$$s$$$. The given strings consist only of lowercase letters of the English alphabet and have lengths between $$$1$$$ and $$$2 \\cdot 10^5$$$ inclusive.\nIt is guaranteed that the sum of the lengths of $$$s$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print a single line containing the string $$$s$$$ after executing the algorithm. It can be shown that such string is non-empty.\nExample\nInput\n6\nabcabdc\na\nbbbbbbbbbb\ncodeforces\ncffcfccffccfcffcfccfcffccffcfccf\nzyzyzwxxyyxxyyzzyzzxxwzxwywxwzxxyzzw\nOutput\nabdc\na\nb\ndeforces\ncf\nxyzzw\nNote\nThe first test case is explained in the statement.\nIn the second test case, no operations can be performed on $$$s$$$.\nIn the third test case,\nInitially, $$$s =$$$ \"\nbbbbbbbbbb\n\".\nAfter $$$1$$$ operation, $$$s =$$$ \"\nb\n\".\nIn the fourth test case,\nInitially, $$$s =$$$ \"\ncodeforces\n\".\nAfter $$$1$$$ operation, $$$s =$$$ \"\nodeforces\n\".\nAfter $$$2$$$ operations, $$$s =$$$ \"\ndeforces\n\".", "input": [ [ [ "abcabdc" ] ], [ [ "a" ] ], [ [ "bbbbbbbbbb" ] ], [ [ "codeforces" ] ], [ [ "cffcfccffccfcffcfccfcffccffcfccf" ] ], [ [ "zyzyzwxxyyxxyyzzyzzxxwzxwywxwzxxyzzw" ] ] ], "output": [ "abdc", "a", "b", "deforces", "cf", "xyzzw" ] }, { "problem_id": "1654A", "problem_name": "Maximum Cake Tastiness\nbrute force, greedy, implementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1654/A", "problem_solution_link": "https://codeforces.com/problemset/status/1654/problem/A", "problem_statement": "A. Maximum Cake Tastiness\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ pieces of cake on a line. The $$$i$$$-th piece of cake has weight $$$a_i$$$ ($$$1 \\leq i \\leq n$$$).\nThe tastiness of the cake is the maximum total weight of two adjacent pieces of cake (i.\u00a0e., $$$\\max(a_1+a_2,\\, a_2+a_3,\\, \\ldots,\\, a_{n-1} + a_{n})$$$).\nYou want to maximize the tastiness of the cake. You are allowed to do the following operation at most once (doing more operations would ruin the cake):\nChoose a contiguous subsegment $$$a[l, r]$$$ of pieces of cake ($$$1 \\leq l \\leq r \\leq n$$$), and reverse it.\nThe subsegment $$$a[l, r]$$$ of the array $$$a$$$ is the sequence $$$a_l, a_{l+1}, \\dots, a_r$$$.\nIf you reverse it, the array will become $$$a_1, a_2, \\dots, a_{l-2}, a_{l-1}, \\underline{a_r}, \\underline{a_{r-1}}, \\underline{\\dots}, \\underline{a_{l+1}}, \\underline{a_l}, a_{r+1}, a_{r+2}, \\dots, a_{n-1}, a_n$$$.\nFor example, if the weights are initially $$$[5, 2, 1, 4, 7, 3]$$$, you can reverse the subsegment $$$a[2, 5]$$$, getting $$$[5, \\underline{7}, \\underline{4}, \\underline{1}, \\underline{2}, 3]$$$. The tastiness of the cake is now $$$5 + 7 = 12$$$ (while before the operation the tastiness was $$$4+7=11$$$).\nFind the maximum tastiness of the cake after doing the operation at most once.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 50$$$) \u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 1000$$$) \u2014 the number of pieces of cake.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 10^9$$$) \u2014 $$$a_i$$$ is the weight of the $$$i$$$-th piece of cake.\nOutput\nFor each test case, print a single integer: the maximum tastiness of the cake after doing the operation at most once.\nExample\nInput\n5\n6\n5 2 1 4 7 3\n3\n32 78 78\n3\n69 54 91\n8\n999021 999021 999021 999021 999652 999021 999021 999021\n2\n1000000000 1000000000\nOutput\n12\n156\n160\n1998673\n2000000000\nNote\nIn the first test case, after reversing the subsegment $$$a[2, 5]$$$, you get a cake with weights $$$[5, \\underline{7}, \\underline{4}, \\underline{1}, \\underline{2}, 3]$$$. The tastiness of the cake is now $$$\\max(5+7, 7+4, 4+1, 1+2, 2+3) = 12$$$. This is the maximum possible tastiness of the cake one can obtain by performing the operation at most once.\nIn the second test case, it's optimal not to do any operation. The tastiness is $$$78+78 = 156$$$.\nIn the third test case, after reversing the subsegment $$$a[1, 2]$$$, you get a cake with weights $$$[\\underline{54}, \\underline{69}, 91]$$$. The tastiness of the cake is now $$$\\max(54+69, 69+91) = 160$$$. There is no way to make the tastiness of the cake greater than $$$160$$$ by performing at most one operation.", "input": [ [ [ "6" ], [ "5", "2", "1", "4", "7", "3" ] ], [ [ "3" ], [ "32", "78", "78" ] ], [ [ "3" ], [ "69", "54", "91" ] ], [ [ "8" ], [ "999021", "999021", "999021", "999021", "999652", "999021", "999021", "999021" ] ], [ [ "2" ], [ "1000000000", "1000000000" ] ] ], "output": [ "12", "156", "160", "1998673", "2000000000" ] }, { "problem_id": "1651B", "problem_name": "Prove Him Wrong\nconstructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1651/B", "problem_solution_link": "https://codeforces.com/problemset/status/1651/problem/B", "problem_statement": "B. Prove Him Wrong\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nRecently, your friend discovered one special operation on an integer array $$$a$$$:\nChoose two indices $$$i$$$ and $$$j$$$ ($$$i \\neq j$$$);\nSet $$$a_i = a_j = |a_i - a_j|$$$.\nAfter playing with this operation for a while, he came to the next conclusion:\nFor every array $$$a$$$ of $$$n$$$ integers, where $$$1 \\le a_i \\le 10^9$$$, you can find a pair of indices $$$(i, j)$$$ such that the total sum of $$$a$$$ will\ndecrease\nafter performing the operation.\nThis statement sounds fishy to you, so you want to find a counterexample for a given integer $$$n$$$. Can you find such counterexample and prove him wrong?\nIn other words, find an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$) such that for all pairs of indices $$$(i, j)$$$ performing the operation won't decrease the total sum (it will increase or not change the sum).\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first and only line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 1000$$$)\u00a0\u2014 the length of array $$$a$$$.\nOutput\nFor each test case, if there is no counterexample array $$$a$$$ of size $$$n$$$, print\nNO\n.\nOtherwise, print\nYES\nfollowed by the array $$$a$$$ itself ($$$1 \\le a_i \\le 10^9$$$). If there are multiple counterexamples, print any.\nExample\nInput\n3\n2\n512\n3\nOutput\nYES\n1 337\nNO\nYES\n31 4 159\nNote\nIn the first test case, the only possible pairs of indices are $$$(1, 2)$$$ and $$$(2, 1)$$$.\nIf you perform the operation on indices $$$(1, 2)$$$ (or $$$(2, 1)$$$), you'll get $$$a_1 = a_2 = |1 - 337| = 336$$$, or array $$$[336, 336]$$$. In both cases, the total sum increases, so this array $$$a$$$ is a counterexample.", "input": [ [ [ "2" ] ], [ [ "512" ] ], [ [ "3" ] ] ], "output": [ ["YES", "1 337"], ["NO"], ["YES", "31 4 159"] ], "error": true }, { "problem_id": "1651A", "problem_name": "Playoff\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1651/A", "problem_solution_link": "https://codeforces.com/problemset/status/1651/problem/A", "problem_statement": "A. Playoff\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nConsider a playoff tournament where $$$2^n$$$ athletes compete. The athletes are numbered from $$$1$$$ to $$$2^n$$$.\nThe tournament is held in $$$n$$$ stages. In each stage, the athletes are split into pairs in such a way that each athlete belongs exactly to one pair. In each pair, the athletes compete against each other, and exactly one of them wins. The winner of each pair advances to the next stage, the athlete who was defeated gets eliminated from the tournament.\nThe pairs are formed as follows:\nin the first stage, athlete $$$1$$$ competes against athlete $$$2$$$; $$$3$$$ competes against $$$4$$$; $$$5$$$ competes against $$$6$$$, and so on;\nin the second stage, the winner of the match \"$$$1$$$\u2013$$$2$$$\" competes against the winner of the match \"$$$3$$$\u2013$$$4$$$\"; the winner of the match \"$$$5$$$\u2013$$$6$$$\" competes against the winner of the match \"$$$7$$$\u2013$$$8$$$\", and so on;\nthe next stages are held according to the same rules.\nWhen athletes $$$x$$$ and $$$y$$$ compete, the winner is decided as follows:\nif $$$x+y$$$ is odd, the athlete with the lower index wins (i.\u2009e. if $$$x < y$$$, then $$$x$$$ wins, otherwise $$$y$$$ wins);\nif $$$x+y$$$ is even, the athlete with the higher index wins.\nThe following picture describes the way the tournament with $$$n = 3$$$ goes.\nYour task is the following one: given the integer $$$n$$$, determine the index of the athlete who wins the tournament.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 30$$$) \u2014 the number of test cases.\nEach test case consists of one line containing one integer $$$n$$$ ($$$1 \\le n \\le 30$$$).\nOutput\nFor each test case, print one integer \u2014 the index of the winner of the tournament.\nExample\nInput\n2\n3\n1\nOutput\n7\n1\nNote\nThe case $$$n = 3$$$ is shown in the picture from the statement.\nIf $$$n = 1$$$, then there's only one match between athletes $$$1$$$ and $$$2$$$. Since $$$1 + 2 = 3$$$ is an odd number, the athlete with the lower index wins. So, the athlete $$$1$$$ is the winner.", "input": [ [ [ "3" ] ], [ [ "1" ] ] ], "output": [ "7", "1" ] }, { "problem_id": "1650A", "problem_name": "Deletions of Two Adjacent Letters\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1650/A", "problem_solution_link": "https://codeforces.com/problemset/status/1650/problem/A", "problem_statement": "A. Deletions of Two Adjacent Letters\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThe string $$$s$$$ is given, the string length is\nodd\nnumber. The string consists of lowercase letters of the Latin alphabet.\nAs long as the string length is greater than $$$1$$$, the following operation can be performed on it: select any two adjacent letters in the string $$$s$$$ and delete them from the string. For example, from the string \"\nlemma\n\" in one operation, you can get any of the four strings: \"\nmma\n\", \"\nlma\n\", \"\nlea\n\" or \"\nlem\n\" In particular, in one operation, the length of the string reduces by $$$2$$$.\nFormally, let the string $$$s$$$ have the form $$$s=s_1s_2 \\dots s_n$$$ ($$$n>1$$$). During one operation, you choose an arbitrary index $$$i$$$ ($$$1 \\le i < n$$$) and replace $$$s=s_1s_2 \\dots s_{i-1}s_{i+2} \\dots s_n$$$.\nFor the given string $$$s$$$ and the letter $$$c$$$, determine whether it is possible to make such a sequence of operations that in the end the equality $$$s=c$$$ will be true? In other words, is there such a sequence of operations that the process will end with a string of length $$$1$$$, which consists of the letter $$$c$$$?\nInput\nThe first line of input data contains an integer $$$t$$$ ($$$1 \\le t \\le 10^3$$$) \u2014 the number of input test cases.\nThe descriptions of the $$$t$$$ cases follow. Each test case is represented by two lines:\nstring $$$s$$$, which has an odd length from $$$1$$$ to $$$49$$$ inclusive and consists of lowercase letters of the Latin alphabet;\nis a string containing one letter $$$c$$$, where $$$c$$$ is a lowercase letter of the Latin alphabet.\nOutput\nFor each test case in a separate line output:\nYES\n, if the string $$$s$$$ can be converted so that $$$s=c$$$ is true;\nNO\notherwise.\nYou can output\nYES\nand\nNO\nin any case (for example, the strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as a positive response).\nExample\nInput\n5\nabcde\nc\nabcde\nb\nx\ny\naaaaaaaaaaaaaaa\na\ncontest\nt\nOutput\nYES\nNO\nNO\nYES\nYES\nNote\nIn the first test case, $$$s$$$=\"\nabcde\n\". You need to get $$$s$$$=\"\nc\n\". For the first operation, delete the first two letters, we get $$$s$$$=\"\ncde\n\". In the second operation, we delete the last two letters, so we get the expected value of $$$s$$$=\"\nc\n\".\nIn the third test case, $$$s$$$=\"\nx\n\", it is required to get $$$s$$$=\"\ny\n\". Obviously, this cannot be done.", "input": [ [ [ "abcde" ], [ "c" ] ], [ [ "abcde" ], [ "b" ] ], [ [ "x" ], [ "y" ] ], [ [ "aaaaaaaaaaaaaaa" ], [ "a" ] ], [ [ "contest" ], [ "t" ] ] ], "output": [ "YES", "NO", "NO", "YES", "YES" ] }, { "problem_id": "1649A", "problem_name": "Game\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1649/A", "problem_solution_link": "https://codeforces.com/problemset/status/1649/problem/A", "problem_statement": "A. Game\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are playing a very popular computer game. The next level consists of $$$n$$$ consecutive locations, numbered from $$$1$$$ to $$$n$$$, each of them containing either land or water. It is known that the first and last locations contain land, and for completing the level you have to move from the first location to the last. Also, if you become inside a location with water, you will die, so you can only move between locations with land.\nYou can jump between adjacent locations for free, as well as\nno more than\nonce jump from any location with land $$$i$$$ to any location with land $$$i + x$$$, spending $$$x$$$ coins ($$$x \\geq 0$$$).\nYour task is to spend the minimum possible number of coins to move from the first location to the last one.\nNote that this is always possible since both the first and last locations are the land locations.\nInput\nThere are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. This is followed by the test cases description.\nThe first line of each test case contains one integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$)\u00a0\u2014 the number of locations.\nThe second line of the test case contains a sequence of integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\leq a_i \\leq 1$$$), where $$$a_i = 1$$$ means that the $$$i$$$-th location is the location with land, and $$$a_i = 0$$$ means that the $$$i$$$-th location is the location with water. It is guaranteed that $$$a_1 = 1$$$ and $$$a_n = 1$$$.\nOutput\nFor each test case print a single integer\u00a0\u2014 the answer to the problem.\nExample\nInput\n3\n2\n1 1\n5\n1 0 1 0 1\n4\n1 0 1 1\nOutput\n0\n4\n2\nNote\nIn the first test case, it is enough to make one free jump from the first location to the second one, which is also the last one, so the answer is $$$0$$$.\nIn the second test case, the only way to move from the first location to the last one is to jump between them, which will cost $$$4$$$ coins.\nIn the third test case, you can jump from the first location to the third for $$$2$$$ coins, and then jump to the fourth location for free, so the answer is $$$2$$$. It can be shown that this is the optimal way.", "input": [ [ [ "2" ], [ "1", "1" ] ], [ [ "5" ], [ "1", "0", "1", "0", "1" ] ], [ [ "4" ], [ "1", "0", "1", "1" ] ] ], "output": [ "0", "4", "2" ] }, { "problem_id": "1647A", "problem_name": "Madoka and Math Dad\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1647/A", "problem_solution_link": "https://codeforces.com/problemset/status/1647/problem/A", "problem_statement": "A. Madoka and Math Dad\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMadoka finally found the administrator password for her computer. Her father is a well-known popularizer of mathematics, so the password is the answer to the following problem.\nFind the maximum decimal number without zeroes and with no equal digits in a row, such that the sum of its digits is $$$n$$$.\nMadoka is too tired of math to solve it herself, so help her to solve this problem!\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases. Description of the test cases follows.\nThe only line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 1000$$$)\u00a0\u2014 the required sum of the digits.\nOutput\nFor each test case print the maximum number you can obtain.\nExample\nInput\n5\n1\n2\n3\n4\n5\nOutput\n1\n2\n21\n121\n212\nNote\nThe only numbers with the sum of digits equal to $$$2$$$ without zeros are $$$2$$$ and $$$11$$$. But the last one has two ones in a row, so it's not valid. That's why the answer is $$$2$$$.\nThe only numbers with the sum of digits equal to $$$3$$$ without zeros are $$$111$$$, $$$12$$$, $$$21$$$, and $$$3$$$. The first one has $$$2$$$ ones in a row, so it's not valid. So the maximum valid number is $$$21$$$.\nThe only numbers with the sum of digits equals to $$$4$$$ without zeros are $$$1111$$$, $$$211$$$, $$$121$$$, $$$112$$$, $$$13$$$, $$$31$$$, $$$22$$$, and $$$4$$$. Numbers $$$1111$$$, $$$211$$$, $$$112$$$, $$$22$$$ aren't valid, because they have some identical digits in a row. So the maximum valid number is $$$121$$$.", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "3" ] ], [ [ "4" ] ], [ [ "5" ] ] ], "output": [ "1", "2", "21", "121", "212" ] }, { "problem_id": "1646B", "problem_name": "Quality vs Quantity\nbrute force, constructive algorithms, greedy, sortings, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1646/B", "problem_solution_link": "https://codeforces.com/problemset/status/1646/problem/B", "problem_statement": "B. Quality vs Quantity\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\n$$$ \\def\\myred#1{\\color{red}{\\underline{\\bf{#1}}}} \\def\\myblue#1{\\color{blue}{\\overline{\\bf{#1}}}} $$$ $$$\\def\\RED{\\myred{Red}} \\def\\BLUE{\\myblue{Blue}}$$$\nYou are given a sequence of $$$n$$$ non-negative integers $$$a_1, a_2, \\ldots, a_n$$$. Initially, all the elements of the sequence are unpainted. You can paint each number $$$\\RED$$$ or $$$\\BLUE$$$ (but not both), or\nleave it unpainted\n.\nFor a color $$$c$$$, $$$\\text{Count}(c)$$$ is the number of elements in the sequence painted with that color and $$$\\text{Sum}(c)$$$ is the sum of the elements in the sequence painted with that color.\nFor example, if the given sequence is $$$[2, 8, 6, 3, 1]$$$ and it is painted this way: $$$[\\myblue{2}, 8, \\myred{6}, \\myblue{3}, 1]$$$ (where $$$6$$$ is painted red, $$$2$$$ and $$$3$$$ are painted blue, $$$1$$$ and $$$8$$$ are unpainted) then $$$\\text{Sum}(\\RED)=6$$$, $$$\\text{Sum}(\\BLUE)=2+3=5$$$, $$$\\text{Count}(\\RED)=1$$$, and $$$\\text{Count}(\\BLUE)=2$$$.\nDetermine if it is possible to paint the sequence so that $$$\\text{Sum}(\\RED) > \\text{Sum}(\\BLUE)$$$ and $$$\\text{Count}(\\RED) < \\text{Count}(\\BLUE)$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$). Description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$3\\le n\\le 2\\cdot 10^5$$$)\u00a0\u2014 the length of the given sequence.\nThe second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\\ldots,a_n$$$ ($$$0\\le a_i\\le 10^9$$$)\u00a0\u2014 the given sequence.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\\cdot 10^5$$$.\nOutput\nFor each test case, print\nYES\nif it is possible to paint the given sequence satisfying the above requirements, and\nNO\notherwise.\nYou can output\nYES\nand\nNO\nin any case (for example, strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as a positive response).\nExample\nInput\n4\n3\n1 2 3\n5\n2 8 6 3 1\n4\n3 5 4 2\n5\n1000000000 1000000000 1000000000 1000000000 1000000000\nOutput\nNO\nYES\nNO\nNO\nNote\nIn the first test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\\myblue{1},\\myblue{2},\\myred{3}]$$$ (where $$$3$$$ is painted red, $$$1$$$ and $$$2$$$ are painted blue) then $$$\\text{Count}(\\RED)=1 < \\text{Count}(\\BLUE)=2$$$, but $$$\\text{Sum}(\\RED)=3 \\ngtr \\text{Sum}(\\BLUE)=3$$$. So, this is not a possible way to paint the sequence.\nIn the second test case, a possible way to paint the sequence is described in the statement. We can see that $$$\\text{Sum}(\\RED)=6 > \\text{Sum}(\\BLUE)=5$$$ and $$$\\text{Count}(\\RED)=1 < \\text{Count}(\\BLUE)=2$$$.\nIn the third test case, there is no possible way to paint the sequence. For example, if you paint the sequence this way: $$$[\\myred{3},\\myred{5},\\myblue{4}, \\myblue{2}]$$$ (where $$$3$$$ and $$$5$$$ are painted red, $$$4$$$ and $$$2$$$ are painted blue) then $$$\\text{Sum}(\\RED) = 8 > \\text{Sum}(\\BLUE) = 6$$$ but $$$\\text{Count}(\\RED) = 2 \\nless \\text{Count}(\\BLUE) = 2$$$. So, this is not a possible way to paint the sequence.\nIn the fourth test case, it can be proven that there is no possible way to paint the sequence satisfying sum and count constraints.", "input": [ [ [ "3" ], [ "1", "2", "3" ] ], [ [ "5" ], [ "2", "8", "6", "3", "1" ] ], [ [ "4" ], [ "3", "5", "4", "2" ] ], [ [ "5" ], [ "1000000000", "1000000000", "1000000000", "1000000000", "1000000000" ] ] ], "output": [ "NO", "YES", "NO", "NO" ] }, { "problem_id": "1646A", "problem_name": "Square Counting\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1646/A", "problem_solution_link": "https://codeforces.com/problemset/status/1646/problem/A", "problem_statement": "A. Square Counting\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLuis has a sequence of $$$n+1$$$ integers $$$a_1, a_2, \\ldots, a_{n+1}$$$. For each $$$i = 1, 2, \\ldots, n+1$$$ it is guaranteed that $$$0\\leq a_i < n$$$, or $$$a_i=n^2$$$. He has calculated the sum of all the elements of the sequence, and called this value $$$s$$$.\nLuis has lost his sequence, but he remembers the values of $$$n$$$ and $$$s$$$. Can you find the number of elements in the sequence that are equal to $$$n^2$$$?\nWe can show that the answer is unique under the given constraints.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 2\\cdot 10^4$$$). Description of the test cases follows.\nThe only line of each test case contains two integers $$$n$$$ and $$$s$$$ ($$$1\\le n< 10^6$$$, $$$0\\le s \\le 10^{18}$$$). It is guaranteed that the value of $$$s$$$ is a valid sum for some sequence satisfying the above constraints.\nOutput\nFor each test case, print one integer\u00a0\u2014 the number of elements in the sequence which are equal to $$$n^2$$$.\nExample\nInput\n4\n7 0\n1 1\n2 12\n3 12\nOutput\n0\n1\n3\n1\nNote\nIn the first test case, we have $$$s=0$$$ so all numbers are equal to $$$0$$$ and there isn't any number equal to $$$49$$$.\nIn the second test case, we have $$$s=1$$$. There are two possible sequences: $$$[0, 1]$$$ or $$$[1, 0]$$$. In both cases, the number $$$1$$$ appears just once.\nIn the third test case, we have $$$s=12$$$, which is the maximum possible value of $$$s$$$ for this case. Thus, the number $$$4$$$ appears $$$3$$$ times in the sequence.", "input": [ [ [ "7", "0" ] ], [ [ "1", "1" ] ], [ [ "2", "12" ] ], [ [ "3", "12" ] ] ], "output": [ "0", "1", "3", "1" ] }, { "problem_id": "1644B", "problem_name": "Anti-Fibonacci Permutation\nbrute force, constructive algorithms, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1644/B", "problem_solution_link": "https://codeforces.com/problemset/status/1644/problem/B", "problem_statement": "B. Anti-Fibonacci Permutation\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's call a permutation $$$p$$$ of length $$$n$$$\nanti-Fibonacci\nif the condition $$$p_{i-2} + p_{i-1} \\ne p_i$$$ holds for all $$$i$$$ ($$$3 \\le i \\le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.\nYour task is for a given number $$$n$$$ print $$$n$$$\ndistinct\nanti-Fibonacci permutations of length $$$n$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 48$$$)\u00a0\u2014 the number of test cases.\nThe single line of each test case contains a single integer $$$n$$$ ($$$3 \\le n \\le 50$$$).\nOutput\nFor each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once.\nIf there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.\nExample\nInput\n2\n4\n3\nOutput\n4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2", "input": [ [ [ "4" ] ], [ [ "3" ] ] ], "output": [ ["4 1 3 2", "1 2 4 3", "3 4 1 2", "2 4 1 3"], ["3 2 1", "1 3 2", "3 1 2"] ], "error": true }, { "problem_id": "1644A", "problem_name": "Doors and Keys\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1644/A", "problem_solution_link": "https://codeforces.com/problemset/status/1644/problem/A", "problem_statement": "A. Doors and Keys\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThe knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.\nIn a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.\nEach door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key\u00a0\u2014 are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.\nThe knight has a map of the hallway. It can be transcribed as a string, consisting of six characters:\nR\n,\nG\n,\nB\n\u2014 denoting red, green and blue doors, respectively;\nr\n,\ng\n,\nb\n\u2014 denoting red, green and blue keys, respectively.\nEach of these six characters appears in the string exactly once.\nThe knight is standing at the beginning of the hallway\u00a0\u2014 on the left on the map.\nGiven a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 720$$$)\u00a0\u2014 the number of testcases.\nEach testcase consists of a single string. Each character is one of\nR\n,\nG\n,\nB\n(for the doors),\nr\n,\ng\n,\nb\n(for the keys), and each of them appears exactly once.\nOutput\nFor each testcase, print\nYES\nif the knight can open all doors. Otherwise, print\nNO\n.\nExample\nInput\n4\nrgbBRG\nRgbrBG\nbBrRgG\nrgRGBb\nOutput\nYES\nNO\nYES\nNO\nNote\nIn the first testcase, the knight first collects all keys, then opens all doors with them.\nIn the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.\nIn the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.\nIn the fourth testcase, the knight can't open the blue door.", "input": [ [ [ "rgbBRG" ] ], [ [ "RgbrBG" ] ], [ [ "bBrRgG" ] ], [ [ "rgRGBb" ] ] ], "output": [ "YES", "NO", "YES", "NO" ] }, { "problem_id": "1642A", "problem_name": "Hard Way\ngeometry", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1642/A", "problem_solution_link": "https://codeforces.com/problemset/status/1642/problem/A", "problem_statement": "A. Hard Way\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nSam lives in Awesomeburg, its downtown has a triangular shape. Also, the following is true about the triangle:\nits vertices have integer coordinates,\nthe coordinates of vertices are non-negative, and\nits vertices are not on a single line.\nHe calls a point on the downtown's border (that is the border of the triangle)\nsafe\nif he can reach this point from\nat least one point\nof the line $$$y = 0$$$ walking along some\nstraight line\n, without crossing the interior of the triangle.\nIn the picture the downtown is marked with grey color. The first path is invalid because it does not go along a straight line. The second path is invalid because it intersects with the interior of the downtown. The third and fourth paths are correct.\nFind the total length of the unsafe parts of the downtown border. It can be proven that these parts are segments and their number is finite.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases. Description of the test cases follows.\nEach test case contains three lines, each of them contains two integers $$$x_i$$$, $$$y_i$$$ ($$$0 \\le x_i, y_i \\le 10^9$$$)\u00a0\u2014 coordinates of the vertices of the downtown's border.\nOutput\nFor each test case print a single number\u00a0\u2014 the answer to the problem.\nYour answer will be considered correct if its absolute or relative error does not exceed $$$10^{-9}$$$. Formally let your answer be $$$a$$$, jury answer be $$$b$$$. Your answer will be considered correct if $$$\\frac{|a - b|}{\\max{(1, |b|)}} \\le 10^{-9}$$$.\nExample\nInput\n5\n8 10\n10 4\n6 2\n4 6\n0 1\n4 2\n14 1\n11 2\n13 2\n0 0\n4 0\n2 4\n0 1\n1 1\n0 0\nOutput\n0.0000000\n0\n2.0000\n0.00\n1\nNote\nIn the picture, the downtowns of the first three test cases are illustrated. Triangles are enumerated according to the indices of test cases they belong to.\nIn the first two test cases, all points on the borders of the downtowns are safe, thus the answers are $$$0$$$.\nIn the following picture unsafe points for the third test case are marked with black color:\nIn the fourth test case, all points on the border of the downtown are safe.", "input": [ [ [ "8", "10" ], [ "10", "4" ], [ "6", "2" ] ], [ [ "4", "6" ], [ "0", "1" ], [ "4", "2" ] ], [ [ "14", "1" ], [ "11", "2" ], [ "13", "2" ] ], [ [ "0", "0" ], [ "4", "0" ], [ "2", "4" ] ], [ [ "0", "1" ], [ "1", "1" ], [ "0", "0" ] ] ], "output": [ "0.0000000", "0", "2.0000", "0.00", "1" ] }, { "problem_id": "1638A", "problem_name": "Reverse\nconstructive algorithms, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1638/A", "problem_solution_link": "https://codeforces.com/problemset/status/1638/problem/A", "problem_statement": "A. Reverse\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a permutation $$$p_1, p_2, \\ldots, p_n$$$ of length $$$n$$$. You have to choose two integers $$$l,r$$$ ($$$1 \\le l \\le r \\le n$$$) and reverse the subsegment $$$[l,r]$$$ of the permutation. The permutation will become $$$p_1,p_2, \\dots, p_{l-1},p_r,p_{r-1}, \\dots, p_l,p_{r+1},p_{r+2}, \\dots ,p_n$$$.\nFind the lexicographically smallest permutation that can be obtained by performing\nexactly\none reverse operation on the initial permutation.\nNote that for two distinct permutations of equal length $$$a$$$ and $$$b$$$, $$$a$$$ is lexicographically smaller than $$$b$$$ if at the first position they differ, $$$a$$$ has the smaller element.\nA permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 500$$$)\u00a0\u2014 the number of test cases. Description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 500$$$)\u00a0\u2014 the length of the permutation.\nThe second line of each test case contains $$$n$$$ integers $$$p_1, p_2, \\dots, p_n$$$ ($$$1 \\le p_i \\le n$$$)\u00a0\u2014 the elements of the permutation.\nOutput\nFor each test case print the lexicographically smallest permutation you can obtain.\nExample\nInput\n4\n1\n1\n3\n2 1 3\n4\n1 4 2 3\n5\n1 2 3 4 5\nOutput\n1 \n1 2 3 \n1 2 4 3 \n1 2 3 4 5\nNote\nIn the first test case, the permutation has length $$$1$$$, so the only possible segment is $$$[1,1]$$$. The resulting permutation is $$$[1]$$$.\nIn the second test case, we can obtain the identity permutation by reversing the segment $$$[1,2]$$$. The resulting permutation is $$$[1,2,3]$$$.\nIn the third test case, the best possible segment is $$$[2,3]$$$. The resulting permutation is $$$[1,2,4,3]$$$.\nIn the fourth test case, there is no lexicographically smaller permutation, so we can leave it unchanged by choosing the segment $$$[1,1]$$$. The resulting permutation is $$$[1,2,3,4,5]$$$.", "input": [ [ [ "1" ], [ "1" ] ], [ [ "3" ], [ "2", "1", "3" ] ], [ [ "4" ], [ "1", "4", "2", "3" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ] ] ], "output": [ "1 ", "1 2 3 ", "1 2 4 3 ", "1 2 3 4 5" ] }, { "problem_id": "1637A", "problem_name": "Sorting Parts\nbrute force, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1637/A", "problem_solution_link": "https://codeforces.com/problemset/status/1637/problem/A", "problem_statement": "A. Sorting Parts\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have an array $$$a$$$ of length $$$n$$$. You can\nexactly\nonce select an integer $$$len$$$ between $$$1$$$ and $$$n - 1$$$ inclusively, and then sort in non-decreasing order the prefix of the array of length $$$len$$$ and the suffix of the array of length $$$n - len$$$ independently.\nFor example, if the array is $$$a = [3, 1, 4, 5, 2]$$$, and you choose $$$len = 2$$$, then after that the array will be equal to $$$[1, 3, 2, 4, 5]$$$.\nCould it be that after performing this operation, the array will\nnot\nbe sorted in non-decreasing order?\nInput\nThere are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. This is followed by the test cases description.\nThe first line of each test case contains one integer $$$n$$$ ($$$2 \\leq n \\leq 10^4$$$)\u00a0\u2014 the length of the array.\nThe second line of the test case contains a sequence of integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 10^9$$$) \u2014 the array elements.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$.\nOutput\nFor each test case of input data, output \"\nYES\n\" (without quotes), if the array may be\nnot\nsorted in non-decreasing order, output \"\nNO\n\" (without quotes) otherwise. You can output each letter in any case (uppercase or lowercase).\nExample\nInput\n3\n3\n2 2 1\n4\n3 1 2 1\n5\n1 2 2 4 4\nOutput\nYES\nYES\nNO\nNote\nIn the first test case, it's possible to select $$$len = 1$$$, then after operation, the array will not be sorted in non-decreasing order and will be equal to $$$[2, 1, 2]$$$.\nIn the second test case, it's possible to select $$$len = 3$$$, then after operation, the array will not be sorted in non-decreasing order and will be equal to $$$[1, 2, 3, 1]$$$.\nIn the third test case, the array will be sorted in non-decreasing order for every possible $$$len$$$.", "input": [ [ [ "3" ], [ "2", "2", "1" ] ], [ [ "4" ], [ "3", "1", "2", "1" ] ], [ [ "5" ], [ "1", "2", "2", "4", "4" ] ] ], "output": [ "YES", "YES", "NO" ] }, { "problem_id": "1635B", "problem_name": "Avoid Local Maximums\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1635/B", "problem_solution_link": "https://codeforces.com/problemset/status/1635/problem/B", "problem_statement": "B. Avoid Local Maximums\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ of size $$$n$$$. Each element in this array is an integer between $$$1$$$ and $$$10^9$$$.\nYou can perform several operations to this array. During an operation, you can replace an element in the array with any integer between $$$1$$$ and $$$10^9$$$.\nOutput the minimum number of operations needed such that the resulting array doesn't contain any local maximums, and the resulting array after the operations.\nAn element $$$a_i$$$ is a local maximum if it is strictly larger than both of its neighbors (that is, $$$a_i > a_{i - 1}$$$ and $$$a_i > a_{i + 1}$$$). Since $$$a_1$$$ and $$$a_n$$$ have only one neighbor each, they will never be a local maximum.\nInput\nEach test contains multiple test cases. The first line will contain a single integer $$$t$$$ $$$(1 \\leq t \\leq 10000)$$$ \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first line of each test case contains a single integer $$$n$$$ $$$(2 \\leq n \\leq 2 \\cdot 10^5)$$$ \u2014 the size of the array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots ,a_n$$$ $$$(1 \\leq a_i \\leq 10^9)$$$, the elements of array.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, first output a line containing a single integer $$$m$$$ \u2014 minimum number of operations required. Then ouput a line consist of $$$n$$$ integers \u2014 the resulting array after the operations. Note that this array should differ in exactly $$$m$$$ elements from the initial array.\nIf there are multiple answers, print any.\nExample\nInput\n5\n3\n2 1 2\n4\n1 2 3 1\n5\n1 2 1 2 1\n9\n1 2 1 3 2 3 1 2 1\n9\n2 1 3 1 3 1 3 1 3\nOutput\n0\n2 1 2\n1\n1 3 3 1\n1\n1 2 2 2 1\n2\n1 2 3 3 2 3 3 2 1\n2\n2 1 3 3 3 1 1 1 3\nNote\nIn the first example, the array contains no local maximum, so we don't need to perform operations.\nIn the second example, we can change $$$a_2$$$ to $$$3$$$, then the array don't have local maximums.", "input": [ [ [ "3" ], [ "2", "1", "2" ] ], [ [ "4" ], [ "1", "2", "3", "1" ] ], [ [ "5" ], [ "1", "2", "1", "2", "1" ] ], [ [ "9" ], [ "1", "2", "1", "3", "2", "3", "1", "2", "1" ] ], [ [ "9" ], [ "2", "1", "3", "1", "3", "1", "3", "1", "3" ] ] ], "output": [ ["0", "2 1 2"], ["1", "1 3 3 1"], ["1", "1 2 2 2 1"], ["2", "1 2 3 3 2 3 3 2 1"], ["2", "2 1 3 3 3 1 1 1 3"] ], "error": true }, { "problem_id": "1635A", "problem_name": "Min Or Sum\nbitmasks, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1635/A", "problem_solution_link": "https://codeforces.com/problemset/status/1635/problem/A", "problem_statement": "A. Min Or Sum\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ of size $$$n$$$.\nYou can perform the following operation on the array:\nChoose two different integers $$$i, j$$$ $$$(1 \\leq i < j \\leq n$$$), replace $$$a_i$$$ with $$$x$$$ and $$$a_j$$$ with $$$y$$$. In order not to break the array, $$$a_i | a_j = x | y$$$ must be held, where $$$|$$$ denotes the\nbitwise OR operation\n. Notice that $$$x$$$ and $$$y$$$ are non-negative integers.\nPlease output the minimum sum of the array you can get after using the operation above any number of times.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \\leq t \\leq 1000)$$$. Description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ $$$(2 \\leq n \\leq 100)$$$ \u2014 the size of array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots ,a_n$$$ $$$(0 \\leq a_i < 2^{30})$$$.\nOutput\nFor each test case, print one number in a line \u2014 the minimum possible sum of the array.\nExample\nInput\n4\n3\n1 3 2\n5\n1 2 4 8 16\n2\n6 6\n3\n3 5 6\nOutput\n3\n31\n6\n7\nNote\nIn the first example, you can perform the following operations to obtain the array $$$[1, 0, 2]$$$:\n1. choose $$$i = 1, j = 2$$$, change $$$a_1 = 1$$$ and $$$a_2 = 2$$$, it's valid since $$$1 | 3 = 1 | 2$$$. The array becomes $$$[1, 2, 2]$$$.\n2. choose $$$i = 2, j = 3$$$, change $$$a_2 = 0$$$ and $$$a_3 = 2$$$, it's valid since $$$2 | 2 = 0 | 2$$$. The array becomes $$$[1, 0, 2]$$$.\nWe can prove that the minimum sum is $$$1 + 0 + 2 = 3$$$\nIn the second example, We don't need any operations.", "input": [ [ [ "3" ], [ "1", "3", "2" ] ], [ [ "5" ], [ "1", "2", "4", "8", "16" ] ], [ [ "2" ], [ "6", "6" ] ], [ [ "3" ], [ "3", "5", "6" ] ] ], "output": [ "3", "31", "6", "7" ] }, { "problem_id": "1634A", "problem_name": "Reverse and Concatenate\ngreedy, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1634/A", "problem_solution_link": "https://codeforces.com/problemset/status/1634/problem/A", "problem_statement": "A. Reverse and Concatenate\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nReal stupidity beats artificial intelligence every time.\n\u2014 Terry Pratchett,\nHogfather, Discworld\nYou are given a string $$$s$$$ of length $$$n$$$ and a number $$$k$$$. Let's denote by $$$rev(s)$$$ the reversed string $$$s$$$ (i.e. $$$rev(s) = s_n s_{n-1} ... s_1$$$). You can apply one of the two kinds of operations to the string:\nreplace the string $$$s$$$ with $$$s + rev(s)$$$\nreplace the string $$$s$$$ with $$$rev(s) + s$$$\nHow many different strings can you get as a result of performing\nexactly\n$$$k$$$ operations (possibly of different kinds) on the original string $$$s$$$?\nIn this statement we denoted the concatenation of strings $$$s$$$ and $$$t$$$ as $$$s + t$$$. In other words, $$$s + t = s_1 s_2 ... s_n t_1 t_2 ... t_m$$$, where $$$n$$$ and $$$m$$$ are the lengths of strings $$$s$$$ and $$$t$$$ respectively.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 number of test cases. Next $$$2 \\cdot t$$$ lines contain $$$t$$$ test cases:\nThe first line of a test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 100$$$, $$$0 \\le k \\le 1000$$$)\u00a0\u2014 the length of the string and the number of operations respectively.\nThe second string of a test case contains one string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters.\nOutput\nFor each test case, print the answer (that is, the number of different strings that you can get after exactly $$$k$$$ operations) on a separate line.\nIt can be shown that the answer does not exceed $$$10^9$$$ under the given constraints.\nExample\nInput\n4\n3 2\naab\n3 3\naab\n7 1\nabacaba\n2 0\nab\nOutput\n2\n2\n1\n1\nNote\nIn the first test case of the example:\nAfter the first operation the string $$$s$$$ can become either\naabbaa\nor\nbaaaab\n. After the second operation there are 2 possibilities for $$$s$$$:\naabbaaaabbaa\nand\nbaaaabbaaaab\n.", "input": [ [ [ "3", "2" ], [ "aab" ] ], [ [ "3", "3" ], [ "aab" ] ], [ [ "7", "1" ], [ "abacaba" ] ], [ [ "2", "0" ], [ "ab" ] ] ], "output": [ "2", "2", "1", "1" ] }, { "problem_id": "1633B", "problem_name": "Minority\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1633/B", "problem_solution_link": "https://codeforces.com/problemset/status/1633/problem/B", "problem_statement": "B. Minority\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a string $$$s$$$, consisting only of characters '0' and '1'.\nYou have to choose a contiguous substring of $$$s$$$ and remove all occurrences of the character, which is a strict minority in it, from the substring.\nThat is, if the amount of '0's in the substring is strictly smaller than the amount of '1's, remove all occurrences of '0' from the substring. If the amount of '1's is strictly smaller than the amount of '0's, remove all occurrences of '1'. If the amounts are the same, do nothing.\nYou have to apply the operation\nexactly once\n. What is the maximum amount of characters that can be removed?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of testcases.\nThe only line of each testcase contains a non-empty string $$$s$$$, consisting only of characters '0' and '1'. The length of $$$s$$$ doesn't exceed $$$2 \\cdot 10^5$$$.\nThe total length of strings $$$s$$$ over all testcases doesn't exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each testcase, print a single integer\u00a0\u2014 the maximum amount of characters that can be removed after applying the operation\nexactly once\n.\nExample\nInput\n4\n01\n1010101010111\n00110001000\n1\nOutput\n0\n5\n3\n0\nNote\nIn the first testcase, you can choose substrings \"0\", \"1\" or \"01\". In \"0\" the amount of '0' is $$$1$$$, the amount of '1' is $$$0$$$. '1' is a strict minority, thus all occurrences of it are removed from the substring. However, since there were $$$0$$$ of them, nothing changes. Same for \"1\". And in \"01\" neither of '0' or '1' is a strict minority. Thus, nothing changes. So there is no way to remove any characters.\nIn the second testcase, you can choose substring \"10101010101\". It contains $$$5$$$ characters '0' and $$$6$$$ characters '1'. '0' is a strict minority. Thus, you can remove all its occurrences. There exist other substrings that produce the same answer.\nIn the third testcase, you can choose substring \"011000100\". It contains $$$6$$$ characters '0' and $$$3$$$ characters '1'. '1' is a strict minority. Thus, you can remove all its occurrences.", "input": [ [ [ "01" ] ], [ [ "1010101010111" ] ], [ [ "00110001000" ] ], [ [ "1" ] ] ], "output": [ "0", "5", "3", "0" ] }, { "problem_id": "1633A", "problem_name": "Div. 7\nbrute force", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1633/A", "problem_solution_link": "https://codeforces.com/problemset/status/1633/problem/A", "problem_statement": "A. Div. 7\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an integer $$$n$$$. You have to change the minimum number of digits in it in such a way that the resulting number\ndoes not have any leading zeroes\nand\nis divisible by $$$7$$$\n.\nIf there are multiple ways to do it, print any of them. If the given number is already divisible by $$$7$$$, leave it unchanged.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 990$$$) \u2014 the number of test cases.\nThen the test cases follow, each test case consists of one line containing one integer $$$n$$$ ($$$10 \\le n \\le 999$$$).\nOutput\nFor each test case, print one integer without any leading zeroes \u2014 the result of your changes (i.\u2009e. the integer that is divisible by $$$7$$$ and can be obtained by changing the minimum possible number of digits in $$$n$$$).\nIf there are multiple ways to apply changes, print any resulting number. If the given number is already divisible by $$$7$$$, just print it.\nExample\nInput\n3\n42\n23\n377\nOutput\n42\n28\n777\nNote\nIn the first test case of the example, $$$42$$$ is already divisible by $$$7$$$, so there's no need to change it.\nIn the second test case of the example, there are multiple answers \u2014 $$$28$$$, $$$21$$$ or $$$63$$$.\nIn the third test case of the example, other possible answers are $$$357$$$, $$$371$$$ and $$$378$$$. Note that you\ncannot\nprint $$$077$$$ or $$$77$$$.", "input": [ [ [ "42" ] ], [ [ "23" ] ], [ [ "377" ] ] ], "output": [ "42", "28", "777" ] }, { "problem_id": "1632A", "problem_name": "ABC\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1632/A", "problem_solution_link": "https://codeforces.com/problemset/status/1632/problem/A", "problem_statement": "A. ABC\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nRecently, the students of School 179 have developed a unique algorithm, which takes in a binary string $$$s$$$ as input. However, they soon found out that if some substring $$$t$$$ of $$$s$$$ is a palindrome of length greater than\n1\n, the algorithm will work incorrectly. Can the students somehow reorder the characters of $$$s$$$ so that the algorithm will work correctly on the string?\nA binary string is a string where each character is either\n0\nor\n1\n.\nA string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.\nA palindrome is a string that reads the same backwards as forwards.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). Description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the length of the string $$$s$$$.\nThe second line of each test case contains the string $$$s$$$ of length $$$n$$$ consisting only of the characters\n0\nand\n1\n.\nOutput\nFor each test case, print\nYES\n(case-insensitive) if it is possible to reorder the characters of $$$s$$$ so that there are no substrings that are a palindrome of length greater than\n1\n, or\nNO\n(case-insensitive) otherwise.\nExample\nInput\n4\n1\n1\n2\n10\n2\n01\n4\n1010\nOutput\nYES\nYES\nYES\nNO\nNote\nIn the first three test cases, the given strings do not contain palindromes of length greater than\n1\n, so the answers are\nYES\n.\nIn the last test case, it is impossible to reorder the characters so that the string does not contain palindromes of length greater than\n1\n, so the answer is\nNO\n.", "input": [ [ [ "1" ], [ "1" ] ], [ [ "2" ], [ "10" ] ], [ [ "2" ], [ "01" ] ], [ [ "4" ], [ "1010" ] ] ], "output": [ "YES", "YES", "YES", "NO" ] }, { "problem_id": "1631A", "problem_name": "Min Max Swap\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1631/A", "problem_solution_link": "https://codeforces.com/problemset/status/1631/problem/A", "problem_statement": "A. Min Max Swap\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two arrays $$$a$$$ and $$$b$$$ of $$$n$$$ positive integers each. You can apply the following operation to them any number of times:\nSelect an index $$$i$$$ ($$$1\\leq i\\leq n$$$) and swap $$$a_i$$$ with $$$b_i$$$ (i.\u00a0e. $$$a_i$$$ becomes $$$b_i$$$ and vice versa).\nFind the\nminimum\npossible value of $$$\\max(a_1, a_2, \\ldots, a_n) \\cdot \\max(b_1, b_2, \\ldots, b_n)$$$ you can get after applying such operation any number of times (possibly zero).\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$) \u2014 the number of test cases. Description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1\\le n\\le 100$$$) \u2014 the length of the arrays.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 10\\,000$$$) where $$$a_i$$$ is the $$$i$$$-th element of the array $$$a$$$.\nThe third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \\ldots, b_n$$$ ($$$1 \\le b_i \\le 10\\,000$$$) where $$$b_i$$$ is the $$$i$$$-th element of the array $$$b$$$.\nOutput\nFor each test case, print a single integer, the\nminimum\npossible value of $$$\\max(a_1, a_2, \\ldots, a_n) \\cdot \\max(b_1, b_2, \\ldots, b_n)$$$ you can get after applying such operation any number of times.\nExample\nInput\n3\n6\n1 2 6 5 1 2\n3 4 3 2 2 5\n3\n3 3 3\n3 3 3\n2\n1 2\n2 1\nOutput\n18\n9\n2\nNote\nIn the first test, you can apply the operations at indices $$$2$$$ and $$$6$$$, then $$$a = [1, 4, 6, 5, 1, 5]$$$ and $$$b = [3, 2, 3, 2, 2, 2]$$$, $$$\\max(1, 4, 6, 5, 1, 5) \\cdot \\max(3, 2, 3, 2, 2, 2) = 6 \\cdot 3 = 18$$$.\nIn the second test, no matter how you apply the operations, $$$a = [3, 3, 3]$$$ and $$$b = [3, 3, 3]$$$ will always hold, so the answer is $$$\\max(3, 3, 3) \\cdot \\max(3, 3, 3) = 3 \\cdot 3 = 9$$$.\nIn the third test, you can apply the operation at index $$$1$$$, then $$$a = [2, 2]$$$, $$$b = [1, 1]$$$, so the answer is $$$\\max(2, 2) \\cdot \\max(1, 1) = 2 \\cdot 1 = 2$$$.", "input": [ [ [ "6" ], [ "1", "2", "6", "5", "1", "2" ], [ "3", "4", "3", "2", "2", "5" ] ], [ [ "3" ], [ "3", "3", "3" ], [ "3", "3", "3" ] ], [ [ "2" ], [ "1", "2" ], [ "2", "1" ] ] ], "output": [ "18", "9", "2" ] }, { "problem_id": "1629B", "problem_name": "GCD Arrays\ngreedy, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1629/B", "problem_solution_link": "https://codeforces.com/problemset/status/1629/problem/B", "problem_statement": "B. GCD Arrays\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nConsider the array $$$a$$$ composed of all the integers in the range $$$[l, r]$$$. For example, if $$$l = 3$$$ and $$$r = 7$$$, then $$$a = [3, 4, 5, 6, 7]$$$.\nGiven $$$l$$$, $$$r$$$, and $$$k$$$, is it possible for $$$\\gcd(a)$$$ to be greater than $$$1$$$ after doing the following operation at most $$$k$$$ times?\nChoose $$$2$$$ numbers from $$$a$$$.\nPermanently remove one occurrence of each of them from the array.\nInsert their product back into $$$a$$$.\n$$$\\gcd(b)$$$ denotes the\ngreatest common divisor (GCD)\nof the integers in $$$b$$$.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^5$$$) \u2014 the number of test cases. The description of test cases follows.\nThe input for each test case consists of a single line containing $$$3$$$ non-negative integers $$$l$$$, $$$r$$$, and $$$k$$$ ($$$1 \\leq l \\leq r \\leq 10^9, \\enspace 0 \\leq k \\leq r - l$$$).\nOutput\nFor each test case, print \"\nYES\n\" if it is possible to have the GCD of the corresponding array greater than $$$1$$$ by performing at most $$$k$$$ operations, and \"\nNO\n\" otherwise (case insensitive).\nExample\nInput\n9\n1 1 0\n3 5 1\n13 13 0\n4 4 0\n3 7 4\n4 10 3\n2 4 0\n1 7 3\n1 5 3\nOutput\nNO\nNO\nYES\nYES\nYES\nYES\nNO\nNO\nYES\nNote\nFor the first test case, $$$a = [1]$$$, so the answer is \"\nNO\n\", since the only element in the array is $$$1$$$.\nFor the second test case the array is $$$a = [3, 4, 5]$$$ and we have $$$1$$$ operation. After the first operation the array can change to: $$$[3, 20]$$$, $$$[4, 15]$$$ or $$$[5, 12]$$$ all of which having their greatest common divisor equal to $$$1$$$ so the answer is \"\nNO\n\".\nFor the third test case, $$$a = [13]$$$, so the answer is \"\nYES\n\", since the only element in the array is $$$13$$$.\nFor the fourth test case, $$$a = [4]$$$, so the answer is \"\nYES\n\", since the only element in the array is $$$4$$$.", "input": [ [ [ "1", "1", "0" ] ], [ [ "3", "5", "1" ] ], [ [ "13", "13", "0" ] ], [ [ "4", "4", "0" ] ], [ [ "3", "7", "4" ] ], [ [ "4", "10", "3" ] ], [ [ "2", "4", "0" ] ], [ [ "1", "7", "3" ] ], [ [ "1", "5", "3" ] ] ], "output": [ "NO", "NO", "YES", "YES", "YES", "YES", "NO", "NO", "YES" ] }, { "problem_id": "1629A", "problem_name": "Download More RAM\nbrute force, greedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1629/A", "problem_solution_link": "https://codeforces.com/problemset/status/1629/problem/A", "problem_statement": "A. Download More RAM\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nDid you know you can download more RAM? There is a shop with $$$n$$$ different pieces of software that increase your RAM. The $$$i$$$-th RAM increasing software takes $$$a_i$$$ GB of memory to run (\ntemporarily, once the program is done running, you get the RAM back\n), and gives you an additional $$$b_i$$$ GB of RAM (permanently).\nEach software can only be used once.\nYour PC currently has $$$k$$$ GB of RAM.\nNote that you can't use a RAM-increasing software if it takes more GB of RAM to use than what you currently have.\nSince RAM is the most important thing in the world, you wonder, what is the maximum possible amount of RAM achievable?\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases. The description of test cases follows.\nThe first line of each test case contains the integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 100$$$, $$$1 \\le k \\le 1000$$$). Then two lines follow, each containing $$$n$$$ integers describing the arrays $$$a$$$ and $$$b$$$ ($$$1 \\le a_i, b_i \\le 1000$$$).\nOutput\nFor each test case, output a single line containing the largest amount of RAM you can achieve.\nExample\nInput\n4\n3 10\n20 30 10\n9 100 10\n5 1\n1 1 5 1 1\n1 1 1 1 1\n5 1\n2 2 2 2 2\n100 100 100 100 100\n5 8\n128 64 32 16 8\n128 64 32 16 8\nOutput\n29\n6\n1\n256\nNote\nIn the first test case, you only have enough RAM to run the third software initially, but that increases your RAM to $$$20$$$ GB, which allows you to use the first software, increasing your RAM to $$$29$$$ GB. The only software left needs $$$30$$$ GB of RAM, so you have to stop here.\nIn the second test case, you can use the first, second, fourth and fifth software that need only $$$1$$$ GB of RAM per software to run to increase your RAM to $$$5$$$ GB, and then use the last remaining one to increase your RAM to $$$6$$$ GB.\nIn the third test case, all the software need more than $$$1$$$ GB of RAM to run, so the amount of RAM you have stays at $$$1$$$ GB.", "input": [ [ [ "3", "10" ], [ "20", "30", "10" ], [ "9", "100", "10" ] ], [ [ "5", "1" ], [ "1", "1", "5", "1", "1" ], [ "1", "1", "1", "1", "1" ] ], [ [ "5", "1" ], [ "2", "2", "2", "2", "2" ], [ "100", "100", "100", "100", "100" ] ], [ [ "5", "8" ], [ "128", "64", "32", "16", "8" ], [ "128", "64", "32", "16", "8" ] ] ], "output": [ "29", "6", "1", "256" ] }, { "problem_id": "1627A", "problem_name": "Not Shading\nconstructive algorithms, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1627/A", "problem_solution_link": "https://codeforces.com/problemset/status/1627/problem/A", "problem_statement": "A. Not Shading\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a grid with $$$n$$$ rows and $$$m$$$ columns. Some cells are colored black, and the rest of the cells are colored white.\nIn one operation, you can select some\nblack\ncell and do\nexactly one\nof the following:\ncolor all cells in its row black, or\ncolor all cells in its column black.\nYou are given two integers $$$r$$$ and $$$c$$$. Find the minimum number of operations required to make the cell in row $$$r$$$ and column $$$c$$$ black, or determine that it is impossible.\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains four integers $$$n$$$, $$$m$$$, $$$r$$$, and $$$c$$$ ($$$1 \\leq n, m \\leq 50$$$; $$$1 \\leq r \\leq n$$$; $$$1 \\leq c \\leq m$$$)\u00a0\u2014 the number of rows and the number of columns in the grid, and the row and column of the cell you need to turn black, respectively.\nThen $$$n$$$ lines follow, each containing $$$m$$$ characters. Each of these characters is either '\nB\n' or '\nW\n'\u00a0\u2014 a black and a white cell, respectively.\nOutput\nFor each test case, if it is impossible to make the cell in row $$$r$$$ and column $$$c$$$ black, output $$$-1$$$.\nOtherwise, output a single integer\u00a0\u2014 the minimum number of operations required to make the cell in row $$$r$$$ and column $$$c$$$ black.\nExample\nInput\n9\n3 5 1 4\nWBWWW\nBBBWB\nWWBBB\n4 3 2 1\nBWW\nBBW\nWBB\nWWB\n2 3 2 2\nWWW\nWWW\n2 2 1 1\nWW\nWB\n5 9 5 9\nWWWWWWWWW\nWBWBWBBBW\nWBBBWWBWW\nWBWBWBBBW\nWWWWWWWWW\n1 1 1 1\nB\n1 1 1 1\nW\n1 2 1 1\nWB\n2 1 1 1\nW\nB\nOutput\n1\n0\n-1\n2\n2\n0\n-1\n1\n1\nNote\nThe first test case is pictured below.\nWe can take the black cell in row $$$1$$$ and column $$$2$$$, and make all cells in its row black. Therefore, the cell in row $$$1$$$ and column $$$4$$$ will become black.\nIn the second test case, the cell in row $$$2$$$ and column $$$1$$$ is already black.\nIn the third test case, it is impossible to make the cell in row $$$2$$$ and column $$$2$$$ black.\nThe fourth test case is pictured below.\nWe can take the black cell in row $$$2$$$ and column $$$2$$$ and make its column black.\nThen, we can take the black cell in row $$$1$$$ and column $$$2$$$ and make its row black.\nTherefore, the cell in row $$$1$$$ and column $$$1$$$ will become black.", "input": [ [ "5", "9", "5", "9" ], [ "WWWWWWWWW", "WBWBWBBBW", "WBBBWWBWW", "WBWBWBBBW", "WWWWWWWWW" ] ], "output": [ "2" ] }, { "problem_id": "1626A", "problem_name": "Equidistant Letters\nconstructive algorithms, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1626/A", "problem_solution_link": "https://codeforces.com/problemset/status/1626/problem/A", "problem_statement": "A. Equidistant Letters\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a string $$$s$$$, consisting of lowercase Latin letters. Every letter appears in it no more than twice.\nYour task is to rearrange the letters in the string in such a way that for each pair of letters that appear exactly twice, the distance between the letters in the pair is the same. You are not allowed to add or remove letters.\nIt can be shown that the answer always exists. If there are multiple answers, print any of them.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^3$$$)\u00a0\u2014 the number of testcases.\nEach testcase consists of a non-empty string $$$s$$$, consisting of lowercase Latin letters. Every letter appears in the string no more than twice. The length of the string doesn't exceed $$$52$$$.\nOutput\nFor each testcase, print a single string. Every letter should appear in it the same number of times as it appears in string $$$s$$$. For each pair of letters that appear exactly twice, the distance between the letters in the pair should be the same.\nIf there are multiple answers, print any of them.\nExample\nInput\n3\noelhl\nabcdcba\nac\nOutput\nhello\nababcdc\nac\nNote\nIn the first testcase of the example, the only letter that appears exactly twice is letter 'l'. You can rearrange the letters arbitrarily, since there are no distances to compare.\nIn the second testcase of the example, the letters that appear exactly twice are 'a', 'b' and 'c'. Initially, letters 'a' are distance $$$6$$$ apart, letters 'b' are distance $$$4$$$ apart and letters 'c' are distance $$$2$$$ apart. They are not the same, so we have to rearrange the letters. After rearrangement, letters 'a' are distance $$$2$$$ apart, letters 'b' are distance $$$2$$$ apart and letters 'c' are distance $$$2$$$ apart. They are all the same, so the answer is valid.\nIn the third testcase of the example, there are no letters that appear exactly twice. Thus, any rearrangement is valid. Including not changing the string at all.", "input": [ [ [ "oelhl" ] ], [ [ "abcdcba" ] ], [ [ "ac" ] ] ], "output": [ "hello", "ababcdc", "ac" ] }, { "problem_id": "1625A", "problem_name": "Ancient Civilization\nbitmasks, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1625/A", "problem_solution_link": "https://codeforces.com/problemset/status/1625/problem/A", "problem_statement": "A. Ancient Civilization\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMartian scientists explore Ganymede, one of Jupiter's numerous moons. Recently, they have found ruins of an ancient civilization. The scientists brought to Mars some tablets with writings in a language unknown to science.\nThey found out that the inhabitants of Ganymede used an alphabet consisting of two letters, and each word was exactly $$$\\ell$$$ letters long. So, the scientists decided to write each word of this language as an integer from $$$0$$$ to $$$2^{\\ell} - 1$$$ inclusively. The first letter of the alphabet corresponds to zero bit in this integer, and the second letter corresponds to one bit.\nThe same word may have various forms in this language. Then, you need to restore the initial form. The process of doing it is described below.\nDenote the\ndistance\nbetween two words as the amount of positions, in which these words differ. For example, the distance between $$$1001_2$$$ and $$$1100_2$$$ (in binary) is equal to two, as these words have different letters in the second and the fourth positions, counting from left to right. Further, denote the distance between words $$$x$$$ and $$$y$$$ as $$$d(x, y)$$$.\nLet the word have $$$n$$$ forms, the $$$i$$$-th of which is described with an integer $$$x_i$$$. All the $$$x_i$$$ are not necessarily different, as two various forms of the word can be written the same. Consider some word $$$y$$$. Then,\ncloseness\nof the word $$$y$$$ is equal to the sum of distances to each of the word forms, i.\u00a0e. the sum $$$d(x_i, y)$$$ over all $$$1 \\le i \\le n$$$.\nThe initial form is the word $$$y$$$ with minimal possible nearness.\nYou need to help the scientists and write the program which finds the initial form of the word given all its known forms. Note that the initial form is\nnot necessarily\nequal to any of the $$$n$$$ given forms.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases. The following are descriptions of the test cases.\nThe first line contains two integers $$$n$$$ and $$$\\ell$$$ ($$$1 \\le n \\le 100$$$, $$$1 \\le \\ell \\le 30$$$) \u2014 the amount of word forms, and the number of letters in one word.\nThe second line contains $$$n$$$ integers $$$x_i$$$ ($$$0 \\le x_i \\le 2^\\ell - 1$$$) \u2014 word forms. The integers are not necessarily different.\nOutput\nFor each test, print a single integer, the initial form of the word, i.\u00a0e. such $$$y$$$ ($$$0 \\le y \\le 2^\\ell - 1$$$) that the sum $$$d(x_i, y)$$$ over all $$$1 \\le i \\le n$$$ is minimal possible. Note that $$$y$$$ can differ from all the integers $$$x_i$$$.\nIf there are multiple ways to restore the initial form, print any.\nExample\nInput\n7\n3 5\n18 9 21\n3 5\n18 18 18\n1 1\n1\n5 30\n1 2 3 4 5\n6 10\n99 35 85 46 78 55\n2 1\n0 1\n8 8\n5 16 42 15 83 65 78 42\nOutput\n17\n18\n1\n1\n39\n0\n2\nNote\nIn the first test case, the words can be written as $$$x_1 = 10010_2$$$, $$$x_2 = 01001_2$$$ and $$$x_3 = 10101_2$$$ in binary. Let $$$y = 10001_2$$$. Then, $$$d(x_1, y) = 2$$$ (the difference is in the fourth and the fifth positions), $$$d(x_2, y) = 2$$$ (the difference is in the first and the second positions), $$$d(x_3, y) = 1$$$ (the difference is in the third position). So, the closeness is $$$2 + 2 + 1 = 5$$$. It can be shown that you cannot achieve smaller closeness.\nIn the second test case, all the forms are equal to $$$18$$$ ($$$10010_2$$$ in binary), so the initial form is also $$$18$$$. It's easy to see that closeness is equal to zero in this case.", "input": [ [ [ "3", "5" ], [ "18", "9", "21" ] ], [ [ "3", "5" ], [ "18", "18", "18" ] ], [ [ "1", "1" ], [ "1" ] ], [ [ "5", "30" ], [ "1", "2", "3", "4", "5" ] ], [ [ "6", "10" ], [ "99", "35", "85", "46", "78", "55" ] ], [ [ "2", "1" ], [ "0", "1" ] ], [ [ "8", "8" ], [ "5", "16", "42", "15", "83", "65", "78", "42" ] ] ], "output": [ "17", "18", "1", "1", "39", "0", "2" ] }, { "problem_id": "1624A", "problem_name": "Plus One on the Subset\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1624/A", "problem_solution_link": "https://codeforces.com/problemset/status/1624/problem/A", "problem_statement": "A. Plus One on the Subset\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp got an array of integers $$$a[1 \\dots n]$$$ as a gift. Now he wants to perform a certain number of operations (possibly zero) so that all elements of the array become the same (that is, to become $$$a_1=a_2=\\dots=a_n$$$).\nIn one operation, he can take some indices in the array and increase the elements of the array at those indices by $$$1$$$.\nFor example, let $$$a=[4,2,1,6,2]$$$. He can perform the following operation: select indices 1, 2, and 4 and increase elements of the array in those indices by $$$1$$$. As a result, in one operation, he can get a new state of the array $$$a=[5,3,1,7,2]$$$.\nWhat is the minimum number of operations it can take so that all elements of the array become equal to each other (that is, to become $$$a_1=a_2=\\dots=a_n$$$)?\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u00a0\u2014 the number of test cases in the test.\nThe following are descriptions of the input test cases.\nThe first line of the description of each test case contains one integer $$$n$$$ ($$$1 \\le n \\le 50$$$) \u00a0\u2014 the array $$$a$$$.\nThe second line of the description of each test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$) \u00a0\u2014 elements of the array $$$a$$$.\nOutput\nFor each test case, print one integer \u00a0\u2014 the minimum number of operations to make all elements of the array $$$a$$$ equal.\nExample\nInput\n3\n6\n3 4 2 4 1 2\n3\n1000 1002 998\n2\n12 11\nOutput\n3\n4\n1\nNote\nFirst test case:\n$$$a=[3,4,2,4,1,2]$$$ take $$$a_3, a_5$$$ and perform an operation plus one on them, as a result we get $$$a=[3,4,3,4,2,2]$$$.\n$$$a=[3,4,3,4,2,2]$$$ we take $$$a_1, a_5, a_6$$$ and perform an operation on them plus one, as a result we get $$$a=[4,4,3,4,3,3]$$$.\n$$$a=[4,4,3,4,3,3]$$$ we take $$$a_3, a_5, a_6$$$ and perform an operation on them plus one, as a result we get $$$a=[4,4,4,4,4,4]$$$.\nThere are other sequences of $$$3$$$ operations, after the application of which all elements become equal.\nSecond test case:\n$$$a=[1000,1002,998]$$$ 2 times we take $$$a_1, a_3$$$ and perform an operation plus one on them, as a result we get $$$a=[1002,1002,1000]$$$.\n$$$a=[1002,1002,1000]$$$ also take $$$a_3$$$ 2 times and perform an operation plus one on it, as a result we get $$$a=[1002,1002,1002]$$$.\nThird test case:\n$$$a=[12,11]$$$ take $$$a_2$$$ and perform an operation plus one on it, as a result we get $$$a=[12,12]$$$.", "input": [ [ [ "6" ], [ "3", "4", "2", "4", "1", "2" ] ], [ [ "3" ], [ "1000", "1002", "998" ] ], [ [ "2" ], [ "12", "11" ] ] ], "output": [ "3", "4", "1" ] }, { "problem_id": "1623A", "problem_name": "Robot Cleaner\nbrute force, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1623/A", "problem_solution_link": "https://codeforces.com/problemset/status/1623/problem/A", "problem_statement": "A. Robot Cleaner\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of $$$n$$$ rows and $$$m$$$ columns. The rows of the floor are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and columns of the floor are numbered from $$$1$$$ to $$$m$$$ from left to right. The cell on the intersection of the $$$r$$$-th row and the $$$c$$$-th column is denoted as $$$(r,c)$$$. The initial position of the robot is $$$(r_b, c_b)$$$.\nIn one second, the robot moves by $$$dr$$$ rows and $$$dc$$$ columns, that is, after one second, the robot moves from the cell $$$(r, c)$$$ to $$$(r + dr, c + dc)$$$. Initially $$$dr = 1$$$, $$$dc = 1$$$. If there is a vertical wall (the left or the right walls) in the movement direction, $$$dc$$$ is\nreflected\nbefore the movement, so the new value of $$$dc$$$ is $$$-dc$$$. And if there is a horizontal wall (the upper or lower walls), $$$dr$$$ is\nreflected\nbefore the movement, so the new value of $$$dr$$$ is $$$-dr$$$.\nEach second (including the moment before the robot starts moving), the robot cleans every cell lying in the same row\nor\nthe same column as its position. There is only one dirty cell at $$$(r_d, c_d)$$$. The job of the robot is to clean that dirty cell.\nIllustration for the first example. The blue arc is the robot. The red star is the target dirty cell. Each second the robot cleans a row and a column, denoted by yellow stripes.\nGiven the floor size $$$n$$$ and $$$m$$$, the robot's initial position $$$(r_b, c_b)$$$ and the dirty cell's position $$$(r_d, c_d)$$$, find the time for the robot to do its job.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^4$$$). Description of the test cases follows.\nA test case consists of only one line, containing six integers $$$n$$$, $$$m$$$, $$$r_b$$$, $$$c_b$$$, $$$r_d$$$, and $$$c_d$$$ ($$$1 \\le n, m \\le 100$$$, $$$1 \\le r_b, r_d \\le n$$$, $$$1 \\le c_b, c_d \\le m$$$)\u00a0\u2014 the sizes of the room, the initial position of the robot and the position of the dirt cell.\nOutput\nFor each test case, print an integer \u2014 the time for the robot to clean the dirty cell. We can show that the robot always cleans the dirty cell eventually.\nExample\nInput\n5\n10 10 6 1 2 8\n10 10 9 9 1 1\n9 8 5 6 2 1\n6 9 2 2 5 8\n2 2 1 1 2 1\nOutput\n7\n10\n9\n3\n0\nNote\nIn the first example, the floor has the size of $$$10\\times 10$$$. The initial position of the robot is $$$(6, 1)$$$ and the position of the dirty cell is $$$(2, 8)$$$. See the illustration of this example in the problem statement.\nIn the second example, the floor is the same, but the initial position of the robot is now $$$(9, 9)$$$, and the position of the dirty cell is $$$(1, 1)$$$. In this example, the robot went straight to the dirty cell and clean it.\nIn the third example, the floor has the size $$$9 \\times 8$$$. The initial position of the robot is $$$(5, 6)$$$, and the position of the dirty cell is $$$(2, 1)$$$.\nIn the fourth example, the floor has the size $$$6 \\times 9$$$. The initial position of the robot is $$$(2, 2)$$$ and the position of the dirty cell is $$$(5, 8)$$$.\nIn the last example, the robot was already standing in the same column as the dirty cell, so it can clean the cell right away.", "input": [ [ [ "10", "10", "6", "1", "2", "8" ] ], [ [ "10", "10", "9", "9", "1", "1" ] ], [ [ "9", "8", "5", "6", "2", "1" ] ], [ [ "6", "9", "2", "2", "5", "8" ] ], [ [ "2", "2", "1", "1", "2", "1" ] ] ], "output": [ "7", "10", "9", "3", "0" ] }, { "problem_id": "1622A", "problem_name": "Construct a Rectangle\ngeometry, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1622/A", "problem_solution_link": "https://codeforces.com/problemset/status/1622/problem/A", "problem_statement": "A. Construct a Rectangle\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are three sticks with integer lengths $$$l_1, l_2$$$ and $$$l_3$$$.\nYou are asked to break exactly one of them into two pieces in such a way that:\nboth pieces have positive (strictly greater than $$$0$$$)\ninteger\nlength;\nthe total length of the pieces is equal to the original length of the stick;\nit's possible to construct a rectangle from the resulting four sticks such that each stick is used as exactly one of its sides.\nA square is also considered a rectangle.\nDetermine if it's possible to do that.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of testcases.\nThe only line of each testcase contains three integers $$$l_1, l_2, l_3$$$ ($$$1 \\le l_i \\le 10^8$$$)\u00a0\u2014 the lengths of the sticks.\nOutput\nFor each testcase, print \"\nYES\n\" if it's possible to break one of the sticks into two pieces with positive integer length in such a way that it's possible to construct a rectangle from the resulting four sticks. Otherwise, print \"\nNO\n\".\nYou may print every letter in any case you want (so, for example, the strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nare all recognized as a positive answer).\nExample\nInput\n4\n6 1 5\n2 5 2\n2 4 2\n5 5 4\nOutput\nYES\nNO\nYES\nYES\nNote\nIn the first testcase, the first stick can be broken into parts of length $$$1$$$ and $$$5$$$. We can construct a rectangle with opposite sides of length $$$1$$$ and $$$5$$$.\nIn the second testcase, breaking the stick of length $$$2$$$ can only result in sticks of lengths $$$1, 1, 2, 5$$$, which can't be made into a rectangle. Breaking the stick of length $$$5$$$ can produce results $$$2, 3$$$ or $$$1, 4$$$ but neither of them can't be put into a rectangle.\nIn the third testcase, the second stick can be broken into parts of length $$$2$$$ and $$$2$$$. The resulting rectangle has opposite sides $$$2$$$ and $$$2$$$ (which is a square).\nIn the fourth testcase, the third stick can be broken into parts of length $$$2$$$ and $$$2$$$. The resulting rectangle has opposite sides $$$2$$$ and $$$5$$$.", "input": [ [ [ "6", "1", "5" ] ], [ [ "2", "5", "2" ] ], [ [ "2", "4", "2" ] ], [ [ "5", "5", "4" ] ] ], "output": [ "YES", "NO", "YES", "YES" ] }, { "problem_id": "1621A", "problem_name": "Stable Arrangement of Rooks\nconstructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1621/A", "problem_solution_link": "https://codeforces.com/problemset/status/1621/problem/A", "problem_statement": "A. Stable Arrangement of Rooks\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have an $$$n \\times n$$$ chessboard and $$$k$$$ rooks. Rows of this chessboard are numbered by integers from $$$1$$$ to $$$n$$$ from top to bottom and columns of this chessboard are numbered by integers from $$$1$$$ to $$$n$$$ from left to right. The cell $$$(x, y)$$$ is the cell on the intersection of row $$$x$$$ and collumn $$$y$$$ for $$$1 \\leq x \\leq n$$$ and $$$1 \\leq y \\leq n$$$.\nThe arrangement of rooks on this board is called\ngood\n, if no rook is beaten by another rook.\nA rook beats all the rooks that shares the same row or collumn with it.\nThe\ngood\narrangement of rooks on this board is called\nnot stable\n, if it is possible to move one rook to the adjacent cell so arrangement becomes not good. Otherwise, the\ngood\narrangement is\nstable\n. Here, adjacent cells are the cells\nthat share a side\n.\nSuch arrangement of $$$3$$$ rooks on the $$$4 \\times 4$$$ chessboard is good, but it is not stable: the rook from $$$(1, 1)$$$ can be moved to the adjacent cell $$$(2, 1)$$$ and rooks on cells $$$(2, 1)$$$ and $$$(2, 4)$$$ will beat each other.\nPlease, find any stable arrangement of $$$k$$$ rooks on the $$$n \\times n$$$ chessboard or report that there is no such arrangement.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \\leq k \\leq n \\leq 40$$$)\u00a0\u2014 the size of the chessboard and the number of rooks.\nOutput\nIf there is a stable arrangement of $$$k$$$ rooks on the $$$n \\times n$$$ chessboard, output $$$n$$$ lines of symbols\n.\nand\nR\n. The $$$j$$$-th symbol of the $$$i$$$-th line should be equals\nR\nif and only if there is a rook on the cell $$$(i, j)$$$ in your arrangement.\nIf there are multiple solutions, you may output any of them.\nIf there is no stable arrangement, output $$$-1$$$.\nExample\nInput\n5\n3 2\n3 3\n1 1\n5 2\n40 33\nOutput\n..R\n...\nR..\n-1\nR\n.....\nR....\n.....\n....R\n.....\n-1\nNote\nIn the first test case, you should find stable arrangement of $$$2$$$ rooks on the $$$3 \\times 3$$$ chessboard. Placing them in cells $$$(3, 1)$$$ and $$$(1, 3)$$$ gives stable arrangement.\nIn the second test case it can be shown that it is impossbile to place $$$3$$$ rooks on the $$$3 \\times 3$$$ chessboard to get stable arrangement.", "input": [ [ [ "3", "2" ] ], [ [ "3", "3" ] ], [ [ "1", "1" ] ], [ [ "5", "2" ] ], [ [ "40", "33" ] ] ], "output": [ ["..R", "...", "R.."], ["-1"], ["R"], [".....", "R....", ".....", "....R", "....."], ["-1"] ], "error": true }, { "problem_id": "1620A", "problem_name": "Equal or Not Equal\nconstructive algorithms, dsu, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1620/A", "problem_solution_link": "https://codeforces.com/problemset/status/1620/problem/A", "problem_statement": "A. Equal or Not Equal\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou had $$$n$$$ positive integers $$$a_1, a_2, \\dots, a_n$$$ arranged\nin a circle\n. For each pair of neighboring numbers ($$$a_1$$$ and $$$a_2$$$, $$$a_2$$$ and $$$a_3$$$, ..., $$$a_{n - 1}$$$ and $$$a_n$$$, and $$$a_n$$$ and $$$a_1$$$), you wrote down: are the numbers in the pair equal or not.\nUnfortunately, you've lost a piece of paper with the array $$$a$$$. Moreover, you are afraid that even information about equality of neighboring elements may be inconsistent. So, you are wondering: is there any array $$$a$$$ which is consistent with information you have about equality or non-equality of corresponding pairs?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases. Next $$$t$$$ cases follow.\nThe first and only line of each test case contains a non-empty string $$$s$$$ consisting of characters\nE\nand/or\nN\n. The length of $$$s$$$ is equal to the size of array $$$n$$$ and $$$2 \\le n \\le 50$$$. For each $$$i$$$ from $$$1$$$ to $$$n$$$:\nif $$$s_i =$$$\nE\nthen $$$a_i$$$ is equal to $$$a_{i + 1}$$$ ($$$a_n = a_1$$$ for $$$i = n$$$);\nif $$$s_i =$$$\nN\nthen $$$a_i$$$ is not equal to $$$a_{i + 1}$$$ ($$$a_n \\neq a_1$$$ for $$$i = n$$$).\nOutput\nFor each test case, print\nYES\nif it's possible to choose array $$$a$$$ that are consistent with information from $$$s$$$ you know. Otherwise, print\nNO\n.\nIt can be proved, that if there exists some array $$$a$$$, then there exists an array $$$a$$$ of positive integers with values less or equal to $$$10^9$$$.\nExample\nInput\n4\nEEE\nEN\nENNEENE\nNENN\nOutput\nYES\nNO\nYES\nYES\nNote\nIn the first test case, you can choose, for example, $$$a_1 = a_2 = a_3 = 5$$$.\nIn the second test case, there is no array $$$a$$$, since, according to $$$s_1$$$, $$$a_1$$$ is equal to $$$a_2$$$, but, according to $$$s_2$$$, $$$a_2$$$ is not equal to $$$a_1$$$.\nIn the third test case, you can, for example, choose array $$$a = [20, 20, 4, 50, 50, 50, 20]$$$.\nIn the fourth test case, you can, for example, choose $$$a = [1, 3, 3, 7]$$$.", "input": [ [ [ "EEE" ] ], [ [ "EN" ] ], [ [ "ENNEENE" ] ], [ [ "NENN" ] ] ], "output": [ "YES", "NO", "YES", "YES" ] }, { "problem_id": "1619B", "problem_name": "Squares and Cubes\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1619/B", "problem_solution_link": "https://codeforces.com/problemset/status/1619/problem/B", "problem_statement": "B. Squares and Cubes\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp likes squares and cubes of positive integers. Here is the beginning of the sequence of numbers he likes: $$$1$$$, $$$4$$$, $$$8$$$, $$$9$$$, ....\nFor a given number $$$n$$$, count the number of integers from $$$1$$$ to $$$n$$$ that Polycarp likes. In other words, find the number of such $$$x$$$ that $$$x$$$ is a square of a positive integer number or a cube of a positive integer number (or both a square and a cube simultaneously).\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 20$$$) \u2014 the number of test cases.\nThen $$$t$$$ lines contain the test cases, one per line. Each of the lines contains one integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$).\nOutput\nFor each test case, print the answer you are looking for \u2014 the number of integers from $$$1$$$ to $$$n$$$ that Polycarp likes.\nExample\nInput\n6\n10\n1\n25\n1000000000\n999999999\n500000000\nOutput\n4\n1\n6\n32591\n32590\n23125", "input": [ [ [ "10" ] ], [ [ "1" ] ], [ [ "25" ] ], [ [ "1000000000" ] ], [ [ "999999999" ] ], [ [ "500000000" ] ] ], "output": [ "4", "1", "6", "32591", "32590", "23125" ] }, { "problem_id": "1619A", "problem_name": "Square String?\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1619/A", "problem_solution_link": "https://codeforces.com/problemset/status/1619/problem/A", "problem_statement": "A. Square String?\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA string is called\nsquare\nif it is some string written twice in a row. For example, the strings \"\naa\n\", \"\nabcabc\n\", \"\nabab\n\" and \"\nbaabaa\n\" are square. But the strings \"\naaa\n\", \"\nabaaab\n\" and \"\nabcdabc\n\" are not square.\nFor a given string $$$s$$$ determine if it is square.\nInput\nThe first line of input data contains an integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014the number of test cases.\nThis is followed by $$$t$$$ lines, each containing a description of one test case. The given strings consist only of lowercase Latin letters and have lengths between $$$1$$$ and $$$100$$$ inclusive.\nOutput\nFor each test case, output on a separate line:\nYES\nif the string in the corresponding test case is square,\nNO\notherwise.\nYou can output\nYES\nand\nNO\nin any case (for example, strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as a positive response).\nExample\nInput\n10\na\naa\naaa\naaaa\nabab\nabcabc\nabacaba\nxxyy\nxyyx\nxyxy\nOutput\nNO\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES", "input": [ [ [ "abab" ] ], [ [ "abcabc" ] ], [ [ "abacaba" ] ] ], "output": [ "YES", "YES", "NO" ] }, { "problem_id": "1618B", "problem_name": "Missing Bigram\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1618/B", "problem_solution_link": "https://codeforces.com/problemset/status/1618/problem/B", "problem_statement": "B. Missing Bigram\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp has come up with a new game to play with you. He calls it \"A missing bigram\".\nA\nbigram\nof a word is a sequence of two adjacent letters in it.\nFor example, word \"\nabbaaba\n\" contains bigrams \"\nab\n\", \"\nbb\n\", \"\nba\n\", \"\naa\n\", \"\nab\n\" and \"\nba\n\".\nThe game goes as follows. First, Polycarp comes up with a word, consisting only of lowercase letters 'a' and 'b'. Then, he writes down all its bigrams on a whiteboard\nin the same order as they appear in the word\n. After that, he wipes one of them off the whiteboard.\nFinally, Polycarp invites you to guess what the word that he has come up with was.\nYour goal is to find any word such that it's possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with.\nThe tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 2000$$$)\u00a0\u2014 the number of testcases.\nThe first line of each testcase contains a single integer $$$n$$$ ($$$3 \\le n \\le 100$$$)\u00a0\u2014 the length of the word Polycarp has come up with.\nThe second line of each testcase contains $$$n-2$$$ bigrams of that word, separated by a single space. Each bigram consists of two letters, each of them is either 'a' or 'b'.\nAdditional constraint on the input: there exists at least one string such that it is possible to write down all its bigrams, except one, so that the resulting sequence is the same as the sequence in the input. In other words, the answer exists.\nOutput\nFor each testcase print a word, consisting of $$$n$$$ letters, each of them should be either 'a' or 'b'. It should be possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with.\nThe tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.\nExample\nInput\n4\n7\nab bb ba aa ba\n7\nab ba aa ab ba\n3\naa\n5\nbb ab bb\nOutput\nabbaaba\nabaabaa\nbaa\nbbabb\nNote\nThe first two testcases from the example are produced from the word \"\nabbaaba\n\". As listed in the statement, it contains bigrams \"\nab\n\", \"\nbb\n\", \"\nba\n\", \"\naa\n\", \"\nab\n\" and \"\nba\n\".\nIn the first testcase, the $$$5$$$-th bigram is removed.\nIn the second testcase, the $$$2$$$-nd bigram is removed. However, that sequence could also have been produced from the word \"\nabaabaa\n\". It contains bigrams \"\nab\n\", \"\nba\n\", \"\naa\n\", \"\nab\n\", \"\nba\n\" and \"\naa\n\". The missing bigram is the $$$6$$$-th one.\nIn the third testcase, all of \"\nbaa\n\", \"\naab\n\" and \"\naaa\n\" are valid answers.", "input": [ [ [ "7" ], [ "ab", "bb", "ba", "aa", "ba" ] ], [ [ "7" ], [ "ab", "ba", "aa", "ab", "ba" ] ], [ [ "3" ], [ "aa" ] ], [ [ "5" ], [ "bb", "ab", "bb" ] ] ], "output": [ "abbaaba", "abaabaa", "baa", "bbabb" ] }, { "problem_id": "1618A", "problem_name": "Polycarp and Sums of Subsequences\nmath, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1618/A", "problem_solution_link": "https://codeforces.com/problemset/status/1618/problem/A", "problem_statement": "A. Polycarp and Sums of Subsequences\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp had an array $$$a$$$ of $$$3$$$\npositive\nintegers. He wrote out the sums of all non-empty subsequences of this array, sorted them in non-decreasing order, and got an array $$$b$$$ of $$$7$$$ integers.\nFor example, if $$$a = \\{1, 4, 3\\}$$$, then Polycarp wrote out $$$1$$$, $$$4$$$, $$$3$$$, $$$1 + 4 = 5$$$, $$$1 + 3 = 4$$$, $$$4 + 3 = 7$$$, $$$1 + 4 + 3 = 8$$$. After sorting, he got an array $$$b = \\{1, 3, 4, 4, 5, 7, 8\\}.$$$\nUnfortunately, Polycarp lost the array $$$a$$$. He only has the array $$$b$$$ left. Help him to restore the array $$$a$$$.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 5000$$$) \u2014 the number of test cases.\nEach test case consists of one line which contains $$$7$$$ integers $$$b_1, b_2, \\dots, b_7$$$ ($$$1 \\le b_i \\le 10^9$$$; $$$b_i \\le b_{i+1}$$$).\nAdditional constraint on the input: there exists at least one array $$$a$$$ which yields this array $$$b$$$ as described in the statement\n.\nOutput\nFor each test case, print $$$3$$$ integers \u2014 $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$. If there can be several answers, print any of them.\nExample\nInput\n5\n1 3 4 4 5 7 8\n1 2 3 4 5 6 7\n300000000 300000000 300000000 600000000 600000000 600000000 900000000\n1 1 2 999999998 999999999 999999999 1000000000\n1 2 2 3 3 4 5\nOutput\n1 4 3\n4 1 2\n300000000 300000000 300000000\n999999998 1 1\n1 2 2\nNote\nThe subsequence of the array $$$a$$$ is a sequence that can be obtained from $$$a$$$ by removing zero or more of its elements.\nTwo subsequences are considered different if index sets of elements included in them are different. That is, the values of the elements don't matter in the comparison of subsequences. In particular, any array of length $$$3$$$ has exactly $$$7$$$ different non-empty subsequences.", "input": [ [ [ "1", "3", "4", "4", "5", "7", "8" ] ], [ [ "1", "2", "3", "4", "5", "6", "7" ] ], [ [ "300000000", "300000000", "300000000", "600000000", "600000000", "600000000", "900000000" ] ], [ [ "1", "1", "2", "999999998", "999999999", "999999999", "1000000000" ] ], [ [ "1", "2", "2", "3", "3", "4", "5" ] ] ], "output": [ "1 4 3", "4 1 2", "300000000 300000000 300000000", "999999998 1 1", "1 2 2" ] }, { "problem_id": "1617A", "problem_name": "Forbidden Subsequence\nconstructive algorithms, greedy, sortings, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1617/A", "problem_solution_link": "https://codeforces.com/problemset/status/1617/problem/A", "problem_statement": "A. Forbidden Subsequence\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given strings $$$S$$$ and $$$T$$$, consisting of lowercase English letters. It is guaranteed that $$$T$$$ is a permutation of the string\nabc\n.\nFind string $$$S'$$$, the\nlexicographically smallest\npermutation of $$$S$$$ such that $$$T$$$ is\nnot\na subsequence of $$$S'$$$.\nString $$$a$$$ is a\npermutation\nof string $$$b$$$ if the number of occurrences of each distinct character is the same in both strings.\nA string $$$a$$$ is a\nsubsequence\nof a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements.\nA string $$$a$$$ is\nlexicographically smaller\nthan a string $$$b$$$ if and only if one of the following holds:\n$$$a$$$ is a prefix of $$$b$$$, but $$$a \\ne b$$$;\nin the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases. Description of the test cases follows.\nThe first line of each test case contains a string $$$S$$$ ($$$1 \\le |S| \\le 100$$$), consisting of lowercase English letters.\nThe second line of each test case contains a string $$$T$$$ that is a permutation of the string\nabc\n. (Hence, $$$|T| = 3$$$).\nNote that there is no limit on the sum of $$$|S|$$$ across all test cases.\nOutput\nFor each test case, output a single string $$$S'$$$, the lexicographically smallest permutation of $$$S$$$ such that $$$T$$$ is not a subsequence of $$$S'$$$.\nExample\nInput\n7\nabacaba\nabc\ncccba\nacb\ndbsic\nbac\nabracadabra\nabc\ndddddddddddd\ncba\nbbc\nabc\nac\nabc\nOutput\naaaacbb\nabccc\nbcdis\naaaaacbbdrr\ndddddddddddd\nbbc\nac\nNote\nIn the first test case, both\naaaabbc\nand\naaaabcb\nare lexicographically smaller than\naaaacbb\n, but they contain\nabc\nas a subsequence.\nIn the second test case,\nabccc\nis the smallest permutation of\ncccba\nand does not contain\nacb\nas a subsequence.\nIn the third test case,\nbcdis\nis the smallest permutation of\ndbsic\nand does not contain\nbac\nas a subsequence.", "input": [ [ [ "abacaba" ], [ "abc" ] ], [ [ "cccba" ], [ "acb" ] ], [ [ "dbsic" ], [ "bac" ] ], [ [ "abracadabra" ], [ "abc" ] ], [ [ "dddddddddddd" ], [ "cba" ] ], [ [ "bbc" ], [ "abc" ] ], [ [ "ac" ], [ "abc" ] ] ], "output": [ "aaaacbb", "abccc", "bcdis", "aaaaacbbdrr", "dddddddddddd", "bbc", "ac" ] }, { "problem_id": "1616A", "problem_name": "Integer Diversity\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1616/A", "problem_solution_link": "https://codeforces.com/problemset/status/1616/problem/A", "problem_statement": "A. Integer Diversity\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$. You choose any subset of the given numbers (possibly, none or all numbers) and negate these numbers (i.\u00a0e. change $$$x \\to (-x)$$$). What is the maximum number of different values in the array you can achieve?\nInput\nThe first line of input contains one integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$): the number of test cases.\nThe next lines contain the description of the $$$t$$$ test cases, two lines per a test case.\nIn the first line you are given one integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$): the number of integers in the array.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$-100 \\leq a_i \\leq 100$$$).\nOutput\nFor each test case, print one integer: the maximum number of different elements in the array that you can achieve negating numbers in the array.\nExample\nInput\n3\n4\n1 1 2 2\n3\n1 2 3\n2\n0 0\nOutput\n4\n3\n1\nNote\nIn the first example we can, for example, negate the first and the last numbers, achieving the array $$$[-1, 1, 2, -2]$$$ with four different values.\nIn the second example all three numbers are already different.\nIn the third example negation does not change anything.", "input": [ [ [ "4" ], [ "1", "1", "2", "2" ] ], [ [ "3" ], [ "1", "2", "3" ] ], [ [ "2" ], [ "0", "0" ] ] ], "output": [ "4", "3", "1" ] }, { "problem_id": "1615A", "problem_name": "Closing The Gap\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1615/A", "problem_solution_link": "https://codeforces.com/problemset/status/1615/problem/A", "problem_statement": "A. Closing The Gap\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ block towers in a row, where tower $$$i$$$ has a height of $$$a_i$$$. You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the following operation:\nChoose two indices $$$i$$$ and $$$j$$$ ($$$1 \\leq i, j \\leq n$$$; $$$i \\neq j$$$), and move a block from tower $$$i$$$ to tower $$$j$$$. This essentially decreases $$$a_i$$$ by $$$1$$$ and increases $$$a_j$$$ by $$$1$$$.\nYou think the ugliness of the buildings is the height difference between the tallest and shortest buildings. Formally, the ugliness is defined as $$$\\max(a)-\\min(a)$$$.\nWhat's the minimum possible ugliness you can achieve, after any number of days?\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases. Then $$$t$$$ cases follow.\nThe first line of each test case contains one integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$)\u00a0\u2014 the number of buildings.\nThe second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 10^7$$$)\u00a0\u2014 the heights of the buildings.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the minimum possible ugliness of the buildings.\nExample\nInput\n3\n3\n10 10 10\n4\n3 2 1 2\n5\n1 2 3 1 5\nOutput\n0\n0\n1\nNote\nIn the first test case, the ugliness is already $$$0$$$.\nIn the second test case, you should do one operation, with $$$i = 1$$$ and $$$j = 3$$$. The new heights will now be $$$[2, 2, 2, 2]$$$, with an ugliness of $$$0$$$.\nIn the third test case, you may do three operations:\nwith $$$i = 3$$$ and $$$j = 1$$$. The new array will now be $$$[2, 2, 2, 1, 5]$$$,\nwith $$$i = 5$$$ and $$$j = 4$$$. The new array will now be $$$[2, 2, 2, 2, 4]$$$,\nwith $$$i = 5$$$ and $$$j = 3$$$. The new array will now be $$$[2, 2, 3, 2, 3]$$$.\nThe resulting ugliness is $$$1$$$. It can be proven that this is the minimum possible ugliness for this test.", "input": [ [ [ "3" ], [ "10", "10", "10" ] ], [ [ "4" ], [ "3", "2", "1", "2" ] ], [ [ "5" ], [ "1", "2", "3", "1", "5" ] ] ], "output": [ "0", "0", "1" ] }, { "problem_id": "1614A", "problem_name": "Divan and a Store\nbrute force, constructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1614/A", "problem_solution_link": "https://codeforces.com/problemset/status/1614/problem/A", "problem_statement": "A. Divan and a Store\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nBusinessman\nDivan\nloves chocolate! Today he came to a store to buy some chocolate. Like all businessmen,\nDivan\nknows the value of money, so he will not buy too expensive chocolate. At the same time, too cheap chocolate tastes bad, so he will not buy it as well.\nThe store he came to has $$$n$$$ different chocolate bars, and the price of the $$$i$$$-th chocolate bar is $$$a_i$$$ dollars.\nDivan\nconsiders a chocolate bar too expensive if it costs strictly more than $$$r$$$ dollars. Similarly, he considers a bar of chocolate to be too cheap if it costs strictly less than $$$l$$$ dollars. Divan will not buy too cheap or too expensive bars.\nDivan\nis not going to spend all his money on chocolate bars, so he will spend at most $$$k$$$ dollars on chocolates.\nPlease determine the maximum number of chocolate bars\nDivan\ncan buy.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). Description of the test cases follows.\nThe description of each test case consists of two lines. The first line contains integers $$$n$$$, $$$l$$$, $$$r$$$, $$$k$$$ ($$$1 \\le n \\le 100$$$, $$$1 \\le l \\le r \\le 10^9$$$, $$$1 \\le k \\le 10^9$$$)\u00a0\u2014 the lowest acceptable price of a chocolate, the highest acceptable price of a chocolate and Divan's total budget, respectively.\nThe second line contains a sequence $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$) integers\u00a0\u2014 the prices of chocolate bars in the store.\nOutput\nFor each test case print a single integer \u2014 the maximum number of chocolate bars\nDivan\ncan buy.\nExample\nInput\n8\n3 1 100 100\n50 100 50\n6 3 5 10\n1 2 3 4 5 6\n6 3 5 21\n1 2 3 4 5 6\n10 50 69 100\n20 30 40 77 1 1 12 4 70 10000\n3 50 80 30\n20 60 70\n10 2 7 100\n2 2 2 2 2 7 7 7 7 7\n4 1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n1\nOutput\n2\n2\n3\n0\n0\n10\n1\n1\nNote\nIn the first example\nDivan\ncan buy chocolate bars $$$1$$$ and $$$3$$$ and spend $$$100$$$ dollars on them.\nIn the second example\nDivan\ncan buy chocolate bars $$$3$$$ and $$$4$$$ and spend $$$7$$$ dollars on them.\nIn the third example\nDivan\ncan buy chocolate bars $$$3$$$, $$$4$$$, and $$$5$$$ for $$$12$$$ dollars.\nIn the fourth example\nDivan\ncannot buy any chocolate bar because each of them is either too cheap or too expensive.\nIn the fifth example\nDivan\ncannot buy any chocolate bar because he considers the first bar too cheap, and has no budget for the second or third.\nIn the sixth example\nDivan\ncan buy all the chocolate bars in the shop.", "input": [ [ [ "3", "1", "100", "100" ], [ "50", "100", "50" ] ], [ [ "6", "3", "5", "10" ], [ "1", "2", "3", "4", "5", "6" ] ], [ [ "6", "3", "5", "21" ], [ "1", "2", "3", "4", "5", "6" ] ], [ [ "10", "50", "69", "100" ], [ "20", "30", "40", "77", "1", "1", "12", "4", "70", "10000" ] ], [ [ "3", "50", "80", "30" ], [ "20", "60", "70" ] ], [ [ "10", "2", "7", "100" ], [ "2", "2", "2", "2", "2", "7", "7", "7", "7", "7" ] ], [ [ "4", "1000000000", "1000000000", "1000000000" ], [ "1000000000", "1000000000", "1000000000", "1000000000" ] ], [ [ "1", "1", "1", "1" ], [ "1" ] ] ], "output": [ "2", "2", "3", "0", "0", "10", "1", "1" ] }, { "problem_id": "1612A", "problem_name": "Distance\nbrute force, constructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1612/A", "problem_solution_link": "https://codeforces.com/problemset/status/1612/problem/A", "problem_statement": "A. Distance\ntime limit per test\n3 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's denote the Manhattan distance between two points $$$p_1$$$ (with coordinates $$$(x_1, y_1)$$$) and $$$p_2$$$ (with coordinates $$$(x_2, y_2)$$$) as $$$d(p_1, p_2) = |x_1 - x_2| + |y_1 - y_2|$$$. For example, the distance between two points with coordinates $$$(1, 3)$$$ and $$$(4, 2)$$$ is $$$|1 - 4| + |3 - 2| = 4$$$.\nYou are given two points, $$$A$$$ and $$$B$$$. The point $$$A$$$ has coordinates $$$(0, 0)$$$, the point $$$B$$$ has coordinates $$$(x, y)$$$.\nYour goal is to find a point $$$C$$$ such that:\nboth coordinates of $$$C$$$ are non-negative integers;\n$$$d(A, C) = \\dfrac{d(A, B)}{2}$$$ (without any rounding);\n$$$d(B, C) = \\dfrac{d(A, B)}{2}$$$ (without any rounding).\nFind any point $$$C$$$ that meets these constraints, or report that no such point exists.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 3000$$$) \u2014 the number of test cases.\nEach test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$0 \\le x, y \\le 50$$$) \u2014 the coordinates of the point $$$B$$$.\nOutput\nFor each test case, print the answer on a separate line as follows:\nif it is impossible to find a point $$$C$$$ meeting the constraints, print \"\n-1 -1\n\" (without quotes);\notherwise, print two non-negative integers not exceeding $$$10^6$$$ \u2014 the coordinates of point $$$C$$$ meeting the constraints. If there are multiple answers, print any of them. It can be shown that if any such point exists, it's possible to find a point with coordinates not exceeding $$$10^6$$$ that meets the constraints.\nExample\nInput\n10\n49 3\n2 50\n13 0\n0 41\n42 0\n0 36\n13 37\n42 16\n42 13\n0 0\nOutput\n23 3\n1 25\n-1 -1\n-1 -1\n21 0\n0 18\n13 12\n25 4\n-1 -1\n0 0\nNote\nExplanations for some of the test cases from the example:\nIn the first test case, the point $$$B$$$ has coordinates $$$(49, 3)$$$. If the point $$$C$$$ has coordinates $$$(23, 3)$$$, then the distance from $$$A$$$ to $$$B$$$ is $$$|49 - 0| + |3 - 0| = 52$$$, the distance from $$$A$$$ to $$$C$$$ is $$$|23 - 0| + |3 - 0| = 26$$$, and the distance from $$$B$$$ to $$$C$$$ is $$$|23 - 49| + |3 - 3| = 26$$$.\nIn the second test case, the point $$$B$$$ has coordinates $$$(2, 50)$$$. If the point $$$C$$$ has coordinates $$$(1, 25)$$$, then the distance from $$$A$$$ to $$$B$$$ is $$$|2 - 0| + |50 - 0| = 52$$$, the distance from $$$A$$$ to $$$C$$$ is $$$|1 - 0| + |25 - 0| = 26$$$, and the distance from $$$B$$$ to $$$C$$$ is $$$|1 - 2| + |25 - 50| = 26$$$.\nIn the third and the fourth test cases, it can be shown that no point with integer coordinates meets the constraints.\nIn the fifth test case, the point $$$B$$$ has coordinates $$$(42, 0)$$$. If the point $$$C$$$ has coordinates $$$(21, 0)$$$, then the distance from $$$A$$$ to $$$B$$$ is $$$|42 - 0| + |0 - 0| = 42$$$, the distance from $$$A$$$ to $$$C$$$ is $$$|21 - 0| + |0 - 0| = 21$$$, and the distance from $$$B$$$ to $$$C$$$ is $$$|21 - 42| + |0 - 0| = 21$$$.", "input": [ [ [ "49", "3" ] ], [ [ "2", "50" ] ] ], "output": [ "23 3", "1 25" ] }, { "problem_id": "1611B", "problem_name": "Team Composition: Programmers and Mathematicians\nbinary search, constructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1611/B", "problem_solution_link": "https://codeforces.com/problemset/status/1611/problem/B", "problem_statement": "B. Team Composition: Programmers and Mathematicians\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThe All-Berland Team Programming Contest will take place very soon. This year, teams of four are allowed to participate.\nThere are $$$a$$$ programmers and $$$b$$$ mathematicians at Berland State University. How many maximum teams can be made if:\neach team must consist of exactly $$$4$$$ students,\nteams of $$$4$$$ mathematicians or $$$4$$$ programmers are unlikely to perform well, so the decision was made not to compose such teams.\nThus, each team must have at least one programmer\nand\nat least one mathematician.\nPrint the required maximum number of teams. Each person can be a member of no more than one team.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014the number of test cases.\nThis is followed by descriptions of $$$t$$$ sets, one per line. Each set is given by two integers $$$a$$$ and $$$b$$$ ($$$0 \\le a,b \\le 10^9$$$).\nOutput\nPrint $$$t$$$ lines. Each line must contain the answer to the corresponding set of input data\u00a0\u2014 the required maximum number of teams.\nExample\nInput\n6\n5 5\n10 1\n2 3\n0 0\n17 2\n1000000000 1000000000\nOutput\n2\n1\n1\n0\n2\n500000000\nNote\nIn the first test case of the example, two teams can be composed. One way to compose two teams is to compose two teams of $$$2$$$ programmers and $$$2$$$ mathematicians.\nIn the second test case of the example, only one team can be composed: $$$3$$$ programmers and $$$1$$$ mathematician in the team.", "input": [ [ [ "5", "5" ] ], [ [ "10", "1" ] ], [ [ "2", "3" ] ], [ [ "0", "0" ] ], [ [ "17", "2" ] ], [ [ "1000000000", "1000000000" ] ] ], "output": [ "2", "1", "1", "0", "2", "500000000" ] }, { "problem_id": "1611A", "problem_name": "Make Even\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1611/A", "problem_solution_link": "https://codeforces.com/problemset/status/1611/problem/A", "problem_statement": "A. Make Even\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp has an integer $$$n$$$ that doesn't contain the digit\n0\n. He can do the following operation with his number several (possibly zero) times:\nReverse the prefix of length $$$l$$$ (in other words, $$$l$$$ leftmost digits) of $$$n$$$. So, the leftmost digit is swapped with the $$$l$$$-th digit from the left, the second digit from the left swapped with ($$$l-1$$$)-th left, etc. For example, if $$$n=123456789$$$ and $$$l=5$$$, then the new value of $$$n$$$ will be $$$543216789$$$.\nNote that for different operations, the values of $$$l$$$ can be different. The number $$$l$$$ can be equal to the length of the number $$$n$$$\u00a0\u2014 in this case, the whole number $$$n$$$ is reversed.\nPolycarp loves even numbers. Therefore, he wants to make his number even. At the same time, Polycarp is very impatient. He wants to do as few operations as possible.\nHelp Polycarp. Determine the minimum number of operations he needs to perform with the number $$$n$$$ to make it even or determine that this is impossible.\nYou need to answer $$$t$$$ independent test cases.\nInput\nThe first line contains the number $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nEach of the following $$$t$$$ lines contains one integer $$$n$$$ ($$$1 \\le n < 10^9$$$). It is guaranteed that the given number doesn't contain the digit\n0\n.\nOutput\nPrint $$$t$$$ lines. On each line print one integer\u00a0\u2014 the answer to the corresponding test case. If it is impossible to make an even number, print\n-1\n.\nExample\nInput\n4\n3876\n387\n4489\n3\nOutput\n0\n2\n1\n-1\nNote\nIn the first test case, $$$n=3876$$$, which is already an even number. Polycarp doesn't need to do anything, so the answer is $$$0$$$.\nIn the second test case, $$$n=387$$$. Polycarp needs to do $$$2$$$ operations:\nSelect $$$l=2$$$ and reverse the prefix $$$\\underline{38}7$$$. The number $$$n$$$ becomes $$$837$$$. This number is odd.\nSelect $$$l=3$$$ and reverse the prefix $$$\\underline{837}$$$. The number $$$n$$$ becomes $$$738$$$. This number is even.\nIt can be shown that $$$2$$$ is the minimum possible number of operations that Polycarp needs to do with his number to make it even.\nIn the third test case, $$$n=4489$$$. Polycarp can reverse the whole number (choose a prefix of length $$$l=4$$$). It will become $$$9844$$$ and this is an even number.\nIn the fourth test case, $$$n=3$$$. No matter how hard Polycarp tried, he would not be able to make an even number.", "input": [ [ [ "3876" ] ], [ [ "387" ] ], [ [ "4489" ] ], [ [ "3" ] ] ], "output": [ "0", "2", "1", "-1" ] }, { "problem_id": "1608A", "problem_name": "Find Array\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1608/A", "problem_solution_link": "https://codeforces.com/problemset/status/1608/problem/A", "problem_statement": "A. Find Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven $$$n$$$, find any array $$$a_1, a_2, \\ldots, a_n$$$ of integers such that all of the following conditions hold:\n$$$1 \\le a_i \\le 10^9$$$ for every $$$i$$$ from $$$1$$$ to $$$n$$$.\n$$$a_1 < a_2 < \\ldots 2$$$. We can perform the operation $$$[1, 3, 4] \\rightarrow [1, \\underline{2}, 3, 4]$$$ (the newly inserted element is underlined), now the condition is satisfied.\nIn the second test case, Shohag can perform the following operations:\n$$$[1, 2, 5, 7, 4] \\rightarrow [1, 2, \\underline{3}, 5, 7, 4] \\rightarrow [1, 2, 3, \\underline{4}, 5, 7, 4] \\rightarrow [1, 2, 3, 4, 5, \\underline{3}, 7, 4]$$$.\nIn the third test case, the sequence already satisfies the condition.", "input": [ [ [ "3" ], [ "1", "3", "4" ] ], [ [ "5" ], [ "1", "2", "5", "7", "4" ] ], [ [ "1" ], [ "1" ] ], [ [ "3" ], [ "69", "6969", "696969" ] ] ], "output": [ "1", "3", "0", "696966" ] }, { "problem_id": "1602A", "problem_name": "Two Subsequences\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1602/A", "problem_solution_link": "https://codeforces.com/problemset/status/1602/problem/A", "problem_statement": "A. Two Subsequences\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a string $$$s$$$. You need to find two non-empty strings $$$a$$$ and $$$b$$$ such that the following conditions are satisfied:\nStrings $$$a$$$ and $$$b$$$ are both\nsubsequences\nof $$$s$$$.\nFor each index $$$i$$$, character $$$s_i$$$ of string $$$s$$$ must belong to\nexactly one\nof strings $$$a$$$ or $$$b$$$.\nString $$$a$$$ is\nlexicographically\nminimum possible; string $$$b$$$ may be any possible string.\nGiven string $$$s$$$, print any valid $$$a$$$ and $$$b$$$.\nReminder:\nA string $$$a$$$ ($$$b$$$) is a\nsubsequence\nof a string $$$s$$$ if $$$a$$$ ($$$b$$$) can be obtained from $$$s$$$ by deletion of several (possibly, zero) elements. For example, \"\ndores\n\", \"\ncf\n\", and \"\nfor\n\" are subsequences of \"\ncodeforces\n\", while \"\ndecor\n\" and \"\nfork\n\" are not.\nA string $$$x$$$ is\nlexicographically smaller\nthan a string $$$y$$$ if and only if one of the following holds:\n$$$x$$$ is a prefix of $$$y$$$, but $$$x \\ne y$$$;\nin the first position where $$$x$$$ and $$$y$$$ differ, the string $$$x$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$y$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$). Description of the test cases follows.\nThe first and only line of each test case contains one string $$$s$$$ ($$$2 \\le |s| \\le 100$$$ where $$$|s|$$$ means the length of $$$s$$$). String $$$s$$$ consists of lowercase Latin letters.\nOutput\nFor each test case, print the strings $$$a$$$ and $$$b$$$ that satisfy the given conditions. If there are multiple answers, print any.\nExample\nInput\n3\nfc\naaaa\nthebrightboiler\nOutput\nc f\na aaa\nb therightboiler\nNote\nIn the first test case, there are only two choices: either $$$a =$$$\nf\nand $$$b = $$$\nc\nor $$$a = $$$\nc\nand $$$b = $$$\nf\n. And $$$a = $$$\nc\nis lexicographically smaller than $$$a = $$$\nf\n.\nIn the second test case,\na\nis the only character in the string.\nIn the third test case, it can be proven that\nb\nis the lexicographically smallest subsequence of $$$s$$$. The second string can be of two variants; one of them is given here.", "input": [ [ [ "fc" ] ], [ [ "aaaa" ] ], [ [ "thebrightboiler" ] ] ], "output": [ "c f", "a aaa", "b therightboiler" ] }, { "problem_id": "1598A", "problem_name": "Computer Game\nbrute force, dfs and similar, dp, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1598/A", "problem_solution_link": "https://codeforces.com/problemset/status/1598/problem/A", "problem_statement": "A. Computer Game\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMonocarp is playing a computer game. Now he wants to complete the first level of this game.\nA level is a rectangular grid of $$$2$$$ rows and $$$n$$$ columns. Monocarp controls a character, which starts in cell $$$(1, 1)$$$\u00a0\u2014 at the intersection of the $$$1$$$-st row and the $$$1$$$-st column.\nMonocarp's character can move from one cell to another in one step if the cells are adjacent by side and/or corner. Formally, it is possible to move from cell $$$(x_1, y_1)$$$ to cell $$$(x_2, y_2)$$$ in one step if $$$|x_1 - x_2| \\le 1$$$ and $$$|y_1 - y_2| \\le 1$$$. Obviously, it is prohibited to go outside the grid.\nThere are traps in some cells. If Monocarp's character finds himself in such a cell, he dies, and the game ends.\nTo complete a level, Monocarp's character should reach cell $$$(2, n)$$$\u00a0\u2014 at the intersection of row $$$2$$$ and column $$$n$$$.\nHelp Monocarp determine if it is possible to complete the level.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases. Then the test cases follow. Each test case consists of three lines.\nThe first line contains a single integer $$$n$$$ ($$$3 \\le n \\le 100$$$)\u00a0\u2014 the number of columns.\nThe next two lines describe the level. The $$$i$$$-th of these lines describes the $$$i$$$-th line of the level\u00a0\u2014 the line consists of the characters '\n0\n' and '\n1\n'. The character '\n0\n' corresponds to a safe cell, the character '\n1\n' corresponds to a trap cell.\nAdditional constraint on the input: cells $$$(1, 1)$$$ and $$$(2, n)$$$ are safe.\nOutput\nFor each test case, output\nYES\nif it is possible to complete the level, and\nNO\notherwise.\nExample\nInput\n4\n3\n000\n000\n4\n0011\n1100\n4\n0111\n1110\n6\n010101\n101010\nOutput\nYES\nYES\nNO\nYES\nNote\nConsider the example from the statement.\nIn the first test case, one of the possible paths is $$$(1, 1) \\rightarrow (2, 2) \\rightarrow (2, 3)$$$.\nIn the second test case, one of the possible paths is $$$(1, 1) \\rightarrow (1, 2) \\rightarrow (2, 3) \\rightarrow (2, 4)$$$.\nIn the fourth test case, one of the possible paths is $$$(1, 1) \\rightarrow (2, 2) \\rightarrow (1, 3) \\rightarrow (2, 4) \\rightarrow (1, 5) \\rightarrow (2, 6)$$$.", "input": [ [ [ "3" ], [ "000" ], [ "000" ] ], [ [ "4" ], [ "0011" ], [ "1100" ] ], [ [ "4" ], [ "0111" ], [ "1110" ] ], [ [ "6" ], [ "010101" ], [ "101010" ] ] ], "output": [ "YES", "YES", "NO", "YES" ] }, { "problem_id": "1594A", "problem_name": "Consecutive Sum Riddle\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1594/A", "problem_solution_link": "https://codeforces.com/problemset/status/1594/problem/A", "problem_statement": "A. Consecutive Sum Riddle\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTheofanis has a riddle for you and if you manage to solve it, he will give you a Cypriot snack halloumi for free (Cypriot cheese).\nYou are given an integer $$$n$$$. You need to find two integers $$$l$$$ and $$$r$$$ such that $$$-10^{18} \\le l < r \\le 10^{18}$$$ and $$$l + (l + 1) + \\ldots + (r - 1) + r = n$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nThe first and only line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^{18}$$$).\nOutput\nFor each test case, print the two integers $$$l$$$ and $$$r$$$ such that $$$-10^{18} \\le l < r \\le 10^{18}$$$ and $$$l + (l + 1) + \\ldots + (r - 1) + r = n$$$.\nIt can be proven that an answer always exists. If there are multiple answers, print any.\nExample\nInput\n7\n1\n2\n3\n6\n100\n25\n3000000000000\nOutput\n0 1\n-1 2 \n1 2 \n1 3 \n18 22\n-2 7\n999999999999 1000000000001\nNote\nIn the first test case, $$$0 + 1 = 1$$$.\nIn the second test case, $$$(-1) + 0 + 1 + 2 = 2$$$.\nIn the fourth test case, $$$1 + 2 + 3 = 6$$$.\nIn the fifth test case, $$$18 + 19 + 20 + 21 + 22 = 100$$$.\nIn the sixth test case, $$$(-2) + (-1) + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 = 25$$$.", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "3" ] ], [ [ "6" ] ], [ [ "100" ] ], [ [ "25" ] ], [ [ "3000000000000" ] ] ], "output": [ "0 1", "-1 2 ", "1 2 ", "1 3 ", "18 22", "-2 7", "999999999999 1000000000001" ] }, { "problem_id": "1593A", "problem_name": "Elections\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1593/A", "problem_solution_link": "https://codeforces.com/problemset/status/1593/problem/A", "problem_statement": "A. Elections\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThe elections in which three candidates participated have recently ended. The first candidate received $$$a$$$ votes, the second one received $$$b$$$ votes, the third one received $$$c$$$ votes. For each candidate, solve the following problem: how many votes should be added to this candidate so that he wins the election (i.e. the number of votes for this candidate was strictly greater than the number of votes for any other candidate)?\nPlease note that for each candidate it is necessary to solve this problem\nindependently\n, i.e. the added votes for any candidate\ndo not\naffect the calculations when getting the answer for the other two candidates.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nEach test case consists of one line containing three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$0 \\le a,b,c \\le 10^9$$$).\nOutput\nFor each test case, output in a separate line three integers $$$A$$$, $$$B$$$, and $$$C$$$ ($$$A, B, C \\ge 0$$$) separated by spaces \u2014 the answers to the problem for the first, second, and third candidate, respectively.\nExample\nInput\n5\n0 0 0\n10 75 15\n13 13 17\n1000 0 0\n0 1000000000 0\nOutput\n1 1 1\n66 0 61\n5 5 0\n0 1001 1001\n1000000001 0 1000000001", "input": [ [ [ "0", "0", "0" ] ], [ [ "10", "75", "15" ] ], [ [ "13", "13", "17" ] ], [ [ "1000", "0", "0" ] ], [ [ "0", "1000000000", "0" ] ] ], "output": [ "1 1 1", "66 0 61", "5 5 0", "0 1001 1001", "1000000001 0 1000000001" ] }, { "problem_id": "1592A", "problem_name": "Gamer Hemose\nbinary search, greedy, math, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1592/A", "problem_solution_link": "https://codeforces.com/problemset/status/1592/problem/A", "problem_statement": "A. Gamer Hemose\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nOne day, Ahmed_Hossam went to Hemose and said \"Let's solve a gym contest!\". Hemose didn't want to do that, as he was playing Valorant, so he came up with a problem and told it to Ahmed to distract him. Sadly, Ahmed can't solve it... Could you help him?\nThere is an Agent in Valorant, and he has $$$n$$$ weapons. The $$$i$$$-th weapon has a damage value $$$a_i$$$, and the Agent will face an enemy whose health value is $$$H$$$.\nThe Agent will perform one or more moves until the enemy dies.\nIn one move, he will choose a weapon and decrease the enemy's health by its damage value. The enemy will die when his health will become less than or equal to $$$0$$$. However, not everything is so easy:\nthe Agent can't choose the same weapon for $$$2$$$ times in a row\n.\nWhat is the minimum number of times that the Agent will need to use the weapons to kill the enemy?\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \\leq t \\leq 10^5)$$$. Description of the test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$H$$$ $$$(2 \\leq n \\leq 10^3, 1 \\leq H \\leq 10^9)$$$ \u2014 the number of available weapons and the initial health value of the enemy.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ $$$(1 \\leq a_i \\leq 10^9)$$$ \u2014 the damage values of the weapons.\nIt's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print a single integer \u2014 the minimum number of times that the Agent will have to use the weapons to kill the enemy.\nExample\nInput\n3\n2 4\n3 7\n2 6\n4 2\n3 11\n2 1 7\nOutput\n1\n2\n3\nNote\nIn the first test case, the Agent can use the second weapon, making health value of the enemy equal to $$$4-7=-3$$$. $$$-3 \\le 0$$$, so the enemy is dead, and using weapon $$$1$$$ time was enough.\nIn the second test case, the Agent can use the first weapon first, and then the second one. After this, the health of enemy will drop to $$$6-4-2 = 0$$$, meaning he would be killed after using weapons $$$2$$$ times.\nIn the third test case, the Agent can use the weapons in order (third, first, third), decreasing the health value of enemy to $$$11 - 7 - 2 - 7 = -5$$$ after using the weapons $$$3$$$ times. Note that we can't kill the enemy by using the third weapon twice, as even though $$$11-7-7<0$$$, it's not allowed to use the same weapon twice in a row.", "input": [ [ [ "2", "4" ], [ "3", "7" ] ], [ [ "2", "6" ], [ "4", "2" ] ], [ [ "3", "11" ], [ "2", "1", "7" ] ] ], "output": [ "1", "2", "3" ] }, { "problem_id": "1585A", "problem_name": "Life of a Flower\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1585/A", "problem_solution_link": "https://codeforces.com/problemset/status/1585/problem/A", "problem_statement": "A. Life of a Flower\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPetya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given $$$n$$$ days from Petya's live and you have to determine what happened with his flower in the end.\nThe flower grows as follows:\nIf the flower isn't watered for two days in a row, it dies.\nIf the flower is watered in the $$$i$$$-th day, it grows by $$$1$$$ centimeter.\nIf the flower is watered in the $$$i$$$-th and in the $$$(i-1)$$$-th day ($$$i > 1$$$), then it grows by $$$5$$$ centimeters instead of $$$1$$$.\nIf the flower is not watered in the $$$i$$$-th day, it does not grow.\nAt the beginning of the $$$1$$$-st day the flower is $$$1$$$ centimeter tall. What is its height after $$$n$$$ days?\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). Description of the test cases follows.\nThe first line of each test case contains the only integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$).\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$a_i = 0$$$ or $$$a_i = 1$$$). If $$$a_i = 1$$$, the flower is watered in the $$$i$$$-th day, otherwise it is not watered.\nOutput\nFor each test case print a single integer $$$k$$$ \u2014 the flower's height after $$$n$$$ days, or $$$-1$$$, if the flower dies.\nExample\nInput\n4\n3\n1 0 1\n3\n0 1 1\n4\n1 0 0 1\n1\n0\nOutput\n3\n7\n-1\n1", "input": [ [ [ "3" ], [ "1", "0", "1" ] ], [ [ "3" ], [ "0", "1", "1" ] ], [ [ "4" ], [ "1", "0", "0", "1" ] ], [ [ "1" ], [ "0" ] ] ], "output": [ "3", "7", "-1", "1" ] }, { "problem_id": "1584A", "problem_name": "Mathematical Addition\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1584/A", "problem_solution_link": "https://codeforces.com/problemset/status/1584/problem/A", "problem_statement": "A. Mathematical Addition\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIvan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form:\nYou are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (\nnot necessarily positive\n) $$$x$$$, $$$y$$$, such that: $$$$$$\\frac{x}{u} + \\frac{y}{v} = \\frac{x + y}{u + v}.$$$$$$\nThe solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \\neq (0, 0)$$$.\nPlease help Ivan to solve some equations of this form.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10^3$$$)\u00a0\u2014 the number of test cases. The next lines contain descriptions of test cases.\nThe only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \\leq u, v \\leq 10^9$$$) \u2014 the parameters of the equation.\nOutput\nFor each test case print two integers $$$x$$$, $$$y$$$ \u2014 a possible solution to the equation. It should be satisfied that $$$-10^{18} \\leq x, y \\leq 10^{18}$$$ and $$$(x, y) \\neq (0, 0)$$$.\nWe can show that an answer always exists. If there are multiple possible solutions you can print any.\nExample\nInput\n4\n1 1\n2 3\n3 5\n6 9\nOutput\n-1 1\n-4 9\n-18 50\n-4 9\nNote\nIn the first test case: $$$\\frac{-1}{1} + \\frac{1}{1} = 0 = \\frac{-1 + 1}{1 + 1}$$$.\nIn the second test case: $$$\\frac{-4}{2} + \\frac{9}{3} = 1 = \\frac{-4 + 9}{2 + 3}$$$.\nIn the third test case: $$$\\frac{-18}{3} + \\frac{50}{5} = 4 = \\frac{-18 + 50}{3 + 5}$$$.\nIn the fourth test case: $$$\\frac{-4}{6} + \\frac{9}{9} = \\frac{1}{3} = \\frac{-4 + 9}{6 + 9}$$$.", "input": [ [ [ "1", "1" ] ], [ [ "2", "3" ] ], [ [ "3", "5" ] ], [ [ "6", "9" ] ] ], "output": [ "-1 1", "-4 9", "-18 50", "-4 9" ] }, { "problem_id": "1583A", "problem_name": "Windblume Ode\nmath, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1583/A", "problem_solution_link": "https://codeforces.com/problemset/status/1583/problem/A", "problem_statement": "A. Windblume Ode\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA bow adorned with nameless flowers that bears the earnest hopes of an equally nameless person.\nYou have obtained the elegant bow known as the Windblume Ode. Inscribed in the weapon is an array of $$$n$$$ ($$$n \\ge 3$$$) positive\ndistinct\nintegers (i.e. different, no duplicates are allowed).\nFind the largest subset (i.e. having the maximum number of elements) of this array such that its sum is a composite number. A positive integer $$$x$$$ is called composite if there exists a positive integer $$$y$$$ such that $$$1 < y < x$$$ and $$$x$$$ is divisible by $$$y$$$.\nIf there are multiple subsets with this largest size with the composite sum, you can output any of them. It can be proven that under the constraints of the problem such a non-empty subset always exists.\nInput\nEach test consists of multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). Description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$3 \\leq n \\leq 100$$$)\u00a0\u2014 the length of the array.\nThe second line of each test case contains $$$n$$$\ndistinct\nintegers $$$a_{1},a_{2},\\dots,a_{n}$$$ ($$$1 \\leq a_{i} \\leq 200$$$)\u00a0\u2014 the elements of the array.\nOutput\nEach test case should have two lines of output.\nThe first line should contain a single integer $$$x$$$: the size of the largest subset with composite sum. The next line should contain $$$x$$$ space separated integers representing the indices of the subset of the initial array.\nExample\nInput\n4\n3\n8 1 2\n4\n6 9 4 2\n9\n1 2 3 4 5 6 7 8 9\n3\n200 199 198\nOutput\n2\n2 1\n4\n2 1 4 3\n9\n6 9 1 2 3 4 5 7 8\n3\n1 2 3\nNote\nIn the first test case, the subset $$$\\{a_2, a_1\\}$$$ has a sum of $$$9$$$, which is a composite number. The only subset of size $$$3$$$ has a prime sum equal to $$$11$$$. Note that you could also have selected the subset $$$\\{a_1, a_3\\}$$$ with sum $$$8 + 2 = 10$$$, which is composite as it's divisible by $$$2$$$.\nIn the second test case, the sum of all elements equals to $$$21$$$, which is a composite number. Here we simply take the whole array as our subset.", "input": [ [ [ "3" ], [ "8", "1", "2" ] ], [ [ "4" ], [ "6", "9", "4", "2" ] ], [ [ "9" ], [ "1", "2", "3", "4", "5", "6", "7", "8", "9" ] ], [ [ "3" ], [ "200", "199", "198" ] ] ], "output": [ ["2", "2 1"], ["4", "2 1 4 3"], ["9", "6 9 1 2 3 4 5 7 8"], ["3", "1 2 3"] ], "error": true }, { "problem_id": "1582A", "problem_name": "Luntik and Concerts\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1582/A", "problem_solution_link": "https://codeforces.com/problemset/status/1582/problem/A", "problem_statement": "A. Luntik and Concerts\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLuntik has decided to try singing. He has $$$a$$$ one-minute songs, $$$b$$$ two-minute songs and $$$c$$$ three-minute songs. He wants to distribute all songs into two concerts such that every song should be included to exactly one concert.\nHe wants to make the absolute difference of durations of the concerts as small as possible. The duration of the concert is the sum of durations of all songs in that concert.\nPlease help Luntik and find the minimal possible difference in minutes between the concerts durations.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of one line containing three integers $$$a, b, c$$$ $$$(1 \\le a, b, c \\le 10^9)$$$\u00a0\u2014 the number of one-minute, two-minute and three-minute songs.\nOutput\nFor each test case print the minimal possible difference in minutes between the concerts durations.\nExample\nInput\n4\n1 1 1\n2 1 3\n5 5 5\n1 1 2\nOutput\n0\n1\n0\n1\nNote\nIn the first test case, Luntik can include a one-minute song and a two-minute song into the first concert, and a three-minute song into the second concert. Then the difference will be equal to $$$0$$$.\nIn the second test case, Luntik can include two one-minute songs and a two-minute song and a three-minute song into the first concert, and two three-minute songs into the second concert. The duration of the first concert will be $$$1 + 1 + 2 + 3 = 7$$$, the duration of the second concert will be $$$6$$$. The difference of them is $$$|7-6| = 1$$$.", "input": [ [ [ "1", "1", "1" ] ], [ [ "2", "1", "3" ] ], [ [ "5", "5", "5" ] ], [ [ "1", "1", "2" ] ] ], "output": [ "0", "1", "0", "1" ] }, { "problem_id": "1581A", "problem_name": "CQXYM Count Permutations\ncombinatorics, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1581/A", "problem_solution_link": "https://codeforces.com/problemset/status/1581/problem/A", "problem_statement": "A. CQXYM Count Permutations\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nCQXYM is counting permutations length of $$$2n$$$.\nA permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).\nA permutation $$$p$$$(length of $$$2n$$$) will be counted only if the number of $$$i$$$ satisfying $$$p_ip_2$$$. Because $$$0 a_{i+1}$$$.\nPetya wonders if it is possible to uniquely determine the result of comparing $$$a_1$$$ and $$$a_n$$$.\nYou have to help Petya determine the result of comparing $$$a_1$$$ and $$$a_n$$$ or report that the result cannot be determined unambiguously.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 500$$$)\u00a0\u2014 the number of test cases.\nThe only line of the test case contains the string $$$s$$$ ($$$1 \\le |s| \\le 100$$$), where $$$s_i$$$ is:\n<\n, if $$$a_i < a_{i + 1}$$$;\n>\n, if $$$a_i > a_{i + 1}$$$;\n=\n, if $$$a_i = a_{i + 1}$$$.\nOutput\nFor each test case, print a single string equal to:\n<\n, if $$$a_1 < a_n$$$;\n>\n, if $$$a_1 > a_n$$$;\n=\n, if $$$a_1 = a_n$$$;\n?\n, if it is impossible to uniquely determine the result of the comparison.\nExample\nInput\n4\n>>>\n<><=<\n=\n<<==\nOutput\n>\n?\n=\n<\nNote\nConsider the test cases of the example:\nin the first test case, it's easy to see that $$$a_1 > a_4$$$ since $$$a_1 > a_2 > a_3 > a_4$$$;\nin the second test case, both sequences $$$[1, 2, 0, 10, 10, 15]$$$ and $$$[10, 11, 1, 2, 2, 5]$$$ meet the constraints; in the first one, $$$a_1 < a_6$$$, and in the second one, $$$a_1 > a_6$$$, so it's impossible to compare $$$a_1$$$ and $$$a_6$$$;\nin the third test case, we already know that $$$a_1 = a_2$$$;\nin the fourth test case, it's easy to see that $$$a_3 = a_4 = a_5$$$, and $$$a_1 < a_2 < a_3$$$, so $$$a_1 < a_5$$$.", "input": [ [ [ ">>>" ] ], [ [ "<><=<" ] ], [ [ "=" ] ], [ [ "<<==" ] ] ], "output": [ ">", "?", "=", "<" ] }, { "problem_id": "1569A", "problem_name": "Balanced Substring\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1569/A", "problem_solution_link": "https://codeforces.com/problemset/status/1569/problem/A", "problem_statement": "A. Balanced Substring\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a string $$$s$$$, consisting of $$$n$$$ letters, each letter is either '\na\n' or '\nb\n'. The letters in the string are numbered from $$$1$$$ to $$$n$$$.\n$$$s[l; r]$$$ is a continuous substring of letters from index $$$l$$$ to $$$r$$$ of the string inclusive.\nA string is called balanced if the number of letters '\na\n' in it is equal to the number of letters '\nb\n'. For example, strings \"\nbaba\n\" and \"\naabbab\n\" are balanced and strings \"\naaab\n\" and \"\nb\n\" are not.\nFind any non-empty balanced substring $$$s[l; r]$$$ of string $$$s$$$. Print its $$$l$$$ and $$$r$$$ ($$$1 \\le l \\le r \\le n$$$). If there is no such substring, then print $$$-1$$$ $$$-1$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of testcases.\nThen the descriptions of $$$t$$$ testcases follow.\nThe first line of the testcase contains a single integer $$$n$$$ ($$$1 \\le n \\le 50$$$)\u00a0\u2014 the length of the string.\nThe second line of the testcase contains a string $$$s$$$, consisting of $$$n$$$ letters, each letter is either '\na\n' or '\nb\n'.\nOutput\nFor each testcase print two integers. If there exists a non-empty balanced substring $$$s[l; r]$$$, then print $$$l$$$ $$$r$$$ ($$$1 \\le l \\le r \\le n$$$). Otherwise, print $$$-1$$$ $$$-1$$$.\nExample\nInput\n4\n1\na\n6\nabbaba\n6\nabbaba\n9\nbabbabbaa\nOutput\n-1 -1\n1 6\n3 6\n2 5\nNote\nIn the first testcase there are no non-empty balanced subtrings.\nIn the second and third testcases there are multiple balanced substrings, including the entire string \"\nabbaba\n\" and substring \"\nbaba\n\".", "input": [ [ [ "1" ], [ "a" ] ], [ [ "6" ], [ "abbaba" ] ], [ [ "6" ], [ "abbaba" ] ], [ [ "9" ], [ "babbabbaa" ] ] ], "output": [ "-1 -1", "1 6", "3 6", "2 5" ] }, { "problem_id": "1567A", "problem_name": "Domino Disaster\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1567/A", "problem_solution_link": "https://codeforces.com/problemset/status/1567/problem/A", "problem_statement": "A. Domino Disaster\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAlice has a grid with $$$2$$$ rows and $$$n$$$ columns. She fully covers the grid using $$$n$$$ dominoes of size $$$1 \\times 2$$$\u00a0\u2014 Alice may place them vertically or horizontally, and each cell should be covered by exactly one domino.\nNow, she decided to show one row of the grid to Bob. Help Bob and figure out what the other row of the grid looks like!\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 5000$$$)\u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the width of the grid.\nThe second line of each test case contains a string $$$s$$$ consisting of $$$n$$$ characters, each of which is either\nL\n,\nR\n,\nU\n, or\nD\n, representing the left, right, top, or bottom half of a domino, respectively (see notes for better understanding). This string represents one of the rows of the grid.\nAdditional constraint on the input:\neach input corresponds to at least one valid tiling.\nOutput\nFor each test case, output one string\u00a0\u2014 the other row of the grid, using the same format as the input string. If there are multiple answers, print any.\nExample\nInput\n4\n1\nU\n2\nLR\n5\nLRDLR\n6\nUUUUUU\nOutput\nD\nLR\nLRULR\nDDDDDD\nNote\nIn the first test case, Alice shows Bob the\ntop\nrow, the whole grid may look like:\nIn the second test case, Alice shows Bob the\nbottom\nrow, the whole grid may look like:\nIn the third test case, Alice shows Bob the\nbottom\nrow, the whole grid may look like:\nIn the fourth test case, Alice shows Bob the\ntop\nrow, the whole grid may look like:", "input": [ [ [ "1" ], [ "U" ] ], [ [ "2" ], [ "LR" ] ], [ [ "5" ], [ "LRDLR" ] ], [ [ "6" ], [ "UUUUUU" ] ] ], "output": [ "D", "LR", "LRULR", "DDDDDD" ] }, { "problem_id": "1566B", "problem_name": "MIN-MEX Cut\nbitmasks, constructive algorithms, dp, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1566/B", "problem_solution_link": "https://codeforces.com/problemset/status/1566/problem/B", "problem_statement": "B. MIN-MEX Cut\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA binary string is a string that consists of characters $$$0$$$ and $$$1$$$.\nLet $$$\\operatorname{MEX}$$$ of a binary string be the smallest digit among $$$0$$$, $$$1$$$, or $$$2$$$ that does not occur in the string. For example, $$$\\operatorname{MEX}$$$ of $$$001011$$$ is $$$2$$$, because $$$0$$$ and $$$1$$$ occur in the string at least once, $$$\\operatorname{MEX}$$$ of $$$1111$$$ is $$$0$$$, because $$$0$$$ and $$$2$$$ do not occur in the string and $$$0 < 2$$$.\nA binary string $$$s$$$ is given. You should cut it into any number of substrings such that each character is in exactly one substring. It is possible to cut the string into a single substring \u2014 the whole string.\nA string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.\nWhat is the\nminimal\nsum of $$$\\operatorname{MEX}$$$ of all substrings pieces can be?\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Description of the test cases follows.\nEach test case contains a single binary string $$$s$$$ ($$$1 \\le |s| \\le 10^5$$$).\nIt's guaranteed that the sum of lengths of $$$s$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each test case print a single integer\u00a0\u2014 the minimal sum of $$$\\operatorname{MEX}$$$ of all substrings that it is possible to get by cutting $$$s$$$ optimally.\nExample\nInput\n6\n01\n1111\n01100\n101\n0000\n01010\nOutput\n1\n0\n2\n1\n1\n2\nNote\nIn the first test case the minimal sum is $$$\\operatorname{MEX}(0) + \\operatorname{MEX}(1) = 1 + 0 = 1$$$.\nIn the second test case the minimal sum is $$$\\operatorname{MEX}(1111) = 0$$$.\nIn the third test case the minimal sum is $$$\\operatorname{MEX}(01100) = 2$$$.", "input": [ [ [ "01" ] ], [ [ "1111" ] ], [ [ "01100" ] ], [ [ "101" ] ], [ [ "0000" ] ], [ [ "01010" ] ] ], "output": [ "1", "0", "2", "1", "1", "2" ] }, { "problem_id": "1566A", "problem_name": "Median Maximization\nbinary search, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1566/A", "problem_solution_link": "https://codeforces.com/problemset/status/1566/problem/A", "problem_statement": "A. Median Maximization\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two positive integers $$$n$$$ and $$$s$$$. Find the maximum possible median of an array of $$$n$$$\nnon-negative\nintegers (not necessarily distinct), such that the sum of its elements is equal to $$$s$$$.\nA\nmedian\nof an array of integers of length $$$m$$$ is the number standing on the $$$\\lceil {\\frac{m}{2}} \\rceil$$$-th (rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting from $$$1$$$. For example, a median of the array $$$[20,40,20,50,50,30]$$$ is the $$$\\lceil \\frac{m}{2} \\rceil$$$-th element of $$$[20,20,30,40,50,50]$$$, so it is $$$30$$$. There exist other definitions of the median, but in this problem we use the described definition.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. Description of the test cases follows.\nEach test case contains a single line with two integers $$$n$$$ and $$$s$$$ ($$$1 \\le n, s \\le 10^9$$$)\u00a0\u2014 the length of the array and the required sum of the elements.\nOutput\nFor each test case print a single integer\u00a0\u2014 the maximum possible median.\nExample\nInput\n8\n1 5\n2 5\n3 5\n2 1\n7 17\n4 14\n1 1000000000\n1000000000 1\nOutput\n5\n2\n2\n0\n4\n4\n1000000000\n0\nNote\nPossible arrays for the first three test cases (in each array the median is underlined):\nIn the first test case $$$[\\underline{5}]$$$\nIn the second test case $$$[\\underline{2}, 3]$$$\nIn the third test case $$$[1, \\underline{2}, 2]$$$", "input": [ [ [ "1", "5" ] ], [ [ "2", "5" ] ], [ [ "3", "5" ] ], [ [ "2", "1" ] ], [ [ "7", "17" ] ], [ [ "4", "14" ] ], [ [ "1", "1000000000" ] ], [ [ "1000000000", "1" ] ] ], "output": [ "5", "2", "2", "0", "4", "4", "1000000000", "0" ] }, { "problem_id": "1562A", "problem_name": "The Miracle and the Sleeper\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1562/A", "problem_solution_link": "https://codeforces.com/problemset/status/1562/problem/A", "problem_statement": "A. The Miracle and the Sleeper\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two integers $$$l$$$ and $$$r$$$, $$$l\\le r$$$. Find the largest possible value of $$$a \\bmod b$$$ over all pairs $$$(a, b)$$$ of integers for which $$$r\\ge a \\ge b \\ge l$$$.\nAs a reminder, $$$a \\bmod b$$$ is a remainder we get when dividing $$$a$$$ by $$$b$$$. For example, $$$26 \\bmod 8 = 2$$$.\nInput\nEach test contains multiple test cases.\nThe first line contains one positive integer $$$t$$$ $$$(1\\le t\\le 10^4)$$$, denoting the number of test cases. Description of the test cases follows.\nThe only line of each test case contains two integers $$$l$$$, $$$r$$$ ($$$1\\le l \\le r \\le 10^9$$$).\nOutput\nFor every test case, output the largest possible value of $$$a \\bmod b$$$ over all pairs $$$(a, b)$$$ of integers for which $$$r\\ge a \\ge b \\ge l$$$.\nExample\nInput\n4\n1 1\n999999999 1000000000\n8 26\n1 999999999\nOutput\n0\n1\n12\n499999999\nNote\nIn the first test case, the only allowed pair is $$$(a, b) = (1, 1)$$$, for which $$$a \\bmod b = 1 \\bmod 1 = 0$$$.\nIn the second test case, the optimal choice is pair $$$(a, b) = (1000000000, 999999999)$$$, for which $$$a \\bmod b = 1$$$.", "input": [ [ [ "1", "1" ] ], [ [ "999999999", "1000000000" ] ], [ [ "8", "26" ] ], [ [ "1", "999999999" ] ] ], "output": [ "0", "1", "12", "499999999" ] }, { "problem_id": "1561A", "problem_name": "Simply Strange Sort\nbrute force, implementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1561/A", "problem_solution_link": "https://codeforces.com/problemset/status/1561/problem/A", "problem_statement": "A. Simply Strange Sort\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have a permutation: an array $$$a = [a_1, a_2, \\ldots, a_n]$$$ of distinct integers from $$$1$$$ to $$$n$$$. The length of the permutation $$$n$$$ is odd.\nConsider the following algorithm of sorting the permutation in increasing order.\nA helper procedure of the algorithm, $$$f(i)$$$, takes a single argument $$$i$$$ ($$$1 \\le i \\le n-1$$$) and does the following. If $$$a_i > a_{i+1}$$$, the values of $$$a_i$$$ and $$$a_{i+1}$$$ are exchanged. Otherwise, the permutation doesn't change.\nThe algorithm consists of iterations, numbered with consecutive integers starting with $$$1$$$. On the $$$i$$$-th iteration, the algorithm does the following:\nif $$$i$$$ is odd, call $$$f(1), f(3), \\ldots, f(n - 2)$$$;\nif $$$i$$$ is even, call $$$f(2), f(4), \\ldots, f(n - 1)$$$.\nIt can be proven that after a finite number of iterations the permutation will be sorted in increasing order.\nAfter how many iterations will this happen for the first time?\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). Description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$3 \\le n \\le 999$$$; $$$n$$$ is odd)\u00a0\u2014 the length of the permutation.\nThe second line contains $$$n$$$ distinct integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le n$$$)\u00a0\u2014 the permutation itself.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$999$$$.\nOutput\nFor each test case print the number of iterations after which the permutation will become sorted in increasing order for the first time.\nIf the given permutation is already sorted, print $$$0$$$.\nExample\nInput\n3\n3\n3 2 1\n7\n4 5 7 1 3 2 6\n5\n1 2 3 4 5\nOutput\n3\n5\n0\nNote\nIn the first test case, the permutation will be changing as follows:\nafter the $$$1$$$-st iteration: $$$[2, 3, 1]$$$;\nafter the $$$2$$$-nd iteration: $$$[2, 1, 3]$$$;\nafter the $$$3$$$-rd iteration: $$$[1, 2, 3]$$$.\nIn the second test case, the permutation will be changing as follows:\nafter the $$$1$$$-st iteration: $$$[4, 5, 1, 7, 2, 3, 6]$$$;\nafter the $$$2$$$-nd iteration: $$$[4, 1, 5, 2, 7, 3, 6]$$$;\nafter the $$$3$$$-rd iteration: $$$[1, 4, 2, 5, 3, 7, 6]$$$;\nafter the $$$4$$$-th iteration: $$$[1, 2, 4, 3, 5, 6, 7]$$$;\nafter the $$$5$$$-th iteration: $$$[1, 2, 3, 4, 5, 6, 7]$$$.\nIn the third test case, the permutation is already sorted and the answer is $$$0$$$.", "input": [ [ [ "3" ], [ "3", "2", "1" ] ], [ [ "7" ], [ "4", "5", "7", "1", "3", "2", "6" ] ], [ [ "5" ], [ "1", "2", "3", "4", "5" ] ] ], "output": [ "3", "5", "0" ] }, { "problem_id": "1560C", "problem_name": "Infinity Table\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1560/C", "problem_solution_link": "https://codeforces.com/problemset/status/1560/problem/C", "problem_statement": "C. Infinity Table\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp has found a table having an infinite number of rows and columns. The rows are numbered from $$$1$$$, starting from the topmost one. The columns are numbered from $$$1$$$, starting from the leftmost one.\nInitially, the table hasn't been filled and Polycarp wants to fix it. He writes integers from $$$1$$$ and so on to the table as follows.\nThe figure shows the placement of the numbers from $$$1$$$ to $$$10$$$. The following actions are denoted by the arrows.\nThe leftmost topmost cell of the table is filled with the number $$$1$$$. Then he writes in the table all positive integers beginning from $$$2$$$ sequentially using the following algorithm.\nFirst, Polycarp selects the leftmost non-filled cell in the first row and fills it. Then, while the left neighbor of the last filled cell is filled, he goes down and fills the next cell. So he goes down until the last filled cell has a non-filled neighbor to the left (look at the vertical arrow going down in the figure above).\nAfter that, he fills the cells from the right to the left until he stops at the first column (look at the horizontal row in the figure above). Then Polycarp selects the leftmost non-filled cell in the first row, goes down, and so on.\nA friend of Polycarp has a favorite number $$$k$$$. He wants to know which cell will contain the number. Help him to find the indices of the row and the column, such that the intersection of the row and the column is the cell containing the number $$$k$$$.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nEach test case consists of one line containing one integer $$$k$$$ ($$$1 \\le k \\le 10^9$$$) which location must be found.\nOutput\nFor each test case, output in a separate line two integers $$$r$$$ and $$$c$$$ ($$$r, c \\ge 1$$$) separated by spaces \u2014 the indices of the row and the column containing the cell filled by the number $$$k$$$, respectively.\nExample\nInput\n7\n11\n14\n5\n4\n1\n2\n1000000000\nOutput\n2 4\n4 3\n1 3\n2 1\n1 1\n1 2\n31623 14130", "input": [ [ [ "11" ] ], [ [ "14" ] ], [ [ "5" ] ], [ [ "4" ] ], [ [ "1" ] ], [ [ "2" ] ], [ [ "1000000000" ] ] ], "output": [ "2 4", "4 3", "1 3", "2 1", "1 1", "1 2", "31623 14130" ] }, { "problem_id": "1560B", "problem_name": "Who's Opposite?\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1560/B", "problem_solution_link": "https://codeforces.com/problemset/status/1560/problem/B", "problem_statement": "B. Who's Opposite?\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nSome number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number $$$1$$$. Each person is looking through the circle's center at the opposite person.\nA sample of a circle of $$$6$$$ persons. The orange arrows indicate who is looking at whom.\nYou don't know the exact number of people standing in the circle (but this number is even, no doubt). It is known that the person with the number $$$a$$$ is looking at the person with the number $$$b$$$ (and vice versa, of course). What is the number associated with a person being looked at by the person with the number $$$c$$$? If, for the specified $$$a$$$, $$$b$$$, and $$$c$$$, no such circle exists, output\n-1\n.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nEach test case consists of one line containing three\ndistinct\nintegers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \\le a,b,c \\le 10^8$$$).\nOutput\nFor each test case output in a separate line a single integer $$$d$$$ \u2014 the number of the person being looked at by the person with the number $$$c$$$ in a circle such that the person with the number $$$a$$$ is looking at the person with the number $$$b$$$. If there are multiple solutions, print any of them. Output $$$-1$$$ if there's no circle meeting the given conditions.\nExample\nInput\n7\n6 2 4\n2 3 1\n2 4 10\n5 3 4\n1 3 2\n2 5 4\n4 3 2\nOutput\n8\n-1\n-1\n-1\n4\n1\n-1\nNote\nIn the first test case, there's a desired circle of $$$8$$$ people. The person with the number $$$6$$$ will look at the person with the number $$$2$$$ and the person with the number $$$8$$$ will look at the person with the number $$$4$$$.\nIn the second test case, there's no circle meeting the conditions. If the person with the number $$$2$$$ is looking at the person with the number $$$3$$$, the circle consists of $$$2$$$ people because these persons are neighbors. But, in this case, they must have the numbers $$$1$$$ and $$$2$$$, but it doesn't meet the problem's conditions.\nIn the third test case, the only circle with the persons with the numbers $$$2$$$ and $$$4$$$ looking at each other consists of $$$4$$$ people. Therefore, the person with the number $$$10$$$ doesn't occur in the circle.", "input": [ [ [ "6", "2", "4" ] ], [ [ "2", "3", "1" ] ], [ [ "2", "4", "10" ] ], [ [ "5", "3", "4" ] ], [ [ "1", "3", "2" ] ], [ [ "2", "5", "4" ] ], [ [ "4", "3", "2" ] ] ], "output": [ "8", "-1", "-1", "-1", "4", "1", "-1" ] }, { "problem_id": "1557A", "problem_name": "Ezzat and Two Subsequences\nbrute force, math, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1557/A", "problem_solution_link": "https://codeforces.com/problemset/status/1557/problem/A", "problem_statement": "A. Ezzat and Two Subsequences\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nEzzat has an array of $$$n$$$ integers\n(maybe negative)\n. He wants to split it into two\nnon-empty\nsubsequences $$$a$$$ and $$$b$$$, such that every element from the array belongs to exactly one subsequence, and the value of $$$f(a) + f(b)$$$ is the maximum possible value, where $$$f(x)$$$ is the average of the subsequence $$$x$$$.\nA sequence $$$x$$$ is a subsequence of a sequence $$$y$$$ if $$$x$$$ can be obtained from $$$y$$$ by deletion of several (possibly, zero or all) elements.\nThe average of a subsequence is the sum of the numbers of this subsequence divided by the size of the subsequence.\nFor example, the average of $$$[1,5,6]$$$ is $$$(1+5+6)/3 = 12/3 = 4$$$, so $$$f([1,5,6]) = 4$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^3$$$)\u2014 the number of test cases. Each test case consists of two lines.\nThe first line contains a single integer $$$n$$$ ($$$2 \\le n \\le 10^5$$$).\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$-10^9 \\le a_i \\le 10^9$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3\\cdot10^5$$$.\nOutput\nFor each test case, print a single value \u2014 the maximum value that Ezzat can achieve.\nYour answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$.\nFormally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\\frac{|a - b|}{\\max{(1, |b|)}} \\le 10^{-6}$$$.\nExample\nInput\n4\n3\n3 1 2\n3\n-7 -6 -6\n3\n2 2 2\n4\n17 3 5 -3\nOutput\n4.500000000\n-12.500000000\n4.000000000\n18.666666667\nNote\nIn the first test case, the array is $$$[3, 1, 2]$$$. These are all the possible ways to split this array:\n$$$a = [3]$$$, $$$b = [1,2]$$$, so the value of $$$f(a) + f(b) = 3 + 1.5 = 4.5$$$.\n$$$a = [3,1]$$$, $$$b = [2]$$$, so the value of $$$f(a) + f(b) = 2 + 2 = 4$$$.\n$$$a = [3,2]$$$, $$$b = [1]$$$, so the value of $$$f(a) + f(b) = 2.5 + 1 = 3.5$$$.\nTherefore, the maximum possible value $$$4.5$$$.\nIn the second test case, the array is $$$[-7, -6, -6]$$$. These are all the possible ways to split this array:\n$$$a = [-7]$$$, $$$b = [-6,-6]$$$, so the value of $$$f(a) + f(b) = (-7) + (-6) = -13$$$.\n$$$a = [-7,-6]$$$, $$$b = [-6]$$$, so the value of $$$f(a) + f(b) = (-6.5) + (-6) = -12.5$$$.\nTherefore, the maximum possible value $$$-12.5$$$.", "input": [ [ [ "3" ], [ "3", "1", "2" ] ], [ [ "3" ], [ "-7", "-6", "-6" ] ], [ [ "3" ], [ "2", "2", "2" ] ], [ [ "4" ], [ "17", "3", "5", "-3" ] ] ], "output": [ "4.500000000", "-12.500000000", "4.000000000", "18.666666667" ] }, { "problem_id": "1556A", "problem_name": "A Variety of Operations\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1556/A", "problem_solution_link": "https://codeforces.com/problemset/status/1556/problem/A", "problem_statement": "A. A Variety of Operations\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nWilliam has two numbers $$$a$$$ and $$$b$$$ initially both equal to\nzero\n. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ is picked, which is then used to perform one of the following operations: (note, that for each operation you can choose a\nnew\npositive integer $$$k$$$)\nadd number $$$k$$$ to both $$$a$$$ and $$$b$$$, or\nadd number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or\nadd number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$.\nNote that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.\nWilliam wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^4$$$). Description of the test cases follows.\nThe only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \\le c, d \\le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.\nOutput\nFor each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.\nExample\nInput\n6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0\nOutput\n-1\n2\n2\n1\n2\n0\nNote\nLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$:\nUsing an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$.\nUsing an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$.\nUsing an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$.\nUsing an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.", "input": [ [ [ "1", "2" ] ], [ [ "3", "5" ] ], [ [ "5", "3" ] ], [ [ "6", "6" ] ], [ [ "8", "0" ] ], [ [ "0", "0" ] ] ], "output": [ "-1", "2", "2", "1", "2", "0" ] }, { "problem_id": "1554A", "problem_name": "Cherry\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1554/A", "problem_solution_link": "https://codeforces.com/problemset/status/1554/problem/A", "problem_statement": "A. Cherry\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$. Find the maximum value of $$$max(a_l, a_{l + 1}, \\ldots, a_r) \\cdot min(a_l, a_{l + 1}, \\ldots, a_r)$$$ over all pairs $$$(l, r)$$$ of integers for which $$$1 \\le l < r \\le n$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10\\,000$$$) \u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\le n \\le 10^5$$$).\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 10^6$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \\cdot 10^5$$$.\nOutput\nFor each test case, print a single integer \u00a0\u2014 the maximum possible value of the product from the statement.\nExample\nInput\n4\n3\n2 4 3\n4\n3 2 3 1\n2\n69 69\n6\n719313 273225 402638 473783 804745 323328\nOutput\n12\n6\n4761\n381274500335\nNote\nLet $$$f(l, r) = max(a_l, a_{l + 1}, \\ldots, a_r) \\cdot min(a_l, a_{l + 1}, \\ldots, a_r)$$$.\nIn the first test case,\n$$$f(1, 2) = max(a_1, a_2) \\cdot min(a_1, a_2) = max(2, 4) \\cdot min(2, 4) = 4 \\cdot 2 = 8$$$.\n$$$f(1, 3) = max(a_1, a_2, a_3) \\cdot min(a_1, a_2, a_3) = max(2, 4, 3) \\cdot min(2, 4, 3) = 4 \\cdot 2 = 8$$$.\n$$$f(2, 3) = max(a_2, a_3) \\cdot min(a_2, a_3) = max(4, 3) \\cdot min(4, 3) = 4 \\cdot 3 = 12$$$.\nSo the maximum is $$$f(2, 3) = 12$$$.\nIn the second test case, the maximum is $$$f(1, 2) = f(1, 3) = f(2, 3) = 6$$$.", "input": [ [ [ "3" ], [ "2", "4", "3" ] ], [ [ "4" ], [ "3", "2", "3", "1" ] ], [ [ "2" ], [ "69", "69" ] ], [ [ "6" ], [ "719313", "273225", "402638", "473783", "804745", "323328" ] ] ], "output": [ "12", "6", "4761", "381274500335" ] }, { "problem_id": "1553A", "problem_name": "Digits Sum\nmath, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1553/A", "problem_solution_link": "https://codeforces.com/problemset/status/1553/problem/A", "problem_statement": "A. Digits Sum\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's define $$$S(x)$$$ to be the sum of digits of number $$$x$$$ written in decimal system. For example, $$$S(5) = 5$$$, $$$S(10) = 1$$$, $$$S(322) = 7$$$.\nWe will call an integer $$$x$$$\ninteresting\nif $$$S(x + 1) < S(x)$$$. In each test you will be given one integer $$$n$$$. Your task is to calculate the number of integers $$$x$$$ such that $$$1 \\le x \\le n$$$ and $$$x$$$ is interesting.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u00a0\u2014 number of test cases.\nThen $$$t$$$ lines follow, the $$$i$$$-th line contains one integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$) for the $$$i$$$-th test case.\nOutput\nPrint $$$t$$$ integers, the $$$i$$$-th should be the answer for the $$$i$$$-th test case.\nExample\nInput\n5\n1\n9\n10\n34\n880055535\nOutput\n0\n1\n1\n3\n88005553\nNote\nThe first interesting number is equal to $$$9$$$.", "input": [ [ [ "1" ] ], [ [ "9" ] ], [ [ "10" ] ], [ [ "34" ] ], [ [ "880055535" ] ] ], "output": [ "0", "1", "1", "3", "88005553" ] }, { "problem_id": "1552A", "problem_name": "Subsequence Permutation\nsortings, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1552/A", "problem_solution_link": "https://codeforces.com/problemset/status/1552/problem/A", "problem_statement": "A. Subsequence Permutation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA string $$$s$$$ of length $$$n$$$, consisting of lowercase letters of the English alphabet, is given.\nYou must choose some number $$$k$$$ between $$$0$$$ and $$$n$$$. Then, you select $$$k$$$ characters of $$$s$$$ and permute them however you want. In this process, the positions of the other $$$n-k$$$ characters remain unchanged. You have to perform this operation exactly once.\nFor example, if $$$s=\\texttt{\"andrea\"}$$$, you can choose the $$$k=4$$$ characters $$$\\texttt{\"a_d_ea\"}$$$ and permute them into $$$\\texttt{\"d_e_aa\"}$$$ so that after the operation the string becomes $$$\\texttt{\"dneraa\"}$$$.\nDetermine the minimum $$$k$$$ so that it is possible to sort $$$s$$$ alphabetically (that is, after the operation its characters appear in alphabetical order).\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first line of each test case contains one integer $$$n$$$ ($$$1 \\le n \\le 40$$$) \u2014 the length of the string.\nThe second line of each test case contains the string $$$s$$$. It is guaranteed that $$$s$$$ contains only lowercase letters of the English alphabet.\nOutput\nFor each test case, output the minimum $$$k$$$ that allows you to obtain a string sorted alphabetically, through the operation described above.\nExample\nInput\n4\n3\nlol\n10\ncodeforces\n5\naaaaa\n4\ndcba\nOutput\n2\n6\n0\n4\nNote\nIn the\nfirst test case\n, we can choose the $$$k=2$$$ characters $$$\\texttt{\"_ol\"}$$$ and rearrange them as $$$\\texttt{\"_lo\"}$$$ (so the resulting string is $$$\\texttt{\"llo\"}$$$). It is not possible to sort the string choosing strictly less than $$$2$$$ characters.\nIn the\nsecond test case\n, one possible way to sort $$$s$$$ is to consider the $$$k=6$$$ characters $$$\\texttt{\"_o__force_\"}$$$ and rearrange them as $$$\\texttt{\"_c__efoor_\"}$$$ (so the resulting string is $$$\\texttt{\"ccdeefoors\"}$$$). One can show that it is not possible to sort the string choosing strictly less than $$$6$$$ characters.\nIn the\nthird test case\n, string $$$s$$$ is already sorted (so we can choose $$$k=0$$$ characters).\nIn the\nfourth test case\n, we can choose all $$$k=4$$$ characters $$$\\texttt{\"dcba\"}$$$ and reverse the whole string (so the resulting string is $$$\\texttt{\"abcd\"}$$$).", "input": [ [ [ "3" ], [ "lol" ] ], [ [ "10" ], [ "codeforces" ] ], [ [ "5" ], [ "aaaaa" ] ], [ [ "4" ], [ "dcba" ] ] ], "output": [ "2", "6", "0", "4" ] }, { "problem_id": "1551B1", "problem_name": "Wonderful Coloring - 1\ngreedy, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1551/B1", "problem_solution_link": "https://codeforces.com/problemset/status/1551/problem/B1", "problem_statement": "B1. Wonderful Coloring - 1\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThis is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.\nPaul and Mary have a favorite string $$$s$$$ which consists of lowercase letters of the Latin alphabet. They want to paint it using pieces of chalk of two colors: red and green. Let's call a coloring of a string wonderful if the following conditions are met:\neach letter of the string is either painted in exactly one color (red or green) or isn't painted;\neach two letters which are painted in the same color are different;\nthe number of letters painted in red is equal to the number of letters painted in green;\nthe number of painted letters of this coloring is\nmaximum\namong all colorings of the string which meet the first three conditions.\nE.\u2009g. consider a string $$$s$$$ equal to \"\nkzaaa\n\". One of the wonderful colorings of the string is shown in the figure.\nThe example of a wonderful coloring of the string \"\nkzaaa\n\".\nPaul and Mary want to learn by themselves how to find a wonderful coloring of the string. But they are very young, so they need a hint. Help them find $$$k$$$ \u2014 the number of red (or green, these numbers are equal) letters in a wonderful coloring.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nEach test case consists of one non-empty string $$$s$$$ which consists of lowercase letters of the Latin alphabet. The number of characters in the string doesn't exceed $$$50$$$.\nOutput\nFor each test case, output a separate line containing one non-negative integer $$$k$$$ \u2014 the number of letters which will be painted in red in a wonderful coloring.\nExample\nInput\n5\nkzaaa\ncodeforces\narchive\ny\nxxxxxx\nOutput\n2\n5\n3\n0\n1\nNote\nThe first test case contains the string from the statement. One of the wonderful colorings is shown in the figure. There's no wonderful coloring containing $$$3$$$ or more red letters because the total number of painted symbols will exceed the string's length.\nThe string from the second test case can be painted as follows. Let's paint the first occurrence of each of the letters \"\nc\n\", \"\no\n\", \"\ne\n\" in red and the second ones in green. Let's paint the letters \"\nd\n\", \"\nf\n\" in red and \"\nr\n\", \"\ns\n\" in green. So every letter will be painted in red or green, hence the answer better than $$$5$$$ doesn't exist.\nThe third test case contains the string of distinct letters, so you can paint any set of characters in red, as long as the size of this set doesn't exceed half of the size of the string and is the maximum possible.\nThe fourth test case contains a single letter which cannot be painted in red because there will be no letter able to be painted in green.\nThe fifth test case contains a string of identical letters, so there's no way to paint more than one letter in red.", "input": [ [ [ "kzaaa" ] ], [ [ "codeforces" ] ], [ [ "archive" ] ], [ [ "y" ] ], [ [ "xxxxxx" ] ] ], "output": [ "2", "5", "3", "0", "1" ] }, { "problem_id": "1551A", "problem_name": "Polycarp and Coins\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1551/A", "problem_solution_link": "https://codeforces.com/problemset/status/1551/problem/A", "problem_statement": "A. Polycarp and Coins\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp must pay\nexactly\n$$$n$$$ burles at the checkout. He has coins of two nominal values: $$$1$$$ burle and $$$2$$$ burles. Polycarp likes both kinds of coins equally. So he doesn't want to pay with more coins of one type than with the other.\nThus, Polycarp wants to minimize the difference between the count of coins of $$$1$$$ burle and $$$2$$$ burles being used. Help him by determining two non-negative integer values $$$c_1$$$ and $$$c_2$$$ which are the number of coins of $$$1$$$ burle and $$$2$$$ burles, respectively, so that the total value of that number of coins is\nexactly\n$$$n$$$ (i.\u2009e. $$$c_1 + 2 \\cdot c_2 = n$$$), and the absolute value of the difference between $$$c_1$$$ and $$$c_2$$$ is as little as possible (i.\u2009e. you must minimize $$$|c_1-c_2|$$$).\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nEach test case consists of one line. This line contains one integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$) \u2014 the number of burles to be paid by Polycarp.\nOutput\nFor each test case, output a separate line containing two integers $$$c_1$$$ and $$$c_2$$$ ($$$c_1, c_2 \\ge 0$$$) separated by a space where $$$c_1$$$ is the number of coins of $$$1$$$ burle and $$$c_2$$$ is the number of coins of $$$2$$$ burles. If there are multiple optimal solutions, print any one.\nExample\nInput\n6\n1000\n30\n1\n32\n1000000000\n5\nOutput\n334 333\n10 10\n1 0\n10 11\n333333334 333333333\n1 2\nNote\nThe answer for the first test case is \"\n334 333\n\". The sum of the nominal values of all coins is $$$334 \\cdot 1 + 333 \\cdot 2 = 1000$$$, whereas $$$|334 - 333| = 1$$$. One can't get the better value because if $$$|c_1 - c_2| = 0$$$, then $$$c_1 = c_2$$$ and $$$c_1 \\cdot 1 + c_1 \\cdot 2 = 1000$$$, but then the value of $$$c_1$$$ isn't an integer.\nThe answer for the second test case is \"\n10 10\n\". The sum of the nominal values is $$$10 \\cdot 1 + 10 \\cdot 2 = 30$$$ and $$$|10 - 10| = 0$$$, whereas there's no number having an absolute value less than $$$0$$$.", "input": [ [ [ "1000" ] ], [ [ "30" ] ], [ [ "1" ] ], [ [ "32" ] ], [ [ "1000000000" ] ], [ [ "5" ] ] ], "output": [ "334 333", "10 10", "1 0", "10 11", "333333334 333333333", "1 2" ] }, { "problem_id": "1550A", "problem_name": "Find The Array\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1550/A", "problem_solution_link": "https://codeforces.com/problemset/status/1550/problem/A", "problem_statement": "A. Find The Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's call an array $$$a$$$ consisting of $$$n$$$ positive (greater than $$$0$$$) integers\nbeautiful\nif the following condition is held for every $$$i$$$ from $$$1$$$ to $$$n$$$: either $$$a_i = 1$$$, or at least one of the numbers $$$a_i - 1$$$ and $$$a_i - 2$$$ exists in the array as well.\nFor example:\nthe array $$$[5, 3, 1]$$$ is beautiful: for $$$a_1$$$, the number $$$a_1 - 2 = 3$$$ exists in the array; for $$$a_2$$$, the number $$$a_2 - 2 = 1$$$ exists in the array; for $$$a_3$$$, the condition $$$a_3 = 1$$$ holds;\nthe array $$$[1, 2, 2, 2, 2]$$$ is beautiful: for $$$a_1$$$, the condition $$$a_1 = 1$$$ holds; for every other number $$$a_i$$$, the number $$$a_i - 1 = 1$$$ exists in the array;\nthe array $$$[1, 4]$$$ is not beautiful: for $$$a_2$$$, neither $$$a_2 - 2 = 2$$$ nor $$$a_2 - 1 = 3$$$ exists in the array, and $$$a_2 \\ne 1$$$;\nthe array $$$[2]$$$ is not beautiful: for $$$a_1$$$, neither $$$a_1 - 1 = 1$$$ nor $$$a_1 - 2 = 0$$$ exists in the array, and $$$a_1 \\ne 1$$$;\nthe array $$$[2, 1, 3]$$$ is beautiful: for $$$a_1$$$, the number $$$a_1 - 1 = 1$$$ exists in the array; for $$$a_2$$$, the condition $$$a_2 = 1$$$ holds; for $$$a_3$$$, the number $$$a_3 - 2 = 1$$$ exists in the array.\nYou are given a positive integer $$$s$$$. Find the minimum possible size of a beautiful array with the sum of elements equal to $$$s$$$.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 5000$$$) \u2014 the number of test cases.\nThen $$$t$$$ lines follow, the $$$i$$$-th line contains one integer $$$s$$$ ($$$1 \\le s \\le 5000$$$) for the $$$i$$$-th test case.\nOutput\nPrint $$$t$$$ integers, the $$$i$$$-th integer should be the answer for the $$$i$$$-th testcase: the minimum possible size of a beautiful array with the sum of elements equal to $$$s$$$.\nExample\nInput\n4\n1\n8\n7\n42\nOutput\n1\n3\n3\n7\nNote\nConsider the example test:\nin the first test case, the array $$$[1]$$$ meets all conditions;\nin the second test case, the array $$$[3, 4, 1]$$$ meets all conditions;\nin the third test case, the array $$$[1, 2, 4]$$$ meets all conditions;\nin the fourth test case, the array $$$[1, 4, 6, 8, 10, 2, 11]$$$ meets all conditions.", "input": [ [ [ "1" ] ], [ [ "8" ] ], [ [ "7" ] ], [ [ "42" ] ] ], "output": [ "1", "3", "3", "7" ] }, { "problem_id": "1549B", "problem_name": "Gregor and the Pawn Game\ndfs and similar, dp, flows, graph matchings, graphs, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1549/B", "problem_solution_link": "https://codeforces.com/problemset/status/1549/problem/B", "problem_statement": "B. Gregor and the Pawn Game\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a chessboard of size $$$n$$$ by $$$n$$$. The square in the $$$i$$$-th row from top and $$$j$$$-th column from the left is labelled $$$(i,j)$$$.\nCurrently, Gregor has some pawns in the $$$n$$$-th row. There are also enemy pawns in the $$$1$$$-st row. On one turn, Gregor moves one of\nhis\npawns. A pawn can move one square up (from $$$(i,j)$$$ to $$$(i-1,j)$$$) if there is no pawn in the destination square. Additionally, a pawn can move one square diagonally up (from $$$(i,j)$$$ to either $$$(i-1,j-1)$$$ or $$$(i-1,j+1)$$$) if and only if there is an enemy pawn in that square. The enemy pawn is also removed.\nGregor wants to know what is the maximum number of his pawns that can reach row $$$1$$$?\nNote that only Gregor takes turns in this game, and\nthe enemy pawns never move\n. Also, when Gregor's pawn reaches row $$$1$$$, it is stuck and cannot make any further moves.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1\\le t\\le 2\\cdot 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nEach test case consists of three lines. The first line contains a single integer $$$n$$$ ($$$2\\le n\\le 2\\cdot{10}^{5}$$$) \u2014 the size of the chessboard.\nThe second line consists of a string of binary digits of length $$$n$$$, where a $$$1$$$ in the $$$i$$$-th position corresponds to an enemy pawn in the $$$i$$$-th cell from the left, and $$$0$$$ corresponds to an empty cell.\nThe third line consists of a string of binary digits of length $$$n$$$, where a $$$1$$$ in the $$$i$$$-th position corresponds to a Gregor's pawn in the $$$i$$$-th cell from the left, and $$$0$$$ corresponds to an empty cell.\nIt is guaranteed that the sum of $$$n$$$ across all test cases is less than $$$2\\cdot{10}^{5}$$$.\nOutput\nFor each test case, print one integer: the\nmaximum\nnumber of Gregor's pawns which can reach the $$$1$$$-st row.\nExample\nInput\n4\n3\n000\n111\n4\n1111\n1111\n3\n010\n010\n5\n11001\n00000\nOutput\n3\n4\n0\n0\nNote\nIn the first example, Gregor can simply advance all $$$3$$$ of his pawns forward. Thus, the answer is $$$3$$$.\nIn the second example, Gregor can guarantee that all $$$4$$$ of his pawns reach the enemy row, by following the colored paths as demonstrated in the diagram below. Remember, only Gregor takes turns in this \"game\"!\nIn the third example, Gregor's only pawn is stuck behind the enemy pawn, and cannot reach the end.\nIn the fourth example, Gregor has no pawns, so the answer is clearly $$$0$$$.", "input": [ [ [ "3" ], [ "000" ], [ "111" ] ], [ [ "4" ], [ "1111" ], [ "1111" ] ], [ [ "3" ], [ "010" ], [ "010" ] ], [ [ "5" ], [ "11001" ], [ "00000" ] ] ], "output": [ "3", "4", "0", "0" ] }, { "problem_id": "1549A", "problem_name": "Gregor and Cryptography\nmath, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1549/A", "problem_solution_link": "https://codeforces.com/problemset/status/1549/problem/A", "problem_statement": "A. Gregor and Cryptography\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.\nGregor's favorite\nprime\nnumber is $$$P$$$. Gregor wants to find two\nbases\nof $$$P$$$. Formally, Gregor is looking for two integers $$$a$$$ and $$$b$$$ which satisfy both of the following properties.\n$$$P \\bmod a = P \\bmod b$$$, where $$$x \\bmod y$$$ denotes the remainder when $$$x$$$ is divided by $$$y$$$, and\n$$$2 \\le a < b \\le P$$$.\nHelp Gregor find two bases of his favorite prime number!\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$).\nEach subsequent line contains the integer $$$P$$$ ($$$5 \\le P \\le {10}^9$$$), with $$$P$$$ guaranteed to be prime.\nOutput\nYour output should consist of $$$t$$$ lines. Each line should consist of two integers $$$a$$$ and $$$b$$$ ($$$2 \\le a < b \\le P$$$). If there are multiple possible solutions, print any.\nExample\nInput\n2\n17\n5\nOutput\n3 5\n2 4\nNote\nThe first query is $$$P=17$$$. $$$a=3$$$ and $$$b=5$$$ are valid\nbases\nin this case, because $$$17 \\bmod 3 = 17 \\bmod 5 = 2$$$. There are other pairs which work as well.\nIn the second query, with $$$P=5$$$, the only solution is $$$a=2$$$ and $$$b=4$$$.", "input": [ [ [ "17" ] ], [ [ "5" ] ] ], "output": [ "3 5", "2 4" ] }, { "problem_id": "1547B", "problem_name": "Alphabetical Strings\ngreedy, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1547/B", "problem_solution_link": "https://codeforces.com/problemset/status/1547/problem/B", "problem_statement": "B. Alphabetical Strings\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nA string $$$s$$$ of length $$$n$$$ ($$$1 \\le n \\le 26$$$) is called\nalphabetical\nif it can be obtained using the following algorithm:\nfirst, write an empty string to $$$s$$$ (i.e. perform the assignment $$$s$$$\n:= \"\"\n);\nthen perform the next step $$$n$$$ times;\nat the $$$i$$$-th step take $$$i$$$-th lowercase letter of the Latin alphabet and write it either to the left of the string $$$s$$$ or to the right of the string $$$s$$$ (i.e. perform the assignment $$$s$$$\n:=\n$$$c+s$$$ or $$$s$$$\n:=\n$$$s+c$$$, where $$$c$$$ is the $$$i$$$-th letter of the Latin alphabet).\nIn other words, iterate over the $$$n$$$ first letters of the Latin alphabet starting from '\na\n' and etc. Each time we prepend a letter to the left of the string $$$s$$$ or append a letter to the right of the string $$$s$$$. Strings that can be obtained in that way are alphabetical.\nFor example, the following strings are alphabetical: \"\na\n\", \"\nba\n\", \"\nab\n\", \"\nbac\n\" and \"\nihfcbadeg\n\". The following strings\nare not\nalphabetical: \"\nz\n\", \"\naa\n\", \"\nca\n\", \"\nacb\n\", \"\nxyz\n\" and \"\nddcba\n\".\nFrom the given string, determine if it is alphabetical.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. Then $$$t$$$ test cases follow.\nEach test case is written on a separate line that contains one string $$$s$$$. String $$$s$$$ consists of lowercase letters of the Latin alphabet and has a length between $$$1$$$ and $$$26$$$, inclusive.\nOutput\nOutput $$$t$$$ lines, each of them must contain the answer to the corresponding test case. Output\nYES\nif the given string $$$s$$$ is alphabetical and\nNO\notherwise.\nYou can output\nYES\nand\nNO\nin any case (for example, strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as a positive answer).\nExample\nInput\n11\na\nba\nab\nbac\nihfcbadeg\nz\naa\nca\nacb\nxyz\nddcba\nOutput\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNote\nThe example contains test cases from the main part of the condition.", "input": [ [ [ "ihfcbadeg" ], [ "ddcba" ] ] ], "output": [ "YES", "NO" ] }, { "problem_id": "1547A", "problem_name": "Shortest Path with Obstacle\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1547/A", "problem_solution_link": "https://codeforces.com/problemset/status/1547/problem/A", "problem_statement": "A. Shortest Path with Obstacle\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are three cells on an infinite 2-dimensional grid, labeled $$$A$$$, $$$B$$$, and $$$F$$$. Find the length of the shortest path from $$$A$$$ to $$$B$$$ if:\nin one move you can go to any of the four adjacent cells sharing a side;\nvisiting the cell $$$F$$$ is forbidden (it is an obstacle).\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases in the input. Then $$$t$$$ test cases follow. Before each test case, there is an empty line.\nEach test case contains three lines. The first one contains two integers $$$x_A, y_A$$$ ($$$1 \\le x_A, y_A \\le 1000$$$)\u00a0\u2014 coordinates of the start cell $$$A$$$. The second one contains two integers $$$x_B, y_B$$$ ($$$1 \\le x_B, y_B \\le 1000$$$)\u00a0\u2014 coordinates of the finish cell $$$B$$$. The third one contains two integers $$$x_F, y_F$$$ ($$$1 \\le x_F, y_F \\le 1000$$$)\u00a0\u2014 coordinates of the forbidden cell $$$F$$$. All cells are distinct.\nCoordinate $$$x$$$ corresponds to the column number and coordinate $$$y$$$ corresponds to the row number (see the pictures below).\nOutput\nOutput $$$t$$$ lines. The $$$i$$$-th line should contain the answer for the $$$i$$$-th test case: the length of the shortest path from the cell $$$A$$$ to the cell $$$B$$$ if the cell $$$F$$$ is not allowed to be visited.\nExample\nInput\n7\n\n1 1\n3 3\n2 2\n\n2 5\n2 1\n2 3\n\n1000 42\n1000 1\n1000 1000\n\n1 10\n3 10\n2 10\n\n3 8\n7 8\n3 7\n\n2 1\n4 1\n1 1\n\n1 344\n1 10\n1 1\nOutput\n4\n6\n41\n4\n4\n2\n334\nNote\nAn example of a possible shortest path for the first test case.\nAn example of a possible shortest path for the second test case.", "input": [ [ [ "" ], [ "1", "1" ], [ "3", "3" ], [ "2", "2" ] ], [ [ "" ], [ "2", "5" ], [ "2", "1" ], [ "2", "3" ] ], [ [ "" ], [ "1000", "42" ], [ "1000", "1" ], [ "1000", "1000" ] ], [ [ "" ], [ "1", "10" ], [ "3", "10" ], [ "2", "10" ] ], [ [ "" ], [ "3", "8" ], [ "7", "8" ], [ "3", "7" ] ], [ [ "" ], [ "2", "1" ], [ "4", "1" ], [ "1", "1" ] ], [ [ "" ], [ "1", "344" ], [ "1", "10" ], [ "1", "1" ] ] ], "output": [ "4", "6", "41", "4", "4", "2", "334" ] }, { "problem_id": "1546A", "problem_name": "AquaMoon and Two Arrays\nbrute force, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1546/A", "problem_solution_link": "https://codeforces.com/problemset/status/1546/problem/A", "problem_statement": "A. AquaMoon and Two Arrays\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays $$$a$$$ and $$$b$$$, both consist of $$$n$$$ non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero):\nShe chooses two indices $$$i$$$ and $$$j$$$ ($$$1 \\le i, j \\le n$$$), then decreases the $$$i$$$-th element of array $$$a$$$ by $$$1$$$, and increases the $$$j$$$-th element of array $$$a$$$ by $$$1$$$. The resulting values at $$$i$$$-th and $$$j$$$-th index of array $$$a$$$ are $$$a_i - 1$$$ and $$$a_j + 1$$$, respectively. Each element of array $$$a$$$\nmust be non-negative after each operation\n. If $$$i = j$$$ this operation doesn't change the array $$$a$$$.\nAquaMoon wants to make some operations to make arrays $$$a$$$ and $$$b$$$ equal. Two arrays $$$a$$$ and $$$b$$$ are considered equal if and only if $$$a_i = b_i$$$ for all $$$1 \\leq i \\leq n$$$.\nHelp AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays $$$a$$$ and $$$b$$$ equal.\nPlease note, that you\ndon't have to minimize\nthe number of operations.\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$) \u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$).\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$0 \\leq a_i \\leq 100$$$).\nThe sum of all $$$a_i$$$ does not exceed $$$100$$$.\nThe third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \\dots, b_n$$$ ($$$0 \\leq b_i \\leq 100$$$).\nThe sum of all $$$b_i$$$ does not exceed $$$100$$$.\nOutput\nFor each test case print \"\n-1\n\" on the only line if it is impossible to make two arrays equal with some sequence of operations.\nOtherwise, print an integer $$$m$$$ ($$$0 \\leq m \\leq 100$$$) in the first line \u2014 the number of operations. Then print $$$m$$$ lines, each line consists of two integers $$$i$$$ and $$$j$$$ \u2014 the indices you choose for the operation.\nIt can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with $$$m \\leq 100$$$.\nIf there are multiple possible solutions, you can print any.\nExample\nInput\n4\n4\n1 2 3 4\n3 1 2 4\n2\n1 3\n2 1\n1\n0\n0\n5\n4 3 2 1 0\n0 1 2 3 4\nOutput\n2\n2 1\n3 1\n-1\n0\n6\n1 4\n1 4\n1 5\n1 5\n2 5\n2 5\nNote\nIn the first example, we do the following operations:\n$$$i = 2$$$, $$$j = 1$$$: $$$[1, 2, 3, 4] \\rightarrow [2, 1, 3, 4]$$$;\n$$$i = 3$$$, $$$j = 1$$$: $$$[2, 1, 3, 4] \\rightarrow [3, 1, 2, 4]$$$;\nIn the second example, it's impossible to make two arrays equal.", "input": [ [ [ "4" ], [ "1", "2", "3", "4" ], [ "3", "1", "2", "4" ] ], [ [ "2" ], [ "1", "3" ], [ "2", "1" ] ], [ [ "1" ], [ "0" ], [ "0" ] ], [ [ "5" ], [ "4", "3", "2", "1", "0" ], [ "0", "1", "2", "3", "4" ] ] ], "output": [ ["2", "2 1", "3 1"], ["-1"], ["0"], ["6", "1 4", "1 4", "1 5", "1 5", "2 5", "2 5"] ], "error": true }, { "problem_id": "1542A", "problem_name": "Odd Set\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1542/A", "problem_solution_link": "https://codeforces.com/problemset/status/1542/problem/A", "problem_statement": "A. Odd Set\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a multiset (i.\u00a0e. a set that can contain multiple equal integers) containing $$$2n$$$ integers. Determine if you can split it into exactly $$$n$$$ pairs (i.\u00a0e. each element should be in exactly one pair) so that the sum of the two elements in each pair is\nodd\n(i.\u00a0e. when divided by $$$2$$$, the remainder is $$$1$$$).\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\\leq t\\leq 100$$$) \u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1\\leq n\\leq 100$$$).\nThe second line of each test case contains $$$2n$$$ integers $$$a_1,a_2,\\dots, a_{2n}$$$ ($$$0\\leq a_i\\leq 100$$$) \u2014 the numbers in the set.\nOutput\nFor each test case, print \"\nYes\n\" if it can be split into exactly $$$n$$$ pairs so that the sum of the two elements in each pair is\nodd\n, and \"\nNo\n\" otherwise. You can print each letter in any case.\nExample\nInput\n5\n2\n2 3 4 5\n3\n2 3 4 5 5 5\n1\n2 4\n1\n2 3\n4\n1 5 3 2 6 7 3 4\nOutput\nYes\nNo\nNo\nYes\nNo\nNote\nIn the first test case, a possible way of splitting the set is $$$(2,3)$$$, $$$(4,5)$$$.\nIn the second, third and fifth test case, we can prove that there isn't any possible way.\nIn the fourth test case, a possible way of splitting the set is $$$(2,3)$$$.", "input": [ [ [ "2" ], [ "2", "3", "4", "5" ] ], [ [ "3" ], [ "2", "3", "4", "5", "5", "5" ] ], [ [ "1" ], [ "2", "4" ] ], [ [ "1" ], [ "2", "3" ] ], [ [ "4" ], [ "1", "5", "3", "2", "6", "7", "3", "4" ] ] ], "output": [ "Yes", "No", "No", "Yes", "No" ] }, { "problem_id": "1541A", "problem_name": "Pretty Permutations\nconstructive algorithms, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1541/A", "problem_solution_link": "https://codeforces.com/problemset/status/1541/problem/A", "problem_statement": "A. Pretty Permutations\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ cats in a line, labeled from $$$1$$$ to $$$n$$$, with the $$$i$$$-th cat at position $$$i$$$. They are bored of gyrating in the same spot all day, so they want to reorder themselves such that no cat is in the same place as before. They are also lazy, so they want to minimize the total distance they move. Help them decide what cat should be at each location after the reordering.\nFor example, if there are $$$3$$$ cats, this is a valid reordering: $$$[3, 1, 2]$$$. No cat is in its original position. The total distance the cats move is $$$1 + 1 + 2 = 4$$$ as cat $$$1$$$ moves one place to the right, cat $$$2$$$ moves one place to the right, and cat $$$3$$$ moves two places to the left.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first and only line of each test case contains one integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$)\u00a0\u2014 the number of cats.\nIt can be proven that under the constraints of the problem, an answer always exist.\nOutput\nOutput $$$t$$$ answers, one for each test case. Each answer consists of $$$n$$$ integers\u00a0\u2014 a permutation with the minimum total distance. If there are multiple answers, print any.\nExample\nInput\n2\n2\n3\nOutput\n2 1 \n3 1 2\nNote\nFor the first test case, there is only one possible permutation that satisfies the conditions: $$$[2, 1]$$$.\nThe second test case was described in the statement. Another possible answer is $$$[2, 3, 1]$$$.", "input": [ [ [ "2" ] ], [ [ "3" ] ] ], "output": [ "2 1 ", "3 1 2" ] }, { "problem_id": "1539B", "problem_name": "Love Song\ndp, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1539/B", "problem_solution_link": "https://codeforces.com/problemset/status/1539/problem/B", "problem_statement": "B. Love Song\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPetya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up $$$q$$$ questions about this song. Each question is about a subsegment of the song starting from the $$$l$$$-th letter to the $$$r$$$-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment $$$k$$$ times, where $$$k$$$ is the index of the corresponding letter in the alphabet. For example, if the question is about the substring \"\nabbcb\n\", then Vasya repeats letter '\na\n' once, each of the letters '\nb\n' twice, letter '\nc\n\" three times, so that the resulting string is \"\nabbbbcccbb\n\", its length is $$$10$$$. Vasya is interested about the length of the resulting string.\nHelp Petya find the length of each string obtained by Vasya.\nInput\nThe first line contains two integers $$$n$$$ and $$$q$$$ ($$$1\\leq n\\leq 100\\,000$$$, $$$1\\leq q \\leq 100\\,000$$$)\u00a0\u2014 the length of the song and the number of questions.\nThe second line contains one string $$$s$$$\u00a0\u2014 the song, consisting of $$$n$$$ lowercase letters of English letters.\nVasya's questions are contained in the next $$$q$$$ lines. Each line contains two integers $$$l$$$ and $$$r$$$ ($$$1 \\leq l \\leq r \\leq n$$$)\u00a0\u2014 the bounds of the question.\nOutput\nPrint $$$q$$$ lines: for each question print the length of the string obtained by Vasya.\nExamples\nInput\n7 3\nabacaba\n1 3\n2 5\n1 7\nOutput\n4\n7\n11\nInput\n7 4\nabbabaa\n1 3\n5 7\n6 6\n2 4\nOutput\n5\n4\n1\n5\nInput\n13 7\nsonoshikumiwo\n1 5\n2 10\n7 7\n1 13\n4 8\n2 5\n3 9\nOutput\n82\n125\n9\n191\n62\n63\n97\nNote\nIn the first example Vasya is interested in three questions. In the first question Vasya considers the substring \"\naba\n\", that transforms to \"\nabba\n\", so the answer is equal to $$$4$$$. In the second question Vasya considers \"\nbaca\n\", that transforms to \"\nbbaccca\n\", so the answer is $$$7$$$. In the third question Vasya considers the string \"\nabacaba\n\",that transforms to \"\nabbacccabba\n\" of length $$$11$$$.", "input": [ [ [ "13", "7" ], [ "sonoshikumiwo", "1", "5", "2", "10", "7", "7", "1", "13", "4", "8", "2", "5", "3", "9" ] ] ], "output": [ "82\n125\n9\n191\n62\n63\n97" ] }, { "problem_id": "1534A", "problem_name": "Colour the Flag\nbrute force, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1534/A", "problem_solution_link": "https://codeforces.com/problemset/status/1534/problem/A", "problem_statement": "A. Colour the Flag\ntime limit per test\n1.5 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nToday we will be playing a red and white colouring game (no, this is not the Russian Civil War; these are just the colours of the Canadian flag).\nYou are given an $$$n \\times m$$$ grid of \"\nR\n\", \"\nW\n\", and \"\n.\n\" characters. \"\nR\n\" is red, \"\nW\n\" is white and \"\n.\n\" is blank. The neighbours of a cell are those that share an edge with it (those that only share a corner do not count).\nYour job is to colour the blank cells red or white so that every red cell only has white neighbours (and no red ones) and every white cell only has red neighbours (and no white ones). You are not allowed to recolour already coloured cells.\nInput\nThe first line contains $$$t$$$ ($$$1 \\le t \\le 100$$$), the number of test cases.\nIn each test case, the first line will contain $$$n$$$ ($$$1 \\le n \\le 50$$$) and $$$m$$$ ($$$1 \\le m \\le 50$$$), the height and width of the grid respectively.\nThe next $$$n$$$ lines will contain the grid. Each character of the grid is either '\nR\n', '\nW\n', or '\n.\n'.\nOutput\nFor each test case, output \"\nYES\n\" if there is a valid grid or \"\nNO\n\" if there is not.\nIf there is, output the grid on the next $$$n$$$ lines. If there are multiple answers, print any.\nIn the output, the \"\nYES\n\"s and \"\nNO\n\"s are case-insensitive, meaning that outputs such as \"\nyEs\n\" and \"\nnO\n\" are valid. However,\nthe grid is case-sensitive\n.\nExample\nInput\n3\n4 6\n.R....\n......\n......\n.W....\n4 4\n.R.W\n....\n....\n....\n5 1\nR\nW\nR\nW\nR\nOutput\nYES\nWRWRWR\nRWRWRW\nWRWRWR\nRWRWRW\nNO\nYES\nR\nW\nR\nW\nR\nNote\nThe answer for the first example case is given in the example output, and it can be proven that no grid exists that satisfies the requirements of the second example case. In the third example all cells are initially coloured, and the colouring is valid.", "input": [ [ [ "4", "6" ], [ ".R....", "......", "......", ".W...." ], [ "4", "4" ], [ ".R.W", "....", "....", "...." ], [ "5", "1" ], [ "R", "W", "R", "W", "R" ] ] ], "output": [ "YES\nWRWRWR\nRWRWRW\nWRWRWR\nRWRWRW", "NO", "YES\nR\nW\nR\nW\nR" ] }, { "problem_id": "1538B", "problem_name": "Friends and Candies\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1538/B", "problem_solution_link": "https://codeforces.com/problemset/status/1538/problem/B", "problem_statement": "B. Friends and Candies\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp has $$$n$$$ friends, the $$$i$$$-th of his friends has $$$a_i$$$ candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all $$$a_i$$$ to be the same. To solve this, Polycarp performs the following set of actions exactly\nonce\n:\nPolycarp chooses $$$k$$$ ($$$0 \\le k \\le n$$$) arbitrary friends (let's say he chooses friends with indices $$$i_1, i_2, \\ldots, i_k$$$);\nPolycarp distributes their $$$a_{i_1} + a_{i_2} + \\ldots + a_{i_k}$$$ candies among all $$$n$$$ friends. During distribution for each of $$$a_{i_1} + a_{i_2} + \\ldots + a_{i_k}$$$ candies he chooses new owner. That can be any of $$$n$$$ friends. Note, that any candy can be given to the person, who has owned that candy before the distribution process.\nNote that the number $$$k$$$ is not fixed in advance and can be arbitrary. Your task is to find the minimum value of $$$k$$$.\nFor example, if $$$n=4$$$ and $$$a=[4, 5, 2, 5]$$$, then Polycarp could make the following distribution of the candies:\nPolycarp chooses $$$k=2$$$ friends with indices $$$i=[2, 4]$$$ and distributes $$$a_2 + a_4 = 10$$$ candies to make $$$a=[4, 4, 4, 4]$$$ (two candies go to person $$$3$$$).\nNote that in this example Polycarp cannot choose $$$k=1$$$ friend so that he can redistribute candies so that in the end all $$$a_i$$$ are equal.\nFor the data $$$n$$$ and $$$a$$$, determine the\nminimum\nvalue $$$k$$$. With this value $$$k$$$, Polycarp should be able to select $$$k$$$ friends and redistribute their candies so that everyone will end up with the same number of candies.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$). Then $$$t$$$ test cases follow.\nThe first line of each test case contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$).\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i \\le 10^4$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case output:\nthe minimum value of $$$k$$$, such that Polycarp can choose exactly $$$k$$$ friends so that he can redistribute the candies in the desired way;\n\"\n-1\n\" if no such value $$$k$$$ exists.\nExample\nInput\n5\n4\n4 5 2 5\n2\n0 4\n5\n10 8 5 1 4\n1\n10000\n7\n1 1 1 1 1 1 1\nOutput\n2\n1\n-1\n0\n0", "input": [ [ [ "4" ], [ "4", "5", "2", "5" ] ], [ [ "2" ], [ "0", "4" ] ], [ [ "5" ], [ "10", "8", "5", "1", "4" ] ], [ [ "1" ], [ "10000" ] ], [ [ "7" ], [ "1", "1", "1", "1", "1", "1", "1" ] ] ], "output": [ "2", "1", "-1", "0", "0" ] }, { "problem_id": "1538A", "problem_name": "Stone Game\nbrute force, dp, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1538/A", "problem_solution_link": "https://codeforces.com/problemset/status/1538/problem/A", "problem_statement": "A. Stone Game\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp is playing a new computer game. This game has $$$n$$$ stones in a row. The stone on the position $$$i$$$ has integer power $$$a_i$$$.\nThe powers of all stones are distinct\n.\nEach turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.\nNow, Polycarp wants two achievements. He gets them if he destroys the stone with the\nleast\npower and the stone with the\ngreatest\npower. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.\nFor example, if $$$n = 5$$$ and $$$a = [1, 5, 4, 3, 2]$$$, then Polycarp could make the following moves:\nDestroy the leftmost stone. After this move $$$a = [5, 4, 3, 2]$$$;\nDestroy the rightmost stone. After this move $$$a = [5, 4, 3]$$$;\nDestroy the leftmost stone. After this move $$$a = [4, 3]$$$. Polycarp destroyed the stones with the greatest and least power, so he can end the game.\nPlease note that in the example above, you can complete the game in two steps. For example:\nDestroy the leftmost stone. After this move $$$a = [5, 4, 3, 2]$$$;\nDestroy the leftmost stone. After this move $$$a = [4, 3, 2]$$$. Polycarp destroyed the stones with the greatest and least power, so he can end the game.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 100$$$). Then $$$t$$$ test cases follow.\nThe first line of each test case contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$)\u00a0\u2014 the number of stones.\nThe second line contains $$$n$$$ distinct integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le n$$$)\u00a0\u2014 the power of the stones.\nOutput\nFor each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.\nExample\nInput\n5\n5\n1 5 4 3 2\n8\n2 1 3 4 5 6 8 7\n8\n4 2 3 1 8 6 7 5\n4\n3 4 2 1\n4\n2 3 1 4\nOutput\n2\n4\n5\n3\n2", "input": [ [ [ "5" ], [ "1", "5", "4", "3", "2" ] ], [ [ "8" ], [ "2", "1", "3", "4", "5", "6", "8", "7" ] ], [ [ "8" ], [ "4", "2", "3", "1", "8", "6", "7", "5" ] ], [ [ "4" ], [ "3", "4", "2", "1" ] ], [ [ "4" ], [ "2", "3", "1", "4" ] ] ], "output": [ "2", "4", "5", "3", "2" ] }, { "problem_id": "1537A", "problem_name": "Arithmetic Array\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1537/A", "problem_solution_link": "https://codeforces.com/problemset/status/1537/problem/A", "problem_statement": "A. Arithmetic Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAn array $$$b$$$ of length $$$k$$$ is called good if its arithmetic mean is equal to $$$1$$$. More formally, if $$$$$$\\frac{b_1 + \\cdots + b_k}{k}=1.$$$$$$\nNote that the value $$$\\frac{b_1+\\cdots+b_k}{k}$$$ is not rounded up or down. For example, the array $$$[1,1,1,2]$$$ has an arithmetic mean of $$$1.25$$$, which is not equal to $$$1$$$.\nYou are given an integer array $$$a$$$ of length $$$n$$$. In an operation, you can append a\nnon-negative\ninteger to the end of the array. What's the minimum number of operations required to make the array good?\nWe have a proof that it is always possible with finitely many operations.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 50$$$) \u2014 the length of the initial array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1,\\ldots,a_n$$$ ($$$-10^4\\leq a_i \\leq 10^4$$$), the elements of the array.\nOutput\nFor each test case, output a single integer \u2014 the minimum number of non-negative integers you have to append to the array so that the arithmetic mean of the array will be exactly $$$1$$$.\nExample\nInput\n4\n3\n1 1 1\n2\n1 2\n4\n8 4 6 2\n1\n-2\nOutput\n0\n1\n16\n1\nNote\nIn the first test case, we don't need to add any element because the arithmetic mean of the array is already $$$1$$$, so the answer is $$$0$$$.\nIn the second test case, the arithmetic mean is not $$$1$$$ initially so we need to add at least one more number. If we add $$$0$$$ then the arithmetic mean of the whole array becomes $$$1$$$, so the answer is $$$1$$$.\nIn the third test case, the minimum number of elements that need to be added is $$$16$$$ since only non-negative integers can be added.\nIn the fourth test case, we can add a single integer $$$4$$$. The arithmetic mean becomes $$$\\frac{-2+4}{2}$$$ which is equal to $$$1$$$.", "input": [ [ [ "3" ], [ "1", "1", "1" ] ], [ [ "2" ], [ "1", "2" ] ], [ [ "4" ], [ "8", "4", "6", "2" ] ], [ [ "1" ], [ "-2" ] ] ], "output": [ "0", "1", "16", "1" ] }, { "problem_id": "1536A", "problem_name": "Omkar and Bad Story\nbrute force, constructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1536/A", "problem_solution_link": "https://codeforces.com/problemset/status/1536/problem/A", "problem_statement": "A. Omkar and Bad Story\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nOmkar has received a message from Anton saying \"Your story for problem A is confusing. Just make a formal statement.\" Because of this, Omkar gives you an array $$$a = [a_1, a_2, \\ldots, a_n]$$$ of $$$n$$$ distinct integers. An array $$$b = [b_1, b_2, \\ldots, b_k]$$$ is called\nnice\nif for any two distinct elements $$$b_i, b_j$$$ of $$$b$$$, $$$|b_i-b_j|$$$ appears in $$$b$$$ at least once. In addition, all elements in $$$b$$$ must be distinct. Can you add several (maybe, $$$0$$$) integers to $$$a$$$ to create a\nnice\narray $$$b$$$\nof size at most $$$300$$$\n? If $$$a$$$ is already\nnice\n, you don't have to add any elements.\nFor example, array $$$[3, 6, 9]$$$ is\nnice\n, as $$$|6-3|=|9-6| = 3$$$, which appears in the array, and $$$|9-3| = 6$$$, which appears in the array, while array $$$[4, 2, 0, 6, 9]$$$ is not\nnice\n, as $$$|9-4| = 5$$$ is not present in the array.\nFor integers $$$x$$$ and $$$y$$$, $$$|x-y| = x-y$$$ if $$$x > y$$$ and $$$|x-y| = y-x$$$ otherwise.\nInput\nEach test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \\leq t \\leq 50$$$), the number of test cases. Description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$) \u2014 the length of the array $$$a$$$.\nThe second line of each test case contains $$$n$$$\ndistinct\nintegers $$$a_1, a_2, \\cdots, a_n$$$ ($$$-100 \\leq a_i \\leq 100$$$) \u2014 the elements of the array $$$a$$$.\nOutput\nFor each test case, output one line containing\nYES\nif Omkar can create a\nnice\narray $$$b$$$ by adding elements to $$$a$$$ and\nNO\notherwise. The case of each letter does not matter, so\nyEs\nand\nnO\nwill also be accepted.\nIf the first line is\nYES\n, output a second line containing a single integer $$$k$$$ ($$$n \\leq k \\leq 300$$$).\nThen output one line containing $$$k$$$\ndistinct\nintegers $$$b_1, b_2, \\cdots, b_k$$$ ($$$-10^9 \\leq b_i \\leq 10^9$$$), the elements of the\nnice\narray $$$b$$$. $$$b_1, b_2, \\cdots, b_k$$$ can be in any order. For each $$$a_i$$$ in $$$a$$$, $$$a_i$$$ must appear at least once in $$$b$$$.\nIt can be proved that if Omkar can create such an array $$$b$$$, then he can also do so in a way that satisfies the above constraints.\nIf multiple solutions exist, you can print any.\nExample\nInput\n4\n3\n3 0 9\n2\n3 4\n5\n-7 3 13 -2 8\n4\n4 8 12 6\nOutput\nyes\n4\n6 0 3 9\nyEs\n5\n5 3 1 2 4\nNO\nYes\n6\n8 12 6 2 4 10\nNote\nFor the first case, you can add integers to $$$a$$$ to receive the array $$$b = [6, 0, 3, 9]$$$. Note that $$$|6-3| = |9-6| = |3-0| = 3$$$ and $$$3$$$ is in $$$b$$$, $$$|6-0| = |9-3| = 6$$$ and $$$6$$$ is in $$$b$$$, and $$$|9-0| = 9$$$ is in $$$b$$$, so $$$b$$$ is\nnice\n.\nFor the second case, you can add integers to $$$a$$$ to receive the array $$$b = [5, 3, 1, 2, 4]$$$. We have that $$$|2-1| = |3-2| = |4-3| = |5-4| = 1$$$ is in $$$b$$$, $$$|3-1| = |4-2| = |5-3| = 2$$$ is in $$$b$$$, $$$|4-1| = |5-2| = 3$$$ is in $$$b$$$, and $$$|5-1| = 4$$$ is in $$$b$$$, so $$$b$$$ is\nnice\n.\nFor the fourth case, you can add integers to $$$a$$$ to receive the array $$$b = [8, 12, 6, 2, 4, 10]$$$. We have that $$$|4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2$$$ is in $$$b$$$, $$$|6-2| = |8-4| = |10-6| = |12-8| = 4$$$ is in $$$b$$$, $$$|8-2| = |10-4| = |12-6| = 6$$$ is in $$$b$$$, $$$|10-2| = |12-4| = 8$$$ is in $$$b$$$, and $$$|12-2| = 10$$$ is in $$$b$$$, so $$$b$$$ is\nnice\n.\nIt can be proven that for all other test cases it is impossible to create a\nnice\narray $$$b$$$.", "input": [ [ [ "3" ], [ "3", "0", "9" ] ], [ [ "2" ], [ "3", "4" ] ], [ [ "5" ], [ "-7", "3", "13", "-2", "8" ] ], [ [ "4" ], [ "4", "8", "12", "6" ] ] ], "output": [ ["yes", "4", "6 0 3 9"], ["yEs", "5", "5 3 1 2 4"], ["NO"], ["Yes", "6", "8 12 6 2 4 10"] ], "error": true }, { "problem_id": "1535A", "problem_name": "Fair Playoff\nbrute force, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1535/A", "problem_solution_link": "https://codeforces.com/problemset/status/1535/problem/A", "problem_statement": "A. Fair Playoff\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nFour players participate in the playoff tournament. The tournament is held according to the following scheme: the first player will play with the second, and the third player with the fourth, then the winners of the pairs will play in the finals of the tournament.\nIt is known that in a match between two players, the one whose skill is greater will win. The skill of the $$$i$$$-th player is equal to $$$s_i$$$ and all skill levels are pairwise different (i.\u2009e. there are no two identical values in the array $$$s$$$).\nThe tournament is called\nfair\nif the two players with the highest skills meet in the finals.\nDetermine whether the given tournament is\nfair\n.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases.\nA single line of test case contains four integers $$$s_1, s_2, s_3, s_4$$$ ($$$1 \\le s_i \\le 100$$$)\u00a0\u2014 skill of the players. It is guaranteed that all the numbers in the array are different.\nOutput\nFor each testcase, output\nYES\nif the tournament is\nfair\n, or\nNO\notherwise.\nExample\nInput\n4\n3 7 9 5\n4 5 6 9\n5 3 8 1\n6 5 3 2\nOutput\nYES\nNO\nYES\nNO\nNote\nConsider the example:\nin the first test case, players $$$2$$$ and $$$3$$$ with skills $$$7$$$ and $$$9$$$ advance to the finals;\nin the second test case, players $$$2$$$ and $$$4$$$ with skills $$$5$$$ and $$$9$$$ advance to the finals. The player with skill $$$6$$$ does not advance, but the player with skill $$$5$$$ advances to the finals, so the tournament is not fair;\nin the third test case, players $$$1$$$ and $$$3$$$ with skills $$$5$$$ and $$$8$$$ advance to the finals;\nin the fourth test case, players $$$1$$$ and $$$3$$$ with skills $$$6$$$ and $$$3$$$ advance to the finals. The player with skill $$$5$$$ does not advance, but the player with skill $$$3$$$ advances to the finals, so the tournament is not fair.", "input": [ [ [ "3", "7", "9", "5" ] ], [ [ "4", "5", "6", "9" ] ], [ [ "5", "3", "8", "1" ] ], [ [ "6", "5", "3", "2" ] ] ], "output": [ "YES", "NO", "YES", "NO" ] }, { "problem_id": "1530B", "problem_name": "Putting Plates\nconstructive algorithms, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1530/B", "problem_solution_link": "https://codeforces.com/problemset/status/1530/problem/B", "problem_statement": "B. Putting Plates\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nTo celebrate your birthday you have prepared a festive table! Now you want to seat as many guests as possible.\nThe table can be represented as a rectangle with height $$$h$$$ and width $$$w$$$, divided into $$$h \\times w$$$ cells. Let $$$(i, j)$$$ denote the cell in the $$$i$$$-th row and the $$$j$$$-th column of the rectangle ($$$1 \\le i \\le h$$$; $$$1 \\le j \\le w$$$).\nInto each cell of the table you can either put a plate or keep it empty.\nAs each guest has to be seated next to their plate, you can only put plates on the edge of the table\u00a0\u2014 into the first or the last row of the rectangle, or into the first or the last column. Formally, for each cell $$$(i, j)$$$ you put a plate into, at least one of the following conditions must be satisfied: $$$i = 1$$$, $$$i = h$$$, $$$j = 1$$$, $$$j = w$$$.\nTo make the guests comfortable, no two plates must be put into cells that have a common side or corner. In other words, if cell $$$(i, j)$$$ contains a plate, you can't put plates into cells $$$(i - 1, j)$$$, $$$(i, j - 1)$$$, $$$(i + 1, j)$$$, $$$(i, j + 1)$$$, $$$(i - 1, j - 1)$$$, $$$(i - 1, j + 1)$$$, $$$(i + 1, j - 1)$$$, $$$(i + 1, j + 1)$$$.\nPut as many plates on the table as possible without violating the rules above.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases.\nEach of the following $$$t$$$ lines describes one test case and contains two integers $$$h$$$ and $$$w$$$ ($$$3 \\le h, w \\le 20$$$)\u00a0\u2014 the height and the width of the table.\nOutput\nFor each test case, print $$$h$$$ lines containing $$$w$$$ characters each. Character $$$j$$$ in line $$$i$$$ must be equal to $$$1$$$ if you are putting a plate into cell $$$(i, j)$$$, and $$$0$$$ otherwise. If there are multiple answers, print any.\nAll plates must be put on the edge of the table. No two plates can be put into cells that have a common side or corner. The number of plates put on the table under these conditions must be as large as possible.\nYou are allowed to print additional empty lines.\nExample\nInput\n3\n3 5\n4 4\n5 6\nOutput\n10101\n00000\n10101\n\n0100\n0001\n1000\n0010\n\n010101\n000000\n100001\n000000\n101010\nNote\nFor the first test case, example output contains the only way to put $$$6$$$ plates on the table.\nFor the second test case, there are many ways to put $$$4$$$ plates on the table, example output contains one of them.\nPutting more than $$$6$$$ plates in the first test case or more than $$$4$$$ plates in the second test case is impossible.", "input": [ [ [ "3", "5" ] ], [ [ "4", "4" ] ], [ [ "5", "6" ] ] ], "output": [ ["10101", "00000", "10101"], ["0100", "0001", "1000", "0010"], ["010101", "000000", "100001", "000000", "101010"] ], "error": true }, { "problem_id": "1530A", "problem_name": "Binary Decimal\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1530/A", "problem_solution_link": "https://codeforces.com/problemset/status/1530/problem/A", "problem_statement": "A. Binary Decimal\ntime limit per test\n1 second\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's call a number a\nbinary decimal\nif it's a positive integer and all digits in its decimal notation are either $$$0$$$ or $$$1$$$. For example, $$$1\\,010\\,111$$$ is a binary decimal, while $$$10\\,201$$$ and $$$787\\,788$$$ are not.\nGiven a number $$$n$$$, you are asked to represent $$$n$$$ as a sum of some (not necessarily distinct) binary decimals. Compute the smallest number of binary decimals required for that.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$), denoting the number of test cases.\nThe only line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$), denoting the number to be represented.\nOutput\nFor each test case, output the smallest number of binary decimals required to represent $$$n$$$ as a sum.\nExample\nInput\n3\n121\n5\n1000000000\nOutput\n2\n5\n1\nNote\nIn the first test case, $$$121$$$ can be represented as $$$121 = 110 + 11$$$ or $$$121 = 111 + 10$$$.\nIn the second test case, $$$5$$$ can be represented as $$$5 = 1 + 1 + 1 + 1 + 1$$$.\nIn the third test case, $$$1\\,000\\,000\\,000$$$ is a binary decimal itself, thus the answer is $$$1$$$.", "input": [ [ [ "121" ] ], [ [ "5" ] ], [ [ "1000000000" ] ] ], "output": [ "2", "5", "1" ] }, { "problem_id": "1529A", "problem_name": "Eshag Loves Big Arrays\nconstructive algorithms, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1529/A", "problem_solution_link": "https://codeforces.com/problemset/status/1529/problem/A", "problem_statement": "A. Eshag Loves Big Arrays\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nEshag has an array $$$a$$$ consisting of $$$n$$$ integers.\nEshag can perform the following operation any number of times: choose some subsequence of $$$a$$$ and delete every element from it which is\nstrictly\nlarger than $$$AVG$$$, where $$$AVG$$$ is the average of the numbers in the chosen subsequence.\nFor example, if $$$a = [1 , 4 , 3 , 2 , 4]$$$ and Eshag applies the operation to the subsequence containing $$$a_1$$$, $$$a_2$$$, $$$a_4$$$ and $$$a_5$$$, then he will delete those of these $$$4$$$ elements which are larger than $$$\\frac{a_1+a_2+a_4+a_5}{4} = \\frac{11}{4}$$$, so after the operation, the array $$$a$$$ will become $$$a = [1 , 3 , 2]$$$.\nYour task is to find the\nmaximum\nnumber of elements Eshag can delete from the array $$$a$$$ by applying the operation described above some number (maybe, zero) times.\nA sequence $$$b$$$ is a subsequence of an array $$$c$$$ if $$$b$$$ can be obtained from $$$c$$$ by deletion of several (possibly, zero or all) elements.\nInput\nThe first line contains an integer $$$t$$$ $$$(1\\le t\\le 100)$$$ \u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ $$$(1\\le n\\le 100)$$$ \u2014 the length of the array $$$a$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ $$$(1\\le a_i \\le 100)$$$ \u2014 the elements of the array $$$a$$$.\nOutput\nFor each test case print a single integer \u2014 the\nmaximum\nnumber of elements Eshag can delete from the array $$$a$$$.\nExample\nInput\n3\n6\n1 1 1 2 2 3\n6\n9 9 9 9 9 9\n6\n6 4 1 1 4 1\nOutput\n3\n0\n3\nNote\nConsider the first test case.\nInitially $$$a = [1, 1, 1, 2, 2, 3]$$$.\nIn the first operation, Eshag can choose the subsequence containing $$$a_1$$$, $$$a_5$$$ and $$$a_6$$$, their average is equal to $$$\\frac{a_1 + a_5 + a_6}{3} = \\frac{6}{3} = 2$$$. So $$$a_6$$$ will be deleted.\nAfter this $$$a = [1, 1, 1, 2, 2]$$$.\nIn the second operation, Eshag can choose the subsequence containing the whole array $$$a$$$, the average of all its elements is equal to $$$\\frac{7}{5}$$$. So $$$a_4$$$ and $$$a_5$$$ will be deleted.\nAfter this $$$a = [1, 1, 1]$$$.\nIn the second test case, Eshag can't delete any element.", "input": [ [ [ "6" ], [ "1", "1", "1", "2", "2", "3" ] ], [ [ "6" ], [ "9", "9", "9", "9", "9", "9" ] ], [ [ "6" ], [ "6", "4", "1", "1", "4", "1" ] ] ], "output": [ "3", "0", "3" ] }, { "problem_id": "1527A", "problem_name": "And Then There Were K\nbitmasks", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1527/A", "problem_solution_link": "https://codeforces.com/problemset/status/1527/problem/A", "problem_statement": "A. And Then There Were K\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven an integer $$$n$$$, find the maximum value of integer $$$k$$$ such that the following condition holds:\n$$$n$$$ & ($$$n-1$$$) & ($$$n-2$$$) & ($$$n-3$$$) & ... ($$$k$$$) = $$$0$$$\nwhere & denotes the\nbitwise AND operation.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 3 \\cdot 10^4$$$). Then $$$t$$$ test cases follow.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$).\nOutput\nFor each test case, output a single integer \u2014 the required integer $$$k$$$.\nExample\nInput\n3\n2\n5\n17\nOutput\n1\n3\n15\nNote\nIn the first testcase, the maximum value for which the continuous & operation gives 0 value, is 1.\nIn the second testcase, the maximum value for which the continuous & operation gives 0 value, is 3. No value greater then 3, say for example 4, will give the & sum 0.\n$$$5 \\, \\& \\, 4 \\neq 0$$$,\n$$$5 \\, \\& \\, 4 \\, \\& \\, 3 = 0$$$.\nHence, 3 is the answer.", "input": [ [ [ "2" ] ], [ [ "5" ] ], [ [ "17" ] ] ], "output": [ "1", "3", "15" ] }, { "problem_id": "1526A", "problem_name": "Mean Inequality\nconstructive algorithms, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1526/A", "problem_solution_link": "https://codeforces.com/problemset/status/1526/problem/A", "problem_statement": "A. Mean Inequality\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ of $$$2n$$$\ndistinct\nintegers. You want to arrange the elements of the array in a circle such that no element is equal to the the arithmetic mean of its $$$2$$$ neighbours.\nMore formally, find an array $$$b$$$, such that:\n$$$b$$$ is a permutation of $$$a$$$.\nFor every $$$i$$$ from $$$1$$$ to $$$2n$$$, $$$b_i \\neq \\frac{b_{i-1}+b_{i+1}}{2}$$$, where $$$b_0 = b_{2n}$$$ and $$$b_{2n+1} = b_1$$$.\nIt can be proved that under the constraints of this problem, such array $$$b$$$ always exists.\nInput\nThe first line of input contains a single integer $$$t$$$ $$$(1 \\leq t \\leq 1000)$$$ \u2014 the number of testcases. The description of testcases follows.\nThe first line of each testcase contains a single integer $$$n$$$ $$$(1 \\leq n \\leq 25)$$$.\nThe second line of each testcase contains $$$2n$$$ integers $$$a_1, a_2, \\ldots, a_{2n}$$$ $$$(1 \\leq a_i \\leq 10^9)$$$ \u2014 elements of the array.\nNote that there is no limit to the sum of $$$n$$$ over all testcases.\nOutput\nFor each testcase, you should output $$$2n$$$ integers, $$$b_1, b_2, \\ldots b_{2n}$$$, for which the conditions from the statement are satisfied.\nExample\nInput\n3\n3\n1 2 3 4 5 6\n2\n123 456 789 10\n1\n6 9\nOutput\n3 1 4 2 5 6\n123 10 456 789\n9 6\nNote\nIn the first testcase, array $$$[3, 1, 4, 2, 5, 6]$$$ works, as it's a permutation of $$$[1, 2, 3, 4, 5, 6]$$$, and $$$\\frac{3+4}{2}\\neq 1$$$, $$$\\frac{1+2}{2}\\neq 4$$$, $$$\\frac{4+5}{2}\\neq 2$$$, $$$\\frac{2+6}{2}\\neq 5$$$, $$$\\frac{5+3}{2}\\neq 6$$$, $$$\\frac{6+1}{2}\\neq 3$$$.", "input": [ [ [ "3" ], [ "1", "2", "3", "4", "5", "6" ] ], [ [ "2" ], [ "123", "456", "789", "10" ] ], [ [ "1" ], [ "6", "9" ] ] ], "output": [ "3 1 4 2 5 6", "123 10 456 789", "9 6" ] }, { "problem_id": "1525A", "problem_name": "Potion-making\nmath, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1525/A", "problem_solution_link": "https://codeforces.com/problemset/status/1525/problem/A", "problem_statement": "A. Potion-making\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly $$$k\\ \\%$$$ magic essence and $$$(100 - k)\\ \\%$$$ water.\nIn one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.\nA small reminder: if you pour $$$e$$$ liters of essence and $$$w$$$ liters of water ($$$e + w > 0$$$) into the cauldron, then it contains $$$\\frac{e}{e + w} \\cdot 100\\ \\%$$$ (without rounding) magic essence and $$$\\frac{w}{e + w} \\cdot 100\\ \\%$$$ water.\nInput\nThe first line contains the single $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases.\nThe first and only line of each test case contains a single integer $$$k$$$ ($$$1 \\le k \\le 100$$$)\u00a0\u2014 the percentage of essence in a good potion.\nOutput\nFor each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.\nExample\nInput\n3\n3\n100\n25\nOutput\n100\n1\n4\nNote\nIn the first test case, you should pour $$$3$$$ liters of magic essence and $$$97$$$ liters of water into the cauldron to get a potion with $$$3\\ \\%$$$ of magic essence.\nIn the second test case, you can pour only $$$1$$$ liter of essence to get a potion with $$$100\\ \\%$$$ of magic essence.\nIn the third test case, you can pour $$$1$$$ liter of magic essence and $$$3$$$ liters of water.", "input": [ [ [ "3" ] ], [ [ "100" ] ], [ [ "25" ] ] ], "output": [ "100", "1", "4" ] }, { "problem_id": "1523A", "problem_name": "Game of Life\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1523/A", "problem_solution_link": "https://codeforces.com/problemset/status/1523/problem/A", "problem_statement": "A. Game of Life\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nWilliam really likes the cellular automaton called \"Game of Life\" so he decided to make his own version. For simplicity, William decided to define his cellular automaton on an array containing $$$n$$$ cells, with each cell either being alive or dead.\nEvolution of the array in William's cellular automaton occurs iteratively in the following way:\nIf the element is dead and it has\nexactly\n$$$1$$$ alive neighbor\nin the current state of the array\n, then on the next iteration it will become alive. For an element at index $$$i$$$ the neighbors would be elements with indices $$$i - 1$$$ and $$$i + 1$$$. If there is no element at that index, it is considered to be a dead neighbor.\nWilliam is a humane person so all alive elements stay alive.\nCheck the note section for examples of the evolution.\nYou are given some initial state of all elements and you need to help William find the state of the array after $$$m$$$ iterations of evolution.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^3$$$). Description of the test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \\le n \\le 10^3, 1 \\le m \\le 10^9$$$), which are the total number of cells in the array and the number of iterations.\nThe second line of each test case contains a string of length $$$n$$$ made up of characters \"\n0\n\" and \"\n1\n\" and defines the initial state of the array. \"\n1\n\" means a cell is alive and \"\n0\n\" means it is dead.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$.\nOutput\nIn each test case output a string of length $$$n$$$, made up of characters \"\n0\n\" and \"\n1\n\" \u00a0\u2014 the state of the array after $$$m$$$ iterations of evolution.\nExample\nInput\n4\n11 3\n01000000001\n10 2\n0110100101\n5 2\n10101\n3 100\n000\nOutput\n11111001111\n1110111101\n10101\n000\nNote\nSequence of iterations of evolution for the first test case\n01000000001\n\u2014 initial state\n11100000011\n\u2014 first iteration of evolution\n11110000111\n\u2014 second iteration of evolution\n11111001111\n\u2014 third iteration of evolution\nSequence of iterations of evolution for the second test case\n0110100101\n\u2014 initial state\n1110111101\n\u2014 first iteration of evolution\n1110111101\n\u2014 second iteration of evolution", "input": [ [ [ "11", "3" ], [ "01000000001" ] ], [ [ "10", "2" ], [ "0110100101" ] ], [ [ "5", "2" ], [ "10101" ] ], [ [ "3", "100" ], [ "000" ] ] ], "output": [ "11111001111", "1110111101", "10101", "000" ] }, { "problem_id": "1520B", "problem_name": "Ordinary Numbers\nbrute force, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1520/B", "problem_solution_link": "https://codeforces.com/problemset/status/1520/problem/B", "problem_statement": "B. Ordinary Numbers\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's call a positive integer $$$n$$$ ordinary if in the decimal notation all its digits are the same. For example, $$$1$$$, $$$2$$$ and $$$99$$$ are ordinary numbers, but $$$719$$$ and $$$2021$$$ are not ordinary numbers.\nFor a given number $$$n$$$, find the number of ordinary numbers among the numbers from $$$1$$$ to $$$n$$$.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$). Then $$$t$$$ test cases follow.\nEach test case is characterized by one integer $$$n$$$ ($$$1 \\le n \\le 10^9$$$).\nOutput\nFor each test case output the number of ordinary numbers among numbers from $$$1$$$ to $$$n$$$.\nExample\nInput\n6\n1\n2\n3\n4\n5\n100\nOutput\n1\n2\n3\n4\n5\n18", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "3" ] ], [ [ "4" ] ], [ [ "5" ] ], [ [ "100" ] ] ], "output": [ "1", "2", "3", "4", "5", "18" ] }, { "problem_id": "1520A", "problem_name": "Do Not Be Distracted!\nbrute force, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1520/A", "problem_solution_link": "https://codeforces.com/problemset/status/1520/problem/A", "problem_statement": "A. Do Not Be Distracted!\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp has $$$26$$$ tasks. Each task is designated by a capital letter of the Latin alphabet.\nThe teacher asked Polycarp to solve tasks in the following way: if Polycarp began to solve some task, then he must solve it to the end, without being distracted by another task. After switching to another task, Polycarp cannot return to the previous task.\nPolycarp can only solve one task during the day. Every day he wrote down what task he solved. Now the teacher wants to know if Polycarp followed his advice.\nFor example, if Polycarp solved tasks in the following order: \"\nDDBBCCCBBEZ\n\", then the teacher will see that on the third day Polycarp began to solve the task '\nB\n', then on the fifth day he got distracted and began to solve the task '\nC\n', on the eighth day Polycarp returned to the task '\nB\n'. Other examples of when the teacher is suspicious: \"\nBAB\n\", \"\nAABBCCDDEEBZZ\n\" and \"\nAAAAZAAAAA\n\".\nIf Polycarp solved the tasks as follows: \"\nFFGZZZY\n\", then the teacher cannot have any suspicions. Please note that Polycarp is not obligated to solve all tasks. Other examples of when the teacher doesn't have any suspicious: \"\nBA\n\", \"\nAFFFCC\n\" and \"\nYYYYY\n\".\nHelp Polycarp find out if his teacher might be suspicious.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 1000$$$). Then $$$t$$$ test cases follow.\nThe first line of each test case contains one integer $$$n$$$ ($$$1 \\le n \\le 50$$$)\u00a0\u2014 the number of days during which Polycarp solved tasks.\nThe second line contains a string of length $$$n$$$, consisting of uppercase Latin letters, which is the order in which Polycarp solved the tasks.\nOutput\nFor each test case output:\n\"\nYES\n\", if the teacher\ncannot be suspicious\n;\n\"\nNO\n\", otherwise.\nYou may print every letter in any case you want (so, for example, the strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nare all recognized as positive answer).\nExample\nInput\n5\n3\nABA\n11\nDDBBCCCBBEZ\n7\nFFGZZZY\n1\nZ\n2\nAB\nOutput\nNO\nNO\nYES\nYES\nYES", "input": [ [ [ "3" ], [ "ABA" ] ], [ [ "11" ], [ "DDBBCCCBBEZ" ] ], [ [ "7" ], [ "FFGZZZY" ] ], [ [ "1" ], [ "Z" ] ], [ [ "2" ], [ "AB" ] ] ], "output": [ "NO", "NO", "YES", "YES", "YES" ] }, { "problem_id": "1519B", "problem_name": "The Cake Is a Lie\ndp, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1519/B", "problem_solution_link": "https://codeforces.com/problemset/status/1519/problem/B", "problem_statement": "B. The Cake Is a Lie\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a $$$n \\times m$$$ grid. You are standing at cell $$$(1, 1)$$$ and your goal is to finish at cell $$$(n, m)$$$.\nYou can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell $$$(x, y)$$$. You can:\nmove right to the cell $$$(x, y + 1)$$$\u00a0\u2014 it costs $$$x$$$ burles;\nmove down to the cell $$$(x + 1, y)$$$\u00a0\u2014 it costs $$$y$$$ burles.\nCan you reach cell $$$(n, m)$$$ spending\nexactly\n$$$k$$$ burles?\nInput\nThe first line contains the single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases.\nThe first and only line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \\le n, m \\le 100$$$; $$$0 \\le k \\le 10^4$$$)\u00a0\u2014 the sizes of grid and the exact amount of money you need to spend.\nOutput\nFor each test case, if you can reach cell $$$(n, m)$$$ spending\nexactly\n$$$k$$$ burles, print\nYES\n. Otherwise, print\nNO\n.\nYou may print every letter in any case you want (so, for example, the strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nare all recognized as positive answer).\nExample\nInput\n6\n1 1 0\n2 2 2\n2 2 3\n2 2 4\n1 4 3\n100 100 10000\nOutput\nYES\nNO\nYES\nNO\nYES\nNO\nNote\nIn the first test case, you are already in the final cell, so you spend $$$0$$$ burles.\nIn the second, third and fourth test cases, there are two paths from $$$(1, 1)$$$ to $$$(2, 2)$$$: $$$(1, 1)$$$ $$$\\rightarrow$$$ $$$(1, 2)$$$ $$$\\rightarrow$$$ $$$(2, 2)$$$ or $$$(1, 1)$$$ $$$\\rightarrow$$$ $$$(2, 1)$$$ $$$\\rightarrow$$$ $$$(2, 2)$$$. Both costs $$$1 + 2 = 3$$$ burles, so it's the only amount of money you can spend.\nIn the fifth test case, there is the only way from $$$(1, 1)$$$ to $$$(1, 4)$$$ and it costs $$$1 + 1 + 1 = 3$$$ burles.", "input": [ [ [ "1", "1", "0" ] ], [ [ "2", "2", "2" ] ], [ [ "2", "2", "3" ] ], [ [ "2", "2", "4" ] ], [ [ "1", "4", "3" ] ], [ [ "100", "100", "10000" ] ] ], "output": [ "YES", "NO", "YES", "NO", "YES", "NO" ] }, { "problem_id": "1519A", "problem_name": "Red and Blue Beans\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1519/A", "problem_solution_link": "https://codeforces.com/problemset/status/1519/problem/A", "problem_statement": "A. Red and Blue Beans\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have $$$r$$$ red and $$$b$$$ blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:\nhas at least one red bean (or the number of red beans $$$r_i \\ge 1$$$);\nhas at least one blue bean (or the number of blue beans $$$b_i \\ge 1$$$);\nthe number of red and blue beans should differ in no more than $$$d$$$ (or $$$|r_i - b_i| \\le d$$$)\nCan you distribute all beans?\nInput\nThe first line contains the single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases.\nThe first and only line of each test case contains three integers $$$r$$$, $$$b$$$, and $$$d$$$ ($$$1 \\le r, b \\le 10^9$$$; $$$0 \\le d \\le 10^9$$$)\u00a0\u2014 the number of red and blue beans and the maximum absolute difference in each packet.\nOutput\nFor each test case, if you can distribute all beans, print\nYES\n. Otherwise, print\nNO\n.\nYou may print every letter in any case you want (so, for example, the strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nare all recognized as positive answer).\nExample\nInput\n4\n1 1 0\n2 7 3\n6 1 4\n5 4 0\nOutput\nYES\nYES\nNO\nNO\nNote\nIn the first test case, you can form one packet with $$$1$$$ red and $$$1$$$ blue bean. The absolute difference $$$|1 - 1| = 0 \\le d$$$.\nIn the second test case, you can form two packets: $$$1$$$ red and $$$4$$$ blue beans in the first packet and $$$1$$$ red and $$$3$$$ blue beans in the second one.\nIn the third test case, since $$$b = 1$$$, you can form only one packet with $$$6$$$ red and $$$1$$$ blue beans. The absolute difference $$$|6 - 1| = 5 > d$$$.\nIn the fourth test case, since $$$d = 0$$$ so each packet should contain the same number of red and blue beans, but $$$r \\neq b$$$.", "input": [ [ [ "1", "1", "0" ] ], [ [ "2", "7", "3" ] ], [ [ "6", "1", "4" ] ], [ [ "5", "4", "0" ] ] ], "output": [ "YES", "YES", "NO", "NO" ] }, { "problem_id": "1517A", "problem_name": "Sum of 2050\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1517/A", "problem_solution_link": "https://codeforces.com/problemset/status/1517/problem/A", "problem_statement": "A. Sum of 2050\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA number is called\n2050-number\nif it is $$$2050$$$, $$$20500$$$, ..., ($$$2050 \\cdot 10^k$$$ for integer $$$k \\ge 0$$$).\nGiven a number $$$n$$$, you are asked to represent $$$n$$$ as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that.\nInput\nThe first line contains a single integer $$$T$$$ ($$$1\\le T\\leq 1\\,000$$$) denoting the number of test cases.\nThe only line of each test case contains a single integer $$$n$$$ ($$$1\\le n\\le 10^{18}$$$) denoting the number to be represented.\nOutput\nFor each test case, output the minimum number of 2050-numbers in one line.\nIf $$$n$$$ cannot be represented as the sum of 2050-numbers, output $$$-1$$$ instead.\nExample\nInput\n6\n205\n2050\n4100\n20500\n22550\n25308639900\nOutput\n-1\n1\n2\n1\n2\n36\nNote\nIn the third case, $$$4100 = 2050 + 2050$$$.\nIn the fifth case, $$$22550 = 20500 + 2050$$$.", "input": [ [ [ "205" ] ], [ [ "2050" ] ], [ [ "4100" ] ], [ [ "20500" ] ], [ [ "22550" ] ], [ [ "25308639900" ] ] ], "output": [ "-1", "1", "2", "1", "2", "36" ] }, { "problem_id": "1516A", "problem_name": "Tit for Tat\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1516/A", "problem_solution_link": "https://codeforces.com/problemset/status/1516/problem/A", "problem_statement": "A. Tit for Tat\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGiven an array $$$a$$$ of length $$$n$$$, you can do at most $$$k$$$ operations of the following type on it:\nchoose $$$2$$$ different elements in the array, add $$$1$$$ to the first, and subtract $$$1$$$ from the second. However, all the elements of $$$a$$$ have to remain non-negative after this operation.\nWhat is lexicographically the smallest array you can obtain?\nAn array $$$x$$$ is\nlexicographically smaller\nthan an array $$$y$$$ if there exists an index $$$i$$$ such that $$$x_i 1$$$.\nInput\nThe first line of input contains one integer $$$t$$$ $$$(1 \\le t \\le 10^4)$$$ \u2014 the number of test cases.\nThen $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(1 \\le n \\le 10^{18})$$$.\nAll test cases in one test are different.\nOutput\nOutput $$$t$$$ lines, where the $$$i$$$-th line is a single integer containing the answer to the $$$i$$$-th test case.\nExample\nInput\n3\n11\n31\n75\nOutput\n12\n33\n75\nNote\nLet us explain the three test cases in the sample.\nTest case 1:\n$$$n = 11$$$:\n$$$\\text{$$$gcdSum$$$}(11) = gcd(11, 1 + 1) = gcd(11,\\ 2) = 1$$$.\n$$$\\text{$$$gcdSum$$$}(12) = gcd(12, 1 + 2) = gcd(12,\\ 3) = 3$$$.\nSo the smallest number $$$\\ge 11$$$ whose $$$gcdSum$$$ $$$> 1$$$ is $$$12$$$.\nTest case 2:\n$$$n = 31$$$:\n$$$\\text{$$$gcdSum$$$}(31) = gcd(31, 3 + 1) = gcd(31,\\ 4) = 1$$$.\n$$$\\text{$$$gcdSum$$$}(32) = gcd(32, 3 + 2) = gcd(32,\\ 5) = 1$$$.\n$$$\\text{$$$gcdSum$$$}(33) = gcd(33, 3 + 3) = gcd(33,\\ 6) = 3$$$.\nSo the smallest number $$$\\ge 31$$$ whose $$$gcdSum$$$ $$$> 1$$$ is $$$33$$$.\nTest case 3:\n$$$\\ n = 75$$$:\n$$$\\text{$$$gcdSum$$$}(75) = gcd(75, 7 + 5) = gcd(75,\\ 12) = 3$$$.\nThe $$$\\text{$$$gcdSum$$$}$$$ of $$$75$$$ is already $$$> 1$$$. Hence, it is the answer.", "input": [ [ [ "11" ] ], [ [ "31" ] ], [ [ "75" ] ] ], "output": [ "12", "33", "75" ] }, { "problem_id": "1497A", "problem_name": "Meximization\nbrute force, data structures, greedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1497/A", "problem_solution_link": "https://codeforces.com/problemset/status/1497/problem/A", "problem_statement": "A. Meximization\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an integer $$$n$$$ and an array $$$a_1, a_2, \\ldots, a_n$$$. You should reorder the elements of the array $$$a$$$ in such way that the sum of $$$\\textbf{MEX}$$$ on prefixes ($$$i$$$-th prefix is $$$a_1, a_2, \\ldots, a_i$$$) is maximized.\nFormally, you should find an array $$$b_1, b_2, \\ldots, b_n$$$, such that the sets of elements of arrays $$$a$$$ and $$$b$$$ are equal (it is equivalent to array $$$b$$$ can be found as an array $$$a$$$ with some reordering of its elements) and $$$\\sum\\limits_{i=1}^{n} \\textbf{MEX}(b_1, b_2, \\ldots, b_i)$$$ is maximized.\n$$$\\textbf{MEX}$$$ of a set of nonnegative integers is the minimal nonnegative integer such that it is not in the set.\nFor example, $$$\\textbf{MEX}(\\{1, 2, 3\\}) = 0$$$, $$$\\textbf{MEX}(\\{0, 1, 2, 4, 5\\}) = 3$$$.\nInput\nThe first line contains a single integer $$$t$$$ $$$(1 \\le t \\le 100)$$$ \u00a0\u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ $$$(1 \\le n \\le 100)$$$.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ $$$(0 \\le a_i \\le 100)$$$.\nOutput\nFor each test case print an array $$$b_1, b_2, \\ldots, b_n$$$ \u00a0\u2014 the optimal reordering of $$$a_1, a_2, \\ldots, a_n$$$, so the sum of $$$\\textbf{MEX}$$$ on its prefixes is maximized.\nIf there exist multiple optimal answers you can find any.\nExample\nInput\n3\n7\n4 2 0 1 3 3 7\n5\n2 2 8 6 9\n1\n0\nOutput\n0 1 2 3 4 7 3 \n2 6 8 9 2 \n0\nNote\nIn the first test case in the answer $$$\\textbf{MEX}$$$ for prefixes will be:\n$$$\\textbf{MEX}(\\{0\\}) = 1$$$\n$$$\\textbf{MEX}(\\{0, 1\\}) = 2$$$\n$$$\\textbf{MEX}(\\{0, 1, 2\\}) = 3$$$\n$$$\\textbf{MEX}(\\{0, 1, 2, 3\\}) = 4$$$\n$$$\\textbf{MEX}(\\{0, 1, 2, 3, 4\\}) = 5$$$\n$$$\\textbf{MEX}(\\{0, 1, 2, 3, 4, 7\\}) = 5$$$\n$$$\\textbf{MEX}(\\{0, 1, 2, 3, 4, 7, 3\\}) = 5$$$\nThe sum of $$$\\textbf{MEX} = 1 + 2 + 3 + 4 + 5 + 5 + 5 = 25$$$. It can be proven, that it is a maximum possible sum of $$$\\textbf{MEX}$$$ on prefixes.", "input": [ [ [ "7" ], [ "4", "2", "0", "1", "3", "3", "7" ] ], [ [ "5" ], [ "2", "2", "8", "6", "9" ] ], [ [ "1" ], [ "0" ] ] ], "output": [ "0 1 2 3 4 7 3 ", "2 6 8 9 2 ", "0" ] }, { "problem_id": "1493A", "problem_name": "Anti-knapsack\nconstructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1493/A", "problem_solution_link": "https://codeforces.com/problemset/status/1493/problem/A", "problem_statement": "A. Anti-knapsack\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two integers $$$n$$$ and $$$k$$$. You are asked to choose maximum number of distinct integers from $$$1$$$ to $$$n$$$ so that there is no subset of chosen numbers with sum equal to $$$k$$$.\nA subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of it.\nInput\nThe first line contains the number of test cases $$$T$$$ ($$$1 \\le T \\le 100$$$).\nEach of the next $$$T$$$ lines contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 1000$$$) \u2014 the description of test cases.\nOutput\nFor each test case output two lines. In the first line output a single integer $$$m$$$ \u2014 the number of chosen integers.\nIn the second line output $$$m$$$ distinct integers from $$$1$$$ to $$$n$$$ \u2014 the chosen numbers.\nIf there are multiple answers, print any. You can print the numbers in any order.\nExample\nInput\n3\n3 2\n5 3\n1 1\nOutput\n2\n3 1 \n3\n4 5 2 \n0", "input": [ [ [ "3", "2" ] ], [ [ "5", "3" ] ], [ [ "1", "1" ] ] ], "output": [ ["2", "3 1"], ["3", "4 5 2"], ["0"] ], "error": true }, { "problem_id": "1492A", "problem_name": "Three swimmers\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1492/A", "problem_solution_link": "https://codeforces.com/problemset/status/1492/problem/A", "problem_statement": "A. Three swimmers\ntime limit per test\n1 second\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nThree swimmers decided to organize a party in the swimming pool! At noon, they started to swim from the left side of the pool.\nIt takes the first swimmer exactly $$$a$$$ minutes to swim across the entire pool and come back, exactly $$$b$$$ minutes for the second swimmer and $$$c$$$ minutes for the third. Hence, the first swimmer will be on the left side of the pool after $$$0$$$, $$$a$$$, $$$2a$$$, $$$3a$$$, ... minutes after the start time, the second one will be at $$$0$$$, $$$b$$$, $$$2b$$$, $$$3b$$$, ... minutes, and the third one will be on the left side of the pool after $$$0$$$, $$$c$$$, $$$2c$$$, $$$3c$$$, ... minutes.\nYou came to the left side of the pool exactly $$$p$$$ minutes after they started swimming. Determine how long you have to wait before one of the swimmers arrives at the left side of the pool.\nInput\nThe first line of the input contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases. Next $$$t$$$ lines contains test case descriptions, one per line.\nEach line contains four integers $$$p$$$, $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \\leq p, a, b, c \\leq 10^{18}$$$), time in minutes after the start, when you came to the pool and times in minutes it take the swimmers to cross the entire pool and come back.\nOutput\nFor each test case, output one integer\u00a0\u2014 how long you have to wait (in minutes) before one of the swimmers arrives at the left side of the pool.\nExample\nInput\n4\n9 5 4 8\n2 6 10 9\n10 2 5 10\n10 9 9 9\nOutput\n1\n4\n0\n8\nNote\nIn the first test case, the first swimmer is on the left side in $$$0, 5, 10, 15, \\ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 4, 8, 12, \\ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 8, 16, 24, \\ldots$$$ minutes after the start time. You arrived at the pool in $$$9$$$ minutes after the start time and in a minute you will meet the first swimmer on the left side.\nIn the second test case, the first swimmer is on the left side in $$$0, 6, 12, 18, \\ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 10, 20, 30, \\ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 9, 18, 27, \\ldots$$$ minutes after the start time. You arrived at the pool $$$2$$$ minutes after the start time and after $$$4$$$ minutes meet the first swimmer on the left side.\nIn the third test case, you came to the pool $$$10$$$ minutes after the start time. At the same time, all three swimmers are on the left side. A rare stroke of luck!\nIn the fourth test case, all swimmers are located on the left side in $$$0, 9, 18, 27, \\ldots$$$ minutes after the start time. You arrived at the pool $$$10$$$ minutes after the start time and after $$$8$$$ minutes meet all three swimmers on the left side.", "input": [ [ [ "9", "5", "4", "8" ] ], [ [ "2", "6", "10", "9" ] ], [ [ "10", "2", "5", "10" ] ], [ [ "10", "9", "9", "9" ] ] ], "output": [ "1", "4", "0", "8" ] }, { "problem_id": "1491A", "problem_name": "K-th Largest Value\nbrute force, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1491/A", "problem_solution_link": "https://codeforces.com/problemset/status/1491/problem/A", "problem_statement": "A. K-th Largest Value\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ consisting of $$$n$$$ integers.\nInitially all elements of $$$a$$$ are either $$$0$$$ or $$$1$$$\n. You need to process $$$q$$$ queries of two kinds:\n1 x\n: Assign to $$$a_x$$$ the value $$$1 - a_x$$$.\n2 k\n: Print the $$$k$$$-th largest value of the array.\nAs a reminder, $$$k$$$-th largest value of the array $$$b$$$ is defined as following:\nSort the array in the non-increasing order, return $$$k$$$-th element from it.\nFor example, the second largest element in array $$$[0, 1, 0, 1]$$$ is $$$1$$$, as after sorting in non-increasing order it becomes $$$[1, 1, 0, 0]$$$, and the second element in this array is equal to $$$1$$$.\nInput\nThe first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \\le n, q \\le 10^5$$$) \u2014 the length of the given array and the number of queries.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, a_3, \\dots, a_n$$$ ($$$0 \\le a_i \\le 1$$$) \u2014 elements of the initial array.\nEach of the following $$$q$$$ lines contains two integers. The first integer is $$$t$$$ ($$$1 \\le t \\le 2$$$) \u2014 the type of query.\nIf $$$t = 1$$$ the second integer is $$$x$$$ ($$$1 \\le x \\le n$$$) \u2014 the position of the modified number. You have to assign to $$$a_x$$$ the value $$$1 - a_x$$$.\nIf $$$t = 2$$$ the second integer is $$$k$$$ ($$$1 \\le k \\le n$$$) \u2014 you need to print the $$$k$$$-th largest value of the array.\nIt's guaranteed that there will be\nat least one\nquery of the second type (satisfying $$$t = 2$$$).\nOutput\nFor each query of the second type, print a single integer \u2014 the answer to the query.\nExample\nInput\n5 5\n1 1 0 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\nOutput\n1\n0\n1\n0\nNote\nInitially $$$a = [1, 1, 0, 1, 0]$$$.\nThe first operation is printing the third largest value, which is $$$1$$$.\nThe second operation is assigning $$$a_2$$$ the value $$$0$$$, $$$a$$$ becomes $$$[1, 0, 0, 1, 0]$$$.\nThe third operation is printing the third largest value, it is $$$0$$$.\nThe fourth operation is printing the first largest value, it is $$$1$$$.\nThe last operation is printing the fifth largest value, it is $$$0$$$.", "input": [ [ [ "5", "5" ], [ "1", "1", "0", "1", "0", "2", "3", "1", "2", "2", "3", "2", "1", "2", "5" ] ] ], "output": [ "1\n0\n1\n0" ] }, { "problem_id": "1490A", "problem_name": "Dense Array\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1490/A", "problem_solution_link": "https://codeforces.com/problemset/status/1490/problem/A", "problem_statement": "A. Dense Array\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any $$$i$$$ ($$$1 \\le i \\le n-1$$$), this condition must be satisfied: $$$$$$\\frac{\\max(a[i], a[i+1])}{\\min(a[i], a[i+1])} \\le 2$$$$$$\nFor example, the arrays $$$[1, 2, 3, 4, 3]$$$, $$$[1, 1, 1]$$$ and $$$[5, 10]$$$ are dense. And the arrays $$$[5, 11]$$$, $$$[1, 4, 2]$$$, $$$[6, 6, 1]$$$ are\nnot\ndense.\nYou are given an array $$$a$$$ of $$$n$$$ integers. What is the minimum number of numbers you need to add to an array to make it dense? You can insert numbers anywhere in the array. If the array is already dense, no numbers need to be added.\nFor example, if $$$a=[4,2,10,1]$$$, then the answer is $$$5$$$, and the array itself after inserting elements into it may look like this: $$$a=[4,2,\\underline{\\textbf{3}},\\underline{\\textbf{5}},10,\\underline{\\textbf{6}},\\underline{\\textbf{4}},\\underline{\\textbf{2}},1]$$$ (there are other ways to build such $$$a$$$).\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$). Then $$$t$$$ test cases follow.\nThe first line of each test case contains one integer $$$n$$$ ($$$2 \\le n \\le 50$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe next line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 50$$$).\nOutput\nFor each test case, output one integer\u00a0\u2014 the minimum number of numbers that must be added to the array to make it dense.\nExample\nInput\n6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n1 4 2\n5\n1 2 3 4 3\n12\n4 31 25 50 30 20 34 46 42 16 15 16\nOutput\n5\n1\n2\n1\n0\n3\nNote\nThe first test case is explained in the statements.\nIn the second test case, you can insert one element, $$$a=[1,\\underline{\\textbf{2}},3]$$$.\nIn the third test case, you can insert two elements, $$$a=[6,\\underline{\\textbf{4}},\\underline{\\textbf{2}},1]$$$.\nIn the fourth test case, you can insert one element, $$$a=[1,\\underline{\\textbf{2}},4,2]$$$.\nIn the fifth test case, the array $$$a$$$ is already dense.", "input": [ [ [ "4" ], [ "4", "2", "10", "1" ] ], [ [ "2" ], [ "1", "3" ] ], [ [ "2" ], [ "6", "1" ] ], [ [ "3" ], [ "1", "4", "2" ] ], [ [ "5" ], [ "1", "2", "3", "4", "3" ] ], [ [ "12" ], [ "4", "31", "25", "50", "30", "20", "34", "46", "42", "16", "15", "16" ] ] ], "output": [ "5", "1", "2", "1", "0", "3" ] }, { "problem_id": "1487A", "problem_name": "Arena\nimplementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1487/A", "problem_solution_link": "https://codeforces.com/problemset/status/1487/problem/A", "problem_statement": "A. Arena\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\n$$$n$$$ heroes fight against each other in the Arena. Initially, the $$$i$$$-th hero has level $$$a_i$$$.\nEach minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (\nit's even possible that it is the same two heroes that were fighting during the last minute\n).\nWhen two heroes of equal levels fight, nobody wins the fight. When two heroes of different levels fight, the one with the higher level wins, and his level increases by $$$1$$$.\nThe winner of the tournament is the first hero that wins in at least $$$100^{500}$$$ fights\n(note that it's possible that the tournament lasts forever if no hero wins this number of fights, then there is no winner)\n. A\npossible winner\nis a hero such that there exists a sequence of fights that this hero becomes the winner of the tournament.\nCalculate the number of\npossible winners\namong $$$n$$$ heroes.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 500$$$) \u2014 the number of test cases.\nEach test case consists of two lines. The first line contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the number of heroes. The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the initial level of the $$$i$$$-th hero.\nOutput\nFor each test case, print one integer \u2014 the number of\npossible winners\namong the given $$$n$$$ heroes.\nExample\nInput\n3\n3\n3 2 2\n2\n5 5\n4\n1 3 3 7\nOutput\n1\n0\n3\nNote\nIn the first test case of the example, the only\npossible winner\nis the first hero.\nIn the second test case of the example, each fight between the heroes results in nobody winning it, so the tournament lasts forever and there is no winner.", "input": [ [ [ "3" ], [ "3", "2", "2" ] ], [ [ "2" ], [ "5", "5" ] ], [ [ "4" ], [ "1", "3", "3", "7" ] ] ], "output": [ "1", "0", "3" ] }, { "problem_id": "1482A", "problem_name": "Prison Break\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1482/A", "problem_solution_link": "https://codeforces.com/problemset/status/1482/problem/A", "problem_statement": "A. Prison Break\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nMichael is accused of violating the social distancing rules and creating a risk of spreading coronavirus. He is now sent to prison. Luckily, Michael knows exactly what the prison looks like from the inside, especially since it's very simple.\nThe prison can be represented as a rectangle $$$a\\times b$$$ which is divided into $$$ab$$$ cells, each representing a prison cell, common sides being the walls between cells, and sides on the perimeter being the walls leading to freedom. Before sentencing, Michael can ask his friends among the prison employees to make (very well hidden) holes in some of the walls (including walls between cells and the outermost walls). Michael wants to be able to get out of the prison after this, no matter which cell he is placed in. However, he also wants to break as few walls as possible.\nYour task is to find out the smallest number of walls to be broken so that there is a path to the outside from every cell after this.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1\\leq t\\leq 100$$$)\u00a0\u2014 the number of test cases.\nEach of the following $$$t$$$ lines contains two integers $$$a$$$ and $$$b$$$ ($$$1\\leq a, b\\leq 100$$$), representing a corresponding test case.\nOutput\nFor each test case print the single integer on a separate line\u00a0\u2014 the answer to the problem.\nExample\nInput\n2\n2 2\n1 3\nOutput\n4\n3\nNote\nSome possible escape plans for the example test cases are shown below. Broken walls are shown in gray, not broken walls are shown in black.", "input": [ [ [ "2", "2" ] ], [ [ "1", "3" ] ] ], "output": [ "4", "3" ] }, { "problem_id": "1481A", "problem_name": "Space Navigation\ngreedy, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1481/A", "problem_solution_link": "https://codeforces.com/problemset/status/1481/problem/A", "problem_statement": "A. Space Navigation\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces.\nSpace can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.\nThe piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$:\nif $$$s_i = \\text{U}$$$, you move to $$$(x, y + 1)$$$;\nif $$$s_i = \\text{D}$$$, you move to $$$(x, y - 1)$$$;\nif $$$s_i = \\text{R}$$$, you move to $$$(x + 1, y)$$$;\nif $$$s_i = \\text{L}$$$, you move to $$$(x - 1, y)$$$.\nSince string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately,\nyou can delete some orders from $$$s$$$ but you can't change their positions\n.\nCan you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases.\nEach test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \\le p_x, p_y \\le 10^5$$$; $$$(p_x, p_y) \\neq (0, 0)$$$)\u00a0\u2014 the coordinates of Planetforces $$$(p_x, p_y)$$$.\nThe second line contains the string $$$s$$$ ($$$1 \\le |s| \\le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$)\u00a0\u2014 the list of orders.\nIt is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each test case, print \"\nYES\n\" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print \"\nNO\n\". You can print each letter in any case (upper or lower).\nExample\nInput\n6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR\nOutput\nYES\nYES\nYES\nNO\nYES\nNO\nNote\nIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.\nIn the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to \"\nUR\n\".\nIn the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces.", "input": [ [ [ "10", "5" ], [ "RRRRRRRRRRUUUUU" ] ], [ [ "1", "1" ], [ "UDDDRLLL" ] ], [ [ "-3", "-5" ], [ "LDLDLDDDR" ] ], [ [ "1", "2" ], [ "LLLLUU" ] ], [ [ "3", "-2" ], [ "RDULRLLDR" ] ], [ [ "-1", "6" ], [ "RUDURUUUUR" ] ] ], "output": [ "YES", "YES", "YES", "NO", "YES", "NO" ] }, { "problem_id": "1480A", "problem_name": "Yet Another String Game\ngames, greedy, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1480/A", "problem_solution_link": "https://codeforces.com/problemset/status/1480/problem/A", "problem_statement": "A. Yet Another String Game\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nHomer has two friends Alice and Bob. Both of them are string fans.\nOne day, Alice and Bob decide to play a game on a string $$$s = s_1 s_2 \\dots s_n$$$ of length $$$n$$$ consisting of lowercase English letters. They move in turns alternatively and\nAlice makes the first move\n.\nIn a move, a player\nmust\nchoose an index $$$i$$$ ($$$1 \\leq i \\leq n$$$) that has not been chosen before, and change $$$s_i$$$ to any other lowercase English letter $$$c$$$ that $$$c \\neq s_i$$$.\nWhen all indices have been chosen, the game ends.\nThe goal of Alice is to make the final string lexicographically as small as possible, while the goal of Bob is to make the final string lexicographically as large as possible. Both of them are game experts, so they always play games optimally. Homer is not a game expert, so he wonders what the final string will be.\nA string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:\n$$$a$$$ is a prefix of $$$b$$$, but $$$a \\ne b$$$;\nin the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.\nInput\nEach test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u00a0\u2014 the number of test cases. Description of the test cases follows.\nThe only line of each test case contains a single string $$$s$$$ ($$$1 \\leq |s| \\leq 50$$$) consisting of lowercase English letters.\nOutput\nFor each test case, print the final string in a single line.\nExample\nInput\n3\na\nbbbb\naz\nOutput\nb\nazaz\nby\nNote\nIn the first test case: Alice makes the first move and must change the only letter to a different one, so she changes it to '\nb\n'.\nIn the second test case: Alice changes the first letter to '\na\n', then Bob changes the second letter to '\nz\n', Alice changes the third letter to '\na\n' and then Bob changes the fourth letter to '\nz\n'.\nIn the third test case: Alice changes the first letter to '\nb\n', and then Bob changes the second letter to '\ny\n'.", "input": [ [ [ "a" ] ], [ [ "bbbb" ] ], [ [ "az" ] ] ], "output": [ "b", "azaz", "by" ] }, { "problem_id": "1478A", "problem_name": "Nezzar and Colorful Balls\nbrute force, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1478/A", "problem_solution_link": "https://codeforces.com/problemset/status/1478/problem/A", "problem_statement": "A. Nezzar and Colorful Balls\ntime limit per test\n1 second\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nNezzar has $$$n$$$ balls, numbered with integers $$$1, 2, \\ldots, n$$$. Numbers $$$a_1, a_2, \\ldots, a_n$$$ are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that $$$a_i \\leq a_{i+1}$$$ for all $$$1 \\leq i < n$$$.\nNezzar wants to color the balls using the minimum number of colors, such that the following holds.\nFor any color, numbers on balls will form a\nstrictly increasing sequence\nif he keeps balls with this chosen color and discards all other balls.\nNote that a sequence with the length at most $$$1$$$ is considered as a strictly increasing sequence.\nPlease help Nezzar determine the minimum number of colors.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of testcases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$).\nThe second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\\ldots,a_n$$$ ($$$1 \\le a_i \\le n$$$). It is guaranteed that $$$a_1 \\leq a_2 \\leq \\ldots \\leq a_n$$$.\nOutput\nFor each test case, output the minimum number of colors Nezzar can use.\nExample\nInput\n5\n6\n1 1 1 2 3 4\n5\n1 1 2 2 3\n4\n2 2 2 2\n3\n1 2 3\n1\n1\nOutput\n3\n2\n4\n1\n1\nNote\nLet's match each color with some numbers. Then:\nIn the first test case, one optimal color assignment is $$$[1,2,3,3,2,1]$$$.\nIn the second test case, one optimal color assignment is $$$[1,2,1,2,1]$$$.", "input": [ [ [ "6" ], [ "1", "1", "1", "2", "3", "4" ] ], [ [ "5" ], [ "1", "1", "2", "2", "3" ] ], [ [ "4" ], [ "2", "2", "2", "2" ] ], [ [ "3" ], [ "1", "2", "3" ] ], [ [ "1" ], [ "1" ] ] ], "output": [ "3", "2", "4", "1", "1" ] }, { "problem_id": "1474A", "problem_name": "Puzzle From the Future\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1474/A", "problem_solution_link": "https://codeforces.com/problemset/status/1474/problem/A", "problem_statement": "A. Puzzle From the Future\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIn the\n$$$2022$$$\nyear, Mike found two binary integers $$$a$$$ and $$$b$$$ of length $$$n$$$ (both of them are written only by digits $$$0$$$ and $$$1$$$) that can have leading zeroes. In order not to forget them, he wanted to construct integer $$$d$$$ in the following way:\nhe creates an integer $$$c$$$ as a result of bitwise summing of $$$a$$$ and $$$b$$$\nwithout transferring carry\n, so $$$c$$$ may have one or more $$$2$$$-s. For example, the result of bitwise summing of $$$0110$$$ and $$$1101$$$ is $$$1211$$$ or the sum of $$$011000$$$ and $$$011000$$$ is $$$022000$$$;\nafter that Mike replaces equal consecutive digits in $$$c$$$ by one digit, thus getting $$$d$$$. In the cases above after this operation, $$$1211$$$ becomes $$$121$$$ and $$$022000$$$ becomes $$$020$$$ (so, $$$d$$$ won't have equal consecutive digits).\nUnfortunately, Mike lost integer $$$a$$$ before he could calculate $$$d$$$ himself. Now, to cheer him up, you want to find\nany binary\ninteger $$$a$$$ of length $$$n$$$ such that $$$d$$$ will be\nmaximum possible as integer\n.\nMaximum possible as integer means that $$$102 > 21$$$, $$$012 < 101$$$, $$$021 = 21$$$ and so on.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains the integer $$$n$$$ ($$$1 \\leq n \\leq 10^5$$$)\u00a0\u2014 the length of $$$a$$$ and $$$b$$$.\nThe second line of each test case contains binary integer $$$b$$$ of length $$$n$$$. The integer $$$b$$$ consists only of digits $$$0$$$ and $$$1$$$.\nIt is guaranteed that the total sum of $$$n$$$ over all $$$t$$$ test cases doesn't exceed $$$10^5$$$.\nOutput\nFor each test case output one\nbinary\ninteger $$$a$$$ of length $$$n$$$. Note, that $$$a$$$ or $$$b$$$ may have leading zeroes but must have the same length $$$n$$$.\nExample\nInput\n5\n1\n0\n3\n011\n3\n110\n6\n111000\n6\n001011\nOutput\n1\n110\n100\n101101\n101110\nNote\nIn the first test case, $$$b = 0$$$ and choosing $$$a = 1$$$ gives $$$d = 1$$$ as a result.\nIn the second test case, $$$b = 011$$$ so:\nif you choose $$$a = 000$$$, $$$c$$$ will be equal to $$$011$$$, so $$$d = 01$$$;\nif you choose $$$a = 111$$$, $$$c$$$ will be equal to $$$122$$$, so $$$d = 12$$$;\nif you choose $$$a = 010$$$, you'll get $$$d = 021$$$.\nIf you select $$$a = 110$$$, you'll get $$$d = 121$$$.\nWe can show that answer $$$a = 110$$$ is optimal and $$$d = 121$$$ is maximum possible.\nIn the third test case, $$$b = 110$$$. If you choose $$$a = 100$$$, you'll get $$$d = 210$$$ and it's the maximum possible $$$d$$$.\nIn the fourth test case, $$$b = 111000$$$. If you choose $$$a = 101101$$$, you'll get $$$d = 212101$$$ and it's maximum possible $$$d$$$.\nIn the fifth test case, $$$b = 001011$$$. If you choose $$$a = 101110$$$, you'll get $$$d = 102121$$$ and it's maximum possible $$$d$$$.", "input": [ [ [ "1" ], [ "0" ] ], [ [ "3" ], [ "011" ] ], [ [ "3" ], [ "110" ] ], [ [ "6" ], [ "111000" ] ], [ [ "6" ], [ "001011" ] ] ], "output": [ "1", "110", "100", "101101", "101110" ] }, { "problem_id": "1473A", "problem_name": "Replacing Elements\ngreedy, implementation, math, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1473/A", "problem_solution_link": "https://codeforces.com/problemset/status/1473/problem/A", "problem_statement": "A. Replacing Elements\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have an array $$$a_1, a_2, \\dots, a_n$$$. All $$$a_i$$$ are positive integers.\nIn one step you can choose three distinct indices $$$i$$$, $$$j$$$, and $$$k$$$ ($$$i \\neq j$$$; $$$i \\neq k$$$; $$$j \\neq k$$$) and assign the sum of $$$a_j$$$ and $$$a_k$$$ to $$$a_i$$$, i.\u00a0e. make $$$a_i = a_j + a_k$$$.\nCan you make all $$$a_i$$$ lower or equal to $$$d$$$ using the operation above any number of times (possibly, zero)?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 2000$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains two integers $$$n$$$ and $$$d$$$ ($$$3 \\le n \\le 100$$$; $$$1 \\le d \\le 100$$$)\u00a0\u2014 the number of elements in the array $$$a$$$ and the value $$$d$$$.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$)\u00a0\u2014 the array $$$a$$$.\nOutput\nFor each test case, print\nYES\n, if it's possible to make all elements $$$a_i$$$ less or equal than $$$d$$$ using the operation above. Otherwise, print\nNO\n.\nYou may print each letter in any case (for example,\nYES\n,\nYes\n,\nyes\n,\nyEs\nwill all be recognized as positive answer).\nExample\nInput\n3\n5 3\n2 3 2 5 4\n3 4\n2 4 4\n5 4\n2 1 5 3 6\nOutput\nNO\nYES\nYES\nNote\nIn the first test case, we can prove that we can't make all $$$a_i \\le 3$$$.\nIn the second test case, all $$$a_i$$$ are already less or equal than $$$d = 4$$$.\nIn the third test case, we can, for example, choose $$$i = 5$$$, $$$j = 1$$$, $$$k = 2$$$ and make $$$a_5 = a_1 + a_2 = 2 + 1 = 3$$$. Array $$$a$$$ will become $$$[2, 1, 5, 3, 3]$$$.\nAfter that we can make $$$a_3 = a_5 + a_2 = 3 + 1 = 4$$$. Array will become $$$[2, 1, 4, 3, 3]$$$ and all elements are less or equal than $$$d = 4$$$.", "input": [ [ [ "5", "3" ], [ "2", "3", "2", "5", "4" ] ], [ [ "3", "4" ], [ "2", "4", "4" ] ], [ [ "5", "4" ], [ "2", "1", "5", "3", "6" ] ] ], "output": [ "NO", "YES", "YES" ] }, { "problem_id": "1472B", "problem_name": "Fair Division\ndp, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1472/B", "problem_solution_link": "https://codeforces.com/problemset/status/1472/problem/B", "problem_statement": "B. Fair Division\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAlice and Bob received $$$n$$$ candies from their parents.\nEach candy weighs either 1 gram or 2 grams\n. Now they want to divide all candies among themselves fairly so that the total weight of Alice's candies is equal to the total weight of Bob's candies.\nCheck if they can do that.\nNote that candies\nare not allowed to be cut in half\n.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the number of candies that Alice and Bob received.\nThe next line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$\u00a0\u2014 the weights of the candies. The weight of each candy is either $$$1$$$ or $$$2$$$.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each test case, output on a separate line:\n\"\nYES\n\", if all candies can be divided into two sets with the same weight;\n\"\nNO\n\" otherwise.\nYou can output \"\nYES\n\" and \"\nNO\n\" in any case (for example, the strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as positive).\nExample\nInput\n5\n2\n1 1\n2\n1 2\n4\n1 2 1 2\n3\n2 2 2\n3\n2 1 2\nOutput\nYES\nNO\nYES\nNO\nNO\nNote\nIn the first test case, Alice and Bob can each take one candy, then both will have a total weight of $$$1$$$.\nIn the second test case, any division will be unfair.\nIn the third test case, both Alice and Bob can take two candies, one of weight $$$1$$$ and one of weight $$$2$$$.\nIn the fourth test case, it is impossible to divide three identical candies between two people.\nIn the fifth test case, any division will also be unfair.", "input": [ [ [ "2" ], [ "1", "1" ] ], [ [ "2" ], [ "1", "2" ] ], [ [ "4" ], [ "1", "2", "1", "2" ] ], [ [ "3" ], [ "2", "2", "2" ] ], [ [ "3" ], [ "2", "1", "2" ] ] ], "output": [ "YES", "NO", "YES", "NO", "NO" ] }, { "problem_id": "1472A", "problem_name": "Cards for Friends\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1472/A", "problem_solution_link": "https://codeforces.com/problemset/status/1472/problem/A", "problem_statement": "A. Cards for Friends\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nFor the New Year, Polycarp decided to send postcards to all his $$$n$$$ friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size $$$w \\times h$$$, which can be cut into pieces.\nPolycarp can cut any sheet of paper $$$w \\times h$$$ that he has in only two cases:\nIf $$$w$$$ is even, then he can cut the sheet in half and get two sheets of size $$$\\frac{w}{2} \\times h$$$;\nIf $$$h$$$ is even, then he can cut the sheet in half and get two sheets of size $$$w \\times \\frac{h}{2}$$$;\nIf $$$w$$$ and $$$h$$$ are even at the same time, then Polycarp can cut the sheet according to any of the rules above.\nAfter cutting a sheet of paper, the total number of sheets of paper is increased by $$$1$$$.\nHelp Polycarp to find out if he can cut his sheet of size $$$w \\times h$$$ at into $$$n$$$ or more pieces, using only the rules described above.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases. Then $$$t$$$ test cases follow.\nEach test case consists of one line containing three integers $$$w$$$, $$$h$$$, $$$n$$$ ($$$1 \\le w, h \\le 10^4, 1 \\le n \\le 10^9$$$)\u00a0\u2014 the width and height of the sheet Polycarp has and the number of friends he needs to send a postcard to.\nOutput\nFor each test case, output on a separate line:\n\"\nYES\n\", if it is possible to cut a sheet of size $$$w \\times h$$$ into at least $$$n$$$ pieces;\n\"\nNO\n\" otherwise.\nYou can output \"\nYES\n\" and \"\nNO\n\" in any case (for example, the strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill be recognized as positive).\nExample\nInput\n5\n2 2 3\n3 3 2\n5 10 2\n11 13 1\n1 4 4\nOutput\nYES\nNO\nYES\nYES\nYES\nNote\nIn the first test case, you can first cut the $$$2 \\times 2$$$ sheet into two $$$2 \\times 1$$$ sheets, and then cut each of them into two more sheets. As a result, we get four sheets $$$1 \\times 1$$$. We can choose any three of them and send them to our friends.\nIn the second test case, a $$$3 \\times 3$$$ sheet cannot be cut, so it is impossible to get two sheets.\nIn the third test case, you can cut a $$$5 \\times 10$$$ sheet into two $$$5 \\times 5$$$ sheets.\nIn the fourth test case, there is no need to cut the sheet, since we only need one sheet.\nIn the fifth test case, you can first cut the $$$1 \\times 4$$$ sheet into two $$$1 \\times 2$$$ sheets, and then cut each of them into two more sheets. As a result, we get four sheets $$$1 \\times 1$$$.", "input": [ [ [ "2", "2", "3" ] ], [ [ "3", "3", "2" ] ], [ [ "5", "10", "2" ] ], [ [ "11", "13", "1" ] ], [ [ "1", "4", "4" ] ] ], "output": [ "YES", "NO", "YES", "YES", "YES" ] }, { "problem_id": "1468E", "problem_name": "Four Segments\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1468/E", "problem_solution_link": "https://codeforces.com/problemset/status/1468/problem/E", "problem_statement": "E. Four Segments\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nMonocarp wants to draw four line segments on a sheet of paper. He wants the $$$i$$$-th segment to have its length equal to $$$a_i$$$ ($$$1 \\le i \\le 4$$$). These segments can intersect with each other, and each segment should be either horizontal or vertical.\nMonocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.\nFor example, if Monocarp wants to draw four segments with lengths $$$1$$$, $$$2$$$, $$$3$$$ and $$$4$$$, he can do it the following way:\nHere, Monocarp has drawn segments $$$AB$$$ (with length $$$1$$$), $$$CD$$$ (with length $$$2$$$), $$$BC$$$ (with length $$$3$$$) and $$$EF$$$ (with length $$$4$$$). He got a rectangle $$$ABCF$$$ with area equal to $$$3$$$ that is enclosed by the segments.\nCalculate the maximum area of a rectangle Monocarp can enclose with four segments.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 3 \\cdot 10^4$$$) \u2014 the number of test cases.\nEach test case consists of a single line containing four integers $$$a_1$$$, $$$a_2$$$, $$$a_3$$$, $$$a_4$$$ ($$$1 \\le a_i \\le 10^4$$$) \u2014 the lengths of the segments Monocarp wants to draw.\nOutput\nFor each test case, print one integer \u2014 the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).\nExample\nInput\n4\n1 2 3 4\n5 5 5 5\n3 1 4 1\n100 20 20 100\nOutput\n3\n25\n3\n2000\nNote\nThe first test case of the example is described in the statement.\nFor the second test case, Monocarp can draw the segments $$$AB$$$, $$$BC$$$, $$$CD$$$ and $$$DA$$$ as follows:\nHere, Monocarp has drawn segments $$$AB$$$ (with length $$$5$$$), $$$BC$$$ (with length $$$5$$$), $$$CD$$$ (with length $$$5$$$) and $$$DA$$$ (with length $$$5$$$). He got a rectangle $$$ABCD$$$ with area equal to $$$25$$$ that is enclosed by the segments.", "input": [ [ [ "1", "2", "3", "4" ] ], [ [ "5", "5", "5", "5" ] ], [ [ "3", "1", "4", "1" ] ], [ [ "100", "20", "20", "100" ] ] ], "output": [ "3", "25", "3", "2000" ] }, { "problem_id": "1466B", "problem_name": "Last minute enhancements\ndp, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1466/B", "problem_solution_link": "https://codeforces.com/problemset/status/1466/problem/B", "problem_statement": "B. Last minute enhancements\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAthenaeus has just finished creating his latest musical composition and will present it tomorrow to the people of Athens. Unfortunately, the melody is rather dull and highly likely won't be met with a warm reception.\nHis song consists of $$$n$$$ notes, which we will treat as\npositive integers\n. The\ndiversity\nof a song is the number of\ndifferent\nnotes it contains. As a patron of music, Euterpe watches over composers and guides them throughout the process of creating new melodies. She decided to help Athenaeus by changing his song to make it more diverse.\nBeing a minor goddess, she cannot arbitrarily change the song. Instead, for each of the $$$n$$$ notes in the song, she can either leave it as it is or\nincrease\nit by $$$1$$$.\nGiven the song as a sequence of integers describing the notes, find out the maximal, achievable diversity.\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 10\\,000$$$)\u00a0\u2014 the number of test cases. Then $$$t$$$ test cases follow, each one is described in two lines.\nIn the first line of each test case there is a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^5$$$) denoting the length of the song. The next line contains a sequence of $$$n$$$ integers $$$x_1, x_2, \\ldots, x_n$$$ $$$(1 \\leq x_1 \\leq x_2 \\leq \\ldots \\leq x_n \\leq 2 \\cdot n)$$$, describing the song.\nThe sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.\nOutput\nFor each test case, you should output a single line containing precisely one integer, the maximal diversity of the song, i.e. the maximal possible number of different elements in the final sequence.\nExample\nInput\n5\n6\n1 2 2 2 5 6\n2\n4 4\n6\n1 1 3 4 4 5\n1\n1\n6\n1 1 1 2 2 2\nOutput\n5\n2\n6\n1\n3\nNote\nIn the first test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence $$$1, \\underline{3}, 2, 2, \\underline{6}, \\underline{7}$$$, which has $$$5$$$ different elements (increased elements are underlined).\nIn the second test case, Euterpe can increase the first element to obtain the sequence $$$\\underline{5}, 4$$$, which has $$$2$$$ different elements.\nIn the third test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence $$$1, \\underline{2}, 3, 4, \\underline{5}, \\underline{6}$$$, which has $$$6$$$ different elements.", "input": [ [ [ "6" ], [ "1", "2", "2", "2", "5", "6" ] ], [ [ "2" ], [ "4", "4" ] ], [ [ "6" ], [ "1", "1", "3", "4", "4", "5" ] ], [ [ "1" ], [ "1" ] ], [ [ "6" ], [ "1", "1", "1", "2", "2", "2" ] ] ], "output": [ "5", "2", "6", "1", "3" ] }, { "problem_id": "1466A", "problem_name": "Bovine Dilemma\nbrute force, geometry, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1466/A", "problem_solution_link": "https://codeforces.com/problemset/status/1466/problem/A", "problem_statement": "A. Bovine Dilemma\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nArgus was charged with guarding Io, which is not an ordinary cow. Io is quite an explorer, and she wanders off rather frequently, making Argus' life stressful. So the cowherd decided to construct an enclosed pasture for Io.\nThere are $$$n$$$ trees growing along the river, where Argus tends Io. For this problem, the river can be viewed as the $$$OX$$$ axis of the Cartesian coordinate system, and the $$$n$$$ trees as points with the $$$y$$$-coordinate equal $$$0$$$. There is also another tree growing in the point $$$(0, 1)$$$.\nArgus will tie a rope around three of the trees, creating a triangular pasture. Its exact shape doesn't matter to Io, but its area is crucial to her. There may be many ways for Argus to arrange the fence, but only the ones which result in different areas of the pasture are interesting for Io. Calculate the number of\ndifferent\nareas that her pasture may have. Note that the pasture must have\nnonzero\narea.\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. Then $$$t$$$ test cases follow, each one is described in two lines.\nIn the first line of each test case there is a single integer $$$n$$$ ($$$1 \\leq n \\leq 50$$$) denoting the number of trees growing along the river. Next line contains $$$n$$$ distinct integers $$$x_1 < x_2 < \\ldots < x_{n - 1} < x_n$$$ ($$$1 \\leq x_i \\leq 50$$$), the $$$x$$$-coordinates of trees growing along the river.\nOutput\nIn a single line output an integer, the number of\ndifferent\nnonzero\nareas that triangles with trees as vertices may have.\nExample\nInput\n8\n4\n1 2 4 5\n3\n1 3 5\n3\n2 6 8\n2\n1 2\n1\n50\n5\n3 4 5 6 8\n3\n1 25 26\n6\n1 2 4 8 16 32\nOutput\n4\n2\n3\n1\n0\n5\n3\n15\nNote\nIn the first test case, we have $$$6$$$ non-degenerate triangles with the following areas: $$$0.5$$$, $$$0.5$$$, $$$1$$$, $$$1.5$$$, $$$1.5$$$ and $$$2$$$. The pasture can have $$$4$$$ different areas, and thus $$$4$$$ is the answer.\nIn the second test case, we have $$$3$$$ non-degenerate triangles with the following areas: $$$1$$$, $$$1$$$ and $$$2$$$. The pasture can have $$$2$$$ different areas, so $$$2$$$ is the answer.\nThe following two drawings present the situation in the second test case. The blue triangles in the first drawing have area $$$1$$$. The red triangle in the second drawing has area $$$2$$$.", "input": [ [ [ "4" ], [ "1", "2", "4", "5" ] ], [ [ "3" ], [ "1", "3", "5" ] ], [ [ "3" ], [ "2", "6", "8" ] ], [ [ "2" ], [ "1", "2" ] ], [ [ "1" ], [ "50" ] ], [ [ "5" ], [ "3", "4", "5", "6", "8" ] ], [ [ "3" ], [ "1", "25", "26" ] ], [ [ "6" ], [ "1", "2", "4", "8", "16", "32" ] ] ], "output": [ "4", "2", "3", "1", "0", "5", "3", "15" ] }, { "problem_id": "1462B", "problem_name": "Last Year's Substring\ndp, implementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1462/B", "problem_solution_link": "https://codeforces.com/problemset/status/1462/problem/B", "problem_statement": "B. Last Year's Substring\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp has a string $$$s[1 \\dots n]$$$ of length $$$n$$$ consisting of decimal digits. Polycarp performs the following operation with the string $$$s$$$\nno more than once\n(i.e. he can perform operation $$$0$$$ or $$$1$$$ time):\nPolycarp selects two numbers $$$i$$$ and $$$j$$$ ($$$1 \\leq i \\leq j \\leq n$$$) and removes characters from the $$$s$$$ string at the positions $$$i, i+1, i+2, \\ldots, j$$$ (i.e. removes substring $$$s[i \\dots j]$$$). More formally, Polycarp turns the string $$$s$$$ into the string $$$s_1 s_2 \\ldots s_{i-1} s_{j+1} s_{j+2} \\ldots s_{n}$$$.\nFor example, the string $$$s = $$$\"\n20192020\n\" Polycarp can turn into strings:\n\"\n2020\n\" (in this case $$$(i, j)=(3, 6)$$$ or $$$(i, j)=(1, 4)$$$);\n\"\n2019220\n\" (in this case $$$(i, j)=(6, 6)$$$);\n\"\n020\n\" (in this case $$$(i, j)=(1, 5)$$$);\nother operations are also possible, only a few of them are listed above.\nPolycarp likes the string \"\n2020\n\" very much, so he is wondering if it is possible to turn the string $$$s$$$ into a string \"\n2020\n\" in no more than one operation? Note that you can perform zero operations.\nInput\nThe first line contains a positive integer $$$t$$$ ($$$1 \\leq t \\leq 1000 $$$)\u00a0\u2014 number of test cases in the test. Then $$$t$$$ test cases follow.\nThe first line of each test case contains an integer $$$n$$$ ($$$4 \\leq n \\leq 200$$$)\u00a0\u2014 length of the string $$$s$$$. The next line contains a string $$$s$$$ of length $$$n$$$ consisting of decimal digits. It is allowed that the string $$$s$$$ starts with digit\n0\n.\nOutput\nFor each test case, output on a separate line:\n\"\nYES\n\" if Polycarp can turn the string $$$s$$$ into a string \"\n2020\n\" in no more than one operation (i.e. he can perform $$$0$$$ or $$$1$$$ operation);\n\"\nNO\n\" otherwise.\nYou may print every letter of \"\nYES\n\" and \"\nNO\n\" in any case you want (so, for example, the strings\nyEs\n,\nyes\n,\nYes\nand\nYES\nwill all be recognized as positive answer).\nExample\nInput\n6\n8\n20192020\n8\n22019020\n4\n2020\n5\n20002\n6\n729040\n6\n200200\nOutput\nYES\nYES\nYES\nNO\nNO\nNO\nNote\nIn the first test case, Polycarp could choose $$$i=3$$$ and $$$j=6$$$.\nIn the second test case, Polycarp could choose $$$i=2$$$ and $$$j=5$$$.\nIn the third test case, Polycarp did not perform any operations with the string.", "input": [ [ [ "8" ], [ "20192020" ] ], [ [ "8" ], [ "22019020" ] ], [ [ "4" ], [ "2020" ] ], [ [ "5" ], [ "20002" ] ], [ [ "6" ], [ "729040" ] ], [ [ "6" ], [ "200200" ] ] ], "output": [ "YES", "YES", "YES", "NO", "NO", "NO" ] }, { "problem_id": "1462A", "problem_name": "Favorite Sequence\nimplementation, two pointers", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1462/A", "problem_solution_link": "https://codeforces.com/problemset/status/1462/problem/A", "problem_statement": "A. Favorite Sequence\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp has a favorite sequence $$$a[1 \\dots n]$$$ consisting of $$$n$$$ integers. He wrote it out on the whiteboard as follows:\nhe wrote the number $$$a_1$$$ to the left side (at the beginning of the whiteboard);\nhe wrote the number $$$a_2$$$ to the right side (at the end of the whiteboard);\nthen as far to the left as possible (but to the right from $$$a_1$$$), he wrote the number $$$a_3$$$;\nthen as far to the right as possible (but to the left from $$$a_2$$$), he wrote the number $$$a_4$$$;\nPolycarp continued to act as well, until he wrote out the entire sequence on the whiteboard.\nThe beginning of the result looks like this (of course, if $$$n \\ge 4$$$).\nFor example, if $$$n=7$$$ and $$$a=[3, 1, 4, 1, 5, 9, 2]$$$, then Polycarp will write a sequence on the whiteboard $$$[3, 4, 5, 2, 9, 1, 1]$$$.\nYou saw the sequence written on the whiteboard and now you want to restore Polycarp's favorite sequence.\nInput\nThe first line contains a single positive integer $$$t$$$ ($$$1 \\le t \\le 300$$$)\u00a0\u2014 the number of test cases in the test. Then $$$t$$$ test cases follow.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 300$$$)\u00a0\u2014 the length of the sequence written on the whiteboard.\nThe next line contains $$$n$$$ integers $$$b_1, b_2,\\ldots, b_n$$$ ($$$1 \\le b_i \\le 10^9$$$)\u00a0\u2014 the sequence written on the whiteboard.\nOutput\nOutput $$$t$$$ answers to the test cases. Each answer\u00a0\u2014 is a sequence $$$a$$$ that Polycarp wrote out on the whiteboard.\nExample\nInput\n6\n7\n3 4 5 2 9 1 1\n4\n9 2 7 1\n11\n8 4 3 1 2 7 8 7 9 4 2\n1\n42\n2\n11 7\n8\n1 1 1 1 1 1 1 1\nOutput\n3 1 4 1 5 9 2 \n9 1 2 7 \n8 2 4 4 3 9 1 7 2 8 7 \n42 \n11 7 \n1 1 1 1 1 1 1 1\nNote\nIn the first test case, the sequence $$$a$$$ matches the sequence from the statement. The whiteboard states after each step look like this:\n$$$[3] \\Rightarrow [3, 1] \\Rightarrow [3, 4, 1] \\Rightarrow [3, 4, 1, 1] \\Rightarrow [3, 4, 5, 1, 1] \\Rightarrow [3, 4, 5, 9, 1, 1] \\Rightarrow [3, 4, 5, 2, 9, 1, 1]$$$.", "input": [ [ [ "7" ], [ "3", "4", "5", "2", "9", "1", "1" ] ], [ [ "4" ], [ "9", "2", "7", "1" ] ], [ [ "11" ], [ "8", "4", "3", "1", "2", "7", "8", "7", "9", "4", "2" ] ], [ [ "1" ], [ "42" ] ], [ [ "2" ], [ "11", "7" ] ], [ [ "8" ], [ "1", "1", "1", "1", "1", "1", "1", "1" ] ] ], "output": [ "3 1 4 1 5 9 2 ", "9 1 2 7 ", "8 2 4 4 3 9 1 7 2 8 7 ", "42 ", "11 7 ", "1 1 1 1 1 1 1 1" ] }, { "problem_id": "1461A", "problem_name": "String Generation\nconstructive algorithms, greedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1461/A", "problem_solution_link": "https://codeforces.com/problemset/status/1461/problem/A", "problem_statement": "A. String Generation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nOne fall day Joe got bored because he couldn't find himself something interesting to do. Marty suggested Joe to generate a string of length $$$n$$$ to entertain him somehow. It didn't seem particularly difficult, but Joe's generated string had to follow these rules:\nthe string may only contain characters '\na\n', '\nb\n', or '\nc\n';\nthe maximum length of a substring of this string that is a palindrome does not exceed $$$k$$$.\nA string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end. For example, strings \"\na\n\", \"\nbc\n\", \"\nabc\n\" are substrings of a string \"\nabc\n\", while strings \"\nac\n\", \"\nba\n\", \"\ncba\n\" are not.\nA string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, strings \"\nabccba\n\", \"\nabbba\n\", \"\naba\n\", \"\nabacaba\n\", \"\na\n\", and \"\nbacab\n\" are palindromes, while strings \"\nabcbba\n\", \"\nabb\n\", and \"\nab\n\" are not.\nNow Joe wants to find any correct string. Help him! It can be proven that the answer always exists under the given constraints.\nInput\nEach test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10$$$).\nThe only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 1\\,000$$$)\u00a0\u2014 the required string length and the maximum length of a palindrome substring, respectively.\nOutput\nFor each test case, print any string that satisfies the conditions from the problem statement. If there are multiple correct answers, you can print any one of them. It can be proven that the answer always exists under the given constraints.\nExample\nInput\n2\n3 2\n4 1\nOutput\naab\nacba\nNote\nIn the first test case of the example, the palindrome substring with the maximum length is \"\naa\n\". Its length does not exceed $$$2$$$, so it fits.\nIn the second test case all palindrome substrings have the length one.", "input": [ [ [ "3", "2" ] ], [ [ "4", "1" ] ] ], "output": [ "aab", "acba" ] }, { "problem_id": "1459A", "problem_name": "Red-Blue Shuffle\nmath, probabilities", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1459/A", "problem_solution_link": "https://codeforces.com/problemset/status/1459/problem/A", "problem_statement": "A. Red-Blue Shuffle\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ cards numbered $$$1, \\ldots, n$$$. The card $$$i$$$ has a red digit $$$r_i$$$ and a blue digit $$$b_i$$$ written on it.\nWe arrange all $$$n$$$ cards in random order from left to right, with all permutations of $$$1, \\ldots, n$$$ having the same probability. We then read all red digits on the cards from left to right, and obtain an integer $$$R$$$. In the same way, we read all blue digits and obtain an integer $$$B$$$. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to $$$0$$$. Below is an illustration of a possible rearrangement of three cards, and how $$$R$$$ and $$$B$$$ can be found.\nTwo players, Red and Blue, are involved in a bet. Red bets that after the shuffle $$$R > B$$$, and Blue bets that $$$R < B$$$. If in the end $$$R = B$$$, the bet results in a draw, and neither player wins.\nDetermine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.\nInput\nThe first line contains a single integer $$$T$$$ ($$$1 \\leq T \\leq 100$$$)\u00a0\u2014 the number of test cases.\nDescriptions of $$$T$$$ test cases follow. Each test case description starts with a line containing a single integer $$$n$$$ ($$$1 \\leq n \\leq 1000$$$)\u00a0\u2014 the number of cards.\nThe following line contains a string of $$$n$$$ digits $$$r_1, \\ldots, r_n$$$\u00a0\u2014 red digits on cards $$$1, \\ldots, n$$$ respectively.\nThe following line contains a string of $$$n$$$ digits $$$b_1, \\ldots, b_n$$$\u00a0\u2014 blue digits on cards $$$1, \\ldots, n$$$ respectively.\nNote that digits in the same line are not separated with any delimiters.\nOutput\nPrint $$$T$$$ answers for the test cases in order, one per line.\nIf Red has a\nstrictly\nhigher change to win, print \"\nRED\n\".\nIf Blue has a\nstrictly\nhigher change to win, print \"\nBLUE\n\".\nIf both players are equally likely to win, print \"\nEQUAL\n\".\nNote that all answers are\ncase-sensitive\n.\nExample\nInput\n3\n3\n777\n111\n3\n314\n159\n5\n09281\n09281\nOutput\nRED\nBLUE\nEQUAL\nNote\nFormally, let $$$n_R$$$ be the number of permutations of cards $$$1, \\ldots, n$$$ such that the resulting numbers $$$R$$$ and $$$B$$$ satisfy $$$R > B$$$. Similarly, let $$$n_B$$$ be the number of permutations such that $$$R < B$$$. If $$$n_R > n_B$$$, you should print \"\nRED\n\". If $$$n_R < n_B$$$, you should print \"\nBLUE\n\". If $$$n_R = n_B$$$, print \"\nEQUAL\n\".\nIn the first sample case, $$$R = 777$$$ and $$$B = 111$$$ regardless of the card order, thus Red always wins.\nIn the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:\norder $$$1, 2, 3$$$: $$$314 > 159$$$;\norder $$$1, 3, 2$$$: $$$341 > 195$$$;\norder $$$2, 1, 3$$$: $$$134 < 519$$$;\norder $$$2, 3, 1$$$: $$$143 < 591$$$;\norder $$$3, 1, 2$$$: $$$431 < 915$$$;\norder $$$3, 2, 1$$$: $$$413 < 951$$$.\nSince $$$R < B$$$ is more frequent, the answer is \"\nBLUE\n\".\nIn the third sample case, $$$R = B$$$ regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.", "input": [ [ [ "3" ], [ "777" ], [ "111" ] ], [ [ "3" ], [ "314" ], [ "159" ] ], [ [ "5" ], [ "09281" ], [ "09281" ] ] ], "output": [ "RED", "BLUE", "EQUAL" ] }, { "problem_id": "1455A", "problem_name": "Strange Functions\nmath, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1455/A", "problem_solution_link": "https://codeforces.com/problemset/status/1455/problem/A", "problem_statement": "A. Strange Functions\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's define a function $$$f(x)$$$ ($$$x$$$ is a positive integer) as follows: write all digits of the decimal representation of $$$x$$$ backwards, then get rid of the leading zeroes. For example, $$$f(321) = 123$$$, $$$f(120) = 21$$$, $$$f(1000000) = 1$$$, $$$f(111) = 111$$$.\nLet's define another function $$$g(x) = \\dfrac{x}{f(f(x))}$$$ ($$$x$$$ is a positive integer as well).\nYour task is the following: for the given positive integer $$$n$$$, calculate the number of different values of $$$g(x)$$$ among all numbers $$$x$$$ such that $$$1 \\le x \\le n$$$.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases.\nEach test case consists of one line containing one integer $$$n$$$ ($$$1 \\le n < 10^{100}$$$). This integer is given without leading zeroes.\nOutput\nFor each test case, print one integer \u2014 the number of different values of the function $$$g(x)$$$, if $$$x$$$ can be any integer from $$$[1, n]$$$.\nExample\nInput\n5\n4\n37\n998244353\n1000000007\n12345678901337426966631415\nOutput\n1\n2\n9\n10\n26\nNote\nExplanations for the two first test cases of the example:\nif $$$n = 4$$$, then for every integer $$$x$$$ such that $$$1 \\le x \\le n$$$, $$$\\dfrac{x}{f(f(x))} = 1$$$;\nif $$$n = 37$$$, then for some integers $$$x$$$ such that $$$1 \\le x \\le n$$$, $$$\\dfrac{x}{f(f(x))} = 1$$$ (for example, if $$$x = 23$$$, $$$f(f(x)) = 23$$$,$$$\\dfrac{x}{f(f(x))} = 1$$$); and for other values of $$$x$$$, $$$\\dfrac{x}{f(f(x))} = 10$$$ (for example, if $$$x = 30$$$, $$$f(f(x)) = 3$$$, $$$\\dfrac{x}{f(f(x))} = 10$$$). So, there are two different values of $$$g(x)$$$.", "input": [ [ [ "4" ] ], [ [ "37" ] ], [ [ "998244353" ] ], [ [ "1000000007" ] ], [ [ "12345678901337426966631415" ] ] ], "output": [ "1", "2", "9", "10", "26" ] }, { "problem_id": "1454B", "problem_name": "Unique Bid Auction\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1454/B", "problem_solution_link": "https://codeforces.com/problemset/status/1454/problem/B", "problem_statement": "B. Unique Bid Auction\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a game called \"Unique Bid Auction\". You can read more about it here:\nhttps://en.wikipedia.org/wiki/Unique_bid_auction\n(though you don't have to do it to solve this problem).\nLet's simplify this game a bit. Formally, there are $$$n$$$ participants, the $$$i$$$-th participant chose the number $$$a_i$$$. The winner of the game is such a participant that the number he chose is\nunique\n(i.\u00a0e. nobody else chose this number except him) and is\nminimal\n(i.\u00a0e. among all unique values of $$$a$$$ the minimum one is the winning one).\nYour task is to find the\nindex\nof the participant who won the game (or\n-1\nif there is no winner). Indexing is $$$1$$$-based, i.\u00a0e. the participants are numbered from $$$1$$$ to $$$n$$$.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 2 \\cdot 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first line of the test case contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) \u2014 the number of participants. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le n$$$), where $$$a_i$$$ is the $$$i$$$-th participant chosen number.\nIt is guaranteed that the sum of $$$n$$$ does not exceed $$$2 \\cdot 10^5$$$ ($$$\\sum n \\le 2 \\cdot 10^5$$$).\nOutput\nFor each test case, print the answer \u2014 the\nindex\nof the participant who won the game (or\n-1\nif there is no winner).\nNote that the answer is always unique\n.\nExample\nInput\n6\n2\n1 1\n3\n2 1 3\n4\n2 2 2 3\n1\n1\n5\n2 3 2 4 2\n6\n1 1 5 5 4 4\nOutput\n-1\n2\n4\n1\n2\n-1", "input": [ [ [ "2" ], [ "1", "1" ] ], [ [ "3" ], [ "2", "1", "3" ] ], [ [ "4" ], [ "2", "2", "2", "3" ] ], [ [ "1" ], [ "1" ] ], [ [ "5" ], [ "2", "3", "2", "4", "2" ] ], [ [ "6" ], [ "1", "1", "5", "5", "4", "4" ] ] ], "output": [ "-1", "2", "4", "1", "2", "-1" ] }, { "problem_id": "1454A", "problem_name": "Special Permutation\nconstructive algorithms, probabilities", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1454/A", "problem_solution_link": "https://codeforces.com/problemset/status/1454/problem/A", "problem_statement": "A. Special Permutation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given one integer $$$n$$$ ($$$n > 1$$$).\nRecall that a permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2, 3, 1, 5, 4]$$$ is a permutation of length $$$5$$$, but $$$[1, 2, 2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1, 3, 4]$$$ is also not a permutation ($$$n = 3$$$ but there is $$$4$$$ in the array).\nYour task is to find a permutation $$$p$$$ of length $$$n$$$ that there is no index $$$i$$$ ($$$1 \\le i \\le n$$$) such that $$$p_i = i$$$ (so, for all $$$i$$$ from $$$1$$$ to $$$n$$$ the condition $$$p_i \\ne i$$$ should be satisfied).\nYou have to answer $$$t$$$ independent test cases.\nIf there are several answers, you can print any. It can be proven that the answer exists for each $$$n > 1$$$.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe only line of the test case contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the length of the permutation you have to find.\nOutput\nFor each test case, print $$$n$$$ distinct integers $$$p_1, p_2, \\ldots, p_n$$$ \u2014 a permutation that there is no index $$$i$$$ ($$$1 \\le i \\le n$$$) such that $$$p_i = i$$$ (so, for all $$$i$$$ from $$$1$$$ to $$$n$$$ the condition $$$p_i \\ne i$$$ should be satisfied).\nIf there are several answers, you can print any. It can be proven that the answer exists for each $$$n > 1$$$.\nExample\nInput\n2\n2\n5\nOutput\n2 1\n2 1 5 3 4", "input": [ [ [ "2" ] ], [ [ "5" ] ] ], "output": [ "2 1", "2 1 5 3 4" ] }, { "problem_id": "1453A", "problem_name": "Cancel the Trains\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1453/A", "problem_solution_link": "https://codeforces.com/problemset/status/1453/problem/A", "problem_statement": "A. Cancel the Trains\ntime limit per test\n1 second\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nGildong's town has a train system that has $$$100$$$ trains that travel from the bottom end to the top end and $$$100$$$ trains that travel from the left end to the right end. The trains starting from each side are numbered from $$$1$$$ to $$$100$$$, respectively, and all trains have the same speed. Let's take a look at the picture below.\nThe train system can be represented as coordinates on a 2D plane. The $$$i$$$-th train starting at the bottom end is initially at $$$(i,0)$$$ and will be at $$$(i,T)$$$ after $$$T$$$ minutes, and the $$$i$$$-th train starting at the left end is initially at $$$(0,i)$$$ and will be at $$$(T,i)$$$ after $$$T$$$ minutes. All trains arrive at their destinations after $$$101$$$ minutes.\nHowever, Gildong found that some trains scheduled to depart at a specific time, simultaneously, are very dangerous. At this time, $$$n$$$ trains are scheduled to depart from the bottom end and $$$m$$$ trains are scheduled to depart from the left end. If two trains are both at $$$(x,y)$$$ at the same time for some $$$x$$$ and $$$y$$$, they will crash into each other. Therefore, he is asking you to find the\nminimum\nnumber of trains that should be cancelled to prevent all such crashes.\nInput\nEach test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$).\nEach test case contains three lines. The first line of each test case consists of two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 100$$$) \u2014 the number of trains scheduled to depart from the bottom end, and the number of trains scheduled to depart from the left end, respectively.\nThe second line of each test case contains $$$n$$$ integers. Each integer is a train number that is scheduled to start from the\nbottom\nend. The numbers are given in strictly increasing order, and are between $$$1$$$ and $$$100$$$, inclusive.\nThe third line of each test case contains $$$m$$$ integers. Each integer is a train number that is scheduled to start from the\nleft\nend. The numbers are given in strictly increasing order, and are between $$$1$$$ and $$$100$$$, inclusive.\nOutput\nFor each test case, print a single integer: the minimum number of trains that should be canceled in order to prevent all crashes.\nExample\nInput\n3\n1 2\n1\n3 4\n3 2\n1 3 4\n2 4\n9 14\n2 7 16 28 33 57 59 86 99\n3 9 14 19 25 26 28 35 41 59 85 87 99 100\nOutput\n0\n1\n3\nNote\nIn the first case, we can show that there will be no crashes if the current schedule is followed. Therefore, the answer is zero.\nIn the second case, at $$$T=4$$$, there will be a crash, as can be seen in the picture below. We can prove that after canceling one of these trains, the remaining trains will not crash. Therefore, the answer is one.", "input": [ [ [ "1", "2" ], [ "1" ], [ "3", "4" ] ], [ [ "3", "2" ], [ "1", "3", "4" ], [ "2", "4" ] ], [ [ "9", "14" ], [ "2", "7", "16", "28", "33", "57", "59", "86", "99" ], [ "3", "9", "14", "19", "25", "26", "28", "35", "41", "59", "85", "87", "99", "100" ] ] ], "output": [ "0", "1", "3" ] }, { "problem_id": "1452C", "problem_name": "Two Brackets\ngreedy", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1452/C", "problem_solution_link": "https://codeforces.com/problemset/status/1452/problem/C", "problem_statement": "C. Two Brackets\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a string $$$s$$$, consisting of brackets of two types: '\n(\n', '\n)\n', '\n[\n' and '\n]\n'.\nA string is called a regular bracket sequence (RBS) if it's of one of the following types:\nempty string;\n'\n(\n' + RBS + '\n)\n';\n'\n[\n' + RBS + '\n]\n';\nRBS + RBS.\nwhere plus is a concatenation of two strings.\nIn one move you can choose a non-empty subsequence of the string $$$s$$$ (not necessarily consecutive) that is an RBS, remove it from the string and concatenate the remaining parts without changing the order.\nWhat is the maximum number of moves you can perform?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of testcases.\nEach of the next $$$t$$$ lines contains a non-empty string, consisting only of characters '\n(\n', '\n)\n', '\n[\n' and '\n]\n'. The total length of the strings over all testcases doesn't exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each testcase print a single integer\u00a0\u2014 the maximum number of moves you can perform on a given string $$$s$$$.\nExample\nInput\n5\n()\n[]()\n([)]\n)]([\n)[(]\nOutput\n1\n2\n2\n0\n1\nNote\nIn the first example you can just erase the whole string.\nIn the second example you can first erase the brackets on positions $$$1$$$ and $$$2$$$: \"\n[]\n()\n\", then \"\n()\n\" is left. After that you can erase it whole. You could erase the whole string from the beginning but you would get one move instead of two.\nIn the third example you can first erase the brackets on positions $$$1$$$ and $$$3$$$: \"\n(\n[\n)\n]\n\". They form an RBS \"\n()\n\". Then \"\n[]\n\" is left, so you can erase it whole.\nIn the fourth example there is no subsequence that is an RBS, so you can't perform a move at all.\nIn the fifth example you can erase the brackets on positions $$$2$$$ and $$$4$$$: \"\n)\n[\n(\n]\n\" and get \"\n)(\n\" as a result. You can erase nothing from it.", "input": [ [ [ "()" ] ], [ [ "[]()" ] ], [ [ "([)]" ] ], [ [ ")]([" ] ], [ [ ")[(]" ] ] ], "output": [ "1", "2", "2", "0", "1" ] }, { "problem_id": "1452A", "problem_name": "Robot Program\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1452/A", "problem_solution_link": "https://codeforces.com/problemset/status/1452/problem/A", "problem_statement": "A. Robot Program\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is an infinite 2-dimensional grid. The robot stands in cell $$$(0, 0)$$$ and wants to reach cell $$$(x, y)$$$. Here is a list of possible commands the robot can execute:\nmove north from cell $$$(i, j)$$$ to $$$(i, j + 1)$$$;\nmove east from cell $$$(i, j)$$$ to $$$(i + 1, j)$$$;\nmove south from cell $$$(i, j)$$$ to $$$(i, j - 1)$$$;\nmove west from cell $$$(i, j)$$$ to $$$(i - 1, j)$$$;\nstay in cell $$$(i, j)$$$.\nThe robot wants to reach cell $$$(x, y)$$$ in as few commands as possible. However, he can't execute the same command two or more times in a row.\nWhat is the minimum number of commands required to reach $$$(x, y)$$$ from $$$(0, 0)$$$?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of testcases.\nEach of the next $$$t$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$0 \\le x, y \\le 10^4$$$)\u00a0\u2014 the destination coordinates of the robot.\nOutput\nFor each testcase print a single integer\u00a0\u2014 the minimum number of commands required for the robot to reach $$$(x, y)$$$ from $$$(0, 0)$$$ if no command is allowed to be executed two or more times in a row.\nExample\nInput\n5\n5 5\n3 4\n7 1\n0 0\n2 0\nOutput\n10\n7\n13\n0\n3\nNote\nThe explanations for the example test:\nWe use characters\nN\n,\nE\n,\nS\n,\nW\nand\n0\nto denote going north, going east, going south, going west and staying in the current cell, respectively.\nIn the first test case, the robot can use the following sequence:\nNENENENENE\n.\nIn the second test case, the robot can use the following sequence:\nNENENEN\n.\nIn the third test case, the robot can use the following sequence:\nESENENE0ENESE\n.\nIn the fourth test case, the robot doesn't need to go anywhere at all.\nIn the fifth test case, the robot can use the following sequence:\nE0E\n.", "input": [ [ [ "5", "5" ] ], [ [ "3", "4" ] ], [ [ "7", "1" ] ], [ [ "0", "0" ] ], [ [ "2", "0" ] ] ], "output": [ "10", "7", "13", "0", "3" ] }, { "problem_id": "1451A", "problem_name": "Subtract or Divide\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1451/A", "problem_solution_link": "https://codeforces.com/problemset/status/1451/problem/A", "problem_statement": "A. Subtract or Divide\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nRidbit starts with an integer $$$n$$$.\nIn one move, he can perform one of the following operations:\ndivide $$$n$$$ by one of its\nproper\ndivisors, or\nsubtract $$$1$$$ from $$$n$$$ if $$$n$$$ is greater than $$$1$$$.\nA proper divisor is a divisor of a number, excluding itself. For example, $$$1$$$, $$$2$$$, $$$4$$$, $$$5$$$, and $$$10$$$ are proper divisors of $$$20$$$, but $$$20$$$ itself is not.\nWhat is the minimum number of moves Ridbit is required to make to reduce $$$n$$$ to $$$1$$$?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$)\u00a0\u2014 the number of test cases.\nThe only line of each test case contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^9$$$).\nOutput\nFor each test case, output the minimum number of moves required to reduce $$$n$$$ to $$$1$$$.\nExample\nInput\n6\n1\n2\n3\n4\n6\n9\nOutput\n0\n1\n2\n2\n2\n3\nNote\nFor the test cases in the example, $$$n$$$ may be reduced to $$$1$$$ using the following operations in sequence\n$$$1$$$\n$$$2 \\xrightarrow{} 1$$$\n$$$3 \\xrightarrow{} 2 \\xrightarrow{} 1$$$\n$$$4 \\xrightarrow{} 2 \\xrightarrow{} 1$$$\n$$$6 \\xrightarrow{} 2 \\xrightarrow{} 1$$$\n$$$9 \\xrightarrow{} 3 \\xrightarrow{} 2\\xrightarrow{} 1$$$", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "3" ] ], [ [ "4" ] ], [ [ "6" ] ], [ [ "9" ] ] ], "output": [ "0", "1", "2", "2", "2", "3" ] }, { "problem_id": "1450A", "problem_name": "Avoid Trygub\nconstructive algorithms, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1450/A", "problem_solution_link": "https://codeforces.com/problemset/status/1450/problem/A", "problem_statement": "A. Avoid Trygub\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA string $$$b$$$ is a subsequence of a string $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) characters. For example, \"\nxy\n\" is a subsequence of \"\nxzyw\n\" and \"\nxy\n\", but not \"\nyx\n\".\nYou are given a string $$$a$$$. Your task is to reorder the characters of $$$a$$$ so that \"\ntrygub\n\" is not a subsequence of the resulting string.\nIn other words, you should find a string $$$b$$$ which is a permutation of symbols of the string $$$a$$$ and \"\ntrygub\n\" is not a subsequence of $$$b$$$.\nWe have a truly marvelous proof that any string can be arranged not to contain \"\ntrygub\n\" as a subsequence, but this problem statement is too short to contain it.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1\\le t\\le 100$$$) \u2014 the number of test cases.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1\\le n\\le 200$$$) \u2014 the length of $$$a$$$.\nThe next line contains the string $$$a$$$ of length $$$n$$$, consisting of lowercase English letters.\nOutput\nFor each test case, output a string $$$b$$$ of length $$$n$$$ which is a permutation of characters of the string $$$a$$$, and such that \"\ntrygub\n\" is not a subsequence of it.\nIf there exist multiple possible strings $$$b$$$, you can print any.\nExample\nInput\n3\n11\nantontrygub\n15\nbestcoordinator\n19\ntrywatchinggurabruh\nOutput\nbugyrtnotna\nbestcoordinator\nbruhtrywatchinggura\nNote\nIn the first test case, \"\nbugyrtnotna\n\" does not contain \"\ntrygub\n\" as a subsequence. It does contain the letters of \"\ntrygub\n\", but not in the correct order, so it is not a subsequence.\nIn the second test case, we did not change the order of characters because it is not needed.\nIn the third test case, \"\nbruhtrywatchinggura\n\" does contain \"\ntrygu\n\" as a subsequence, but not \"\ntrygub\n\".", "input": [ [ [ "11" ], [ "antontrygub" ] ], [ [ "15" ], [ "bestcoordinator" ] ], [ [ "19" ], [ "trywatchinggurabruh" ] ] ], "output": [ "bugyrtnotna", "bestcoordinator", "bruhtrywatchinggura" ] }, { "problem_id": "1447A", "problem_name": "Add Candies\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1447/A", "problem_solution_link": "https://codeforces.com/problemset/status/1447/problem/A", "problem_statement": "A. Add Candies\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ bags with candies, initially the $$$i$$$-th bag contains $$$i$$$ candies. You want all the bags to contain an equal amount of candies in the end.\nTo achieve this, you will:\nChoose $$$m$$$ such that $$$1 \\le m \\le 1000$$$\nPerform $$$m$$$ operations. In the $$$j$$$-th operation, you will pick one bag and add $$$j$$$ candies to all bags apart from the chosen one.\nYour goal is to find a valid sequence of operations after which all the bags will contain an equal amount of candies.\nIt can be proved that for the given constraints such a sequence always exists.\nYou\ndon't\nhave to minimize $$$m$$$.\nIf there are several valid sequences, you can output\nany\n.\nInput\nEach test contains multiple test cases.\nThe first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). Description of the test cases follows.\nThe first and only line of each test case contains one integer $$$n$$$ ($$$2 \\le n\\le 100$$$).\nOutput\nFor each testcase, print two lines with your answer.\nIn the first line print $$$m$$$ ($$$1\\le m \\le 1000$$$)\u00a0\u2014 the number of operations you want to take.\nIn the second line print $$$m$$$ positive integers $$$a_1, a_2, \\dots, a_m$$$ ($$$1 \\le a_i \\le n$$$), where $$$a_j$$$ is the number of bag you chose on the $$$j$$$-th operation.\nExample\nInput\n2\n2\n3\nOutput\n1\n2\n5\n3 3 3 1 2\nNote\nIn the first case, adding $$$1$$$ candy to all bags except of the second one leads to the arrangement with $$$[2, 2]$$$ candies.\nIn the second case, firstly you use first three operations to add $$$1+2+3=6$$$ candies in total to each bag except of the third one, which gives you $$$[7, 8, 3]$$$. Later, you add $$$4$$$ candies to second and third bag, so you have $$$[7, 12, 7]$$$, and $$$5$$$ candies to first and third bag \u00a0\u2014 and the result is $$$[12, 12, 12]$$$.", "input": [ [ [ "2" ] ], [ [ "3" ] ] ], "output": [ ["1", "2"], ["5", "3 3 3 1 2"] ], "error": true }, { "problem_id": "1445A", "problem_name": "Array Rearrangment\ngreedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1445/A", "problem_solution_link": "https://codeforces.com/problemset/status/1445/problem/A", "problem_statement": "A. Array Rearrangment\ntime limit per test\n1 second\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two arrays $$$a$$$ and $$$b$$$, each consisting of $$$n$$$ positive integers, and an integer $$$x$$$. Please determine if one can rearrange the elements of $$$b$$$ so that $$$a_i + b_i \\leq x$$$ holds for each $$$i$$$ ($$$1 \\le i \\le n$$$).\nInput\nThe first line of input contains one integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. $$$t$$$ blocks follow, each describing an individual test case.\nThe first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \\leq n \\leq 50$$$; $$$1 \\leq x \\leq 1000$$$)\u00a0\u2014 the length of arrays $$$a$$$ and $$$b$$$, and the parameter $$$x$$$, described in the problem statement.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_1 \\le a_2 \\le \\dots \\le a_n \\leq x$$$)\u00a0\u2014 the elements of array $$$a$$$ in non-descending order.\nThe third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \\ldots, b_n$$$ ($$$1 \\leq b_1 \\le b_2 \\le \\dots \\le b_n \\leq x$$$)\u00a0\u2014 the elements of array $$$b$$$ in non-descending order.\nTest cases are separated by a blank line.\nOutput\nFor each test case print\nYes\nif one can rearrange the corresponding array $$$b$$$ so that $$$a_i + b_i \\leq x$$$ holds for each $$$i$$$ ($$$1 \\le i \\le n$$$) or\nNo\notherwise.\nEach character can be printed in any case.\nExample\nInput\n4\n3 4\n1 2 3\n1 1 2\n\n2 6\n1 4\n2 5\n\n4 4\n1 2 3 4\n1 2 3 4\n\n1 5\n5\n5\nOutput\nYes\nYes\nNo\nNo\nNote\nIn the first test case, one can rearrange $$$b$$$ so it'll look like $$$[1, 2, 1]$$$. In this case, $$$1 + 1 \\leq 4$$$; $$$2 + 2 \\leq 4$$$; $$$3 + 1 \\leq 4$$$.\nIn the second test case, one can set $$$b$$$ to $$$[5, 2]$$$, then $$$1 + 5 \\leq 6$$$; $$$4 + 2 \\leq 6$$$.\nIn the third test case, no matter how one shuffles array $$$b$$$, $$$a_4 + b_4 = 4 + b_4 > 4$$$.\nIn the fourth test case, there is only one rearrangement of array $$$b$$$ and it doesn't satisfy the condition since $$$5 + 5 > 5$$$.", "input": [ [ [ "3", "4" ], [ "1", "2", "3", "1", "1", "2" ] ] ], "output": [ "Yes" ] }, { "problem_id": "1443A", "problem_name": "Kids Seating\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1443/A", "problem_solution_link": "https://codeforces.com/problemset/status/1443/problem/A", "problem_statement": "A. Kids Seating\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nToday the kindergarten has a new group of $$$n$$$ kids who need to be seated at the dinner table. The chairs at the table are numbered from $$$1$$$ to $$$4n$$$. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers $$$a$$$ and $$$b$$$ ($$$a \\neq b$$$) will indulge if:\n$$$gcd(a, b) = 1$$$ or,\n$$$a$$$ divides $$$b$$$ or $$$b$$$ divides $$$a$$$.\n$$$gcd(a, b)$$$\u00a0\u2014 the maximum number $$$x$$$ such that $$$a$$$ is divisible by $$$x$$$ and $$$b$$$ is divisible by $$$x$$$.\nFor example, if $$$n=3$$$ and the kids sit on chairs with numbers $$$2$$$, $$$3$$$, $$$4$$$, then they will indulge since $$$4$$$ is divided by $$$2$$$ and $$$gcd(2, 3) = 1$$$. If kids sit on chairs with numbers $$$4$$$, $$$6$$$, $$$10$$$, then they will not indulge.\nThe teacher really doesn't want the mess at the table, so she wants to seat the kids so there are no $$$2$$$ of the kid that can indulge. More formally, she wants no pair of chairs $$$a$$$ and $$$b$$$ that the kids occupy to fulfill the condition above.\nSince the teacher is very busy with the entertainment of the kids, she asked you to solve this problem.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$)\u00a0\u2014 the number of test cases. Then $$$t$$$ test cases follow.\nEach test case consists of one line containing an integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$)\u00a0\u2014 the number of kids.\nOutput\nOutput $$$t$$$ lines, which contain $$$n$$$ distinct integers from $$$1$$$ to $$$4n$$$\u00a0\u2014 the numbers of chairs that the kids should occupy in the corresponding test case. If there are multiple answers, print any of them. You can print $$$n$$$ numbers in any order.\nExample\nInput\n3\n2\n3\n4\nOutput\n6 4\n4 6 10\n14 10 12 8", "input": [ [ [ "2" ] ], [ [ "3" ] ], [ [ "4" ] ] ], "output": [ "6 4", "4 6 10", "14 10 12 8" ] }, { "problem_id": "1440A", "problem_name": "Buy the String\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1440/A", "problem_solution_link": "https://codeforces.com/problemset/status/1440/problem/A", "problem_statement": "A. Buy the String\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given four integers $$$n$$$, $$$c_0$$$, $$$c_1$$$ and $$$h$$$ and a binary string $$$s$$$ of length $$$n$$$.\nA binary string is a string consisting of characters $$$0$$$ and $$$1$$$.\nYou can change any character of the string $$$s$$$ (the string should be still binary after the change). You should pay $$$h$$$ coins for each change.\nAfter some changes (possibly zero) you want to buy the string. To buy the string you should buy all its characters. To buy the character $$$0$$$ you should pay $$$c_0$$$ coins, to buy the character $$$1$$$ you should pay $$$c_1$$$ coins.\nFind the minimum number of coins needed to buy the string.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 10$$$)\u00a0\u2014 the number of test cases. Next $$$2t$$$ lines contain descriptions of test cases.\nThe first line of the description of each test case contains four integers $$$n$$$, $$$c_{0}$$$, $$$c_{1}$$$, $$$h$$$ ($$$1 \\leq n, c_{0}, c_{1}, h \\leq 1000$$$).\nThe second line of the description of each test case contains the binary string $$$s$$$ of length $$$n$$$.\nOutput\nFor each test case print a single integer\u00a0\u2014 the minimum number of coins needed to buy the string.\nExample\nInput\n6\n3 1 1 1\n100\n5 10 100 1\n01010\n5 10 1 1\n11111\n5 1 10 1\n11111\n12 2 1 10\n101110110101\n2 100 1 10\n00\nOutput\n3\n52\n5\n10\n16\n22\nNote\nIn the first test case, you can buy all characters and pay $$$3$$$ coins, because both characters $$$0$$$ and $$$1$$$ costs $$$1$$$ coin.\nIn the second test case, you can firstly change $$$2$$$-nd and $$$4$$$-th symbols of the string from $$$1$$$ to $$$0$$$ and pay $$$2$$$ coins for that. Your string will be $$$00000$$$. After that, you can buy the string and pay $$$5 \\cdot 10 = 50$$$ coins for that. The total number of coins paid will be $$$2 + 50 = 52$$$.", "input": [ [ [ "3", "1", "1", "1" ], [ "100" ] ], [ [ "5", "10", "100", "1" ], [ "01010" ] ], [ [ "5", "10", "1", "1" ], [ "11111" ] ], [ [ "5", "1", "10", "1" ], [ "11111" ] ], [ [ "12", "2", "1", "10" ], [ "101110110101" ] ], [ [ "2", "100", "1", "10" ], [ "00" ] ] ], "output": [ "3", "52", "5", "10", "16", "22" ] }, { "problem_id": "1438A", "problem_name": "Specific Tastes of Andre\nconstructive algorithms, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1438/A", "problem_solution_link": "https://codeforces.com/problemset/status/1438/problem/A", "problem_statement": "A. Specific Tastes of Andre\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAndre has very specific tastes. Recently he started falling in love with arrays.\nAndre calls an nonempty array $$$b$$$\ngood\n, if sum of its elements is divisible by the length of this array. For example, array $$$[2, 3, 1]$$$ is good, as sum of its elements\u00a0\u2014 $$$6$$$\u00a0\u2014 is divisible by $$$3$$$, but array $$$[1, 1, 2, 3]$$$ isn't good, as $$$7$$$ isn't divisible by $$$4$$$.\nAndre calls an array $$$a$$$ of length $$$n$$$\nperfect\nif the following conditions hold:\nEvery nonempty subarray of this array is\ngood\n.\nFor every $$$i$$$ ($$$1 \\le i \\le n$$$), $$$1 \\leq a_i \\leq 100$$$.\nGiven a positive integer $$$n$$$, output any\nperfect\narray of length $$$n$$$. We can show that for the given constraints such an array always exists.\nAn array $$$c$$$ is a subarray of an array $$$d$$$ if $$$c$$$ can be obtained from $$$d$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). Description of the test cases follows.\nThe first and only line of every test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$).\nOutput\nFor every test, output any\nperfect\narray of length $$$n$$$ on a separate line.\nExample\nInput\n3\n1\n2\n4\nOutput\n24\n19 33\n7 37 79 49\nNote\nArray $$$[19, 33]$$$ is perfect as all $$$3$$$ its subarrays: $$$[19]$$$, $$$[33]$$$, $$$[19, 33]$$$, have sums divisible by their lengths, and therefore are good.", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "4" ] ] ], "output": [ "24", "19 33", "7 37 79 49" ] }, { "problem_id": "1437A", "problem_name": "Marketing Scheme\nbrute force, constructive algorithms, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1437/A", "problem_solution_link": "https://codeforces.com/problemset/status/1437/problem/A", "problem_statement": "A. Marketing Scheme\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts.\nSuppose you decided to sell packs with $$$a$$$ cans in a pack with a discount and some customer wants to buy $$$x$$$ cans of cat food. Then he follows a greedy strategy:\nhe buys $$$\\left\\lfloor \\frac{x}{a} \\right\\rfloor$$$ packs with a discount;\nthen he wants to buy the remaining $$$(x \\bmod a)$$$ cans one by one.\n$$$\\left\\lfloor \\frac{x}{a} \\right\\rfloor$$$ is $$$x$$$ divided by $$$a$$$ rounded down, $$$x \\bmod a$$$ is the remainer of $$$x$$$ divided by $$$a$$$.\nBut customers are greedy in general, so if the customer wants to buy $$$(x \\bmod a)$$$ cans one by one and it happens that $$$(x \\bmod a) \\ge \\frac{a}{2}$$$ he decides to buy the whole pack of $$$a$$$ cans (instead of buying $$$(x \\bmod a)$$$ cans). It makes you, as a marketer, happy since the customer bought more than he wanted initially.\nYou know that each of the customers that come to your shop can buy any number of cans from $$$l$$$ to $$$r$$$ inclusive. Can you choose such size of pack $$$a$$$ that each customer buys more cans than they wanted initially?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases.\nThe first and only line of each test case contains two integers $$$l$$$ and $$$r$$$ ($$$1 \\le l \\le r \\le 10^9$$$)\u00a0\u2014 the range of the number of cans customers can buy.\nOutput\nFor each test case, print\nYES\nif you can choose such size of pack $$$a$$$ that each customer buys more cans than they wanted initially. Otherwise, print\nNO\n.\nYou can print each character in any case.\nExample\nInput\n3\n3 4\n1 2\n120 150\nOutput\nYES\nNO\nYES\nNote\nIn the first test case, you can take, for example, $$$a = 5$$$ as the size of the pack. Then if a customer wants to buy $$$3$$$ cans, he'll buy $$$5$$$ instead ($$$3 \\bmod 5 = 3$$$, $$$\\frac{5}{2} = 2.5$$$). The one who wants $$$4$$$ cans will also buy $$$5$$$ cans.\nIn the second test case, there is no way to choose $$$a$$$.\nIn the third test case, you can take, for example, $$$a = 80$$$.", "input": [ [ [ "3", "4" ] ], [ [ "1", "2" ] ], [ [ "120", "150" ] ] ], "output": [ "YES", "NO", "YES" ] }, { "problem_id": "1436A", "problem_name": "Reorder\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1436/A", "problem_solution_link": "https://codeforces.com/problemset/status/1436/problem/A", "problem_statement": "A. Reorder\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nFor a given array $$$a$$$ consisting of $$$n$$$ integers and a given integer $$$m$$$ find if it is possible to reorder elements of the array $$$a$$$ in such a way that $$$\\sum_{i=1}^{n}{\\sum_{j=i}^{n}{\\frac{a_j}{j}}}$$$ equals $$$m$$$? It is forbidden to delete elements as well as insert new elements. Please note that no rounding occurs during division, for example, $$$\\frac{5}{2}=2.5$$$.\nInput\nThe first line contains a single integer $$$t$$$\u00a0\u2014 the number of test cases ($$$1 \\le t \\le 100$$$). The test cases follow, each in two lines.\nThe first line of a test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 100$$$, $$$0 \\le m \\le 10^6$$$). The second line contains integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i \\le 10^6$$$)\u00a0\u2014 the elements of the array.\nOutput\nFor each test case print \"\nYES\n\", if it is possible to reorder the elements of the array in such a way that the given formula gives the given value, and \"\nNO\n\" otherwise.\nExample\nInput\n2\n3 8\n2 5 1\n4 4\n0 1 2 3\nOutput\nYES\nNO\nNote\nIn the first test case one of the reorders could be $$$[1, 2, 5]$$$. The sum is equal to $$$(\\frac{1}{1} + \\frac{2}{2} + \\frac{5}{3}) + (\\frac{2}{2} + \\frac{5}{3}) + (\\frac{5}{3}) = 8$$$. The brackets denote the inner sum $$$\\sum_{j=i}^{n}{\\frac{a_j}{j}}$$$, while the summation of brackets corresponds to the sum over $$$i$$$.", "input": [ [ [ "3", "8" ], [ "2", "5", "1" ] ], [ [ "4", "4" ], [ "0", "1", "2", "3" ] ] ], "output": [ "YES", "NO" ] }, { "problem_id": "1433B", "problem_name": "Yet Another Bookshelf\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1433/B", "problem_solution_link": "https://codeforces.com/problemset/status/1433/problem/B", "problem_statement": "B. Yet Another Bookshelf\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a bookshelf which can fit $$$n$$$ books. The $$$i$$$-th position of bookshelf is $$$a_i = 1$$$ if there is a book on this position and $$$a_i = 0$$$ otherwise. It is guaranteed that there is\nat least one book\non the bookshelf.\nIn one move, you can choose some contiguous segment $$$[l; r]$$$ consisting of books (i.e. for each $$$i$$$ from $$$l$$$ to $$$r$$$ the condition $$$a_i = 1$$$ holds) and:\nShift it to the right by $$$1$$$: move the book at index $$$i$$$ to $$$i + 1$$$ for all $$$l \\le i \\le r$$$. This move can be done only if $$$r+1 \\le n$$$ and there is no book at the position $$$r+1$$$.\nShift it to the left by $$$1$$$: move the book at index $$$i$$$ to $$$i-1$$$ for all $$$l \\le i \\le r$$$. This move can be done only if $$$l-1 \\ge 1$$$ and there is no book at the position $$$l-1$$$.\nYour task is to find the\nminimum\nnumber of moves required to collect all the books on the shelf as a\ncontiguous\n(consecutive) segment (i.e. the segment without any gaps).\nFor example, for $$$a = [0, 0, 1, 0, 1]$$$ there is a gap between books ($$$a_4 = 0$$$ when $$$a_3 = 1$$$ and $$$a_5 = 1$$$), for $$$a = [1, 1, 0]$$$ there are no gaps between books and for $$$a = [0, 0,0]$$$ there are also no gaps between books.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 200$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first line of the test case contains one integer $$$n$$$ ($$$1 \\le n \\le 50$$$) \u2014 the number of places on a bookshelf. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i \\le 1$$$), where $$$a_i$$$ is $$$1$$$ if there is a book at this position and $$$0$$$ otherwise. It is guaranteed that there is\nat least one book\non the bookshelf.\nOutput\nFor each test case, print one integer: the\nminimum\nnumber of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without gaps).\nExample\nInput\n5\n7\n0 0 1 0 1 0 1\n3\n1 0 0\n5\n1 1 0 0 1\n6\n1 0 0 0 0 1\n5\n1 1 0 1 1\nOutput\n2\n0\n2\n4\n1\nNote\nIn the first test case of the example, you can shift the segment $$$[3; 3]$$$ to the right and the segment $$$[4; 5]$$$ to the right. After all moves, the books form the contiguous segment $$$[5; 7]$$$. So the answer is $$$2$$$.\nIn the second test case of the example, you have nothing to do, all the books on the bookshelf form the contiguous segment already.\nIn the third test case of the example, you can shift the segment $$$[5; 5]$$$ to the left and then the segment $$$[4; 4]$$$ to the left again. After all moves, the books form the contiguous segment $$$[1; 3]$$$. So the answer is $$$2$$$.\nIn the fourth test case of the example, you can shift the segment $$$[1; 1]$$$ to the right, the segment $$$[2; 2]$$$ to the right, the segment $$$[6; 6]$$$ to the left and then the segment $$$[5; 5]$$$ to the left. After all moves, the books form the contiguous segment $$$[3; 4]$$$. So the answer is $$$4$$$.\nIn the fifth test case of the example, you can shift the segment $$$[1; 2]$$$ to the right. After all moves, the books form the contiguous segment $$$[2; 5]$$$. So the answer is $$$1$$$.", "input": [ [ [ "7" ], [ "0", "0", "1", "0", "1", "0", "1" ] ], [ [ "3" ], [ "1", "0", "0" ] ], [ [ "5" ], [ "1", "1", "0", "0", "1" ] ], [ [ "6" ], [ "1", "0", "0", "0", "0", "1" ] ], [ [ "5" ], [ "1", "1", "0", "1", "1" ] ] ], "output": [ "2", "0", "2", "4", "1" ] }, { "problem_id": "1433A", "problem_name": "Boring Apartments\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1433/A", "problem_solution_link": "https://codeforces.com/problemset/status/1433/problem/A", "problem_statement": "A. Boring Apartments\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a building consisting of $$$10~000$$$ apartments numbered from $$$1$$$ to $$$10~000$$$, inclusive.\nCall an apartment\nboring\n, if its number consists of\nthe same digit\n. Examples of boring apartments are $$$11, 2, 777, 9999$$$ and so on.\nOur character is a troublemaker, and he calls the intercoms of all\nboring\napartments, till someone answers the call, in the following order:\nFirst he calls all apartments consisting of digit $$$1$$$, in increasing order ($$$1, 11, 111, 1111$$$).\nNext he calls all apartments consisting of digit $$$2$$$, in increasing order ($$$2, 22, 222, 2222$$$)\nAnd so on.\nThe resident of the boring apartment $$$x$$$ answers the call, and our character\nstops\ncalling anyone further.\nOur character wants to know how many digits he pressed in total and your task is to help him to count the total number of keypresses.\nFor example, if the resident of boring apartment $$$22$$$ answered, then our character called apartments with numbers $$$1, 11, 111, 1111, 2, 22$$$ and the total number of digits he pressed is $$$1 + 2 + 3 + 4 + 1 + 2 = 13$$$.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 36$$$) \u2014 the number of test cases.\nThe only line of the test case contains one integer $$$x$$$ ($$$1 \\le x \\le 9999$$$) \u2014 the apartment number of the resident who answered the call. It is guaranteed that $$$x$$$ consists of the same digit.\nOutput\nFor each test case, print the answer: how many digits our character pressed in total.\nExample\nInput\n4\n22\n9999\n1\n777\nOutput\n13\n90\n1\n66", "input": [ [ [ "22" ] ], [ [ "9999" ] ], [ [ "1" ] ], [ [ "777" ] ] ], "output": [ "13", "90", "1", "66" ] }, { "problem_id": "1431A", "problem_name": "Selling Hamburgers\n*special problem", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1431/A", "problem_solution_link": "https://codeforces.com/problemset/status/1431/problem/A", "problem_statement": "A. Selling Hamburgers\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ customers in the cafeteria. Each of them wants to buy a hamburger. The $$$i$$$-th customer has $$$a_i$$$ coins, and they will buy a hamburger if it costs at most $$$a_i$$$ coins.\nSuppose the cost of the hamburger is $$$m$$$. Then the number of coins the cafeteria earns is $$$m$$$ multiplied by the number of people who buy a hamburger if it costs $$$m$$$. Your task is to calculate the maximum number of coins the cafeteria can earn.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases.\nEach test case consists of two lines. The first line contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the number of customers.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\le a_i \\le 10^{12}$$$), where $$$a_i$$$ is the number of coins the $$$i$$$-th customer has.\nOutput\nFor each test case, print one integer \u2014 the maximum number of coins the cafeteria can earn.\nExample\nInput\n6\n3\n1 1 1\n3\n4 1 1\n3\n2 4 2\n8\n1 2 3 4 5 6 7 8\n1\n1000000000000\n3\n1000000000000 999999999999 1\nOutput\n3\n4\n6\n20\n1000000000000\n1999999999998\nNote\nExplanations for the test cases of the example:\nthe best price for the hamburger is $$$m = 1$$$, so $$$3$$$ hamburgers are bought, and the cafeteria earns $$$3$$$ coins;\nthe best price for the hamburger is $$$m = 4$$$, so $$$1$$$ hamburger is bought, and the cafeteria earns $$$4$$$ coins;\nthe best price for the hamburger is $$$m = 2$$$, so $$$3$$$ hamburgers are bought, and the cafeteria earns $$$6$$$ coins;\nthe best price for the hamburger is $$$m = 4$$$, so $$$5$$$ hamburgers are bought, and the cafeteria earns $$$20$$$ coins;\nthe best price for the hamburger is $$$m = 10^{12}$$$, so $$$1$$$ hamburger is bought, and the cafeteria earns $$$10^{12}$$$ coins;\nthe best price for the hamburger is $$$m = 10^{12} - 1$$$, so $$$2$$$ hamburgers are bought, and the cafeteria earns $$$2 \\cdot 10^{12} - 2$$$ coins.", "input": [ [ [ "3" ], [ "1", "1", "1" ] ], [ [ "3" ], [ "4", "1", "1" ] ], [ [ "3" ], [ "2", "4", "2" ] ], [ [ "8" ], [ "1", "2", "3", "4", "5", "6", "7", "8" ] ], [ [ "1" ], [ "1000000000000" ] ], [ [ "3" ], [ "1000000000000", "999999999999", "1" ] ] ], "output": [ "3", "4", "6", "20", "1000000000000", "1999999999998" ] }, { "problem_id": "1430B", "problem_name": "Barrels\ngreedy, implementation, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1430/B", "problem_solution_link": "https://codeforces.com/problemset/status/1430/problem/B", "problem_statement": "B. Barrels\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have $$$n$$$ barrels lined up in a row, numbered from left to right from one. Initially, the $$$i$$$-th barrel contains $$$a_i$$$ liters of water.\nYou can pour water from one barrel to another. In one act of pouring, you can choose two different barrels $$$x$$$ and $$$y$$$ (the $$$x$$$-th barrel shouldn't be empty) and pour any possible amount of water from barrel $$$x$$$ to barrel $$$y$$$ (possibly, all water). You may assume that barrels have infinite capacity, so you can pour any amount of water in each of them.\nCalculate the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water\nat most\n$$$k$$$ times.\nSome examples:\nif you have four barrels, each containing $$$5$$$ liters of water, and $$$k = 1$$$, you may pour $$$5$$$ liters from the second barrel into the fourth, so the amounts of water in the barrels are $$$[5, 0, 5, 10]$$$, and the difference between the maximum and the minimum is $$$10$$$;\nif all barrels are empty, you can't make any operation, so the difference between the maximum and the minimum amount is still $$$0$$$.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k < n \\le 2 \\cdot 10^5$$$)\u00a0\u2014 the number of barrels and the number of pourings you can make.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$0 \\le a_i \\le 10^{9}$$$), where $$$a_i$$$ is the initial amount of water the $$$i$$$-th barrel has.\nIt's guaranteed that the total sum of $$$n$$$ over test cases doesn't exceed $$$2 \\cdot 10^5$$$.\nOutput\nFor each test case, print the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water\nat most\n$$$k$$$ times.\nExample\nInput\n2\n4 1\n5 5 5 5\n3 2\n0 0 0\nOutput\n10\n0", "input": [ [ [ "4", "1" ], [ "5", "5", "5", "5" ] ], [ [ "3", "2" ], [ "0", "0", "0" ] ] ], "output": [ "10", "0" ] }, { "problem_id": "1428A", "problem_name": "Box is Pull\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1428/A", "problem_solution_link": "https://codeforces.com/problemset/status/1428/problem/A", "problem_statement": "A. Box is Pull\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nWabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point $$$(x_1,y_1)$$$ to the point $$$(x_2,y_2)$$$.\nHe has a rope, which he can use to pull the box. He can only pull the box if he stands\nexactly\n$$$1$$$ unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by $$$1$$$ unit.\nFor example, if the box is at the point $$$(1,2)$$$ and Wabbit is standing at the point $$$(2,2)$$$, he can pull the box right by $$$1$$$ unit, with the box ending up at the point $$$(2,2)$$$ and Wabbit ending at the point $$$(3,2)$$$.\nAlso, Wabbit can move $$$1$$$ unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly $$$1$$$ unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.\nWabbit can start at any point. It takes $$$1$$$ second to travel $$$1$$$ unit right, left, up, or down, regardless of whether he pulls the box while moving.\nDetermine the minimum amount of time he needs to move the box from $$$(x_1,y_1)$$$ to $$$(x_2,y_2)$$$. Note that the point where Wabbit ends up at does not matter.\nInput\nEach test contains multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \\leq t \\leq 1000)$$$: the number of test cases. The description of the test cases follows.\nEach of the next $$$t$$$ lines contains four space-separated integers $$$x_1, y_1, x_2, y_2$$$ $$$(1 \\leq x_1, y_1, x_2, y_2 \\leq 10^9)$$$, describing the next test case.\nOutput\nFor each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from $$$(x_1,y_1)$$$ to $$$(x_2,y_2)$$$.\nExample\nInput\n2\n1 2 2 2\n1 1 2 2\nOutput\n1\n4\nNote\nIn the first test case, the starting and the ending points of the box are $$$(1,2)$$$ and $$$(2,2)$$$ respectively. This is the same as the picture in the statement. Wabbit needs only $$$1$$$ second to move as shown in the picture in the statement.\nIn the second test case, Wabbit can start at the point $$$(2,1)$$$. He pulls the box to $$$(2,1)$$$ while moving to $$$(3,1)$$$. He then moves to $$$(3,2)$$$ and then to $$$(2,2)$$$ without pulling the box. Then, he pulls the box to $$$(2,2)$$$ while moving to $$$(2,3)$$$. It takes $$$4$$$ seconds.", "input": [ [ [ "1", "2", "2", "2" ] ], [ [ "1", "1", "2", "2" ] ] ], "output": [ "1", "4" ] }, { "problem_id": "1426A", "problem_name": "Floor Number\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1426/A", "problem_solution_link": "https://codeforces.com/problemset/status/1426/problem/A", "problem_statement": "A. Floor Number\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nVasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is $$$n$$$.\nThere is only one entrance in Petya's house and the distribution of apartments is the following: the first floor contains $$$2$$$ apartments, every other floor contains $$$x$$$ apartments each. Apartments are numbered starting from one, from the first floor. I.e. apartments on the first floor have numbers $$$1$$$ and $$$2$$$, apartments on the second floor have numbers from $$$3$$$ to $$$(x + 2)$$$, apartments on the third floor have numbers from $$$(x + 3)$$$ to $$$(2 \\cdot x + 2)$$$, and so on.\nYour task is to find the number of floor on which Petya lives. Assume that the house is always high enough to fit at least $$$n$$$ apartments.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe only line of the test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \\le n, x \\le 1000$$$) \u2014 the number of Petya's apartment and the number of apartments on each floor of the house except the first one (there are two apartments on the first floor).\nOutput\nFor each test case, print the answer: the number of floor on which Petya lives.\nExample\nInput\n4\n7 3\n1 5\n22 5\n987 13\nOutput\n3\n1\n5\n77\nNote\nConsider the first test case of the example: the first floor contains apartments with numbers $$$1$$$ and $$$2$$$, the second one contains apartments with numbers $$$3$$$, $$$4$$$ and $$$5$$$, the third one contains apartments with numbers $$$6$$$, $$$7$$$ and $$$8$$$. Therefore, Petya lives on the third floor.\nIn the second test case of the example, Petya lives in the apartment $$$1$$$ which is on the first floor.", "input": [ [ [ "7", "3" ] ], [ [ "1", "5" ] ], [ [ "22", "5" ] ], [ [ "987", "13" ] ] ], "output": [ "3", "1", "5", "77" ] }, { "problem_id": "1422A", "problem_name": "Fence\ngeometry, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1422/A", "problem_solution_link": "https://codeforces.com/problemset/status/1422/problem/A", "problem_statement": "A. Fence\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.\nA non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.\nInput\nThe first line contains a single integer $$$t$$$\u00a0\u2014 the number of test cases ($$$1 \\le t \\le 1000$$$). The next $$$t$$$ lines describe the test cases.\nEach line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$\u00a0\u2014 the lengths of the three fence segments ($$$1 \\le a, b, c \\le 10^9$$$).\nOutput\nFor each test case print a single integer $$$d$$$\u00a0\u2014 the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.\nExample\nInput\n2\n1 2 3\n12 34 56\nOutput\n4\n42\nNote\nWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.\nWe can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.", "input": [ [ [ "1", "2", "3" ] ], [ [ "12", "34", "56" ] ] ], "output": [ "4", "42" ] }, { "problem_id": "1421A", "problem_name": "XORwice\nbitmasks, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1421/A", "problem_solution_link": "https://codeforces.com/problemset/status/1421/problem/A", "problem_statement": "A. XORwice\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIn order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.\nTzuyu gave Sana two integers $$$a$$$ and $$$b$$$ and a really important quest.\nIn order to complete the quest, Sana has to output the smallest possible value of ($$$a \\oplus x$$$) + ($$$b \\oplus x$$$) for any given $$$x$$$, where $$$\\oplus$$$ denotes the\nbitwise XOR operation\n.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^{4}$$$). Description of the test cases follows.\nThe only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le 10^{9}$$$).\nOutput\nFor each testcase, output the smallest possible value of the given expression.\nExample\nInput\n6\n6 12\n4 9\n59 832\n28 14\n4925 2912\n1 1\nOutput\n10\n13\n891\n18\n6237\n0\nNote\nFor the first test case Sana can choose $$$x=4$$$ and the value will be ($$$6 \\oplus 4$$$) + ($$$12 \\oplus 4$$$) = $$$2 + 8$$$ = $$$10$$$. It can be shown that this is the smallest possible value.", "input": [ [ [ "6", "12" ] ], [ [ "4", "9" ] ], [ [ "59", "832" ] ], [ [ "28", "14" ] ], [ [ "4925", "2912" ] ], [ [ "1", "1" ] ] ], "output": [ "10", "13", "891", "18", "6237", "0" ] }, { "problem_id": "1417A", "problem_name": "Copy-paste\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1417/A", "problem_solution_link": "https://codeforces.com/problemset/status/1417/problem/A", "problem_statement": "A. Copy-paste\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\n\u2014 Hey folks, how do you like this problem?\n\u2014 That'll do it.\nBThero\nis a powerful magician. He has got $$$n$$$ piles of candies, the $$$i$$$-th pile initially contains $$$a_i$$$ candies.\nBThero\ncan cast a\ncopy-paste\nspell as follows:\nHe chooses two piles $$$(i, j)$$$ such that $$$1 \\le i, j \\le n$$$ and $$$i \\ne j$$$.\nAll candies from pile $$$i$$$ are copied into pile $$$j$$$. Formally, the operation $$$a_j := a_j + a_i$$$ is performed.\nBThero\ncan cast this spell any number of times he wants to \u2014 but unfortunately, if some pile contains strictly more than $$$k$$$ candies, he loses his magic power. What is the maximum number of times\nBThero\ncan cast the spell without losing his power?\nInput\nThe first line contains one integer $$$T$$$ ($$$1 \\le T \\le 500$$$) \u2014 the number of test cases.\nEach test case consists of two lines:\nthe first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\le n \\le 1000$$$, $$$2 \\le k \\le 10^4$$$);\nthe second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \\le a_i \\le k$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$, and the sum of $$$k$$$ over all test cases does not exceed $$$10^4$$$.\nOutput\nFor each test case, print one integer \u2014 the maximum number of times\nBThero\ncan cast the spell without losing his magic power.\nExample\nInput\n3\n2 2\n1 1\n3 5\n1 2 3\n3 7\n3 2 2\nOutput\n1\n5\n4\nNote\nIn the first test case we get either $$$a = [1, 2]$$$ or $$$a = [2, 1]$$$ after casting the spell for the first time, and it is impossible to cast it again.", "input": [ [ [ "2", "2" ], [ "1", "1" ] ], [ [ "3", "5" ], [ "1", "2", "3" ] ], [ [ "3", "7" ], [ "3", "2", "2" ] ] ], "output": [ "1", "5", "4" ] }, { "problem_id": "1415A", "problem_name": "Prison Break\nbrute force, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1415/A", "problem_solution_link": "https://codeforces.com/problemset/status/1415/problem/A", "problem_statement": "A. Prison Break\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere is a prison that can be represented as a rectangular matrix with $$$n$$$ rows and $$$m$$$ columns. Therefore, there are $$$n \\cdot m$$$ prison cells. There are also $$$n \\cdot m$$$ prisoners, one in each prison cell. Let's denote the cell in the $$$i$$$-th row and the $$$j$$$-th column as $$$(i, j)$$$.\nThere's a secret tunnel in the cell $$$(r, c)$$$, that the prisoners will use to escape! However, to avoid the risk of getting caught, they will escape at night.\nBefore the night, every prisoner is in his own cell. When night comes, they can start moving to adjacent cells. Formally, in one second, a prisoner located in cell $$$(i, j)$$$ can move to cells $$$( i - 1 , j )$$$ , $$$( i + 1 , j )$$$ , $$$( i , j - 1 )$$$ , or $$$( i , j + 1 )$$$, as long as the target cell is inside the prison. They can also choose to stay in cell $$$(i, j)$$$.\nThe prisoners want to know the minimum number of seconds needed so that every prisoner can arrive to cell $$$( r , c )$$$ if they move optimally. Note that there can be any number of prisoners in the same cell at the same time.\nInput\nThe first line contains an integer $$$t$$$ $$$(1 \\le t \\le 10^4)$$$, the number of test cases.\nEach of the next $$$t$$$ lines contains four space-separated integers $$$n$$$, $$$m$$$, $$$r$$$, $$$c$$$ ($$$1 \\le r \\le n \\le 10^9$$$, $$$1 \\le c \\le m \\le 10^9$$$).\nOutput\nPrint $$$t$$$ lines, the answers for each test case.\nExample\nInput\n3\n10 10 1 1\n3 5 2 4\n10 2 5 1\nOutput\n18\n4\n6", "input": [ [ [ "10", "10", "1", "1" ] ], [ [ "3", "5", "2", "4" ] ], [ [ "10", "2", "5", "1" ] ] ], "output": [ "18", "4", "6" ] }, { "problem_id": "1413A", "problem_name": "Finding Sasuke\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1413/A", "problem_solution_link": "https://codeforces.com/problemset/status/1413/problem/A", "problem_statement": "A. Finding Sasuke\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nNaruto has sneaked into the Orochimaru's lair and is now looking for Sasuke. There are $$$T$$$ rooms there. Every room has a door into it, each door can be described by the number $$$n$$$ of seals on it and their integer energies $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$. All energies $$$a_i$$$ are\nnonzero\nand do not exceed $$$100$$$ by absolute value. Also,\n$$$n$$$ is even\n.\nIn order to open a door, Naruto must find such $$$n$$$ seals with integer energies $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ that the following equality holds: $$$a_{1} \\cdot b_{1} + a_{2} \\cdot b_{2} + ... + a_{n} \\cdot b_{n} = 0$$$. All $$$b_i$$$ must\nbe nonzero\nas well as $$$a_i$$$ are, and also\nmust not exceed $$$100$$$\nby absolute value. Please find required seals for every room there.\nInput\nThe first line contains the only integer $$$T$$$ ($$$1 \\leq T \\leq 1000$$$) standing for the number of rooms in the Orochimaru's lair. The other lines contain descriptions of the doors.\nEach description starts with the line containing the only even integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$) denoting the number of seals.\nThe following line contains the space separated sequence of nonzero integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$|a_{i}| \\leq 100$$$, $$$a_{i} \\neq 0$$$) denoting the energies of seals.\nOutput\nFor each door print a space separated sequence of nonzero integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$|b_{i}| \\leq 100$$$, $$$b_{i} \\neq 0$$$) denoting the seals that can open the door. If there are multiple valid answers, print any. It can be proven that at least one answer always exists.\nExample\nInput\n2\n2\n1 100\n4\n1 2 3 6\nOutput\n-100 1\n1 1 1 -1\nNote\nFor the first door Naruto can use energies $$$[-100, 1]$$$. The required equality does indeed hold: $$$1 \\cdot (-100) + 100 \\cdot 1 = 0$$$.\nFor the second door Naruto can use, for example, energies $$$[1, 1, 1, -1]$$$. The required equality also holds: $$$1 \\cdot 1 + 2 \\cdot 1 + 3 \\cdot 1 + 6 \\cdot (-1) = 0$$$.", "input": [ [ [ "2" ], [ "1", "100" ] ], [ [ "4" ], [ "1", "2", "3", "6" ] ] ], "output": [ "-100 1", "1 1 1 -1" ] }, { "problem_id": "1411A", "problem_name": "In-game Chat\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1411/A", "problem_solution_link": "https://codeforces.com/problemset/status/1411/problem/A", "problem_statement": "A. In-game Chat\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have been assigned to develop a filter for bad messages in the in-game chat. A message is a string $$$S$$$ of length $$$n$$$, consisting of lowercase English letters and characters '\n)\n'. The message is\nbad\nif the number of characters '\n)\n' at the end of the string strictly greater than the number of remaining characters. For example, the string \"\n)bc)))\n\" has three parentheses at the end, three remaining characters, and is not considered bad.\nInput\nThe first line contains the number of test cases $$$t$$$ ($$$1 \\leq t \\leq 100$$$). Description of the $$$t$$$ test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$). The second line of each test case contains a string $$$S$$$ of length $$$n$$$, consisting of lowercase English letters and characters '\n)\n'.\nOutput\nFor each of $$$t$$$ test cases, print \"\nYes\n\" if the string is bad. Otherwise, print \"\nNo\n\".\nYou can print each letter in any case (upper or lower).\nExample\nInput\n5\n2\n))\n12\ngl))hf))))))\n9\ngege)))))\n14\n)aa))b))))))))\n1\n)\nOutput\nYes\nNo\nYes\nYes\nYes", "input": [ [ [ "2" ], [ "))" ] ], [ [ "12" ], [ "gl))hf))))))" ] ], [ [ "9" ], [ "gege)))))" ] ], [ [ "14" ], [ ")aa))b))))))))" ] ], [ [ "1" ], [ ")" ] ] ], "output": [ "Yes", "No", "Yes", "Yes", "Yes" ] }, { "problem_id": "1409A", "problem_name": "Yet Another Two Integers Problem\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1409/A", "problem_solution_link": "https://codeforces.com/problemset/status/1409/problem/A", "problem_statement": "A. Yet Another Two Integers Problem\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two integers $$$a$$$ and $$$b$$$.\nIn one move, you can choose some\ninteger\n$$$k$$$ from $$$1$$$ to $$$10$$$ and add it to $$$a$$$ or subtract it from $$$a$$$. In other words, you choose an integer $$$k \\in [1; 10]$$$ and perform $$$a := a + k$$$ or $$$a := a - k$$$. You may use\ndifferent\nvalues of $$$k$$$ in different moves.\nYour task is to find the\nminimum\nnumber of moves required to obtain $$$b$$$ from $$$a$$$.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 2 \\cdot 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe only line of the test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le 10^9$$$).\nOutput\nFor each test case, print the answer: the minimum number of moves required to obtain $$$b$$$ from $$$a$$$.\nExample\nInput\n6\n5 5\n13 42\n18 4\n1337 420\n123456789 1000000000\n100500 9000\nOutput\n0\n3\n2\n92\n87654322\n9150\nNote\nIn the first test case of the example, you don't need to do anything.\nIn the second test case of the example, the following sequence of moves can be applied: $$$13 \\rightarrow 23 \\rightarrow 32 \\rightarrow 42$$$ (add $$$10$$$, add $$$9$$$, add $$$10$$$).\nIn the third test case of the example, the following sequence of moves can be applied: $$$18 \\rightarrow 10 \\rightarrow 4$$$ (subtract $$$8$$$, subtract $$$6$$$).", "input": [ [ [ "5", "5" ] ], [ [ "13", "42" ] ], [ [ "18", "4" ] ], [ [ "1337", "420" ] ], [ [ "123456789", "1000000000" ] ], [ [ "100500", "9000" ] ] ], "output": [ "0", "3", "2", "92", "87654322", "9150" ] }, { "problem_id": "1408A", "problem_name": "Circle Coloring\nconstructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1408/A", "problem_solution_link": "https://codeforces.com/problemset/status/1408/problem/A", "problem_statement": "A. Circle Coloring\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given three sequences: $$$a_1, a_2, \\ldots, a_n$$$; $$$b_1, b_2, \\ldots, b_n$$$; $$$c_1, c_2, \\ldots, c_n$$$.\nFor each $$$i$$$, $$$a_i \\neq b_i$$$, $$$a_i \\neq c_i$$$, $$$b_i \\neq c_i$$$.\nFind a sequence $$$p_1, p_2, \\ldots, p_n$$$, that satisfy the following conditions:\n$$$p_i \\in \\{a_i, b_i, c_i\\}$$$\n$$$p_i \\neq p_{(i \\mod n) + 1}$$$.\nIn other words, for each element, you need to choose one of the three possible values, such that no two adjacent elements (where we consider elements $$$i,i+1$$$ adjacent for $$$i 1000$$$.", "input": [ [ [ "5" ] ], [ [ "4" ] ] ], "output": [ "1 5 3 77 12", "384 384 44 44" ] }, { "problem_id": "1371A", "problem_name": "Magical Sticks\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1371/A", "problem_solution_link": "https://codeforces.com/problemset/status/1371/problem/A", "problem_statement": "A. Magical Sticks\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA penguin Rocher has $$$n$$$ sticks. He has exactly one stick with length $$$i$$$ for all $$$1 \\le i \\le n$$$.\nHe can connect some sticks. If he connects two sticks that have lengths $$$a$$$ and $$$b$$$, he gets one stick with length $$$a + b$$$. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his set and can be used for the next connections.\nHe wants to create the maximum number of sticks that have the same length. It is not necessary to make all sticks have the same length, some sticks can have the other length. How many sticks with the equal length he can create?\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases. Next $$$t$$$ lines contain descriptions of test cases.\nFor each test case, the only line contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^{9}$$$).\nOutput\nFor each test case, print a single integer \u00a0\u2014 the answer to the problem.\nExample\nInput\n4\n1\n2\n3\n4\nOutput\n1\n1\n2\n2\nNote\nIn the third case, he can connect two sticks with lengths $$$1$$$ and $$$2$$$ and he will get one stick with length $$$3$$$. So, he will have two sticks with lengths $$$3$$$.\nIn the fourth case, he can connect two sticks with lengths $$$1$$$ and $$$3$$$ and he will get one stick with length $$$4$$$. After that, he will have three sticks with lengths $$$\\{2, 4, 4\\}$$$, so two sticks have the same length, and one stick has the other length.", "input": [ [ [ "1" ] ], [ [ "2" ] ], [ [ "3" ] ], [ [ "4" ] ] ], "output": [ "1", "1", "2", "2" ] }, { "problem_id": "1370A", "problem_name": "Maximum GCD\ngreedy, implementation, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1370/A", "problem_solution_link": "https://codeforces.com/problemset/status/1370/problem/A", "problem_statement": "A. Maximum GCD\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's consider all integers in the range from $$$1$$$ to $$$n$$$ (inclusive).\nAmong all pairs of\ndistinct\nintegers in this range, find the maximum possible greatest common divisor of integers in pair. Formally, find the maximum value of $$$\\mathrm{gcd}(a, b)$$$, where $$$1 \\leq a < b \\leq n$$$.\nThe greatest common divisor, $$$\\mathrm{gcd}(a, b)$$$, of two positive integers $$$a$$$ and $$$b$$$ is the biggest integer that is a divisor of both $$$a$$$ and $$$b$$$.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe only line of each test case contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 10^6$$$).\nOutput\nFor each test case, output the maximum value of $$$\\mathrm{gcd}(a, b)$$$ among all $$$1 \\leq a < b \\leq n$$$.\nExample\nInput\n2\n3\n5\nOutput\n1\n2\nNote\nIn the first test case, $$$\\mathrm{gcd}(1, 2) = \\mathrm{gcd}(2, 3) = \\mathrm{gcd}(1, 3) = 1$$$.\nIn the second test case, $$$2$$$ is the maximum possible value, corresponding to $$$\\mathrm{gcd}(2, 4)$$$.", "input": [ [ [ "3" ] ], [ [ "5" ] ] ], "output": [ "1", "2" ] }, { "problem_id": "1369A", "problem_name": "FashionabLee\ngeometry, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1369/A", "problem_solution_link": "https://codeforces.com/problemset/status/1369/problem/A", "problem_statement": "A. FashionabLee\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLee is going to fashionably decorate his house for a party, using some regular convex polygons...\nLee thinks a regular $$$n$$$-sided (convex) polygon is\nbeautiful\nif and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.\nRecall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.\nNow he is shopping: the market has $$$t$$$ regular polygons. For each of them print\nYES\nif it is beautiful and\nNO\notherwise.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of polygons in the market.\nEach of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \\le n_i \\le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.\nOutput\nFor each polygon, print\nYES\nif it's beautiful or\nNO\notherwise (case insensitive).\nExample\nInput\n4\n3\n4\n12\n1000000000\nOutput\nNO\nYES\nYES\nYES\nNote\nIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.", "input": [ [ [ "3" ] ], [ [ "4" ] ], [ [ "12" ] ], [ [ "1000000000" ] ] ], "output": [ "NO", "YES", "YES", "YES" ] }, { "problem_id": "1368A", "problem_name": "C+=\nbrute force, greedy, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1368/A", "problem_solution_link": "https://codeforces.com/problemset/status/1368/problem/A", "problem_statement": "A. C+=\ntime limit per test\n2 seconds\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nLeo has developed a new programming language C+=. In C+=, integer variables can only be changed with a \"\n+=\n\" operation that adds the right-hand side value to the left-hand side variable. For example, performing \"\na += b\n\" when\na =\n$$$2$$$,\nb =\n$$$3$$$ changes the value of\na\nto $$$5$$$ (the value of\nb\ndoes not change).\nIn a prototype program Leo has two integer variables\na\nand\nb\n, initialized with some positive values. He can perform any number of operations \"\na += b\n\" or \"\nb += a\n\". Leo wants to test handling large integers, so he wants to make the value of either\na\nor\nb\nstrictly greater\nthan a given value $$$n$$$. What is the smallest number of operations he has to perform?\nInput\nThe first line contains a single integer $$$T$$$ ($$$1 \\leq T \\leq 100$$$)\u00a0\u2014 the number of test cases.\nEach of the following $$$T$$$ lines describes a single test case, and contains three integers $$$a, b, n$$$ ($$$1 \\leq a, b \\leq n \\leq 10^9$$$)\u00a0\u2014 initial values of\na\nand\nb\n, and the value one of the variables has to exceed, respectively.\nOutput\nFor each test case print a single integer\u00a0\u2014 the smallest number of operations needed. Separate answers with line breaks.\nExample\nInput\n2\n1 2 3\n5 4 100\nOutput\n2\n7\nNote\nIn the first case we cannot make a variable exceed $$$3$$$ in one operation. One way of achieving this in two operations is to perform \"\nb += a\n\" twice.", "input": [ [ [ "1", "2", "3" ] ], [ [ "5", "4", "100" ] ] ], "output": [ "2", "7" ] }, { "problem_id": "1367B", "problem_name": "Even Array\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1367/B", "problem_solution_link": "https://codeforces.com/problemset/status/1367/problem/B", "problem_statement": "B. Even Array\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a[0 \\ldots n-1]$$$ of length $$$n$$$ which consists of non-negative integers.\nNote that array indices start from zero.\nAn array is called\ngood\nif the parity of each index matches the parity of the element at that index. More formally, an array is good if for all $$$i$$$ ($$$0 \\le i \\le n - 1$$$) the equality $$$i \\bmod 2 = a[i] \\bmod 2$$$ holds, where $$$x \\bmod 2$$$ is the remainder of dividing $$$x$$$ by 2.\nFor example, the arrays [$$$0, 5, 2, 1$$$] and [$$$0, 17, 0, 3$$$] are good, and the array [$$$2, 4, 6, 7$$$] is bad, because for $$$i=1$$$, the parities of $$$i$$$ and $$$a[i]$$$ are different: $$$i \\bmod 2 = 1 \\bmod 2 = 1$$$, but $$$a[i] \\bmod 2 = 4 \\bmod 2 = 0$$$.\nIn one move, you can take\nany\ntwo elements of the array and swap them (these elements are not necessarily adjacent).\nFind the minimum number of moves in which you can make the array $$$a$$$ good, or say that this is not possible.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases in the test. Then $$$t$$$ test cases follow.\nEach test case starts with a line containing an integer $$$n$$$ ($$$1 \\le n \\le 40$$$)\u00a0\u2014 the length of the array $$$a$$$.\nThe next line contains $$$n$$$ integers $$$a_0, a_1, \\ldots, a_{n-1}$$$ ($$$0 \\le a_i \\le 1000$$$)\u00a0\u2014 the initial array.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the minimum number of moves to make the given array $$$a$$$ good, or\n-1\nif this is not possible.\nExample\nInput\n4\n4\n3 2 7 6\n3\n3 2 6\n1\n7\n7\n4 9 2 1 18 3 0\nOutput\n2\n1\n-1\n0\nNote\nIn the first test case, in the first move, you can swap the elements with indices $$$0$$$ and $$$1$$$, and in the second move, you can swap the elements with indices $$$2$$$ and $$$3$$$.\nIn the second test case, in the first move, you need to swap the elements with indices $$$0$$$ and $$$1$$$.\nIn the third test case, you cannot make the array good.", "input": [ [ [ "4" ], [ "3", "2", "7", "6" ] ], [ [ "3" ], [ "3", "2", "6" ] ], [ [ "1" ], [ "7" ] ], [ [ "7" ], [ "4", "9", "2", "1", "18", "3", "0" ] ] ], "output": [ "2", "1", "-1", "0" ] }, { "problem_id": "1367A", "problem_name": "Short Substrings\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1367/A", "problem_solution_link": "https://codeforces.com/problemset/status/1367/problem/A", "problem_statement": "A. Short Substrings\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAlice guesses the strings that Bob made for her.\nAt first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.\nBob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.\nFor example, if Bob came up with the string $$$a$$$=\"\nabac\n\", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: \"\nab\n\", \"\nba\n\", \"\nac\n\". Therefore, the string $$$b$$$=\"\nabbaac\n\".\nYou are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.\nInput\nThe first line contains a single positive integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases in the test. Then $$$t$$$ test cases follow.\nEach test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \\le |b| \\le 100$$$)\u00a0\u2014 the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.\nOutput\nOutput $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.\nExample\nInput\n4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz\nOutput\nabac\nac\nbcdaf\nzzzzzz\nNote\nThe first test case is explained in the statement.\nIn the second test case, Bob came up with the string $$$a$$$=\"\nac\n\", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.\nIn the third test case, Bob came up with the string $$$a$$$=\"\nbcdaf\n\", substrings of length $$$2$$$ of string $$$a$$$ are: \"\nbc\n\", \"\ncd\n\", \"\nda\n\", \"\naf\n\", so the string $$$b$$$=\"\nbccddaaf\n\".", "input": [ [ [ "abbaac" ] ], [ [ "ac" ] ], [ [ "bccddaaf" ] ], [ [ "zzzzzzzzzz" ] ] ], "output": [ "abac", "ac", "bcdaf", "zzzzzz" ] }, { "problem_id": "1360B", "problem_name": "Honest Coach\ngreedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1360/B", "problem_solution_link": "https://codeforces.com/problemset/status/1360/problem/B", "problem_statement": "B. Honest Coach\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are $$$n$$$ athletes in front of you. Athletes are numbered from $$$1$$$ to $$$n$$$ from left to right. You know the strength of each athlete\u00a0\u2014 the athlete number $$$i$$$ has the strength $$$s_i$$$.\nYou want to split all athletes into two teams. Each team must have at least one athlete, and each athlete must be exactly in one team.\nYou want the strongest athlete from the first team to differ as little as possible from the weakest athlete from the second team. Formally, you want to split the athletes into two teams $$$A$$$ and $$$B$$$ so that the value $$$|\\max(A) - \\min(B)|$$$ is as small as possible, where $$$\\max(A)$$$ is the maximum strength of an athlete from team $$$A$$$, and $$$\\min(B)$$$ is the minimum strength of an athlete from team $$$B$$$.\nFor example, if $$$n=5$$$ and the strength of the athletes is $$$s=[3, 1, 2, 6, 4]$$$, then one of the possible split into teams is:\nfirst team: $$$A = [1, 2, 4]$$$,\nsecond team: $$$B = [3, 6]$$$.\nIn this case, the value $$$|\\max(A) - \\min(B)|$$$ will be equal to $$$|4-3|=1$$$. This example illustrates one of the ways of optimal split into two teams.\nPrint the minimum value $$$|\\max(A) - \\min(B)|$$$.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u00a0\u2014 the number of test cases in the input. Then $$$t$$$ test cases follow.\nEach test case consists of two lines.\nThe first line contains positive integer $$$n$$$ ($$$2 \\le n \\le 50$$$)\u00a0\u2014 number of athletes.\nThe second line contains $$$n$$$ positive integers $$$s_1, s_2, \\ldots, s_n$$$ ($$$1 \\le s_i \\le 1000$$$), where $$$s_i$$$\u00a0\u2014 is the strength of the $$$i$$$-th athlete. Please note that $$$s$$$ values may not be distinct.\nOutput\nFor each test case print one integer\u00a0\u2014 the minimum value of $$$|\\max(A) - \\min(B)|$$$ with the optimal split of all athletes into two teams. Each of the athletes must be a member of exactly one of the two teams.\nExample\nInput\n5\n5\n3 1 2 6 4\n6\n2 1 3 2 4 3\n4\n7 9 3 1\n2\n1 1000\n3\n100 150 200\nOutput\n1\n0\n2\n999\n50\nNote\nThe first test case was explained in the statement. In the second test case, one of the optimal splits is $$$A=[2, 1]$$$, $$$B=[3, 2, 4, 3]$$$, so the answer is $$$|2-2|=0$$$.", "input": [ [ [ "5" ], [ "3", "1", "2", "6", "4" ] ], [ [ "6" ], [ "2", "1", "3", "2", "4", "3" ] ], [ [ "4" ], [ "7", "9", "3", "1" ] ], [ [ "2" ], [ "1", "1000" ] ], [ [ "3" ], [ "100", "150", "200" ] ] ], "output": [ "1", "0", "2", "999", "50" ] }, { "problem_id": "1360A", "problem_name": "Minimal Square\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1360/A", "problem_solution_link": "https://codeforces.com/problemset/status/1360/problem/A", "problem_statement": "A. Minimal Square\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nFind the minimum area of a\nsquare\nland on which you can place two identical rectangular $$$a \\times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.\nFormally,\nYou are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le 100$$$)\u00a0\u2014 positive integers (you are given just the sizes, but\nnot\ntheir positions).\nFind the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square.\nTwo rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding.\nThe picture shows a square that contains red and green rectangles.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 10\\,000$$$)\u00a0\u2014the number of test cases in the input. Then $$$t$$$ test cases follow.\nEach test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \\le a, b \\le 100$$$)\u00a0\u2014 side lengths of the rectangles.\nOutput\nPrint $$$t$$$ answers to the test cases. Each answer must be a single integer\u00a0\u2014 minimal area of square land, that contains two rectangles with dimensions $$$a \\times b$$$.\nExample\nInput\n8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100\nOutput\n16\n16\n4\n9\n64\n9\n64\n40000\nNote\nBelow are the answers for the first two test cases:", "input": [ [ [ "3", "2" ] ], [ [ "4", "2" ] ], [ [ "1", "1" ] ], [ [ "3", "1" ] ], [ [ "4", "7" ] ], [ [ "1", "3" ] ], [ [ "7", "4" ] ], [ [ "100", "100" ] ] ], "output": [ "16", "16", "4", "9", "64", "9", "64", "40000" ] }, { "problem_id": "1358A", "problem_name": "Park Lighting\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1358/A", "problem_solution_link": "https://codeforces.com/problemset/status/1358/problem/A", "problem_statement": "A. Park Lighting\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nDue to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.\nThe park is a rectangular table with $$$n$$$ rows and $$$m$$$ columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length $$$1$$$. For example, park with $$$n=m=2$$$ has $$$12$$$ streets.\nYou were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).\nThe park sizes are: $$$n=4$$$, $$$m=5$$$. The lighted squares are marked yellow. Please note that all streets have length $$$1$$$. Lanterns are placed in the middle of the streets. In the picture\nnot all\nthe squares are lit.\nSemyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases in the input. Then $$$t$$$ test cases follow.\nEach test case is a line containing two integers $$$n$$$, $$$m$$$ ($$$1 \\le n, m \\le 10^4$$$) \u2014 park sizes.\nOutput\nPrint $$$t$$$ answers to the test cases. Each answer must be a single integer \u2014 the minimum number of lanterns that are required to light all the squares.\nExample\nInput\n5\n1 1\n1 3\n2 2\n3 3\n5 3\nOutput\n1\n2\n2\n5\n8\nNote\nPossible optimal arrangement of the lanterns for the $$$2$$$-nd test case of input data example:\nPossible optimal arrangement of the lanterns for the $$$3$$$-rd test case of input data example:", "input": [ [ [ "1", "1" ] ], [ [ "1", "3" ] ], [ [ "2", "2" ] ], [ [ "3", "3" ] ], [ [ "5", "3" ] ] ], "output": [ "1", "2", "2", "5", "8" ] }, { "problem_id": "1353B", "problem_name": "Two Arrays And Swaps\ngreedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1353/B", "problem_solution_link": "https://codeforces.com/problemset/status/1353/problem/B", "problem_statement": "B. Two Arrays And Swaps\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two arrays $$$a$$$ and $$$b$$$ both consisting of $$$n$$$ positive (greater than zero) integers. You are also given an integer $$$k$$$.\nIn one move, you can choose two indices $$$i$$$ and $$$j$$$ ($$$1 \\le i, j \\le n$$$) and swap $$$a_i$$$ and $$$b_j$$$ (i.e. $$$a_i$$$ becomes $$$b_j$$$ and vice versa). Note that $$$i$$$ and $$$j$$$ can be equal or different (in particular, swap $$$a_2$$$ with $$$b_2$$$ or swap $$$a_3$$$ and $$$b_9$$$ both are acceptable moves).\nYour task is to find the\nmaximum\npossible sum you can obtain in the array $$$a$$$ if you can do no more than (i.e. at most) $$$k$$$ such moves (swaps).\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 200$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe first line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 30; 0 \\le k \\le n$$$) \u2014 the number of elements in $$$a$$$ and $$$b$$$ and the maximum number of moves you can do. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 30$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. The third line of the test case contains $$$n$$$ integers $$$b_1, b_2, \\dots, b_n$$$ ($$$1 \\le b_i \\le 30$$$), where $$$b_i$$$ is the $$$i$$$-th element of $$$b$$$.\nOutput\nFor each test case, print the answer \u2014 the\nmaximum\npossible sum you can obtain in the array $$$a$$$ if you can do no more than (i.e. at most) $$$k$$$ swaps.\nExample\nInput\n5\n2 1\n1 2\n3 4\n5 5\n5 5 6 6 5\n1 2 5 4 3\n5 3\n1 2 3 4 5\n10 9 10 10 9\n4 0\n2 2 4 3\n2 4 2 3\n4 4\n1 2 2 1\n4 4 5 4\nOutput\n6\n27\n39\n11\n17\nNote\nIn the first test case of the example, you can swap $$$a_1 = 1$$$ and $$$b_2 = 4$$$, so $$$a=[4, 2]$$$ and $$$b=[3, 1]$$$.\nIn the second test case of the example, you don't need to swap anything.\nIn the third test case of the example, you can swap $$$a_1 = 1$$$ and $$$b_1 = 10$$$, $$$a_3 = 3$$$ and $$$b_3 = 10$$$ and $$$a_2 = 2$$$ and $$$b_4 = 10$$$, so $$$a=[10, 10, 10, 4, 5]$$$ and $$$b=[1, 9, 3, 2, 9]$$$.\nIn the fourth test case of the example, you cannot swap anything.\nIn the fifth test case of the example, you can swap arrays $$$a$$$ and $$$b$$$, so $$$a=[4, 4, 5, 4]$$$ and $$$b=[1, 2, 2, 1]$$$.", "input": [ [ [ "2", "1" ], [ "1", "2" ], [ "3", "4" ] ], [ [ "5", "5" ], [ "5", "5", "6", "6", "5" ], [ "1", "2", "5", "4", "3" ] ], [ [ "5", "3" ], [ "1", "2", "3", "4", "5" ], [ "10", "9", "10", "10", "9" ] ], [ [ "4", "0" ], [ "2", "2", "4", "3" ], [ "2", "4", "2", "3" ] ], [ [ "4", "4" ], [ "1", "2", "2", "1" ], [ "4", "4", "5", "4" ] ] ], "output": [ "6", "27", "39", "11", "17" ] }, { "problem_id": "1353A", "problem_name": "Most Unstable Array\nconstructive algorithms, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1353/A", "problem_solution_link": "https://codeforces.com/problemset/status/1353/problem/A", "problem_statement": "A. Most Unstable Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two integers $$$n$$$ and $$$m$$$. You have to construct the array $$$a$$$ of length $$$n$$$ consisting of\nnon-negative integers\n(i.e. integers greater than or equal to zero) such that the sum of elements of this array is\nexactly\n$$$m$$$ and the value $$$\\sum\\limits_{i=1}^{n-1} |a_i - a_{i+1}|$$$ is the maximum possible. Recall that $$$|x|$$$ is the absolute value of $$$x$$$.\nIn other words, you have to maximize the sum of absolute differences between adjacent (consecutive) elements. For example, if the array $$$a=[1, 3, 2, 5, 5, 0]$$$ then the value above for this array is $$$|1-3| + |3-2| + |2-5| + |5-5| + |5-0| = 2 + 1 + 3 + 0 + 5 = 11$$$. Note that this example\ndoesn't show the optimal answer\nbut it shows how the required value for some array is calculated.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe only line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 10^9$$$) \u2014 the length of the array and its sum correspondingly.\nOutput\nFor each test case, print the answer \u2014 the maximum possible value of $$$\\sum\\limits_{i=1}^{n-1} |a_i - a_{i+1}|$$$ for the array $$$a$$$ consisting of $$$n$$$ non-negative integers with the sum $$$m$$$.\nExample\nInput\n5\n1 100\n2 2\n5 5\n2 1000000000\n1000000000 1000000000\nOutput\n0\n2\n10\n1000000000\n2000000000\nNote\nIn the first test case of the example, the only possible array is $$$[100]$$$ and the answer is obviously $$$0$$$.\nIn the second test case of the example, one of the possible arrays is $$$[2, 0]$$$ and the answer is $$$|2-0| = 2$$$.\nIn the third test case of the example, one of the possible arrays is $$$[0, 2, 0, 3, 0]$$$ and the answer is $$$|0-2| + |2-0| + |0-3| + |3-0| = 10$$$.", "input": [ [ [ "1", "100" ] ], [ [ "2", "2" ] ], [ [ "5", "5" ] ], [ [ "2", "1000000000" ] ], [ [ "1000000000", "1000000000" ] ] ], "output": [ "0", "2", "10", "1000000000", "2000000000" ] }, { "problem_id": "1352A", "problem_name": "Sum of Round Numbers\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1352/A", "problem_solution_link": "https://codeforces.com/problemset/status/1352/problem/A", "problem_statement": "A. Sum of Round Numbers\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA positive (strictly greater than zero) integer is called\nround\nif it is of the form\nd00...0\n. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from $$$1$$$ to $$$9$$$ (inclusive) are round.\nFor example, the following numbers are round: $$$4000$$$, $$$1$$$, $$$9$$$, $$$800$$$, $$$90$$$. The following numbers are\nnot\nround: $$$110$$$, $$$707$$$, $$$222$$$, $$$1001$$$.\nYou are given a positive integer $$$n$$$ ($$$1 \\le n \\le 10^4$$$). Represent the number $$$n$$$ as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number $$$n$$$ as a sum of the least number of terms, each of which is a round number.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases in the input. Then $$$t$$$ test cases follow.\nEach test case is a line containing an integer $$$n$$$ ($$$1 \\le n \\le 10^4$$$).\nOutput\nPrint $$$t$$$ answers to the test cases. Each answer must begin with an integer $$$k$$$ \u2014 the minimum number of summands. Next, $$$k$$$ terms must follow, each of which is a round number, and their sum is $$$n$$$. The terms can be printed in any order. If there are several answers, print any of them.\nExample\nInput\n5\n5009\n7\n9876\n10000\n10\nOutput\n2\n5000 9\n1\n7 \n4\n800 70 6 9000 \n1\n10000 \n1\n10", "input": [ [ [ "5009" ] ], [ [ "7" ] ], [ [ "9876" ] ], [ [ "10000" ] ], [ [ "10" ] ] ], "output": [ ["2", "5000 9"], ["1", "7"], ["4", "800 70 6 9000"], ["1", "10000"], ["1", "10"] ], "error": true }, { "problem_id": "1351A", "problem_name": "A+B (Trial Problem)\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1351/A", "problem_solution_link": "https://codeforces.com/problemset/status/1351/problem/A", "problem_statement": "A. A+B (Trial Problem)\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two integers $$$a$$$ and $$$b$$$. Print $$$a+b$$$.\nInput\nThe first line contains an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases in the input. Then $$$t$$$ test cases follow.\nEach test case is given as a line of two integers $$$a$$$ and $$$b$$$ ($$$-1000 \\le a, b \\le 1000$$$).\nOutput\nPrint $$$t$$$ integers \u2014 the required numbers $$$a+b$$$.\nExample\nInput\n4\n1 5\n314 15\n-99 99\n123 987\nOutput\n6\n329\n0\n1110", "input": [ [ [ "1", "5" ] ], [ [ "314", "15" ] ], [ [ "-99", "99" ] ], [ [ "123", "987" ] ] ], "output": [ "6", "329", "0", "1110" ] }, { "problem_id": "1348A", "problem_name": "Phoenix and Balance\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1348/A", "problem_solution_link": "https://codeforces.com/problemset/status/1348/problem/A", "problem_statement": "A. Phoenix and Balance\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPhoenix has $$$n$$$ coins with weights $$$2^1, 2^2, \\dots, 2^n$$$. He knows that $$$n$$$ is even.\nHe wants to split the coins into two piles such that each pile has exactly $$$\\frac{n}{2}$$$ coins and the difference of weights between the two piles is\nminimized\n. Formally, let $$$a$$$ denote the sum of weights in the first pile, and $$$b$$$ denote the sum of weights in the second pile. Help Phoenix minimize $$$|a-b|$$$, the absolute value of $$$a-b$$$.\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\le t \\le 100$$$)\u00a0\u2014 the number of test cases.\nThe first line of each test case contains an integer $$$n$$$ ($$$2 \\le n \\le 30$$$; $$$n$$$ is even)\u00a0\u2014 the number of coins that Phoenix has.\nOutput\nFor each test case, output one integer\u00a0\u2014 the minimum possible difference of weights between the two piles.\nExample\nInput\n2\n2\n4\nOutput\n2\n6\nNote\nIn the first test case, Phoenix has two coins with weights $$$2$$$ and $$$4$$$. No matter how he divides the coins, the difference will be $$$4-2=2$$$.\nIn the second test case, Phoenix has four coins of weight $$$2$$$, $$$4$$$, $$$8$$$, and $$$16$$$. It is optimal for Phoenix to place coins with weights $$$2$$$ and $$$16$$$ in one pile, and coins with weights $$$4$$$ and $$$8$$$ in another pile. The difference is $$$(2+16)-(4+8)=6$$$.", "input": [ [ [ "2" ] ], [ [ "4" ] ] ], "output": [ "2", "6" ] }, { "problem_id": "1345A", "problem_name": "Puzzle Pieces\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1345/A", "problem_solution_link": "https://codeforces.com/problemset/status/1345/problem/A", "problem_statement": "A. Puzzle Pieces\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a special jigsaw puzzle consisting of $$$n\\cdot m$$$ identical pieces. Every piece has three tabs and one blank, as pictured below.\nThe jigsaw puzzle is considered solved if the following conditions hold:\nThe pieces are arranged into a grid with $$$n$$$ rows and $$$m$$$ columns.\nFor any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.\nThrough rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.\nInput\nThe test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\\le t\\le 1000$$$)\u00a0\u2014 the number of test cases. Next $$$t$$$ lines contain descriptions of test cases.\nEach test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n,m \\le 10^5$$$).\nOutput\nFor each test case output a single line containing \"\nYES\n\" if it is possible to solve the jigsaw puzzle, or \"\nNO\n\" otherwise. You can print each letter in any case (upper or lower).\nExample\nInput\n3\n1 3\n100000 100000\n2 2\nOutput\nYES\nNO\nYES\nNote\nFor the first test case, this is an example solution:\nFor the second test case, we can show that no solution exists.\nFor the third test case, this is an example solution:", "input": [ [ [ "1", "3" ] ], [ [ "100000", "100000" ] ], [ [ "2", "2" ] ] ], "output": [ "YES", "NO", "YES" ] }, { "problem_id": "1343B", "problem_name": "Balanced Array\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1343/B", "problem_solution_link": "https://codeforces.com/problemset/status/1343/problem/B", "problem_statement": "B. Balanced Array\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a positive integer $$$n$$$, it is guaranteed that $$$n$$$ is even (i.e. divisible by $$$2$$$).\nYou want to construct the array $$$a$$$ of length $$$n$$$ such that:\nThe first $$$\\frac{n}{2}$$$ elements of $$$a$$$ are even (divisible by $$$2$$$);\nthe second $$$\\frac{n}{2}$$$ elements of $$$a$$$ are odd (not divisible by $$$2$$$);\nall elements of $$$a$$$ are distinct and positive\n;\nthe sum of the first half equals to the sum of the second half ($$$\\sum\\limits_{i=1}^{\\frac{n}{2}} a_i = \\sum\\limits_{i=\\frac{n}{2} + 1}^{n} a_i$$$).\nIf there are multiple answers, you can print any. It is\nnot guaranteed\nthat the answer exists.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe only line of the test case contains one integer $$$n$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$) \u2014 the length of the array. It is guaranteed that that $$$n$$$ is even (i.e. divisible by $$$2$$$).\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \\cdot 10^5$$$ ($$$\\sum n \\le 2 \\cdot 10^5$$$).\nOutput\nFor each test case, print the answer \u2014 \"\nNO\n\" (without quotes), if there is no suitable answer for the given test case or \"\nYES\n\" in the first line and\nany\nsuitable array $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^9$$$) satisfying conditions from the problem statement on the second line.\nExample\nInput\n5\n2\n4\n6\n8\n10\nOutput\nNO\nYES\n2 4 1 5\nNO\nYES\n2 4 6 8 1 3 5 11\nNO", "input": [ [ [ "2" ] ], [ [ "4" ] ], [ [ "6" ] ], [ [ "8" ] ], [ [ "10" ] ] ], "output": [ ["NO"], ["YES", "2 4 1 5"], ["NO"], ["YES", "2 4 6 8 1 3 5 11"], ["NO"] ], "error": true }, { "problem_id": "1337A", "problem_name": "Ichihime and Triangle\nconstructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1337/A", "problem_solution_link": "https://codeforces.com/problemset/status/1337/problem/A", "problem_statement": "A. Ichihime and Triangle\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIchihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.\nThese days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite \u2014 cookies. Ichihime decides to attend the contest. Now she is solving the following problem.\nYou are given four positive integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$, such that $$$a \\leq b \\leq c \\leq d$$$.\nYour task is to find three integers $$$x$$$, $$$y$$$, $$$z$$$, satisfying the following conditions:\n$$$a \\leq x \\leq b$$$.\n$$$b \\leq y \\leq c$$$.\n$$$c \\leq z \\leq d$$$.\nThere exists a triangle with a positive non-zero area and the lengths of its three sides are $$$x$$$, $$$y$$$, and $$$z$$$.\nIchihime desires to get the cookie, but the problem seems too hard for her. Can you help her?\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 1000$$$) \u00a0\u2014 the number of test cases.\nThe next $$$t$$$ lines describe test cases. Each test case is given as four space-separated integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$1 \\leq a \\leq b \\leq c \\leq d \\leq 10^9$$$).\nOutput\nFor each test case, print three integers $$$x$$$, $$$y$$$, $$$z$$$ \u00a0\u2014 the integers you found satisfying the conditions given in the statement.\nIt is guaranteed that the answer always exists. If there are multiple answers, print any.\nExample\nInput\n4\n1 3 5 7\n1 5 5 7\n100000 200000 300000 400000\n1 1 977539810 977539810\nOutput\n3 4 5\n5 5 5\n182690 214748 300999\n1 977539810 977539810\nNote\nOne of the possible solutions to the first test case:\nOne of the possible solutions to the second test case:", "input": [ [ [ "1", "3", "5", "7" ] ], [ [ "1", "5", "5", "7" ] ], [ [ "100000", "200000", "300000", "400000" ] ], [ [ "1", "1", "977539810", "977539810" ] ] ], "output": [ "3 4 5", "5 5 5", "182690 214748 300999", "1 977539810 977539810" ] }, { "problem_id": "1773F", "problem_name": "Football\nconstructive algorithms", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1773/F", "problem_solution_link": "https://codeforces.com/problemset/status/1773/problem/F", "problem_statement": "F. Football\ntime limit per test\n3 seconds\nmemory limit per test\n1024 megabytes\ninput\nstandard input\noutput\nstandard output\nScientists are researching an impact of football match results on the mood of football fans. They have a hypothesis that there is a correlation between the number of draws and fans' desire to watch football matches in the future.\nIn football, two teams play a match. The teams score goals throughout a match. A score \"$$$x$$$\n:\n$$$y$$$\" means that the team we observe scored $$$x$$$ goals and conceded $$$y$$$ goals. If $$$x = y$$$, then the match ends in a draw. If $$$x > y$$$, then the observed team wins, and if $$$x < y$$$, then it loses.\nTo find out if there is a correlation, the scientists gathered information about the results of teams in lower leagues. The information they found is the number of matches played by the team ($$$n$$$), the number of goals scored in these matches ($$$a$$$), and the number of goals conceded in these matches ($$$b$$$).\nYou are given this information for a single team. You are asked to calculate the minimum number of draws that could have happened during the team's matches and provide a list of match scores with the minimum number of draws.\nInput\nThe first line contains an integer $$$n$$$\u00a0\u2014 the number of matches played by the team ($$$1 \\le n \\le 100$$$). The second line contains an integer $$$a$$$\u00a0\u2014 the total number of goals scored by the team in all $$$n$$$ matches ($$$0 \\le a \\le 1000$$$). The third line contains an integer $$$b$$$\u00a0\u2014 the total number of goals conceded by the team in all $$$n$$$ matches ($$$0 \\le b \\le 1000$$$).\nOutput\nIn the first line, print a single integer $$$d$$$\u00a0\u2014 the minimum number of draws.\nIn the following $$$n$$$ lines, print a list of match scores, each line in the format \"$$$x$$$\n:\n$$$y$$$\", where $$$x$$$ is the number of goals scored in the match, and $$$y$$$\u00a0\u2013 the number of goals conceded, so that exactly $$$d$$$ of these matches have ended in a draw. In case multiple such lists of match scores exist, print any of them.\nExamples\nInput\n3\n2\n4\nOutput\n0\n1:0\n1:2\n0:2\nInput\n1\n2\n2\nOutput\n1\n2:2\nInput\n4\n0\n7\nOutput\n0\n0:1\n0:2\n0:1\n0:3\nInput\n6\n3\n1\nOutput\n2\n0:0\n1:0\n0:0\n0:1\n1:0\n1:0", "input": [ [ [ "3", "2", "4" ] ], [ [ "1", "2", "2" ] ], [ [ "4", "0", "7" ] ], [ [ "6", "3", "1" ] ] ], "output": [ "0\n1:0\n1:2\n0:2", "1\n2:2", "0\n0:1\n0:2\n0:1\n0:3", "2\n0:0\n1:0\n0:0\n0:1\n1:0\n1:0" ] }, { "problem_id": "1335A", "problem_name": "Candies and Two Sisters\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1335/A", "problem_solution_link": "https://codeforces.com/problemset/status/1335/problem/A", "problem_statement": "A. Candies and Two Sisters\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are two sisters Alice and Betty. You have $$$n$$$ candies. You want to distribute these $$$n$$$ candies between two sisters in such a way that:\nAlice will get $$$a$$$ ($$$a > 0$$$) candies;\nBetty will get $$$b$$$ ($$$b > 0$$$) candies;\neach sister will get some\ninteger\nnumber of candies;\nAlice will get a greater amount of candies than Betty (i.e. $$$a > b$$$);\nall the candies will be given to one of two sisters (i.e. $$$a+b=n$$$).\nYour task is to calculate the number of ways to distribute exactly $$$n$$$ candies between sisters in a way described above. Candies are indistinguishable.\nFormally, find the number of ways to represent $$$n$$$ as the sum of $$$n=a+b$$$, where $$$a$$$ and $$$b$$$ are positive integers and $$$a>b$$$.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe only line of a test case contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^9$$$) \u2014 the number of candies you have.\nOutput\nFor each test case, print the answer \u2014 the number of ways to distribute exactly $$$n$$$ candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print $$$0$$$.\nExample\nInput\n6\n7\n1\n2\n3\n2000000000\n763243547\nOutput\n3\n0\n0\n1\n999999999\n381621773\nNote\nFor the test case of the example, the $$$3$$$ possible ways to distribute candies are:\n$$$a=6$$$, $$$b=1$$$;\n$$$a=5$$$, $$$b=2$$$;\n$$$a=4$$$, $$$b=3$$$.", "input": [ [ [ "7" ] ], [ [ "1" ] ], [ [ "2" ] ], [ [ "3" ] ], [ [ "2000000000" ] ], [ [ "763243547" ] ] ], "output": [ "3", "0", "0", "1", "999999999", "381621773" ] }, { "problem_id": "1328A", "problem_name": "Divisibility Problem\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1328/A", "problem_solution_link": "https://codeforces.com/problemset/status/1328/problem/A", "problem_statement": "A. Divisibility Problem\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two positive integers $$$a$$$ and $$$b$$$. In one move you can increase $$$a$$$ by $$$1$$$ (replace $$$a$$$ with $$$a+1$$$). Your task is to find the minimum number of moves you need to do in order to make $$$a$$$ divisible by $$$b$$$. It is possible, that you have to make $$$0$$$ moves, as $$$a$$$ is already divisible by $$$b$$$. You have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases. Then $$$t$$$ test cases follow.\nThe only line of the test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le 10^9$$$).\nOutput\nFor each test case print the answer \u2014 the minimum number of moves you need to do in order to make $$$a$$$ divisible by $$$b$$$.\nExample\nInput\n5\n10 4\n13 9\n100 13\n123 456\n92 46\nOutput\n2\n5\n4\n333\n0", "input": [ [ [ "10", "4" ] ], [ [ "13", "9" ] ], [ [ "100", "13" ] ], [ [ "123", "456" ] ], [ [ "92", "46" ] ] ], "output": [ "2", "5", "4", "333", "0" ] }, { "problem_id": "1325B", "problem_name": "CopyCopyCopyCopyCopy\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1325/B", "problem_solution_link": "https://codeforces.com/problemset/status/1325/problem/B", "problem_statement": "B. CopyCopyCopyCopyCopy\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nEhab has an array $$$a$$$ of length $$$n$$$. He has just enough free time to make a new array consisting of $$$n$$$ copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?\nA sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements. The longest increasing subsequence of an array is the longest subsequence such that its elements are ordered in strictly increasing order.\nInput\nThe first line contains an integer $$$t$$$\u00a0\u2014 the number of test cases you need to solve. The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 10^5$$$)\u00a0\u2014 the number of elements in the array $$$a$$$.\nThe second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\\ldots$$$, $$$a_{n}$$$ ($$$1 \\le a_i \\le 10^9$$$)\u00a0\u2014 the elements of the array $$$a$$$.\nThe sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.\nOutput\nFor each testcase, output the length of the longest increasing subsequence of $$$a$$$ if you concatenate it to itself $$$n$$$ times.\nExample\nInput\n2\n3\n3 2 1\n6\n3 1 4 1 5 9\nOutput\n3\n5\nNote\nIn the first sample, the new array is $$$[3,2,\\textbf{1},3,\\textbf{2},1,\\textbf{3},2,1]$$$. The longest increasing subsequence is marked in bold.\nIn the second sample, the longest increasing subsequence will be $$$[1,3,4,5,9]$$$.", "input": [ [ [ "3" ], [ "3", "2", "1" ] ], [ [ "6" ], [ "3", "1", "4", "1", "5", "9" ] ] ], "output": [ "3", "5" ] }, { "problem_id": "1325A", "problem_name": "EhAb AnD gCd\nconstructive algorithms, greedy, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1325/A", "problem_solution_link": "https://codeforces.com/problemset/status/1325/problem/A", "problem_statement": "A. EhAb AnD gCd\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a positive integer $$$x$$$. Find\nany\nsuch $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.\nAs a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.\nIt's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.\nInput\nThe first line contains a single integer $$$t$$$ $$$(1 \\le t \\le 100)$$$ \u00a0\u2014 the number of testcases.\nEach testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \\le x \\le 10^9)$$$.\nOutput\nFor each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.\nExample\nInput\n2\n2\n14\nOutput\n1 1\n6 4\nNote\nIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.\nIn the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.", "input": [ [ [ "2" ] ], [ [ "14" ] ] ], "output": [ "1 1", "6 4" ] }, { "problem_id": "1323A", "problem_name": "Even Subset Sum Problem\nbrute force, dp, greedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1323/A", "problem_solution_link": "https://codeforces.com/problemset/status/1323/problem/A", "problem_statement": "A. Even Subset Sum Problem\ntime limit per test\n1 second\nmemory limit per test\n512 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a\nnon-empty\nsubset of its elements such that their sum is\neven\n(i.e. divisible by $$$2$$$) or determine that there is no such subset.\nBoth the given array and required subset may contain equal values.\nInput\nThe first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow.\nA description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 100$$$), length of array $$$a$$$.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).\nOutput\nFor each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \\leq p_i \\leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.\nExample\nInput\n3\n3\n1 4 3\n1\n15\n2\n3 5\nOutput\n1\n2\n-1\n2\n1 2\nNote\nThere are three test cases in the example.\nIn the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.\nIn the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.\nIn the third test case, the subset consisting of all array's elements has even sum.", "input": [ [ [ "3" ], [ "1", "4", "3" ] ], [ [ "1" ], [ "15" ] ], [ [ "2" ], [ "3", "5" ] ] ], "output": [ ["1", "2"], ["-1"], ["2", "1 2"] ], "error": true }, { "problem_id": "1316A", "problem_name": "Grade Allocation\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1316/A", "problem_solution_link": "https://codeforces.com/problemset/status/1316/problem/A", "problem_statement": "A. Grade Allocation\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\n$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.\nYou can change each student's score as long as the following conditions are satisfied:\nAll scores are integers\n$$$0 \\leq a_{i} \\leq m$$$\nThe average score of the class doesn't change.\nYou are student $$$1$$$ and you would like to maximize your own score.\nFind the highest possible score you can assign to yourself such that all conditions are satisfied.\nInput\nEach test contains multiple test cases.\nThe first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 200$$$). The description of the test cases follows.\nThe first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\leq n \\leq 10^{3}$$$, $$$1 \\leq m \\leq 10^{5}$$$) \u00a0\u2014 the number of students and the highest possible score respectively.\nThe second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$ 0 \\leq a_{i} \\leq m$$$) \u00a0\u2014 scores of the students.\nOutput\nFor each testcase, output one integer \u00a0\u2014 the highest possible score you can assign to yourself such that both conditions are satisfied._\nExample\nInput\n2\n4 10\n1 2 3 4\n4 5\n1 2 3 4\nOutput\n10\n5\nNote\nIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.\nIn the second case, $$$0 \\leq a_{i} \\leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\\le a_i\\le m$$$.", "input": [ [ [ "4", "10" ], [ "1", "2", "3", "4" ] ], [ [ "4", "5" ], [ "1", "2", "3", "4" ] ] ], "output": [ "10", "5" ] }, { "problem_id": "1315A", "problem_name": "Dead Pixel\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1315/A", "problem_solution_link": "https://codeforces.com/problemset/status/1315/problem/A", "problem_statement": "A. Dead Pixel\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nScreen resolution of Polycarp's monitor is $$$a \\times b$$$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $$$(x, y)$$$ ($$$0 \\le x < a, 0 \\le y < b$$$). You can consider columns of pixels to be numbered from $$$0$$$ to $$$a-1$$$, and rows\u00a0\u2014 from $$$0$$$ to $$$b-1$$$.\nPolycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.\nPrint the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.\nInput\nIn the first line you are given an integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$)\u00a0\u2014 the number of test cases in the test. In the next lines you are given descriptions of $$$t$$$ test cases.\nEach test case contains a single line which consists of $$$4$$$ integers $$$a, b, x$$$ and $$$y$$$ ($$$1 \\le a, b \\le 10^4$$$; $$$0 \\le x < a$$$; $$$0 \\le y < b$$$)\u00a0\u2014 the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $$$a+b>2$$$ (e.g. $$$a=b=1$$$ is impossible).\nOutput\nPrint $$$t$$$ integers\u00a0\u2014 the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.\nExample\nInput\n6\n8 8 0 0\n1 10 0 3\n17 31 10 4\n2 1 0 0\n5 10 3 9\n10 10 4 8\nOutput\n56\n6\n442\n1\n45\n80\nNote\nIn the first test case, the screen resolution is $$$8 \\times 8$$$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window.", "input": [ [ [ "8", "8", "0", "0" ] ], [ [ "1", "10", "0", "3" ] ], [ [ "17", "31", "10", "4" ] ], [ [ "2", "1", "0", "0" ] ], [ [ "5", "10", "3", "9" ] ], [ [ "10", "10", "4", "8" ] ] ], "output": [ "56", "6", "442", "1", "45", "80" ] }, { "problem_id": "1312A", "problem_name": "Two Regular Polygons\ngeometry, greedy, math, number theory", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1312/A", "problem_solution_link": "https://codeforces.com/problemset/status/1312/problem/A", "problem_statement": "A. Two Regular Polygons\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two integers $$$n$$$ and $$$m$$$ ($$$m < n$$$). Consider a\nconvex\nregular polygon of $$$n$$$ vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length).\nExamples of convex regular polygons\nYour task is to say if it is possible to build another\nconvex\nregular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases.\nThe next $$$t$$$ lines describe test cases. Each test case is given as two space-separated integers $$$n$$$ and $$$m$$$ ($$$3 \\le m < n \\le 100$$$) \u2014 the number of vertices in the initial polygon and the number of vertices in the polygon you want to build.\nOutput\nFor each test case, print the answer \u2014 \"\nYES\n\" (without quotes), if it is possible to build another\nconvex\nregular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon and \"\nNO\n\" otherwise.\nExample\nInput\n2\n6 3\n7 3\nOutput\nYES\nNO\nNote\nThe first test case of the example\nIt can be shown that the answer for the second test case of the example is \"\nNO\n\".", "input": [ [ [ "6", "3" ] ], [ [ "7", "3" ] ] ], "output": [ "YES", "NO" ] }, { "problem_id": "1311A", "problem_name": "Add Odd or Subtract Even\ngreedy, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1311/A", "problem_solution_link": "https://codeforces.com/problemset/status/1311/problem/A", "problem_statement": "A. Add Odd or Subtract Even\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given two positive integers $$$a$$$ and $$$b$$$.\nIn one move, you can\nchange\n$$$a$$$ in the following way:\nChoose any positive\nodd\ninteger $$$x$$$ ($$$x > 0$$$) and replace $$$a$$$ with $$$a+x$$$;\nchoose any positive\neven\ninteger $$$y$$$ ($$$y > 0$$$) and replace $$$a$$$ with $$$a-y$$$.\nYou can perform as many such operations as you want. You can choose the same numbers $$$x$$$ and $$$y$$$ in different moves.\nYour task is to find the minimum number of moves required to obtain $$$b$$$ from $$$a$$$. It is guaranteed that you can always obtain $$$b$$$ from $$$a$$$.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases.\nThen $$$t$$$ test cases follow. Each test case is given as two space-separated integers $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le 10^9$$$).\nOutput\nFor each test case, print the answer \u2014 the minimum number of moves required to obtain $$$b$$$ from $$$a$$$ if you can perform any number of moves described in the problem statement. It is guaranteed that you can always obtain $$$b$$$ from $$$a$$$.\nExample\nInput\n5\n2 3\n10 10\n2 4\n7 4\n9 3\nOutput\n1\n0\n2\n2\n1\nNote\nIn the first test case, you can just add $$$1$$$.\nIn the second test case, you don't need to do anything.\nIn the third test case, you can add $$$1$$$ two times.\nIn the fourth test case, you can subtract $$$4$$$ and add $$$1$$$.\nIn the fifth test case, you can just subtract $$$6$$$.", "input": [ [ [ "2", "3" ] ], [ [ "10", "10" ] ], [ [ "2", "4" ] ], [ [ "7", "4" ] ], [ [ "9", "3" ] ] ], "output": [ "1", "0", "2", "2", "1" ] }, { "problem_id": "1307A", "problem_name": "Cow and Haybales\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1307/A", "problem_solution_link": "https://codeforces.com/problemset/status/1307/problem/A", "problem_statement": "A. Cow and Haybales\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThe USA Construction Operation (USACO) recently ordered Farmer John to arrange\na row\nof $$$n$$$ haybale piles on the farm. The $$$i$$$-th pile contains $$$a_i$$$ haybales.\nHowever, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an adjacent pile. Formally, in one day she can choose any two indices $$$i$$$ and $$$j$$$ ($$$1 \\le i, j \\le n$$$) such that $$$|i-j|=1$$$ and $$$a_i>0$$$ and apply $$$a_i = a_i - 1$$$, $$$a_j = a_j + 1$$$. She may also decide to not do anything on some days because she is lazy.\nBessie wants to maximize the number of haybales in pile $$$1$$$ (i.e. to maximize $$$a_1$$$), and she only has $$$d$$$ days to do so before Farmer John returns. Help her find the maximum number of haybales that may be in pile $$$1$$$ if she acts optimally!\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u00a0\u2014 the number of test cases. Next $$$2t$$$ lines contain a description of test cases \u00a0\u2014 two lines per test case.\nThe first line of each test case contains integers $$$n$$$ and $$$d$$$ ($$$1 \\le n,d \\le 100$$$) \u2014 the number of haybale piles and the number of days, respectively.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i \\le 100$$$) \u00a0\u2014 the number of haybales in each pile.\nOutput\nFor each test case, output one integer: the maximum number of haybales that may be in pile $$$1$$$ after $$$d$$$ days if Bessie acts optimally.\nExample\nInput\n3\n4 5\n1 0 3 2\n2 2\n100 1\n1 8\n0\nOutput\n3\n101\n0\nNote\nIn the first test case of the sample, this is one possible way Bessie can end up with $$$3$$$ haybales in pile $$$1$$$:\nOn day one, move a haybale from pile $$$3$$$ to pile $$$2$$$\nOn day two, move a haybale from pile $$$3$$$ to pile $$$2$$$\nOn day three, move a haybale from pile $$$2$$$ to pile $$$1$$$\nOn day four, move a haybale from pile $$$2$$$ to pile $$$1$$$\nOn day five, do nothing\nIn the second test case of the sample, Bessie can do nothing on the first day and move a haybale from pile $$$2$$$ to pile $$$1$$$ on the second day.", "input": [ [ [ "4", "5" ], [ "1", "0", "3", "2" ] ], [ [ "2", "2" ], [ "100", "1" ] ], [ [ "1", "8" ], [ "0" ] ] ], "output": [ "3", "101", "0" ] }, { "problem_id": "1305A", "problem_name": "Kuroni and the Gifts\nbrute force, constructive algorithms, greedy, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1305/A", "problem_solution_link": "https://codeforces.com/problemset/status/1305/problem/A", "problem_statement": "A. Kuroni and the Gifts\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nKuroni has $$$n$$$ daughters. As gifts for them, he bought $$$n$$$ necklaces and $$$n$$$ bracelets:\nthe $$$i$$$-th necklace has a brightness $$$a_i$$$, where all the $$$a_i$$$ are\npairwise distinct\n(i.e. all $$$a_i$$$ are different),\nthe $$$i$$$-th bracelet has a brightness $$$b_i$$$, where all the $$$b_i$$$ are\npairwise distinct\n(i.e. all $$$b_i$$$ are different).\nKuroni wants to give\nexactly one\nnecklace and\nexactly one\nbracelet to each of his daughters. To make sure that all of them look unique, the total brightnesses of the gifts given to each daughter should be\npairwise distinct\n. Formally, if the $$$i$$$-th daughter receives a necklace with brightness $$$x_i$$$ and a bracelet with brightness $$$y_i$$$, then the sums $$$x_i + y_i$$$ should be pairwise distinct. Help Kuroni to distribute the gifts.\nFor example, if the brightnesses are $$$a = [1, 7, 5]$$$ and $$$b = [6, 1, 2]$$$, then we may distribute the gifts as follows:\nGive the third necklace and the first bracelet to the first daughter, for a total brightness of $$$a_3 + b_1 = 11$$$.\nGive the first necklace and the third bracelet to the second daughter, for a total brightness of $$$a_1 + b_3 = 3$$$.\nGive the second necklace and the second bracelet to the third daughter, for a total brightness of $$$a_2 + b_2 = 8$$$.\nHere is an example of an\ninvalid\ndistribution:\nGive the first necklace and the first bracelet to the first daughter, for a total brightness of $$$a_1 + b_1 = 7$$$.\nGive the second necklace and the second bracelet to the second daughter, for a total brightness of $$$a_2 + b_2 = 8$$$.\nGive the third necklace and the third bracelet to the third daughter, for a total brightness of $$$a_3 + b_3 = 7$$$.\nThis distribution is\ninvalid\n, as the total brightnesses of the gifts received by the first and the third daughter are the same. Don't make them this upset!\nInput\nThe input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u00a0\u2014 the number of daughters, necklaces and bracelets.\nThe second line of each test case contains $$$n$$$\ndistinct\nintegers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 1000$$$) \u00a0\u2014 the brightnesses of the necklaces.\nThe third line of each test case contains $$$n$$$\ndistinct\nintegers $$$b_1, b_2, \\dots, b_n$$$ ($$$1 \\le b_i \\le 1000$$$) \u00a0\u2014 the brightnesses of the bracelets.\nOutput\nFor each test case, print a line containing $$$n$$$ integers $$$x_1, x_2, \\dots, x_n$$$, representing that the $$$i$$$-th daughter receives a necklace with brightness $$$x_i$$$. In the next line print $$$n$$$ integers $$$y_1, y_2, \\dots, y_n$$$, representing that the $$$i$$$-th daughter receives a bracelet with brightness $$$y_i$$$.\nThe sums $$$x_1 + y_1, x_2 + y_2, \\dots, x_n + y_n$$$ should all be distinct. The numbers $$$x_1, \\dots, x_n$$$ should be equal to the numbers $$$a_1, \\dots, a_n$$$ in some order, and the numbers $$$y_1, \\dots, y_n$$$ should be equal to the numbers $$$b_1, \\dots, b_n$$$ in some order.\nIt can be shown that an answer always exists. If there are multiple possible answers, you may print any of them.\nExample\nInput\n2\n3\n1 8 5\n8 4 5\n3\n1 7 5\n6 1 2\nOutput\n1 8 5\n8 4 5\n5 1 7\n6 2 1\nNote\nIn the first test case, it is enough to give the $$$i$$$-th necklace and the $$$i$$$-th bracelet to the $$$i$$$-th daughter. The corresponding sums are $$$1 + 8 = 9$$$, $$$8 + 4 = 12$$$, and $$$5 + 5 = 10$$$.\nThe second test case is described in the statement.", "input": [ [ [ "3" ], [ "1", "8", "5" ], [ "8", "4", "5" ] ], [ [ "3" ], [ "1", "7", "5" ], [ "6", "1", "2" ] ] ], "output": [ ["1 8 5", "8 4 5"], ["5 1 7", "6 2 1"] ], "error": true }, { "problem_id": "1304A", "problem_name": "Two Rabbits\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1304/A", "problem_solution_link": "https://codeforces.com/problemset/status/1304/problem/A", "problem_statement": "A. Two Rabbits\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nBeing tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other.\nHe noticed that the two rabbits were hopping\ntowards each other\n. The positions of the two rabbits can be represented as integer coordinates on a horizontal line. The taller rabbit is currently on position $$$x$$$, and the shorter rabbit is currently on position $$$y$$$ ($$$x \\lt y$$$). Every second, each rabbit hops to another position. The taller rabbit hops to the positive direction by $$$a$$$, and the shorter rabbit hops to the negative direction by $$$b$$$.\nFor example, let's say $$$x=0$$$, $$$y=10$$$, $$$a=2$$$, and $$$b=3$$$. At the $$$1$$$-st second, each rabbit will be at position $$$2$$$ and $$$7$$$. At the $$$2$$$-nd second, both rabbits will be at position $$$4$$$.\nGildong is now wondering:\nWill the two rabbits be at the same position\nat the same moment\n? If so, how long will it take?\nLet's find a moment in time (in seconds) after which the rabbits will be at the same point.\nInput\nEach test contains one or more test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 1000$$$).\nEach test case contains exactly one line. The line consists of four integers $$$x$$$, $$$y$$$, $$$a$$$, $$$b$$$ ($$$0 \\le x \\lt y \\le 10^9$$$, $$$1 \\le a,b \\le 10^9$$$) \u2014 the current position of the taller rabbit, the current position of the shorter rabbit, the hopping distance of the taller rabbit, and the hopping distance of the shorter rabbit, respectively.\nOutput\nFor each test case, print the single integer: number of seconds the two rabbits will take to be at the same position.\nIf the two rabbits will never be at the same position simultaneously, print $$$-1$$$.\nExample\nInput\n5\n0 10 2 3\n0 10 3 3\n900000000 1000000000 1 9999999\n1 2 1 1\n1 3 1 1\nOutput\n2\n-1\n10\n-1\n1\nNote\nThe first case is explained in the description.\nIn the second case, each rabbit will be at position $$$3$$$ and $$$7$$$ respectively at the $$$1$$$-st second. But in the $$$2$$$-nd second they will be at $$$6$$$ and $$$4$$$ respectively, and we can see that they will never be at the same position since the distance between the two rabbits will only increase afterward.", "input": [ [ [ "0", "10", "2", "3" ] ], [ [ "0", "10", "3", "3" ] ], [ [ "900000000", "1000000000", "1", "9999999" ] ], [ [ "1", "2", "1", "1" ] ], [ [ "1", "3", "1", "1" ] ] ], "output": [ "2", "-1", "10", "-1", "1" ] }, { "problem_id": "1303A", "problem_name": "Erasing Zeroes\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1303/A", "problem_solution_link": "https://codeforces.com/problemset/status/1303/problem/A", "problem_statement": "A. Erasing Zeroes\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a string $$$s$$$. Each character is either\n0\nor\n1\n.\nYou want all\n1\n's in the string to form a contiguous subsegment. For example, if the string is\n0\n,\n1\n,\n00111\nor\n01111100\n, then all\n1\n's form a contiguous subsegment, and if the string is\n0101\n,\n100001\nor\n11111111111101\n, then this condition is not met.\nYou may erase some (possibly none)\n0\n's from the string. What is the minimum number of\n0\n's that you have to erase?\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases.\nThen $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \\le |s| \\le 100$$$); each character of $$$s$$$ is either\n0\nor\n1\n.\nOutput\nPrint $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of\n0\n's that you have to erase from $$$s$$$).\nExample\nInput\n3\n010011\n0\n1111000\nOutput\n2\n0\n0\nNote\nIn the first test case you have to delete the third and forth symbols from string\n010011\n(it turns into\n0111\n).", "input": [ [ [ "010011" ] ], [ [ "0" ] ], [ [ "1111000" ] ] ], "output": [ "2", "0", "0" ] }, { "problem_id": "1301A", "problem_name": "Three Strings\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1301/A", "problem_solution_link": "https://codeforces.com/problemset/status/1301/problem/A", "problem_statement": "A. Three Strings\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given three strings $$$a$$$, $$$b$$$ and $$$c$$$ of the same length $$$n$$$. The strings consist of lowercase English letters only. The $$$i$$$-th letter of $$$a$$$ is $$$a_i$$$, the $$$i$$$-th letter of $$$b$$$ is $$$b_i$$$, the $$$i$$$-th letter of $$$c$$$ is $$$c_i$$$.\nFor every $$$i$$$ ($$$1 \\leq i \\leq n$$$) you\nmust\nswap (i.e. exchange) $$$c_i$$$ with either $$$a_i$$$ or $$$b_i$$$. So in total you'll perform exactly $$$n$$$ swap operations, each of them either $$$c_i \\leftrightarrow a_i$$$ or $$$c_i \\leftrightarrow b_i$$$ ($$$i$$$ iterates over all integers between $$$1$$$ and $$$n$$$, inclusive).\nFor example, if $$$a$$$ is \"\ncode\n\", $$$b$$$ is \"\ntrue\n\", and $$$c$$$ is \"\nhelp\n\", you can make $$$c$$$ equal to \"\ncrue\n\" taking the $$$1$$$-st and the $$$4$$$-th letters from $$$a$$$ and the others from $$$b$$$. In this way $$$a$$$ becomes \"\nhodp\n\" and $$$b$$$ becomes \"\ntele\n\".\nIs it possible that after these swaps the string $$$a$$$ becomes exactly the same as the string $$$b$$$?\nInput\nThe input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$) \u00a0\u2014 the number of test cases. The description of the test cases follows.\nThe first line of each test case contains a string of lowercase English letters $$$a$$$.\nThe second line of each test case contains a string of lowercase English letters $$$b$$$.\nThe third line of each test case contains a string of lowercase English letters $$$c$$$.\nIt is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding $$$100$$$.\nOutput\nPrint $$$t$$$ lines with answers for all test cases. For each test case:\nIf it is possible to make string $$$a$$$ equal to string $$$b$$$ print \"\nYES\n\" (without quotes), otherwise print \"\nNO\n\" (without quotes).\nYou can print either lowercase or uppercase letters in the answers.\nExample\nInput\n4\naaa\nbbb\nccc\nabc\nbca\nbca\naabb\nbbaa\nbaba\nimi\nmii\niim\nOutput\nNO\nYES\nYES\nNO\nNote\nIn the first test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.\nIn the second test case, you should swap $$$c_i$$$ with $$$a_i$$$ for all possible $$$i$$$. After the swaps $$$a$$$ becomes \"\nbca\n\", $$$b$$$ becomes \"\nbca\n\" and $$$c$$$ becomes \"\nabc\n\". Here the strings $$$a$$$ and $$$b$$$ are equal.\nIn the third test case, you should swap $$$c_1$$$ with $$$a_1$$$, $$$c_2$$$ with $$$b_2$$$, $$$c_3$$$ with $$$b_3$$$ and $$$c_4$$$ with $$$a_4$$$. Then string $$$a$$$ becomes \"\nbaba\n\", string $$$b$$$ becomes \"\nbaba\n\" and string $$$c$$$ becomes \"\nabab\n\". Here the strings $$$a$$$ and $$$b$$$ are equal.\nIn the fourth test case, it is impossible to do the swaps so that string $$$a$$$ becomes exactly the same as string $$$b$$$.", "input": [ [ [ "aaa" ], [ "bbb" ], [ "ccc" ] ], [ [ "abc" ], [ "bca" ], [ "bca" ] ], [ [ "aabb" ], [ "bbaa" ], [ "baba" ] ], [ [ "imi" ], [ "mii" ], [ "iim" ] ] ], "output": [ "NO", "YES", "YES", "NO" ] }, { "problem_id": "1300A", "problem_name": "Non-zero\nimplementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1300/A", "problem_solution_link": "https://codeforces.com/problemset/status/1300/problem/A", "problem_statement": "A. Non-zero\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nGuy-Manuel and Thomas have an array $$$a$$$ of $$$n$$$ integers [$$$a_1, a_2, \\dots, a_n$$$]. In one step they can add $$$1$$$ to any element of the array. Formally, in one step they can choose any integer index $$$i$$$ ($$$1 \\le i \\le n$$$) and do $$$a_i := a_i + 1$$$.\nIf either the sum or the product of all elements in the array is equal to zero, Guy-Manuel and Thomas do not mind to do this operation one more time.\nWhat is the minimum number of steps they need to do to make both the sum and the product of all elements in the array\ndifferent from zero\n? Formally, find the minimum number of steps to make $$$a_1 + a_2 +$$$ $$$\\dots$$$ $$$+ a_n \\ne 0$$$ and $$$a_1 \\cdot a_2 \\cdot$$$ $$$\\dots$$$ $$$\\cdot a_n \\ne 0$$$.\nInput\nEach test contains multiple test cases.\nThe first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^3$$$). The description of the test cases follows.\nThe first line of each test case contains an integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the size of the array.\nThe second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$-100 \\le a_i \\le 100$$$)\u00a0\u2014 elements of the array .\nOutput\nFor each test case, output the minimum number of steps required to make both sum and product of all elements in the array different from zero.\nExample\nInput\n4\n3\n2 -1 -1\n4\n-1 0 0 1\n2\n-1 2\n3\n0 -2 1\nOutput\n1\n2\n0\n2\nNote\nIn the first test case, the sum is $$$0$$$. If we add $$$1$$$ to the first element, the array will be $$$[3,-1,-1]$$$, the sum will be equal to $$$1$$$ and the product will be equal to $$$3$$$.\nIn the second test case, both product and sum are $$$0$$$. If we add $$$1$$$ to the second and the third element, the array will be $$$[-1,1,1,1]$$$, the sum will be equal to $$$2$$$ and the product will be equal to $$$-1$$$. It can be shown that fewer steps can't be enough.\nIn the third test case, both sum and product are non-zero, we don't need to do anything.\nIn the fourth test case, after adding $$$1$$$ twice to the first element the array will be $$$[2,-2,1]$$$, the sum will be $$$1$$$ and the product will be $$$-4$$$.", "input": [ [ [ "3" ], [ "2", "-1", "-1" ] ], [ [ "4" ], [ "-1", "0", "0", "1" ] ], [ [ "2" ], [ "-1", "2" ] ], [ [ "3" ], [ "0", "-2", "1" ] ] ], "output": [ "1", "2", "0", "2" ] }, { "problem_id": "1296A", "problem_name": "Array with Odd Sum\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1296/A", "problem_solution_link": "https://codeforces.com/problemset/status/1296/problem/A", "problem_statement": "A. Array with Odd Sum\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$a$$$ consisting of $$$n$$$ integers.\nIn one move, you can choose two indices $$$1 \\le i, j \\le n$$$ such that $$$i \\ne j$$$ and set $$$a_i := a_j$$$. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose $$$i$$$ and $$$j$$$ and replace $$$a_i$$$ with $$$a_j$$$).\nYour task is to say if it is possible to obtain an array with an odd (not divisible by $$$2$$$) sum of elements.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 2000$$$) \u2014 the number of test cases.\nThe next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \\le n \\le 2000$$$) \u2014 the number of elements in $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 2000$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.\nIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$ ($$$\\sum n \\le 2000$$$).\nOutput\nFor each test case, print the answer on it \u2014 \"\nYES\n\" (without quotes) if it is possible to obtain the array with an odd sum of elements, and \"\nNO\n\" otherwise.\nExample\nInput\n5\n2\n2 3\n4\n2 2 8 8\n3\n3 3 3\n4\n5 5 5 5\n4\n1 1 1 1\nOutput\nYES\nNO\nYES\nNO\nNO", "input": [ [ [ "2" ], [ "2", "3" ] ], [ [ "4" ], [ "2", "2", "8", "8" ] ], [ [ "3" ], [ "3", "3", "3" ] ], [ [ "4" ], [ "5", "5", "5", "5" ] ], [ [ "4" ], [ "1", "1", "1", "1" ] ] ], "output": [ "YES", "NO", "YES", "NO", "NO" ] }, { "problem_id": "1294A", "problem_name": "Collecting Coins\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1294/A", "problem_solution_link": "https://codeforces.com/problemset/status/1294/problem/A", "problem_statement": "A. Collecting Coins\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nPolycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has $$$a$$$ coins, Barbara has $$$b$$$ coins and Cerene has $$$c$$$ coins. Recently Polycarp has returned from the trip around the world and brought $$$n$$$ coins.\nHe wants to distribute\nall\nthese $$$n$$$ coins between his sisters in such a way that the number of coins Alice has is equal to the number of coins Barbara has and is equal to the number of coins Cerene has. In other words, if Polycarp gives $$$A$$$ coins to Alice, $$$B$$$ coins to Barbara and $$$C$$$ coins to Cerene ($$$A+B+C=n$$$), then $$$a + A = b + B = c + C$$$.\nNote\nthat A, B or C (the number of coins Polycarp gives to Alice, Barbara and Cerene correspondingly) can be 0.\nYour task is to find out if it is possible to distribute\nall\n$$$n$$$ coins between sisters in a way described above.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 10^4$$$) \u2014 the number of test cases.\nThe next $$$t$$$ lines describe test cases. Each test case is given on a new line and consists of four space-separated integers $$$a, b, c$$$ and $$$n$$$ ($$$1 \\le a, b, c, n \\le 10^8$$$) \u2014 the number of coins Alice has, the number of coins Barbara has, the number of coins Cerene has and the number of coins Polycarp has.\nOutput\nFor each test case, print \"\nYES\n\" if Polycarp can distribute\nall\n$$$n$$$ coins between his sisters and \"\nNO\n\" otherwise.\nExample\nInput\n5\n5 3 2 8\n100 101 102 105\n3 2 1 100000000\n10 20 15 14\n101 101 101 3\nOutput\nYES\nYES\nNO\nNO\nYES", "input": [ [ [ "5", "3", "2", "8" ] ], [ [ "100", "101", "102", "105" ] ], [ [ "3", "2", "1", "100000000" ] ], [ [ "10", "20", "15", "14" ] ], [ [ "101", "101", "101", "3" ] ] ], "output": [ "YES", "YES", "NO", "NO", "YES" ] }, { "problem_id": "1287A", "problem_name": "Angry Students\ngreedy, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1287/A", "problem_solution_link": "https://codeforces.com/problemset/status/1287/problem/A", "problem_statement": "A. Angry Students\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nIt's a walking tour day in SIS.Winter, so $$$t$$$ groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.\nInitially, some students are angry. Let's describe a group of students by a string of capital letters \"\nA\n\" and \"\nP\n\":\n\"\nA\n\" corresponds to an angry student\n\"\nP\n\" corresponds to a patient student\nSuch string describes the row from the last to the first student.\nEvery minute every angry student throws a snowball at the next student. Formally, if an angry student corresponds to the character with index $$$i$$$ in the string describing a group then they will throw a snowball at the student that corresponds to the character with index $$$i+1$$$ (students are given from the last to the first student). If the target student was not angry yet, they become angry. Even if the first (the rightmost in the string) student is angry, they don't throw a snowball since there is no one in front of them.\nLet's look at the first example test. The row initially looks like this:\nPPAP\n. Then, after a minute the only single angry student will throw a snowball at the student in front of them, and they also become angry:\nPPAA\n. After that, no more students will become angry.\nYour task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.\nInput\nThe first line contains a single integer $$$t$$$\u00a0\u2014 the number of groups of students ($$$1 \\le t \\le 100$$$). The following $$$2t$$$ lines contain descriptions of groups of students.\nThe description of the group starts with an integer $$$k_i$$$ ($$$1 \\le k_i \\le 100$$$)\u00a0\u2014 the number of students in the group, followed by a string $$$s_i$$$, consisting of $$$k_i$$$ letters \"\nA\n\" and \"\nP\n\", which describes the $$$i$$$-th group of students.\nOutput\nFor every group output single integer\u00a0\u2014 the last moment a student becomes angry.\nExamples\nInput\n1\n4\nPPAP\nOutput\n1\nInput\n3\n12\nAPPAPPPAPPPP\n3\nAAP\n3\nPPA\nOutput\n4\n1\n0\nNote\nIn the first test, after $$$1$$$ minute the state of students becomes\nPPAA\n. After that, no new angry students will appear.\nIn the second tets, state of students in the first group is:\nafter $$$1$$$ minute\u00a0\u2014\nAAPAAPPAAPPP\nafter $$$2$$$ minutes\u00a0\u2014\nAAAAAAPAAAPP\nafter $$$3$$$ minutes\u00a0\u2014\nAAAAAAAAAAAP\nafter $$$4$$$ minutes all $$$12$$$ students are angry\nIn the second group after $$$1$$$ minute, all students are angry.", "input": [ [ [ "4" ], [ "PPAP" ], [ "Output" ], [ "1" ], [ "Input" ], [ "3" ], [ "12" ], [ "APPAPPPAPPPP" ], [ "3" ], [ "AAP" ], [ "3" ], [ "PPA" ] ] ], "output": [ ["4", "1", "0"] ], "error": true }, { "problem_id": "1285A", "problem_name": "Mezo Playing Zoma\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1285/A", "problem_solution_link": "https://codeforces.com/problemset/status/1285/problem/A", "problem_statement": "A. Mezo Playing Zoma\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nToday, Mezo is playing a game. Zoma, a character in that game, is initially at position $$$x = 0$$$. Mezo starts sending $$$n$$$ commands to Zoma. There are two possible commands:\n'L' (Left) sets the position $$$x: =x - 1$$$;\n'R' (Right) sets the position $$$x: =x + 1$$$.\nUnfortunately, Mezo's controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position $$$x$$$ doesn't change and Mezo simply proceeds to the next command.\nFor example, if Mezo sends commands \"\nLRLR\n\", then here are some possible outcomes (underlined commands are sent successfully):\n\"\nLRLR\n\" \u2014 Zoma moves to the left, to the right, to the left again and to the right for the final time, ending up at position $$$0$$$;\n\"\nLRLR\n\" \u2014 Zoma recieves no commands, doesn't move at all and ends up at position $$$0$$$ as well;\n\"\nL\nR\nL\nR\n\" \u2014 Zoma moves to the left, then to the left again and ends up in position $$$-2$$$.\nMezo doesn't know which commands will be sent successfully beforehand. Thus, he wants to know how many different positions may Zoma end up at.\nInput\nThe first line contains $$$n$$$ $$$(1 \\le n \\le 10^5)$$$ \u2014 the number of commands Mezo sends.\nThe second line contains a string $$$s$$$ of $$$n$$$ commands, each either 'L' (Left) or 'R' (Right).\nOutput\nPrint one integer \u2014 the number of different positions Zoma may end up at.\nExample\nInput\n4\nLRLR\nOutput\n5\nNote\nIn the example, Zoma may end up anywhere between $$$-2$$$ and $$$2$$$.", "input": [ [ [ "4" ], [ "LRLR" ] ] ], "output": [ "5" ] }, { "problem_id": "1284A", "problem_name": "New Year and Naming\nimplementation, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1284/A", "problem_solution_link": "https://codeforces.com/problemset/status/1284/problem/A", "problem_statement": "A. New Year and Naming\ntime limit per test\n1 second\nmemory limit per test\n1024 megabytes\ninput\nstandard input\noutput\nstandard output\nHappy new year! The year 2020 is also known as\nYear Gyeongja\n(\uacbd\uc790\ub144,\ngyeongja-nyeon\n) in Korea. Where did the name come from? Let's briefly look at the\nGapja\nsystem, which is traditionally used in Korea to name the years.\nThere are two sequences of $$$n$$$ strings $$$s_1, s_2, s_3, \\ldots, s_{n}$$$ and $$$m$$$ strings $$$t_1, t_2, t_3, \\ldots, t_{m}$$$. These strings contain only lowercase letters. There might be duplicates among these strings.\nLet's call a concatenation of strings $$$x$$$ and $$$y$$$ as the string that is obtained by writing down strings $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, the concatenation of the strings \"\ncode\n\" and \"\nforces\n\" is the string \"\ncodeforces\n\".\nThe year 1 has a name which is the concatenation of the two strings $$$s_1$$$ and $$$t_1$$$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.\nFor example, if $$$n = 3, m = 4, s = $$$\n{\"a\", \"b\", \"c\"}\n, $$$t =$$$\n{\"d\", \"e\", \"f\", \"g\"}\n, the following table denotes the resulting year names. Note that the names of the years may repeat.\nYou are given two sequences of strings of size $$$n$$$ and $$$m$$$ and also $$$q$$$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the\nGapja\nsystem?\nInput\nThe first line contains two integers $$$n, m$$$ ($$$1 \\le n, m \\le 20$$$).\nThe next line contains $$$n$$$ strings $$$s_1, s_2, \\ldots, s_{n}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$.\nThe next line contains $$$m$$$ strings $$$t_1, t_2, \\ldots, t_{m}$$$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $$$1$$$ and at most $$$10$$$.\nAmong the given $$$n + m$$$ strings may be duplicates (that is, they are not necessarily all different).\nThe next line contains a single integer $$$q$$$ ($$$1 \\le q \\le 2\\,020$$$).\nIn the next $$$q$$$ lines, an integer $$$y$$$ ($$$1 \\le y \\le 10^9$$$) is given, denoting the year we want to know the name for.\nOutput\nPrint $$$q$$$ lines. For each line, print the name of the year as per the rule described above.\nExample\nInput\n10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020\nOutput\nsinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja\nNote\nThe first example denotes the actual names used in the\nGapja\nsystem. These strings usually are either a number or the name of some animal.", "input": [ [ [ "10", "12" ], [ "sin", "im", "gye", "gap", "eul", "byeong", "jeong", "mu", "gi", "gyeong" ], [ "yu", "sul", "hae", "ja", "chuk", "in", "myo", "jin", "sa", "o", "mi", "sin" ], ["14"], ["1"], ["2"], ["3"], ["4"], ["10"], ["11"], ["12"], ["13"], ["73"], ["2016"], ["2017"], ["2018"], ["2019"], ["2020"] ] ], "output": [ ["sinyu", "imsul", "gyehae", "gapja", "gyeongo", "sinmi", "imsin", "gyeyu", "gyeyu", "byeongsin", "jeongyu", "musul", "gihae", "gyeongja"] ] }, { "problem_id": "1283A", "problem_name": "Minutes Before the New Year\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1283/A", "problem_solution_link": "https://codeforces.com/problemset/status/1283/problem/A", "problem_statement": "A. Minutes Before the New Year\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nNew Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $$$h$$$ hours and $$$m$$$ minutes, where $$$0 \\le hh < 24$$$ and $$$0 \\le mm < 60$$$.\nWe use 24-hour time format!\nYour task is to find the number of minutes before the New Year. You know that New Year comes when the clock shows $$$0$$$ hours and $$$0$$$ minutes.\nYou have to answer $$$t$$$ independent test cases.\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 1439$$$) \u2014 the number of test cases.\nThe following $$$t$$$ lines describe test cases. The $$$i$$$-th line contains the time as two integers $$$h$$$ and $$$m$$$ ($$$0 \\le h < 24$$$, $$$0 \\le m < 60$$$). It is guaranteed that this time is\nnot\na midnight, i.e. the following two conditions can't be met at the same time: $$$h=0$$$ and $$$m=0$$$. It is guaranteed that both $$$h$$$ and $$$m$$$ are given without leading zeros.\nOutput\nFor each test case, print the answer on it \u2014 the number of minutes before the New Year.\nExample\nInput\n5\n23 55\n23 0\n0 1\n4 20\n23 59\nOutput\n5\n60\n1439\n1180\n1", "input": [ [ [ "23", "55" ] ], [ [ "23", "0" ] ], [ [ "0", "1" ] ], [ [ "4", "20" ] ], [ [ "23", "59" ] ] ], "output": [ "5", "60", "1439", "1180", "1" ] }, { "problem_id": "1281A", "problem_name": "Suffix Three\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1281/A", "problem_solution_link": "https://codeforces.com/problemset/status/1281/problem/A", "problem_statement": "A. Suffix Three\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nWe just discovered a new data structure in our research group: a\nsuffix three\n!\nIt's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.\nIt's super simple, 100% accurate, and doesn't involve advanced machine learning algorithms.\nLet us tell you how it works.\nIf a sentence ends with \"\npo\n\" the language is Filipino.\nIf a sentence ends with \"\ndesu\n\" or \"\nmasu\n\" the language is Japanese.\nIf a sentence ends with \"\nmnida\n\" the language is Korean.\nGiven this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.\nOh, did I say three suffixes? I meant four.\nInput\nThe first line of input contains a single integer $$$t$$$ ($$$1 \\leq t \\leq 30$$$) denoting the number of test cases. The next lines contain descriptions of the test cases.\nEach test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol \"\n_\n\") for ease of reading. The sentence has at least $$$1$$$ and at most $$$1000$$$ characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.\nOutput\nFor each test case, print a single line containing either \"\nFILIPINO\n\", \"\nJAPANESE\n\", or \"\nKOREAN\n\" (all in uppercase, without quotes), depending on the detected language.\nExample\nInput\n8\nkamusta_po\ngenki_desu\nohayou_gozaimasu\nannyeong_hashimnida\nhajime_no_ippo\nbensamu_no_sentou_houhou_ga_okama_kenpo\nang_halaman_doon_ay_sarisari_singkamasu\nsi_roy_mustang_ay_namamasu\nOutput\nFILIPINO\nJAPANESE\nJAPANESE\nKOREAN\nFILIPINO\nFILIPINO\nJAPANESE\nJAPANESE\nNote\nThe first sentence ends with \"\npo\n\", so it is written in Filipino.\nThe second and third sentences end with \"\ndesu\n\" and \"\nmasu\n\", so they are written in Japanese.\nThe fourth sentence ends with \"\nmnida\n\", so it is written in Korean.", "input": [ [ [ "kamusta_po" ] ], [ [ "genki_desu" ] ], [ [ "ohayou_gozaimasu" ] ], [ [ "annyeong_hashimnida" ] ], [ [ "hajime_no_ippo" ] ], [ [ "bensamu_no_sentou_houhou_ga_okama_kenpo" ] ], [ [ "ang_halaman_doon_ay_sarisari_singkamasu" ] ], [ [ "si_roy_mustang_ay_namamasu" ] ] ], "output": [ "FILIPINO", "JAPANESE", "JAPANESE", "KOREAN", "FILIPINO", "FILIPINO", "JAPANESE", "JAPANESE" ] }, { "problem_id": "1271A", "problem_name": "Suits\nbrute force, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1271/A", "problem_solution_link": "https://codeforces.com/problemset/status/1271/problem/A", "problem_statement": "A. Suits\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nA new delivery of clothing has arrived today to the clothing store. This delivery consists of $$$a$$$ ties, $$$b$$$ scarves, $$$c$$$ vests and $$$d$$$ jackets.\nThe store does not sell single clothing items \u2014 instead, it sells suits of two types:\na suit of the first type consists of one tie and one jacket;\na suit of the second type consists of one scarf, one vest and one jacket.\nEach suit of the first type costs $$$e$$$ coins, and each suit of the second type costs $$$f$$$ coins.\nCalculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).\nInput\nThe first line contains one integer $$$a$$$ $$$(1 \\le a \\le 100\\,000)$$$ \u2014 the number of ties.\nThe second line contains one integer $$$b$$$ $$$(1 \\le b \\le 100\\,000)$$$ \u2014 the number of scarves.\nThe third line contains one integer $$$c$$$ $$$(1 \\le c \\le 100\\,000)$$$ \u2014 the number of vests.\nThe fourth line contains one integer $$$d$$$ $$$(1 \\le d \\le 100\\,000)$$$ \u2014 the number of jackets.\nThe fifth line contains one integer $$$e$$$ $$$(1 \\le e \\le 1\\,000)$$$ \u2014 the cost of one suit of the first type.\nThe sixth line contains one integer $$$f$$$ $$$(1 \\le f \\le 1\\,000)$$$ \u2014 the cost of one suit of the second type.\nOutput\nPrint one integer \u2014 the maximum total cost of some set of suits that can be composed from the delivered items.\nExamples\nInput\n4\n5\n6\n3\n1\n2\nOutput\n6\nInput\n12\n11\n13\n20\n4\n6\nOutput\n102\nInput\n17\n14\n5\n21\n15\n17\nOutput\n325\nNote\nIt is possible to compose three suits of the second type in the first example, and their total cost will be $$$6$$$. Since all jackets will be used, it's impossible to add anything to this set.\nThe best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is $$$9 \\cdot 4 + 11 \\cdot 6 = 102$$$.", "input": [ [ "4", "5", "6", "3", "1", "2" ], [ "12", "11", "13", "20", "4", "6" ] ], "output": [ "6", "102" ] }, { "problem_id": "1270A", "problem_name": "Card Game\ngames, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1270/A", "problem_solution_link": "https://codeforces.com/problemset/status/1270/problem/A", "problem_statement": "A. Card Game\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTwo players decided to play one interesting card game.\nThere is a deck of $$$n$$$ cards, with values from $$$1$$$ to $$$n$$$. The values of cards are\npairwise different\n(this means that no two different cards have equal values). At the beginning of the game, the deck is completely distributed between players such that each player has at least one card.\nThe game goes as follows: on each turn, each player chooses one of their cards (whichever they want) and puts on the table, so that the other player doesn't see which card they chose. After that, both cards are revealed, and the player, value of whose card was larger, takes both cards in his hand. Note that as all cards have different values, one of the cards will be strictly larger than the other one. Every card may be played any amount of times. The player loses if he doesn't have any cards.\nFor example, suppose that $$$n = 5$$$, the first player has cards with values $$$2$$$ and $$$3$$$, and the second player has cards with values $$$1$$$, $$$4$$$, $$$5$$$. Then one possible flow of the game is:\nThe first player chooses the card $$$3$$$. The second player chooses the card $$$1$$$. As $$$3>1$$$, the first player gets both cards. Now the first player has cards $$$1$$$, $$$2$$$, $$$3$$$, the second player has cards $$$4$$$, $$$5$$$.\nThe first player chooses the card $$$3$$$. The second player chooses the card $$$4$$$. As $$$3<4$$$, the second player gets both cards. Now the first player has cards $$$1$$$, $$$2$$$. The second player has cards $$$3$$$, $$$4$$$, $$$5$$$.\nThe first player chooses the card $$$1$$$. The second player chooses the card $$$3$$$. As $$$1<3$$$, the second player gets both cards. Now the first player has only the card $$$2$$$. The second player has cards $$$1$$$, $$$3$$$, $$$4$$$, $$$5$$$.\nThe first player chooses the card $$$2$$$. The second player chooses the card $$$4$$$. As $$$2<4$$$, the second player gets both cards. Now the first player is out of cards and loses. Therefore, the second player wins.\nWho will win if both players are playing optimally? It can be shown that one of the players has a winning strategy.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 100$$$). The description of the test cases follows.\nThe first line of each test case contains three integers $$$n$$$, $$$k_1$$$, $$$k_2$$$ ($$$2 \\le n \\le 100, 1 \\le k_1 \\le n - 1, 1 \\le k_2 \\le n - 1, k_1 + k_2 = n$$$)\u00a0\u2014 the number of cards, number of cards owned by the first player and second player correspondingly.\nThe second line of each test case contains $$$k_1$$$ integers $$$a_1, \\dots, a_{k_1}$$$ ($$$1 \\le a_i \\le n$$$)\u00a0\u2014 the values of cards of the first player.\nThe third line of each test case contains $$$k_2$$$ integers $$$b_1, \\dots, b_{k_2}$$$ ($$$1 \\le b_i \\le n$$$)\u00a0\u2014 the values of cards of the second player.\nIt is guaranteed that the values of all cards are different.\nOutput\nFor each test case, output \"\nYES\n\" in a separate line, if the first player wins. Otherwise, output \"\nNO\n\" in a separate line. You can print each letter in any case (upper or lower).\nExample\nInput\n2\n2 1 1\n2\n1\n5 2 3\n2 3\n1 4 5\nOutput\nYES\nNO\nNote\nIn the first test case of the example, there is only one possible move for every player: the first player will put $$$2$$$, the second player will put $$$1$$$. $$$2>1$$$, so the first player will get both cards and will win.\nIn the second test case of the example, it can be shown that it is the second player who has a winning strategy. One possible flow of the game is illustrated in the statement.", "input": [ [ [ "2", "1", "1" ], [ "2" ], [ "1" ] ], [ [ "5", "2", "3" ], [ "2", "3" ], [ "1", "4", "5" ] ] ], "output": [ "YES", "NO" ] }, { "problem_id": "1269A", "problem_name": "Equation\nbrute force, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1269/A", "problem_solution_link": "https://codeforces.com/problemset/status/1269/problem/A", "problem_statement": "A. Equation\ntime limit per test\n3 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's call a positive integer\ncomposite\nif it has at least one divisor other than $$$1$$$ and itself. For example:\nthe following numbers are composite: $$$1024$$$, $$$4$$$, $$$6$$$, $$$9$$$;\nthe following numbers are not composite: $$$13$$$, $$$1$$$, $$$2$$$, $$$3$$$, $$$37$$$.\nYou are given a positive integer $$$n$$$. Find two composite integers $$$a,b$$$ such that $$$a-b=n$$$.\nIt can be proven that solution always exists.\nInput\nThe input contains one integer $$$n$$$ ($$$1 \\leq n \\leq 10^7$$$): the given integer.\nOutput\nPrint two composite integers $$$a,b$$$ ($$$2 \\leq a, b \\leq 10^9, a-b=n$$$).\nIt can be proven, that solution always exists.\nIf there are several possible solutions, you can print any.\nExamples\nInput\n1\nOutput\n9 8\nInput\n512\nOutput\n4608 4096", "input": [ [ [ "Output" ], [ "9", "8" ], [ "Input" ], [ "512" ] ] ], "output": [ "4608 4096" ] }, { "problem_id": "1257A", "problem_name": "Two Rival Students\ngreedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1257/A", "problem_solution_link": "https://codeforces.com/problemset/status/1257/problem/A", "problem_statement": "A. Two Rival Students\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are the gym teacher in the school.\nThere are $$$n$$$ students in the row. And there are two rivalling students among them. The first one is in position $$$a$$$, the second in position $$$b$$$. Positions are numbered from $$$1$$$ to $$$n$$$ from left to right.\nSince they are rivals, you want to maximize the distance between them. If students are in positions $$$p$$$ and $$$s$$$ respectively, then distance between them is $$$|p - s|$$$.\nYou can do the following operation at most $$$x$$$ times: choose two\nadjacent (neighbouring)\nstudents and swap them.\nCalculate the maximum distance between two rivalling students after at most $$$x$$$ swaps.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases.\nThe only line of each test case contains four integers $$$n$$$, $$$x$$$, $$$a$$$ and $$$b$$$ ($$$2 \\le n \\le 100$$$, $$$0 \\le x \\le 100$$$, $$$1 \\le a, b \\le n$$$, $$$a \\neq b$$$) \u2014 the number of students in the row, the number of swaps which you can do, and positions of first and second rivaling students respectively.\nOutput\nFor each test case print one integer \u2014 the maximum distance between two rivaling students which you can obtain.\nExample\nInput\n3\n5 1 3 2\n100 33 100 1\n6 0 2 3\nOutput\n2\n99\n1\nNote\nIn the first test case you can swap students in positions $$$3$$$ and $$$4$$$. And then the distance between the rivals is equal to $$$|4 - 2| = 2$$$.\nIn the second test case you don't have to swap students.\nIn the third test case you can't swap students.", "input": [ [ [ "5", "1", "3", "2" ] ], [ [ "100", "33", "100", "1" ] ], [ [ "6", "0", "2", "3" ] ] ], "output": [ "2", "99", "1" ] }, { "problem_id": "1255A", "problem_name": "Changing Volume\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1255/A", "problem_solution_link": "https://codeforces.com/problemset/status/1255/problem/A", "problem_statement": "A. Changing Volume\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nBob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.\nThere are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.\nAs Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$.\nInput\nEach test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \\le T \\le 1\\,000$$$). Then the descriptions of the test cases follow.\nEach test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \\le a, b \\le 10^{9}$$$)\u00a0\u2014 the current volume and Bob's desired volume, respectively.\nOutput\nFor each test case, output a single integer\u00a0\u2014 the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$.\nExample\nInput\n3\n4 0\n5 14\n3 9\nOutput\n2\n3\n2\nNote\nIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative.\nIn the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.\nIn the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$.", "input": [ [ [ "4", "0" ] ], [ [ "5", "14" ] ], [ [ "3", "9" ] ] ], "output": [ "2", "3", "2" ] }, { "problem_id": "1250F", "problem_name": "Data Center\nbrute force, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1250/F", "problem_solution_link": "https://codeforces.com/problemset/status/1250/problem/F", "problem_statement": "F. Data Center\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are developing a project to build a new data center. The data center will be a rectangle with an area of exactly $$$n$$$ square meters. Each side of the data center must be an integer.\nYour goal is to minimize the impact of the external environment on the data center. For this reason, you want to minimize the length of the perimeter of the data center (that is, the sum of the lengths of its four sides).\nWhat is the minimum perimeter of a rectangular data center with an area of exactly $$$n$$$ square meters, if the lengths of all its sides must be integers?\nInput\nThe first and only line of the input contains an integer $$$n$$$ ($$$1 \\le n \\le 10^5$$$), where $$$n$$$ is the area of the data center in square meters.\nOutput\nPrint the required minimum perimeter in meters.\nExamples\nInput\n36\nOutput\n24\nInput\n13\nOutput\n28\nInput\n1\nOutput\n4\nNote\nIn the first example, the required shape of the data center is $$$6\\times6$$$ square. Its area is $$$36$$$ and the perimeter is $$$6+6+6+6=24$$$.\nIn the second example, the required shape of the data center is $$$1\\times13$$$ rectangle. Its area is $$$13$$$ and the perimeter is $$$1+13+1+13=28$$$.\nIn the third example, the required shape of the data center is $$$1\\times1$$$ square. Its area is $$$1$$$ and the perimeter is $$$1+1+1+1=4$$$.", "input": [ [ ["36"] ], [ ["13"] ], [ ["1"] ] ], "output": [ "24", "28", "4" ] }, { "problem_id": "1249A", "problem_name": "Yet Another Dividing into Teams\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1249/A", "problem_solution_link": "https://codeforces.com/problemset/status/1249/problem/A", "problem_statement": "A. Yet Another Dividing into Teams\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are a coach of a group consisting of $$$n$$$ students. The $$$i$$$-th student has programming skill $$$a_i$$$.\nAll students have distinct programming skills\n. You want to divide them into teams in such a way that:\nNo two students $$$i$$$ and $$$j$$$ such that $$$|a_i - a_j| = 1$$$ belong to the same team (i.e. skills of each pair of students in the same team have the difference strictly greater than $$$1$$$);\nthe number of teams is the minimum possible.\nYou have to answer $$$q$$$ independent queries.\nInput\nThe first line of the input contains one integer $$$q$$$ ($$$1 \\le q \\le 100$$$) \u2014 the number of queries. Then $$$q$$$ queries follow.\nThe first line of the query contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the number of students in the query. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$, all $$$a_i$$$ are distinct), where $$$a_i$$$ is the programming skill of the $$$i$$$-th student.\nOutput\nFor each query, print the answer on it \u2014 the minimum number of teams you can form if no two students $$$i$$$ and $$$j$$$ such that $$$|a_i - a_j| = 1$$$ may belong to the same team (i.e. skills of each pair of students in the same team has the difference strictly greater than $$$1$$$)\nExample\nInput\n4\n4\n2 10 1 20\n2\n3 6\n5\n2 3 4 99 100\n1\n42\nOutput\n2\n1\n2\n1\nNote\nIn the first query of the example, there are $$$n=4$$$ students with the skills $$$a=[2, 10, 1, 20]$$$. There is only one restriction here: the $$$1$$$-st and the $$$3$$$-th students can't be in the same team (because of $$$|a_1 - a_3|=|2-1|=1$$$). It is possible to divide them into $$$2$$$ teams: for example, students $$$1$$$, $$$2$$$ and $$$4$$$ are in the first team and the student $$$3$$$ in the second team.\nIn the second query of the example, there are $$$n=2$$$ students with the skills $$$a=[3, 6]$$$. It is possible to compose just a single team containing both students.", "input": [ [ [ "4" ], [ "2", "10", "1", "20" ] ], [ [ "2" ], [ "3", "6" ] ], [ [ "5" ], [ "2", "3", "4", "99", "100" ] ], [ [ "1" ], [ "42" ] ] ], "output": [ "2", "1", "2", "1" ] }, { "problem_id": "1244A", "problem_name": "Pens and Pencils\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1244/A", "problem_solution_link": "https://codeforces.com/problemset/status/1244/problem/A", "problem_statement": "A. Pens and Pencils\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTomorrow is a difficult day for Polycarp: he has to attend $$$a$$$ lectures and $$$b$$$ practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them.\nWhile preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and draw everything he has to during all of the practical classes. Polycarp writes lectures using a pen (he can't use a pencil to write lectures!); he can write down $$$c$$$ lectures using one pen, and after that it runs out of ink. During practical classes Polycarp draws blueprints with a pencil (he can't use a pen to draw blueprints!); one pencil is enough to draw all blueprints during $$$d$$$ practical classes, after which it is unusable.\nPolycarp's pencilcase can hold no more than $$$k$$$ writing implements, so if Polycarp wants to take $$$x$$$ pens and $$$y$$$ pencils, they will fit in the pencilcase if and only if $$$x + y \\le k$$$.\nNow Polycarp wants to know how many pens and pencils should he take. Help him to determine it, or tell that his pencilcase doesn't have enough room for all the implements he needs tomorrow!\nNote that you don't have to minimize the number of writing implements (though their total number must not exceed $$$k$$$).\nInput\nThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2014 the number of test cases in the input. Then the test cases follow.\nEach test case is described by one line containing five integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ and $$$k$$$, separated by spaces ($$$1 \\le a, b, c, d, k \\le 100$$$) \u2014 the number of lectures Polycarp has to attend, the number of practical classes Polycarp has to attend, the number of lectures which can be written down using one pen, the number of practical classes for which one pencil is enough, and the number of writing implements that can fit into Polycarp's pencilcase, respectively.\nIn hacks\nit is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.\nOutput\nFor each test case, print the answer as follows:\nIf the pencilcase can't hold enough writing implements to use them during all lectures and practical classes, print one integer $$$-1$$$. Otherwise, print two non-negative integers $$$x$$$ and $$$y$$$ \u2014 the number of pens and pencils Polycarp should put in his pencilcase. If there are multiple answers, print any of them. Note that you don't have to minimize the number of writing implements (though their total number must not exceed $$$k$$$).\nExample\nInput\n3\n7 5 4 5 8\n7 5 4 5 2\n20 53 45 26 4\nOutput\n7 1\n-1\n1 3\nNote\nThere are many different answers for the first test case; $$$x = 7$$$, $$$y = 1$$$ is only one of them. For example, $$$x = 3$$$, $$$y = 1$$$ is also correct.\n$$$x = 1$$$, $$$y = 3$$$ is the only correct answer for the third test case.", "input": [ [ [ "7", "5", "4", "5", "8" ] ], [ [ "7", "5", "4", "5", "2" ] ], [ [ "20", "53", "45", "26", "4" ] ] ], "output": [ "7 1", "-1", "1 3" ] }, { "problem_id": "1243A", "problem_name": "Maximum Square\nimplementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1243/A", "problem_solution_link": "https://codeforces.com/problemset/status/1243/problem/A", "problem_statement": "A. Maximum Square\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nUjan decided to make a new wooden roof for the house. He has $$$n$$$ rectangular planks numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th plank has size $$$a_i \\times 1$$$ (that is, the width is $$$1$$$ and the height is $$$a_i$$$).\nNow, Ujan wants to make a square roof. He will first choose some of the planks and place them side by side in some order. Then he will glue together all of these planks by their vertical sides. Finally, he will cut out a square from the resulting shape in such a way that the sides of the square are horizontal and vertical.\nFor example, if Ujan had planks with lengths $$$4$$$, $$$3$$$, $$$1$$$, $$$4$$$ and $$$5$$$, he could choose planks with lengths $$$4$$$, $$$3$$$ and $$$5$$$. Then he can cut out a $$$3 \\times 3$$$ square, which is the maximum possible. Note that this is not the only way he can obtain a $$$3 \\times 3$$$ square.\nWhat is the maximum side length of the square Ujan can get?\nInput\nThe first line of input contains a single integer $$$k$$$ ($$$1 \\leq k \\leq 10$$$), the number of test cases in the input.\nFor each test case, the first line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 1\\,000$$$), the number of planks Ujan has in store. The next line contains $$$n$$$ integers $$$a_1, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq n$$$), the lengths of the planks.\nOutput\nFor each of the test cases, output a single integer, the maximum possible side length of the square.\nExample\nInput\n4\n5\n4 3 1 4 5\n4\n4 4 4 4\n3\n1 1 1\n5\n5 5 1 1 5\nOutput\n3\n4\n1\n3\nNote\nThe first sample corresponds to the example in the statement.\nIn the second sample, gluing all $$$4$$$ planks will result in a $$$4 \\times 4$$$ square.\nIn the third sample, the maximum possible square is $$$1 \\times 1$$$ and can be taken simply as any of the planks.", "input": [ [ [ "5" ], [ "4", "3", "1", "4", "5" ] ], [ [ "4" ], [ "4", "4", "4", "4" ] ], [ [ "3" ], [ "1", "1", "1" ] ], [ [ "5" ], [ "5", "5", "1", "1", "5" ] ] ], "output": [ "3", "4", "1", "3" ] }, { "problem_id": "1236A", "problem_name": "Stones\nbrute force, greedy, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1236/A", "problem_solution_link": "https://codeforces.com/problemset/status/1236/problem/A", "problem_statement": "A. Stones\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAlice is playing with some stones.\nNow there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.\nEach time she can do one of two operations:\ntake one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);\ntake one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).\nShe wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\leq t \\leq 100$$$) \u00a0\u2014 the number of test cases. Next $$$t$$$ lines describe test cases in the following format:\nLine contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \\leq a,b,c \\leq 100$$$)\u00a0\u2014 the number of stones in the first, the second and the third heap, respectively.\nIn hacks\nit is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.\nOutput\nPrint $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer \u00a0\u2014 the maximum possible number of stones that Alice can take after making some operations.\nExample\nInput\n3\n3 4 5\n1 0 5\n5 3 2\nOutput\n9\n0\n6\nNote\nFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.", "input": [ [ [ "3", "4", "5" ] ], [ [ "1", "0", "5" ] ], [ [ "5", "3", "2" ] ] ], "output": [ "9", "0", "6" ] }, { "problem_id": "1234A", "problem_name": "Equalize Prices Again\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1234/A", "problem_solution_link": "https://codeforces.com/problemset/status/1234/problem/A", "problem_statement": "A. Equalize Prices Again\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are both a shop keeper and a shop assistant at a small nearby shop. You have $$$n$$$ goods, the $$$i$$$-th good costs $$$a_i$$$ coins.\nYou got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More precisely you decided to set the same price for all $$$n$$$ goods you have.\nHowever, you don't want to lose any money so you want to choose the price in such a way that the sum of new prices is not less than the sum of the initial prices. It means that if you sell all $$$n$$$ goods for the new price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.\nOn the other hand, you don't want to lose customers because of big prices so among all prices you can choose you need to choose the minimum one.\nSo you need to find the minimum possible equal price of all $$$n$$$ goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.\nYou have to answer $$$q$$$ independent queries.\nInput\nThe first line of the input contains one integer $$$q$$$ ($$$1 \\le q \\le 100$$$) \u2014 the number of queries. Then $$$q$$$ queries follow.\nThe first line of the query contains one integer $$$n$$$ ($$$1 \\le n \\le 100)$$$ \u2014 the number of goods. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^7$$$), where $$$a_i$$$ is the price of the $$$i$$$-th good.\nOutput\nFor each query, print the answer for it \u2014 the minimum possible equal price of all $$$n$$$ goods so if you sell them for this price, you will receive at least the same (or greater) amount of money as if you sell them for their initial prices.\nExample\nInput\n3\n5\n1 2 3 4 5\n3\n1 2 2\n4\n1 1 1 1\nOutput\n3\n2\n1", "input": [ [ [ "5" ], [ "1", "2", "3", "4", "5" ] ], [ [ "3" ], [ "1", "2", "2" ] ], [ [ "4" ], [ "1", "1", "1", "1" ] ] ], "output": [ "3", "2", "1" ] }, { "problem_id": "1230A", "problem_name": "Dawid and Bags of Candies\nbrute force, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1230/A", "problem_solution_link": "https://codeforces.com/problemset/status/1230/problem/A", "problem_statement": "A. Dawid and Bags of Candies\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nDawid has four bags of candies. The $$$i$$$-th of them contains $$$a_i$$$ candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?\nNote, that you can't keep bags for yourself or throw them away, each bag should be given to one of the friends.\nInput\nThe only line contains four integers $$$a_1$$$, $$$a_2$$$, $$$a_3$$$ and $$$a_4$$$ ($$$1 \\leq a_i \\leq 100$$$) \u2014 the numbers of candies in each bag.\nOutput\nOutput\nYES\nif it's possible to give the bags to Dawid's friends so that both friends receive the same amount of candies, or\nNO\notherwise. Each character can be printed in any case (either uppercase or lowercase).\nExamples\nInput\n1 7 11 5\nOutput\nYES\nInput\n7 3 2 5\nOutput\nNO\nNote\nIn the first sample test, Dawid can give the first and the third bag to the first friend, and the second and the fourth bag to the second friend. This way, each friend will receive $$$12$$$ candies.\nIn the second sample test, it's impossible to distribute the bags.", "input": [ [ [ "1", "7", "11", "5" ] ], [ [ "7", "3", "2", "5" ] ] ], "output": [ "YES", "NO" ] }, { "problem_id": "1228A", "problem_name": "Distinct Digits\nbrute force, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1228/A", "problem_solution_link": "https://codeforces.com/problemset/status/1228/problem/A", "problem_statement": "A. Distinct Digits\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have two integers $$$l$$$ and $$$r$$$. Find an integer $$$x$$$ which satisfies the conditions below:\n$$$l \\le x \\le r$$$.\nAll digits of $$$x$$$ are different.\nIf there are multiple answers, print any of them.\nInput\nThe first line contains two integers $$$l$$$ and $$$r$$$ ($$$1 \\le l \\le r \\le 10^{5}$$$).\nOutput\nIf an answer exists, print any of them. Otherwise, print $$$-1$$$.\nExamples\nInput\n121 130\nOutput\n123\nInput\n98766 100000\nOutput\n-1\nNote\nIn the first example, $$$123$$$ is one of the possible answers. However, $$$121$$$ can't be the answer, because there are multiple $$$1$$$s on different digits.\nIn the second example, there is no valid answer.", "input": [ [ [ "121", "130" ] ], [ [ "98766", "100000" ] ] ], "output": [ "123", "-1" ] }, { "problem_id": "1223A", "problem_name": "CME\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1223/A", "problem_solution_link": "https://codeforces.com/problemset/status/1223/problem/A", "problem_statement": "A. CME\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nLet's denote\ncorrect match equation\n(we will denote it as CME) an equation $$$a + b = c$$$ there all integers $$$a$$$, $$$b$$$ and $$$c$$$ are greater than zero.\nFor example, equations $$$2 + 2 = 4$$$ (\n||+||=||||\n) and $$$1 + 2 = 3$$$ (\n|+||=|||\n) are CME but equations $$$1 + 2 = 4$$$ (\n|+||=||||\n), $$$2 + 2 = 3$$$ (\n||+||=|||\n), and $$$0 + 1 = 1$$$ (\n+|=|\n) are not.\nNow, you have $$$n$$$ matches. You want to assemble a CME using\nall\nyour matches. Unfortunately, it is possible that you can't assemble the CME using all matches. But you can buy some extra matches and then assemble CME!\nFor example, if $$$n = 2$$$, you can buy two matches and assemble\n|+|=||\n, and if $$$n = 5$$$ you can buy one match and assemble\n||+|=|||\n.\nCalculate the minimum number of matches which you have to buy for assembling CME.\nNote, that you have to answer $$$q$$$ independent queries.\nInput\nThe first line contains one integer $$$q$$$ ($$$1 \\le q \\le 100$$$)\u00a0\u2014 the number of queries.\nThe only line of each query contains one integer $$$n$$$ ($$$2 \\le n \\le 10^9$$$)\u00a0\u2014 the number of matches.\nOutput\nFor each test case print one integer in single line\u00a0\u2014 the minimum number of matches which you have to buy for assembling CME.\nExample\nInput\n4\n2\n5\n8\n11\nOutput\n2\n1\n0\n1\nNote\nThe first and second queries are explained in the statement.\nIn the third query, you can assemble $$$1 + 3 = 4$$$ (\n|+|||=||||\n) without buying matches.\nIn the fourth query, buy one match and assemble $$$2 + 4 = 6$$$ (\n||+||||=||||||\n).", "input": [ [ [ "2" ] ], [ [ "5" ] ], [ [ "8" ] ], [ [ "11" ] ] ], "output": [ "2", "1", "0", "1" ] }, { "problem_id": "1220A", "problem_name": "Cards\nimplementation, sortings, strings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1220/A", "problem_solution_link": "https://codeforces.com/problemset/status/1220/problem/A", "problem_statement": "A. Cards\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nWhen Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided to rearrange them. Help him restore the original number, on condition that it was the maximum possible one.\nInput\nThe first line contains a single integer $$$n$$$ ($$$1 \\leqslant n \\leqslant 10^5$$$)\u00a0\u2014 the length of the string. The second line contains a string consisting of English lowercase letters: '\nz\n', '\ne\n', '\nr\n', '\no\n' and '\nn\n'.\nIt is guaranteed that it is possible to rearrange the letters in such a way that they form a sequence of words, each being either \"\nzero\n\" which corresponds to the digit $$$0$$$ or \"\none\n\" which corresponds to the digit $$$1$$$.\nOutput\nPrint the maximum possible number in binary notation. Print binary digits separated by a space. The leading zeroes are allowed.\nExamples\nInput\n4\nezor\nOutput\n0\nInput\n10\nnznooeeoer\nOutput\n1 1 0\nNote\nIn the first example, the correct initial ordering is \"\nzero\n\".\nIn the second example, the correct initial ordering is \"\noneonezero\n\".", "input": [ [ ["4"], ["ezor"] ], [ ["10"], ["nznooeeoer"] ] ], "output": [ "0", "1 1 0" ] }, { "problem_id": "1216A", "problem_name": "Prefixes\nstrings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1216/A", "problem_solution_link": "https://codeforces.com/problemset/status/1216/problem/A", "problem_statement": "A. Prefixes\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nNikolay got a string $$$s$$$ of\neven\nlength $$$n$$$, which consists only of lowercase Latin letters '\na\n' and '\nb\n'. Its positions are numbered from $$$1$$$ to $$$n$$$.\nHe wants to modify his string so that every its prefix of\neven\nlength has an equal amount of letters '\na\n' and '\nb\n'. To achieve that, Nikolay can perform the following operation arbitrary number of times (possibly, zero): choose some position in his string and replace the letter on this position with the other letter (i.e. replace '\na\n' with '\nb\n' or replace '\nb\n' with '\na\n'). Nikolay can use no letters except '\na\n' and '\nb\n'.\nThe prefix of string $$$s$$$ of length $$$l$$$ ($$$1 \\le l \\le n$$$) is a string $$$s[1..l]$$$.\nFor example, for the string $$$s=$$$\"abba\" there are two prefixes of the even length. The first is $$$s[1\\dots2]=$$$\"ab\" and the second $$$s[1\\dots4]=$$$\"abba\". Both of them have the same number of '\na\n' and '\nb\n'.\nYour task is to calculate the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of\neven\nlength has an equal amount of letters '\na\n' and '\nb\n'.\nInput\nThe first line of the input contains one\neven\ninteger $$$n$$$ $$$(2 \\le n \\le 2\\cdot10^{5})$$$ \u2014 the length of string $$$s$$$.\nThe second line of the input contains the string $$$s$$$ of length $$$n$$$, which consists only of lowercase Latin letters '\na\n' and '\nb\n'.\nOutput\nIn the first line print the minimum number of operations Nikolay has to perform with the string $$$s$$$ to modify it so that every its prefix of\neven\nlength has an equal amount of letters '\na\n' and '\nb\n'.\nIn the second line print the string Nikolay obtains after applying all the operations. If there are multiple answers, you can print any of them.\nExamples\nInput\n4\nbbbb\nOutput\n2\nabba\nInput\n6\nababab\nOutput\n0\nababab\nInput\n2\naa\nOutput\n1\nba\nNote\nIn the first example Nikolay has to perform two operations. For example, he can replace the first '\nb\n' with '\na\n' and the last '\nb\n' with '\na\n'.\nIn the second example Nikolay doesn't need to do anything because each prefix of an even length of the initial string already contains an equal amount of letters '\na\n' and '\nb\n'.", "input": [ [ ["4"], ["bbbb"] ], [ ["6"], ["ababab"] ], [ ["2"], ["aa"] ] ], "output": [ "2\nabba", "0\nababab", "1\nba" ] }, { "problem_id": "1209A", "problem_name": "Paint the Numbers\ngreedy, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1209/A", "problem_solution_link": "https://codeforces.com/problemset/status/1209/problem/A", "problem_statement": "A. Paint the Numbers\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given a sequence of integers $$$a_1, a_2, \\dots, a_n$$$. You need to paint elements in colors, so that:\nIf we consider any color, all elements of this color must be divisible by the minimal element of this color.\nThe number of used colors must be minimized.\nFor example, it's fine to paint elements $$$[40, 10, 60]$$$ in a single color, because they are all divisible by $$$10$$$. You can use any color an arbitrary amount of times (in particular, it is allowed to use a color only once). The elements painted in one color do not need to be consecutive.\nFor example, if $$$a=[6, 2, 3, 4, 12]$$$ then two colors are required: let's paint $$$6$$$, $$$3$$$ and $$$12$$$ in the first color ($$$6$$$, $$$3$$$ and $$$12$$$ are divisible by $$$3$$$) and paint $$$2$$$ and $$$4$$$ in the second color ($$$2$$$ and $$$4$$$ are divisible by $$$2$$$). For example, if $$$a=[10, 7, 15]$$$ then $$$3$$$ colors are required (we can simply paint each element in an unique color).\nInput\nThe first line contains an integer $$$n$$$ ($$$1 \\le n \\le 100$$$), where $$$n$$$ is the length of the given sequence.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$). These numbers can contain duplicates.\nOutput\nPrint the minimal number of colors to paint all the given numbers in a valid way.\nExamples\nInput\n6\n10 2 3 5 4 2\nOutput\n3\nInput\n4\n100 100 100 100\nOutput\n1\nInput\n8\n7 6 5 4 3 2 2 3\nOutput\n4\nNote\nIn the first example, one possible way to paint the elements in $$$3$$$ colors is:\npaint in the first color the elements: $$$a_1=10$$$ and $$$a_4=5$$$,\npaint in the second color the element $$$a_3=3$$$,\npaint in the third color the elements: $$$a_2=2$$$, $$$a_5=4$$$ and $$$a_6=2$$$.\nIn the second example, you can use one color to paint all the elements.\nIn the third example, one possible way to paint the elements in $$$4$$$ colors is:\npaint in the first color the elements: $$$a_4=4$$$, $$$a_6=2$$$ and $$$a_7=2$$$,\npaint in the second color the elements: $$$a_2=6$$$, $$$a_5=3$$$ and $$$a_8=3$$$,\npaint in the third color the element $$$a_3=5$$$,\npaint in the fourth color the element $$$a_1=7$$$.", "input": [ [ [ "6" ], [ "10", "2", "3", "5", "4", "2" ] ], [ [ "4" ], [ "100", "100", "100", "100" ] ] ], "output": [ "3", "1" ] }, { "problem_id": "1207A", "problem_name": "There Are Two Types Of Burgers\nbrute force, greedy, implementation, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1207/A", "problem_solution_link": "https://codeforces.com/problemset/status/1207/problem/A", "problem_statement": "A. There Are Two Types Of Burgers\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nThere are two types of burgers in your restaurant \u2014 hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet.\nYou have $$$b$$$ buns, $$$p$$$ beef patties and $$$f$$$ chicken cutlets in your restaurant. You can sell one hamburger for $$$h$$$ dollars and one chicken burger for $$$c$$$ dollars. Calculate the maximum profit you can achieve.\nYou have to answer $$$t$$$ independent queries.\nInput\nThe first line contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) \u2013 the number of queries.\nThe first line of each query contains three integers $$$b$$$, $$$p$$$ and $$$f$$$ ($$$1 \\le b, ~p, ~f \\le 100$$$) \u2014 the number of buns, beef patties and chicken cutlets in your restaurant.\nThe second line of each query contains two integers $$$h$$$ and $$$c$$$ ($$$1 \\le h, ~c \\le 100$$$) \u2014 the hamburger and chicken burger prices in your restaurant.\nOutput\nFor each query print one integer \u2014 the maximum profit you can achieve.\nExample\nInput\n3\n15 2 3\n5 10\n7 5 2\n10 12\n1 100 100\n100 100\nOutput\n40\n34\n0\nNote\nIn first query you have to sell two hamburgers and three chicken burgers. Your income is $$$2 \\cdot 5 + 3 \\cdot 10 = 40$$$.\nIn second query you have to ell one hamburgers and two chicken burgers. Your income is $$$1 \\cdot 10 + 2 \\cdot 12 = 34$$$.\nIn third query you can not create any type of burgers because because you have only one bun. So your income is zero.", "input": [ [ [ "15", "2", "3" ], [ "5", "10" ] ], [ [ "7", "5", "2" ], [ "10", "12" ] ], [ [ "1", "100", "100" ], [ "100", "100" ] ] ], "output": [ "40", "34", "0" ] }, { "problem_id": "1206A", "problem_name": "Choose Two Numbers\nmath, sortings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1206/A", "problem_solution_link": "https://codeforces.com/problemset/status/1206/problem/A", "problem_statement": "A. Choose Two Numbers\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou are given an array $$$A$$$, consisting of $$$n$$$ positive integers $$$a_1, a_2, \\dots, a_n$$$, and an array $$$B$$$, consisting of $$$m$$$ positive integers $$$b_1, b_2, \\dots, b_m$$$.\nChoose some element $$$a$$$ of $$$A$$$ and some element $$$b$$$ of $$$B$$$ such that $$$a+b$$$ doesn't belong to $$$A$$$ and doesn't belong to $$$B$$$.\nFor example, if $$$A = [2, 1, 7]$$$ and $$$B = [1, 3, 4]$$$, we can choose $$$1$$$ from $$$A$$$ and $$$4$$$ from $$$B$$$, as number $$$5 = 1 + 4$$$ doesn't belong to $$$A$$$ and doesn't belong to $$$B$$$. However, we can't choose $$$2$$$ from $$$A$$$ and $$$1$$$ from $$$B$$$, as $$$3 = 2 + 1$$$ belongs to $$$B$$$.\nIt can be shown that such a pair exists. If there are multiple answers, print any.\nChoose and print any such two numbers.\nInput\nThe first line contains one integer $$$n$$$ ($$$1\\le n \\le 100$$$)\u00a0\u2014 the number of elements of $$$A$$$.\nThe second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 200$$$)\u00a0\u2014 the elements of $$$A$$$.\nThe third line contains one integer $$$m$$$ ($$$1\\le m \\le 100$$$)\u00a0\u2014 the number of elements of $$$B$$$.\nThe fourth line contains $$$m$$$ different integers $$$b_1, b_2, \\dots, b_m$$$ ($$$1 \\le b_i \\le 200$$$)\u00a0\u2014 the elements of $$$B$$$.\nIt can be shown that the answer always exists.\nOutput\nOutput two numbers $$$a$$$ and $$$b$$$ such that $$$a$$$ belongs to $$$A$$$, $$$b$$$ belongs to $$$B$$$, but $$$a+b$$$ doesn't belong to nor $$$A$$$ neither $$$B$$$.\nIf there are multiple answers, print any.\nExamples\nInput\n1\n20\n2\n10 20\nOutput\n20 20\nInput\n3\n3 2 2\n5\n1 5 7 7 9\nOutput\n3 1\nInput\n4\n1 3 5 7\n4\n7 5 3 1\nOutput\n1 1\nNote\nIn the first example, we can choose $$$20$$$ from array $$$[20]$$$ and $$$20$$$ from array $$$[10, 20]$$$. Number $$$40 = 20 + 20$$$ doesn't belong to any of those arrays. However, it is possible to choose $$$10$$$ from the second array too.\nIn the second example, we can choose $$$3$$$ from array $$$[3, 2, 2]$$$ and $$$1$$$ from array $$$[1, 5, 7, 7, 9]$$$. Number $$$4 = 3 + 1$$$ doesn't belong to any of those arrays.\nIn the third example, we can choose $$$1$$$ from array $$$[1, 3, 5, 7]$$$ and $$$1$$$ from array $$$[7, 5, 3, 1]$$$. Number $$$2 = 1 + 1$$$ doesn't belong to any of those arrays.", "input": [ [ [ "20" ], [ "2" ], [ "10", "20" ], [ "Output" ], [ "20", "20" ], [ "Input" ], [ "3" ], [ "3", "2", "2" ], [ "5" ], [ "1", "5", "7", "7", "9" ], [ "Output" ], [ "3", "1" ], [ "Input" ], [ "4" ], [ "1", "3", "5", "7" ], [ "4" ], [ "7", "5", "3", "1" ] ] ], "output": [ "1 1" ] }, { "problem_id": "1200A", "problem_name": "Hotelier\nbrute force, data structures, implementation", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1200/A", "problem_solution_link": "https://codeforces.com/problemset/status/1200/problem/A", "problem_statement": "A. Hotelier\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAmugae has a hotel consisting of $$$10$$$ rooms. The rooms are numbered from $$$0$$$ to $$$9$$$ from left to right.\nThe hotel has two entrances \u2014 one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance.\nOne day, Amugae lost the room assignment list. Thankfully Amugae's memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae's memory.\nInput\nThe first line consists of an integer $$$n$$$ ($$$1 \\le n \\le 10^5$$$), the number of events in Amugae's memory.\nThe second line consists of a string of length $$$n$$$ describing the events in chronological order. Each character represents:\n'\nL\n': A customer arrives from the left entrance.\n'\nR\n': A customer arrives from the right entrance.\n'\n0\n', '\n1\n', ..., '\n9\n': The customer in room $$$x$$$ ($$$0$$$, $$$1$$$, ..., $$$9$$$ respectively) leaves.\nIt is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room $$$x$$$ when $$$x$$$ ($$$0$$$, $$$1$$$, ..., $$$9$$$) is given. Also, all the rooms are initially empty.\nOutput\nIn the only line, output the hotel room's assignment status, from room $$$0$$$ to room $$$9$$$. Represent an empty room as '\n0\n', and an occupied room as '\n1\n', without spaces.\nExamples\nInput\n8\nLLRL1RL1\nOutput\n1010000011\nInput\n9\nL0L0LLRR9\nOutput\n1100000010\nNote\nIn the first example, hotel room's assignment status after each action is as follows.\nFirst of all, all rooms are empty. Assignment status is\n0000000000\n.\nL\n: a customer arrives to the hotel through the left entrance. Assignment status is\n1000000000\n.\nL\n: one more customer from the left entrance. Assignment status is\n1100000000\n.\nR\n: one more customer from the right entrance. Assignment status is\n1100000001\n.\nL\n: one more customer from the left entrance. Assignment status is\n1110000001\n.\n1\n: the customer in room $$$1$$$ leaves. Assignment status is\n1010000001\n.\nR\n: one more customer from the right entrance. Assignment status is\n1010000011\n.\nL\n: one more customer from the left entrance. Assignment status is\n1110000011\n.\n1\n: the customer in room $$$1$$$ leaves. Assignment status is\n1010000011\n.\nSo after all, hotel room's final assignment status is\n1010000011\n.\nIn the second example, hotel room's assignment status after each action is as follows.\nL\n: a customer arrives to the hotel through the left entrance. Assignment status is\n1000000000\n.\n0\n: the customer in room $$$0$$$ leaves. Assignment status is\n0000000000\n.\nL\n: a customer arrives to the hotel through the left entrance. Assignment status is\n1000000000\nagain.\n0\n: the customer in room $$$0$$$ leaves. Assignment status is\n0000000000\n.\nL\n: a customer arrives to the hotel through the left entrance. Assignment status is\n1000000000\n.\nL\n: one more customer from the left entrance. Assignment status is\n1100000000\n.\nR\n: one more customer from the right entrance. Assignment status is\n1100000001\n.\nR\n: one more customer from the right entrance. Assignment status is\n1100000011\n.\n9\n: the customer in room $$$9$$$ leaves. Assignment status is\n1100000010\n.\nSo after all, hotel room's final assignment status is\n1100000010\n.", "input": [ [ [ "8" ], [ "LLRL1RL1" ] ], [ [ "9" ], [ "L0L0LLRR9" ] ] ], "output": [ "1010000011", "1100000010" ] }, { "problem_id": "1196A", "problem_name": "Three Piles of Candies\nbrute force, constructive algorithms, math", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1196/A", "problem_solution_link": "https://codeforces.com/problemset/status/1196/problem/A", "problem_statement": "A. Three Piles of Candies\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAlice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.\nAfter taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.\nAlice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).\nYou have to answer $$$q$$$ independent queries.\nLet's see the following example: $$$[1, 3, 4]$$$. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob\u00a0\u2014 then Alice has $$$4$$$ candies, and Bob has $$$4$$$ candies.\nAnother example is $$$[1, 10, 100]$$$. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes $$$54$$$ candies, and Alice takes $$$46$$$ candies. Now Bob has $$$55$$$ candies, and Alice has $$$56$$$ candies, so she has to discard one candy\u00a0\u2014 and after that, she has $$$55$$$ candies too.\nInput\nThe first line of the input contains one integer $$$q$$$ ($$$1 \\le q \\le 1000$$$)\u00a0\u2014 the number of queries. Then $$$q$$$ queries follow.\nThe only line of the query contains three integers $$$a, b$$$ and $$$c$$$ ($$$1 \\le a, b, c \\le 10^{16}$$$)\u00a0\u2014 the number of candies in the first, second and third piles correspondingly.\nOutput\nPrint $$$q$$$ lines. The $$$i$$$-th line should contain the answer for the $$$i$$$-th query\u00a0\u2014 the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).\nExample\nInput\n4\n1 3 4\n1 10 100\n10000000000000000 10000000000000000 10000000000000000\n23 34 45\nOutput\n4\n55\n15000000000000000\n51", "input": [ [ [ "1", "3", "4" ] ], [ [ "1", "10", "100" ] ], [ [ "10000000000000000", "10000000000000000", "10000000000000000" ] ], [ [ "23", "34", "45" ] ] ], "output": [ "4", "55", "15000000000000000", "51" ] }, { "problem_id": "1194A", "problem_name": "Remove a Progression\nmath", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1194/A", "problem_solution_link": "https://codeforces.com/problemset/status/1194/problem/A", "problem_statement": "A. Remove a Progression\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nYou have a list of numbers from $$$1$$$ to $$$n$$$ written from left to right on the blackboard.\nYou perform an algorithm consisting of several steps (steps are $$$1$$$-indexed). On the $$$i$$$-th step you wipe the $$$i$$$-th number (considering only\nremaining\nnumbers). You wipe\nthe whole number\n(not one digit).\nWhen there are less than $$$i$$$ numbers remaining, you stop your algorithm.\nNow you wonder: what is the value of the $$$x$$$-th remaining number after the algorithm is stopped?\nInput\nThe first line contains one integer $$$T$$$ ($$$1 \\le T \\le 100$$$) \u2014 the number of queries. The next $$$T$$$ lines contain queries \u2014 one per line. All queries are independent.\nEach line contains two space-separated integers $$$n$$$ and $$$x$$$ ($$$1 \\le x < n \\le 10^{9}$$$) \u2014 the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least $$$x$$$ numbers.\nOutput\nPrint $$$T$$$ integers (one per query) \u2014 the values of the $$$x$$$-th number after performing the algorithm for the corresponding queries.\nExample\nInput\n3\n3 1\n4 2\n69 6\nOutput\n2\n4\n12", "input": [ [ [ "3", "1" ] ], [ [ "4", "2" ] ], [ [ "69", "6" ] ] ], "output": [ "2", "4", "12" ] }, { "problem_id": "1191A", "problem_name": "Tokitsukaze and Enhancement\nbrute force", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1191/A", "problem_solution_link": "https://codeforces.com/problemset/status/1191/problem/A", "problem_statement": "A. Tokitsukaze and Enhancement\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nTokitsukaze is one of the characters in the game \"Kantai Collection\". In this game, every character has a common attribute\u00a0\u2014 health points, shortened to HP.\nIn general, different values of HP are grouped into $$$4$$$ categories:\nCategory $$$A$$$ if HP is in the form of $$$(4 n + 1)$$$, that is, when divided by $$$4$$$, the remainder is $$$1$$$;\nCategory $$$B$$$ if HP is in the form of $$$(4 n + 3)$$$, that is, when divided by $$$4$$$, the remainder is $$$3$$$;\nCategory $$$C$$$ if HP is in the form of $$$(4 n + 2)$$$, that is, when divided by $$$4$$$, the remainder is $$$2$$$;\nCategory $$$D$$$ if HP is in the form of $$$4 n$$$, that is, when divided by $$$4$$$, the remainder is $$$0$$$.\nThe above-mentioned $$$n$$$ can be any integer.\nThese $$$4$$$ categories ordered from highest to lowest as $$$A > B > C > D$$$, which means category $$$A$$$ is the highest and category $$$D$$$ is the lowest.\nWhile playing the game, players can increase the HP of the character. Now, Tokitsukaze wants you to increase her HP by at most $$$2$$$ (that is, either by $$$0$$$, $$$1$$$ or $$$2$$$). How much should she increase her HP so that it has the highest possible category?\nInput\nThe only line contains a single integer $$$x$$$ ($$$30 \\leq x \\leq 100$$$)\u00a0\u2014 the value Tokitsukaze's HP currently.\nOutput\nPrint an integer $$$a$$$ ($$$0 \\leq a \\leq 2$$$) and an uppercase letter $$$b$$$ ($$$b \\in \\lbrace A, B, C, D \\rbrace$$$), representing that the best way is to increase her HP by $$$a$$$, and then the category becomes $$$b$$$.\nNote that the output characters are case-sensitive.\nExamples\nInput\n33\nOutput\n0 A\nInput\n98\nOutput\n1 B\nNote\nFor the first example, the category of Tokitsukaze's HP is already $$$A$$$, so you don't need to enhance her ability.\nFor the second example:\nIf you don't increase her HP, its value is still $$$98$$$, which equals to $$$(4 \\times 24 + 2)$$$, and its category is $$$C$$$.\nIf you increase her HP by $$$1$$$, its value becomes $$$99$$$, which equals to $$$(4 \\times 24 + 3)$$$, and its category becomes $$$B$$$.\nIf you increase her HP by $$$2$$$, its value becomes $$$100$$$, which equals to $$$(4 \\times 25)$$$, and its category becomes $$$D$$$.\nTherefore, the best way is to increase her HP by $$$1$$$ so that the category of her HP becomes $$$B$$$.", "input": [ [ "33" ], [ "98" ] ], "output": [ "0, A", "1, B" ] }, { "problem_id": "1189A", "problem_name": "Keanu Reeves\nstrings", "problem_difficulty": 800, "problem_link": "https://codeforces.com/problemset/problem/1189/A", "problem_solution_link": "https://codeforces.com/problemset/status/1189/problem/A", "problem_statement": "A. Keanu Reeves\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\nAfter playing Neo in the legendary \"\nMatrix\n\" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.\nLet's call a string consisting of only zeroes and ones\ngood\nif it contains\ndifferent\nnumbers of zeroes and ones. For example,\n1\n,\n101\n,\n0000\nare good, while\n01\n,\n1001\n, and\n111000\nare not good.\nWe are given a string $$$s$$$ of length $$$n$$$ consisting of only zeroes and ones. We need to cut $$$s$$$ into\nminimal possible\nnumber of substrings $$$s_1, s_2, \\ldots, s_k$$$ such that\nall\nof them are good. More formally, we have to find\nminimal\nby number of strings sequence of good strings $$$s_1, s_2, \\ldots, s_k$$$ such that their concatenation (joining) equals $$$s$$$, i.e. $$$s_1 + s_2 + \\dots + s_k = s$$$.\nFor example, cuttings\n110010\ninto\n110\nand\n010\nor into\n11\nand\n0010\nare valid, as\n110\n,\n010\n,\n11\n,\n0010\nare all good, and we can't cut\n110010\nto the smaller number of substrings as\n110010\nisn't good itself. At the same time, cutting of\n110010\ninto\n1100\nand\n10\nisn't valid as both strings aren't good. Also, cutting of\n110010\ninto\n1\n,\n1\n,\n0010\nisn't valid, as it isn't minimal, even though all $$$3$$$ strings are good.\nCan you help Keanu? We can show that the solution always exists. If there are multiple optimal answers, print any.\nInput\nThe first line of the input contains a single integer $$$n$$$ ($$$1\\le n \\le 100$$$)\u00a0\u2014 the length of the string $$$s$$$.\nThe second line contains the string $$$s$$$ of length $$$n$$$ consisting only from zeros and ones.\nOutput\nIn the first line, output a single integer $$$k$$$ ($$$1\\le k$$$)\u00a0\u2014 a\nminimal\nnumber of strings you have cut $$$s$$$ into.\nIn the second line, output $$$k$$$ strings $$$s_1, s_2, \\ldots, s_k$$$ separated with spaces. The length of each string has to be positive. Their concatenation has to be equal to $$$s$$$ and all of them have to be good.\nIf there are multiple answers, print any.\nExamples\nInput\n1\n1\nOutput\n1\n1\nInput\n2\n10\nOutput\n2\n1 0\nInput\n6\n100011\nOutput\n2\n100 011\nNote\nIn the first example, the string\n1\nwasn't cut at all. As it is good, the condition is satisfied.\nIn the second example,\n1\nand\n0\nboth are good. As\n10\nisn't good, the answer is indeed minimal.\nIn the third example,\n100\nand\n011\nboth are good. As\n100011\nisn't good, the answer is indeed minimal.", "input": [ [ [ "1" ], [ "Output" ], [ "1" ], [ "1" ], [ "Input" ], [ "2" ], [ "10" ], [ "Output" ], [ "2" ], [ "1", "0" ], [ "Input" ], [ "6" ], [ "100011" ] ] ], "output": [ ["2", "100 011"] ], "error": true } ]