info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"5 4\\n2 1\\n4 2\\n3 3\\n3 4\\n\", \"4 5\\n1 1\\n4 4\\n4 3\\n3 2\\n2 4\\n\", \"1 1\\n1 1\\n\", \"2 4\\n1 1\\n2 1\\n1 2\\n2 2\\n\", \"2 4\\n1 1\\n2 2\\n1 2\\n2 2\\n\", \"5 4\\n2 1\\n4 4\\n3 3\\n3 4\\n\", \"4 5\\n2 1\\n4 4\\n4 3\\n3 2\\n2 4\\n\", \"2 4\\n1 1\\n2 2\\n2 2\\n2 2\\n\", \"5 4\\n2 1\\...
You are given a chessboard of size n Γ— n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) βŒ‰ numbers from 1 to ⌈ (n^2)/(2) βŒ‰ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) βŒ‰ numbers from ⌈ (n^2)/(2) βŒ‰ + 1 to n^2 ...
0.125
{"tests": "{\"inputs\": [\"4\\n\", \"10\\n\", \"3\\n\", \"20\\n\", \"8\\n\", \"1872\\n\", \"771623\\n\", \"623847\\n\", \"1\\n\", \"324\\n\", \"14\\n\", \"15\\n\", \"259813\\n\", \"11\\n\", \"2\\n\", \"13\\n\", \"98232\\n\", \"17\\n\", \"898934\\n\", \"18\\n\", \"6\\n\", \"1248\\n\", \"1000000\\n\", \"9\\n\", \"5\\n\",...
Let n be an integer. Consider all permutations on integers 1 to n in lexicographic order, and concatenate them into one big sequence p. For example, if n = 3, then p = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]. The length of this sequence will be n β‹… n!. Let 1 ≀ i ≀ j ≀ n β‹… n! be a pair of indices. We cal...
0
{"tests": "{\"inputs\": [\"4 100 2\\n20 30 75 80\\n\", \"5 100 3\\n1 2 4 60 87\\n\", \"4 10 4\\n1 3 6 10\\n\", \"2 1000000000 1\\n1 1000000000\\n\", \"3 8 3\\n1 2 6\\n\", \"3 8 2\\n4 6 8\\n\", \"4 8 2\\n2 3 6 8\\n\", \"4 8 1\\n3 4 6 8\\n\", \"5 8 1\\n2 4 5 6 7\\n\", \"5 8 3\\n3 5 6 7 8\\n\", \"1 1000000000 1\\n228\\n\"...
You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece...
0
{"tests": "{\"inputs\": [\"6\\n3\\n2 3 4\\n2\\n3 3\\n3\\n-1 -1 -1\\n3\\n3 4 -1\\n1\\n2\\n4\\n4 -1 4 5\\n\", \"6\\n3\\n2 3 4\\n2\\n3 3\\n3\\n-1 -1 -1\\n3\\n3 4 -1\\n1\\n2\\n4\\n4 -1 4 5\\n\", \"10\\n4\\n2 4 4 5\\n4\\n2 -1 4 -1\\n4\\n4 5 5 5\\n4\\n2 3 4 5\\n4\\n2 3 4 5\\n4\\n-1 3 4 5\\n4\\n-1 3 4 5\\n4\\n3 3 4 5\\n4\\n3 ...
Vasya has written some permutation p_1, p_2, …, p_n of integers from 1 to n, so for all 1 ≀ i ≀ n it is true that 1 ≀ p_i ≀ n and all p_1, p_2, …, p_n are different. After that he wrote n numbers next_1, next_2, …, next_n. The number next_i is equal to the minimal index i < j ≀ n, such that p_j > p_i. If there is no su...
0
{"tests": "{\"inputs\": [\"3 5\\n\", \"1 2\\n\", \"3510 4371\\n\", \"207434 496771\\n\", \"117 485\\n\", \"1 6\\n\", \"999999 1000000\\n\", \"1 100\\n\", \"91306 947926\\n\", \"882942 924458\\n\", \"7882 399082\\n\", \"1395 6977\\n\", \"1 1000000\\n\", \"324 637\\n\", \"2115 5821\\n\", \"5 9\\n\", \"61 464\\n\", \"4666...
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surfac...
0.875
{"tests": "{\"inputs\": [\"6\\nababab\\n\", \"4\\nbbbb\\n\", \"2\\naa\\n\", \"4\\nbbbb\\n\", \"6\\nbbbbba\\n\", \"8\\nbbbabbba\\n\", \"8\\nbbabbbaa\\n\", \"4\\nbbba\\n\", \"6\\nabbbbb\\n\", \"8\\nbbbababa\\n\", \"8\\nababbbba\\n\", \"6\\nbababa\\n\", \"4\\nabbb\\n\", \"6\\nbbbbbb\\n\", \"8\\nabababbb\\n\", \"8\\naabbbb...
Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n. He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arb...
0
{"tests": "{\"inputs\": [\"2\\n6\\n2 3 11 14 1 8\\n2\\n3 2\\n100 1\\n5\\n3 5 100 2 3\\n2\\n30 5\\n90 1\\n\", \"2\\n6\\n2 3 11 14 1 8\\n2\\n3 2\\n100 1\\n5\\n3 5 100 2 3\\n2\\n30 5\\n95 1\\n\", \"2\\n6\\n3 3 11 14 1 8\\n2\\n3 1\\n100 1\\n5\\n3 5 100 2 3\\n2\\n30 5\\n90 1\\n\", \"2\\n6\\n2 3 11 14 1 8\\n2\\n3 2\\n000 1\\...
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i. The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero ...
0.25
{"tests": "{\"inputs\": [\"4\\n1 0\\n4 1\\n3 4\\n0 3\\n\", \"8\\n0 0\\n1 0\\n2 1\\n3 3\\n4 6\\n3 6\\n2 5\\n1 3\\n\", \"3\\n100 86\\n50 0\\n150 0\\n\", \"6\\n-99555247 -9420873\\n-68495517 -72858523\\n-56392372 -82582689\\n-45496035 -89051170\\n-76555765 -25613520\\n-88658910 -15889354\\n\", \"4\\n15618728 -98772746\\n9...
Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of t...
0
{"tests": "{\"inputs\": [\"7 24 21 23\\n16 17 14 20 20 11 22\\n\", \"62 51 43 50\\n40 36 14 6 44 12 23 23 50 37 15 14 21 16 6 9 40 21 20 11 21 6 34 50 40 43 44 30 12 41 28 39 31 34 12 32 9 33 45 9 13 22 48 24 11 5 24 21 46 26 14 47 10 18 42 2 40 30 46 47 22 3\\n\", \"39 14 6 10\\n1 10 13 7 6 11 1 2 2 11 6 3 10 3 13 7 4...
Vova had a pretty weird sleeping schedule. There are h hours in a day. Vova will sleep exactly n times. The i-th time he will sleep exactly after a_i hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of this story (the initial time is 0). Each time Vova sleeps exactly one day (in...
0
{"tests": "{\"inputs\": [\"3\\n3 1 4\\n\", \"4\\n7 7 1 1\\n\", \"1\\n1\\n\", \"3\\n2 1 3\\n\", \"2\\n3 4\\n\", \"10\\n582366931603099761 314858607473442114 530263190370309150 871012489649491233 877068367969362781 671646356752418008 390155369686708364 958695211216189893 919124874293325142 196726357117434998\\n\", \"20\\...
Ridhiman challenged Ashish to find the maximum valued subsequence of an array a of size n consisting of positive integers. The value of a non-empty subsequence of k elements of a is defined as βˆ‘ 2^i over all integers i β‰₯ 0 such that at least max(1, k - 2) elements of the subsequence have the i-th bit set in their bin...
0.5
{"tests": "{\"inputs\": [\"3\\n\\n1\\n\\n2\\n\\n1\\n\\n0\", \"8\\n4 8 2 6 3 1 5 7\\n\", \"10\\n5 1 6 2 8 3 4 10 9 7\\n\", \"4\\n3 4 1 2\\n\", \"5\\n1 4 2 3 5\\n\", \"3\\n1 3 2\\n\", \"5\\n5 4 3 2 1\\n\", \"10\\n10 1 2 3 4 5 9 8 7 6\\n\", \"7\\n6 1 2 3 4 5 7\\n\", \"1\\n1\\n\", \"2\\n1 2\\n\", \"2\\n2 1\\n\", \"10\\n5 9...
This is an interactive problem. We hid from you a permutation p of length n, consisting of the elements from 1 to n. You want to guess it. To do that, you can give us 2 different indices i and j, and we will reply with p_{i} mod p_{j} (remainder of division p_{i} by p_{j}). We have enough patience to answer at most 2...
0
{"tests": "{\"inputs\": [\"2\\n1 2 2 2\\n1 1 2 2\\n\", \"1\\n69 69 69 69\\n\", \"1\\n3 2 4 7\\n\", \"5\\n1 1 1000000000 1000000000\\n1 1 1000000000 1000000000\\n1 1 1000000000 1000000000\\n1 1 1000000000 1000000000\\n1 1 65537 65537\\n\", \"1\\n1 1 131073 131073\\n\", \"1\\n69 69 34 69\\n\", \"1\\n3 2 4 1\\n\", \"5\\n1...
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2). He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will...
0
{"tests": "{\"inputs\": [\"6\\n1\\n2\\n3\\n4\\n6\\n9\\n\", \"6\\n1\\n2\\n3\\n4\\n6\\n16\\n\", \"6\\n1\\n2\\n3\\n7\\n6\\n16\\n\", \"6\\n1\\n2\\n3\\n7\\n1\\n30\\n\", \"6\\n1\\n2\\n3\\n4\\n11\\n9\\n\", \"6\\n1\\n3\\n3\\n4\\n6\\n16\\n\", \"6\\n1\\n2\\n3\\n7\\n6\\n45\\n\", \"6\\n1\\n2\\n3\\n7\\n1\\n17\\n\", \"6\\n1\\n2\\n3\...
Ridbit starts with an integer n. In one move, he can perform one of the following operations: * divide n by one of its proper divisors, or * subtract 1 from n if n is greater than 1. A proper divisor is a divisor of a number, excluding itself. For example, 1, 2, 4, 5, and 10 are proper divisors of 20, but 2...
0
{"tests": "{\"inputs\": [\"1\\naaaaaaaaaaa\\n\", \"1\\nab\\n\", \"2\\nya\\nklmbfxzb\\n\", \"1\\nz\\n\", \"1\\na\\n\", \"19\\nqhovyphr\\nttymgy\\nqbed\\nidxitl\\nusbrx\\nqevvydqdb\\nltyjljj\\ncgv\\nsruvudcu\\naqjbqjybyq\\nrhtwwtthhh\\nh\\nksktyyst\\npmwmnzswlw\\nm\\nuwaup\\nxhvk\\nj\\nvii\\n\", \"15\\nieqqe\\nwwbnobrb\\...
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything. At last, after some thought, he thought of somethin...
0.5
{"tests": "{\"inputs\": [\"10\\n6 6 6 6\\n7 7 7 7\\n4 4 4 4\\n8 8 8 8\\n\", \"10\\n5 6 5 6\\n6 6 7 7\\n5 8 6 6\\n9 9 9 9\\n\", \"5\\n3 3 3 3\\n3 3 3 3\\n3 3 3 3\\n3 3 3 3\\n\", \"100000\\n25000 75000 80000 80000\\n99999 99999 2 2\\n99999 2 99999 99999\\n2 99999 99999 99999\\n\", \"100000\\n25000 50000 50001 75001\\n250...
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards... There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can b...
0
{"tests": "{\"inputs\": [\"381 492\\n\", \"5 14\\n\", \"629 657\\n\", \"536 298\\n\", \"441 915\\n\", \"522 92\\n\", \"723 350\\n\", \"339 433\\n\", \"953 553\\n\", \"433 126\\n\", \"399 280\\n\", \"538 261\\n\", \"740 519\\n\", \"242 86\\n\", \"117 399\\n\", \"632 264\\n\", \"143 522\\n\", \"923 488\\n\", \"828 485\\n...
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? Input The input contains two integers a and b (0 ≀ a, b ≀ 103), separated by a single space. Output Output ...
0.875
{"tests": "{\"inputs\": [\"4 5\\n1 2 1\\n1 2 2\\n2 3 1\\n2 3 3\\n2 4 3\\n3\\n1 2\\n3 4\\n1 4\\n\", \"5 7\\n1 5 1\\n2 5 1\\n3 5 1\\n4 5 1\\n1 2 2\\n2 3 2\\n3 4 2\\n5\\n1 5\\n5 1\\n2 5\\n1 5\\n1 4\\n\", \"2 1\\n1 2 1\\n1\\n1 2\\n\", \"2 5\\n1 2 1\\n1 2 2\\n1 2 3\\n1 2 4\\n1 2 5\\n1\\n1 2\\n\", \"2 3\\n1 2 3\\n1 2 2\\n1 2...
Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the following q queries. In the i-th query, he gives you two integers - ui and vi. ...
0.875
{"tests": "{\"inputs\": [\"3 3 1 2 3\\n\", \"2 1 1 1 2\\n\", \"100000 64022 49026 55956 88430\\n\", \"10 9 10 8 10\\n\", \"100000 100000 1 1 1\\n\", \"5 1 1 5 5\\n\", \"100000 1 100000 100000 100000\\n\", \"100000 87223 66046 27153 40823\\n\", \"100000 100000 1 100000 100000\\n\", \"100000 83958 32567 91083 95317\\n\",...
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. * The painting is a square 3 Γ— 3, each cell contains a single integer from 1 to n, an...
0
{"tests": "{\"inputs\": [\"2 2\\nBk Fm\\nCf Es\\n\", \"2 1\\nH H\\nHe\\n\", \"10 3\\nMn Co Li Mg C P F Zn Sc K\\nSn Pt Y\\n\", \"17 7\\nH H H H H H H H H H H H H H H H B\\nLi Li Li Li Li Li Li\\n\", \"16 9\\nB Zn Mn Li Li B Na Mg Sc Ne Mn Cr V N Ne Cr\\nB V Cd Sc Al Fm B Cl C\\n\", \"17 13\\nHe Ru Cu Sr P Br Ar Cr Na I...
There is the following puzzle popular among nuclear physicists. A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements. You are allowed to take any two different atoms and fuse a ...
0
{"tests": "{\"inputs\": [\"3\\nSVO\\nSVO-&gt;HKT\\nHKT-&gt;SVO\\nSVO-&gt;RAP\\n\", \"4\\nSVO\\nSVO-&gt;CDG\\nLHR-&gt;SVO\\nSVO-&gt;LHR\\nCDG-&gt;SVO\\n\", \"1\\nESJ\\nESJ->TSJ\\n\", \"1\\nAAK\\nAAK->ABA\\n\", \"3\\nZIZ\\nDWJ->ZIZ\\nZIZ->DWJ\\nZIZ->DWJ\\n\", \"3\\nSVO\\nSVO->HKT\\nHKT->SVO\\nSVO->RAP\\n\", \"11\\nFGH\\n...
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
0
{"tests": "{\"inputs\": [\"7 2\\n\", \"5 3\\n\", \"33 57\\n\", \"99 55\\n\", \"37 19\\n\", \"31 32\\n\", \"99 20\\n\", \"37 39\\n\", \"7 10\\n\", \"57 15\\n\", \"99 177\\n\", \"99 193\\n\", \"19 12\\n\", \"13 21\\n\", \"57 67\\n\", \"23 39\\n\", \"97 100\\n\", \"99 99\\n\", \"69 17\\n\", \"55 55\\n\", \"39 73\\n\", \"7...
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon p...
0
{"tests": "{\"inputs\": [\"5\\n3\\n2\\n4\\n3\\n5\", \"10\\n123\\n123\\n123\\n123\\n123\", \"10000000007\\n2\\n3\\n5\\n7\\n11\", \"5\\n3\\n2\\n4\\n3\\n6\", \"10\\n123\\n219\\n123\\n123\\n123\", \"10000000007\\n2\\n3\\n5\\n3\\n11\", \"10000000007\\n2\\n3\\n1\\n3\\n11\", \"10\\n123\\n633\\n27\\n9\\n123\", \"5\\n3\\n2\\n4\...
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)! There are five means of transport in this empire: * Train: travels from City 1 to 2 in one minute. A train can occupy at most A people. * Bus: travels from City 2 to 3 in one minute. A bus can occupy a...
0.625
{"tests": "{\"inputs\": [\"81 58\", \"4 54\", \"35 58\", \"3 54\", \"68 58\", \"3 34\", \"88 58\", \"5 34\", \"88 51\", \"5 0\", \"88 27\", \"5 -1\", \"51 11\", \"51 1\", \"2 -2\", \"95 1\", \"2 -4\", \"54 1\", \"4 -1\", \"47 0\", \"7 -1\", \"47 -1\", \"10 -1\", \"77 1\", \"15 -1\", \"134 1\", \"28 -1\", \"13 1\", \"24...
There is a train going from Station A to Station B that costs X yen (the currency of Japan). Also, there is a bus going from Station B to Station C that costs Y yen. Joisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station A to Station B by train and then trav...
0.875
{"tests": "{\"inputs\": [\"3 2 30 3 26 226\\n9 0 18 3 20 118\\n5 5 12 2 15 203\\n7 4 19 2 22 197\\n7 4 24 4 17 209\\n0 0 0 0 0 0\", \"3 2 30 3 26 226\\n9 0 18 3 20 118\\n5 5 12 0 15 203\\n7 4 19 2 22 197\\n7 4 24 4 17 209\\n0 0 0 0 0 0\", \"3 2 30 3 41 226\\n9 0 18 3 20 118\\n5 5 12 0 15 203\\n7 4 19 2 22 197\\n7 4 24 ...
Ataru Oafoot of Aizu Gakuen University High School decided to play with a slot machine. When you insert a medal on this machine, three reels will start spinning and each reel will stop automatically. In a normal game (normal game), 3 medals are inserted, and when the symbols are aligned, the following medals are obtai...
0
{"tests": "{\"inputs\": [\"5 5\\n3 2 3 0 0\\n4 2 0 0 2\", \"5 4\\n0 2 2 1 1\\n1 1 1 3\", \"5 3\\n3 2 3 0 0\\n4 2 0 0 2\", \"4 4\\n0 1 1 1 1\\n1 0 1 4\", \"5 3\\n3 2 5 0 0\\n4 2 0 0 2\", \"4 3\\n3 2 5 0 0\\n4 2 0 0 2\", \"4 3\\n3 2 5 0 0\\n4 2 0 0 4\", \"4 3\\n3 2 6 0 0\\n4 2 0 0 4\", \"4 3\\n3 1 6 0 0\\n4 2 0 0 4\", \"...
Mr. Kobou found a bundle of old paper when he was cleaning his family home. On each paper, two series of numbers are written. Strange as it appeared to him, Mr. Kobou further went through the storehouse and found out a note his ancestor left. According to it, the bundle of paper is a treasure map, in which the two sequ...
0.5
{"tests": "{\"inputs\": [\"hyo\\nni\\nEND_OF_TEXT\\nf\\nd\\nf\\nf\\nk\\np\\np\\ne\\ny\\na\\nk\\ny\\ny\\nn\\ny\\n-\", \"oyh\\nni\\nEND_OF_TEXT\\nf\\nd\\nf\\nf\\nk\\np\\np\\ne\\ny\\na\\nk\\ny\\ny\\nn\\ny\\n-\", \"hyo\\nnh\\nEND_OF_TEXT\\nf\\nd\\nf\\nf\\nk\\np\\np\\ne\\ny\\na\\nk\\ny\\ny\\nn\\ny\\n-\", \"hyo\\nni\\nEND_OF...
Emacs is a text editor which is widely used by many programmers. The advantage of Emacs is that we can move a cursor without arrow keys and the mice. For example, the cursor can be moved right, left, down, and up by pushing f, b, n, p with the Control Key respectively. In addition, cut-and-paste can be performed witho...
0
{"tests": "{\"inputs\": [\"3\\n...\\n.@.\\n...\\n3\\n.##\\n.#.\\n@##\\n3\\n##.\\n#..\\n@..\\n5\\n....@\\n##...\\n#....\\n...#.\\n##.##\\n5\\n#...#\\n...#.\\n#....\\n...##\\n..@..\\n5\\n#....\\n.....\\n.....\\n.....\\n..@..\\n5\\n#..#.\\n#.#.#\\n.#.#.\\n....#\\n.#@##\\n5\\n..##.\\n..#..\\n#....\\n#....\\n.#@..\\n0\", \"...
The earth is under an attack of a deadly virus. Luckily, prompt actions of the Ministry of Health against this emergency successfully confined the spread of the infection within a square grid of areas. Recently, public health specialists found an interesting pattern with regard to the transition of infected areas. At e...
0
{"tests": "{\"inputs\": [\"2\\n-35 -35 100 100\\n-49 49 2000 -2000\\n4\\n0 0 0 3\\n0 0 3 0\\n0 3 3 3\\n3 0 3 3\\n4\\n0 3 -4 6\\n3 0 6 -4\\n2 3 6 6\\n-1 2 -4 6\\n0\", \"2\\n-35 -35 100 100\\n-49 49 2000 -2000\\n4\\n0 0 0 3\\n0 0 3 0\\n0 3 3 3\\n6 0 3 3\\n4\\n0 3 -4 6\\n3 0 6 -4\\n2 3 6 6\\n-1 2 -4 6\\n0\", \"2\\n-35 -35...
We understand that reading English is a great pain to many of you. So we’ll keep this problem statememt simple. Write a program that reports the point equally distant from a set of lines given as the input. In case of no solutions or multiple solutions, your program should report as such. Input The input consists o...
0
{"tests": "{\"inputs\": [\"20\\n1\\n0 10\", \"20\\n1\\n1 10\", \"20\\n1\\n0 7\", \"20\\n1\\n2 10\", \"20\\n1\\n3 7\", \"20\\n1\\n0 19\", \"20\\n1\\n0 12\", \"20\\n1\\n2 7\", \"20\\n1\\n4 10\", \"20\\n1\\n0 28\", \"20\\n0\\n0 12\", \"20\\n1\\n0 3\", \"20\\n1\\n4 6\", \"20\\n1\\n1 15\", \"20\\n1\\n-1 12\", \"20\\n1\\n6 7...
D: Sunburn-Suntan- story Aizunyan is a second-year student who belongs to the programming contest club of Wakagamatsu High School, commonly known as the Prokon club. Cute like an angel. Aizu Nyan is planning to participate in this summer festival, so I made a schedule for the band to go to listen to. I'm worried abou...
0.25
{"tests": "{\"inputs\": [\"2 3\\n..#\\n##.\\n.##\\n#..\", \"2 3\\n..\\\"\\n##.\\n.##\\n#..\", \"2 3\\n..\\\"\\n.##\\n.##\\n#..\", \"2 3\\n..#\\n#\\\".\\n.##\\n$./\", \"2 1\\n..\\\"\\n.##\\n.##\\n#./\", \"2 3\\n..#\\n#\\\".\\n##.\\n$./\", \"0 3\\n..#\\n.\\\"#\\n##.\\n$./\", \"3 3\\n#..\\n.#\\\"\\n##.\\n$./\", \"2 3\\n.#...
A: Find the difference problem Given rectangular boards A and B with N squares vertically and M squares horizontally. For each board, each square is painted white or black. The color of the square in the i-th row and j-th column of the board X is written as C (i, j, X). Count how many pairs of integers (i, j) meet ...
0
{"tests": "{\"inputs\": [\"4\\n1 2 3 5\", \"3\\n3 4 6\", \"4\\n1 2 5 5\", \"3\\n3 4 3\", \"4\\n1 2 5 7\", \"3\\n3 7 3\", \"4\\n1 2 1 7\", \"3\\n3 10 3\", \"3\\n3 13 3\", \"4\\n1 2 2 11\", \"3\\n6 13 3\", \"3\\n4 13 3\", \"3\\n4 13 4\", \"3\\n4 13 5\", \"3\\n4 6 5\", \"3\\n4 6 7\", \"3\\n4 4 7\", \"3\\n5 4 7\", \"3\\n9 ...
Find the least common multiple (LCM) of given n integers. Constraints * 2 ≀ n ≀ 10 * 1 ≀ ai ≀ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of th...
0.75
{"tests": "{\"inputs\": [\"15\\n3 11 2 5 10 9 7 13 15 8 4 12 6 1 14\\n\", \"8\\n3 6 5 4 2 7 1 8\\n\", \"7\\n1 2 3 6 7 4 5\\n\", \"15\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\\n\", \"3\\n2 3 1\\n\", \"40\\n5 40 6 27 39 37 17 34 3 30 28 13 12 8 11 10 31 4 1 16 38 22 29 35 33 23 7 9 24 14 18 26 19 21 15 36 2 20 32 25\\n\", \...
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating turns of mo...
0.875
{"tests": "{\"inputs\": [\"6\\n1 2 4 4 4 9\\n\", \"4\\n1 4 2 2\\n\", \"50\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\\n\", \"100\\n50 50 50 50 50 50 87 87 87 46 46 46 96 96 96 96 94 94 94 47 47 47 42 84 86 84 84 93 49 49...
You have a set of n weights. You know that their masses are a_1, a_2, ..., a_n grams, but you don't know which of them has which mass. You can't distinguish the weights. However, your friend does know the mass of each weight. You can ask your friend to give you exactly k weights with the total mass m (both parameters ...
0
{"tests": "{\"inputs\": [\"4\\n\", \"1\\n\", \"2\\n\", \"10\\n\", \"87341\\n\", \"204575811\\n\", \"605551861\\n\", \"8\\n\", \"776\\n\", \"864918\\n\", \"377684528\\n\", \"15\\n\", \"972\\n\", \"1000000000\\n\", \"8795795\\n\", \"423353776\\n\", \"16\\n\", \"9\\n\", \"772168\\n\", \"11\\n\", \"306495050\\n\", \"17\\n\...
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with ve...
0.5
{"tests": "{\"inputs\": [\"3\\n123456789 214365879 987654321\\n\", \"4\\n5 2 4 7\\n\", \"8\\n9 1 4 10 7 5 8 6\\n\", \"8\\n3 8 10 6 7 5 2 9\\n\", \"8\\n9 8 4 5 6 1 7 10\\n\", \"8\\n2 5 4 9 7 1 6 3\\n\", \"8\\n10 8 5 1 4 2 3 6\\n\", \"2\\n1 1000000000\\n\", \"8\\n2 3 10 5 9 1 4 7\\n\", \"8\\n8 5 2 3 7 1 6 10\\n\", \"1\\n...
You are given an array a_1, a_2, ..., a_n. All a_i are pairwise distinct. Let's define function f(l, r) as follows: * let's define array b_1, b_2, ..., b_{r - l + 1}, where b_i = a_{l - 1 + i}; * sort array b in increasing order; * result of the function f(l, r) is βˆ‘_{i = 1}^{r - l + 1}{b_i β‹… i}. Calcula...
0.125
{"tests": "{\"inputs\": [\"8 5 20\\n\", \"3 9 3\\n\", \"5 8 6\\n\", \"5 3 2\\n\", \"20 61 100\\n\", \"44 2 53\\n\", \"100 1 1\\n\", \"100 100 100\\n\", \"68 73 96\\n\", \"92 35 39\\n\", \"2 2 2\\n\", \"68 91 90\\n\", \"54 82 100\\n\", \"1 1 1\\n\", \"2 1 1\\n\", \"2 1 2\\n\", \"2 2 1\\n\", \"100 99 99\\n\", \"58 92 33\...
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks. Determine whether the Cossack can reward all participants, giving each of them at leas...
0
{"tests": "{\"inputs\": [\"3\\n3 2\\nXX......XX...X\\n4 2\\nX...X.X..X\\n5 3\\n.......X..X\\n\", \"6\\n5 4\\n...............\\n5 4\\n...............X.....\\n5 4\\n...............X....\\n5 4\\n...............X.....X....\\n5 4\\n...................\\n5 4\\n...................X.....\\n\", \"7\\n240501 42869\\nXX.X.X.X.X.X...
Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select...
0
{"tests": "{\"inputs\": [\"4\\n1 1 2 2\\n\", \"3\\n1 2 3\\n\", \"1\\n2359\\n\", \"10\\n9381 6234 2965 9236 4685 3101 5832 7369 5233 5308\\n\", \"10\\n5957 94 8220 2463 9623 7028 9656 677 8373 1126\\n\", \"10\\n9906 9903 10000 9998 9936 9952 9924 9939 9917 9966\\n\", \"11\\n15 12 9915 40 63 9984 9968 9924 9925 11 9991\\...
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting o...
0.125
{"tests": "{\"inputs\": [\"3\\n1 1\\n4 5\\n5 11\\n\", \"1\\n1000000 1000000\\n\", \"2\\n63242 999919263\\n63242 999919264\\n\", \"5\\n1000000000 1000000000\\n1000000000 1000000000\\n1000000000 1000000000\\n1000000000 1000000000\\n1000000000 1000000000\\n\", \"5\\n998244353 999999998\\n998244353 999999999\\n998244353 99...
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days opt...
0.875
{"tests": "{\"inputs\": [\"A089956\\n\", \"A089957\\n\", \"A144045\\n\", \"A278832\\n\", \"A089946\\n\", \"A144035\\n\", \"A378822\\n\", \"A089947\\n\", \"A378282\\n\", \"A079948\\n\", \"A388282\\n\", \"A079848\\n\", \"A388822\\n\", \"A079849\\n\", \"B388822\\n\", \"A079749\\n\", \"B398822\\n\", \"A079759\\n\", \"A9890...
Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A1440...
0.75
{"tests": "{\"inputs\": [\"3\\n2 3\\n3 1\\n3 2\\n1 3\\n3 3\\n1 3\\n\", \"1\\n64 9\\n41 36\\n\", \"1\\n64 9\\n41 14\\n\", \"3\\n2 3\\n3 1\\n3 2\\n1 3\\n3 6\\n1 3\\n\", \"3\\n2 3\\n3 1\\n3 0\\n1 3\\n3 6\\n1 3\\n\", \"3\\n2 4\\n3 1\\n3 0\\n1 3\\n3 6\\n1 3\\n\", \"1\\n59 9\\n41 14\\n\", \"1\\n5 9\\n41 14\\n\", \"1\\n5 14\\...
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rec...
0.25
{"tests": "{\"inputs\": [\"5\\n1 4 3 1 2\\n\", \"3\\n1 3 2\\n\", \"94\\n23 8 25 27 33 16 8 8 15 11 33 23 13 18 26 20 21 10 18 15 6 11 21 14 27 16 5 1 33 11 31 33 3 21 31 7 28 32 19 16 20 22 23 18 24 16 24 18 22 12 31 9 14 29 25 29 29 16 12 15 21 6 30 21 28 11 2 33 7 12 33 16 28 32 28 27 21 18 27 17 24 22 23 4 16 2 5 23...
In this problem MEX of a certain array is the smallest positive integer not contained in this array. Everyone knows this definition, including Lesha. But Lesha loves MEX, so he comes up with a new problem involving MEX every day, including today. You are given an array a of length n. Lesha considers all the non-empty...
0
{"tests": "{\"inputs\": [\"5 7\\n1 3 1 5 3\\n\", \"6 4\\n4 11 8 2 1 13\\n\", \"6 3\\n8 9 4 17 11 5\\n\", \"5 6\\n2 2 2 2 2\\n\", \"3 1\\n2 4 6\\n\", \"10 9\\n6 4 1 6 4 9 2 2 10 5\\n\", \"10 7\\n5 10 4 3 8 10 6 1 6 2\\n\", \"8 2\\n65 77 69 91 4 5 79 52\\n\", \"3 8\\n2 9 108\\n\", \"10 2\\n9 4 6 3 10 6 6 4 10 2\\n\", \"1...
Diana loves playing with numbers. She's got n cards with positive integer numbers a_i written on them. She spends her free time multiplying the numbers on the cards. She picks a non-empty subset of the cards and multiplies all the numbers a_i written on them. Diana is happy when the product of the numbers ends with he...
0
{"tests": "{\"inputs\": [\"3 3 2\\n\", \"5 -4 4\\n\", \"5 -4 3\\n\", \"100 -1000 100\\n\", \"20 97 13\\n\", \"100 1000 3\\n\", \"100 -1000 100\\n\", \"50 231 39\\n\", \"60 -728 29\\n\", \"5 2 2\\n\", \"2 1 1\\n\", \"100 -1000 1\\n\", \"100 1000 100\\n\", \"100 -1000 3\\n\", \"100 -10000 100\\n\", \"70 2335 100\\n\", \"...
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into...
0.125
{"tests": "{\"inputs\": [\"4 7 2\\n3 3 2 4\\n\", \"3 5 3\\n3 1 2\\n\", \"5 5 1\\n1 3 1 2 1\\n\", \"10 49 11\\n5 18 1 19 11 11 16 5 6 6\\n\", \"1 1 1\\n1\\n\", \"13 20 9\\n2 9 2 2 5 11 10 10 13 4 6 11 14\\n\", \"15 26 4\\n3 6 7 1 5 2 4 4 7 3 8 7 2 4 8\\n\", \"5 50 6\\n2 1 3 1 3\\n\", \"50 50 2\\n2 2 4 5 2 1 5 4 5 4 5 2 ...
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets. Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filt...
0.625
{"tests": "{\"inputs\": [\"2\\n5 2 3\\n6 4 5\\n\", \"50\\n69 6 6\\n22 1 1\\n23 3 3\\n60 13 13\\n13 3 3\\n7 4 7\\n6 1 1\\n49 7 9\\n68 8 8\\n20 2 2\\n34 1 1\\n79 5 5\\n22 1 1\\n77 58 65\\n10 3 3\\n72 5 5\\n47 1 1\\n82 3 3\\n92 8 8\\n34 1 1\\n42 9 10\\n63 14 14\\n10 3 3\\n38 2 2\\n80 6 6\\n79 5 5\\n53 5 5\\n44 7 7\\n85 2 ...
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity β€” he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
0
{"tests": "{\"inputs\": [\"4\\n92 31\\n0 7\\n31 0\\n7 141\\n\", \"6\\n10001 0\\n0 10005\\n10003 10001\\n10002 10000\\n10005 10002\\n10004 10003\\n\", \"3\\n0 2\\n1 3\\n2 0\\n\", \"9\\n308992 348750\\n0 6496\\n487447 676506\\n874677 985199\\n260782 487447\\n985199 260782\\n348750 0\\n570981 308992\\n6496 570981\\n\", \"...
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. Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of...
0
{"tests": "{\"inputs\": [\"2 1 2\\n1 1\\n1 0\\n\", \"4 0 0\\n1 1\\n2 2\\n2 0\\n-1 -1\\n\", \"2 -10000 -10000\\n9998 9999\\n9999 10000\\n\", \"10 -4 -4\\n2 -4\\n2 0\\n-4 2\\n5 -4\\n-3 -5\\n1 4\\n-4 2\\n-3 5\\n0 -3\\n2 4\\n\", \"2 -10000 -10000\\n10000 10000\\n10000 9999\\n\", \"2 0 0\\n10000 -10000\\n10000 10000\\n\", \...
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can ...
0.875
{"tests": "{\"inputs\": [\"5 4\\n.X..\\n...X\\nX.X.\\n....\\n.XX.\\n5 3\\n1 1\\n\", \"4 7\\n..X.XX.\\n.XX..X.\\nX...X..\\nX......\\n2 2\\n1 6\\n\", \"4 6\\nX...XX\\n...XX.\\n.X..X.\\n......\\n1 6\\n2 2\\n\", \"1 2\\nX.\\n1 1\\n1 2\\n\", \"2 1\\nX\\nX\\n2 1\\n2 1\\n\", \"4 3\\n..X\\n..X\\n.XX\\n.XX\\n4 2\\n2 2\\n\", \"2...
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists e...
0
{"tests": "{\"inputs\": [\"6\\n123434\\n\", \"8\\n20152016\\n\", \"30\\n110110001101001110011000010100\\n\", \"10\\n5558403946\\n\", \"65\\n25852165999999999999942386995999999999999999999999999999999999999\\n\", \"40\\n1211122211121211111122121111221121112221\\n\", \"1\\n8\\n\", \"1\\n1\\n\", \"2\\n55\\n\", \"100\\n989...
Limak is a little polar bear. In the snow he found a scroll with the ancient prophecy. Limak doesn't know any ancient languages and thus is unable to understand the prophecy. But he knows digits! One fragment of the prophecy is a sequence of n digits. The first digit isn't zero. Limak thinks that it's a list of some s...
0
{"tests": "{\"inputs\": [\"3\\n2 3 1\\n\", \"3\\n1 2 3\\n\", \"100\\n39 8 87 59 49 19 6 64 81 26 90 58 30 93 51 94 91 10 37 68 14 86 75 41 15 73 76 85 13 84 34 25 54 92 23 11 99 53 80 74 22 29 20 79 7 66 62 72 28 71 12 48 18 9 78 38 43 47 5 50 77 82 52 96 97 65 55 88 16 45 69 4 61 42 60 100 24 32 57 21 89 70 27 35 98 8...
You are given a permutation of integers from 1 to n. Exactly once you apply the following operation to this permutation: pick a random segment and shuffle its elements. Formally: 1. Pick a random segment (continuous subsequence) from l to r. All <image> segments are equiprobable. 2. Let k = r - l + 1, i.e. the le...
0.25
{"tests": "{\"inputs\": [\"8\\n6 2 3\\n3 4 5\\n12 6 7\\n1 -1 8\\n4 -1 -1\\n5 -1 -1\\n14 -1 -1\\n2 -1 -1\\n\", \"3\\n15 -1 -1\\n10 1 3\\n5 -1 -1\\n\", \"10\\n911605217 -1 -1\\n801852416 -1 -1\\n140035920 -1 9\\n981454947 10 2\\n404988051 6 3\\n307545107 8 7\\n278188888 4 1\\n523010786 -1 -1\\n441817740 -1 -1\\n789680429...
Let T be arbitrary binary tree β€” tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent β€” it's the root of a tree. Every vertex has an integer number written on it. Following algorithm is run on every value from the tree T: 1. Set ...
0.75
{"tests": "{\"inputs\": [\"3 0\\n\", \"3 2\\n1 1 3 2\\n2 1 3 2\\n\", \"3 1\\n1 1 3 2\\n\", \"3 2\\n1 1 3 2\\n2 1 3 1\\n\", \"3 6\\n1 1 1 2\\n2 1 1 2\\n1 2 2 2\\n2 2 2 2\\n1 3 3 2\\n2 3 3 3\\n\", \"7 3\\n2 1 2 2\\n1 3 7 2\\n2 3 7 3\\n\", \"50 2\\n2 1 33 1\\n2 14 50 1\\n\", \"29 5\\n2 4 9 27\\n1 25 29 14\\n1 9 10 18\\n2 ...
Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were n elements in the array, and each element was not less...
0
{"tests": "{\"inputs\": [\"4 3\\n2 1 1\\n\", \"3 9\\n1 1 3\\n\", \"12345678 87654321\\n43043751 1000000000 53798715\\n\", \"25 5\\n3 3 3\\n\", \"612127849 669475006\\n271630930 676010757 22959739\\n\", \"100 10\\n2 3 4\\n\", \"626115781 966381948\\n395190569 820194184 229233367\\n\", \"48 27\\n22 39 20\\n\", \"19806641...
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
0.875
{"tests": "{\"inputs\": [\"2 2\\n20 18\\n2 14\\n\", \"5 3\\n-1 0 1 2 3\\n-1 0 1\\n\", \"14 8\\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\\n1000000000 1000000000 1000000000 1000000000 1000000000 ...
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has n lanterns and Big Ban...
0.25
{"tests": "{\"inputs\": [\"5 3\", \"2000 3\", \"7 3\", \"1776 3\", \"7 5\", \"195 3\", \"5 5\", \"206 3\", \"96 3\", \"96 2\", \"2000 1\", \"7 4\", \"1776 1\", \"7 2\", \"203 3\", \"206 4\", \"72 3\", \"14 4\", \"5 2\", \"203 5\", \"158 4\", \"115 3\", \"14 5\", \"203 7\", \"158 7\", \"14 9\", \"203 2\", \"158 2\", \"1...
There are K blue balls and N-K red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls. First, Snuke will arrange the N balls in a row from left to right. Then, Takahashi will collect only the K blue balls. In one move, he can collect any number of consecutive ...
0.75
{"tests": "{\"inputs\": [\"8 5\\n-9 -7 -4 -3 1 2 3 4\", \"5 3\\n-30 -10 10 20 50\", \"1 1\\n0\", \"3 2\\n10 20 30\", \"8 5\\n-9 -7 -4 -3 1 2 4 4\", \"5 5\\n-30 -10 10 20 50\", \"3 2\\n10 18 30\", \"5 3\\n-30 -5 10 20 50\", \"3 2\\n10 20 43\", \"8 1\\n-9 -7 -4 -3 1 2 4 4\", \"5 5\\n-30 -10 8 20 76\", \"5 5\\n-19 -10 8 2...
There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light...
0.625
{"tests": "{\"inputs\": [\"8 10\", \"3 7\", \"123456 234567\", \"8 3\", \"2 4\", \"8 5\", \"0 7\", \"25732 234567\", \"0 5\", \"3 4\", \"0 11\", \"29001 234567\", \"4 7\", \"2 5\", \"4 8\", \"3 5\", \"4 12\", \"3 6\", \"4 18\", \"7 10\", \"4 13\", \"7 7\", \"4 15\", \"4 17\", \"7 17\", \"7 21\", \"10 21\", \"4 21\", \"...
In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps N Snuke Chameleons in a cage. A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules: * A Snuke Chameleon that is blue will change its color to ...
0
{"tests": "{\"inputs\": [\"4 20 9\\n7 2\\n9 1\\n12 1\\n18 1\", \"3 8 3\\n0 1\\n3 2\\n6 1\", \"3 8 3\\n0 2\\n3 2\\n6 1\", \"4 20 18\\n7 2\\n9 1\\n12 1\\n18 1\", \"2 8 3\\n0 1\\n3 2\\n6 1\", \"3 8 3\\n1 2\\n3 2\\n6 1\", \"4 20 18\\n3 2\\n9 1\\n12 1\\n18 1\", \"1 8 3\\n1 2\\n3 2\\n6 1\", \"1 8 0\\n1 2\\n3 4\\n6 1\", \"1 8...
There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coor...
0
{"tests": "{\"inputs\": [\"5 8\\n5\\n10\\n8\\n7\\n3\\nADD 1\\nADD 3\\nCHECK 0\\nCHECK 1\\nCHECK 2\\nCHECK 3\\nCHECK 4\\nCHECK 5\", \"5 8\\n5\\n10\\n8\\n7\\n3\\nADD 1\\nADD 3\\nCHECK 0\\nCHECK 1\\nCHECK 2\\nCHFCK 3\\nCHECK 4\\nCHECK 5\", \"5 8\\n5\\n10\\n8\\n3\\n3\\nADD 1\\nADD 3\\nCHECK 0\\nCHECK 1\\nCHECK 2\\nCHFCK 3\...
At Akabe High School, a programmer training school, there is a unique study session run by the students themselves. It is important for programmers to constantly adopt new technologies, so the aim of this activity is to develop the habit of self-study through this study session. There are a total of N students, each w...
0
{"tests": "{\"inputs\": [\"6 6\\n1 2 3 4 5 6\\n1 2\\n2 3\\n3 4\\n1 4\\n4 5\\n5 6\", \"6 6\\n1 2 3 4 5 6\\n1 2\\n2 3\\n3 4\\n1 1\\n4 5\\n5 6\", \"6 6\\n1 3 3 4 5 6\\n1 2\\n2 3\\n3 4\\n1 1\\n4 5\\n5 6\", \"6 10\\n1 3 3 1 5 6\\n1 2\\n2 3\\n2 4\\n1 1\\n4 5\\n5 6\", \"6 6\\n2 4 3 4 5 6\\n1 2\\n2 3\\n3 4\\n1 3\\n4 5\\n5 6\",...
Escape An undirected graph with positive values ​​at the vertices is given. The vertices are numbered from 1 to N, and the i-th vertex has a value of w_i. You can start from the first vertex and move on the graph with the constraint that you cannot pass the edge that you just passed. At each vertex, you can get the sc...
0
{"tests": "{\"inputs\": [\"4 4\\n1 2\\n2 3\\n3 4\\n4 1\", \"4 3\\n1 2\\n2 3\\n3 4\", \"3 3\\n1 2\\n1 3\\n2 3\", \"8 9\\n2 1\\n3 5\\n1 6\\n2 5\\n3 1\\n8 4\\n2 7\\n7 1\\n7 4\", \"4 4\\n1 2\\n2 3\\n3 1\\n4 1\", \"4 3\\n1 2\\n2 4\\n3 4\", \"8 9\\n2 1\\n3 5\\n1 6\\n2 5\\n3 1\\n8 4\\n2 7\\n7 1\\n6 4\", \"4 4\\n1 2\\n2 3\\n3 ...
Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on an undirected graph. An example of pseudo code of BFS is as follows: 1: $current \leftarrow \{start\_vertex\}$ 2: $visited \leftarrow current$ 3: while $visited \ne $ the set of all the v...
0.375
{"tests": "{\"inputs\": [\"5\\n1 5 4 1 3\\n\", \"7\\n1 2 1 1 1 3 2\\n\", \"10\\n2 2 4 4 3 1 1 2 3 2\\n\", \"15\\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4\\n\", \"1\\n1\\n\", \"10\\n2 2 4 4 3 1 1 2 4 2\\n\", \"15\\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 5\\n\", \"15\\n1 2 3 1 2 4 2 1 1 6 6 4 2 5 5\\n\", \"15\\n1 2 3 1 2 7 2 1 1 6 6 4 2 5 5\\...
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn n numbers in a row, a_i is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will giv...
0.875
{"tests": "{\"inputs\": [\"4\\n0 0 5 5\\n0 0 4 4\\n1 1 4 4\\n1 1 4 4\\n\", \"5\\n0 0 10 8\\n1 2 6 7\\n2 3 5 6\\n3 4 4 5\\n8 1 9 2\\n\", \"3\\n0 0 1 1\\n1 1 2 2\\n3 0 4 1\\n\", \"3\\n0 0 1 1\\n0 1 1 2\\n1 0 2 1\\n\", \"4\\n0 0 10 10\\n5 5 15 15\\n11 11 14 14\\n12 12 13 13\\n\", \"4\\n5 2 10 3\\n1 2 7 3\\n9 2 12 3\\n8 2 ...
You are given n rectangles on a plane with coordinates of their bottom left and upper right points. Some (n-1) of the given n rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary. Find any point with integer coordinates that belongs...
0.125
{"tests": "{\"inputs\": [\"4\\n2 5\\n0 0 0 10\\n5 5 5 6\\n5 0 10 5\\n14 7 10 5\\n\", \"3\\n20 50\\n41 176 16 161\\n103 169 113 199\\n74 46 79 16\\n\", \"8\\n100 200\\n500 500 301 301\\n500 500 301 699\\n500 500 500 500\\n500 500 699 301\\n500 500 499 301\\n500 500 499 400\\n500 500 400 500\\n500 500 480 520\\n\", \"8\\...
Two friends are travelling through Bubble galaxy. They say "Hello!" via signals to each other if their distance is smaller or equal than d_1 and * it's the first time they speak to each other or * at some point in time after their last talk their distance was greater than d_2. We need to calculate how many t...
0
{"tests": "{\"inputs\": [\"4\\ntest\\ncontests\\ntest.\\n.test\\n6\\nts\\n.\\nst.\\n.test\\ncontes.\\nst\\n\", \"4\\ntest\\ncontests\\ntest.\\n.test\\n6\\nts\\n.\\nst.\\n.test\\ncontes.\\nst\\n\", \"8\\na\\nab\\naba\\nabacaba\\nabacabad\\nabac\\nabaca\\nabacab\\n13\\na\\nb\\nc\\naa\\nab\\nba\\nac\\nca\\nbc\\ncb\\naba\\...
Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature. There are n files on hard drive and their names are f_1, f_2, ..., f_n. Any file name contains between 1 and 8 characters, inclusive. All file names are unique. The file suggestion feature...
0
{"tests": "{\"inputs\": [\"5\\n2 1 1 2 5\\n\", \"3\\n4 5 3\\n\", \"2\\n10 10\\n\", \"3\\n1 2 3\\n\", \"4\\n1 1 3 5\\n\", \"4\\n5 3 3 3\\n\", \"5\\n1 1 2 2 1\\n\", \"5\\n10 9 5 3 7\\n\", \"5\\n10 10 9 8 8\\n\", \"6\\n3 3 4 4 3 4\\n\", \"5\\n3 3 1 1 2\\n\", \"8\\n2 2 10 6 4 2 2 4\\n\", \"4\\n4 4 4 3\\n\", \"3\\n1 1 1\\n\...
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th par...
0
{"tests": "{\"inputs\": [\"2 4 6\\n4 7\\n\", \"4 2 6\\n1 3 2 3\\n\", \"9 99252 6470888\\n74578 2746 96295 86884 21198 28655 22503 7868 47942\\n\", \"9 407 2710197\\n24191 58791 9486 68030 25807 11 88665 32600 12100\\n\", \"9 10770 5887448\\n3054 67926 81667 95184 41139 64840 76118 18577 22469\\n\", \"1 59139 1199252\\n...
Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations. Initially, there are n superheroes in avengers team having powers a_1, a_2, …, a_n, respectively. In one operation, they can r...
0
{"tests": "{\"inputs\": [\"3\\n3 10\\n6 3\\n8 2\\n1 4\\n4 10\\n4 1\\n3 2\\n2 6\\n1 100\\n2 15\\n10 11\\n14 100\\n\", \"1\\n2 1\\n2 2\\n1 1\\n\", \"1\\n1 20\\n20 25\\n\", \"1\\n7 745132167\\n928769069 893298383\\n653090177 337257634\\n815624998 996403895\\n224663197 845554094\\n663417903 312894963\\n27048664 603602031\\...
You are fighting with Zmei Gorynich β€” a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! <image> Initially Zmei Gorynich has x heads. You can deal n types of blows. If you deal a blow of the i-th type, you decrease the number of Gorynich's heads by min(d_i, curX), there curX is th...
0.5
{"tests": "{\"inputs\": [\"9\\n1 10 7 1\\n3 3 3 0\\n8 2 10 4\\n8 2 10 100\\n-10 20 -17 2\\n-3 2 2 0\\n-3 1 2 0\\n2 3 2 3\\n-1 3 -2 2\\n\", \"9\\n1 10 7 1\\n3 3 3 0\\n8 2 10 4\\n8 2 10 100\\n-10 20 -17 2\\n-3 1 2 0\\n-3 1 2 0\\n2 3 2 3\\n-1 3 -2 2\\n\", \"9\\n1 10 7 1\\n3 3 3 0\\n8 2 10 4\\n8 2 10 100\\n-10 13 -17 2\\n-...
Polycarp lives on the coordinate axis Ox and travels from the point x=a to x=b. It moves uniformly rectilinearly at a speed of one unit of distance per minute. On the axis Ox at the point x=c the base station of the mobile operator is placed. It is known that the radius of its coverage is r. Thus, if Polycarp is at a ...
0.625
{"tests": "{\"inputs\": [\"15 15 23\\n13 10 12\\n11 14 12\\n2 15 5\\n4 10 8\\n10 2 4\\n10 7 5\\n3 10 1\\n5 6 11\\n1 13 8\\n9 15 4\\n4 2 9\\n11 15 1\\n11 12 14\\n10 8 12\\n3 6 11\\n\", \"5 10 10000000\\n2 4 798\\n1 5 824\\n5 2 558\\n4 1 288\\n3 4 1890\\n3 1 134\\n2 3 1485\\n4 5 284\\n3 5 1025\\n1 2 649\\n\", \"2 1 5\\n1...
You are given a simple weighted connected undirected graph, consisting of n vertices and m edges. A path in the graph of length k is a sequence of k+1 vertices v_1, v_2, ..., v_{k+1} such that for each i (1 ≀ i ≀ k) the edge (v_i, v_{i+1}) is present in the graph. A path from some vertex v also has vertex v_1=v. Note ...
0
{"tests": "{\"inputs\": [\"5\\n\", \"2\\n\", \"3\\n\", \"200000\\n\", \"7\\n\", \"69\\n\", \"199998\\n\", \"199999\\n\", \"4\\n\", \"13\\n\", \"1\\n\", \"6\\n\", \"42\\n\", \"1337\\n\", \"12\\n\", \"31\\n\", \"103835\\n\", \"25\\n\", \"57\\n\", \"1040\\n\", \"11\\n\", \"14\\n\", \"43\\n\", \"22480\\n\", \"47\\n\", \"44...
There are n + 2 towns located on a coordinate line, numbered from 0 to n + 1. The i-th town is located at the point i. You build a radio tower in each of the towns 1, 2, ..., n with probability 1/2 (these events are independent). After that, you want to set the signal power on each tower to some integer from 1 to n (s...
0.125
{"tests": "{\"inputs\": [\"2\\n4 1\\n20100 1 202 202\\n3 100\\n1 1 1\\n\", \"1\\n3 3\\n97 2 2\\n\", \"1\\n3 3\\n132 2 2\\n\", \"2\\n4 1\\n20100 1 202 288\\n3 100\\n1 1 1\\n\", \"2\\n4 1\\n20100 1 202 525\\n3 101\\n1 0 1\\n\", \"2\\n4 1\\n20100 1 182 525\\n3 101\\n1 0 1\\n\", \"2\\n4 1\\n20100 1 202 202\\n3 101\\n1 1 1\...
You have a statistic of price changes for one product represented as an array of n positive integers p_0, p_1, ..., p_{n - 1}, where p_0 is the initial price of the product and p_i is how the price was increased during the i-th month. Using these price changes you are asked to calculate the inflation coefficients for ...
0.25
{"tests": "{\"inputs\": [\"2\\n2\\n2 4\\n10 12\\n0 2\\n5\\n1 4\\n7 8\\n9 10\\n13 15\\n19 20\\n1 2 3 4 5\\n\", \"1\\n1\\n1 8\\n0\\n\", \"1\\n1\\n1 4\\n0\\n\", \"2\\n2\\n2 3\\n10 12\\n0 2\\n5\\n1 4\\n7 8\\n9 10\\n13 15\\n19 20\\n1 2 3 4 5\\n\", \"1\\n1\\n0 4\\n0\\n\", \"2\\n2\\n2 3\\n10 12\\n0 2\\n5\\n1 4\\n7 8\\n9 9\\n1...
Alexey is travelling on a train. Unfortunately, due to the bad weather, the train moves slower that it should! Alexey took the train at the railroad terminal. Let's say that the train starts from the terminal at the moment 0. Also, let's say that the train will visit n stations numbered from 1 to n along its way, and ...
0.125
{"tests": "{\"inputs\": [\"1 4 6 2 2 1\\n\", \"4 10 13 10 3 1\\n\", \"3 10 15 17 9 2\\n\", \"4 9 30 10 3 1\\n\", \"4 9 24 10 3 1\\n\", \"196112 214848 221935 465535 132387 3661\\n\", \"1 9 10 5 5 3\\n\", \"626 705 1000 10072 858 35\\n\", \"1 8 10 3 3 3\\n\", \"5010 6384 10000 9022 3213 187\\n\", \"1 8 10 5 5 3\\n\", \"...
It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guys. For example, he can hit the ball directly to the specified point. And ye...
0
{"tests": "{\"inputs\": [\"@aa@a\\n\", \"a@aa@a\\n\", \"a@a@a\\n\", \"a@mc@ks@gu@rl@gq@zq@iz@da@uq@mi@nf@zs@hi@we@ej@ke@vb@az@yz@yl@rr@gh@um@nv@qe@qq@de@dy@op@gt@vx@ak@q\\n\", \"aglvesxsmivijisod@mxcnbfcfgqfwjouidlsueaswf@obehqpvbkmukxkicyoknkbol@kutunggpoxxfpbe@qkhv@llddqqoyjeex@byvtlhbifqmvlukmrvgvpwrscwfhpuwyknwchqh...
Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in Β«BersoftΒ» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order...
0.125
{"tests": "{\"inputs\": [\"4 1 1\\n\", \"3 4 5\\n\", \"1 1 2\\n\", \"3 11 8\\n\", \"1000000 1000000 1000000\\n\", \"5 8 13\\n\", \"602752 645534 784262\\n\", \"10 5 15\\n\", \"8 5 12\\n\", \"93952 49553 83405\\n\", \"688348 726472 442198\\n\", \"310703 820961 326806\\n\", \"246 137 940\\n\", \"3 3 3\\n\", \"1000000 500...
Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule. A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number β€” the number of bonds the atom must form with other atoms. An atom can form one...
0.75
{"tests": "{\"inputs\": [\"1 1 1\\n0\\n\", \"3 2 2\\n1 2\\n1 2\\n2 2\\n\", \"4 3 5\\n1 0 0\\n1 0 2\\n2 3 1\\n3 2 0\\n\", \"2 1 1\\n1\\n0\\n\", \"2 1 1\\n0\\n1\\n\", \"2 1 1\\n0\\n0\\n\", \"2 1 2\\n1\\n2\\n\", \"100 1 100\\n59\\n37\\n53\\n72\\n37\\n15\\n8\\n93\\n92\\n74\\n11\\n11\\n68\\n16\\n92\\n40\\n76\\n20\\n10\\n86\...
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor. At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information ...
0
{"tests": "{\"inputs\": [\"3 20\\n2 1 1\\n\", \"3 30\\n2 2 1\\n\", \"100 10000\\n54 46 72 94 79 83 91 54 73 3 24 55 54 31 28 20 19 6 25 19 47 23 1 70 15 87 51 39 54 77 55 5 60 3 15 99 56 88 22 78 79 21 38 27 28 86 7 88 12 59 55 70 25 1 70 49 1 45 69 72 50 17 4 56 8 100 90 34 35 20 61 76 88 79 4 74 65 68 75 26 40 72 59 ...
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song wi...
0
{"tests": "{\"inputs\": [\"2 5 1\\n5 8\\n\", \"6 2 3\\n2 2 2 2 1 1\\n\", \"4 100 3\\n1 100000 100000 1\\n\", \"1 1 1\\n1\\n\", \"1 100000 1\\n1000000000\\n\", \"3 2 3\\n999999998 999999998 999999998\\n\", \"11 18 8\\n4996 4993 4988 4982 4982 4982 4982 4982 4986 4989 4994\\n\", \"10 8 3\\n499 498 497 497 497 497 497 497...
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noti...
0.125
{"tests": "{\"inputs\": [\"3\\n3 4 5\\n\", \"1\\n1000000\\n\", \"1\\n1\\n\", \"7\\n2 13 22 32 72 91 96\\n\", \"2\\n1000000 999999\\n\", \"3\\n1 2 4\\n\", \"5\\n5 11 12 109 110\\n\", \"12\\n4 4 10 13 28 30 41 43 58 61 70 88\\n\", \"2\\n1000000 597253\\n\", \"5\\n8 11 12 109 110\\n\", \"12\\n4 4 10 13 28 30 35 43 58 61 7...
You are given a sequence a consisting of n integers. Find the maximum possible value of <image> (integer remainder of ai divided by aj), where 1 ≀ i, j ≀ n and ai β‰₯ aj. Input The first line contains integer n β€” the length of the sequence (1 ≀ n ≀ 2Β·105). The second line contains n space-separated integers ai (1 ≀ a...
0.75
{"tests": "{\"inputs\": [\"4573\\n\", \"527\\n\", \"1357997531\\n\", \"333333332379\\n\", \"8623\\n\", \"4052769\\n\", \"24683\\n\", \"4250769\\n\", \"21\\n\", \"5685341\\n\", \"99\\n\", \"444443\\n\", \"503147\\n\", \"23759\\n\", \"333333333333333333333\\n\", \"11\\n\", \"435729\\n\", \"1001\\n\", \"7700016673\\n\", \...
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer. Reliable sources have informed the financier Anton of some information about the exchange rate of...
0.875
{"tests": "{\"inputs\": [\"2\\n1 5\\n3 2\\n\", \"3\\n2 4 4\\n1 1 1\\n\", \"6\\n2 2 1 1 3 3\\n4 3 5 5 2 1\\n\", \"3\\n1 2 3\\n3 3 3\\n\", \"1\\n5\\n4\\n\", \"10\\n1 1 3 4 5 6 7 8 9 10\\n10 10 4 2 3 4 2 2 2 2\\n\", \"20\\n24 15 7 18 6 18 11 22 18 20 28 8 23 17 22 22 23 23 30 23\\n24 137 173 189 43 164 2 11 142 153 16 200...
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In total the table Arthur bought has n legs, the length of the i-th leg is li. Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number di β€” the a...
0.125
{"tests": "{\"inputs\": [\"1\\n1 1\\n\", \"2\\n1 1\\n1 2\\n2 1\\n2 2\\n\", \"2\\n1 2\\n2 2\\n2 1\\n1 1\\n\", \"2\\n1 1\\n2 2\\n1 2\\n2 1\\n\", \"3\\n2 2\\n1 2\\n3 2\\n3 3\\n1 1\\n2 3\\n1 3\\n3 1\\n2 1\\n\", \"9\\n4 5\\n2 3\\n8 3\\n5 6\\n9 3\\n4 4\\n5 4\\n4 7\\n1 7\\n8 4\\n1 4\\n1 5\\n5 7\\n7 8\\n7 1\\n9 9\\n8 7\\n7 5\\...
City X consists of n vertical and n horizontal infinite roads, forming n Γ— n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphal...
0.875
{"tests": "{\"inputs\": [\"5\\n20 30 10 50 40\\n\", \"4\\n200 100 100 200\\n\", \"10\\n103 101 103 103 101 102 100 100 101 104\\n\", \"20\\n990 994 996 999 997 994 990 992 990 993 992 990 999 999 992 994 997 990 993 998\\n\", \"100\\n1 8 3 8 10 8 5 3 10 3 5 8 4 5 5 5 10 3 6 6 6 6 6 7 2 7 2 4 7 8 3 8 7 2 5 6 1 5 5 7 9 7...
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while pa...
0
{"tests": "{\"inputs\": [\"1 2\\n-1\\n?\\n\", \"2 100\\n-10000\\n0\\n1\\n\", \"4 5\\n?\\n1\\n?\\n1\\n?\\n\", \"5 3\\n?\\n?\\n?\\n?\\n?\\n?\\n\", \"4 4\\n?\\n?\\n?\\n?\\n?\\n\", \"17 10\\n3\\n6\\n0\\n0\\n0\\n0\\n0\\n0\\n7\\n9\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n1\\n\", \"2 0\\n?\\n1\\n?\\n\", \"7 10000\\n0\\n0\\n0\\n0\\n0\\n0...
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet. The following game was chosen for the fights: initially there is a polynom...
0
{"tests": "{\"inputs\": [\"5 3\\n1\\n2\\n2\\n3\\n3\\n\", \"6 4\\n3\\n3\\n3\\n4\\n4\\n2\\n\", \"10 3\\n-55\\n-35\\n-80\\n91\\n-96\\n-93\\n-39\\n-77\\n4\\n29\\n\", \"10 3\\n-6\\n2\\n79\\n-49\\n86\\n13\\n-31\\n-71\\n57\\n93\\n\", \"10 3\\n-38\\n68\\n-77\\n57\\n-35\\n28\\n-61\\n-9\\n3\\n60\\n\", \"10 3\\n-20\\n-63\\n-64\\n...
Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in <image>, which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find t...
0.75
{"tests": "{\"inputs\": [\"5 2\\ncba\\nabc\\nbb1\\nabC\\nABC\\nabc\\n\", \"4 100\\n11\\n22\\n1\\n2\\n22\\n\", \"2 1\\n1\\n12\\n12\\n\", \"4 2\\na\\nb\\naa\\nbb\\naa\\n\", \"10 2\\na\\nb\\nc\\nd\\nee\\nff\\ngg\\nhh\\nii\\njj\\nii\\n\", \"6 4\\na\\nb\\nc\\nbb\\nbc\\ncc\\ncc\\n\", \"2 1\\nab\\nabc\\nab\\n\", \"4 2\\n1\\n2...
Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration. Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrar...
0
{"tests": "{\"inputs\": [\"5\\n1 5 3 2 4\\n\", \"3\\n4 1 2\\n\", \"4\\n2 3 4 8\\n\", \"7\\n3 150 900 4 500 1500 5\\n\", \"6\\n1 1 1 4 5 100\\n\", \"11\\n1 2 5 6 7 8 9 17 18 19 100\\n\", \"8\\n2 3 5 5 5 6 6 13\\n\", \"5\\n5761 20966 27841 28800 29399\\n\", \"3\\n1 1 1\\n\", \"10\\n1 10 100 1000 10000 100000 1000000 1000...
Mahmoud has n line segments, the i-th of them has length ai. Ehab challenged him to use exactly 3 line segments to form a non-degenerate triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check ...
0.75
{"tests": "{\"inputs\": [\"..-**-..\\n..-**-..\\n..-..-..\\n..-..-..\\n..-..-..\\n..-..-..\\n\", \"**-**-**\\n**-**-**\\n..-**-.*\\n**-**-**\\n..-..-..\\n..-**-..\\n\", \"**-**-*.\\n*.-*.-**\\n**-**-**\\n**-**-**\\n..-..-..\\n..-**-..\\n\", \"**-.*-**\\n**-**-**\\n**-**-*.\\n**-*.-**\\n**-**-**\\n**-*.-**\\n\", \"**-**...
A classroom in a school has six rows with 3 desks in each row. Two people can use the same desk: one sitting on the left and one sitting on the right. Some places are already occupied, and some places are vacant. Petya has just entered the class and wants to occupy the most convenient place. The conveniences of the p...
0
{"tests": "{\"inputs\": [\"yeee\\n\", \"zzcxx\\n\", \"ababa\\n\", \"a\\n\", \"abbbc\\n\", \"aa\\n\", \"abcc\\n\", \"adb\\n\", \"aabcdef\\n\", \"ssab\\n\", \"aaabbbccc\\n\", \"bbbba\\n\", \"aaaaaaabbbbbbcder\\n\", \"abca\\n\", \"aabbcc\\n\", \"abc\\n\", \"abbc\\n\", \"ccdd\\n\", \"aabbccddee\\n\", \"abcdaaaa\\n\", \"ab\...
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others β€” a gr...
0
{"tests": "{\"inputs\": [\"7 3\\n3 14 15 92 65 35 89\\n\", \"10 4\\n9 14 28 1 7 13 15 29 2 31\\n\", \"1 1\\n847523811295364\\n\", \"4 2\\n162835105872970 116592879151848 139965176195127 395498533500931\\n\", \"16 7\\n1103813397013349 727264530801741 378049079598082 630901233315595 518569339136212 532452143552615 428093...
Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the ne...
0
{"tests": "{\"inputs\": [\"6 727202214173249351\\n6 5 2 5 3 2\", \"4 5\\n3 2 4 1\", \"6 727202214173249351\\n6 5 1 5 3 2\", \"4 9\\n3 2 4 1\", \"6 1007784494318310970\\n6 5 2 5 3 2\", \"6 237500909755776657\\n6 4 1 5 3 2\", \"6 727202214173249351\\n4 5 2 5 3 2\", \"6 165759462200935729\\n4 5 2 5 3 2\", \"6 727202214173...
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
0.875
{"tests": "{\"inputs\": [\"2 2 10\\n1 2 100\\n2 2 100\", \"4 5 10\\n1 2 1\\n1 4 1\\n3 4 1\\n2 2 100\\n3 3 100\", \"3 3 10\\n1 2 20\\n2 3 30\\n1 3 45\", \"4 5 10\\n1 2 1\\n1 4 1\\n2 4 1\\n2 2 100\\n3 3 100\", \"2 1 10\\n1 2 100\\n2 2 100\", \"4 5 10\\n1 2 1\\n1 4 1\\n3 4 1\\n2 2 101\\n3 3 100\", \"3 3 10\\n1 2 20\\n2 3 ...
There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N. We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for V...
0.375
{"tests": "{\"inputs\": [\"4\", \"3\", \"2\", \"1\", \"-1\", \"-2\", \"-4\", \"-3\", \"-8\", \"-16\", \"-10\", \"-5\", \"-6\", \"-7\", \"-15\", \"-28\", \"-18\", \"-20\", \"5\", \"7\", \"8\", \"11\", \"-12\", \"-11\", \"9\", \"20\", \"-14\", \"-27\", \"-23\", \"12\", \"13\", \"-17\", \"-13\", \"-24\", \"-9\", \"-21\", ...
You are given an integer N. Determine if there exists a tuple of subsets of \\{1,2,...N\\}, (S_1,S_2,...,S_k), that satisfies the following conditions: * Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k. * Any two of the sets S_1,S_2,...,S_k have exactly one element in common. ...
0
{"tests": "{\"inputs\": [\"1222\", \"3242\", \"0290\", \"2364\", \"1114\", \"2005\", \"1455\", \"1152\", \"3246\", \"6120\", \"2768\", \"1183\", \"1024\", \"1181\", \"1785\", \"1372\", \"1765\", \"1280\", \"2308\", \"1824\", \"2162\", \"1802\", \"1226\", \"2412\", \"1699\", \"4212\", \"2632\", \"2195\", \"1732\", \"491...
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given in...
0.875
{"tests": "{\"inputs\": [\"3\\n10\\n10\\n15\", \"3\\n10\\n20\\n30\", \"3\\n5\\n10\\n15\", \"3\\n4\\n10\\n15\", \"3\\n10\\n20\\n40\", \"3\\n5\\n10\\n12\", \"3\\n8\\n10\\n15\", \"3\\n7\\n20\\n40\", \"3\\n5\\n10\\n8\", \"3\\n1\\n10\\n15\", \"3\\n7\\n34\\n40\", \"3\\n5\\n10\\n10\", \"3\\n7\\n38\\n40\", \"3\\n5\\n10\\n19\",...
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 are answered correctly. When...
0.875
{"tests": "{\"inputs\": [\"4\\n1 7 14 47\\n2 5 35 55\\n3 6 3 59\\n4 6 5 15\\n10 15 50 400\\n2\\n1 8 10 78\\n2 4 18 33\\n10 10 50 300\\n0\", \"4\\n1 7 14 47\\n2 5 35 55\\n3 6 3 59\\n4 6 5 15\\n10 15 50 110\\n2\\n1 8 10 78\\n2 4 18 33\\n10 10 50 300\\n0\", \"4\\n1 7 14 47\\n2 7 35 55\\n3 6 3 78\\n4 2 7 15\\n10 15 50 110\...
Food contains three nutrients called "protein", "fat" and "carbohydrate", which are called three major nutrients. It is calculated that protein and carbohydrate are 4 kcal (kilocalories) and fat is 9 kcal per 1 g (gram). For example, according to the table below, the number 1 cake contains 7 g of protein, 14 g of fat a...
0.75
{"tests": "{\"inputs\": [\"4 5\\n20 35 60 70\\n15 30 40 80 90\\n3 2\\n10 20 30\\n42 60\\n0 1\\n100\\n1 1\\n10\\n50\\n0 0\", \"4 5\\n20 35 60 70\\n15 30 40 80 91\\n3 2\\n10 20 30\\n42 60\\n0 1\\n100\\n1 1\\n10\\n50\\n0 0\", \"4 5\\n20 35 60 70\\n15 30 40 80 170\\n3 2\\n10 20 30\\n42 60\\n0 1\\n100\\n1 1\\n10\\n50\\n0 0\...
There are two cameras which observe the up line and the down line respectively on the double lane (please see the following figure). These cameras are located on a line perpendicular to the lane, and we call the line 'monitoring line.' (the red line in the figure) <image> Monitoring systems are connected to the cam...
0
{"tests": "{\"inputs\": [\"48 3 3\\ngAY4I4wA\\ngIIgIIgg\\nw4IAYAg4\\ng\\ng\\nw\\n153 3 3\\nkkkkkkkkkkkkkkkkkkkkkkkkkg\\nSSSSSSSSSSSSSSSSSSSSSSSSSQ\\nJJJJJJJJJJJJJJJJJJJJJJJJJI\\ng\\nQ\\nI\\n1 1 2\\nA\\nA\\nA\\n384 3 2\\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\\nBCDEFGHIJKLMNOPQRSTUVWXYZabcdefgh...
Do you know the famous series of children's books named "Where's Wally"? Each of the books contains a variety of pictures of hundreds of people. Readers are challenged to find a person called Wally in the crowd. We can consider "Where's Wally" as a kind of pattern matching of two-dimensional graphical images. Wally's ...
0.625