info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"1\\n\", \"4\\n\", \"6\\n\", \"2\\n\", \"205078485761\\n\", \"873109054817\\n\", \"518649879439\\n\", \"401021537803\\n\", \"821985629174\\n\", \"614685146646\\n\", \"551519879446\\n\", \"583102513046\\n\", \"690824608515\\n\", \"681460970070\\n\", \"355170254369\\n\", \"924639053494\\n\", \"7...
Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a, b) such that LCM(a, b) equals X. Both a and b should be positive integers. LCM(a, b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6, 8) = 24, LCM(4, 12) = 12, LCM(2, 3) = 6. O...
0.5
{"tests": "{\"inputs\": [\"5\\n1 2\\n2 3\\n3 4\\n4 5\\n5\\n1 3 1 2 2\\n1 4 1 3 2\\n1 4 1 3 3\\n4 2 3 3 9\\n5 2 3 3 9\\n\", \"9\\n3 9\\n3 4\\n7 2\\n6 9\\n5 3\\n6 2\\n8 3\\n1 9\\n10\\n8 4 8 2 5\\n9 2 7 4 4\\n8 5 7 3 3\\n1 2 3 8 4\\n2 9 2 4 3\\n6 4 3 4 5\\n6 7 6 6 4\\n7 5 3 1 4\\n5 4 7 8 3\\n4 5 1 5 2\\n\", \"14\\n4 9\\n3...
Gildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree? Then he found that such tree-like graphs are called 1-trees. Since Gildong was bored of solving too many tree problems, he wan...
0
{"tests": "{\"inputs\": [\"7\\n1\\n2\\n3\\n4\\n5\\n100\\n2000000\\n\", \"3\\n1234567\\n1268501\\n1268499\\n\", \"3\\n60615\\n1268501\\n1268499\\n\", \"7\\n1\\n2\\n3\\n4\\n5\\n110\\n2000000\\n\", \"3\\n89610\\n1268501\\n1268499\\n\", \"7\\n2\\n2\\n5\\n4\\n5\\n110\\n2000000\\n\", \"7\\n2\\n2\\n5\\n4\\n5\\n100\\n2000000\\...
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level n ...
0
{"tests": "{\"inputs\": [\"4\\n3\\n1 4 2\\n1 3 1\\n2\\n2 4\\n2 3\\n2\\n1 1000000000\\n1 1000000000\\n4\\n3 10 5 8\\n2 5 2 4\\n\", \"4\\n3\\n1 4 2\\n1 3 1\\n2\\n2 4\\n2 3\\n2\\n1 1100000000\\n1 1000000000\\n4\\n3 10 5 8\\n2 5 2 4\\n\", \"4\\n3\\n1 6 2\\n1 3 1\\n2\\n2 4\\n2 3\\n2\\n1 1100000000\\n1 1000000000\\n4\\n3 10 ...
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r ...
0
{"tests": "{\"inputs\": [\"3 2\\n2 1\\n3 2\\n3 1\\n\", \"4 3\\n4 1\\n1 2\\n2 2\\n3 2\\n\", \"11 11\\n6 2\\n6 2\\n1 2\\n2 2\\n3 1\\n6 2\\n1 1\\n1 1\\n3 1\\n3 1\\n6 2\\n\", \"21 7\\n14 1\\n882797755 2\\n17 1\\n906492329 2\\n209923513 2\\n802927469 2\\n949195463 2\\n677323647 2\\n2129083 2\\n2 1\\n13 1\\n539523264 2\\n7 1...
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheape...
0
{"tests": "{\"inputs\": [\"abc\\ndefg\\n\", \"czaaab\\nabcdef\\n\", \"aad\\naac\\n\", \"abad\\nbob\\n\", \"z\\na\\n\", \"abc\\naaac\\n\", \"bcbcdddbbd\\nbcbcdbdbbd\\n\", \"aaabccadac\\nacabbbabaa\\n\", \"a\\nb\\n\", \"acaccaaadz\\ncaadccaaaa\\n\", \"aa\\nab\\n\", \"abacaba\\naba\\n\", \"aabbaa\\naaaaaaaaaaaaaaaaaaaa\\n...
Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep...
0
{"tests": "{\"inputs\": [\"2 1 0\\n\", \"2 2 4\\n0 1 2 1\\n0 1 2 1\\n1 2 1 0\\n1 1 1 2\\n\", \"2 2 1\\n0 1 1 1\\n\", \"5 5 20\\n3 1 3 3\\n1 2 2 2\\n4 3 4 2\\n3 2 2 2\\n3 4 2 4\\n4 1 4 5\\n4 3 5 3\\n5 1 0 1\\n0 1 5 1\\n3 5 3 1\\n3 1 3 2\\n1 5 1 0\\n3 4 3 3\\n3 3 3 4\\n1 3 3 3\\n2 5 2 1\\n0 2 1 2\\n2 1 0 1\\n4 3 5 3\\n1 ...
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid l...
0
{"tests": "{\"inputs\": [\"7\\n0 8 9\\n5 9 -2\\n6 -8 -7\\n9 4 5\\n-4 -9 9\\n-4 5 2\\n-6 8 -7\\n\", \"2\\n1 0 0\\n1 1 0\\n\", \"3\\n1 0 0\\n0 1 0\\n0 0 1\\n\", \"3\\n7089544 9134148 -5332724\\n368810 1638695 7889905\\n-3866235 -4257263 5802154\\n\", \"16\\n-3253484 -6513322 5617669\\n-8870526 9976385 -7313669\\n5682511 ...
In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has n mandatory quests. To perform each of them, you need to take exactly two companions. The attitude of each of the companions to the hero is an integer. Initially, the attitude of each o...
0
{"tests": "{\"inputs\": [\"5 3\\n1 2 3 4 0\\n4 1 2 14 3\\n\", \"7 3\\n1 2 3 4 3 2 6\\n6 3 1 4 2 2 3\\n\", \"4 4\\n0 1 2 3\\n0 1 2 3\\n\", \"1 1\\n0\\n10000\\n\", \"2 3\\n1 0\\n4 7\\n\", \"1 2\\n0\\n10000\\n\", \"3 10\\n0 1 2\\n9240 5331 6721\\n\", \"4 10\\n2 1 2 1\\n960 2596 3752 8303\\n\", \"6 10\\n0 3 3 5 3 5\\n4845 ...
You are given a functional graph. It is a directed graph, in which from each vertex goes exactly one arc. The vertices are numerated from 0 to n - 1. Graph is given as the array f0, f1, ..., fn - 1, where fi — the number of vertex to which goes the only arc from the vertex i. Besides you are given array with weights o...
0.25
{"tests": "{\"inputs\": [\"3\\nkek\\npreceq\\ncheburek\\n\", \"4\\nmail\\nai\\nlru\\ncf\\n\", \"2\\nab\\nac\\n\", \"2\\nca\\ncb\\n\", \"2\\ndc\\nec\\n\", \"2\\naz\\nzb\\n\", \"2\\naa\\nb\\n\", \"25\\nsw\\nwt\\nc\\nl\\nyo\\nag\\nz\\nof\\np\\nmz\\nnm\\nui\\nzs\\nj\\nq\\nk\\ngd\\nb\\nen\\nx\\ndv\\nty\\nh\\nr\\nvu\\n\", \"...
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res...
0
{"tests": "{\"inputs\": [\"aabb\\n\", \"aabcaa\\n\", \"bbbbbbbbaaaaaaaaaaaccccccaaaaaaaaaaaaaaccccccccaaaaaaaaabbbbbbccbbbaaaaaabccccccaaaacaaacccccccccccb\\n\", \"ccccccccccccccccccccccccccccccccaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccccccc\\n\", \"aaaaabbbbbaaaaabbbbaaabbbbbbbaaabbbbbabbbbbbbaa...
You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one from the left and one from the right. You perform a sequence of operations on this set of p...
0.75
{"tests": "{\"inputs\": [\"10\\n1 2 3 4 5\\n\", \"6\\n1 2 6\\n\", \"10\\n9 8 7 6 5\\n\", \"100\\n41 13 29 11 25 15 6 23 28 50 48 17 3 9 44 24 5 19 34 22 33 32 20 16 35 37 4 10 46 2 39 40 47 49 36 42 1 30 43 21 14 7 18 45 31 8 12 26 27 38\\n\", \"10\\n10 9 8 1 5\\n\", \"6\\n3 5 6\\n\", \"6\\n1 4 5\\n\", \"100\\n84 10 26...
You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to <image>. In one step you can mov...
0.25
{"tests": "{\"inputs\": [\"1\\n3 3\\n1 2\\n2 3\\n1 3\\n\\nSAMPLE\", \"1\\n3 3\\n1 2\\n2 3\\n1 3\", \"1\\n3 3\\n1 2\\n3 3\\n1 3\", \"1\\n2 3\\n0 0\\n2 -1\\n0 1\\n\\nSANPLE\", \"1\\n3 3\\n1 2\\n2 3\\n1 3\\n\\nELPMAS\", \"1\\n3 3\\n1 2\\n2 3\\n2 3\\n\\nELPMAS\", \"1\\n3 3\\n1 0\\n2 3\\n2 3\\n\\nELPMAS\", \"1\\n3 3\\n1 2\\...
Leonard has decided to quit living with Dr. Sheldon Cooper and has started to live with Penny. Yes, you read it right. (And you read it here for the first time!) He is fed up of Sheldon, after all. Since, Sheldon no more has Leonard to drive him all around the city for various things, he's feeling a lot uneasy so he de...
0.625
{"tests": "{\"inputs\": [\"2 1 2\\n1 2\", \"5 4 5\\n1 2\\n1 3\\n1 4\\n1 5\", \"5 4 1\\n1 2\\n2 3\\n3 4\\n3 5\", \"9 6 1\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n4 7\\n7 8\\n8 9\", \"5 4 5\\n1 2\\n1 3\\n2 4\\n1 5\", \"5 4 1\\n1 2\\n1 3\\n3 4\\n3 5\", \"9 6 1\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n4 7\\n4 8\\n8 9\", \"5 4 1\\n1 2\\n2 3\...
We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally. Takahashi is standing at Vertex u, and Aoki is standing at Vertex v. Now, they will play a game of tag as follows: * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vert...
0
{"tests": "{\"inputs\": [\"3 3 3\\n#.#\\n#S.\\n###\", \"3 3 3\\n.#\\nS.\", \"3 3 3\\n\\nS#\", \"7 7 2\\n\\n\\n...##\\nS###\\n.#.##\\n.###\", \"2 3 3\\n.#\\nS.\", \"7 8 2\\n\\n\\n...##\\n###S\\n.#.##\\n.###\", \"7 7 2\\n\\n\\n##...\\nS###\\n.#.##\\n.###\", \"2 3 3\\n#.\\nS.\", \"7 7 2\\n\\n\\n##...\\nS###\\n##.#.\\n.###...
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the r...
0
{"tests": "{\"inputs\": [\"341143514535\\n314\\n143565553551655311343411652235654535651124615163\\n551544654451431564\\n4\\n3411\\n6363636363\\n153414\", \"341143514535\\n158\\n143565553551655311343411652235654535651124615163\\n551544654451431564\\n4\\n3411\\n6363636363\\n153414\", \"341143514535\\n314\\n10141283183115...
One day, Taro received a strange email with only the number "519345213244" in the text. The email was from my cousin, who was 10 years older than me, so when I called and asked, "Oh, I sent it with a pocket bell because I was in a hurry. It's convenient. Nice to meet you!" I got it. You know this cousin, who is always ...
0
{"tests": "{\"inputs\": [\"5\\n8 5\\n6 4\\n4 3\\n7 10\\n0 10\\n10\\n10 5\\n2 7\\n9 7\\n8 10\\n10 2\\n1 2\\n8 1\\n6 7\\n6 0\\n0 9\\n5\\n904207 809784\\n845370 244806\\n499091 59863\\n638406 182509\\n435076 362268\\n10\\n757559 866424\\n114810 239537\\n519926 989458\\n461089 424480\\n674361 448440\\n81851 150384\\n459107...
problem You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up th...
0.625
{"tests": "{\"inputs\": [\"2 7\\n4\\n2\\n1\\n0\\n-1\\n-2\\n-4\\n131\\n137\\n2 7\\n4\\n2\\n1\\n0\\n-1\\n-2\\n-4\\n131\\n123\\n10 7\\n-4\\n-2\\n-1\\n0\\n1\\n2\\n4\\n132\\n134\\n135\\n134\\n132\\n128\\n124\\n122\\n121\\n122\\n5 1\\n255\\n0\\n0\\n0\\n0\\n0\\n4 1\\n0\\n255\\n0\\n255\\n0\\n0 0\", \"2 7\\n4\\n2\\n1\\n0\\n-1\\...
Differential pulse code modulation is one of the compression methods mainly used when compressing audio signals. The audio signal is treated as an integer sequence (impulse sequence) on the computer. The integer sequence is a sample of the input signal at regular time intervals and the amplitude recorded. In general, ...
0
{"tests": "{\"inputs\": [\"4 6 0\\n0 1 3\\n0 2 2\\n2 0 1\\n2 3 1\\n3 0 1\\n3 1 5\", \"6 10 0\\n0 2 7\\n0 1 1\\n0 3 5\\n1 4 9\\n2 1 6\\n1 3 2\\n3 4 3\\n4 2 2\\n2 5 8\\n3 5 3\", \"4 6 0\\n0 1 3\\n0 2 2\\n2 0 1\\n2 3 2\\n3 0 1\\n3 1 5\", \"6 10 0\\n0 2 7\\n0 1 1\\n0 3 5\\n1 4 9\\n2 1 6\\n1 3 2\\n3 4 3\\n4 2 2\\n1 5 8\\n3 ...
Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E). Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 1,000 * 0 ≤ wi ≤ 10,000 * G has arborescence(s) with the root r Input |V| |E| r s0 t0 w0 s1 t1 w1 : s|E|-1 t|E|-1 w|E|-1 , where |V| is the...
0
{"tests": "{\"inputs\": [\"14 3 2012\", \"14 2 2012\", \"14 4 2012\", \"14 4 1177\", \"20 4 1177\", \"20 4 1433\", \"20 3 1433\", \"14 3 1433\", \"14 3 1186\", \"14 1 1186\", \"7 1 1186\", \"7 2 1186\", \"7 2 1946\", \"7 1 1946\", \"10 1 1946\", \"10 1 3808\", \"2 1 3808\", \"2 1 6973\", \"0 1 6973\", \"0 2 6973\", \"0...
Computation of the date either previous or forthcoming dates is quiet easy. But it is quiet difficult to calculate the day from a particular given date. You are required to find a day from a particular date given to you. Input It consists of a single line entry consisting of date in format dd mm yyyy. i.e. the input...
0
{"tests": "{\"inputs\": [\"5 4\\n2 4 8 2 4\\n8\\n5\\n14\\n10\\n\", \"1 10\\n8\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n16\\n\", \"1 10\\n4\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n16\\n\", \"1 10\\n2\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n16\\n\", \"1 10\\n1\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n16\\n\", \"3 3\\n1 1 1\\n1\\n2...
Polycarp has n coins, the value of the i-th coin is a_i. It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d). Polycarp wants to know answers on q queries. The j-th query is described as integer number b_j. The answer to the query is the minimum number of...
0.125
{"tests": "{\"inputs\": [\"3\\n2\\n&lt;&gt;\\n3\\n&gt;&lt;&lt;\\n1\\n&gt;\\n\", \"1\\n9\\n>>>>>>>><\\n\", \"13\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n\", \"14\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n>\\n1\\n...
You have a string s of length n consisting of only characters > and <. You may do some operations with this string, for each operation you have to choose some character that still remains in the string. If you choose a character >, the character that comes right after it is deleted (if the character you chose was the l...
0.375
{"tests": "{\"inputs\": [\"4\\n1 2\\n1 3\\n1 2\\n1 2\\n1 3\\n1 2\\n2 5\\n1 2\\n3 1\\n1 4\\n5 1\\n1 6\\n2 15\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n2 3\\n2 4\\n2 5\\n2 6\\n3 4\\n3 5\\n3 6\\n4 5\\n4 6\\n5 6\\n\", \"1\\n5 39\\n1 2\\n3 4\\n5 6\\n7 8\\n1 9\\n3 10\\n3 11\\n5 12\\n5 13\\n7 14\\n7 15\\n9 2\\n10 2\\n11 2\\n12 2\\n13 2...
You are given a graph with 3 ⋅ n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices. A set of edges is called a matching if no two edges share an endpoint. A set of vertices is called an independent set if no two vertices are connected with an edge. Input The first line...
0
{"tests": "{\"inputs\": [\"3\\nAZAMON APPLE\\nAZAMON AAAAAAAAAAALIBABA\\nAPPLE BANANA\\n\", \"3\\nAZAMON APPLE\\nAZAMON AAAAAAAAAAALIBABA\\nAPPLE BANANA\\n\", \"3\\nAZAMON APPLE\\nAZOMAN AAAAAAAAAAALIBABA\\nAPPLE BANANA\\n\", \"3\\nAZAMNO ELPPA\\nAZAMON AAAAAAAAAAALIBABA\\nAPPLE BANANA\\n\", \"3\\nAZAMON APPLE\\nAZAMON...
Your friend Jeff Zebos has been trying to run his new online company, but it's not going very well. He's not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he's not ranking high enough on the search engines. If only he could rename his products to have better ...
0
{"tests": "{\"inputs\": [\"2\\n3\\n3 2 1\\n6\\n3 1 4 1 5 9\\n\", \"1\\n5\\n1 3 4 5 2\\n\", \"1\\n3\\n1 1 274005660\\n\", \"4\\n7\\n6 6 8 8 6 6 6\\n1\\n2\\n5\\n4 5 9 8 7\\n7\\n1 2 7 1 6 10 2\\n\", \"2\\n3\\n1 1 1\\n2\\n1 1\\n\", \"2\\n2\\n1 1\\n1\\n1\\n\", \"2\\n5\\n5 5 5 5 5\\n3\\n1 2 5\\n\", \"2\\n5\\n1 2 3 4 5\\n4\\n...
Ehab 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? A sequence a is a subsequence of an array b if a can be obtained from b by deletion of several (pos...
0.75
{"tests": "{\"inputs\": [\"5\\n2 1\\n5 2\\n10 3\\n25 4\\n15441 33\\n\", \"5\\n2 1\\n5 2\\n10 3\\n25 4\\n25479 33\\n\", \"5\\n2 1\\n9 1\\n10 3\\n25 4\\n25479 33\\n\", \"5\\n1 1\\n9 1\\n10 3\\n46 4\\n25479 33\\n\", \"5\\n2 1\\n5 1\\n10 3\\n25 3\\n25479 33\\n\", \"5\\n2 1\\n9 1\\n10 3\\n25 4\\n25479 57\\n\", \"5\\n2 1\\n9...
Utkarsh is forced to play yet another one of Ashish's games. The game progresses turn by turn and as usual, Ashish moves first. Consider the 2D plane. There is a token which is initially at (0,0). In one move a player must increase either the x coordinate or the y coordinate of the token by exactly k. In doing so, the...
0.125
{"tests": "{\"inputs\": [\"-++-\\n\", \"++\\n\", \"+-\\n\", \"-\\n\", \"+-+--+-+\\n\", \"+-+--+\\n\", \"+-+++-\\n\", \"+++-\\n\", \"-++-+--++--+-++-\\n\", \"-+++--\\n\", \"-+--+-\\n\", \"+-++-+\\n\", \"+++---+++---\\n\", \"+-+-\\n\", \"-+-+-+\\n\", \"+++---\\n\", \"++--++\\n\", \"+---+\\n\", \"--++-+\\n\", \"-+\\n\", \...
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u...
0
{"tests": "{\"inputs\": [\"4 4\\n1 2 1 10\\n2 4 3 5\\n1 3 1 5\\n2 4 2 7\\n\", \"5 6\\n1 2 1 10\\n2 5 11 20\\n1 4 2 5\\n1 3 10 11\\n3 4 12 10000\\n4 5 6 6\\n\", \"5 5\\n1 5 9403 40347\\n1 3 13851 29314\\n4 5 1315 561894\\n3 5 2748 33090\\n5 3 10717 32306\\n\", \"2 1\\n1 2 1 1\\n\", \"1000 0\\n\", \"10 0\\n\", \"6 6\\n1 ...
Dima and Inna love spending time together. The problem is, Seryozha isn't too enthusiastic to leave his room for some reason. But Dima and Inna love each other so much that they decided to get criminal... Dima constructed a trap graph. He shouted: "Hey Seryozha, have a look at my cool graph!" to get his roommate inter...
0.25
{"tests": "{\"inputs\": [\"4 4\\n1 2\\n2 3\\n2 4\\n3 4\\n\", \"4 3\\n1 2\\n2 3\\n3 4\\n\", \"10 9\\n7 9\\n8 9\\n8 2\\n10 6\\n8 3\\n9 4\\n2 6\\n8 5\\n9 1\\n\", \"2 1\\n1 2\\n\", \"20 20\\n1 9\\n11 9\\n3 5\\n15 13\\n1 20\\n11 18\\n10 6\\n10 8\\n10 19\\n12 16\\n10 3\\n9 18\\n8 4\\n15 1\\n13 16\\n11 2\\n7 20\\n10 15\\n3 17...
The Berland capital (as you very well know) contains n junctions, some pairs of which are connected by two-way roads. Unfortunately, the number of traffic jams in the capital has increased dramatically, that's why it was decided to build several new roads. Every road should connect two junctions. The city administrat...
0
{"tests": "{\"inputs\": [\"1 1 1 4 4\\n\", \"2 0 0 0 4\\n\", \"4 5 6 5 6\\n\", \"1 100000 100000 100000 -100000\\n\", \"46456 -2621 -23623 -98302 -99305\\n\", \"9 20 0 40 0\\n\", \"100000 -100000 -100000 100000 100000\\n\", \"5 6 3 7 2\\n\", \"97741 23818 78751 97583 26933\\n\", \"99125 26876 -21414 14176 17443\\n\", \...
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle ...
0.125
{"tests": "{\"inputs\": [\"3 2\\n2 1 2\\n1 3\\n\", \"7 3\\n3 1 3 7\\n2 2 5\\n2 4 6\\n\", \"100 3\\n45 1 2 3 4 5 6 7 8 9 19 21 24 27 28 30 34 35 37 39 40 41 42 43 46 47 48 51 52 55 58 59 61 63 64 66 69 71 76 80 85 86 88 89 94 99\\n26 10 11 15 18 23 29 31 33 36 38 44 49 54 56 60 62 65 75 78 82 83 84 95 96 97 98\\n29 12 1...
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to n. A matryoshka with a smaller number can be ...
0
{"tests": "{\"inputs\": [\"4\\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\\n\", \"1\\n42\\n\", \"2\\n1 1 1 1\\n\", \"3\\n121339 121339 121339 55451923 531222142 121339 121339 435485671 121339\\n\", \"3\\n1 7 923264237 374288891 7 524125987 1 1 1\\n\", \"5\\n2029 6087 2029 2029 6087 2029 527243766 4058 2029 2029 2029 2029 2029 202...
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula <image> Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as <image>. For example, for array a = {4, 3, 6,...
0.875
{"tests": "{\"inputs\": [\"20 40 60 80 100\\n0 1 2 3 4\\n1 0\\n\", \"119 119 119 119 119\\n0 0 0 0 0\\n10 0\\n\", \"36 102 73 101 19\\n5 9 2 2 6\\n4 13\\n\", \"119 0 0 0 0\\n2 0 0 0 0\\n5 5\\n\", \"0 0 119 0 0\\n0 0 2 0 0\\n5 5\\n\", \"0 0 0 0 0\\n10 10 10 10 10\\n0 20\\n\", \"0 46 86 72 40\\n1 5 5 5 9\\n6 5\\n\", \"45...
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a...
0
{"tests": "{\"inputs\": [\"3\\n1 2 10\\n\", \"2\\n1 2\\n\", \"11\\n54 91 4 6 88 23 38 71 77 26 84\\n\", \"20\\n11 37 81 56 61 2 26 27 59 69 24 7 71 76 45 54 89 17 95 20\\n\", \"13\\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096\\n\", \"11\\n1 2 4 8 16 32 64 128 256 512 1024\\n\", \"4\\n2 4 1 3\\n\", \"15\\n1 2 3 4 5 10 2...
Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to t...
0
{"tests": "{\"inputs\": [\"5 2 4 13\\nhhwhh\\n\", \"3 1 100 10\\nwhw\\n\", \"5 2 4 1000\\nhhwhh\\n\", \"4 2 3 10\\nwwhw\\n\", \"5 2 4 12\\nhhhwh\\n\", \"2 5 5 1000000000\\nwh\\n\", \"16 1 1000 2100\\nhhhwwwhhhwhhhwww\\n\", \"1 2 3 3\\nw\\n\", \"10 2 3 32\\nhhwwhwhwwh\\n\", \"5 2 4 13\\nhhhwh\\n\", \"7 1 1000 13\\nhhhhw...
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a sec...
0
{"tests": "{\"inputs\": [\"3\\nTroll likes Dracul\\nDracul likes Anka\\nSnowy likes Hexadecimal\\n210 200 180\\n\", \"2\\nAnka likes Chapay\\nChapay likes Anka\\n10000 50 50\\n\", \"0\\n2000000000 2000000000 1\\n\", \"22\\nCleo likes Snowy\\nCleo likes Troll\\nChapay likes Dracul\\nSnowy likes Troll\\nDracul likes Chap...
The year of 2012 is coming... According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us...
0
{"tests": "{\"inputs\": [\"4\\n6 6 5 5\\n\", \"5\\n1 2 3 1 3\\n\", \"4\\n6 6 4 4\\n\", \"100\\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 4...
Let's denote a function <image> You are given an array a consisting of n integers. You have to calculate the sum of d(ai, aj) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n. Input The first line contains one integer n (1 ≤ n ≤ 200000) — the number of elements in a. The second line contains n integers a1, a2, ..., ...
0
{"tests": "{\"inputs\": [\"3 2\\n1 2\\n2 3\\n\", \"42 28\\n7 19\\n15 24\\n3 42\\n18 5\\n32 27\\n26 20\\n40 30\\n35 2\\n14 8\\n22 10\\n36 4\\n16 14\\n21 29\\n37 40\\n2 12\\n30 21\\n19 17\\n39 34\\n31 28\\n20 3\\n4 33\\n11 42\\n26 21\\n9 10\\n4 32\\n6 1\\n1 14\\n14 12\\n\", \"2 2\\n1 2\\n2 1\\n\", \"3 2\\n3 2\\n2 1\\n\",...
Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A f...
0
{"tests": "{\"inputs\": [\"12\\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932\", \"3\\n1 2 3\", \"12\\n161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 1765707086\", \"3\\n1 2 5\", \"12...
There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedures: * Choose an integer k between 1 and N-i (inclusive) with equ...
0
{"tests": "{\"inputs\": [\"5 1\\nbacba\", \"10 2\\nbbaabbbaab\", \"5 2\\nbacba\", \"10 2\\nbbbabbbaaa\", \"10 3\\nbbaabbbaab\", \"5 2\\nbacaa\", \"10 2\\nbaabbbaabb\", \"10 2\\nbaabbaaabb\", \"10 2\\nbbaaabbbab\", \"5 1\\nbabba\", \"10 2\\nbabbbbaabb\", \"10 1\\nbaabbaaabb\", \"5 1\\nbabbb\", \"10 2\\nbbaabbbbab\", \"1...
Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: * Let T be the string obtained by reversing S, and U be the string obtained by concatenating S and T in this order. * Let S' be some contiguous substring of U with length N, an...
0
{"tests": "{\"inputs\": [\"5 4\\n#.##\\n.##.\\n#...\\n..##\\n...#\", \"13 27\\n......#.........#.......#..\\n...#.....###..\\n..............#####...##...\\n...#######......#...#######\\n...#.....#.....###...#...#.\\n...#######....#.#.#.#.###.#\\n..............#.#.#...#.#..\\n.#.#.#...###..\\n...........#...#...#######\...
There are some coins in the xy-plane. The positions of the coins are represented by a grid of characters with H rows and W columns. If the character at the i-th row and j-th column, s_{ij}, is `#`, there is one coin at point (i,j); if that character is `.`, there is no coin at point (i,j). There are no other coins in t...
0
{"tests": "{\"inputs\": [\"aba\", \"abac\", \"babacccabab\", \"acac\", \"bacaccbabab\", \"ccaa\", \"bacaacbcbab\", \"babcbcaacab\", \"bababccacab\", \"bacaccbabac\", \"bacaccbaaac\", \"caaabccacab\", \"caaaaccacab\", \"bacaccaaaac\", \"baa\", \"caba\", \"babacccbaab\", \"aacc\", \"bacabcbabab\", \"bacaacccbab\", \"babc...
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible. Constraints * 1 \leq |S| \leq 10^5 * S consists of `a`...
0
{"tests": "{\"inputs\": [\"3\", \"1422\", \"1000000000000000000\", \"4\", \"1026\", \"1000000001000000000\", \"0\", \"530\", \"1100000001000000000\", \"1\", \"706\", \"1100000001000010000\", \"2\", \"152\", \"1100000001001010000\", \"7\", \"192\", \"1100000011001010000\", \"5\", \"292\", \"1100000001001010010\", \"271\...
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7. Constraints * 1≦N≦10^{18...
0
{"tests": "{\"inputs\": [\"1 2 0\\n1\\n1 2 1\\n1\\n1 2 100\\n1 2 1\\n2\\n1 2 100\\n2 2 1\\n1 2\\n1 2 100\\n4 5 3\\n1 2 3 4\\n1 1 2\\n2 2 100\\n4 3 60\\n0 0 0\", \"1 2 0\\n1\\n1 2 1\\n1\\n1 2 101\\n1 2 1\\n2\\n1 2 100\\n2 2 1\\n1 2\\n1 2 100\\n4 5 3\\n1 2 3 4\\n1 1 2\\n2 2 100\\n4 3 60\\n0 0 0\", \"1 2 0\\n1\\n1 2 1\\n1...
Taro went to a toy store to buy a game of life made by Aizu Hobby. Life games are played using a board with squares and roulette. As shown in the figure, the board has one start point and one goal point, which are connected by a single grid. First, the pieces are placed in the square at the starting point, and the piec...
0
{"tests": "{\"inputs\": [\"2 1\\n2 3\\n6 4\\n0 0\", \"3 1\\n2 3\\n6 4\\n0 0\", \"4 1\\n2 3\\n6 4\\n0 0\", \"3 1\\n4 3\\n6 4\\n0 0\", \"4 1\\n1 3\\n6 6\\n0 0\", \"5 1\\n4 3\\n6 6\\n0 0\", \"8 1\\n1 3\\n6 6\\n0 0\", \"5 1\\n4 3\\n12 4\\n0 0\", \"8 1\\n1 3\\n2 6\\n0 0\", \"5 1\\n4 3\\n23 4\\n0 0\", \"16 1\\n1 3\\n2 6\\n0 ...
Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful. First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has N × N rooms arranged in...
0
{"tests": "{\"inputs\": [\"5 1 5\\n1 0 1 0 0\\n0 2 1 0 0\\n2 0 0 1 0\\n1 0 0 1 0\\n0 1 1 0 1\\n0 0 0 1 0\\n0 0 0\", \"5 1 5\\n0 0 1 0 0\\n0 2 1 0 0\\n2 0 0 1 0\\n1 0 0 1 0\\n0 1 1 0 1\\n0 0 0 1 0\\n0 0 0\", \"5 1 5\\n1 0 1 0 1\\n0 2 1 0 0\\n2 0 0 1 0\\n1 0 0 1 0\\n0 1 1 0 1\\n0 0 0 1 0\\n0 0 0\", \"5 1 5\\n1 0 1 0 1\\n...
Alice and Bob are going to drive from their home to a theater for a date. They are very challenging - they have no maps with them even though they don’t know the route at all (since they have just moved to their new home). Yes, they will be going just by their feeling. The town they drive can be considered as an undir...
0
{"tests": "{\"inputs\": [\"8 5 2 0 5 5\\n0 1\\n0 3\\n0 6\\n1 2\\n6 7\\n3 4 7\\n4 5 2\", \"8 5 2 0 5 5\\n0 1\\n0 3\\n0 6\\n1 2\\n6 7\\n1 4 7\\n4 5 2\", \"8 5 2 0 5 5\\n0 1\\n0 3\\n0 2\\n1 2\\n6 7\\n3 4 7\\n4 5 2\", \"8 5 2 0 5 5\\n0 1\\n0 3\\n0 6\\n1 2\\n6 7\\n1 4 7\\n4 5 4\", \"8 5 2 0 5 5\\n0 2\\n0 3\\n0 6\\n1 2\\n6 7...
Problem statement You are a hero. The world in which the hero is traveling consists of N cities and M roads connecting different cities. Road i connects town a_i and town b_i and can move in both directions. The purpose of the brave is to start from town S and move to town T. S and T are different cities. The hero ca...
0
{"tests": "{\"inputs\": [\"73\\n6?\", \"73\\n?6\", \"73\\n@6\", \"73\\n5?\", \"73\\n?5\", \"73\\n4?\", \"73\\n?4\", \"73\\n?8\", \"73\\n?7\", \"73\\n7?\", \"73\\n?3\", \"73\\n3?\", \"73\\n?9\", \"73\\n?2\", \"73\\n70\", \"73\\n1?\", \"73\\n27\", \"73\\n?1\", \"73\\n49\", \"73\\n72\", \"73\\n59\", \"73\\n?0\", \"73\\n69...
D: Many Decimal Integers problem Given a string S consisting only of numbers (0-9) and a string T consisting only of numbers and `?`. S and T are the same length. Consider changing each `?` That exists in T to one of the numbers from 0 to 9 to create the string T'consisting of only numbers. At this time, it must be ...
0
{"tests": "{\"inputs\": [\"2\\n3 5\\n2 3\", \"2\\n3 7\\n2 3\", \"2\\n3 7\\n2 5\", \"2\\n3 7\\n0 5\", \"2\\n3 7\\n-1 5\", \"2\\n3 7\\n-1 7\", \"2\\n2 7\\n-1 7\", \"2\\n2 6\\n-1 7\", \"2\\n0 6\\n-1 7\", \"2\\n0 12\\n-1 7\", \"2\\n0 2\\n-1 7\", \"2\\n-1 2\\n-1 7\", \"2\\n-2 2\\n-1 7\", \"2\\n-2 1\\n-1 7\", \"2\\n-2 0\\n-1...
In the country of Numberia, there is a city called Primeland. Sherry is one of the rich inhabitants of the city, who likes to collect coins of various denominations. Coins in primeland are little strange , they are only available in prime denominations (i.e as coins of value 2,3,5 etc.).Sherry is taking a tour of the c...
0.75
{"tests": "{\"inputs\": [\"3\\n2 2 3\\n4 3 7\\n10 1 9\\n\", \"3\\n2 2 3\\n4 3 7\\n7 1 9\\n\", \"3\\n2 2 3\\n4 3 9\\n7 1 9\\n\", \"3\\n2 2 3\\n6 1 9\\n7 1 1\\n\", \"3\\n2 1 3\\n6 1 9\\n7 0 2\\n\", \"3\\n2 0 3\\n3 1 9\\n13 0 2\\n\", \"3\\n4 0 3\\n3 1 9\\n13 0 2\\n\", \"3\\n7 0 0\\n3 1 5\\n22 0 2\\n\", \"3\\n1 0 0\\n5 0 5...
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); * (-1, -1);...
0
{"tests": "{\"inputs\": [\"5\\n2 2\\n1 1 2 2\\n1 1 2 2\\n3 4\\n2 2 3 2\\n3 1 4 3\\n1 5\\n1 1 5 1\\n3 1 5 1\\n4 4\\n1 1 4 2\\n1 3 4 4\\n3 4\\n1 2 4 2\\n2 1 3 3\\n\", \"1\\n3456 4567\\n1 234 678 1000\\n346 903 1005 2003\\n\", \"5\\n2 2\\n1 1 2 2\\n1 1 2 2\\n3 5\\n2 2 3 2\\n3 1 4 3\\n1 5\\n1 1 5 1\\n3 1 5 1\\n4 4\\n1 1 4 ...
Recently, Masha was presented with a chessboard with a height of n and a width of m. The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is ...
0.25
{"tests": "{\"inputs\": [\"4\\n2 4\\n2 3\\n2 1\\n\", \"3\\n2 3\\n2 1\\n\", \"5\\n1 2\\n1 3\\n1 4\\n2 5\\n\", \"43\\n7 29\\n19 18\\n32 4\\n39 40\\n21 11\\n34 28\\n30 23\\n13 19\\n33 39\\n13 35\\n37 21\\n29 8\\n40 1\\n7 9\\n8 38\\n7 31\\n8 12\\n7 42\\n33 20\\n5 36\\n17 32\\n30 43\\n39 34\\n40 3\\n8 24\\n13 37\\n35 16\\n2...
You are given a tree with n nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied: For every two nodes i, j, look at the path between them and count the sum of numbers on the edges of this path. Write all obtained sums on the blackboard. Then every integer from ...
0
{"tests": "{\"inputs\": [\"2 3 1\\nabcabc\\n\", \"3 2 2\\nabcdef\\n\", \"5 5 5\\nuuuuuyyyyybbbbbqqqqqkkkkk\\n\", \"10 9 2\\nskpjgpwrqajrdnynybnsmybttmhkboiqlndqtghvqyorholdzwasytnvteawhahjfhjknhfobiifrtfrlbjkqyxgnc\\n\", \"10 1 3\\navdtkzddkk\\n\", \"3 2 2\\nabcdef\\n\", \"1 10 1\\nlduuukmwxx\\n\", \"9 1 9\\neeeeeeeee\...
Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it. At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words and minimize one of them. This was much harder! Formally, Lucy want...
0
{"tests": "{\"inputs\": [\"4\\n6 4 2\\n2 9 2 3 8 5\\n4 4 1\\n2 13 60 4\\n4 1 3\\n1 2 2 1\\n2 2 0\\n1 2\\n\", \"4\\n6 4 2\\n2 9 2 3 8 5\\n4 4 1\\n2 13 60 4\\n4 1 3\\n1 2 1 1\\n2 2 0\\n1 2\\n\", \"4\\n6 4 2\\n2 9 2 3 8 5\\n4 4 1\\n2 13 60 4\\n4 2 3\\n1 2 2 1\\n2 2 0\\n1 2\\n\", \"4\\n6 3 2\\n2 9 2 3 8 5\\n4 4 1\\n2 13 60...
You and your n - 1 friends have found an array of integers a_1, a_2, ..., 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, removes it, and keeps it for h...
0
{"tests": "{\"inputs\": [\"6 2\\n3 1 4 1 5 9\\n1 3\\n4 6\\n\", \"10 5\\n448242954 927941687 223935474 107020324 288030870 635970780 444360884 697847668 783719272 808030300\\n3 10\\n4 9\\n3 8\\n2 5\\n5 9\\n\", \"3 1\\n1000000000 1000000000 1000000000\\n1 3\\n\", \"30 27\\n698632656 525581861 577504542 296603772 99899094...
Given a sequence of integers a of length n, a tuple (i,j,k) is called monotone triples if * 1 ≤ i<j<k≤ n; * a_i ≤ a_j ≤ a_k or a_i ≥ a_j ≥ a_k is satisfied. For example, a=[5,3,4,5], then (2,3,4) is monotone triples for sequence a while (1,3,4) is not. Bob is given a sequence of integers a of length n in a ...
0
{"tests": "{\"inputs\": [\"4\\nvasya 0\\npetya 1\\nmanya 3\\ndunay 3\\n\", \"4\\na 0\\nb 2\\nc 0\\nd 0\\n\", \"23\\nfgtxkw 4\\nqgbokh 0\\nfrb 0\\nnninr 10\\nbczzdfvjkh 1\\nuxpelsmxxq 2\\nntvvx 2\\nardaae 0\\nctetnl 0\\nhgk 0\\nvmwo 18\\nojaubfibf 1\\nnu 7\\ngbixtuotft 4\\nekmjrgxylj 1\\navcygg 1\\nmxgdulijf 1\\notjmjmv...
In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand in queue in front of him. After a while the cashier has a lunch break and t...
0
{"tests": "{\"inputs\": [\"5\\n2 7\\n2 8\\n1 2\\n2 4\\n1 8\\n\", \"3\\n3 4\\n1 3\\n1 5\\n\", \"8\\n1 8\\n1 6\\n1 5\\n1 3\\n1 3\\n1 8\\n1 7\\n1 3\\n\", \"4\\n4 1\\n2 2\\n1 6\\n1 2\\n\", \"7\\n2 11\\n3 12\\n2 1\\n2 6\\n1 6\\n2 2\\n3 14\\n\", \"8\\n1 7\\n3 16\\n1 15\\n2 1\\n1 15\\n4 11\\n1 4\\n2 15\\n\", \"4\\n2 1\\n3 2\\...
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store: * The store has an infinite number of items of every product. * All products have the same price: 2 rubles per item. * ...
0
{"tests": "{\"inputs\": [\"0 1 1\\n1 0 1\\n1 1 0\\n\", \"0 3 6\\n5 0 5\\n4 7 0\\n\", \"0 100000 100000\\n100000 0 100000\\n100000 100000 0\\n\", \"0 99626 99582\\n99766 0 99258\\n99442 99398 0\\n\", \"0 6361 2304\\n1433 0 8103\\n7232 3175 0\\n\", \"0 28 10\\n12 0 24\\n26 8 0\\n\", \"0 97 56\\n69 0 71\\n84 43 0\\n\", \"...
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15...
0.875
{"tests": "{\"inputs\": [\"2\\n1 999\\n999 1\\n\", \"3\\n400 600\\n400 600\\n400 600\\n\", \"1\\n500 500\\n\", \"2\\n500 500\\n500 500\\n\", \"1\\n1 999\\n\", \"2\\n499 501\\n501 499\\n\", \"10\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n1 999\\n\", \"1\\n0 1000\\n\", \"1\\n1000 0\\n\", \"...
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. h...
0
{"tests": "{\"inputs\": [\"2 1 1\\n1\\n2\\n\", \"4 3 2\\n1\\n2\\n3\\n4\\n\", \"10 13 27\\n3\\n21\\n23\\n17\\n15\\n23\\n16\\n7\\n24\\n20\\n\", \"5 5 6\\n999999999\\n999999998\\n999999997\\n999999996\\n999999995\\n\", \"10 10 1\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n\", \"11 22 33\\n55\\n56\\n57\\n58\\n59\\n60\\n61\\...
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to...
0
{"tests": "{\"inputs\": [\"5\\n0 1 0 1 0\\n\", \"4\\n0 0 1 1\\n\", \"4\\n0 1 0 1\\n\", \"3\\n1 1 0\\n\", \"3\\n1 0 1\\n\", \"3\\n0 1 1\\n\", \"3\\n0 0 0\\n\", \"168\\n0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1...
A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practi...
0.75
{"tests": "{\"inputs\": [\"6 11 6\\n\", \"3 2 7\\n\", \"4 6 15\\n\", \"15 12 26\\n\", \"79 36 2854\\n\", \"11 34 383\\n\", \"16 78 712\\n\", \"76 69 4122\\n\", \"48 65 917\\n\", \"57 52 2634\\n\", \"12 17 15\\n\", \"62 1 501\\n\", \"70 24 1784\\n\", \"21 71 657\\n\", \"63 17 858\\n\", \"1 1 10000\\n\", \"2 17 105\\n\",...
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots. For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of dama...
0
{"tests": "{\"inputs\": [\"5 5 1 2 3\\n2 2 3\\n\", \"3 3 3 3 5\\n2 3 5 4 2\\n\", \"3 3 2 4 4\\n2 5 4 10\\n\", \"3 4 1 1 3\\n2 3 2\\n\", \"662 859 2 3 17\\n3 2 2 2 3 3 3 2 3 3 2 3 2 2 2 2 2\\n\", \"21865 53623 9 7 116\\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
0
{"tests": "{\"inputs\": [\"9\\n10 5 4 7 9 12 6 2 10\\n\", \"20\\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4\\n\", \"100\\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 97 5 502 584 567 79 543 444 413 463 455 316 545 329 437 443 9 435 291 384 328 501 603 234 285 297 453 587 550 72 130 163 282 298 605 349 270 198 2...
You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you...
0
{"tests": "{\"inputs\": [\"4 2 20\\n\", \"3 2 6\\n\", \"8 10 9\\n\", \"312 93 1000000000000000000\\n\", \"42 9 1000000000000000000\\n\", \"1000 1000 1000\\n\", \"963276084 698548036 1000000000\\n\", \"200 10 979220166595737684\\n\", \"3260 4439 6837\\n\", \"87 4 1000\\n\", \"6 3 417701740543616353\\n\", \"9 10000000000...
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The s...
0
{"tests": "{\"inputs\": [\"1\\n3 60 70 80 90 100 200\\n3 50 70 100 120 150 200\\n3 50 80 90 100 200 220\\n3 80 100 110 115 200 210\\n3 10 20 40 50 60 100\\n3 10 50 60 80 90 100\\n3 50 80 90 100 200 300\\n\\nSAMPLE\", \"1\\n3 60 70 80 90 100 200\\n3 50 70 100 120 150 200\\n3 50 80 90 100 200 279\\n3 80 100 110 115 200 2...
All the students in NIT are very lazy. They want to have maximum time for rest. But due to college rules, they must maintain 75% attendance at the end of every week. Given the schedule of a week, tell them what is the maximum amount of time they might have for resting. NOTE: Each day has 24 hrs. i.e. 24x60x60 second...
0
{"tests": "{\"inputs\": [\"4 3\\n1 3 2\\n2 4 3\\n1 4 6\", \"10 7\\n1 5 18\\n3 4 8\\n1 3 5\\n4 7 10\\n5 9 8\\n6 10 5\\n8 10 3\", \"4 2\\n1 2 1\\n3 4 2\", \"10 7\\n1 5 18\\n3 4 8\\n1 3 5\\n4 7 10\\n5 9 8\\n6 10 5\\n8 10 5\", \"4 2\\n1 2 2\\n3 4 2\", \"10 7\\n1 5 18\\n3 4 8\\n1 3 5\\n4 7 10\\n5 9 8\\n6 10 5\\n5 10 5\", \"...
We have N points numbered 1 to N arranged in a line in this order. Takahashi decides to make an undirected graph, using these points as the vertices. In the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph. The i-th operation is as follows: * The operation uses integers L_i ...
0
{"tests": "{\"inputs\": [\"3\\n1 1\\n4 3 2\", \"8\\n1 1 1 3 4 5 5\\n4 1 6 2 2 1 3 3\", \"1\\n\\n0\", \"3\\n1 2\\n1 2 3\", \"3\\n1 1\\n6 3 2\", \"8\\n1 2 2 3 4 5 5\\n4 1 6 2 2 1 3 3\", \"8\\n1 1 1 3 4 5 5\\n6 1 6 2 2 1 3 3\", \"1\\n\\n1\", \"3\\n1 1\\n6 6 2\", \"1\\n\\n2\", \"3\\n1 1\\n3 6 2\", \"1\\n\\n3\", \"3\\n1 1\\...
We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i. To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight. Snuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to all...
0
{"tests": "{\"inputs\": [\"6 6\\n1 2 3 4 5 6\\n8 6 9 1 2 0\\n3 1 4 1 5 9\\n2 6 5 3 5 8\\n1 4 1 4 2 1\\n2 7 1 8 2 8\", \"3 3\\n1 0 5\\n2 2 3\\n4 2 4\", \"6 6\\n1 2 3 4 5 6\\n8 6 9 1 2 0\\n3 1 4 1 5 9\\n2 6 5 3 5 8\\n1 4 1 4 2 1\\n2 10 1 8 2 8\", \"3 3\\n1 0 5\\n1 2 3\\n4 2 4\", \"6 6\\n1 2 3 4 5 6\\n8 6 9 1 2 0\\n1 1 4 ...
Input The input is given from standard input in the following format. > $H \ W$ $a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}$ $a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}$ $\vdots \ \ \ \ \ \ \ \ \ \ \vdots \ \ \ \ \ \ \ \ \ \ \vdots$ $a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}$ Output * Print the maximum number of souvenirs...
0
{"tests": "{\"inputs\": [\"9 1 8 2\\n4 1 5 9\\n4 6 8 2\\n4 6 3 2\", \"9 1 8 2\\n4 1 5 9\\n4 6 8 2\\n4 6 3 0\", \"9 1 8 2\\n6 1 5 9\\n4 6 8 2\\n2 6 3 0\", \"9 1 8 2\\n4 1 5 9\\n2 6 8 2\\n4 6 3 0\", \"9 1 8 2\\n6 2 5 9\\n4 6 8 2\\n4 6 3 0\", \"9 1 8 2\\n6 2 5 9\\n4 6 8 2\\n4 9 3 0\", \"9 1 8 2\\n6 1 2 9\\n4 6 13 2\\n2 6 ...
Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers: * The number of numbers which have the same place with numbers A imagined (Hit) * The number of numbers included (but different place) in the numbers A imagined (Blow) For example, if A imagin...
0.875
{"tests": "{\"inputs\": [\"a+b+c\\n(a+b)+c\\na- (b-c)+2\\n.\\n4ab\\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\\n2 b 2 a\\n.\\n108 a\\n2 2 3 3 3 a\\n4 a^1 27\\n.\\n.\", \"a+b+c\\n(a+b)+c\\na- (b-c)+2\\n.\\n4ab\\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\\n2 b 2 a\\n.\\n169 a\\n2 2 3 3 3 a\\n4 a^1 27\\n.\\n.\", \"a+b+c\\n(a+b)+c\\na- (b-c...
Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink. His hea...
0
{"tests": "{\"inputs\": [\"4 2\", \"5 1\", \"4 3\", \"0 1\", \"4 5\", \"6 5\", \"0 2\", \"4 1\", \"-1 1\", \"6 9\", \"0 8\", \"8 1\", \"6 3\", \"0 9\", \"1 8\", \"11 1\", \"8 3\", \"0 12\", \"1 10\", \"19 1\", \"8 2\", \"0 6\", \"2 8\", \"9 1\", \"0 11\", \"-1 11\", \"1 11\", \"-2 11\", \"0 4\", \"-3 11\", \"2 14\", \"...
Problem There are n vertices that are not connected to any of the vertices. An undirected side is stretched between each vertex. Find out how many sides can be stretched when the diameter is set to d. The diameter represents the largest of the shortest distances between two vertices. Here, the shortest distance is the...
0
{"tests": "{\"inputs\": [\"10 5 1 1 0\\n10 5 2 2 1\\n10 10 70 70 20\\n0 0 0 0 0\", \"10 5 1 1 0\\n10 5 2 2 1\\n10 10 71 70 20\\n0 0 0 0 0\", \"10 5 1 1 0\\n10 8 2 2 1\\n10 10 71 70 20\\n0 0 0 0 0\", \"10 5 1 1 1\\n10 8 2 2 1\\n10 10 71 70 20\\n0 0 0 0 0\", \"10 5 1 0 0\\n10 5 2 2 1\\n10 10 71 70 20\\n0 0 0 0 0\", \"17 ...
Problem Statement Alice is a private teacher. One of her job is to prepare the learning materials for her student. Now, as part of the materials, she is drawing a Venn diagram between two sets $A$ and $B$. Venn diagram is a diagram which illustrates the relationships among one or more sets. For example, a Venn diagra...
0
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n6 5 4\\n\", \"3\\n1 1000 10000\\n10 100 100000\\n\", \"6\\n12 8 12 17 20 5\\n17 4 8 8 8 4\\n\", \"6\\n4 1 12 9 3 11\\n12 20 19 12 19 11\\n\", \"1\\n1\\n1\\n\", \"2\\n1 2\\n1 1\\n\", \"1\\n7\\n5\\n\", \"6\\n16 20 18 7 14 2\\n17 12 4 10 7 4\\n\", \"6\\n20 8 12 17 20 5\\n17 4 8 8 8 4...
Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends...
0
{"tests": "{\"inputs\": [\"5 2 5\\n1\\n2\\n3\\n4\\n5\\n\", \"6 3 6\\n1\\n2\\n3\\n4\\n5\\n6\\n\", \"3 1 3\\n1\\n2\\n3\\n\", \"7 7 7\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n\", \"4 2 8\\n1\\n3\\n4\\n2\\n3\\n4\\n1\\n2\\n\", \"9 4 9\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n\", \"7 5 7\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n\", \"15 10 15\\n1\\n...
After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all. Sasha se...
0
{"tests": "{\"inputs\": [\"2\\nbnn\\na\\n\", \"3\\na\\nb\\na\\n\", \"9\\nlfpgbnlzyn\\nc\\ns\\nw\\nr\\nm\\nq\\ny\\nyinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy\\n\", \"6\\nu\\np\\nm\\nz\\nv\\nvv\\n\", \"4\\nqe\\nnd\\niqryhukieskfvaeettersinksrmazelxtgvartuz\\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...
Roman and Denis are on the trip to the programming competition. Since the trip was long, they soon got bored, and hence decided to came up with something. Roman invented a pizza's recipe, while Denis invented a string multiplication. According to Denis, the result of multiplication (product) of strings s of length m an...
0.125
{"tests": "{\"inputs\": [\"13 4 5\\n7 8 9 10\\n\", \"10 4 5\\n3 5 7 10\\n\", \"10 5 5\\n2 3 4 5 6\\n\", \"1 1 1\\n1\\n\", \"1000000000000000000 10 68\\n9818112234872670 233245257111863071 266483628625876079 375103213040049805 431982380866113633 489732004669478331 501030096787260719 541800997319766183 551892546260532408...
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed o...
0.75
{"tests": "{\"inputs\": [\"3\\n3\\n1 5\\n2 10\\n2 8\\n7\\n0 1\\n3 1\\n1 1\\n6 1\\n1 1\\n4 1\\n4 1\\n6\\n2 6\\n2 3\\n2 8\\n2 7\\n4 4\\n5 5\\n\", \"3\\n3\\n1 5\\n2 10\\n2 4\\n7\\n0 1\\n3 1\\n1 1\\n6 1\\n1 1\\n4 1\\n4 1\\n6\\n2 6\\n2 3\\n2 8\\n2 7\\n4 4\\n5 5\\n\", \"3\\n3\\n1 5\\n2 10\\n2 8\\n7\\n0 1\\n1 1\\n1 1\\n6 1\\n...
The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are n voters, and two ways to convince each of them to vote for you. The first way to convince the i-th voter is to pay him p_i coins....
0
{"tests": "{\"inputs\": [\"7 10 12\\n5 6\\n20 23\\n15 4\\n16 5\\n4 54\\n12 1\\n4 15\\n\", \"4 3 2\\n1 3\\n4 2\\n5 1\\n4 1\\n\", \"3 100 100\\n0 0\\n0 0\\n100 200\\n\", \"1 1000000000 7\\n1000000000 9\\n\", \"3 2 2\\n2 4\\n2 1\\n3 6\\n\", \"2 1000000000 100000\\n1000000000 1000000\\n1000000000 10000\\n\", \"1 100 100\\n...
The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes. The main school of the capital is located in (s_x, ...
0.375
{"tests": "{\"inputs\": [\"5\\n3 7 9 7 8\\n5 2 5 7 5\\n\", \"5\\n1 2 3 4 5\\n1 1 1 1 1\\n\", \"5\\n1000000000 1000000000 1000000000 1000000000 1000000000\\n100000 100000 100000 100000 100000\\n\", \"10\\n14 31 50 67 42 44 86 82 35 63\\n76 17 26 44 60 54 50 73 71 70\\n\", \"10\\n4 4 1 2 2 2 5 4 1 5\\n28 81 36 44 2 40 39...
VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications. The latest A/B test suggests that users are reading recommended publications more actively ...
0
{"tests": "{\"inputs\": [\"3\\n-10 6 -15\\n\", \"8\\n5 2 5 3 -30 -30 6 9\\n\", \"5\\n5 -2 10 -1 4\\n\", \"10\\n-3 4 -4 1 1 -4 -5 3 -4 -2\\n\", \"10\\n8 9 -10 -10 -4 -3 5 9 -9 9\\n\", \"6\\n5 -4 2 -1 2 -2\\n\", \"11\\n3 0 1 -2 5 -5 -1 0 3 2 2\\n\", \"10\\n4 -2 -2 -2 2 0 1 0 -4 -1\\n\", \"4\\n2 2 -3 4\\n\", \"11\\n-11 -7...
Alice and Bob are playing yet another card game. This time the rules are the following. There are n cards lying in a row in front of them. The i-th card has value a_i. First, Alice chooses a non-empty consecutive segment of cards [l; r] (l ≤ r). After that Bob removes a single card j from that segment (l ≤ j ≤ r). Th...
0.75
{"tests": "{\"inputs\": [\"500\\n\", \"198\\n\", \"545\\n\", \"2603340571199714716025114079373828413509944752618962350632892540710372640383149198328312562980217104434880337288055817064\\n\", \"670042\\n\", \"1099\\n\", \"8679647744\\n\", \"5057017252180797906185\\n\", \"404\\n\", \"4877\\n\", \"7665711\\n\", \"34676240...
Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly. Then Andrey got bored from looking at the same number and he started to swap digits first in one, then in the other number, then again in the first number and so o...
0
{"tests": "{\"inputs\": [\"4\\n4 5 7\\n4 1 3\\n1 2 5\\n2 3 8\\n2 4 1\\n3 4 4\\n4 6 5\\n1 2 1\\n1 3 1\\n1 4 2\\n2 4 1\\n4 3 1\\n3 2 1\\n3 2 10\\n1 2 8\\n1 3 10\\n5 5 15\\n1 2 17\\n3 1 15\\n2 3 10\\n1 4 14\\n2 5 8\\n\", \"4\\n4 5 7\\n4 2 3\\n1 2 5\\n2 3 8\\n2 4 1\\n3 4 4\\n4 6 5\\n1 2 1\\n1 3 1\\n1 4 2\\n2 4 1\\n4 3 1\\n...
There are n cities and m bidirectional roads in Berland. The i-th road connects the cities x_i and y_i, and has the speed limit s_i. The road network allows everyone to get from any city to any other city. The Berland Transport Ministry is planning a road reform. First of all, maintaining all m roads is too costly, ...
0
{"tests": "{\"inputs\": [\"4\\n4 2\\nabcd\\n3 1\\nabc\\n4 3\\naaaa\\n9 3\\nabaabaaaa\\n\", \"12\\n12 3\\nzazasqzqsasq\\n1 1\\nz\\n1 1\\na\\n15 4\\nabccbaabccbazaa\\n16 8\\ncadjfdsljfdkljds\\n6 2\\nbaazaa\\n6 3\\nbosszb\\n6 1\\nqwerty\\n7 7\\ndaaaaaa\\n14 2\\nacabcbdeffewzd\\n18 6\\nzzzzzzzzzzzzyyyyyz\\n9 4\\naabaabbbc\...
You are given a string s consisting of lowercase English letters and a number k. Let's call a string consisting of lowercase English letters beautiful if the number of occurrences of each letter in that string is divisible by k. You are asked to find the lexicographically smallest beautiful string of length n, which is...
0
{"tests": "{\"inputs\": [\"4 1 2 3 4\\n\", \"20 228 779 225 819 142 849 24 494 45 172 95 207 908 510 424 78 100 166 869 456\\n\", \"4 220 380 729 969\\n\", \"23 486 261 249 312 592 411 874 397 18 70 417 512 338 679 517 997 938 328 418 793 522 745 59\\n\", \"17 644 532 255 57 108 413 51 284 364 300 597 646 712 470 42 73...
How to make a cake you'll never eat. Ingredients. * 2 carrots * 0 calories * 100 g chocolate spread * 1 pack of flour * 1 egg Method. 1. Put calories into the mixing bowl. 2. Take carrots from refrigerator. 3. Chop carrots. 4. Take chocolate spread from refrigerator. 5. Put chocolate spread ...
0.375
{"tests": "{\"inputs\": [\"4\\n1 2 3 4\\n5\\n10 11 12 13 14\\n\", \"2\\n4 5\\n3\\n12 13 15\\n\", \"1\\n1\\n2\\n1 2\\n\", \"50\\n17 20 22 28 36 38 46 47 48 50 52 57 58 62 63 69 70 74 75 78 79 81 82 86 87 90 93 95 103 202 292 442 1756 1769 2208 2311 2799 2957 3483 4280 4324 4932 5109 5204 6225 6354 6561 7136 8754 9670\\n...
Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on t...
0
{"tests": "{\"inputs\": [\"rquwmzexectvnbanemsmdufrg\\n\", \"bbbabcbbb\\n\", \"gamjuklsvzwddaocadujdmvlenyyvlflipneqofeyipmtunbdmbdyhkovnpdetueeiunsipowrhxrhtastjniqdhmehcumdcrghewljvpikcraoouhfwtnoaukbnykjapkvyakdnckkypargamvnsqtchesbmuffqqycnjvolmtpjfykvkeexkpdxjexrvdzpcbthhkxuucermkaebrvcxoovidpqnpkgbhiatyjvumihptri...
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible. Input The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) c...
0
{"tests": "{\"inputs\": [\"1 100\\n1\\n40\\n\", \"2 100\\n1 1\\n60 60\\n\", \"2 100\\n1 1\\n25 30\\n\", \"5 5005\\n5 53 65 52 99\\n21 49 9 3 66\\n\", \"14 3615\\n81 79 13 94 54 69 92 5 47 98 40 64 44 88\\n52 73 7 12 29 40 46 47 60 66 63 68 71 4\\n\", \"7 529\\n77 18 67 64 43 51 30\\n35 87 17 52 1 97 84\\n\", \"16 1718\...
It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills. According to the borscht recipe it consists of n ingredients that have to be mixed in propor...
0.75
{"tests": "{\"inputs\": [\"2 2\\n50 2\\n10 1\\n\", \"2 2\\n0 2\\n0 2\\n\", \"3 3\\n50 3\\n50 2\\n25 2\\n\", \"2 2\\n0 2\\n100 2\\n\", \"37 4648\\n53 3169\\n66 4152\\n81 4540\\n98 4302\\n51 4427\\n42 2556\\n35 2288\\n56 2401\\n12 3864\\n45 4223\\n93 1809\\n4 2372\\n17 4357\\n67 1700\\n19 4508\\n5 2586\\n99 2754\\n4 3163...
It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the name of the song. After you tell the song name, Peter immediately plays the following song in order, and so on. The i-th...
0
{"tests": "{\"inputs\": [\"3 1\\n108\\n\", \"3 2\\n108\\n\", \"57 13\\n177946005798852216692528643323484389368821547834013121843\\n\", \"16 15\\n8086179429588546\\n\", \"14 6\\n00000000000001\\n\", \"200 100\\n56988719755815575893282254081467698462485803782142631369385180999746639622554559884281193367342283559238834106...
Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so that the result was a correct arithmetic expression; formally, no ...
0
{"tests": "{\"inputs\": [\"2\\n0 1\\n1 0\\n\", \"5\\n0 2 2 1 2\\n2 0 4 1 3\\n2 4 0 1 3\\n1 1 1 0 1\\n2 3 3 1 0\\n\", \"10\\n0 1 5 2 5 3 4 5 5 5\\n1 0 1 1 1 1 1 1 1 1\\n5 1 0 2 6 3 4 6 6 6\\n2 1 2 0 2 2 2 2 2 2\\n5 1 6 2 0 3 4 8 8 7\\n3 1 3 2 3 0 3 3 3 3\\n4 1 4 2 4 3 0 4 4 4\\n5 1 6 2 8 3 4 0 9 7\\n5 1 6 2 8 3 4 9 0 7\...
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n. Bob gave you all the values of ai, j that he wro...
0
{"tests": "{\"inputs\": [\"1 1 10\\n0101010101\\n\", \"2 2 3\\n000\\n000\\n\\n111\\n111\\n\", \"3 3 3\\n111\\n111\\n111\\n\\n111\\n111\\n111\\n\\n111\\n111\\n111\\n\", \"1 1 3\\n111\\n\", \"1 3 1\\n1\\n1\\n1\\n\", \"3 1 1\\n1\\n\\n1\\n\\n1\\n\", \"3 1 1\\n1\\n\\n0\\n\\n1\\n\", \"1 1 3\\n011\\n\", \"1 3 1\\n1\\n0\\n1\\n...
A super computer has been built in the Turtle Academy of Sciences. The computer consists of n·m·k CPUs. The architecture was the paralellepiped of size n × m × k, split into 1 × 1 × 1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbers from the layer nu...
0
{"tests": "{\"inputs\": [\"8 9\\n1 2\\n2 3\\n3 4\\n4 1\\n4 5\\n5 6\\n6 7\\n7 8\\n8 5\\n\", \"4 15\\n1 2\\n1 4\\n1 2\\n1 4\\n1 1\\n1 3\\n2 1\\n2 4\\n3 1\\n3 2\\n4 1\\n4 2\\n4 2\\n4 4\\n4 3\\n\", \"4 3\\n3 2\\n2 1\\n1 4\\n\", \"4 14\\n1 3\\n1 1\\n2 4\\n2 2\\n2 3\\n2 4\\n2 1\\n3 3\\n3 1\\n3 4\\n3 4\\n4 1\\n4 4\\n4 1\\n\",...
A famous sculptor Cicasso goes to a world tour! Well, it is not actually a world-wide. But not everyone should have the opportunity to see works of sculptor, shouldn't he? Otherwise there will be no any exclusivity. So Cicasso will entirely hold the world tour in his native country — Berland. Cicasso is very devoted ...
0
{"tests": "{\"inputs\": [\"1 2 2 1\\n\", \"1 1 1 2\\n\", \"2 12 3 1\\n\", \"38 38 701 74\\n\", \"10 10 1000 100\\n\", \"2 56 438 41\\n\", \"40 94 510 53\\n\", \"69 69 443 53\\n\", \"60 60 86 51\\n\", \"40 40 955 95\\n\", \"14 47 184 49\\n\", \"3 7 8 6\\n\", \"81 13 607 21\\n\", \"1 8 1 4\\n\", \"45 54 4 5\\n\", \"5 3 1...
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k, - k + 1, - k + 2, ..., - 2, - 1, 0, 1, 2, ..., k - 1, k) and add...
0
{"tests": "{\"inputs\": [\"5\\n1 1 1 3 3\\n3\\n2 1 6\\n\", \"6\\n1 2 2 2 1 2\\n2\\n5 5\\n\", \"5\\n1 2 3 4 5\\n1\\n15\\n\", \"3\\n2 1 3\\n1\\n6\\n\", \"3\\n3 2 1\\n1\\n6\\n\", \"3\\n1 2 2\\n1\\n5\\n\", \"2\\n1 1\\n1\\n1\\n\", \"5\\n1 2 3 4 5\\n3\\n1 2 3\\n\", \"5\\n3 3 2 2 1\\n2\\n8 3\\n\", \"3\\n3 2 5\\n1\\n10\\n\", \...
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city. Soon, monsters became hungry and began to eat each other. One monster can eat other monster if its weight is strictly greater than the weight of the monste...
0
{"tests": "{\"inputs\": [\"3 3\\n1 2\\n1 3\\n3 2\\n\", \"4 5\\n3 1\\n4 1\\n2 3\\n3 4\\n2 4\\n\", \"5 4\\n3 1\\n2 1\\n2 3\\n4 5\\n\", \"2 1\\n2 1\\n\", \"100 10\\n73 55\\n29 76\\n15 12\\n94 46\\n77 67\\n76 16\\n72 50\\n41 40\\n89 75\\n27 22\\n\", \"5 10\\n5 2\\n4 1\\n2 1\\n3 4\\n2 4\\n3 2\\n5 4\\n3 5\\n3 1\\n5 1\\n\", \...
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected. You should assign labels to all vertices in such a way that: * Labels form a valid permutation of length n — an integer sequence such that each integ...
0
{"tests": "{\"inputs\": [\"4 20 32\\n21 11 11 12\\n\", \"4 11 32\\n5 5 16 16\\n\", \"6 8 16\\n3 5 2 9 8 7\\n\", \"5 12 20\\n7 8 4 11 9\\n\", \"2 1 1\\n1 1000000\\n\", \"2 1 1\\n1 1\\n\", \"2 1 2\\n1 1\\n\", \"6 8 16\\n3 5 2 9 8 7\\n\", \"15 250 200\\n71 2 77 69 100 53 54 40 73 32 82 58 24 82 41\\n\", \"4 12 11\\n4 4 6 ...
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units. In order for production to work, it is needed ...
0
{"tests": "{\"inputs\": [\"ELEMENT\\n1 13\", \"ELEMENT\\n6 4\", \"ELEMENT\\n2 15\", \"ELEMENT\\n9 2\", \"ELEMENT\\n16 3\", \"ELEMENT\\n4 6\"], \"outputs\": [\"13\\n\", \"4\\n\", \"15\\n\", \"2\\n\", \"3\\n\", \"6\\n\"]}", "source": "primeintellect"}
In this problem your goal is to guess some secret permutation A of integers from 1 to 16. There are 17 tests in this problem. Test number i for 1 ≤ i ≤ 16 will have the following form: the first line of the input contains string "ELEMENT" (without quotes) the second line of the input of the test i contains two intege...
0.875
{"tests": "{\"inputs\": [\"4\\n5\\n11\\n45\\n23987443\\n\\nSAMPLE\", \"4\\n5\\n11\\n45\\n28960650\\n\\nSAMPLE\", \"4\\n5\\n11\\n45\\n19738501\\n\\nSAMPLE\", \"4\\n5\\n6\\n45\\n19738501\\n\\nSAMPLE\", \"4\\n5\\n6\\n73\\n19738501\\n\\nRALPME\", \"4\\n5\\n6\\n73\\n28777926\\n\\nRALPME\", \"4\\n7\\n6\\n73\\n28777926\\n\\nE...
Ali baba did a trick on the forty thieves and was able to trap them inside a big cave which was the home of wild wolves. The thieves are without any weapons, only the chief of the thieves has knife. With no weapons they will not be able to fight with the wolves, so they decide to kill themselves rather than being eate...
0.875
{"tests": "{\"inputs\": [\"10\", \"18\", \"7\", \"5\", \"8\", \"2\", \"6\", \"15\", \"4\", \"1\", \"11\", \"17\", \"3\", \"12\", \"9\", \"13\", \"20\", \"16\", \"14\", \"23\", \"29\", \"22\", \"35\", \"25\", \"26\", \"28\", \"41\", \"37\", \"31\", \"19\", \"21\", \"44\", \"72\", \"52\", \"24\", \"47\", \"54\", \"113\",...
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds. Given an integer K, list the K smallest Snuke numbers. Constraints * 1 \leq K...
0