messages listlengths 1 1 | ground_truth stringlengths 156 726k | dataset stringclasses 1
value |
|---|---|---|
[
{
"content": "It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.\n\nThere are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.\n\nFind the minimum distance to be traveled ... | [{"input": "8\n121 1 -1 -1 -3 3 0 1", "output": "124\n"}, {"input": "8\n0 -4 -1 21 -2 -15 4 2", "output": "36\n"}, {"input": "8\n0 -3 -1 27 -6 -18 4 2", "output": "45\n"}, {"input": "8\n-2 -1 0 1 3 -143 0 1", "output": "146\n"}, {"input": "8\n-2 -1 0 1 3 -149 0 1", "output": "152\n"}, {"input": "8\n0 -5 0 15 -1 -10 2 1... | code_stdio |
[
{
"content": "Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much. \n\nA song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can ... | [{"input": "10\n2 2 2 4 10 6 7 16 9 17\n1 2 3 5 5 6 7 8 18 10\n", "output": "157\n"}, {"input": "10\n1 2 0 4 10 4 7 16 9 17\n1 2 3 5 5 6 7 8 18 10\n", "output": "154\n"}, {"input": "10\n1 2 2 4 10 6 7 16 9 17\n1 2 3 5 5 6 7 8 18 10\n", "output": "157\n"}, {"input": "10\n1 2 2 4 10 4 7 16 9 17\n1 2 3 5 5 6 7 8 18 10\n",... | code_stdio |
[
{
"content": "Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo.\n\nSimply speaking, the process of phot... | [{"input": "10\n489 685\n857 870\n736 221\n687 697\n166 360\n265 200\n738 519\n393 760\n66 176\n798 160\n", "output": "3231747\n"}, {"input": "10\n489 685\n857 870\n736 221\n687 697\n166 360\n265 200\n738 519\n393 760\n66 176\n798 160\n", "output": "3231747\n"}, {"input": "10\n864 874\n534 702\n73 363\n856 895\n827 72\... | code_stdio |
[
{
"content": "Today is Chef's birthday. His mom has surprised him with truly fruity gifts: 2 fruit baskets. The first basket contains N apples, and the second one contains M oranges. Chef likes apples and oranges very much but he likes them equally, and therefore, wants to have the minimum possible difference b... | [{"input": "3\n-1 0 1\n13 0 5\n-1 4 3", "output": "0\n8\n2\n"}, {"input": "3\n-1 0 0\n13 0 5\n-1 4 3", "output": "1\n8\n2\n"}, {"input": "3\n10 -2 0\n7 0 2\n2 4 1", "output": "12\n5\n1\n"}, {"input": "3\n-1 0 0\n14 0 5\n-1 4 3", "output": "1\n9\n2\n"}, {"input": "3\n10 -2 0\n7 0 2\n2 6 1", "output": "12\n5\n3\n"}, {"in... | code_stdio |
[
{
"content": "Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!\n\nStill unsatisfied with the garland, Nadeko decided to polish it again. The garland has n pieces numb... | [{"input": "100\ndddddccccdddddaaaaabbbbbbbbbbbbbaaacdcabbacccacccccbdbbadddbbddddbdaaccacdddbbbaddddbbbbdcbbbdddddda\n50\n54 b\n48 d\n45 b\n52 c\n52 a\n48 a\n54 b\n45 a\n47 d\n50 d\n53 a\n34 a\n51 b\n48 d\n47 d\n47 a\n48 d\n53 b\n52 d\n54 d\n46 a\n38 a\n52 b\n49 a\n49 b\n46 c\n99 a\n45 b\n35 c\n55 c\n51 c\n46 d\n54 d\... | code_stdio |
[
{
"content": "An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its... | [{"input": "50\n39 8 41 9 45 1 5 18 38 31 28 7 12 49 33 19 26 6 42 13 37 27 2 21 20 22 14 16 48 47 32 50 25 17 35 24 36 4 29 15 43 10 11 30 40 46 3 23 44 34\n", "output": "46\n"}, {"input": "50\n43 15 10 33 32 31 13 7 5 22 36 1 25 14 38 19 8 6 24 42 28 21 44 35 4 3 49 30 27 46 2 9 17 37 45 41 18 39 12 11 16 20 50 26 29... | code_stdio |
[
{
"content": "As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written... | [{"input": "100 1\n92 93 p\n", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | code_stdio |
[
{
"content": "You are given a rectangular cake, represented as an r × c grid. Each cell either has an evil strawberry, or is empty. For example, a 3 × 4 cake may look as follows: [Image] \n\nThe cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil ... | [{"input": "10 10\n.....SSSSS\n.....SSSSS\n.....SSSSS\n.....SSSSS\n.....SSSSS\n..........\n..........\n..........\n..........\n..........\n", "output": "75\n"}, {"input": "10 10\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\nS...SSSSSS\n", "output": "30\n"},... | code_stdio |
[
{
"content": "Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.\n\nFrom the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical b... | [{"input": "15\n999999986 268435456\n999999987 67108864\n999999988 16777216\n999999989 4194304\n999999990 1048576\n999999991 262144\n999999992 65536\n999999993 16384\n999999994 4096\n999999995 1024\n999999996 256\n999999997 64\n999999998 16\n999999999 4\n1000000000 1\n", "output": "1000000001\n"}, {"input": "15\n999999... | code_stdio |
[
{
"content": "Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.\n\nTo bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, locate... | [{"input": "8 57 3\n1 3 15\n2 3 1\n1 7 21\n1 2 11\n2 1 16\n1 6 4\n1 3 2\n3 7 17\n5 8 3\n1 3 18\n1 4 3\n1 2 1\n2 8 14\n1 4 17\n4 5 21\n2 3 6\n3 5 11\n2 8 11\n3 4 1\n1 3 9\n1 4 3\n2 3 12\n1 5 9\n2 3 15\n1 2 14\n1 2 10\n1 4 19\n5 7 7\n5 8 20\n5 8 1\n1 4 3\n4 5 8\n5 7 1\n1 2 14\n4 5 9\n6 7 2\n2 6 9\n2 6 4\n3 7 4\n3 5 11\n4... | code_stdio |
[
{
"content": "Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-interesting, if their binary representation differs from each other exactly in k bits. For example, if k = 2, the pair of integers x = 5 and y = 3 is k-interesting, because their binary representation x=... | [{"input": "100 14\n8192 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8191 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8192 8192 8192 8192 8192 8192 8191 8191 8192 8192 8191 8191 8192 8192 8192 8191 8191 8192 8191 8191 8191 8191 8191 8191 8192 8191 8191 8192 8191 8191 8192 8192 8191 ... | code_stdio |
[
{
"content": "Musicians of a popular band \"Flayer\" have announced that they are going to \"make their exit\" with a world tour. Of course, they will visit Berland as well.\n\nThere are n cities in Berland. People can travel between cities using two-directional train routes; there are exactly m routes, i-th ro... | [{"input": "7 7\n1 6 745325\n2 3 3581176\n2 4 19\n3 6 71263060078\n5 4 141198\n7 4 163953\n5 6 15994\n1 297404206755 82096176217 14663411 187389745 21385 704393\n", "output": "1 335807 7498159 335769 53373 21385 663675 \n"}, {"input": "7 7\n1 6 745325\n2 3 3581176\n2 4 19\n3 6 71263060078\n5 4 170098\n7 4 163953\n5 6 1... | code_stdio |
[
{
"content": "Little C loves number «3» very much. He loves all things about it.\n\nNow he is playing a game on a chessboard of size n × m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Man... | [{"input": "1000000000 1000000000\n", "output": "1000000000000000000\n"}, {"input": "1000001000 1000000000\n", "output": "1000001000000000000\n"}, {"input": "1000001000 1100000000\n", "output": "1100001100000000000\n"}, {"input": "567298709 2116937786\n", "output": "1200936073031118274\n"}, {"input": "567298709 1327099... | code_stdio |
[
{
"content": "After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note a_{i} + j.\n\nTayuya wants to play a melody of n note... | [{"input": "58260522 77914575 2436426 24979445 61648772 23690081\n10\n582107247 906728404 411434947 673536177 411497300 488012525 561127307 800305059 992325267 112738006\n", "output": "804109112\n"}, {"input": "58260522 77914575 2436426 24979445 61648772 23690081\n10\n582107247 906728404 411434947 673536177 411497300 4... | code_stdio |
[
{
"content": "Takahashi has a string S of length N consisting of digits from 0 through 9.\nHe loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S - there are N \\times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten.\nHere substrings ... | [{"input": "20 11\n33883322005544116655\n", "output": "68\n"}, {"input": "20 16\n10763178948652303319", "output": "136\n"}, {"input": "20 16\n46280926482052991001", "output": "139\n"}, {"input": "20 8\n33883322005544116655", "output": "171\n"}, {"input": "20 2\n33883322005544116655", "output": "103\n"}, {"input": "20 1... | code_stdio |
[
{
"content": "There are n employees working in company \"X\" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place: either employee y became the boss of employee x (at that, employee... | [{"input": "2 10\n2 2\n1 2 1\n3 1 1\n3 2 1\n3 1 1\n2 2\n3 1 2\n3 1 1\n3 2 1\n3 1 2\n", "output": "NO\nYES\nNO\nYES\nNO\nYES\nYES\n"}, {"input": "2 10\n2 2\n1 2 1\n3 1 1\n3 1 1\n3 1 1\n2 2\n3 1 2\n3 1 1\n3 2 1\n3 1 2\n", "output": "NO\nNO\nNO\nYES\nNO\nYES\nYES\n"}, {"input": "2 10\n2 2\n1 2 1\n3 1 1\n3 1 1\n3 2 1\n2 2\... | code_stdio |
[
{
"content": "You are given four integers $n$, $B$, $x$ and $y$. You should build a sequence $a_0, a_1, a_2, \\dots, a_n$ where $a_0 = 0$ and for each $i \\ge 1$ you can choose:\n\neither $a_i = a_{i - 1} + x$\n\nor $a_i = a_{i - 1} - y$.\n\nYour goal is to build such a sequence $a$ that $a_i \\le B$ for all $i... | [{"input": "2\n100000 1000000000 1000000000 1\n100000 1 1000000000 10000\n", "output": "99995000050000\n-50000500000000\n"}, {"input": "7\n1 1 1 1\n2 2 2 2\n3 3 3 3\n4 4 4 4\n5 5 5 5\n6 6 6 6\n7 7 7 7\n", "output": "1\n2\n6\n8\n15\n18\n28\n"}, {"input": "3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3\n", "o... | code_stdio |
[
{
"content": "Память компьютера состоит из n ячеек, которые выстроены в ряд. Пронумеруем ячейки от 1 до n слева направо. Про каждую ячейку известно, свободна она или принадлежит какому-либо процессу (в таком случае известен процесс, которому она принадлежит).\n\nДля каждого процесса известно, что принадлежащие ... | [{"input": "24\n0 0 6 6 6 0 22 22 0 23 23 0 19 19 19 19 0 0 17 0 0 3 3 3\n", "output": "14\n"}, {"input": "21\n0 11 11 11 11 0 7 0 12 12 12 12 12 0 19 19 19 0 1 1 1\n", "output": "11\n"}, {"input": "24\n6 6 0 0 0 22 0 0 23 0 0 19 0 0 0 0 17 17 0 3 3 0 0 0\n", "output": "7\n"}, {"input": "21\n11 0 0 0 0 7 0 12 0 0 0 0 0... | code_stdio |
[
{
"content": "Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.\n\nMore formally, first one of four diagonal directions is chosen and ... | [{"input": "1000000 1000000\n", "output": "1000000\n"}, {"input": "666667 1000000\n", "output": "333334\n"}, {"input": "871866 348747\n", "output": "174374\n"}, {"input": "863029 287677\n", "output": "287677\n"}, {"input": "962963 1000000\n", "output": "37038\n"}, {"input": "701905 526429\n", "output": "175477\n"}, {"i... | code_stdio |
[
{
"content": "Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercas... | [{"input": "100\nqn\nBE\nyN\nep\nPq\nXz\nLM\nEZ\ndb\nMn\nbn\nFe\nqA\nzc\nyq\npC\nyA\nWk\nYq\nrs\noD\nvD\nzW\nxZ\nbl\nur\nkf\ndf\nLS\nUW\nMy\nhR\nsh\nNh\nog\nCW\nor\nzo\nrO\nao\nXH\nDq\nKa\nlL\nYQ\nOh\nRZ\nAx\nta\nko\nDn\nNg\nNy\nDB\nYD\njO\nAp\nFT\noB\nNc\nwB\nHO\neW\nAc\nDr\nMt\nDf\nbF\nFP\nRa\nnF\nhF\nXC\nnG\nan\nZY\... | code_stdio |
[
{
"content": "You are given a directed graph consisting of $n$ vertices. Each directed edge (or arc) labeled with a single character. Initially, the graph is empty.\n\nYou should process $m$ queries with it. Each query is one of three types:\n\n\"$+$ $u$ $v$ $c$\" — add arc from $u$ to $v$ with label $c$. It's ... | [{"input": "3 11\n+ 1 2 a\n+ 1 3 c\n+ 3 2 a\n+ 2 1 a\n? 6\n? 5\n- 2 1\n- 3 2\n+ 2 1 c\n+ 3 2 d\n? 5\n", "output": "YES\nYES\nYES\n"}, {"input": "3 11\n+ 1 2 a\n+ 1 3 c\n+ 3 2 a\n+ 2 1 a\n? 6\n? 5\n- 2 1\n- 3 2\n+ 2 1 c\n+ 3 3 d\n? 5\n", "output": "YES\nYES\nYES\n"}, {"input": "3 11\n+ 1 2 a\n+ 1 3 c\n+ 3 2 a\n+ 2 1 a\n... | code_stdio |
[
{
"content": "n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some g... | [{"input": "2 2\n100000000 100000000\n100000000 100000000\n", "output": "400000000\n"}, {"input": "2 2\n100000000 100000000\n101000000 100000000\n", "output": "401000000\n"}, {"input": "2 2\n72765050 72765049\n108366500 77716490\n", "output": "331613089\n"}, {"input": "2 2\n23720786 43602829\n112215563 67248253\n", "ou... | code_stdio |
[
{
"content": "Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.\n\nLet's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters \"a\", \"e\", \"i\", \"o\", \"u\" are considered ... | [{"input": "7 3\nferwljzwakxedlgwl\noerwljzwakxedlgwl\nhyqombizhuhxedprb\netptjrizhuhxedprb\nurtuckar\ndkartmwramklcmi\nrurtuckar\nnurartmwramklcmi\niraziomsv\nsaziomsv\nbprapiqpayzurgij\nusyemayzurgij\nztstmeecvmkvuu\nquexlecvmkvuu\nrlhwecvmkvuu\nzecvmkvuu\niikymgbncljtub\nqiikymgbncljtub\nbcavhexqamyszgfya\nojexqamys... | code_stdio |
[
{
"content": "Berland Football Cup starts really soon! Commentators from all over the world come to the event.\n\nOrganizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied ... | [{"input": "500000000001 1000000000000 100 100\n", "output": "49999999999900\n"}, {"input": "500000000001 1000000000000 100 100\n", "output": "49999999999900\n"}, {"input": "500000000001 1000000000000 110 100\n", "output": "50000000000100\n"}, {"input": "1000000000000 750000000001 10 100\n", "output": "5000000000020\n"... | code_stdio |
[
{
"content": "From the FAQ:\n\nWhat am I allowed to post as a comment for a problem? \n\nDo NOT post code.\nDo NOT post a comment asking why your solution is wrong.\nDo NOT post a comment asking if you can be given the test case your program fails on.\nDo NOT post a comment asking how your solution can be impro... | [{"input": "7\n1\n?\n2\n0?\n11\n69259?087\n4\n??\n2\n0?1\n4\n?????\n3\n22", "output": "0\n01\n692591087\n01\nNO\n01012\nNO\n"}, {"input": "7\n1\n?\n2\n0?\n11\n69259?087\n4\n??\n2\n0?1\n4\n?????\n3\n15", "output": "0\n01\n692591087\n01\nNO\n01012\n15\n"}, {"input": "7\n1\n?\n2\n0?\n11\n69259?087\n4\n?>\n2\n0?1\n4\n?????... | code_stdio |
[
{
"content": "Daniel is watching a football team playing a game during their training session. They want to improve their passing skills during that session.\n\nThe game involves $n$ players, making multiple passes towards each other. Unfortunately, since the balls were moving too fast, after the session Daniel... | [{"input": "1\n200\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ... | code_stdio |
[
{
"content": "This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can install the generators wherever you like, but in order for ... | [{"input": "6\n5 2\n10 30 40 70 100\n7 3\n3 5 10 53 21 26 28\n1 1\n100\n2 1\n-1 1000000\n3 5\n30 70 211\n6 5\n0 10 20 30 40 50", "output": "60\n-23\n0\n1000001\n0\n10\n"}, {"input": "6\n5 2\n10 30 40 70 100\n7 3\n3 5 10 53 21 26 28\n1 1\n100\n2 1\n-1 1000000\n3 5\n30 70 211\n6 5\n0 10 20 8 40 50", "output": "60\n-23\n0... | code_stdio |
[
{
"content": "Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team... | [{"input": "10\nU\nD\nU\nD\nU\nD\nU\nD\nU\nD", "output": "608"}, {"input": "8\nT\nD\nD\nD\nD\nD\nD\nC", "output": "0\n"}, {"input": "8\nT\nD\nD\nD\nD\nD\nC\nC", "output": "0\n"}, {"input": "8\nT\nD\nD\nD\nD\nE\nC\nC", "output": "0\n"}, {"input": "8\nS\nD\nD\nD\nD\nE\nC\nC", "output": "0\n"}, {"input": "8\nS\nD\nD\nD\nD... | code_stdio |
[
{
"content": "For an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.\nThen, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.\nFind the maximum possible value of M_1 + M_2 + \\cdots + M_N.\n\n-----Constraints-----\n - N is an integer satisfying 1 \\... | [{"input": "1000000000\n", "output": "499999999500000000\n"}, {"input": "999999999\n", "output": "499999998500000001\n"}, {"input": "999999998\n", "output": "499999997500000003\n"}, {"input": "234679769\n", "output": "27537296871606796\n"}, {"input": "160767\n", "output": "12922933761\n"}, {"input": "569\n", "output": ... | code_stdio |
[
{
"content": "Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.\n\nLucky number is super lucky if it's decimal representation contains equal amou... | [{"input": "1000000000\n", "output": "4444477777\n"}, {"input": "1000100000\n", "output": "4444477777\n"}, {"input": "1211766791\n", "output": "4444477777\n"}, {"input": "1101704081\n", "output": "4444477777\n"}, {"input": "1010000000\n", "output": "4444477777\n"}, {"input": "444000000\n", "output": "4444477777\n"}, {"... | code_stdio |
[
{
"content": "Let S(n) denote the sum of the digits in the decimal notation of n.\nFor example, S(123) = 1 + 2 + 3 = 6.\nWe 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.\nGiven an integer K, list the K smallest Snuke numbers... | [{"input": "792\n", "output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n29\n39\n49\n59\n69\n79\n89\n99\n199\n299\n399\n499\n599\n699\n799\n899\n999\n1099\n1199\n1299\n1399\n1499\n1599\n1699\n1799\n1899\n1999\n2999\n3999\n4999\n5999\n6999\n7999\n8999\n9999\n10999\n11999\n12999\n13999\n14999\n15999\n16999\n17999\n18999\n19999\n209... | code_stdio |
[
{
"content": "A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them.\n\nLimak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through n.\n\nLimak recently learned how to jump. He can jump ... | [{"input": "15 1\n12 9\n13 7\n1 3\n10 4\n9 2\n2 15\n11 4\n2 14\n10 8\n6 7\n12 5\n8 7\n3 10\n10 2\n", "output": "346\n"}, {"input": "15 1\n12 9\n13 7\n1 3\n10 4\n9 2\n2 15\n11 4\n2 14\n10 8\n6 7\n12 5\n8 7\n3 10\n10 2\n", "output": "346\n"}, {"input": "15 1\n12 9\n13 7\n1 3\n10 4\n9 2\n2 15\n11 4\n2 14\n10 8\n6 8\n12 5\... | code_stdio |
[
{
"content": "During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.\n\nStanding in a queue that isn't being served is so boring! So, each of the students wrote down the num... | [{"input": "10\n419946 201769\n245945 0\n842799 113073\n836998 245945\n0 794376\n692107 836998\n113073 904403\n904403 987165\n201769 692107\n794376 842799\n", "output": "419946 794376 201769 842799 692107 113073 836998 904403 245945 987165 \n"}, {"input": "10\n419946 201769\n245945 0\n842799 113073\n836998 245945\n0 79... | code_stdio |
[
{
"content": "You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}). \n\nYour task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain... | [{"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43\n58 26\n... | code_stdio |
[
{
"content": "You are given an array $a_1, a_2, \\dots , a_n$. Array is good if for each pair of indexes $i < j$ the condition $j - a_j \\ne i - a_i$ holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an opt... | [{"input": "3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n", "output": "7\n5 3 1 1\n6 5 4 3 2 1\n"}, {"input": "3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n", "output": "7\n5 3 1 1\n6 5 4 3 2 1\n"}, {"input": "3\n1\n7\n4\n0 1 3 5\n6\n3 2 1 5 6 4\n", "output": "7\n5 3 1 0\n6 5 4 3 2 1\n"}, {"input": "3\n1\n7\n4\n0 1 1 5\n6\n3 2 1 5 6 4... | code_stdio |
[
{
"content": "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 the... | [{"input": "20 6 15\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n", "output": "Both\nBoth\nVova\nVova\nVanya\nVova\nVova\nBoth\nBoth\nVova\nVova\nVanya\nVova\nVova\nBoth\nBoth\nVova\nVova\nVanya\nVova\n"}, {"input": "20 5 15\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34... | code_stdio |
[
{
"content": "The well-known Fibonacci sequence $F_0, F_1, F_2,\\ldots $ is defined as follows: $F_0 = 0, F_1 = 1$. For each $i \\geq 2$: $F_i = F_{i - 1} + F_{i - 2}$. \n\nGiven an increasing arithmetic sequence of positive integers with $n$ elements: $(a, a + d, a + 2\\cdot d,\\ldots, a + (n - 1)\\cdot d)$... | [{"input": "1 123456 961946\n", "output": "11954016000000000001 3158031000000000000\n"}, {"input": "1 123456 961946\n", "output": "11954016000000000001 3158031000000000000\n"}, {"input": "10000 154768 13\n", "output": "11015448000000000001 9428455500000000000\n"}, {"input": "0 123456 961946\n", "output": "1195401600000... | code_stdio |
[
{
"content": "In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ starting from the $l$-th character and ending with th... | [{"input": "50\n01110100101100100100011001100001110010010000000101\n50\n27 18 7\n22 35 2\n50 35 1\n41 16 1\n27 5 5\n11 6 33\n7 19 2\n9 12 33\n14 37 4\n1 22 8\n22 3 5\n50 42 1\n50 38 1\n29 20 2\n20 34 17\n20 4 29\n16 21 3\n11 43 3\n15 45 1\n12 28 3\n31 34 13\n43 1 8\n3 41 1\n18 3 13\n29 44 6\n47 44 3\n40 43 2\n6 46 5\n9... | code_stdio |
[
{
"content": "A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells.\n\nInput\n\nThe first inp... | [{"input": "200 2\nBABAABBABBABBABABBBABAAABABBABABBBAABBBBABBAABBABABAAAAABAABBBAAAAAAABBBABAAAABABBBAABABAABAABBBAABBABAAAABABAAAABABABBBABBBAAABAAABAAABABAAABABABBABABABBABBBABBBBBABABBBABAAABAAABAABBAABBABBBBBABBBAB\n", "output": "87\nABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA... | code_stdio |
[
{
"content": "A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|).\n\nYou've got two strings — s and t. Let's consider all subsequences of string s, coinciding with string t. Is it true that each character ... | [{"input": "ctkhagrifaztmnxhmqztzibnmzzkojiztvrkfeoqegvwtbxlvvjhebshqaicsovtkcdovytimjggglyxlvglgunbohnkxargymbqvzgsnvjzgxivdgnaesgxqcruaopjuqsyyorrobnelehjnxcetveehlbmeskptivsuhuqupbieumycwczxyqjtwfofehfkpqmjngygwxkaviuyouiippgvlxjgtkxmhcwtzacbllsybgiujyryngapfwjkkyapfgxtcdpc\nctkhagrifaztmnxhmqztzibnmzzkojiztvrkfeoqe... | code_stdio |
[
{
"content": "Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are?\n\nConstraints\n\n* 1 ≤ A ≤ B < 2^{60}\n* A and B are integers.\n\nInput\n\nThe input is given from Standard I... | [{"input": "271828182845904523\n1128816364578546661", "output": "881093321760942453\n"}, {"input": "271828182845904523\n1080587834201094862", "output": "881093321760942453\n"}, {"input": "271828182845904523\n1104519973481288013", "output": "881093321760942453\n"}, {"input": "271828182845904523\n1031296135146934819", "o... | code_stdio |
[
{
"content": "The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters ... | [{"input": "50\nagecd\ncghafi\nfiide\niecc\njbdcfjhgd\ndiee\nhfeg\nehc\ngfijgjh\ngacaifebg\ndicbbddc\nhjgciaei\njjcdh\ng\ngc\ncf\nhfdjhd\nc\nicidbec\nji\neeh\ncgeejggc\nacfd\njjg\najefdj\neghhebiic\nbih\ngbb\njjaa\nidc\ngafi\necg\ndbigbjiehj\ncedif\nahidfaaajg\nhfhhiccbgb\ndgegjgieif\nhgjebhfdc\nj\nahehd\nahdah\nbijbhh... | code_stdio |
[
{
"content": "Vasya has recently developed a new algorithm to optimize the reception of customer flow and he considered the following problem.\n\nLet the queue to the cashier contain n people, at that each of them is characterized by a positive integer ai — that is the time needed to work with this customer. Wh... | [{"input": "100\n1525 7246 2782 4070 10420 5459 8162 8074 5197 4808 4599 8161 2110 2216 7434 9937 2350 9406 9497 8027 2100 1600 7508 3441 4356 3928 8448 3788 7189 9186 7923 5170 6940 6986 9909 8418 2963 9146 8411 6136 6753 3006 2726 4290 7310 8044 3558 6136 4781 1765 4242 5433 9937 8768 5103 4470 1000 5480 4834 3372 88... | code_stdio |
[
{
"content": "You've got a positive integer sequence a_1, a_2, ..., a_{n}. All numbers in the sequence are distinct. Let's fix the set of variables b_1, b_2, ..., b_{m}. Initially each variable b_{i} (1 ≤ i ≤ m) contains the value of zero. Consider the following sequence, consisting of n operations.\n\nThe firs... | [{"input": "23\n26988535 53977070 107954140 161931210 323862420 215908280 431816560 647724840 269885350 242896815 755678980 485793630 863633120 404828025 539770700 134942675 593747770 377839490 917610190 809656050 620736305 971587260 458805095\n", "output": "7\n"}, {"input": "23\n26988535 53977070 107954140 161931210 3... | code_stdio |
[
{
"content": "Find the symmetric difference of two sets $A = \\\\{a_0, a_1, ..., a_{n-1}\\\\}$ and $B = \\\\{b_0, b_1, ..., b_{m-1}\\\\}$.\n\nConstraints\n\n* $1 \\leq n, m \\leq 200,000$\n* $0 \\leq a_0 < a_1 < ... < a_{n-1} \\leq 10^9$\n* $0 \\leq b_0 < b_1 < ... < b_{m-1} \\leq 10^9$\n\nInput\n\nThe input is... | [{"input": "7\n1 2 3 4 5 7 10\n2\n0 11 6 11", "output": "0\n1\n2\n3\n4\n5\n7\n10\n11\n"}, {"input": "7\n1 2 3 4 5 7 12\n1\n0 14 3 11", "output": "0\n1\n2\n3\n4\n5\n7\n12\n"}, {"input": "7\n1 2 3 4 5 7 10\n1\n0 11 6 11", "output": "0\n1\n2\n3\n4\n5\n7\n10\n"}, {"input": "7\n1 2 3 4 5 6 10\n3\n0 4 11 8", "output": "0\n1\... | code_stdio |
[
{
"content": "The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls.\n\nThere, however, is an inconvenience. The shapes of the fuel containers #1 and #2 are always cubic and regular tetrahedral respectively. Both of the ... | [{"input": "100\n160\n50\n20\n150323\n0", "output": "99\n160\n47\n20\n150303\n"}, {"input": "100\n31\n37\n104\n151200\n0", "output": "99\n31\n37\n99\n151200\n"}, {"input": "100\n84\n50\n20\n151200\n0", "output": "99\n84\n47\n20\n151200\n"}, {"input": "100\n84\n50\n20\n150323\n0", "output": "99\n84\n47\n20\n150303\n"}, ... | code_stdio |
[
{
"content": "The ACM ICPC judges are very careful about not leaking their problems, and all communications are encrypted. However, one does sometimes make mistakes, like using too weak an encryption scheme. Here is an example of that.\n\nThe encryption chosen was very simple: encrypt each chunk of the input by... | [{"input": "8\n1 1 1 1 1 1 2 1 8\n3 2 3 2 3 2 4 2 10\n6 4 7 13 7 b a 2 2e\ne1 13 ce 28 ca 6 ab 46 a5d\nb08 49e2 6128 f27 8cf2 bc50 7380 7fe1 722b\n4eba eb4 a352 fd14 6ac1 fed1 dd06 bb83 392bc\nef593c08 847e522f c9b20c47 26f3a4e1 e2720a01 6fe66007\n7a4e96ad 6ee5cef6 3853cd88\n8bf20206 757d6d66 9c3a9525 fbcd7983 82b9571c... | code_stdio |
[
{
"content": "Snuke lives on an infinite two-dimensional plane. He is going on an N-day trip. At the beginning of Day 1, he is at home. His plan is described in a string S of length N. On Day i(1 ≦ i ≦ N), he will travel a positive distance in the following direction:\n\n* North if the i-th letter of S is `N`\n... | [{"input": "NSNSNNSN", "output": "Yes\n"}, {"input": "NSSNSNNN", "output": "Yes\n"}, {"input": "NSNNSNSN", "output": "Yes"}, {"input": "SEWN", "output": "Yes\n"}, {"input": "ESWN", "output": "Yes\n"}, {"input": "WNES", "output": "Yes\n"}, {"input": "NEWS", "output": "Yes\n"}, {"input": "ENWS", "output": "Yes\n"}, {"inp... | code_stdio |
[
{
"content": "The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.\n\nThe Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. ... | [{"input": "128\n1 2 4 6 8 17 20 20 23 33 43 49 49 49 52 73 74 75 82 84 85 87 90 91 102 103 104 105 111 111 401 142 142 152 155 160 175 176 178 181 183 184 187 188 191 193 326 202 202 214 224 225 236 239 240 243 246 247 249 249 257 257 261 264 265 271 277 281 284 284 286 289 290 296 297 303 305 307 307 317 318 320 322 ... | 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\nPetya has a number consisting of n digits without leading zeroes. He represe... | [{"input": "485 9554485\n7759121368632736852539182753173468028218114958118158732302477551670775608015153610483175626465946144780731573954182900412248382710280376491925985206156109890139333293746203940442347501294009600230166311978044218247083102712257326301109220002496805123344816427514286225153139924306380089284878322... | code_stdio |
[
{
"content": "Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm.\n\n\n.#.#.#.#.\n.#.#.#.#.#\n.#.#.#.#.\n.#.#.#.#.#\n.#.#.#.#.\n.#.#.#.#.#\n\n\nNote that the top left corner should be drawn by '#'... | [{"input": "11 21\n10 0\n5 0\n2 4\n2 0\n0 0", "output": "#.#.#.#.#.#.#.#.#.#.#\n.#.#.#.#.#.#.#.#.#.#.\n#.#.#.#.#.#.#.#.#.#.#\n.#.#.#.#.#.#.#.#.#.#.\n#.#.#.#.#.#.#.#.#.#.#\n.#.#.#.#.#.#.#.#.#.#.\n#.#.#.#.#.#.#.#.#.#.#\n.#.#.#.#.#.#.#.#.#.#.\n#.#.#.#.#.#.#.#.#.#.#\n.#.#.#.#.#.#.#.#.#.#.\n#.#.#.#.#.#.#.#.#.#.#\n\n\n\n\n\n... | code_stdio |
[
{
"content": "So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 ≥ p_2 ≥ ... ≥ p_n.\... | [{"input": "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 0\n1\n1000000\n20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 10 3 2 1\n32\n64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 17 16 16 11\n", "output": "1 2 3\n0 0 0\n0 0 0\n1 2 7\n2 6 6\n"}, {"input": "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1... | code_stdio |
[
{
"content": "It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.\n\nThe bus stop queue has n groups of people. The i-th group... | [{"input": "100 60\n34 21 39 17 48 46 23 56 46 52 50 39 55 48 54 38 32 38 24 26 44 12 28 9 25 26 10 52 42 60 41 3 16 60 44 29 27 55 19 19 19 57 45 59 29 35 5 14 50 47 57 48 16 7 12 36 58 31 37 58 30 50 19 11 10 41 59 57 49 41 33 9 12 11 53 50 60 51 21 9 44 23 1 16 4 15 17 57 15 17 46 50 18 52 43 24 47 50 19 18\n", "out... | code_stdio |
[
{
"content": "Read problems statements in Mandarin Chinese and Russian. \n\nRecently Chef bought a bunch of robot-waiters. And now he needs to know how much to pay for the electricity that robots use for their work. All waiters serve food from the kitchen (which is in the point (0, 0)) and carry it to some tab... | [{"input": "2\n-1 -1\n7 -1", "output": "2\n14\n"}, {"input": "2\n-1 -1\n2 11", "output": "2\n21\n"}, {"input": "2\n-1 -2\n4 14", "output": "3\n28\n"}, {"input": "2\n1 -1\n10 14", "output": "2\n28\n"}, {"input": "2\n2 -1\n10 14", "output": "5\n28\n"}, {"input": "2\n-1 0\n7 -1", "output": "3\n14\n"}, {"input": "2\n-1 -1\... | code_stdio |
[
{
"content": "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.\n\nYou should assign labels to all vertices in such a way that:\n\n Labels form a valid permutation of length n — an integer seque... | [{"input": "101 10\n73 41\n29 76\n11 8\n94 46\n77 67\n76 18\n72 50\n45 40\n89 75\n27 22\n", "output": "1 2 3 4 5 6 7 9 10 11 8 12 13 14 15 16 17 20 21 22 23 25 26 27 28 29 24 30 18 31 32 33 34 35 36 37 38 39 40 42 44 45 46 47 41 49 50 51 52 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 72 73 74 75 76 53 43 77 79 1... | code_stdio |
[
{
"content": "Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains a_{i} liters of paint of color i.\n\nVika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1. Squares are numbered 1, 2, 3 and so on. ... | [{"input": "10\n896619242 805194919 1680710614 848347723 816995848 856813612 805194919 954097478 816255448 566613186\n", "output": "5666131869\n"}, {"input": "10\n896619242 805194919 1680710614 848347723 816995848 856813612 805194919 545821022 816255448 805194919\n", "output": "5458210229\n"}, {"input": "10\n896619242 ... | code_stdio |
[
{
"content": "Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and ... | [{"input": "63 67 18046757 61758841 85367218 68\n22 30\n25 40\n56 58\n29 11\n34 63\n28 66\n51 5\n39 64\n1 23\n24 61\n19 47\n10 31\n55 28\n52 26\n38 7\n28 31\n13 27\n37 42\n10 52\n19 33\n7 36\n13 1\n46 40\n21 41\n1 1\n6 35\n10 4\n46 9\n21 57\n1 49\n34 14\n14 35\n43 4\n1 41\n25 22\n18 25\n27 23\n43 17\n34 23\n29 4\n50 40... | code_stdio |
[
{
"content": "Shohag has an integer sequence $a_1, a_2, \\ldots, a_n$. He can perform the following operation any number of times (possibly, zero):\n\nSelect any positive integer $k$ (it can be different in different operations).\n\nChoose any position in the sequence (possibly the beginning or end of the seque... | [{"input": "1\n39\n481199252 336470888 728039650 446497694 740396295 773386884 579721198 396628655 503722503 971207868 202647942 2087506 268792718 46761498 443917727 16843338 125908043 1772709198 717268783 787375312 150414369 693319712 519096230 29277141 856168102 762263554 674936674 407246545 274667941 279198849 52726... | code_stdio |
[
{
"content": "You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y) (0 ≤ x ≤ n, 0 ≤ y ≤ m).\n\nYour task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it co... | [{"input": "1000000000 1000001000 286536427 579261823 230782719 1150170645\n", "output": "209608854 195871608 363464000 962652038\n"}, {"input": "1000000000 1000000000 500000000 500000000 500000000 500000001\n", "output": "250000000 249999999 750000000 750000000\n"}, {"input": "1000000000 1000000000 286536427 579261823... | code_stdio |
[
{
"content": "You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.\n\n* `0 p x`: a_p \\gets a_p + x\n* `1 l r`: Print \\sum_{i = l}^{r - 1}{a_i}.\n\nConstraints\n\n* 1 \\leq N, Q \\leq 500,000\n* 0 \\leq a_i, x \\leq 10^9\n* 0 \\leq p < N\n* 0 \\leq l_i < r_i \\le... | [{"input": "5 5\n1 2 9 4 5\n1 1 5\n1 2 4\n0 3 15\n1 0 5\n1 0 3", "output": "20\n13\n36\n12\n"}, {"input": "5 5\n1 2 8 4 5\n1 0 5\n1 2 4\n0 3 10\n1 0 5\n1 0 3", "output": "20\n12\n30\n11\n"}, {"input": "5 5\n1 2 8 4 5\n1 0 5\n1 2 4\n0 3 10\n1 0 4\n1 0 3", "output": "20\n12\n25\n11\n"}, {"input": "5 5\n1 0 4 0 5\n1 0 5\n... | code_stdio |
[
{
"content": "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 p... | [{"input": "100 20 100 15061\nwwwwhhwhhwhhwhhhhhwwwhhhwwwhwwhwhhwwhhwwwhwwhwwwhwhwhwwhhhwwwhhwhwwhhwhwhwwwhwwwwhwhwwwwhwhhhwhwhwwh\n", "output": "100\n"}, {"input": "100 20 110 15061\nwwwwhhwhhwhhwhhhhhwwwhhhwwwhwwhwhhwwhhwwwhwwhwwwhwhwhwwhhhwwwhhwhwwhhwhwhwwwhwwwwhwhwwwwhwhhhwhwhwwh\n", "output": "100\n"}, {"input": "... | code_stdio |
[
{
"content": "One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!\n\nWhy not make her own Codeforces, with blackjack and other really cool stuff? Many people w... | [{"input": "010\n", "output": "0\n"}, {"input": "011\n", "output": "4\n"}, {"input": "001\n", "output": "0\n"}, {"input": "20\n", "output": "15\n"}, {"input": "15\n", "output": "4\n"}, {"input": "13\n", "output": "4\n"}, {"input": "11\n", "output": "4\n"}, {"input": "17\n", "output": "4\n"}, {"input": "18\n", "output":... | code_stdio |
[
{
"content": "Problem Statement\n\nNathan O. Davis is a student at the department of integrated systems.\n\nToday's agenda in the class is audio signal processing. Nathan was given a lot of homework out. One of the homework was to write a program to process an audio signal. He copied the given audio signal to h... | [{"input": "5\n1 x 0 4 x\n2\nx x\n2\n1 2\n2\n3 0\n2\n1000000000 x\n4\nx 4 1 x\n0", "output": "ambiguous\nnone\nambiguous\nnone\nambiguous\nambiguous\n"}, {"input": "5\n1 x 0 4 x\n2\nx x\n2\n1 2\n2\n3 0\n2\n0000000000 x\n4\nx 4 1 x\n0", "output": "ambiguous\nnone\nambiguous\nnone\nambiguous\nambiguous\n"}, {"input": "5\... | code_stdio |
[
{
"content": "Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.\nLet a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \\leq k \\leq N):\n - There exists a non-negative integer p such that X= a_k \\times (p+0.5).\nFi... | [{"input": "5 1000000000\n6 6 2 6 2\n", "output": "166666667\n"}, {"input": "5 1000000000\n6 6 2 6 2", "output": "166666667"}, {"input": "3 100\n14 22 40\n", "output": "0\n"}, {"input": "3 000\n14 22 40", "output": "0\n"}, {"input": "3 000\n14 16 40", "output": "0\n"}, {"input": "3 010\n14 16 40", "output": "0\n"}, {"i... | code_stdio |
[
{
"content": "Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. \n\nIahub asks Iahubina: can you build a rooted tr... | [{"input": "24\n3 3 3 4 5 6 7 14 9 10 11 12 13 14 15 16 17 18 19 20 21 18 23 24\n", "output": "NO\n"}, {"input": "24\n3 3 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 18 23 24\n", "output": "NO\n"}, {"input": "24\n1 2 3 4 5 6 7 8 9 10 11 12 23 14 15 16 17 18 19 20 21 22 23 24\n", "output": "NO\n"}, {"input": "24\n... | code_stdio |
[
{
"content": "Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29.\n\n\n\nInput\n\nThe input is a sequence of datasets. The end of the input is indicated by a line containing... | [{"input": "6 2\n12 8\n0 0", "output": "Wednesday\nWednesday\n"}, {"input": "4 1\n2 18\n0 0", "output": "Thursday\nWednesday\n"}, {"input": "6 2\n7 17\n0 0", "output": "Wednesday\nSaturday\n"}, {"input": "1 1\n5 19\n0 0", "output": "Thursday\nWednesday\n"}, {"input": "3 3\n2 14\n0 0", "output": "Wednesday\nSaturday\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\nLet next(x) be the minimum lucky number which is larger than or equals x. Pe... | [{"input": "614586850 1000000000\n", "output": "1110059271353421796\n"}, {"input": "190535551 1000000000\n", "output": "1340487604111893304\n"}, {"input": "614586850 1000001000\n", "output": "1110063715797865796\n"}, {"input": "190535551 1010000000\n", "output": "1384932048551893304\n"}, {"input": "402822109 1000001000... | code_stdio |
[
{
"content": "A: Alphabet block\n\nWakana Nakawa loves palindromes. Because my name is also a palindrome.\n\nWakana got a set with some alphabet blocks. An alphabet block is a block in which one lowercase alphabet is written for each block, and you can create your favorite character string by changing the order... | [{"input": "gcpc", "output": "1\n"}, {"input": "bgnc", "output": "2\n"}, {"input": "gcoc", "output": "1\n"}, {"input": "gcnc", "output": "1\n"}, {"input": "cgnc", "output": "1\n"}, {"input": "bcng", "output": "2\n"}, {"input": "bcnh", "output": "2\n"}, {"input": "hncb", "output": "2\n"}, {"input": "bnch", "output": "2\... | code_stdio |
[
{
"content": "Word $s$ of length $n$ is called $k$-complete if $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \\le i \\le n$; $s$ has a period of $k$, i.e. $s_i=s_{k+i}$ for all $1 \\le i \\le n-k$. \n\nFor example, \"abaaba\" is a $3$-complete word, while \"abccba\" is not.\n\nBob is given a word $s$ ... | [{"input": "4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotomonstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n", "output": "2\n0\n23\n16\n"}, {"input": "4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotononstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n", "output": "2\n0\n23\n16\n"}, {"input": "4\n6 2\nabaaba\n6 ... | code_stdio |
[
{
"content": "Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. \n\nThere are N students living in the dormitory of Berland State University. Each of them sometimes wants to use the kitchen, so the head of the dormitory came up with a timetable for kitchen's usage in order to avoid t... | [{"input": "2\n3\n1 10 16\n1 27 3\n3\n19 20 30\n15 10 20", "output": "2\n1\n"}, {"input": "2\n3\n1 10 15\n1 10 3\n3\n19 20 30\n15 5 20", "output": "2\n1\n"}, {"input": "2\n3\n1 10 29\n1 10 3\n2\n17 39 30\n15 5 20", "output": "2\n2\n"}, {"input": "2\n3\n1 10 29\n2 10 3\n2\n25 39 30\n15 5 20", "output": "1\n2\n"}, {"inpu... | code_stdio |
[
{
"content": "There are N children, numbered 1, 2, ..., N.\n\nSnuke has decided to distribute x sweets among them. He needs to give out all the x sweets, but some of the children may get zero sweets.\n\nFor each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets. Snuke is trying to m... | [{"input": "4 1111\n-1 2 110 1000", "output": "4\n"}, {"input": "4 1111\n1 5 100 1000", "output": "3\n"}, {"input": "4 1101\n1 5 100 1000", "output": "3\n"}, {"input": "4 1101\n0 5 100 1000", "output": "3\n"}, {"input": "4 1101\n0 5 110 1000", "output": "3\n"}, {"input": "4 1101\n1 5 110 1000", "output": "3\n"}, {"inpu... | code_stdio |
[
{
"content": "Each day in Berland consists of $n$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $a_1, a_2, \\dots, a_n$ (each $a_i$ is either $0$ or $1$), where $a_i=0$ if Polycarp works during the $i$-th hour of the day and $a_i=1$ if Polycarp rests d... | [{"input": "23\n1 1 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1\n", "output": "10\n"}, {"input": "23\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n", "output": "2\n"}, {"input": "23\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1\n", "output": "2\n"}, {"input": "23\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1\n", "out... | code_stdio |
[
{
"content": "You are given a permutation $a$ of size $n$ and you should perform $n$ operations on it. In the $i$-th operation, you can choose a non-empty suffix of $a$ and increase all of its elements by $i$. How can we perform the operations to minimize the number of inversions in the final array?\n\nNote tha... | [{"input": "1\n20\n19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 20 1\n", "output": "19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 \n"}, {"input": "1\n20\n20 1 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2\n", "output": "1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 \n"}, {"input": "4\n4\n1 2 3 4\n5\n1 3 2 4 ... | code_stdio |
[
{
"content": "A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1.\n\nWhen you enter the integer n, write a... | [{"input": "19\n10887", "output": "17 23\n10883 10889\n"}, {"input": "19\n17073", "output": "17 23\n17053 17077\n"}, {"input": "19\n30085", "output": "17 23\n30071 30089\n"}, {"input": "19\n21592", "output": "17 23\n21589 21599\n"}, {"input": "19\n16181", "output": "17 23\n16141 16183\n"}, {"input": "19\n38456", "outpu... | code_stdio |
[
{
"content": "We have a 2 \\times N grid. We will denote the square at the i-th row and j-th column (1 \\leq i \\leq 2, 1 \\leq j \\leq N) as (i, j).\nYou are initially in the top-left square, (1, 1).\nYou will travel to the bottom-right square, (2, N), by repeatedly moving right or down.\nThe square (i, j) con... | [{"input": "7\n-2 -1 0 0 1 24 0\n166 0 -1 -2 -11 -1 2", "output": "151\n"}, {"input": "7\n-1 4 -1 4 2 16 0\n136 4 -4 6 -1 -1 -1", "output": "138\n"}, {"input": "7\n-1 4 -1 4 1 24 1\n136 2 -4 6 -1 -1 -1", "output": "136\n"}, {"input": "7\n-2 -1 0 -1 1 23 1\n73 -1 0 -1 -12 -2 2", "output": "57\n"}, {"input": "7\n-2 -1 1 ... | code_stdio |
[
{
"content": "Joisino wants to evaluate the formula \"A op B\".\nHere, A and B are integers, and the binary operator op is either + or -.\nYour task is to evaluate the formula instead of her.\n\n-----Constraints-----\n - 1≦A,B≦10^9\n - op is either + or -.\n\n-----Input-----\nThe input is given from Standard In... | [{"input": "-1 - 182", "output": "-183\n"}, {"input": "6 - 131", "output": "-125\n"}, {"input": "5 - 118", "output": "-113\n"}, {"input": "-1 + 112", "output": "111\n"}, {"input": "-1 - 15", "output": "-16\n"}, {"input": "-2 - 12", "output": "-14\n"}, {"input": "-2 - 48", "output": "-50\n"}, {"input": "-2 - 74", "outpu... | code_stdio |
[
{
"content": "Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. \n\nFind all integer solutions x (0 < x < 10^9) of the equation:x = b·s(x)^{a} + c, \n\nwhere a, b, c are some predetermined constant values and function s(x) determ... | [{"input": "1 3034 -9234\n", "output": "23\n12004 21106 24140 30208 33242 39310 42344 48412 51446 54480 57514 60548 63582 66616 69650 72684 75718 78752 81786 87854 90888 96956 99990 "}, {"input": "1 3034 -9234\n", "output": "23\n12004 21106 24140 30208 33242 39310 42344 48412 51446 54480 57514 60548 63582 66616 69650 7... | code_stdio |
[
{
"content": "In this problem, you should process T testcases.\n\nFor each testcase, you are given four integers N, M, A, B.\n\nCalculate \\sum_{i = 0}^{N - 1} floor((A \\times i + B) / M).\n\nConstraints\n\n* 1 \\leq T \\leq 100,000\n* 1 \\leq N, M \\leq 10^9\n* 0 \\leq A, B < M\n\nInput\n\nInput is given from... | [{"input": "5\n0 26 3 24\n6 5 4 1\n1 2 0 0\n31415 92653 41909 43244\n1000000000 1000000000 1831327114 999999999", "output": "0\n11\n0\n223190696\n915663556584336442\n"}, {"input": "5\n4 8 6 0\n11 5 7 3\n2 1 0 0\n31415 92653 111964 60313\n1000000000 1000000000 999999999 1505207673", "output": "3\n79\n0\n596283347\n50000... | code_stdio |
[
{
"content": "Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message). Thus, whole sentences and words get split... | [{"input": "123\nOjg CVJm qfE RnHislFds nNKKt TCPLWukqNGAsVBplYbTfq? VeYKjfFGTzXWA ydpVZLIImNub yApKnAHv iXQmqv GjQvxrnAgtfTApiQyCKtg. GdmapGwvI udRqxTbnzgnOUNZx slAuEuLGCJycZJvtCczQ vommS xuuT eIK! DOJeFEaubbz HYLGlIIlNKfyaJQKVN eFNnUvKKCQLXvGhwX gjmRscMkedELUlHq? aTbyMGB EofzX wcAEjyRQpxghWvXhdJb cwIz FEUsEFicYZ.\n",... | code_stdio |
[
{
"content": "Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robo... | [{"input": "100\n27 20 18 78 93 38 56 2 48 75 36 88 96 57 69 10 25 74 68 86 65 85 66 14 22 12 43 80 99 34 42 63 61 71 77 15 37 54 21 59 23 94 28 30 50 84 62 76 47 16 26 64 82 92 72 53 17 11 41 91 35 83 79 95 67 13 1 7 3 4 73 90 8 19 33 58 98 32 39 45 87 52 60 46 6 44 49 70 51 9 5 29 31 24 40 97 81 0 89 55\n", "output":... | code_stdio |
[
{
"content": "Little Petya likes permutations a lot. Recently his mom has presented him permutation q1, q2, ..., qn of length n.\n\nA permutation a of length n is a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ n), all integers there are distinct. \n\nThere is only one thing Petya likes more than permutations:... | [{"input": "55 28\n35 33 46 8 11 13 14 26 42 38 1 7 34 5 2 21 17 45 54 43 4 18 27 50 25 10 29 48 6 16 22 28 55 53 49 41 39 23 40 47 51 37 36 19 9 32 52 12 24 3 20 15 30 44 31\n5 52 24 16 7 27 48 21 18 8 14 28 29 12 47 53 17 31 54 41 30 55 10 35 25 4 38 46 23 34 33 3 15 6 11 20 9 26 42 37 43 45 51 19 22 50 39 32 1 49 36... | code_stdio |
[
{
"content": "You have a plate and you want to add some gilding to it. The plate is a rectangle that we split into $w\\times h$ cells. There should be $k$ gilded rings, the first one should go along the edge of the plate, the second one — $2$ cells away from the edge and so on. Each ring has a width of $1$ cell... | [{"input": "100 100 25\n", "output": "5100\n"}, {"input": "100 100 20\n", "output": "4880\n"}, {"input": "100 100 20\n", "output": "4880\n"}, {"input": "100 100 25\n", "output": "5100\n"}, {"input": "100 100 16\n", "output": "4416\n"}, {"input": "110 100 25\n", "output": "5600\n"}, {"input": "110 100 16\n", "output": "... | code_stdio |
[
{
"content": "Let's denote correct match equation (we will denote it as CME) an equation $a + b = c$ there all integers $a$, $b$ and $c$ are greater than zero.\n\nFor example, equations $2 + 2 = 4$ (||+||=||||) and $1 + 2 = 3$ (|+||=|||) are CME but equations $1 + 2 = 4$ (|+||=||||), $2 + 2 = 3$ (||+||=|||), an... | [{"input": "100\n928\n970\n950\n921\n1007\n974\n353\n999\n964\n920\n926\n942\n934\n918\n930\n901\n977\n961\n978\n962\n951\n909\n994\n953\n946\n993\n982\n922\n1789\n932\n904\n910\n991\n937\n963\n988\n278\n903\n956\n976\n967\n958\n902\n986\n960\n965\n940\n914\n955\n987\n952\n971\n939\n966\n938\n911\n916\n954\n929\n935\n9... | code_stdio |
[
{
"content": "This is the hard version of this problem. The only difference is the constraint on $k$ — the number of gifts in the offer. In this version: $2 \\le k \\le n$.\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 g... | [{"input": "8\n5 6 2\n2 4 3 5 12\n5 5 2\n2 4 3 5 10\n3 1 1\n4 2 6\n5 2 5\n10 1 3 9 2\n2 10000 2\n10000 10000\n2 9999 2\n10000 10000\n4 6 4\n3 2 2 2\n5 5 3\n1 2 2 1 2\n", "output": "3\n2\n0\n1\n2\n0\n4\n5\n"}, {"input": "8\n5 6 2\n2 4 3 5 12\n5 5 2\n2 4 1 5 10\n3 1 1\n4 2 6\n5 2 5\n10 1 3 9 2\n2 10000 2\n10000 10000\n2 ... | code_stdio |
[
{
"content": "Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.\n\nConstraints\n\n* 1 ≤ length of T ≤ 1000000\n* 1 ≤ length of P_i ≤ 1000\n* 1 ≤ Q ≤ 10000\n* The input consists of alphabetical characters and digits\n\nInput\n\nIn the first line, a t... | [{"input": "aabaaa\n4\nab\nba\nbb\nxyz", "output": "1\n1\n0\n0\n"}, {"input": "aabaaa\n4\nab\nba\nba\nxyz", "output": "1\n1\n1\n0\n"}, {"input": "aabaaa\n4\nba\nbb\nac\nzyx", "output": "1\n0\n0\n0\n"}, {"input": "aabaaa\n4\nca\nab\nba\nzyx", "output": "0\n1\n1\n0\n"}, {"input": "aacaaa\n4\nba\nb`\nac\nzyx", "output": "... | code_stdio |
[
{
"content": "There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:\n - Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.\nWhat is the largest possible sum of the integers written on... | [{"input": "-1 0 -1\n-1", "output": "-2.0\n"}, {"input": "-1 0 0\n-1", "output": "-1.0\n"}, {"input": "13 5 21\n2", "output": "102\n"}, {"input": "12 10 25\n0", "output": "47\n"}, {"input": "5 8 2\n10", "output": "8199\n"}, {"input": "42 4 21\n2", "output": "193\n"}, {"input": "3 8 2\n10", "output": "8197\n"}, {"input"... | code_stdio |
[
{
"content": "Recently, chef Ciel often hears about lucky numbers.\n\nEverybody knows that lucky numbers are positive integers\nwhose decimal representation contains only the lucky digits 4 and 7.\nFor example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.\n\nCiel decides to make Ciel numbers.\nAs you kn... | [{"input": "6\nklin 18\nCiel's Drink 174\nThe curry 2nd edition 677505\necis omelet 85855\nunagi 1\n She firsu amd last letters can eb a space 253", "output": "0\n"}, {"input": "6\nklin 18\nCiel's Drink 133\nThe curry 2nd edition 888888\necir omelet 85855\nunagi 1\n The firsu amd last letters can be a spac... | code_stdio |
[
{
"content": "Little Petya likes to play very much. And most of all he likes to play the following game:\n\nHe is given a sequence of N integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is to make the sequence non-decreasing with th... | [{"input": "7\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000\n", "output": "6000000000\n"}, {"input": "7\n1000000000 -447358682 1000000000 -1000000000 1000000000 -1000000000 1000000000\n", "output": "5447358682\n"}, {"input": "7\n1000000000 -447358682 1000000000 -1000000000 1100000000 ... | code_stdio |
[
{
"content": "Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: \n\n * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. \n * Bob won some programming competitio... | [{"input": "50\nwin 596\nwin 1799\nwin 1462\nsell 460\nwin 731\nwin 723\nwin 731\nwin 329\nwin 838\nsell 728\nwin 728\nwin 460\nwin 723\nwin 1462\nwin 1462\nwin 460\nwin 329\nwin 1462\nwin 460\nwin 460\nwin 723\nwin 731\nwin 723\nwin 596\nwin 731\nwin 596\nwin 329\nwin 728\nwin 715\nwin 329\nwin 1799\nwin 715\nwin 723\... | code_stdio |
[
{
"content": "You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either \"correct\" or \"incorrect\", and your grade will be the sum of the points allocated to questions that ar... | [{"input": "3\n-101\n-1\n-1", "output": "-103\n"}, {"input": "3\n-109\n-1\n-1", "output": "-111\n"}, {"input": "3\n-156\n-1\n-1", "output": "-158\n"}, {"input": "3\n-166\n-1\n-1", "output": "-168\n"}, {"input": "3\n-166\n-2\n-1", "output": "-169\n"}, {"input": "3\n-166\n-4\n-1", "output": "-171\n"}, {"input": "3\n-390\... | code_stdio |
[
{
"content": "You are given a set of all integers from $l$ to $r$ inclusive, $l < r$, $(r - l + 1) \\le 3 \\cdot 10^5$ and $(r - l)$ is always odd.\n\nYou want to split these numbers into exactly $\\frac{r - l + 1}{2}$ pairs in such a way that for each pair $(i, j)$ the greatest common divisor of $i$ and $j$ is... | [{"input": "804212830686677670 804212830686679109\n", "output": "YES\n804212830686677670 804212830686677671\n804212830686677672 804212830686677673\n804212830686677674 804212830686677675\n804212830686677676 804212830686677677\n804212830686677678 804212830686677679\n804212830686677680 804212830686677681\n8042128306866776... | code_stdio |
[
{
"content": "The Little Elephant from the Zoo of Lviv likes listening to music.\nThere are N songs, numbered from 1 to N, in his MP3-player. The song i is described by a pair of integers B_{i} and L_{i} - the band (represented as integer) that performed that song and the length of that song in seconds. The Lit... | [{"input": "2\n3\n1 1\n2 2\n-1 2\n3\n1 3\n1 3\n4 2", "output": "11\n14\n"}, {"input": "2\n3\n1 1\n2 3\n-1 2\n3\n0 3\n1 3\n4 2", "output": "14\n17\n"}, {"input": "2\n3\n1 3\n2 3\n4 2\n3\n2 1\n1 2\n2 11", "output": "17\n27\n"}, {"input": "2\n3\n1 1\n2 2\n-1 2\n3\n0 3\n1 3\n4 4", "output": "11\n21\n"}, {"input": "2\n3\n1 ... | code_stdio |
[
{
"content": "Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function does the following: \n \n \n \n ... | [{"input": "20\n5 9 11 12 13 13 13 13 13 13 13 13 13 6 12 11 11 8 6 4\n", "output": "19\n5 13\n4 13\n3 13\n3 13\n2 13\n2 13\n2 13\n15 15\n15 17\n15 17\n15 17\n15 18\n15 18\n2 19\n1 19\n1 20\n1 20\n1 20\n1 20\n"}, {"input": "20\n5 9 11 12 13 13 13 13 13 13 13 13 13 6 12 11 11 8 6 2\n", "output": "19\n5 13\n4 13\n3 13\n3... | code_stdio |
[
{
"content": "Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a_1, a_2, ..., a_{n}. His teapot stores w milliliters of tea (w ≤ a_1 + a_2 + ... + a_{n}). Polycarp wants to pour tea in cups in such a way that: Every cup will ... | [{"input": "100 10000\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 1... | code_stdio |
[
{
"content": "Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes. \n\nLet's call a sequence of non-negative integers v1, v2, ..., vn a plan, i... | [{"input": "123 432 342 1000000007\n72 20 34 115 65 29 28 41 18 16 122 104 88 37 119 11 108 91 13 110 47 73 80 35 62 12 9 116 55 66 54 113 50 57 8 25 98 105 0 120 93 78 61 17 84 48 42 106 63 103 7 59 90 89 28 49 53 71 51 83 75 67 64 95 107 3 32 85 69 99 33 79 109 56 10 23 87 19 121 94 44 82 102 27 112 52 21 1 5 74 117 ... | code_stdio |
[
{
"content": "You are given an integer $n$. You have to calculate the number of binary (consisting of characters 0 and/or 1) strings $s$ meeting the following constraints.\n\nFor every pair of integers $(i, j)$ such that $1 \\le i \\le j \\le n$, an integer $a_{i,j}$ is given. It imposes the following constrain... | [{"input": "20\n1 1 2 0 0 2 0 2 2 2 0 0 2 2 2 0 2 0 0 0\n0 0 0 0 0 0 0 0 0 2 0 2 0 0 0 2 0 0 0\n0 1 2 0 2 2 2 2 0 0 2 0 2 2 0 2 2 2\n1 2 2 2 2 2 2 2 0 2 2 2 0 2 2 2 2\n0 2 0 0 2 2 2 0 2 2 0 0 2 0 0 0\n1 1 1 0 2 0 0 0 0 0 2 0 2 0 2\n1 0 1 2 2 2 0 0 2 0 0 0 2 0\n0 1 2 0 0 0 0 0 0 0 0 2 0\n0 0 0 0 0 0 0 0 0 0 2 2\n0 2 0 2... | code_stdio |
[
{
"content": "Some country is populated by wizards. They want to organize a demonstration.\n\nThere are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know... | [{"input": "10000 10000 10000\n", "output": "990000\n"}, {"input": "16485 10573 4769\n", "output": "775597\n"}, {"input": "1829 10325 17617\n", "output": "311890\n"}, {"input": "12248 10573 4769\n", "output": "573535\n"}, {"input": "13372 2590 2818\n", "output": "374233\n"}, {"input": "6571 10325 8965\n", "output": "57... | code_stdio |
[
{
"content": "Given are two strings s and t consisting of lowercase English letters. Determine if there exists an integer i satisfying the following condition, and find the minimum such i if it exists.\n - Let s' be the concatenation of 10^{100} copies of s. t is a subsequence of the string {s'}_1{s'}_2\\ldots{... | [{"input": "contest\nprogramming\n", "output": "-1\n"}, {"input": "contest\nprogrammhng", "output": "-1\n"}, {"input": "eontcst\nprogrammhng", "output": "-1\n"}, {"input": "eonscst\nprogrammhng", "output": "-1\n"}, {"input": "eonscst\nprogrammhog", "output": "-1\n"}, {"input": "eonscst\nprogrammhpg", "output": "-1\n"},... | code_stdio |
[
{
"content": "After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wr... | [{"input": "100\n45 55\n3 5 3 4 1 1 1 1 5 2 1 3 1 5 3 5 1 1 3 1 1 3 5 5 1 1 1 5 5 1 3 1 1 1 3 3 1 1 1 4 3 1 5 1 3 1 4 5 4 3 3 1 1 5 5 1 3 5 1 1 5 1 1 3 5 5 1 1 3 3 4 1 1 4 5 3 1 3 1 5 1 5 4 5 1 1 1 1 4 5 4 5 3 1 1 5 1 5 1 4\n", "output": "1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1 2 2 1 1 1 2 2 2 1 1 2 1 2 2 2 1 1 2 2 2 1 1... | code_stdio |
[
{
"content": "Claire is a man-eater. She's a real man-eater. She's going around with dozens of guys. She's dating all the time. And one day she found some conflicts in her date schedule. D'oh!\n\nSo she needs to pick some dates and give the others up. The dates are set by hours like 13:00 to 15:00. She may have... | [{"input": "2\n2 100\n10 12\n14 16\n2 200\n12 13\n18 20\n4\n1 100\n6 22\n1 1000\n12 22\n1 10000\n6 22\n1 100000\n6 22\n16\n1 100000000\n6 7\n1 100000000\n7 8\n1 100000000\n8 15\n1 110000000\n9 10\n1 100000000\n10 11\n1 100000000\n11 12\n1 100000000\n12 13\n1 100000000\n13 17\n1 100000000\n14 15\n1 100000000\n15 16\n1 1... | code_stdio |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.