messages listlengths 1 1 | ground_truth stringlengths 156 726k | dataset stringclasses 1
value |
|---|---|---|
[
{
"content": "Example\n\nInput\n\n4 3\n1000 1\n2000 2\n3000 3\n\n\nOutput\n\n2 3 4 4\n\nWrite Python code to solve this problem. Your program should read the input from stdin and write the output to stdout. Enclose your complete solution in a single ```python code block.",
"role": "user"
}
] | [{"input": "25 1\n1010 1\n3784 7\n3000 6", "output": "2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"}, {"input": "25 2\n1011 2\n2889 1\n308 2", "output": "3 3 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"}, {"input": "20 3\n0010 1\n4107 3\n4267 4", "output": "2 2 2 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"}, {"inpu... | code_stdio |
[
{
"content": "There is a data which provides heights (in meter) of mountains. The data is only for ten mountains.\n\nWrite a program which prints heights of the top three mountains in descending order.\n\nConstraints\n\n0 ≤ height of mountain (integer) ≤ 10,000\n\nInput\n\n\nHeight of mountain 1\nHeight of moun... | [{"input": "1819\n2003\n1094\n2489\n1723\n492\n4419\n2848\n2834\n1724", "output": "4419\n2848\n2834\n"}, {"input": "1819\n2003\n1094\n2489\n1142\n492\n4419\n4289\n2834\n1724", "output": "4419\n4289\n2834\n"}, {"input": "1819\n2003\n876\n2840\n1723\n1799\n3776\n2848\n1592\n922", "output": "3776\n2848\n2840\n"}, {"input"... | code_stdio |
[
{
"content": "One day Jeff got hold of an integer sequence a_1, a_2, ..., a_{n} of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold:\n\n x occurs in sequence a. Consider all positions of numbers x in the sequence a (such... | [{"input": "12\n10 19 7 3 1 8 15 17 14 9 4 5\n", "output": "12\n1 0\n3 0\n4 0\n5 0\n7 0\n8 0\n9 0\n10 0\n14 0\n15 0\n17 0\n19 0\n"}, {"input": "12\n10 19 7 3 1 8 15 17 14 15 4 5\n", "output": "11\n1 0\n3 0\n4 0\n5 0\n7 0\n8 0\n10 0\n14 0\n15 3\n17 0\n19 0\n"}, {"input": "12\n10 19 7 3 3 8 15 17 14 9 4 5\n", "output": "... | code_stdio |
[
{
"content": "You are given N points (x_i,y_i) located on a two-dimensional plane.\nConsider a subset S of the N points that forms a convex polygon.\nHere, we say a set of points S forms a convex polygon when there exists a convex polygon with a positive area that has the same set of vertices as S. All the inte... | [{"input": "200\n6961 9533\n1847 2184\n9391 1072\n8146 7944\n3403 1703\n2280 4570\n8872 8035\n9417 8677\n8552 1719\n6602 3237\n6223 2519\n654 7141\n8494 2638\n7204 8528\n1352 3164\n1638 4388\n1102 7239\n3795 5213\n6836 786\n9662 2985\n6241 9368\n1325 8963\n1237 5004\n8000 5104\n9833 4105\n8543 3581\n9753 6278\n7003 822... | code_stdio |
[
{
"content": "ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bil... | [{"input": "58 5\n1 6 9 18 34 41 82 99 164 179 183 204 240 396 636 1224 2023 2856 4488 4705 5712 9180 9266 18360 18850 20270 23086 60810 190701 197064 211140 214200 222970 243240 263510 314442 425670 486480 708288 789888 1009800 1025349 1054040 1094580 1325184 1579776 1748076 2050698 2635100 2895984 2918880 3975552 428... | code_stdio |
[
{
"content": "This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem.\n\nYou are given an array $a$ of $n$ integers (the given array can contain equal elements). You can perform the followi... | [{"input": "9\n5\n4 7 2 2 10\n5\n5 0 2 1 11\n5\n1 2 2 4 0\n2\n0 1\n3\n0 1 0\n4\n0 2 0 0\n4\n0 1 0 1\n4\n0 1 0 2\n20\n16 15 1 10 0 14 0 10 3 16 0 5 4 5 17 13 14 14 1 9\n", "output": "2\n3\n1\n0\n1\n1\n1\n1\n15\n"}, {"input": "9\n5\n4 7 2 2 10\n5\n5 0 2 1 7\n5\n1 2 2 4 0\n2\n0 1\n3\n0 1 0\n4\n0 1 0 0\n4\n0 1 0 1\n4\n0 1 ... | code_stdio |
[
{
"content": "There are n types of coins in Byteland. Conveniently, the denomination of the coin type k divides the denomination of the coin type k + 1, the denomination of the coin type 1 equals 1 tugrick. The ratio of the denominations of coin types k + 1 and k equals a_{k}. It is known that for each x there ... | [{"input": "100\n4 1 5 3 2 1 1 1 4 1 1 2 1 1 1 4 1 1 3 1 3 1 1 1 1 4 5 1 5 2 5 3 1 1 1 1 1 1 1 3 2 1 1 3 1 1 3 4 3 2 4 1 1 4 1 1 2 2 4 1 4 1 2 5 1 2 2 1 5 3 1 5 4 2 1 1 2 5 5 1 4 4 2 3 1 4 1 3 2 1 1 1 4 1 3 1 1 5 1\n0 18 10 2 1 9 9 0 9 5 6 8 11 6 28 11 29 50 25 15 9 4 3 51 13 4 68 31 4 6 2 5 26 1 21 7 3 4 9 7 40 3 0 7 ... | code_stdio |
[
{
"content": "The elections to Berland parliament are happening today. Voting is in full swing!\n\nTotally there are n candidates, they are numbered from 1 to n. Based on election results k (1 ≤ k ≤ n) top candidates will take seats in the parliament.\n\nAfter the end of the voting the number of votes for each ... | [{"input": "100 100 100 100\n71 22 92 3 19 90 1 16 88 56 62 37 56 84 52 46 4 64 21 19 37 54 21 81 56 33 71 57 86 75 62 42 79 67 14 8 66 30 13 38 20 71 36 66 46 55 4 99 18 37 7 24 72 46 32 86 87 7 90 93 96 94 21 23 62 53 16 11 11 83 21 81 68 50 85 9 94 60 47 41 34 82 11 12 95 81 61 81 86 85 64 36 57 62 86 3 16 90 73 91\... | code_stdio |
[
{
"content": "Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.\n\nHere are some interesting facts about XXX: XXX consists of n cities, k of whose (just imagine!) are capital cities. ... | [{"input": "76 24\n6814 3834 1131 6256 2598 850 7353 1702 5773 1699 35 5103 1368 2258 7891 7455 8546 7316 7428 8864 6536 5750 8455 2624 7326 2197 8239 3806 3016 7126 85 3249 1138 6783 9684 4417 7417 3660 6334 7324 9760 9755 7605 9891 3676 8784 8739 8266 3272 9250 5875 939 4130 6540 7813 6867 9148 781 6190 964 5612 1864... | code_stdio |
[
{
"content": "<image>\n\n\nThis figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.\n\nWe can simula... | [{"input": "1\n6\n-1\n13\n10\n0\n0\n0", "output": "10\n13\n-1\n"}, {"input": "1\n20\n0\n20\n11\n0\n0\n1", "output": "20\n11\n20\n"}, {"input": "1\n38\n0\n20\n11\n0\n0\n1", "output": "38\n11\n20\n"}, {"input": "1\n10\n0\n20\n11\n0\n0\n1", "output": "10\n11\n20\n"}, {"input": "1\n10\n0\n20\n14\n0\n0\n1", "output": "10\n1... | code_stdio |
[
{
"content": "2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase).... | [{"input": "3\n0110?11\n6\n5 1\n6 ?\n7 ?\n1 ?\n5 ?\n1 1\n", "output": "\n1\n2\n3\n3\n5\n4\n"}, {"input": "3\n0110?11\n6\n5 1\n6 ?\n7 ?\n2 ?\n5 ?\n1 1\n", "output": "1\n2\n3\n4\n5\n5\n"}, {"input": "3\n0110?11\n6\n5 1\n6 ?\n6 ?\n1 ?\n5 ?\n1 1\n", "output": "1\n2\n2\n2\n2\n2\n"}, {"input": "3\n11?0110\n6\n5 1\n6 ?\n7 ?\n... | code_stdio |
[
{
"content": "As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: \"Which one committed the crime?\"... | [{"input": "64 28\n+54\n+44\n+55\n-3\n+33\n-54\n-54\n-7\n+33\n+54\n+54\n+26\n-54\n+14\n-54\n-47\n+25\n-54\n-54\n-54\n-52\n+54\n+54\n+54\n+54\n+20\n+7\n+54\n+4\n+32\n+46\n-54\n-47\n+15\n+32\n-54\n+7\n+62\n-16\n-54\n+3\n+54\n+54\n+54\n+54\n-54\n+54\n-54\n+54\n-52\n+27\n-7\n+54\n-5\n-54\n-18\n+1\n+58\n+28\n-46\n+61\n-54\n... | code_stdio |
[
{
"content": "You are given a book with n chapters.\n\nEach chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list.\n\nCurrently you don't understand any of t... | [{"input": "5\n4\n1 2\n0\n2 1 4\n1 3\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 3\n0\n0\n2 3 2\n5\n1 2\n1 3\n1 4\n1 3\n0\n", "output": "-1\n-1\n1\n2\n-1\n"}, {"input": "5\n4\n1 2\n0\n2 1 4\n1 2\n5\n1 5\n1 1\n1 1\n1 1\n1 4\n5\n0\n0\n2 1 2\n1 2\n2 2 1\n4\n2 2 4\n0\n0\n2 3 1\n5\n1 2\n1 3\n1 4\n1 3\n0\... | code_stdio |
[
{
"content": "You are given a function $f$ written in some basic language. The function accepts an integer value, which is immediately written into some variable $x$. $x$ is an integer variable and can be assigned values from $0$ to $2^{32}-1$. The function contains three types of commands:\n\n for $n$ — for l... | [{"input": "83\nadd\nfor 58\nend\nadd\nadd\nfor 36\nfor 84\nadd\nadd\nfor 86\nadd\nadd\nend\nend\nadd\nadd\nadd\nadd\nfor 23\nadd\nadd\nadd\nfor 70\nadd\nadd\nend\nfor 24\nfor 58\nend\nadd\nend\nend\nend\nfor 41\nfor 51\nend\nfor 22\nfor 39\nend\nfor 94\nfor 47\nadd\nfor 57\nend\nadd\nend\nfor 55\nadd\nfor 75\nfor 90\n... | code_stdio |
[
{
"content": "Snuke loves puzzles.\n\nToday, he is working on a puzzle using `S`- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below:\n\n9b0bd546db9f28b4093d417b8f274124.png\n\nSnuke decided to create as many `Scc` groups as possi... | [{"input": "12345 267141", "output": "72957\n"}, {"input": "12345 263982", "output": "72168\n"}, {"input": "10389 263982", "output": "71190\n"}, {"input": "10389 232248", "output": "63256\n"}, {"input": "12345 678901", "output": "175897"}, {"input": "5656 263982", "output": "68823\n"}, {"input": "10389 85698", "output"... | code_stdio |
[
{
"content": "As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads.\n\nThe «Two Paths» company, where Bob's brother works, has won a tender to repair two pa... | [{"input": "50\n7 34\n5 34\n5 11\n11 23\n42 5\n41 11\n12 41\n41 49\n1 49\n12 6\n7 15\n17 42\n20 6\n17 46\n20 19\n46 22\n49 40\n44 40\n43 46\n22 8\n17 29\n44 18\n31 18\n46 9\n7 16\n32 11\n13 41\n20 36\n34 25\n46 28\n39 34\n30 42\n11 47\n45 15\n37 17\n4 23\n35 17\n17 48\n2 17\n34 24\n1 10\n21 5\n2 3\n50 16\n33 5\n20 14\n... | code_stdio |
[
{
"content": "Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. The painting is a square 3 × 3, each cell contains a single integ... | [{"input": "100000 100000 100000 100000 100000\n", "output": "10000000000\n"}, {"input": "100000 100000 100000 100000 100000\n", "output": "10000000000"}, {"input": "100000 83958 32567 91083 110780\n", "output": "1466200000\n"}, {"input": "100000 80015 84290 50777 30497\n", "output": "1696900000\n"}, {"input": "100000 ... | code_stdio |
[
{
"content": "Three-valued logic is a logic system that has, in addition to \"true\" and \"false\", \"unknown\" as a valid value. In the following, logical values \"false\", \"unknown\" and \"true\" are represented by 0, 1 and 2 respectively.\n\nLet \"-\" be a unary operator (i.e. a symbol representing one argu... | [{"input": "(Q*P)\n(--R+(Q*R))\n(P+-Q)\n2\n-1\n(-1+(((---P+Q)*(--Q+---R))+(-R+-P)))\n.", "output": "3\n9\n15\n27\n0\n19\n"}, {"input": "(P*Q)\n(--R+(P*Q))\n(P*-P)\n2\n2\n(-1+(((---P+Q)*(--Q+---R))*(-R+-P)))\n.", "output": "3\n11\n0\n27\n27\n7\n"}, {"input": "(P*R)\n(--R*(P*R))\n(P+-P)\n0\n2\n(-1+(((---P+Q)*(--Q+---P))*... | code_stdio |
[
{
"content": "There is a grid with R rows and C columns. We call the cell in the r-th row and c-th column (r,c).\n\nMr. Takahashi wrote non-negative integers into N of the cells, that is, he wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that he fell asleep.\n\nMr. Aoki found the grid... | [{"input": "2 3\n5\n2 1 0\n1 2 10\n1 3 20\n2 1 30\n2 3 40", "output": "No\n"}, {"input": "2 3\n5\n2 1 0\n1 2 10\n1 3 37\n2 1 30\n2 3 40", "output": "No\n"}, {"input": "4 3\n5\n2 1 0\n1 2 10\n1 3 20\n2 1 30\n2 3 40", "output": "No\n"}, {"input": "2 3\n5\n1 1 0\n1 2 10\n1 3 20\n2 1 33\n2 3 40", "output": "No\n"}, {"input... | code_stdio |
[
{
"content": "A company has N members, who are assigned ID numbers 1, ..., N.\nEvery member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.\nWhen a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.\nYou are ... | [{"input": "10\n1 1 1 1 1 1 1 1 1\n", "output": "9\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"}, {"input": "10\n1 1 1 1 1 2 1 1 1", "output": "8\n1\n0\n0\n0\n0\n0\n0\n0\n0\n"}, {"input": "10\n1 1 1 2 1 2 1 1 1", "output": "7\n2\n0\n0\n0\n0\n0\n0\n0\n0\n"}, {"input": "10\n1 1 1 2 1 2 1 1 2", "output": "6\n3\n0\n0\n0\n0\n0\n0\n0\n0\n"... | code_stdio |
[
{
"content": "Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.\n\nOne day Petya dreamt of a lexicographically k-th permutation of integers fro... | [{"input": "1000000000 1000000000\n", "output": "1022"}, {"input": "852355975 1000000000\n", "output": "1022\n"}, {"input": "444747744 1000000000\n", "output": "554"}, {"input": "70407598 1000000000\n", "output": "382\n"}, {"input": "77777779 1000000000\n", "output": "508"}, {"input": "1577407 95554455\n", "output": "1... | code_stdio |
[
{
"content": "Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a_1, a_2, ..., a_{n} megabytes. The file size is equal to m megabytes. \n\nFind the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.\... | [{"input": "100\n32630\n548\n21\n756\n138\n56\n719\n97\n140\n599\n531\n464\n137\n737\n239\n626\n179\n170\n271\n335\n178\n298\n597\n616\n104\n190\n216\n333\n606\n621\n310\n70\n286\n593\n655\n472\n556\n77\n625\n744\n395\n487\n762\n316\n469\n258\n475\n596\n651\n180\n737\n101\n511\n708\n163\n713\n475\n557\n649\n705\n583\n9... | code_stdio |
[
{
"content": "Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.\n\nFangy takes some positive integer x and wants to get a number one from it. While x is not equal to 1, Fangy repeats the following action: if x is odd, then he adds 1 to it, o... | [{"input": "1000101100110000000001111010110000000010001001111110011011000011101011001001010010111\n", "output": "133\n"}, {"input": "1000101100100000000001111010110000000010001001111110011011000011101011001001010010111\n", "output": "134\n"}, {"input": "100010110010000000000111101010000000001000100111111001101100001110... | code_stdio |
[
{
"content": "You've got an undirected graph, consisting of n vertices and m edges. We will consider the graph's vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer c_{i}.\n\nLet's consider all vertices of the graph, that are painted some... | [{"input": "50 47\n21 17 47 15 50 47 47 41 28 18 27 47 29 28 32 26 16 26 8 22 27 10 45 21 17 30 31 38 14 8 9 40 29 35 41 24 22 14 40 46 44 34 40 31 48 40 8 50 1 28\n10 5\n34 2\n42 5\n36 28\n8 44\n36 3\n40 15\n33 18\n5 50\n1 6\n25 20\n39 24\n45 35\n14 27\n14 39\n17 47\n19 49\n28 10\n7 13\n34 3\n22 26\n5 6\n8 17\n32 18\n... | code_stdio |
[
{
"content": "Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number ... | [{"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB\n", "output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "}, {"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBW... | code_stdio |
[
{
"content": "You are given positive integers A and B.\nIf A is a divisor of B, print A + B; otherwise, print B - A.\n\n-----Constraints-----\n - All values in input are integers.\n - 1 \\leq A \\leq B \\leq 20\n\n-----Input-----\nInput is given from Standard Input in the following format:\nA B\n\n-----Output--... | [{"input": "10 111", "output": "101\n"}, {"input": "110 40", "output": "-70\n"}, {"input": "111 40", "output": "-71\n"}, {"input": "111 62", "output": "-49\n"}, {"input": "111 68", "output": "-43\n"}, {"input": "101 68", "output": "-33\n"}, {"input": "111 90", "output": "-21\n"}, {"input": "20 20\n", "output": "40\n"},... | code_stdio |
[
{
"content": "Positive integer $x$ is called divisor of positive integer $y$, if $y$ is divisible by $x$ without remainder. For example, $1$ is a divisor of $7$ and $3$ is not divisor of $8$.\n\nWe gave you an integer $d$ and asked you to find the smallest positive integer $a$, such that\n\n$a$ has at least $4$... | [{"input": "2\n14\n100\n", "output": "527\n21311\n"}, {"input": "2\n14\n110\n", "output": "527\n25199\n"}, {"input": "2\n14\n111\n", "output": "527\n25651\n"}, {"input": "2\n60\n25\n", "output": "7747\n1711\n"}, {"input": "2\n22\n29\n", "output": "1081\n1891\n"}, {"input": "2\n40\n31\n", "output": "3403\n2627\n"}, {"in... | code_stdio |
[
{
"content": "For 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.\n\nPolycarp can cut any sheet of paper $w \\times h$ that he has in only two ca... | [{"input": "16\n8192 8192 67108864\n8192 8192 67108865\n8192 8192 70000000\n8192 8192 67108863\n1 1 1\n13 13 1\n1000 1000 100\n100 15 16\n157 185 95\n1992 1895 12\n1888 4984 164\n1564 8917 15\n150 15 2\n1500 10 40\n1 10000 1000\n1 10000 10000\n", "output": "YES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\n... | code_stdio |
[
{
"content": "There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.\n\nWe will ... | [{"input": "1495 932", "output": "1388490\n"}, {"input": "582 1592", "output": "922200\n"}, {"input": "1018 932", "output": "944880\n"}, {"input": "1018 374", "output": "377952\n"}, {"input": "314 1692", "output": "527280\n"}, {"input": "218 1592", "output": "343440\n"}, {"input": "582 1178", "output": "682080\n"}, {"i... | code_stdio |
[
{
"content": "Problem\n\n\"Ritsumeikan University Competitive Programming Camp\" will be held this year as well. I am very much looking forward to this annual training camp. However, I couldn't stand my desires and splurged before the training camp, so I couldn't afford it. So I decided to use the cheapest Seis... | [{"input": "1234 5 4 789012345678901234 5 6", "output": "1357101234567708000\n"}, {"input": "2017 4 2 789012345678901234 5 6", "output": "1357101234567706652\n"}, {"input": "2684 2 6 699116447311015755 5 1", "output": "1202480289374942482\n"}, {"input": "2152 4 2 789012345678901234 5 6", "output": "1357101234567706421\... | code_stdio |
[
{
"content": "Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions q (q + (m - 1)·p ≤ n; q ≥ 1), such that sequ... | [{"input": "82 50 1\n4 2 2 4 4 3 2 2 3 3 4 3 4 1 4 1 4 3 5 3 4 2 4 4 5 2 5 4 2 4 2 5 3 2 3 4 2 5 4 3 3 4 3 4 1 1 5 2 4 1 3 3 2 4 1 2 2 5 4 4 5 3 3 1 2 3 4 5 3 1 2 3 3 5 5 2 4 1 4 2 3 1\n4 3 3 3 4 1 4 4 5 5 5 2 5 4 1 2 2 1 3 3 3 3 2 5 3 2 4 3 2 2 4 4 4 3 4 2 1 2 3 2 1 1 5 2 3 5 4 5 3 4\n", "output": "2\n24 28 "}, {"inpu... | code_stdio |
[
{
"content": "Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated.\n\nThere are n video cards in the shop, the power of the i-th v... | [{"input": "100\n955 479 355 759 257 497 690 598 275 446 439 787 257 326 584 713 322 5 253 781 434 307 164 154 241 381 38 942 771 906 240 11 431 478 628 1892 346 74 493 964 455 1105 950 41 585 549 892 687 264 41 487 676 63 453 861 980 620 844 80 907 285 506 772 748 773 743 44 925 529 685 845 313 419 504 770 324 2 559 4... | code_stdio |
[
{
"content": "Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.\n\nGregor's favorite prime number is $P$. Gregor wants to find two bases of $P$. Formally, Gregor is looking for two integers $a$ and $b$ which s... | [{"input": "5\n5\n11\n11\n13\n19\n", "output": "2 4\n2 10\n2 10\n2 12\n2 18\n"}, {"input": "5\n5\n7\n11\n13\n19\n", "output": "2 4\n2 6\n2 10\n2 12\n2 18\n"}, {"input": "5\n5\n7\n11\n13\n19\n", "output": "2 4\n2 6\n2 10\n2 12\n2 18\n"}, {"input": "5\n5\n7\n13\n13\n19\n", "output": "2 4\n2 6\n2 12\n2 12\n2 18\n"}, {"inp... | code_stdio |
[
{
"content": "This is a hard version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.\n\nYou are given a string $s$ consisting of $n$ lowercase Latin letters.\n\nYou have to color all i... | [{"input": "500\nhvmmnbwnblqfvwwrcbzkccvcdrhoxbvzwkopagpwntjwwqppduunnenopvyjumjotgcnkoorjcbzctddppezypklfhmxcmufnhcuwxhzbpumlevwdufpyasriaupqdjhpccvtxwqkjseqpsatgbkihgteuclmpaamloxpbtbxhekgpbjvndelmrenhtotvuaymrzpyhmlaujjttwrrlamijsxyegcwagncdscpbvprkwgpwdikdsbqrpkecilprocbyzsupmanekspjzoebjqvmjxjggleinlhipqtbxduimcol... | code_stdio |
[
{
"content": "Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. \n\nFor example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.\n\nThe following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3... | [{"input": "1000000000\n", "output": "500000001\n"}, {"input": "1000000000\n", "output": "500000001\n"}, {"input": "1223796969\n", "output": "611898485\n"}, {"input": "1074371686\n", "output": "537185844\n"}, {"input": "1141423649\n", "output": "570711825\n"}, {"input": "1000100000\n", "output": "500050001\n"}, {"input... | code_stdio |
[
{
"content": "We have two indistinguishable pieces placed on a number line. Both pieces are initially at coordinate 0. (They can occupy the same position.)\n\nWe can do the following two kinds of operations:\n\n* Choose a piece and move it to the right (the positive direction) by 1.\n* Move the piece with the s... | [{"input": "1010000 100000 200000", "output": "489638142\n"}, {"input": "1010000 100001 200000", "output": "645079609\n"}, {"input": "1011000 100001 200000", "output": "150445035\n"}, {"input": "1011001 100001 200000", "output": "160610610\n"}, {"input": "1000000 110000 200000", "output": "385341624\n"}, {"input": "101... | code_stdio |
[
{
"content": "Recently Anton found a box with digits in his room. There are k_2 digits 2, k_3 digits 3, k_5 digits 5 and k_6 digits 6.\n\nAnton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him so... | [{"input": "5000000 5000000 5000000 5000000\n", "output": "1280000000\n"}, {"input": "4759823 3520376 4743363 4743363\n", "output": "1214827648\n"}, {"input": "4759823 3520376 4743363 4743363\n", "output": "1214827648\n"}, {"input": "5000000 5000000 5000000 5000000\n", "output": "1280000000\n"}, {"input": "4288078 3520... | code_stdio |
[
{
"content": "Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters.\n\nThere is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go ... | [{"input": "100\nggogogoooggogooggoggogggggogoogoggooooggooggoooggogoooggoggoogggoogoggogggoooggoggoggogggogoogggoooo\n", "output": "gg***oogg***oggoggoggggg******ggooooggooggooogg***ooggoggoogggo***ggogggoooggoggoggoggg***ogggoooo\n"}, {"input": "100\nggogogoooggogooggoggogggggogoogoggooooggooggoooggogoooggoggoogggoog... | code_stdio |
[
{
"content": "In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east.\nA company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i).\nTakahashi the king is interested in the foll... | [{"input": "10 10 10\n1 6\n2 9\n4 5\n4 7\n4 7\n5 8\n6 6\n6 7\n7 9\n10 10\n1 8\n1 9\n1 10\n2 8\n2 9\n2 10\n3 8\n3 9\n3 10\n1 10\n", "output": "7\n9\n10\n6\n8\n9\n6\n7\n8\n10\n"}, {"input": "10 10 10\n1 6\n2 9\n4 5\n4 7\n4 7\n5 8\n6 6\n6 7\n7 9\n10 10\n1 8\n1 9\n1 10\n2 8\n2 10\n3 10\n3 8\n3 9\n3 10\n1 10", "output": "7\... | code_stdio |
[
{
"content": "International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never... | [{"input": "9\nIAO'0\nIAO'00\nIAO'000\nIAO'0000\nIAO'00000\nIAO'000000\nIAO'0000000\nIAO'00000000\nIAO'000000000\n", "output": "1990\n2000\n3000\n10000\n100000\n1000000\n10000000\n100000000\n1000000000\n"}, {"input": "9\nIAO'0\nIAO'00\nIAO'000\nIAO'0000\nIAO'00000\nIAO'000000\nIAO'0000000\nIAO'00000000\nIAO'000000000\n... | code_stdio |
[
{
"content": "Andrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final test, the teacher decided to give him a difficult task as a punishment.\n\nThe teacher gave Andrew an array of n numbers a_1, ..., a_{n}. After that he asked Andrew for each k from... | [{"input": "100\n0 1 1 1 0 0 0 2 1 2 2 1 2 2 2 0 0 2 1 2 0 1 1 0 2 0 1 2 2 0 2 0 1 0 1 2 0 2 1 1 0 1 0 1 0 0 0 2 2 2 2 1 1 1 0 2 1 0 0 0 0 0 1 0 2 -1 1 0 0 2 0 2 2 1 0 2 2 0 2 0 2 1 2 1 1 1 0 2 1 0 2 1 1 2 1 2 0 1 2 2\n", "output": "36 30 38 35 35 33 34 31 28 22 22 23 19 16 19 20 22 23 24 25 25 26 26 27 26 26 26 26 25 ... | code_stdio |
[
{
"content": "Snuke has two boards, each divided into a grid with N rows and N columns. For both of these boards, the square at the i-th row from the top and the j-th column from the left is called Square (i,j).\n\nThere is a lowercase English letter written in each square on the first board. The letter written... | [{"input": "5\nabcde\nfghij\nklmno\npqrst\nuvvxy", "output": "0\n"}, {"input": "5\nabcde\nfghij\nonmlk\npqrst\nuvwxy", "output": "0\n"}, {"input": "5\nedcba\nfghij\nonmlk\npqrst\nuvwxy", "output": "0\n"}, {"input": "5\nedcba\njihgf\nonmlk\npqrst\nuvwxy", "output": "0\n"}, {"input": "5\nedcba\njihfg\nonmlk\npqrst\nuvwxy... | code_stdio |
[
{
"content": "There is a card game called \"Durak\", which means \"Fool\" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.\n\nTo play durak you need a pack of 36 cards. Each... | [{"input": "D\n9S 8S\n", "output": "YES\n"}, {"input": "H\nTH 8H\n", "output": "YES\n"}, {"input": "H\nAH KH\n", "output": "YES\n"}, {"input": "H\nAD KD\n", "output": "YES\n"}, {"input": "H\nAC QC\n", "output": "YES\n"}, {"input": "H\n7D 6D\n", "output": "YES\n"}, {"input": "H\nJS TS\n", "output": "YES\n"}, {"input": "... | code_stdio |
[
{
"content": "Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degrees.\n\n-----Input-----\n\nThe first line contains an integer T, the total number of testcases. Then T lines... | [{"input": "3 \n30 40 110\n45 45 90\n180 0 0", "output": "YES\nYES\nNO\n"}, {"input": "3 \n30 40 110\n12 45 90\n180 0 0", "output": "YES\nNO\nNO\n"}, {"input": "3 \n30 77 110\n45 45 90\n180 0 0", "output": "NO\nYES\nNO\n"}, {"input": "3 \n30 40 110\n12 56 90\n180 0 0", "output": "YES\nNO\nNO\n"}, {"input": "3 \n30 77 0... | code_stdio |
[
{
"content": "Boboniu likes bit operations. He wants to play a game with you.\n\nBoboniu gives you two sequences of non-negative integers $a_1,a_2,\\ldots,a_n$ and $b_1,b_2,\\ldots,b_m$.\n\nFor each $i$ ($1\\le i\\le n$), you're asked to choose a $j$ ($1\\le j\\le m$) and let $c_i=a_i\\& b_j$, where $\\&$ denot... | [{"input": "30 55\n194 478 207 22 344 507 374 462 107 506 317 299 326 308 459 396 330 317 138 342 126 473 423 180 41 165 435 72 53 71\n44 229 106 350 420 462 412 115 452 364 452 294 280 171 325 250 94 266 33 329 197 384 50 36 495 464 67 283 83 3 335 62 101 307 474 296 484 388 315 444 203 304 110 97 70 169 170 369 384 3... | code_stdio |
[
{
"content": "You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.\n\n-----Constraints-----\n - 1\\leq A\\leq B\\leq 10^{18}\n - 1\\leq C,D\\leq 10^9\n - All values in input are integers.\n\n-----Input-----\nInput is g... | [{"input": "123456789987654321 987654321123456789 999999999 1000000000\n", "output": "864197529407407405\n"}, {"input": "314159265358979323 846264338327950288 419716939 937510582\n", "output": "532105071133627368\n"}, {"input": "827191816666888190 908822776155224411 1000000000 300000000\n", "output": "81630959161812384... | code_stdio |
[
{
"content": "Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can'... | [{"input": "10 85\n2 2\n1 10\n1 1\n2 6\n1 2\n1 4\n1 7\n2 1\n1 1\n3 3\n1 9\n1 6\n1 8\n1 10\n1 8\n2 8\n1 6\n1 3\n1 9\n1 6\n1 3\n1 8\n1 1\n1 6\n1 10\n2 1\n2 10\n1 10\n1 1\n1 10\n1 6\n1 2\n1 8\n1 3\n1 4\n1 9\n1 5\n1 5\n2 2\n2 4\n1 7\n1 1\n2 4\n1 9\n2 1\n1 7\n1 8\n3 33\n1 10\n2 2\n1 3\n1 10\n1 6\n3 32\n2 3\n1 5\n2 10\n2 2\n... | code_stdio |
[
{
"content": "Berland State University has received a new update for the operating system. Initially it is installed only on the $1$-st computer.\n\nUpdate files should be copied to all $n$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to ... | [{"input": "13\n576460752303423486 576460752303423486\n576460752303423487 576460752303423487\n576460752303423488 576460752303423488\n576460752303423489 576460752303423489\n576460752303423490 576460752303423490\n576460752303423488 288230376151711743\n576460752303423488 288230376151711744\n576460752303423488 288230376151... | code_stdio |
[
{
"content": "Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there.\n\nFinally he found n islands that had treasures and one island that had nothing.... | [{"input": "3\n2 5\n-1 13\n2 2\n3\n2 0\n3 6\n2 3\n0", "output": "Yes\nNo\n"}, {"input": "3\n3 5\n-1 13\n2 2\n3\n2 0\n3 6\n2 3\n0", "output": "Yes\nNo\n"}, {"input": "3\n2 5\n0 8\n2 2\n3\n2 -1\n3 10\n2 2\n0", "output": "Yes\nNo\n"}, {"input": "3\n2 4\n0 8\n2 2\n3\n2 -1\n3 10\n2 2\n0", "output": "Yes\nNo\n"}, {"input": "... | code_stdio |
[
{
"content": "You are given two arrays $a$ and $b$ of positive integers, with length $n$ and $m$ respectively. \n\nLet $c$ be an $n \\times m$ matrix, where $c_{i,j} = a_i \\cdot b_j$. \n\nYou need to find a subrectangle of the matrix $c$ such that the sum of its elements is at most $x$, and its area (the total... | [{"input": "235 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | code_stdio |
[
{
"content": "The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this inform... | [{"input": "10\nXXXOOOOXOX\nOOOXXXOXXO\nXOXXXXOOXX\nXOOOXXOXOO\nOOXOOOOOOX\nXXXXOXOOOO\nXXXOOXOXOX\nOOOOXOXOXX\nXOXXOXOOXO\nOOOOOXOOOO\nXXXOOOOXOX\nOOOXXXOXXO\nXOXXXXOOXX\nXOOOXXOXOO\nOOXOOOOOOX\nXXXXOXOOOO\nXXXOOXOXOX\nOOOOXOXOXX\nXOXXOXOOXO\nOOOOOXOOOO\n", "output": "Yes\n"}, {"input": "10\nXXOXXOXOOX\nOOOOXOOXXO\nOX... | code_stdio |
[
{
"content": "Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.\n\nToday Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b... | [{"input": "100 37 -100\n", "output": "37\n"}, {"input": "100 37 -100\n", "output": "37\n"}, {"input": "100 37 -124\n", "output": "13\n"}, {"input": "145 38 106\n", "output": "144\n"}, {"input": "100 54 100\n", "output": "54\n"}, {"input": "100 54 100\n", "output": "54\n"}, {"input": "100 54 101\n", "output": "55\n"}, ... | code_stdio |
[
{
"content": "Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest.\nIn this game, an honest player always tells the truth, and an dishonest player always tell lies.\nYou are given two characters a and b as the input. Each of them is either H or D, and carries the following informatio... | [{"input": "H H\n", "output": "H\n"}, {"input": "D H\n", "output": "D\n"}, {"input": "D D\n", "output": "H\n"}, {"input": "H 14", "output": "D\n"}, {"input": "H 15", "output": "D\n"}, {"input": "H 23", "output": "D\n"}, {"input": "H 17", "output": "D\n"}, {"input": "H 13", "output": "D\n"}, {"input": "H 12", "output": ... | code_stdio |
[
{
"content": "You are given N non-negative integers A_1, A_2, ..., A_N and another non-negative integer K.\nFor a integer X between 0 and K (inclusive), let f(X) = (X XOR A_1) + (X XOR A_2) + ... + (X XOR A_N).\nHere, for non-negative integers a and b, a XOR b denotes the bitwise exclusive OR of a and b.\nFind ... | [{"input": "1 0\n1000000000000\n", "output": "1000000000000\n"}, {"input": "4 9\n7 4 0 3\n", "output": "46\n"}, {"input": "3 7\n1 6 3\n", "output": "14\n"}] | code_stdio |
[
{
"content": "You are given an array $a$ consisting of $n$ integers $a_1, a_2, \\dots , a_n$.\n\nIn one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $[2, 1, 4]$ you can o... | [{"input": "2\n5\n3 1 10 4 1\n7\n1 0 1 1 1 2 2\n", "output": "2\n3\n"}, {"input": "2\n5\n3 1 10 5 1\n7\n1 0 1 1 1 2 2\n", "output": "2\n3\n"}, {"input": "2\n5\n3 1 10 5 1\n7\n1 0 1 1 1 2 4\n", "output": "2\n3\n"}, {"input": "2\n5\n3 1 10 5 1\n7\n1 0 1 1 0 2 4\n", "output": "2\n4\n"}, {"input": "2\n5\n3 1 10 5 1\n7\n1 0... | code_stdio |
[
{
"content": "Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n_1 balls and second player's box contains exactly n_2 balls. In one move first player can take from 1 to k_1 balls from his box and throw them away. Similarly, the second player can ... | [{"input": "50 50 50 50\n", "output": "Second\n"}, {"input": "48 50 12 11\n", "output": "Second\n"}, {"input": "49 50 11 12\n", "output": "Second\n"}, {"input": "50 50 50 50\n", "output": "Second\n"}, {"input": "48 50 12 11\n", "output": "Second\n"}, {"input": "49 50 11 12\n", "output": "Second\n"}, {"input": "50 50 87... | code_stdio |
[
{
"content": "There is a robot in a warehouse and $n$ packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point $(0, 0)$. The $i$-th package is at the point $(x_i, y_i)$. It is guaranteed that there are no two packages at the same point. It is a... | [{"input": "3\n5\n1 3\n1 2\n3 3\n5 5\n4 3\n2\n1 0\n0 1\n1\n4 3\n", "output": "YES\nRUUURRRRUU\nNO\nYES\nRRRRUUU\n"}, {"input": "3\n5\n1 3\n1 2\n3 3\n5 5\n2 3\n2\n1 0\n0 1\n1\n4 3\n", "output": "YES\nRUUURRRRUU\nNO\nYES\nRRRRUUU\n"}, {"input": "3\n5\n1 3\n1 0\n3 3\n5 5\n4 3\n2\n1 0\n0 1\n1\n4 3\n", "output": "YES\nRUUUR... | code_stdio |
[
{
"content": "On the competitive programming platform CodeCook, every person has a rating graph described by an array of integers $a$ of length $n$. You are now updating the infrastructure, so you've created a program to compress these graphs.\n\nThe program works as follows. Given an integer parameter $k$, the... | [{"input": "5\n5\n1 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 1\n10\n1 2 3 4 5 10 7 8 9 10\n3\n3 3 2\n", "output": "10111\n0001\n00001\n0000011111\n000\n"}, {"input": "5\n5\n2 5 3 4 2\n4\n1 3 2 1\n5\n1 3 3 3 2\n10\n1 1 1 4 10 6 2 8 9 10\n3\n3 3 2\n", "output": "00000\n0001\n00111\n0000000001\n000\n"}, {"input": "5\n5\n1 5 3 4 2\... | code_stdio |
[
{
"content": "ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bil... | [{"input": "58 5\n1 6 9 18 34 41 82 99 164 179 183 204 240 396 636 1224 2023 2856 4488 4705 5712 9180 9266 18360 18850 20270 23086 60810 190701 197064 211140 214200 222970 243240 263510 314442 425670 486480 708288 789888 1009800 1025349 1054040 1094580 1325184 1579776 1748076 2050698 2635100 2895984 2918880 3975552 428... | code_stdio |
[
{
"content": "Is it rated?\n\nHere it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.\n\nAnother Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the stand... | [{"input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110\n", "output": "unrated\n"}, {"input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110\n", "output": "unrated\n"}, {"input": "10\n4078... | code_stdio |
[
{
"content": "Mikhail walks on a Cartesian plane. He starts at the point $(0, 0)$, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $(0, 0)$, he can go to any of the following points in one move: $(1, 0)$; $(1, 1)$; $(0, 1)$; $(-1, 1)$; $(-1, 0)$... | [{"input": "3\n7 0 0\n3 1 0\n22 0 2\n", "output": "-1\n-1\n-1\n"}, {"input": "3\n1 1 1\n9 -1 5\n35 0 1\n", "output": "1\n-1\n-1\n"}, {"input": "3\n2 2 3\n6 2 18\n10 0 1\n", "output": "1\n18\n-1\n"}, {"input": "3\n1 0 1\n9 -1 5\n35 0 1\n", "output": "0\n-1\n-1\n"}, {"input": "3\n1 0 1\n9 0 5\n35 -1 1\n", "output": "0\n-... | code_stdio |
[
{
"content": "Let $s$ be some string consisting of symbols \"0\" or \"1\". Let's call a string $t$ a substring of string $s$, if there exists such number $1 \\leq l \\leq |s| - |t| + 1$ that $t = s_l s_{l+1} \\ldots s_{l + |t| - 1}$. Let's call a substring $t$ of string $s$ unique, if there exist only one such ... | [{"input": "99985 45273\n", "output": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000... | code_stdio |
[
{
"content": "You are creating a level for a video game. The level consists of $n$ rooms placed in a circle. The rooms are numbered $1$ through $n$. Each room contains exactly one exit: completing the $j$-th room allows you to go the $(j+1)$-th room (and completing the $n$-th room allows you to go the $1$-st ro... | [{"input": "50\n499 1400 1621 123 72 526 944 482 862 136 265 605 5 616 974 967 713 187 969 467 573 845 71 224 17 873 648 120 239 1722 438 574 404 129 899 583 632 314 525 496 443 857 241 78 575 2 430 137 387 911\n", "output": "459200194 19968654 978281891 778632355 119790684 519088159 339403985 279509183 259544188 47915... | code_stdio |
[
{
"content": "Ayoub thinks that he is a very smart person, so he created a function $f(s)$, where $s$ is a binary string (a string which contains only symbols \"0\" and \"1\"). The function $f(s)$ is equal to the number of substrings in the string $s$ that contains at least one symbol, that is equal to \"1\".\n... | [{"input": "5\n6 4\n5 2\n3 2\n2 1\n10 2\n", "output": "19\n12\n5\n2\n40\n"}, {"input": "5\n6 4\n5 2\n4 2\n2 1\n10 2\n", "output": "19\n12\n8\n2\n40\n"}, {"input": "5\n6 1\n0 0\n5 0\n16 1\n8 1\n", "output": "12\n0\n0\n72\n20\n"}, {"input": "5\n6 4\n5 2\n4 2\n2 2\n10 2\n", "output": "19\n12\n8\n3\n40\n"}, {"input": "5\n6... | code_stdio |
[
{
"content": "A and B are preparing themselves for programming contests.\n\nTo train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.\n\nFor each chess piece we know its weight: the queen's weight is 9, the rook's weig... | [{"input": "...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n", "output": "White\n"}, {"input": "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n", "output": "Black\n"}, {"input": "....bQ.K\n.B......\n.....P..\n........\n........\n........\n...N.P..\n.....R... | code_stdio |
[
{
"content": "We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the n... | [{"input": "10 8\n10 3 6 8 7 10 9 1 2 4\n2 1\n4 1\n5 9\n4 2\n6 2\n3 5\n8 9\n7 9", "output": "2\n"}, {"input": "10 8\n10 3 6 8 7 10 9 1 2 4\n2 1\n3 1\n5 9\n4 2\n6 2\n3 5\n8 9\n7 9", "output": "7\n"}, {"input": "10 8\n10 3 6 8 7 10 9 1 2 4\n2 1\n4 1\n5 9\n4 2\n6 1\n3 5\n8 9\n7 9", "output": "2\n"}, {"input": "10 8\n5 3 6... | code_stdio |
[
{
"content": "Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.\n\nYou are to place a spotlight on the stage in some good position. The spotlight will project... | [{"input": "10 20\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 ... | code_stdio |
[
{
"content": "One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one.\n\nThe maze is organized as follows. Each room of the maze has two one-way portals. Let's ... | [{"input": "129\n1 1 3 3 1 3 7 4 3 5 8 11 3 9 15 4 11 15 1 6 18 9 11 13 17 22 8 18 26 13 16 20 3 16 35 26 23 28 27 30 39 29 43 8 14 6 17 32 26 31 2 18 3 47 52 21 57 1 35 35 53 47 16 26 30 65 48 2 1 11 10 5 4 1 4 53 71 21 53 8 58 49 17 6 19 80 1 49 43 60 12 60 35 25 86 45 47 97 69 74 10 91 93 31 69 41 80 90 67 4 111 100... | code_stdio |
[
{
"content": "Tarly has two different type of items, food boxes and wine barrels. There are f food boxes and w wine barrels. Tarly stores them in various stacks and each stack can consist of either food boxes or wine barrels but not both. The stacks are placed in a line such that no two stacks of food boxes are... | [{"input": "100000 100000 10000\n", "output": "308343288\n"}, {"input": "100000 100000 10000\n", "output": "308343288\n"}, {"input": "100000 100000 1000\n", "output": "402115033\n"}, {"input": "100000 100000 1000\n", "output": "402115033\n"}, {"input": "100000 100000 1001\n", "output": "500272705\n"}, {"input": "100000... | code_stdio |
[
{
"content": "Read problems statements in Russian here \nChef has a special affection for sets of binary strings of equal length which have same numbers of 1's. Given three integers n, k and m, your task is to find the the lexicographically m^{th} smallest string among strings which have length n and have k 1... | [{"input": "1\n57 0 -2", "output": "000000000000000000000000000000000000000000000000000000000\n"}, {"input": "1\n51 2 0", "output": "000000000000000000000000000000000000000000000000000\n"}, {"input": "1\n51 2 1", "output": "000000000000000000000000000000000000000000000000011\n"}, {"input": "1\n43 0 -2", "output": "0000... | code_stdio |
[
{
"content": "You and your $n - 1$ friends have found an array of integers $a_1, a_2, \\dots, a_n$. You have decided to share it in the following way: All $n$ of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array,... | [{"input": "4\n6 3 2\n4 16 1 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 -1 2 2\n2 2 0\n2 2\n", "output": "16\n4\n2\n2\n"}, {"input": "4\n6 3 2\n2 9 2 3 10 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n", "output": "10\n4\n2\n1\n"}, {"input": "4\n6 3 2\n2 9 2 3 10 5\n4 4 1\n2 13 60 4\n4 3 3\n1 2 2 1\n2 2 0\n2 2\n", "output": ... | code_stdio |
[
{
"content": "Consider an infinite sequence a_1, a_2, … Initially, the values of all the terms are 0, and from this state we will sequentially perform Q operations. The i-th operation (1 ≤ i ≤ Q) is as follows:\n\n* For every positive integer j, add x_i to the value of a_{j × m_i}.\n\n\n\nFind the value of the ... | [{"input": "5\n56 114834\n72 -134386\n100 190757\n192 -132693\n240 133108", "output": "438699\n"}, {"input": "5\n56 114834\n72 -134386\n100 190757\n192 -132693\n240 261716", "output": "567307\n"}, {"input": "5\n92 114834\n125 -176641\n100 13125\n192 -68478\n240 133108", "output": "261067\n"}, {"input": "5\n42 114834\n1... | code_stdio |
[
{
"content": "The store sells $n$ items, the price of the $i$-th item is $p_i$. The store's management is going to hold a promotion: if a customer purchases at least $x$ items, $y$ cheapest of them are free.\n\nThe management has not yet decided on the exact values of $x$ and $y$. Therefore, they ask you to pro... | [{"input": "13 3\n5 3 1 5 2 5 3 1 5 2 5 3 1\n3 2\n1 1\n5 3\n", "output": "10\n5\n15\n"}, {"input": "5 3\n100 200 300 400 500\n2 1\n1 1\n3 2\n", "output": "400\n500\n700\n"}, {"input": "5 3\n100 200 300 400 500\n1 1\n3 2\n2 2\n", "output": "500\n700\n900\n"}, {"input": "5 2\n100 200 300 400 500\n1 1\n3 2\n", "output": "... | code_stdio |
[
{
"content": "Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.\n\nOne two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).\n\nThe University works in su... | [{"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "100\n"}, {"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | code_stdio |
[
{
"content": "Given is an integer sequence A_1, ..., A_N of length N.\nWe will choose exactly \\left\\lfloor \\frac{N}{2} \\right\\rfloor elements from this sequence so that no two adjacent elements are chosen.\nFind the maximum possible sum of the chosen elements.\nHere \\lfloor x \\rfloor denotes the greatest... | [{"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "5000000000\n"}, {"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 0000000000 1000000000 1000000000 1000000000", "output": "5000000000\n"}, {"input":... | code_stdio |
[
{
"content": "There are n cities numbered from 1 to n in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the ... | [{"input": "5\n0 954 1255 266 751\n954 0 1677 688 1173\n1255 1677 0 989 504\n266 688 989 0 485\n751 1173 504 485 0\n5\n5 2 1509\n3 4 692\n3 5 756\n3 1 151\n2 5 262\n", "output": "8742 7851 7851 6398 5111 "}, {"input": "5\n0 954 1255 266 751\n954 0 1677 688 1173\n1255 1677 0 989 504\n266 688 989 0 485\n751 1173 504 485 ... | code_stdio |
[
{
"content": "Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length.\n\nOver the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is very narrow and can be viewed as an infinite... | [{"input": "20 15\n7 8720.017100830131\n2 13067.215819731118\n8 58623.690996\n9 184322.3412850205\n6 227999.61123331118\n2 279836.330518\n9 282807.34217112145\n2 311057.23684687156\n1 312315.562927\n5 459200.373445\n14 563454.265947\n11 647366.9355815595\n13 679761.613732\n4 684192.647497\n3 733121.2686885264\n4 748638... | code_stdio |
[
{
"content": "Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. \n\nLittle Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure whic... | [{"input": "2\n2\n2 2\n3 2\n3\n-1 1 4 1\n1 4 1 4", "output": "1\n2\n"}, {"input": "2\n2\n2 2\n3 2\n3\n-1 1 2 1\n1 4 1 4", "output": "1\n2\n"}, {"input": "2\n2\n1 2\n2 1\n4\n1 2 1 1\n2 10 1 3", "output": "1\n2\n"}, {"input": "2\n1\n2 3\n2 1\n4\n2 1 4 1\n2 10 1 4", "output": "1\n2\n"}, {"input": "2\n2\n1 2\n2 1\n4\n1 4 1... | code_stdio |
[
{
"content": "Yukiya, the owner of Aizuyama Ski Resort, has prepared a course for advanced skiers with obstacles and jumping hills. There are various ways to slide on the course, and users who can slide in all patterns during the season will be given a gift.\n\nLet's create a program for the oil tree shop that ... | [{"input": "5 5\n0 0 0 0 1\n2 1 0 2 0\n1 0 0 1 1\n0 2 1 2 0\n0 1 -1 0 0\n5 5\n0 0 1 0 0\n2 1 0 2 0\n1 0 0 0 1\n0 2 1 2 0\n0 1 0 0 0\n15 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0... | code_stdio |
[
{
"content": "There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.\nYou can take and complete at most one of these jobs in a day.\nHowever, you cannot retake a job that you have already done.\nFind the maximum total ... | [{"input": "7791 7791\n7791 7707\n7789 2110\n7791 1594\n7791 2921\n7791 9233\n7791 9612\n7789 8647\n7790 5898\n7791 5096\n7789 9048\n7791 1635\n7790 623\n7790 7404\n7791 5805\n7790 9498\n7789 2644\n7791 1482\n7791 5994\n7791 1562\n7790 120\n7789 5327\n7789 9548\n7790 6224\n7791 5478\n7789 6056\n7789 1262\n7790 6328\n77... | code_stdio |
[
{
"content": "You 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 ... | [{"input": "21\n1 3218\n28 10924\n908802 141084\n82149 7374\n893257 19784\n3535315 802705\n2857 176\n691 227749\n1 3218\n28 10924\n436302 141084\n82149 9274\n893257 10248\n4004924 1003579\n2857 142\n114 209385\n1 1131\n28 10924\n1144405 141084\n132660 9274\n2346605 10248\n", "output": "3217\n10896\n78786\n6339\n16807\n... | code_stdio |
[
{
"content": "Dr. Hedro is astonished. According to his theory, we can make sludge that can dissolve almost everything on the earth. Now he's trying to produce the sludge to verify his theory.\n\nThe sludge is produced in a rectangular solid shaped tank whose size is N × N × 2. Let coordinate of two corner poin... | [{"input": "2\n14\n0", "output": "24\n328\n"}, {"input": "2\n12\n0", "output": "24\n264\n"}, {"input": "2\n10\n0", "output": "24\n216\n"}, {"input": "2\n18\n0", "output": "24\n440\n"}, {"input": "2\n24\n0", "output": "24\n608\n"}, {"input": "2\n10\n0", "output": "24\n216\n"}, {"input": "2\n12\n0", "output": "24\n264\n"... | code_stdio |
[
{
"content": "Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.\n\nThere are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the integers are distinct. \n\nUjan is lazy, so he will do ... | [{"input": "5\n10 -251 650 475 -114 364 -75754 -982 -532 -151 -484\n10 -623 -132 -317561 -438 20 -275 -323 -530089 -311 -587\n10 450900 -519 903 -401 -789 -606529 277 -267 -682 -161\n10 -246 873 -641 838 719 234 789 -74 -287288 -772972\n10 186 741 -927 -866 -855 578 -1057019 202 162962 -458\n", "output": "Yes\n650 3\n-... | code_stdio |
[
{
"content": "Kamil likes streaming the competitive programming videos. His MeTube channel has recently reached $100$ million subscribers. In order to celebrate this, he posted a video with an interesting problem he couldn't solve yet. Can you help him?\n\nYou're given a tree — a connected undirected graph cons... | [{"input": "32\n402528994560 0 0 0 0 0 0 932646223872 893192888700 0 813583026900 0 0 0 0 143521875000 0 177570054144 186624000000 0 517655600000 202145625000 341007975000 0 116252718750 0 148561875000 0 304819200000 248474688000 0 103125000000\n29 25\n20 24\n8 21\n23 3\n32 14\n29 30\n31 24\n28 12\n7 10\n18 1\n11 7\n29... | code_stdio |
[
{
"content": "Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.\n\nShe has only two pockets. She can put at most k pebbles in each ... | [{"input": "9 13\n132 166 200 62 168 51 185 192 118\n", "output": "51\n"}, {"input": "9 13\n132 166 200 62 168 58 185 192 118\n", "output": "52\n"}, {"input": "9 13\n132 166 200 62 168 58 106 192 118\n", "output": "49\n"}, {"input": "9 13\n132 166 200 62 168 58 299 192 118\n", "output": "56\n"}, {"input": "9 13\n186 16... | code_stdio |
[
{
"content": "There are N blocks arranged in a row. Let us paint these blocks.\nWe will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.\nFind the number of ways to paint the blocks under the following conditions:\n - For each block, ... | [{"input": "200000 200000 199999\n", "output": "703273590\n"}, {"input": "178720 187658 129518\n", "output": "963607179\n"}, {"input": "189770 199455 133747\n", "output": "971381227\n"}, {"input": "189992 49130 122242\n", "output": "956044281\n"}, {"input": "146600 147466 95872\n", "output": "932390522\n"}, {"input": "... | code_stdio |
[
{
"content": "Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.\n\nThe canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n ... | [{"input": "101 1\n----------------------------------------------------------------------------------------------------X\n----------------------------------------------------------------------------------------------------X\n", "output": "NO\n"}, {"input": "100 10\n-X------XXX--XXX-XXXXXX---XXX---X-XX--XXX----------XX-... | code_stdio |
[
{
"content": "You will be given a string S of length 3 representing the weather forecast for three days in the past.\nThe i-th character (1 \\leq i \\leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.\nYou will also be given a string T of length 3... | [{"input": "CSS\nCSR\n", "output": "2\n"}, {"input": "SSR\nSSR\n", "output": "3\n"}, {"input": "RRR\nSSS\n", "output": "0\n"}, {"input": "SSS\nSSS\n", "output": "3\n"}, {"input": "CCC\nSSS\n", "output": "0\n"}, {"input": "RSC\nRCS\n", "output": "1\n"}, {"input": "CCC\nSCS\n", "output": "1\n"}, {"input": "RRC\nCRS\n", "... | code_stdio |
[
{
"content": "This is the easy version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $k=2$.\n\nVasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer \"$k$ of goods for the... | [{"input": "8\n5 11 2\n2 4 3 5 14\n5 11 2\n2 4 3 5 7\n3 3 3\n4 2 6\n5 2 3\n10 1 3 9 2\n2 10000 2\n10100 10000\n2 9999 2\n10000 10000\n4 6 4\n3 2 3 2\n5 5 3\n1 2 2 1 2\n", "output": "4\n4\n1\n2\n1\n0\n4\n5\n"}, {"input": "8\n5 11 2\n2 3 3 5 13\n5 11 2\n2 4 3 5 7\n3 2 3\n4 2 6\n5 2 6\n10 1 3 9 2\n2 10000 2\n10100 10000\n... | code_stdio |
[
{
"content": "Polycarp is a beginner programmer. He is studying how to use a command line.\n\nPolycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be delete... | [{"input": "2 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac\n1\n", "output": "Yes\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | code_stdio |
[
{
"content": "You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc.\n\n-----Constraints-----\n - |S|=3\n - S consists of a, b and c.\n\n-----Input-----\nInput is given from Standard Input in the following format:\nS\n\n-----Output-----\nIf S can be obtai... | [{"input": "bac\n", "output": "Yes\n"}, {"input": "abc\n", "output": "Yes\n"}, {"input": "bab\n", "output": "No\n"}, {"input": "aaa\n", "output": "No\n"}, {"input": "cab", "output": "Yes\n"}, {"input": "acb", "output": "Yes\n"}, {"input": "cba", "output": "Yes\n"}, {"input": "bca", "output": "Yes\n"}, {"input": "bba", ... | code_stdio |
[
{
"content": "Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.\n\nA poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the... | [{"input": "100 100\n50 50\n", "output": "NO\n"}, {"input": "82 60\n100 38\n", "output": "YES\n"}, {"input": "100 100\n36 50\n", "output": "NO\n"}, {"input": "82 60\n100 64\n", "output": "YES\n"}, {"input": "150 35\n53 79\n", "output": "YES\n"}, {"input": "82 60\n100 52\n", "output": "YES\n"}, {"input": "166 12\n87 103... | code_stdio |
[
{
"content": "Numbers $1, 2, 3, \\dots n$ (each integer from $1$ to $n$ once) are written on a board. In one operation you can erase any two numbers $a$ and $b$ from the board and write one integer $\\frac{a + b}{2}$ rounded up instead.\n\nYou should perform the given operation $n - 1$ times and make the result... | [{"input": "1\n275\n", "output": "2\n275 274\n275 273\n274 272\n273 271\n272 270\n271 269\n270 268\n269 267\n268 266\n267 265\n266 264\n265 263\n264 262\n263 261\n262 260\n261 259\n260 258\n259 257\n258 256\n257 255\n256 254\n255 253\n254 252\n253 251\n252 250\n251 249\n250 248\n249 247\n248 246\n247 245\n246 244\n245 ... | code_stdio |
[
{
"content": "You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side.\n\nLet's call a connected component any non-extendible ... | [{"input": "10 10\n*.*...*.**\n..*...*.**\n.**.***...\n....*.*.**\n***....***\n.*..*...*.\n.***.*..*.\n.*****.*.*\n*.***.*...\n..*..*....\n", "output": "9.9...5.71\n..9...5.77\n.99.997...\n....9.5.77\n299....513\n.2..0...1.\n.490.0..9.\n.71120.7.1\n7.434.8...\n..6..2....\n"}, {"input": "10 10\n*.*...*.**\n..*...*.**\n.... | code_stdio |
[
{
"content": "Input\n\nThe only line of input contains three integers a1, a2, a3 (1 ≤ a1, a2, a3 ≤ 20), separated by spaces.\n\nOutput\n\nOutput a single integer.\n\nExamples\n\nInput\n\n2 3 2\n\n\nOutput\n\n5\n\n\nInput\n\n13 14 1\n\n\nOutput\n\n14\n\n\nInput\n\n14 5 9\n\n\nOutput\n\n464\n\n\nInput\n\n17 18 3\... | [{"input": "20 20 20\n", "output": "218920\n"}, {"input": "1 19 20\n", "output": "132716\n"}, {"input": "10 11 15\n", "output": "10480\n"}, {"input": "10 11 12\n", "output": "2474\n"}, {"input": "12 9 18\n", "output": "42420\n"}, {"input": "1 19 15\n", "output": "11967\n"}, {"input": "1 19 17\n", "output": "31330\n"}, ... | code_stdio |
[
{
"content": "Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that... | [{"input": "4\n1000000000 1000000000 1000000000 99999999\n", "output": "First\n"}, {"input": "4\n1000000000 1000000000 1000000000 99999999\n", "output": "First\n"}, {"input": "4\n1000000000 1000000001 1000000000 99999999\n", "output": "First\n"}, {"input": "4\n1000000000 1000000001 1000000000 80256192\n", "output": "Fi... | code_stdio |
[
{
"content": "There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.\n\nThe university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of students from all $a+b$ students, which you can ... | [{"input": "64 59 2\n.*.***......****.*..**..**..****.*.*.*.**...**..***.***.*..*..*.\n", "output": "23\n"}, {"input": "64 59 2\n.*.***......****.*..**..**..****.*.*.*.**...**..***.***.*..*..*.\n", "output": "23\n"}, {"input": "64 59 3\n.*.***......****.*..**..**..****.*.*.*.**...**..***.***.*..*..*.\n", "output": "24\... | code_stdio |
[
{
"content": "A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.\n\nA performer holding the rod low is represented by a 1, while one holding it high is repr... | [{"input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | code_stdio |
[
{
"content": "You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.\n\nWe'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|.\n\nString x = x1x2... x|x| is lexicographically ... | [{"input": "zyxzxzwyxywxxwabcdabdacdbcacdbcacabaaba\n", "output": "zzzyyxxwddddccbba\n"}, {"input": "zyxzxzwyxybxxwabcdawdacdccacdbcacabaaba\n", "output": "zzzyyxxwwdddccbba\n"}, {"input": "thankstosamarasauteddybearsforthiscontest\n", "output": "yttt\n"}, {"input": "thamkstosamarasauteddybearsforthiscontest\n", "outpu... | code_stdio |
[
{
"content": "A string $s$ of length $n$ ($1 \\le n \\le 26$) is called alphabetical if it can be obtained using the following algorithm:\n\nfirst, write an empty string to $s$ (i.e. perform the assignment $s$ := \"\");\n\nthen perform the next step $n$ times;\n\nat the $i$-th step take $i$-th lowercase letter ... | [{"input": "11\na\nba\nab\nbac\nihfcbadeg\nz\naa\nca\nacb\nxyz\nddcba\n", "output": "YES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n"}, {"input": "11\na\nba\nab\ncac\nihfcbadeg\nz\nab\nca\nbca\nxyz\nddcba\n", "output": "YES\nYES\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\n"}, {"input": "11\na\nba\nab\nbac\nihfcbadeg\nz\n... | code_stdio |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.