info stringlengths 120 50k | question stringlengths 504 10.4k | avg@8_qwen3_4b_instruct_2507 float64 0 0.88 |
|---|---|---|
{"tests": "{\"inputs\": [\"7\\n0010101\\n1 2\\n2 3\\n1 4\\n4 5\\n1 6\\n6 7\", \"7\\n0010110\\n1 2\\n2 3\\n1 4\\n4 5\\n1 6\\n6 7\", \"2\\n01\\n1 2\", \"2\\n01\\n2 2\", \"7\\n0011101\\n1 2\\n2 3\\n1 4\\n4 5\\n1 6\\n6 7\", \"7\\n0111101\\n1 2\\n2 3\\n1 4\\n4 5\\n1 6\\n6 7\", \"7\\n0110110\\n1 1\\n2 3\\n1 4\\n1 5\\n2 6\\n6... | You are given a tree with N vertices numbered 1, 2, ..., N. The i-th edge connects Vertex a_i and Vertex b_i. You are also given a string S of length N consisting of `0` and `1`. The i-th character of S represents the number of pieces placed on Vertex i.
Snuke will perform the following operation some number of times:... | 0 |
{"tests": "{\"inputs\": [\"3\\n2 5\\n4 6\\n1 4\", \"5\\n123456 789012\\n123 456\\n12 345678901\\n123456 789012\\n1 23\", \"3\\n1 3\\n5 7\\n1 3\", \"1\\n1 400\", \"5\\n999999999 1000000000\\n1 2\\n314 315\\n500000 500001\\n999999999 1000000000\", \"3\\n2 5\\n4 6\\n2 4\", \"5\\n123456 789012\\n17 456\\n12 345678901\\n123... | AtCoDeer the deer found N rectangle lying on the table, each with height 1. If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i], as shown in the following figure:
<image>
AtCoDeer will move these rect... | 0 |
{"tests": "{\"inputs\": [\"ABAABBBAABABAAABBAA\\nAABBBABBABBAAABABABAAB\\nBABAABAABABABBAAAB\\nAABABAAABBAABBBABAA\\nAAAAAAAAAAA\\nABBBBBBBBBB\\n0\", \"AABBAAABABAABBBAABA\\nAABBBABBABBAAABABABAAB\\nBABAABAABABABBAAAB\\nAABABAAABBAABBBABAA\\nAAAAAAAAAAA\\nABBBBBBBBBB\\n0\", \"ABAABBBAABABAAABBAA\\nAABBBABBABBAAABABABAA... | It's been a while since I played with A, B, and C. Mr. A and Mr. B became players, and Mr. C became a referee and played a badminton singles game. The rules decided by the three people are as follows.
* 3 Play the game.
* The person who gets 11 points first wins the game.
* The first serve of the first game starts wit... | 0 |
{"tests": "{\"inputs\": [\"8\\n6 2 1 3 8 5 4 7\", \"5\\n1 5 3 2 4\", \"7\\n1 2 3 4 5 6 7\", \"4\\n1 4 2 3\", \"7\\n1 2 5 4 3 6 7\", \"4\\n2 4 2 2\", \"4\\n1 4 3 2\", \"7\\n1 3 2 4 5 6 7\", \"4\\n3 4 1 2\", \"8\\n7 2 1 3 8 5 4 6\", \"7\\n1 2 8 1 3 6 7\", \"5\\n2 5 3 1 4\", \"8\\n5 2 1 3 8 6 4 7\", \"7\\n2 1 5 4 3 6 7\",... | Taro has decided to move. Taro has a lot of luggage, so I decided to ask a moving company to carry the luggage. Since there are various weights of luggage, I asked them to arrange them in order from the lightest one for easy understanding, but the mover left the luggage in a different order. So Taro tried to sort the l... | 0.125 |
{"tests": "{\"inputs\": [\"HEISEI 1 1 8\\nHEISEI 31 4 30\\nHEISEI 31 5 1\\nHEISEI 99 12 31\\nHEISEI 38 8 30\\nHEISEI 98 2 22\\nHEISEI 2 3 26\\nHEISEI 28 4 23\\n#\", \"HEISEI 1 1 8\\nHEISEI 31 4 30\\nIESIEH 31 5 1\\nHEISEI 99 12 31\\nHEISEI 38 8 30\\nHEISEI 98 2 22\\nHEISEI 2 3 26\\nHEISEI 28 4 23\\n#\", \"HEISEI 1 1 8\... | Revised
The current era, Heisei, will end on April 30, 2019, and a new era will begin the next day. The day after the last day of Heisei will be May 1, the first year of the new era.
In the system developed by the ACM-ICPC OB / OG Association (Japanese Alumni Group; JAG), the date uses the Japanese calendar (the Japa... | 0.25 |
{"tests": "{\"inputs\": [\"abaabbabaabaabbabbabaabbab\\nab\", \"AABABCAC\\nA\", \"AbCdEfG\\naBcDeFg\", \"abaabbabaab`abbabbabaabbab\\nab\", \"AABABCAC\\nB\", \"AbCdEfG\\naBcDeFh\", \"abaabbbbaab`abbabbabaabaab\\nab\", \"AACABCAC\\nB\", \"AbGdEfC\\naBcDeFh\", \"abaabbbbaab`abbabbabaabaab\\n`b\", \"AACABCAC\\nC\", \"AbGd... | Problem
Given the strings $ s $, $ t $.
First, let the string set $ A = $ {$ s $}, $ B = \ phi $.
At this time, I want to perform the following operations as much as possible.
operation
step1
Perform the following processing for all $ u ∊ A $.
1. From all subsequences of $ u $ (not necessarily contiguous), choose ... | 0.5 |
{"tests": "{\"inputs\": [\"4\\n1 1 1 1\\n\", \"3\\n2 1 1\\n\", \"1\\n1\\n\", \"1\\n0\\n\", \"1\\n2\\n\", \"4\\n1 1 2 1\\n\", \"3\\n2 2 1\\n\", \"4\\n1 0 2 1\\n\", \"4\\n-2 1 5 0\\n\", \"1\\n-1\\n\", \"1\\n3\\n\", \"1\\n4\\n\", \"4\\n1 0 1 1\\n\", \"3\\n0 2 1\\n\", \"1\\n-2\\n\", \"1\\n6\\n\", \"3\\n0 4 1\\n\", \"1\\n-3... | The sequence of integers a_1, a_2, ..., a_k is called a good array if a_1 = k - 1 and a_1 > 0. For example, the sequences [3, -1, 44, 0], [1, -99] are good arrays, and the sequences [3, 7, 8], [2, 5, 4, 1], [0] — are not.
A sequence of integers is called good if it can be divided into a positive number of good arrays.... | 0 |
{"tests": "{\"inputs\": [\"1\\na\\nb\\n\", \"8\\nbabbaabb\\nabababaa\\n\", \"4\\nabab\\naabb\\n\", \"10\\naaaaaaaaaa\\nbbbbbbbbbb\\n\", \"101\\nbabbbbabbbbaabbbbbbbabbbababababbbbbbbbabaababbababbaaabbababbbbbbbbbaabbbababbbbbabbbbbabbbaabbbaabb\\nbbabbbbbbabbbbbbbbbbbabbbbbbbbbbabbabbbbbbbbbbbabbababbbabbabbbbbbbbbbbb... | Monocarp has got two strings s and t having equal length. Both strings consist of lowercase Latin letters "a" and "b".
Monocarp wants to make these two strings s and t equal to each other. He can do the following operation any number of times: choose an index pos_1 in the string s, choose an index pos_2 in the string... | 0 |
{"tests": "{\"inputs\": [\"15 4\\nabacabadabacaba\\n\", \"6 3\\naacabc\\n\", \"6 4\\naaaaaa\\n\", \"44 20\\nbcdefghijklmnopqrstabcdefghijklmnopqrstatata\\n\", \"44 20\\ncdefghijklmnopqrstabcdefghijklmnopqrstabtata\\n\", \"44 20\\natatbatsrqponmlkjihgfedcbatsrqponmlkjihgfedc\\n\", \"4 4\\naaaaaa\\n\", \"44 20\\natatbats... | You have a password which you often type — a string s of length n. Every character of this string is one of the first m lowercase Latin letters.
Since you spend a lot of time typing it, you want to buy a new keyboard.
A keyboard is a permutation of the first m Latin letters. For example, if m = 3, then there are six ... | 0 |
{"tests": "{\"inputs\": [\"4\\n3\\n1 1 3\\n4\\n1 1 2 1\\n2\\n11 11\\n1\\n100\\n\", \"1\\n12\\n2 2 2 2 1 2 2 2 2 2 2 2\\n\", \"1\\n1\\n1\\n\", \"1\\n3\\n1 1 2\\n\", \"1\\n1\\n2\\n\", \"4\\n3\\n1 1 3\\n4\\n1 1 2 1\\n2\\n11 14\\n1\\n100\\n\", \"4\\n3\\n1 1 3\\n4\\n1 1 2 2\\n2\\n11 9\\n1\\n100\\n\", \"4\\n3\\n2 1 3\\n4\\n1... | You are given some Tetris field consisting of n columns. The initial height of the i-th column of the field is a_i blocks. On top of these columns you can place only figures of size 2 × 1 (i.e. the height of this figure is 2 blocks and the width of this figure is 1 block). Note that you cannot rotate these figures.
Yo... | 0.125 |
{"tests": "{\"inputs\": [\"4\\n2 -1 7 3\\n2\\n2 4 -3\\n3 4 2\\n\", \"6\\n-9 -10 -9 -6 -5 4\\n3\\n2 6 -9\\n1 2 -10\\n4 6 -3\\n\", \"1\\n0\\n2\\n1 1 -1\\n1 1 -1\\n\", \"1\\n-101\\n1\\n1 1 5\\n\", \"1\\n-78\\n1\\n1 1 5\\n\", \"4\\n2 0 7 3\\n2\\n2 4 -3\\n3 4 2\\n\", \"6\\n-9 -10 -9 -6 -4 4\\n3\\n2 6 -9\\n1 2 -10\\n4 6 -3\\... | You are given a sequence of n integers a_1, a_2, …, a_n.
You have to construct two sequences of integers b and c with length n that satisfy:
* for every i (1≤ i≤ n) b_i+c_i=a_i
* b is non-decreasing, which means that for every 1<i≤ n, b_i≥ b_{i-1} must hold
* c is non-increasing, which means that for every 1<... | 0 |
{"tests": "{\"inputs\": [\"4\\n2\\n3 5 1 2\\n3\\n1 1 8 8 64 64\\n2\\n1 1 2 4\\n5\\n1 2 3 4 5 6 7 14 3 11\\n\", \"6\\n4\\n5 6 9 13 36 42 47 60\\n3\\n1 2 3 4 5 6\\n3\\n1 2 3 3 5 6\\n4\\n5 22 42 47 49 54 69 123\\n2\\n1 1 2 2\\n3\\n1000000 1000000 990000 10000 900000 90000\\n\", \"4\\n2\\n3 5 1 2\\n3\\n1 1 8 8 64 64\\n2\\n... | You found a useless array a of 2n positive integers. You have realized that you actually don't need this array, so you decided to throw out all elements of a.
It could have been an easy task, but it turned out that you should follow some rules:
1. In the beginning, you select any positive integer x.
2. Then you ... | 0 |
{"tests": "{\"inputs\": [\"10 10\\n+ 6\\n+ 10\\n+ 5\\n- 10\\n- 5\\n- 6\\n+ 10\\n+ 3\\n+ 6\\n+ 3\\n\", \"100 1\\n+ 51\\n\", \"100000 1\\n+ 12345\\n\", \"50 50\\n+ 14\\n+ 4\\n+ 20\\n+ 37\\n+ 50\\n+ 46\\n+ 19\\n- 20\\n+ 25\\n+ 47\\n+ 10\\n+ 6\\n+ 34\\n+ 12\\n+ 41\\n- 47\\n+ 9\\n+ 22\\n+ 28\\n- 41\\n- 34\\n+ 47\\n+ 40\\n- ... | By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated.
In 2312 there was a startling discovery:... | 0 |
{"tests": "{\"inputs\": [\"3\\n1 10\\n2 1\\n2 4\\n\", \"5\\n1 12\\n1 3\\n2 15\\n2 5\\n2 1\\n\", \"1\\n1 2\\n\", \"1\\n1 1\\n\", \"100\\n2 2\\n1 2\\n1 5\\n1 5\\n1 2\\n1 4\\n2 3\\n1 2\\n1 5\\n2 1\\n2 2\\n2 4\\n1 2\\n2 3\\n1 1\\n1 1\\n2 5\\n2 3\\n2 2\\n1 2\\n2 1\\n2 2\\n1 5\\n2 1\\n2 4\\n1 4\\n1 4\\n2 2\\n1 1\\n2 4\\n1 4\... | Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2. All books have the same page heights.
<image>
Shaass puts the books... | 0 |
{"tests": "{\"inputs\": [\"7\\n\", \"1\\n\", \"2\\n\", \"11\\n\", \"15\\n\", \"13\\n\", \"14\\n\", \"16\\n\", \"12\\n\", \"5\\n\", \"9\\n\", \"8\\n\", \"4\\n\", \"6\\n\", \"3\\n\", \"10\\n\"], \"outputs\": [\"0\", \"1\", \"0\", \"0\", \"1\", \"1\", \"0\", \"0\", \"0\", \"0\", \"1\", \"1\", \"1\", \"1\", \"0\", \"1\"]}"... | Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts:
... | 0 |
{"tests": "{\"inputs\": [\"4 2 10\\n17:05:53\\n17:05:58\\n17:06:01\\n22:39:47\\n\", \"1 2 86400\\n00:00:00\\n\", \"10 3 30000\\n00:06:54\\n00:42:06\\n03:49:45\\n04:38:35\\n05:33:30\\n05:51:46\\n10:46:34\\n14:34:59\\n14:40:06\\n14:53:13\\n\", \"1 1 86400\\n00:00:00\\n\", \"5 2 40000\\n06:30:57\\n07:27:25\\n09:10:21\\n11... | Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarp... | 0 |
{"tests": "{\"inputs\": [\"7\\n1 1 2 3 1 4\\n3 3 1 1 1 2 3\\n\", \"6\\n1 2 2 1 5\\n2 1 1 1 1 1\\n\", \"4\\n1 1 2\\n4 1 4 1\\n\", \"4\\n1 2 3\\n4 1 2 4\\n\", \"3\\n1 2\\n2 1 1\\n\", \"3\\n1 1\\n2 2 2\\n\", \"5\\n1 2 1 4\\n1 1 1 2 2\\n\", \"3\\n1 1\\n1 2 2\\n\", \"4\\n1 2 2\\n3 1 2 3\\n\", \"4\\n1 2 1\\n1 2 3 4\\n\", \"2... | You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex v by cv. Initially cv = 0.
You have to color the tree into the given colors using the smallest possible number of steps. On each step you can c... | 0.625 |
{"tests": "{\"inputs\": [\"2+2\\n\", \"112-37\\n\", \"8-7+6-5+4-3+2-1-0\\n\", \"131+49+249+71-251-61+159-111+51\\n\", \"150+222-3-90-248-187+198\\n\", \"0-0-0-0-0-0-0-0-0-0\\n\", \"240-120-234-156-207-189\\n\", \"23+6-9\\n\", \"101+200+195+231+107+222+146+254+160+209\\n\", \"5-9-1-3+6+4-7+8-2\\n\", \"1-2+3-4+5-6\\n\", ... | One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution...
Input
The only line of input data contains the arith... | 0 |
{"tests": "{\"inputs\": [\"2\\n3 \\n3\\n1 2 3 \\n2 4 8\\n4 \\n8\\n2 4 5 7\\n4 9 7 5\\n\\nSAMPLE\", \"2\\n3 \\n3\\n1 2 3 \\n2 4 5\\n4 \\n8\\n2 4 5 7\\n4 9 7 5\\n\\nSAMPLE\", \"2\\n3 \\n3\\n1 2 3 \\n2 4 5\\n4 \\n7\\n2 4 5 7\\n4 9 14 5\\n\\nSAMPLE\", \"2\\n3 \\n3\\n1 2 3 \\n2 4 5\\n4 \\n7\\n2 4 5 7\\n4 16 ... | "RMS Lusitania" was one of the world biggest ship of her time.On the outbreak of the First World War in 1914, she was commandeered by the Admiralty as an armed merchant cruiser. When Lusitania left New York for Liverpool on what would be her final voyage on 1 May 1915, submarine warfare was intensifying in the Atlantic... | 0.125 |
{"tests": "{\"inputs\": [\"3 3\\n...\\n...\\n...\", \"2 2\\n#.\\n.#\", \"2 4\\n...\\n...#\", \"6 7\\n.......\\n.......\\n.#.....\\n..#....\\n.#.#...\\n.......\", \"2 2\\n.\\n.#\", \"3 2\\n...\\n...\\n...\", \"2 1\\n#.\\n.#\", \"1 4\\n...\\n...#\", \"2 2\\n..-\\n...\\n...\", \"4 3\\n...\\n...\\n...\", \"2 8\\n...\\n...#... | We have an H \times W grid, where each square is painted white or black in the initial state. Given are strings A_1, A_2, ..., A_H representing the colors of the squares in the initial state. For each pair (i, j) (1 \leq i \leq H, 1 \leq j \leq W), if the j-th character of A_i is `.`, the square at the i-th row and j-t... | 0 |
{"tests": "{\"inputs\": [\"2 1 1 0 0 0 0\", \"0 0 10 0 0 0 0\", \"0 0 10 0 1 0 0\", \"1 1 1 0 0 0 0\", \"0 0 -1 0 2 0 2\", \"4 0 1 0 0 0 0\", \"0 3 0 0 1 0 0\", \"0 3 0 0 2 0 0\", \"6 0 2 0 0 0 0\", \"11 0 2 0 0 0 0\", \"14 0 2 0 0 0 0\", \"2 5 1 0 1 2 2\", \"23 0 2 0 0 0 0\", \"1 4 0 0 4 0 3\", \"1 0 0 1 7 -1 2\", \"1... | A tetromino is a figure formed by joining four squares edge to edge. We will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively:
a60bcb8e9e8f22e3af51049eda063392.png
Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and Z-tetrominos in his possession... | 0 |
{"tests": "{\"inputs\": [\"5 5\\n.....\\n.#.#.\\n.....\\n.#.#.\\n.....\", \"7 13\\n.............\\n.###.###.###.\\n.#.#.#...#...\\n.###.#...#...\\n.#.#.#.#.#...\\n.#.#.###.###.\\n.............\", \"5 5\\n.....\\n.#.#.\\n.....\\n.#.#.\\n.../.\", \"7 13\\n.............\\n.###.###.###.\\n.#.#.#...#...\\n.###.#...#...\\n..... | Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.
Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically ... | 0 |
{"tests": "{\"inputs\": [\"3 4\\n4 4\\n0 0\", \"3 1\\n4 4\\n0 0\", \"3 1\\n6 4\\n0 0\", \"3 4\\n4 1\\n0 0\", \"3 1\\n4 2\\n0 0\", \"3 2\\n6 4\\n0 0\", \"3 7\\n4 1\\n0 0\", \"4 4\\n4 1\\n0 0\", \"4 1\\n4 2\\n0 0\", \"3 7\\n7 1\\n0 0\", \"4 1\\n6 4\\n0 0\", \"4 1\\n4 1\\n0 0\", \"4 1\\n10 4\\n0 0\", \"4 4\\n9 1\\n0 0\", ... | A tatami mat, a Japanese traditional floor cover, has a rectangular form with aspect ratio 1:2. When spreading tatami mats on a floor, it is prohibited to make a cross with the border of the tatami mats, because it is believed to bring bad luck.
Your task is to write a program that reports how many possible ways to sp... | 0 |
{"tests": "{\"inputs\": [\"2 3\\n4 0\\n0 0\\n2 3\\n2 -2\\n3 1\", \"2 2\\n0 0\\n1 1\\n2 0\\n2 -1\", \"5 2\\n-2 1\\n1 2\\n-1 3\\n-1 5\\n1 4\\n0 4\\n0 0\", \"2 3\\n4 0\\n-1 0\\n2 3\\n2 -2\\n3 1\", \"2 2\\n0 0\\n1 2\\n2 0\\n2 -1\", \"5 2\\n-2 0\\n1 2\\n-1 3\\n-1 5\\n1 4\\n0 4\\n0 0\", \"2 3\\n2 2\\n-2 0\\n4 3\\n2 -2\\n-1 1... | The Kingdom of Neva is home to two ethnic groups, the Totata and the Tutete. The biggest feature of the Totata tribe is that they eat sweet and sour pork with pineapple. However, the Tutete tribe eats vinegared pork in pineapple. These two peoples couldn't get along with each other, and the Totata and Tutete have been ... | 0 |
{"tests": "{\"inputs\": [\"1 1\\n0 2\\n1\", \"1 1\\n0 4\\n1\", \"2 1\\n0 4\\n1\", \"0 1\\n0 4\\n0\", \"2 1\\n0 4\\n2\", \"3 1\\n0 8\\n0\", \"3 1\\n0 8\\n2\", \"3 1\\n0 8\\n3\", \"1 1\\n0 8\\n1\", \"1 1\\n-1 3\\n1\", \"2 1\\n0 4\\n0\", \"1 1\\n0 2\\n0\", \"1 1\\n-2 2\\n1\", \"0 1\\n0 8\\n0\", \"0 1\\n0 1\\n0\", \"0 2\\n... | This year too, the time has come for the National Programming Championships. In the district tournament where the right to participate in the national tournament is bet, 2n teams will face each other in a one-on-one winning tournament system.
Team numbers 0, .. .2n − 1 are assigned to the tournament table, and the con... | 0 |
{"tests": "{\"inputs\": [\"5 2\\n1 2\\n2 1\", \"5 2\\n1 2\\n2 2\", \"3 2\\n1 2\\n2 1\", \"3 2\\n1 2\\n3 1\", \"6 2\\n1 2\\n2 1\", \"9 2\\n1 2\\n2 4\", \"6 2\\n1 1\\n2 1\", \"17 2\\n1 2\\n2 4\", \"4 2\\n2 2\\n3 1\", \"26 2\\n2 2\\n4 4\", \"12 2\\n2 2\\n4 4\", \"1 0\\n2 2\\n1 1\", \"17 2\\n1 2\\n2 1\", \"7 1\\n2 1\\n3 0\... | problem
There are $ N $ propositions, named $ 1, 2, \ cdots, N $, respectively. Also, $ M $ information about the propositions is given. The $ i $ th information is "$ a_i $$". Given in the form "b_i $", which means that $ a_i $ is $ b_i $. ("If" is a logical conditional and the transition law holds.) $ For each propo... | 0 |
{"tests": "{\"inputs\": [\"4 3 2 2\\n3 1 3 2\\n1 2\\n2 3\\n4 4\\n\", \"5 3 3 5\\n5 5 2 1 1\\n1 2\\n2 3\\n3 4\\n\", \"5 2 1 1\\n1 2 3 4 5\\n2 4\\n1 5\\n\", \"10 1 1 8\\n1 1 1 991992993 1 991992993 3 6664666 1000000000 999999999\\n3 10\\n\", \"10 5 4 10\\n1 2 3 4 5 6 7 8 9 10\\n3 8\\n4 7\\n5 6\\n1 10\\n2 9\\n\", \"1 5 2 ... | You are a given a list of integers a_1, a_2, …, a_n and s of its segments [l_j; r_j] (where 1 ≤ l_j ≤ r_j ≤ n).
You need to select exactly m segments in such a way that the k-th order statistic of the multiset of a_i, where i is contained in at least one segment, is the smallest possible. If it's impossible to select ... | 0 |
{"tests": "{\"inputs\": [\"2\\n5\\n9\\n6\\n10\\n9\\n10\\n2\\n99\\n\", \"2\\n5\\n1 2 3\\n2 3 4\\n2 4 5\\n4 5 1\\n2\\n1 2 99\\n\", \"2\\n5\\n1 3 3\\n2 3 4\\n2 4 5\\n4 5 1\\n2\\n1 2 99\\n\", \"2\\n5\\n9\\n12\\n10\\n9\\n10\\n2\\n99\\n\", \"2\\n5\\n17\\n12\\n10\\n9\\n10\\n2\\n99\\n\", \"2\\n5\\n1 3 4\\n2 3 4\\n2 4 5\\n4 5 0... | There is a weighted tree with n nodes and n-1 edges. The nodes are conveniently labeled from 1 to n. The weights are positive integers at most 100. Define the distance between two nodes to be the sum of edges on the unique path between the nodes. You would like to find the diameter of the tree. Diameter is the maximum ... | 0 |
{"tests": "{\"inputs\": [\"1 5\\n9 9 8 7 6 5 4 3 2 1\\n3 4 1 2 3 4\\n1 4 5 6 7 8\\n4 4 1 3 5 7\\n1 4 2 4 6 8\\n5 4 1 9 2 8\\n\", \"3 4\\n2 6 7\\n4 2 3 9 5\\n3 2 3 9\\n100 1 7\\n400 3 3 2 5\\n100 2 9 2\\n500 3 2 9 5\\n\", \"4 3\\n1 1\\n1 2\\n1 3\\n1 4\\n10 4 1 2 3 4\\n20 4 1 2 3 4\\n30 4 1 2 3 4\\n\", \"3 3\\n1 9\\n6 4 ... | A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9.
Each of the n friends has one or more favorite ingredients: the i-th of friends has the number of favorite ingredients equal to f_i (1 ≤ f_i ≤ 9) and y... | 0 |
{"tests": "{\"inputs\": [\"0111001100111011101000\\n\", \"0001111\\n\", \"110\\n\", \"010\\n\", \"0010000110000100\\n\", \"0000000000000000\\n\", \"0000100010001110\\n\", \"1111111111111111\\n\", \"0100000001000001\\n\", \"1001101000001101\\n\", \"1\\n\", \"0\\n\", \"1111111111111010\\n\", \"1111101000110110\\n\", \"00... | The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.
Kirk has a binary string s (a string which consists of zeroes and ones) of length n and he is asking you to find a binary string t of the same length which satisfies the following ... | 0 |
{"tests": "{\"inputs\": [\"4\\n\\na\\naa\\na\\n\\ncb\\nb\\nc\\n\\nc\", \"99\\nyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\\n\", \"4\\nabcd\\n\", \"100\\ntssttststtssttsssttsssttttttsttttssstssstsstssstststttssssstttsssttststststtttsssstsstsssssttttttsst\\n\", \"9\... | This problem is different with hard version only by constraints on total answers length
It is an interactive problem
Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of length n, consisting only of lowercase English letters. The player can ask tw... | 0 |
{"tests": "{\"inputs\": [\"3 2\\n2 3 2\\n3 1\\n2 1\\n\", \"5 2\\n1 1 1 1 1\\n1 2\\n1 3\\n\", \"5 1\\n1 1 1 1 1\\n2 5\\n\", \"5 2\\n1 1 1 1 1\\n1 2\\n1 4\\n\", \"5 1\\n1 1 1 1 1\\n1 3\\n\", \"5 1\\n1 2 3 2 1\\n1 2\\n\", \"5 5\\n1 1 1 1 1\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n\", \"2 1\\n2 2\\n1 1\\n\", \"5 2\\n1 1 1 1 1\\n1 1... | After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass!
On the field, there is a row of n units of grass, each with a sweetness s_i. Farmer John has m cows, each with a favorite sweetness f_i and a hunger value h_i. He would like to pick two disjoint subset... | 0 |
{"tests": "{\"inputs\": [\"2\\n3 2\\n7 6 3 5 4 2 1\\n3 2\\n7 6 5 4 3 2 1\\n\", \"2\\n3 2\\n7 6 3 5 4 2 1\\n3 2\\n7 6 5 4 3 2 1\\n\", \"2\\n3 2\\n7 6 3 5 4 2 1\\n3 2\\n14 6 5 4 3 2 1\\n\", \"2\\n3 1\\n7 6 3 5 4 2 1\\n3 2\\n14 6 5 4 3 2 1\\n\", \"2\\n3 2\\n7 6 3 5 4 2 1\\n3 1\\n23 6 5 4 3 2 1\\n\", \"2\\n3 1\\n7 6 3 5 4 ... | Drazil likes heap very much. So he created a problem with heap:
There is a max heap with a height h implemented on the array. The details of this heap are the following:
This heap contains exactly 2^h - 1 distinct positive non-zero integers. All integers are distinct. These numbers are stored in the array a indexed f... | 0 |
{"tests": "{\"inputs\": [\"5 5\\nzbacg\\nbaaac\\naaaaa\\neaaad\\nweadd\\n\", \"3 3\\naaa\\naaa\\naaa\\n\", \"3 4\\nabab\\nbaba\\nabab\\n\", \"1 1\\nn\\n\", \"3 4\\nabab\\nabab\\nabab\\n\", \"5 5\\nzbacg\\nbaaac\\naaaaa\\ndaaae\\nweadd\\n\", \"1 1\\nm\\n\", \"3 3\\naba\\naaa\\naaa\\n\", \"5 5\\nzbacf\\nbcaaa\\naaaaa\\ne... | Carousel Boutique is busy again! Rarity has decided to visit the pony ball and she surely needs a new dress, because going out in the same dress several times is a sign of bad manners. First of all, she needs a dress pattern, which she is going to cut out from the rectangular piece of the multicolored fabric.
The piec... | 0.625 |
{"tests": "{\"inputs\": [\"2\\n1 2\\n\", \"10\\n1 2 3 4 5 6 7 8 9 10\\n\", \"1\\n1\\n\", \"4\\n2 3 9 10\\n\", \"5\\n1000000000 100000000 10000000 1000000 100000\\n\", \"2\\n100 777777777777\\n\", \"2\\n2562991876 16\\n\", \"3\\n2 3 10\\n\", \"50\\n153423475 640900906 773155924 97361082 413127059 154467262 26144388 1726... | Furlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to:
* choose some pile, let's denote the current number of coins in it as x;
* choose some integer y (0 ≤ y < x; x1 / 4 ≤ y ≤ x1 / 2) a... | 0 |
{"tests": "{\"inputs\": [\"5\\n67 499 600 42 23\\n\", \"3\\n1 2 3\\n\", \"3\\n2 3 1\\n\", \"3\\n3 1 2\\n\", \"4\\n-227347 -573134 -671045 11011\\n\", \"1\\n-895376\\n\", \"5\\n834472 -373089 441294 -633071 -957672\\n\", \"2\\n7 8\\n\", \"3\\n-771740 -255752 -300809\\n\", \"2\\n166442 61629\\n\", \"3\\n3 1 1\\n\", \"4\\... | The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.
A subsequence is a sequence that can be... | 0 |
{"tests": "{\"inputs\": [\"1 2\\n2 8\\n1 16\\n\", \"4 9\\n1 2\\n2 1\\n1 1\\n2 2\\n1 2 3 4 5 6 7 8 9\\n\", \"3 3\\n2 8\\n5 1\\n10 5\\n13 16 62\\n\", \"10 10\\n3 1\\n2 7\\n5 1\\n7 2\\n9 10\\n9 5\\n2 5\\n4 10\\n9 9\\n1 9\\n26 34 37 141 146 201 239 245 296 299\\n\", \"2 3\\n500000000 1\\n1 500000000\\n499999999 500000000 5... | Eugeny loves listening to music. He has n songs in his play list. We know that song number i has the duration of ti minutes. Eugeny listens to each song, perhaps more than once. He listens to song number i ci times. Eugeny's play list is organized as follows: first song number 1 plays c1 times, then song number 2 plays... | 0.25 |
{"tests": "{\"inputs\": [\"5 4\\n1 2\\n2 3\\n3 4\\n4 1\\n\", \"3 2\\n1 2\\n2 3\\n\", \"8 7\\n1 2\\n2 3\\n4 5\\n5 6\\n6 8\\n8 7\\n7 4\\n\", \"6 5\\n6 3\\n4 1\\n2 1\\n2 5\\n4 5\\n\", \"5 4\\n4 2\\n2 5\\n1 5\\n1 4\\n\", \"6 2\\n2 4\\n5 1\\n\", \"7 4\\n5 4\\n2 6\\n2 3\\n6 3\\n\", \"2 1\\n1 2\\n\", \"7 3\\n5 1\\n3 7\\n2 4\\... | I have an undirected graph consisting of n nodes, numbered 1 through n. Each node has at most two incident edges. For each pair of nodes, there is at most an edge connecting them. No edge connects a node to itself.
I would like to create a new graph in such a way that:
* The new graph consists of the same number o... | 0 |
{"tests": "{\"inputs\": [\"1\\n\", \"123456789987654321\\n\", \"369727\\n\", \"123456789\\n\", \"3639272918194549\\n\", \"1212172727\\n\", \"1188\\n\", \"1212121217272727121\\n\", \"112131415161718192122232425262728293132333435363738394142434445464748495152535455657585961626364656676869717273747576778798182838485868788... | Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine ... | 0 |
{"tests": "{\"inputs\": [\"2 1\\n1 2\\n1 2 1\\n\", \"5 6\\n13 56 73 98 17\\n1 2 56\\n1 3 29\\n1 4 42\\n2 3 95\\n2 4 88\\n3 4 63\\n\", \"1 0\\n1\\n\", \"20 20\\n265918 744212 196368 74731 293587 679367 460805 632939 453630 565881 835276 606327 181087 721045 219431 849838 370939 582350 335676 32244\\n2 16 989\\n14 19 628... | DZY loves Physics, and he enjoys calculating density.
Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows:
<image> where v is the sum of the values of the nodes, e is the sum of the values of the edges.
Once DZY got a ... | 0 |
{"tests": "{\"inputs\": [\"4 6 2\\n1 2\\n2 3\\n3 4\\n4 1\\n1 3\\n2 4\\n\", \"3 3 2\\n1 2\\n2 3\\n1 3\\n\", \"4 6 3\\n1 2\\n2 3\\n3 4\\n4 1\\n1 3\\n2 4\\n\", \"10 25 9\\n10 8\\n9 10\\n6 9\\n8 5\\n1 7\\n4 7\\n5 3\\n8 6\\n9 2\\n10 1\\n7 2\\n7 10\\n3 1\\n9 5\\n4 10\\n7 3\\n5 7\\n2 5\\n6 1\\n4 8\\n2 4\\n8 7\\n8 2\\n2 6\\n5 ... | Life in Bertown has become hard. The city has too many roads and the government spends too much to maintain them. There are n junctions and m two way roads, at which one can get from each junction to any other one. The mayor wants to close some roads so that the number of roads left totaled to n - 1 roads and it were s... | 0 |
{"tests": "{\"inputs\": [\"1 1\\n\", \"1 42\\n\", \"6 4\\n\", \"10000 10000\\n\", \"5858 674\\n\", \"214 210\\n\", \"10000 9999\\n\", \"999 10000\\n\", \"620 35\\n\", \"10000 239\\n\", \"5 8\\n\", \"1307 3420\\n\", \"7 267\\n\", \"16 60\\n\", \"241 10000\\n\", \"238 9996\\n\", \"239 10000\\n\", \"42 1\\n\", \"106 6\\n\... | Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!
Let us remind you... | 0 |
{"tests": "{\"inputs\": [\"3 5\\n4 3\\n5 2\\n6 1\\n\", \"1 100\\n1 1\\n\", \"2 1\\n2 2\\n2 1000\\n\", \"20 16807\\n75250 50074\\n43659 8931\\n11273 27545\\n50879 77924\\n37710 64441\\n38166 84493\\n43043 7988\\n22504 82328\\n31730 78841\\n42613 44304\\n33170 17710\\n97158 29561\\n70934 93100\\n80279 51817\\n95336 99098... | You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a si... | 0.5 |
{"tests": "{\"inputs\": [\"8 1 1\\n2 2 1\\n3 3 1\\n3 1 3\\n1 1 1\\n2 1 1\\n1 2 3\\n\", \"10 2 1\\n1 1 1\\n1 1 1\\n1 1 1\\n2 2 2\\n2 2 2\\n2 2 2\\n\", \"5 1 1\\n1 2 2\\n2 2 2\\n2 2 2\\n1 2 2\\n2 2 2\\n2 2 2\\n\", \"1000000000000000000 2 3\\n1 3 1\\n2 3 3\\n2 2 2\\n1 2 3\\n3 1 2\\n2 2 2\\n\", \"1 3 1\\n1 3 3\\n2 3 2\\n2 ... | Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice".
... | 0.125 |
{"tests": "{\"inputs\": [\"5 3\\n2 3 1\\n\", \"5 3\\n3 2 1\\n\", \"5 2\\n3 4\\n\", \"5 1\\n3\\n\", \"10 7\\n10 8 5 1 2 7 3\\n\", \"4 3\\n3 4 2\\n\", \"10 4\\n2 1 3 4\\n\", \"10 4\\n2 1 7 3\\n\", \"20 5\\n11 19 6 2 12\\n\", \"2 1\\n1\\n\", \"10 3\\n2 1 4\\n\", \"4 3\\n3 1 2\\n\", \"10 9\\n10 8 7 5 6 2 1 9 4\\n\", \"2000... | Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty).
You may perform the following operations until both a and s are empty:
* Take the first element of a, push it into s and remove it from a (if a is not empty);
* Take the top element from s, append it to the end ... | 0 |
{"tests": "{\"inputs\": [\"3\\n0 0 2\\n3 0 2\\n6 0 2\\n\", \"3\\n0 0 1\\n2 0 1\\n4 0 1\\n\", \"3\\n0 0 2\\n2 0 2\\n1 1 2\\n\", \"3\\n3 4 9\\n2 -3 1\\n-1 1 4\\n\", \"3\\n2 -5 2\\n-5 -6 3\\n-2 -2 3\\n\", \"3\\n-4 1 5\\n-7 7 10\\n-3 -4 8\\n\", \"3\\n5 -2 3\\n1 1 2\\n4 -3 7\\n\", \"3\\n-6 -6 7\\n1 4 2\\n0 -5 2\\n\", \"3\\n... | Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement.
Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve.
A wonder strikes Tommy. How many regions are formed by the circl... | 0 |
{"tests": "{\"inputs\": [\"3\\n1 2\\n2 3\", \"6\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\", \"8\\n1 2\\n2 3\\n2 4\\n2 5\\n4 7\\n5 6\\n6 8\", \"8\\n1 2\\n2 3\\n2 4\\n2 5\\n4 7\\n5 6\\n2 8\", \"8\\n1 2\\n2 3\\n2 4\\n4 5\\n4 7\\n5 6\\n2 8\", \"8\\n1 2\\n2 3\\n2 4\\n2 5\\n4 7\\n3 6\\n6 8\", \"8\\n1 2\\n2 3\\n2 4\\n2 5\\n4 7\\n3 6\\n5... | Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.
Among the colo... | 0.625 |
{"tests": "{\"inputs\": [\"6\\n5\\n3\\n4\\n1\\n2\\n6\", \"5\\n5\\n2\\n1\\n4\\n3\", \"4\\n3\\n2\\n4\\n1\", \"7\\n3\\n2\\n1\\n6\\n5\\n4\\n7\", \"6\\n5\\n3\\n8\\n1\\n2\\n6\", \"4\\n3\\n2\\n3\\n1\", \"6\\n5\\n3\\n8\\n1\\n2\\n3\", \"4\\n3\\n2\\n2\\n1\", \"6\\n4\\n3\\n8\\n1\\n2\\n3\", \"4\\n3\\n1\\n2\\n1\", \"4\\n6\\n1\\n2\\... | You are given a permutation of 1,2,...,N: p_1,p_2,...,p_N. Determine if the state where p_i=i for every i can be reached by performing the following operation any number of times:
* Choose three elements p_{i-1},p_{i},p_{i+1} (2\leq i\leq N-1) such that p_{i-1}>p_{i}>p_{i+1} and reverse the order of these three.
Cons... | 0 |
{"tests": "{\"inputs\": [\"4 15\\n1000000000 15\\n9 5\\n8 6\\n7 4\", \"4 15\\n0 15\\n2 5\\n3 6\\n4 4\", \"3 10\\n10 10\\n20 5\\n4 3\", \"4 15\\n1000000000 15\\n9 5\\n8 6\\n2 4\", \"4 15\\n0 15\\n2 5\\n3 6\\n3 4\", \"4 15\\n1100000000 15\\n9 5\\n8 6\\n2 4\", \"1 15\\n1100000000 15\\n9 5\\n8 6\\n2 4\", \"4 15\\n100000000... | You are in charge of controlling a dam. The dam can store at most L liters of water. Initially, the dam is empty. Some amount of water flows into the dam every morning, and any amount of water may be discharged every night, but this amount needs to be set so that no water overflows the dam the next morning.
It is know... | 0 |
{"tests": "{\"inputs\": [\"11\\n15\\n0\", \"11\\n23\\n0\", \"11\\n45\\n0\", \"11\\n77\\n0\", \"11\\n13\\n0\", \"11\\n17\\n0\", \"11\\n25\\n0\", \"11\\n37\\n0\", \"11\\n5\\n0\", \"11\\n69\\n0\", \"11\\n19\\n0\", \"11\\n21\\n0\", \"11\\n27\\n0\", \"11\\n11\\n0\", \"11\\n31\\n0\", \"11\\n33\\n0\", \"11\\n29\\n0\", \"11\\n... | A prime number n (11, 19, 23, etc.) that divides by 4 and has 3 has an interesting property. The results of calculating the remainder of the square of a natural number (1, 2, ..., n -1) of 1 or more and less than n divided by n are the same, so they are different from each other. The number is (n -1) / 2.
The set of n... | 0 |
{"tests": "{\"inputs\": [\"4 5 7 2\\n20\\n80\\n100\\n50\\n1 1\\n2 6\\n2 3\\n1 5\\n3 1\\n2 2 5 1\\n10\\n20\\n1 1\\n1 3\\n0 0 0 0\", \"4 5 7 2\\n20\\n80\\n100\\n50\\n1 1\\n2 6\\n2 3\\n1 5\\n3 1\\n2 2 5 1\\n10\\n19\\n1 1\\n1 3\\n0 0 0 0\", \"4 5 7 2\\n38\\n80\\n100\\n50\\n1 1\\n2 6\\n2 3\\n1 5\\n3 1\\n2 2 5 1\\n10\\n19\\n... | problem
You are playing with J using the Midakuji. The Amida lottery consists of n vertical bars and m horizontal bars. The vertical bars are numbered from 1 to n in order from the left, and the vertical bar i The positive integer si is written at the bottom of.
<image>
Figure 3-1 Example of Amidakuji (n = 4, m = 5,... | 0 |
{"tests": "{\"inputs\": [\"3 1\\n1\\n2\\n3\", \"5 3\\n9\\n2\\n6\\n8\\n8\", \"5 7\\n9\\n9\\n9\\n1\\n5\", \"3 0\\n1\\n2\\n3\", \"5 3\\n9\\n1\\n6\\n8\\n8\", \"5 8\\n9\\n9\\n9\\n1\\n5\", \"3 1\\n1\\n2\\n6\", \"5 2\\n9\\n1\\n6\\n8\\n8\", \"6 2\\n9\\n1\\n6\\n8\\n8\", \"5 8\\n14\\n9\\n9\\n1\\n5\", \"6 2\\n9\\n1\\n6\\n11\\n9\"... | Honestly, a rabbit does not matter.
There is a rabbit playing a stage system action game. In this game, every stage has a difficulty level. The rabbit, which always needs challenges, basically wants to play more difficult stages than he has ever played. However, he sometimes needs rest too. So, to compromise, he admit... | 0 |
{"tests": "{\"inputs\": [\"3 3 2\\n1 2\\n2 3\\n3 1\", \"3 3 1\\n1 2\\n2 3\\n3 1\", \"3 3 3\\n1 2\\n2 3\\n3 1\", \"6 1 2\\n1 3\\n2 6\\n4 1\", \"6 0 1\\n1 2\\n1 3\\n5 1\", \"6 3 1\\n1 2\\n2 3\\n3 1\", \"6 3 1\\n1 2\\n2 3\\n5 1\", \"6 3 1\\n1 2\\n4 3\\n5 1\", \"3 3 0\\n1 2\\n2 3\\n3 1\", \"9 3 1\\n1 2\\n2 3\\n3 1\", \"6 3... | D - Medical Inspection
Problem Statement
The government has declared a state of emergency due to the MOFU syndrome epidemic in your country. Persons in the country suffer from MOFU syndrome and cannot get out of bed in the morning. You are a programmer working for the Department of Health. You have to take prompt mea... | 0.25 |
{"tests": "{\"inputs\": [\"4 2 2\\n1 2\\n2 4\\n3 1\\n4 2\\n1 3\", \"4 2 2\\n1 2\\n2 4\\n3 1\\n4 2\\n1 4\", \"4 1 2\\n1 2\\n2 4\\n0 1\\n4 2\\n1 -1\", \"4 0 1\\n1 2\\n2 6\\n0 1\\n4 2\\n2 -1\", \"4 2 2\\n1 2\\n2 4\\n0 1\\n4 2\\n1 4\", \"4 2 2\\n1 2\\n2 4\\n0 1\\n4 2\\n1 0\", \"4 2 2\\n1 2\\n2 4\\n0 1\\n4 2\\n1 -1\", \"4 1... | A pitch-black room
When I woke up, Mr. A was in a pitch-black room. Apparently, Mr. A got lost in a dungeon consisting of N rooms. You couldn't know which room A got lost in, but fortunately he got a map of the dungeon. Let's show A the way to go and lead to a bright room.
It is known that M of the N rooms are pitch ... | 0 |
{"tests": "{\"inputs\": [\"4\\n1 2\\n1 3\\n2 4\\n1 2 4 3\\n\", \"4\\n1 2\\n1 3\\n2 4\\n1 2 3 4\\n\", \"4\\n1 2\\n1 3\\n1 4\\n2 1 3 4\\n\", \"4\\n2 3\\n3 4\\n4 1\\n2 3 4 1\\n\", \"6\\n1 2\\n1 5\\n2 3\\n2 4\\n5 6\\n1 2 5 3 4 6\\n\", \"4\\n1 2\\n1 3\\n2 4\\n4 2 1 3\\n\", \"2\\n1 2\\n2 1\\n\", \"8\\n1 2\\n1 6\\n1 7\\n8 2\\... | The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows.
1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue](http://gg.gg/queue_en) containing only vertex 1, mark the vertex 1 as used.
2. Extract a vertex v from the head of the qu... | 0.625 |
{"tests": "{\"inputs\": [\"5\\n1\\n0\\n1\\n0\\n1\\n\", \"9\\n1\\n1\\n0\\n0\\n0\\n1\\n1\\n0\\n1\\n\", \"3\\n1\\n1\\n1\\n\", \"3\\n0\\n0\\n0\\n\", \"2\\n1\\n0\\n\", \"15\\n1\\n0\\n0\\n1\\n0\\n0\\n0\\n0\\n1\\n1\\n1\\n1\\n1\\n0\\n0\\n\", \"30\\n1\\n0\\n1\\n0\\n1\\n1\\n0\\n1\\n1\\n0\\n1\\n0\\n1\\n1\\n0\\n0\\n1\\n0\\n0\\n0\\... | In Morse code, an letter of English alphabet is represented as a string of some length from 1 to 4. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and a dash with a "1".
Because there are 2^1+2^2+2^3+2^4 = 30 strings with le... | 0 |
{"tests": "{\"inputs\": [\"6 7 13 22\\n1 2 13\\n2 3 13\\n1 4 22\\n3 4 13\\n4 5 13\\n5 6 13\\n6 1 13\\n\", \"5 5 20 25\\n1 2 25\\n2 3 25\\n3 4 20\\n4 5 20\\n5 1 20\\n\", \"3 2 509529 5982470\\n1 2 509529\\n3 2 509529\\n\", \"3 2 451715 1577270\\n1 3 1577270\\n1 2 1577270\\n\", \"2 1 1 2\\n2 1 1\\n\", \"3 2 150319 500296... | Codefortia is a small island country located somewhere in the West Pacific. It consists of n settlements connected by m bidirectional gravel roads. Curiously enough, the beliefs of the inhabitants require the time needed to pass each road to be equal either to a or b seconds. It's guaranteed that one can go between any... | 0 |
{"tests": "{\"inputs\": [\"aaaaa\\n3\\n1 1\\n2 4\\n5 5\\n\", \"aabbbbbbc\\n6\\n1 2\\n2 4\\n2 2\\n1 9\\n5 7\\n3 5\\n\", \"abca\\n1\\n1 4\\n\", \"f\\n1\\n1 1\\n\", \"aaaaa\\n3\\n1 1\\n2 4\\n1 5\\n\", \"e\\n1\\n1 1\\n\", \"aabbbbbbc\\n6\\n1 1\\n2 4\\n2 2\\n1 9\\n5 7\\n3 5\\n\", \"aaaaa\\n3\\n1 2\\n1 5\\n1 5\\n\", \"aaaaa\... | Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k ≥ 2 and 2k non-empty strings s_1, t_1, s_... | 0 |
{"tests": "{\"inputs\": [\"6 3\\n2 2 2\\n3 1\\n5 4\\n2 5\\n\", \"5 9\\n0 2 3\\n1 2\\n1 3\\n1 5\\n2 3\\n2 4\\n2 5\\n3 4\\n3 5\\n4 5\\n\", \"1 0\\n1 0 0\\n\", \"5000 0\\n0 5000 0\\n\", \"1 0\\n0 1 0\\n\", \"5000 1\\n1000 0 4000\\n444 789\\n\", \"5000 0\\n5000 0 0\\n\", \"5000 5\\n1000 1000 3000\\n4 11\\n11 7\\n7 127\\n12... | You are given an undirected graph without self-loops or multiple edges which consists of n vertices and m edges. Also you are given three integers n_1, n_2 and n_3.
Can you label each vertex with one of three numbers 1, 2 or 3 in such way, that:
1. Each vertex should be labeled by exactly one number 1, 2 or 3;
... | 0.75 |
{"tests": "{\"inputs\": [\"4 2 4 4 1\\n4 5 1 2\\n\", \"4 1 3 4 3\\n3 2 5 1\\n\", \"35 2 5 6 3\\n6 8 3 4 2 1 1 10 8 1 2 4 4 2 10 1 1 6 3 8 10 6 3 8 10 8 9 7 9 10 3 9 4 6 7\\n\", \"36 6 6 9 6\\n3 5 8 7 6 8 1 5 10 10 8 5 10 9 8 1 9 7 2 1 8 8 6 1 6 7 4 3 10 2 5 8 4 1 1 4\\n\", \"17 2 7 10 6\\n10 5 9 2 7 5 6 10 9 7 10 3 10 ... | Ziota found a video game called "Monster Invaders".
Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns.
For the sake of simplicity, we only consider two different types of monsters and three different types of guns.
Namely, the two types of monsters are:
*... | 0 |
{"tests": "{\"inputs\": [\"17\\nint f(int n)\\n{\\nif (n < 100) return 17;\\nif (n > 99) return 27;\\n}\\n\", \"144\\nint f(int n)\\n{\\nif (n == 0) return 0;\\nif (n == 1) return n;\\nreturn f(n - 1) + f(n - 2);\\n}\", \"13\\nint f(int n)\\n{\\nif (n == 0) return 0;\\nreturn f(n - 1) + 1;\\n}\\n\", \"15\\nint f(... | Petya wrote a programme on C++ that calculated a very interesting function f(n). Petya ran the program with a certain value of n and went to the kitchen to have some tea. The history has no records concerning how long the program had been working. By the time Petya returned, it had completed the calculations and had th... | 0 |
{"tests": "{\"inputs\": [\"0001\\n1011\\n\", \"000\\n111\\n\", \"1010101011111110111111001111111111111111111111101101110111111111111110110110101011111110110111111101\\n0101111111000100010100001100010101000000011000000000011011000001100100001110111011111000001110011111\\n\", \"0000000001000000000000100000100001000000\\n... | Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:
We will define the distance between two strings s and t of the same length consisting of digits zero and one as the num... | 0.125 |
{"tests": "{\"inputs\": [\"4 2 2 6\\n\", \"1 1 1 8\\n\", \"3 7 4 6\\n\", \"6 1 654321100 654321115\\n\", \"10 7 987654339 987654340\\n\", \"7 8 305686738 573739036\\n\", \"10 1 100 1000000000\\n\", \"3 12 987654345 987654347\\n\", \"1 1 1 1000000000\\n\", \"2 2 987654333 987654335\\n\", \"3 3 240953737 404170887\\n\", ... | Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens.
All characters in this game are lowercase English letters. There are two players: Mister B and his competitor.
Initially the players have a string s consisting of the... | 0 |
{"tests": "{\"inputs\": [\"4\\nword\\n\", \"5\\naaeaa\\n\", \"5\\nweird\\n\", \"4\\naepo\\n\", \"6\\naaaaaa\\n\", \"2\\nou\\n\", \"10\\naaaaaaaaaa\\n\", \"6\\nxxxahg\\n\", \"2\\nba\\n\", \"13\\nmmmmmmmmmmmmm\\n\", \"18\\niuiuqpyyaoaetiwliu\\n\", \"79\\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb... | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | 0 |
{"tests": "{\"inputs\": [\"2\\n5 6\\n1 2 2\\n2 3 -1\\n3 4 -7\\n4 5 0\\n2 3 -7\\n3 5 6\\n5 8\\n1 5 10\\n2 3 -6\\n5 2 5\\n4 5 9\\n1 5 1\\n2 4 -10\\n2 3 -2\\n4 1 1\\n\\nSAMPLE\", \"2\\n1 1\\n1 1 4\\n4 6\\n1 3 -3\\n2 3 1\\n4 2 -5\\n2 4 4\\n1 3 -3\\n1 2 1\", \"2\\n5 6\\n1 2 2\\n2 3 -1\\n3 0 -7\\n4 5 0\\n2 3 -7\\n3 5 6\\n5 8... | Monk visits Biksy, the largest trading market in the land. Biksy has traders from all over the world.
There are a total of N items indexed from 1 to N, that are traded in the market by a total of M dealers. Each trader is characterized by three integers, say i, j, C , meaning that the trader will take i'th item from yo... | 0.375 |
{"tests": "{\"inputs\": [\"5 1 3\", \"1000000 100000 200000\", \"10 4 6\", \"10 0 0\", \"5 1 1\", \"1010000 100000 200000\", \"4 4 6\", \"10 0 1\", \"1010000 100001 200000\", \"5 2 2\", \"1011000 100001 200000\", \"1011001 100001 200000\", \"0100111 001111 35243\", \"5 2 3\", \"1000000 110000 200000\", \"16 4 6\", \"7 ... | We have two indistinguishable pieces placed on a number line. Both pieces are initially at coordinate 0. (They can occupy the same position.)
We can do the following two kinds of operations:
* Choose a piece and move it to the right (the positive direction) by 1.
* Move the piece with the smaller coordinate to the po... | 0 |
{"tests": "{\"inputs\": [\"1\", \"2\", \"123\", \"36018\", \"1000\", \"236\", \"58364\", \"217\", \"112006\", \"77\", \"86941\", \"130\", \"124627\", \"158\", \"136594\", \"261\", \"69011\", \"378\", \"133460\", \"199\", \"210929\", \"383\", \"57266\", \"365\", \"112408\", \"730\", \"54217\", \"859\", \"52868\", \"1083... | For a positive integer n, let us define f(n) as the number of digits in base 10.
You are given an integer S. Count the number of the pairs of positive integers (l, r) (l \leq r) such that f(l) + f(l + 1) + ... + f(r) = S, and find the count modulo 10^9 + 7.
Constraints
* 1 \leq S \leq 10^8
Input
Input is given fro... | 0 |
{"tests": "{\"inputs\": [\"1\\n3141 2718\", \"4\\n0 0\\n0 1\\n1 0\\n1 1\", \"5\\n0 0\\n0 1\\n0 2\\n0 3\\n1 1\", \"1\\n3141 411\", \"4\\n0 0\\n0 1\\n1 0\\n1 2\", \"5\\n0 0\\n0 1\\n0 2\\n0 3\\n1 2\", \"5\\n1 0\\n0 1\\n0 2\\n0 3\\n1 2\", \"5\\n1 0\\n-1 1\\n0 2\\n0 3\\n1 2\", \"1\\n3490 411\", \"1\\n3490 245\", \"1\\n2424 ... | You are given N points (x_i,y_i) located on a two-dimensional plane. Consider a subset S of the N points that forms a convex polygon. Here, we say a set of points S forms a convex polygon when there exists a convex polygon with a positive area that has the same set of vertices as S. All the interior angles of the polyg... | 0 |
{"tests": "{\"inputs\": [\"1,1,1,1,1,1,1,1,1,1,40,60\\n1,1,1,1,1,3,3,3,3,3,50,50\\n10,10,10,10,10,10,10,10,10,10,50,49\", \"06,04,1,1,1,1,1,1,1,1,1,1\\n1,1,1,1,1,3,3,3,3,3,50,50\\n10,10,10,10,10,10,10,10,10,10,50,49\", \"1,1,1,1,1,1,1,1,1,0,40,60\\n1,1,1,1,1,3,3,3,3,3,50,50\\n10,10,10,10,10,10,10,10,10,10,50,49\", \"06... | There is a double-track line (up and down are separate lines and pass each other everywhere). There are 11 stations on this line, including the terminal station, and each station is called by the section number shown in the figure.
<image>
Trains depart from both terminal stations on this line at the same time and r... | 0.625 |
{"tests": "{\"inputs\": [\"4\\n30\\n125\\n75\\n4\\n30\\n125\\n75\\n5\\n30\\n125\\n75\\n65\\n4\\n30\\n125\\n75\\n4\\n30\\n125\\n75\\n6\\n30\\n50\\n50\\n25\\n75\\n0\", \"4\\n30\\n125\\n75\\n4\\n30\\n125\\n75\\n5\\n30\\n125\\n75\\n65\\n4\\n30\\n125\\n75\\n4\\n30\\n125\\n75\\n6\\n30\\n50\\n50\\n29\\n75\\n0\", \"4\\n30\\n12... | Create a program that inputs the vertex information of two polygons inscribed in one circle and outputs the magnitude relationship of their areas.
Assume that each vertex of the X-side is numbered counterclockwise from 1 to X (the figure shows an example when X = 4). However, the given polygon assumes that the center ... | 0.125 |
{"tests": "{\"inputs\": [\"7 6 5 1 8 9 2 3 4\", \"-1 -1 -1 -1 -1 -1 8 4 6\", \"7 6 -1 1 -1 9 2 3 4\", \"-1 -1 -1 -1 -1 -1 -1 -1 -1\", \"7 6 5 2 8 9 2 3 4\", \"7 5 -1 1 -1 9 2 3 4\", \"7 6 -1 1 -1 14 2 3 4\", \"7 6 5 2 8 9 1 3 4\", \"5 6 -1 1 -1 14 2 3 4\", \"7 6 5 3 8 9 1 3 4\", \"7 6 5 3 8 3 1 3 4\", \"7 6 5 3 8 3 1 1... | Addition is easy to calculate by hand, but if some numbers are missing, is it easy to fill in the missing numbers? For example, in the following long division, if there is a condition that the numbers 1 to 9 appear only once, how many numbers will fit in the C and E squares? In this case, 8 is correct for C and 5 is co... | 0.625 |
{"tests": "{\"inputs\": [\"8 4\\n0 1 0 1 0 1 1 1\\n0 1 1 0 0 1 0 0\\n1 0 1 0 1 1 1 1\\n0 1 1 0 1 0 1 0\", \"8 4\\n0 1 0 1 1 1 1 1\\n0 1 1 0 0 1 0 0\\n1 0 1 0 1 1 1 1\\n0 1 1 0 1 0 1 0\", \"8 0\\n0 1 0 1 1 1 1 1\\n0 1 1 0 0 1 0 0\\n1 0 1 0 1 1 1 1\\n0 1 1 0 1 0 1 0\", \"8 1\\n0 1 0 1 0 1 1 1\\n0 1 1 -1 0 1 -1 1\\n2 1 1 ... | problem
The JOI building is a combination of regular hexagons with a side of 1 meter as shown in the figure. As Christmas is approaching, JOI decided to decorate the walls of the building with illuminations. However, since it is useless to illuminate the parts that cannot be seen from the outside, we decided to decora... | 0 |
{"tests": "{\"inputs\": [\"4\\n5 -3\\n1 0\\n1 7\\n-7 -1\\n3\\n5 5\\n18 5\\n5 10\\n3\\n-5 -5\\n-5 -10\\n-18 -10\\n5\\n0 0\\n20 2\\n11 1\\n21 2\\n2 0\\n0\", \"4\\n5 -3\\n1 0\\n1 7\\n-7 -1\\n3\\n5 5\\n18 5\\n5 10\\n3\\n-7 -5\\n-5 -10\\n-18 -10\\n5\\n0 0\\n20 2\\n11 1\\n21 2\\n2 0\\n0\", \"4\\n5 -3\\n1 0\\n1 7\\n-7 -1\\n3\... | Yoko’s math homework today was to calculate areas of polygons in the xy-plane. Vertices are all aligned to grid points (i.e. they have integer coordinates).
Your job is to help Yoko, not good either at math or at computer programming, get her home- work done. A polygon is given by listing the coordinates of its vertic... | 0 |
{"tests": "{\"inputs\": [\"3\\naa\\nabacaba\\nxdd\\n\", \"1\\naad\\n\", \"3\\naa\\nbb\\nccd\\n\", \"1\\nxy\\n\", \"1\\naax\\n\", \"1\\nab\\n\", \"1\\nabb\\n\", \"3\\naa\\nabacaba\\nxdd\\n\", \"4\\ncz\\naabb\\na\\naba\\n\", \"1\\nabbabab\\n\", \"1\\nasasa\\n\", \"1\\naab\\n\", \"1\\nabc\\n\", \"1\\naabb\\n\", \"100\\naa... | You are given a string s consisting only of lowercase Latin letters.
You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible to do it.
Let's call a string good if it is not a palindrome. Palindrome is... | 0.5 |
{"tests": "{\"inputs\": [\"8\\n11 -1 13 19 24 7 17 5\\n\", \"4\\n3 9 1 -1\\n\", \"2\\n-1 1000000000\\n\", \"16\\n-1 70 57 84 80 17 45 10 70 10 51 72 100 37 26 89\\n\", \"16\\n-1 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2\\n\", \"8\\n-1 99 99 2 4 3 2 4\\n\", \"8\\n-1 10 10 10 2 2 2 2\\n\", \"32\\n455576261 993874315 239353491... | You are organizing a boxing tournament, where n boxers will participate (n is a power of 2), and your friend is one of them. All boxers have different strength from 1 to n, and boxer i wins in the match against boxer j if and only if i is stronger than j.
The tournament will be organized as follows: n boxers will be d... | 0 |
{"tests": "{\"inputs\": [\"4\\nabac\\n3\\n2 1 0\\nabc\\n1\\n0\\nabba\\n3\\n1 0 1\\necoosdcefr\\n10\\n38 13 24 14 11 5 3 24 17 0\\n\", \"2\\naccccccc\\n1\\n0\\naaaaac\\n3\\n0 0 0\\n\", \"1\\naba\\n2\\n0 0\\n\", \"1\\naaabbc\\n4\\n3 2 1 0\\n\", \"3\\nybb\\n2\\n0 0\\nzbb\\n2\\n0 0\\nzyybb\\n2\\n0 0\\n\", \"1\\nabbc\\n3\\n... | Polycarp wrote on the board a string s containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input.
After that, he erased some letters from the string s, and he rewrote the remaining letters in any order. As a result, he got some new string t. You have to find it with some ad... | 0 |
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n2 3 -1\\n\", \"10\\n-10 -1 2 2 5 -2 -3 -4 2 -6\\n-1 -1 2 2 -1 5 5 7 7 9\\n\", \"2\\n-1 100\\n2 -1\\n\", \"10\\n-10 -1 2 2 5 -2 -3 -4 2 -6\\n-1 -1 2 2 -1 5 5 7 7 9\\n\", \"10\\n-10 -1 2 3 5 -2 -3 -4 2 -6\\n-1 -1 2 2 -1 5 5 7 7 9\\n\", \"2\\n-1 000\\n2 -1\\n\", \"10\\n-10 -1 2 3 5 -... | Captain Fint is involved in another treasure hunt, but have found only one strange problem. The problem may be connected to the treasure's location or may not. That's why captain Flint decided to leave the solving the problem to his crew and offered an absurdly high reward: one day off. The problem itself sounds like t... | 0 |
{"tests": "{\"inputs\": [\"2 2\\n1.0 0.0 0.0\\n1.0 0.0 1.0\\n\", \"2 2\\n1.0 0.0 0.0\\n0.0 1.0 1.0\\n\", \"2 2\\n1.0 0.0 0.0\\n-1.0 0.0 0.0\\n\", \"2 2\\n1.0 0.0 1.0\\n-1.0 0.0 1.0\\n\", \"2 2\\n1.0 0.0 0.0\\n-1.0 0.0 0.0\\n\", \"939 172\\n760.602725383313210 550.640076764737840 0.000000000000000\\n0.000000000000000 0.... | Greg the Dwarf has been really busy recently with excavations by the Neverland Mountain. However for the well-known reasons (as you probably remember he is a very unusual dwarf and he cannot stand sunlight) Greg can only excavate at night. And in the morning he should be in his crypt before the first sun ray strikes. T... | 0 |
{"tests": "{\"inputs\": [\"2\\n1 2\\n3 4\\n\", \"3\\n1 2\\n3 6\\n4 5\\n\", \"5\\n3 10\\n6 4\\n1 9\\n5 8\\n2 7\\n\", \"3\\n3 5\\n4 1\\n2 6\\n\", \"3\\n1 6\\n5 4\\n2 3\\n\", \"20\\n7 29\\n4 34\\n40 2\\n39 10\\n33 5\\n1 37\\n20 23\\n14 21\\n22 9\\n8 28\\n19 24\\n26 13\\n32 6\\n30 16\\n11 38\\n36 3\\n35 12\\n15 31\\n17 27\... | There is a deck of n cards. The i-th card has a number a_i on the front and a number b_i on the back. Every integer between 1 and 2n appears exactly once on the cards.
A deck is called sorted if the front values are in increasing order and the back values are in decreasing order. That is, if a_i< a_{i+1} and b_i> b_{i... | 0 |
{"tests": "{\"inputs\": [\"3\\n3\\n110\\n2\\n00\\n4\\n1010\\n\", \"3\\n3\\n110\\n2\\n00\\n4\\n1011\\n\", \"3\\n3\\n010\\n2\\n00\\n4\\n0011\\n\", \"3\\n3\\n110\\n2\\n00\\n4\\n0110\\n\", \"3\\n3\\n010\\n2\\n00\\n4\\n1001\\n\", \"3\\n3\\n110\\n2\\n00\\n4\\n0011\\n\", \"3\\n3\\n110\\n2\\n00\\n4\\n0010\\n\", \"3\\n3\\n000\\... | The only difference between the easy and hard versions is that the given string s in the easy version is initially a palindrome, this condition is not always true for the hard version.
A palindrome is a string that reads the same left to right and right to left. For example, "101101" is a palindrome, while "0101" is n... | 0 |
{"tests": "{\"inputs\": [\"1 1000\\na b 0\\n\", \"4 1\\nvasya petya 1\\npetya vasya 2\\nanya ivan 2\\nivan anya 4\\n\", \"3 1\\na b 1\\nb c 2\\nc d 3\\n\", \"3 1\\na b 1\\na b 2\\nb a 2\\n\", \"10 2\\nfxn ipntr 0\\nipntr fxn 1\\nfxn ipntr 1\\npfvpfteadph ipntr 2\\nfxn pfvpfteadph 4\\nipntr fxn 4\\npfvpfteadph fxn 5\\nf... | Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ... | 0.5 |
{"tests": "{\"inputs\": [\"2\\n5 5 5 5\\n\", \"3\\n1 0 -1 0 2 -1 -2 0 1\\n\", \"3\\n1 2 3 4 5 6 7 8 9\\n\", \"3\\n2 4 6 8 10 12 14 16 18\\n\", \"4\\n1936924 6264932 1936924 -4555088 -8883096 -19703116 -8883096 1936924 12756944 -8883096 -8883096 -8883096 6264932 1936924 6264932 -8883096\\n\", \"3\\n399 -1025 -129 -497 9... | The Smart Beaver from ABBYY loves puzzles. One of his favorite puzzles is the magic square. He has recently had an idea to automate the solution of this puzzle. The Beaver decided to offer this challenge to the ABBYY Cup contestants.
The magic square is a matrix of size n × n. The elements of this matrix are integers.... | 0 |
{"tests": "{\"inputs\": [\"2 1\\n1 2\\n\", \"3 3\\n1 2\\n2 3\\n3 1\\n\", \"10 45\\n10 5\\n10 7\\n6 1\\n5 8\\n3 5\\n6 5\\n1 2\\n6 10\\n2 9\\n9 5\\n4 1\\n7 5\\n1 8\\n6 8\\n10 9\\n7 2\\n7 9\\n4 10\\n7 3\\n4 8\\n10 3\\n10 8\\n2 10\\n8 2\\n4 2\\n5 2\\n9 1\\n4 5\\n1 3\\n9 6\\n3 8\\n5 1\\n6 4\\n4 7\\n8 7\\n7 1\\n9 3\\n3 4\\n6... | The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else.
Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one ... | 0 |
{"tests": "{\"inputs\": [\"3\\n4 8 2\\n\", \"3\\n3 5 6\\n\", \"2\\n99999 99998\\n\", \"7\\n7 4096 8192 16384 32768 65536 100000\\n\", \"17\\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536\\n\", \"9\\n7 4096 8192 16384 32768 65536 100000 100000 100000\\n\", \"1\\n100000\\n\", \"17\\n100000 99999 4999... | Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.
Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his t... | 0 |
{"tests": "{\"inputs\": [\"3\\n1 1 1\\n\", \"24\\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8\\n\", \"8\\n8 7 6 5 4 3 2 1\\n\", \"7\\n8 8 2 6 1 8 5\\n\", \"18\\n4 3 3 3 7 7 5 2 1 1 3 3 6 1 2 4 1 8\\n\", \"120\\n6 7 8 5 2 8 5 4 6 4 3 2 5 6 5 7 5 7 1 7 4 6 4 1 4 1 1 7 6 7 3 7 4 7 4 6 4 7 6 6 6 5 5 7 3 5 3 7 2 2 4 2 5... | Vladik was bored on his way home and decided to play the following game. He took n cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of cards which satisfies the following conditions:
* the number of occ... | 0 |
{"tests": "{\"inputs\": [\"10 15 2\\n2\\n10 13\\n\", \"8 17 3\\n4\\n3 4 5 8\\n\", \"30 70 10\\n3\\n30 32 35\\n\", \"100000000000 200000000000 10000000000\\n10\\n1 1 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000\\n\", \"61 1000000000 13\\n55\\n29 72 85 94 103 123... | Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.
He know... | 0 |
{"tests": "{\"inputs\": [\"9\\n5 1 3 1 5 2 4 2 5\\n\", \"6\\n4 4 2 5 2 3\\n\", \"100\\n915 7 282 162 24 550 851 240 39 302 538 76 131 150 104 848 507 842 32 453 998 990 1002 225 887 1005 259 199 873 87 258 318 837 511 663 1008 861 516 445 426 335 743 672 345 320 461 650 649 612 9 1017 113 169 722 643 253 562 661 879 52... | Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code ai is know... | 0 |
{"tests": "{\"inputs\": [\"2 2 1\\n1 1 2\\n2 2 1\\n\", \"6 6 3\\n2 2 6\\n1 4 5\\n2 3 4\\n1 4 1\\n1 3 1\\n2 2 3\\n\", \"5 5 5\\n2 5 3\\n1 2 3\\n1 4 5\\n2 5 2\\n1 2 1\\n\", \"5 10 3\\n2 5 1\\n2 1 3\\n2 3 5\\n2 1 4\\n2 5 4\\n2 2 5\\n2 3 2\\n2 2 1\\n2 4 3\\n2 4 2\\n\", \"5 5 1\\n2 5 3\\n2 2 5\\n1 2 1\\n2 4 2\\n1 1 5\\n\", ... | Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.
Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans:
1. to orient each undirected edge in one of two possible directions to maximize... | 0 |
{"tests": "{\"inputs\": [\"xoo x.. x..\\nooo ... ...\\nooo ... ...\\n\\nx.. x.. x..\\n... ... ...\\n... ... ...\\n\\nx.. x.. x..\\n... ... ...\\n... ... ...\\n7 4\\n\", \"... ... ...\\n... ... ...\\n... ... ...\\n\\n... ... ...\\n... ... ...\\n... x.. ...\\n\\n... ... ...\\n... ... ...\\n... ... ...\\n6 4\\n\", \"o.. .... | Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.
The game is played on the following field.
<image>
Players are making moves by turns. At first move a player can put his chip in any cell of any sm... | 0 |
{"tests": "{\"inputs\": [\"5\\n?CYC?\\n\", \"5\\nCY??Y\\n\", \"5\\nC?C?Y\\n\", \"5\\nC??MM\\n\", \"3\\nMMY\\n\", \"8\\nCMC??MCM\\n\", \"10\\nMCYM?MYM?C\\n\", \"5\\nC???Y\\n\", \"6\\n?CC???\\n\", \"1\\nC\\n\", \"3\\nMC?\\n\", \"6\\nMC??MC\\n\", \"2\\nY?\\n\", \"100\\n?????????????????????????????????????????????????????... | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into n consecutive segments, each segment needs to be painted in one of the colo... | 0.625 |
{"tests": "{\"inputs\": [\"5\\n21\\n22\\n23\\n24\\n25\\n\\nSAMPLE\", \"5\\n21\\n22\\n23\\n24\\n25\\n\\nELPMAS\", \"5\\n5\\n22\\n27\\n24\\n25\\n\\nELPMAS\", \"5\\n5\\n22\\n27\\n31\\n25\\n\\nELPMAS\", \"5\\n3\\n11\\n21\\n34\\n25\\n\\nESPNAL\", \"5\\n63\\n22\\n23\\n2\\n3\\n\\nSAMPLF\", \"5\\n21\\n22\\n27\\n24\\n25\\n\\nEL... | Mehta is a forever alone and desperate guy. He has a crush on N girls of his society. He wants to impress them all and so he needs to do their task collectively.All the girls give him a number which he stores in an array named A of size N. To do their task, he has to report the number of triplets (i,j,k) in the array A... | 0 |
{"tests": "{\"inputs\": [\"3\", \"0\", \"4\", \"1\", \"2\", \"000\", \"001\", \"2\", \"0\", \"1\", \"4\", \"001\", \"000\"], \"outputs\": [\"2\\n1 3\\n2 3\", \"0\\n\", \"4\\n1 2\\n1 3\\n2 4\\n3 4\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"4\\n1 2\\n1 3\\n2 4\\n3 4\\n\", \"0\\n\", \"0\... | You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:
* The graph is simple and connected.
* There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.
It can be proved t... | 0 |
{"tests": "{\"inputs\": [\"3 4 4\\n1101\\n0110\\n1101\\n1 1 3 4\\n1 1 3 1\\n2 2 3 4\\n1 2 2 4\", \"5 5 6\\n11010\\n01110\\n10101\\n11101\\n01010\\n1 1 5 5\\n1 2 4 5\\n2 3 3 4\\n3 3 3 3\\n3 1 3 5\\n1 1 3 4\", \"3 4 4\\n1101\\n0110\\n1101\\n1 1 3 4\\n1 1 3 1\\n2 2 3 4\\n1 2 3 4\", \"5 5 6\\n11010\\n01110\\n10101\\n11101\... | Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the square at the i-th row and j-th column is blue; if S_{i,j} is 0, the ... | 0 |
{"tests": "{\"inputs\": [\"3 100\\n7 6 5\\n9 9 9\", \"1 2\\n1\\n3\", \"2 3\\n1 1\\n1 1\", \"2 3\\n1 1\\n2 2\", \"4 8\\n3 1 4 1\\n3 1 4 1\", \"3 100\\n7 1 5\\n9 9 9\", \"1 2\\n1\\n4\", \"4 8\\n3 1 4 1\\n3 1 5 1\", \"3 000\\n7 1 5\\n9 9 9\", \"1 4\\n1\\n4\", \"4 8\\n3 1 3 1\\n3 1 5 1\", \"4 8\\n3 1 2 1\\n3 1 5 1\", \"4 8... | 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience.
There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to the children.
If child i is given a candies, the child's happine... | 0.75 |
{"tests": "{\"inputs\": [\"123+4X6=X79\\n12X+4X6=X79\\nXX22+89=X2XX\", \"123+4X6=X79\\n12X+4X7=X79\\nXX22+89=X2XX\", \"123+5X6=X79\\n12X+4X7=X79\\nXX22+89=X2XX\", \"123+5X6=X89\\n12X+4X7=X79\\nXX22+89=X2XX\", \"127+5XX=638\\n1+X14X7=X59\\nXX32+89=X2XX\", \"123+4X6=X79\\n12X+4X6=X79\\nXX12+89=X2XX\", \"1X3+426=X79\\n12X... | The problem of hiding a part of a formula and searching for the hidden number is called verbal arithmetic. This time, I'm dealing with an expression in which some numbers in the expression are hidden by X. Enter the following formula and create a program that outputs the result.
Formula
* A simple one-line addition e... | 0 |
{"tests": "{\"inputs\": [\"2 1\\n1 2 5\\n3 2\\n1 2 5\\n2 3 5\\n6 9\\n1 2 7\\n1 3 9\\n1 5 14\\n2 3 10\\n2 4 15\\n3 4 11\\n3 5 2\\n4 5 9\\n4 6 8\\n0 0\", \"2 1\\n1 2 5\\n3 2\\n1 2 5\\n2 3 5\\n6 9\\n1 2 7\\n1 3 9\\n1 5 14\\n2 3 15\\n2 4 15\\n3 4 11\\n3 5 2\\n4 5 9\\n4 6 8\\n0 0\", \"2 1\\n1 2 5\\n3 2\\n1 2 5\\n2 3 5\\n6 9... | Takeshi, who loves hot springs, is planning a trip to a hot spring resort on his next long vacation. I would like to travel by connecting to a long-distance bus and reach my destination with as little money as possible. Takeshi, who has savings but is unwilling to pay, decided to consult with his grandfather. The grand... | 0 |
{"tests": "{\"inputs\": [\"3\\n-3 1 1\\n2 -4 1\\n2 1 -1\\n3\\n-4 1 1\\n1 1 -6\\n1 -5 3\\n4\\n-8 6 -2 1\\n2 -7 -2 1\\n1 -1 1 1\\n1 1 1 -5\\n6\\n2 2 3 -7 3 2\\n1 -10 1 1 3 2\\n2 6 5 2 -6 1\\n3 4 -23 2 2 5\\n3 3 -6 2 3 7\\n-7 2 3 2 -5 -13\\n6\\n2 2 3 -7 3 2\\n1 -10 1 1 3 2\\n2 6 5 2 -6 1\\n3 4 -23 2 2 5\\n3 3 -6 2 3 7\\n-... | Let's solve the puzzle by programming.
The numbers n x n are arranged in a grid pattern. Some of the numbers are circled and we will call them the starting point. The rules of the puzzle are as follows:
* Draw one line that goes vertically and horizontally from each starting point (cannot be drawn diagonally).
* Exte... | 0 |
{"tests": "{\"inputs\": [\"10\\n802 0 10\\n814 0 4\\n820 1 4\\n826 1 4\\n832 3 5\\n838 5 5\\n845 7 3\\n849 10 3\\n853 14 4\\n857 18 3\\n3\\n0 0 5\\n8 0 5\\n8 8 5\\n3\\n0 0 5\\n7 3 6\\n16 0 5\\n9\\n0 3 5\\n8 0 8\\n19 2 8\\n23 14 6\\n23 21 6\\n23 28 6\\n19 40 8\\n8 42 8\\n0 39 5\\n11\\n0 0 5\\n8 0 5\\n18 8 10\\n8 16 5\\n... | There is a chain consisting of multiple circles on a plane. The first (last) circle of the chain only intersects with the next (previous) circle, and each intermediate circle intersects only with the two neighboring circles.
Your task is to find the shortest path that satisfies the following conditions.
* The path co... | 0 |
{"tests": "{\"inputs\": [\"4\\nA\\nAND\\nCAT\\nDOG\\nZ XUW ZVX Z YZT.\\n2\\nAZ\\nAY\\nZA.\\n2\\nAA\\nBB\\nCC.\\n16\\nA\\nB\\nC\\nD\\nE\\nF\\nG\\nH\\nI\\nJ\\nK\\nL\\nM\\nN\\nO\\nABCDEFGHIJKLMNO\\nA B C D E F G H I J K L M N O ABCDEFGHIJKLMNO.\\n0\", \"4\\nA\\nAND\\nCAT\\nDOG\\nZ XUW ZVX Z YZT.\\n2\\nAZ\\nAY\\nZA.\\n2\\n... | The committee members of the Kitoshima programming contest had decided to use crypto-graphic software for their secret communication. They had asked a company, Kodai Software, to develop cryptographic software that employed a cipher based on highly sophisticated mathematics.
According to reports on IT projects, many p... | 0 |
{"tests": "{\"inputs\": [\"3 2\\nc ? ?\\n0 1\\n0 2\", \"5 0\\n? ? ? ? ?\", \"3 3\\nc ? ?\\n0 1\\n0 2\\n1 2\", \"7 6\\n? a ? ? z a ?\\n0 1\\n0 2\\n3 4\\n4 5\\n4 6\\n5 6\", \"1 0\\n? ? ? ? ?\", \"3 3\\nb ? ?\\n0 1\\n0 2\\n1 2\", \"7 6\\n? a ? ? z a ?\\n1 1\\n0 2\\n3 4\\n4 5\\n4 6\\n5 6\", \"7 6\\n? a ? ? z a ?\\n1 1\\n0 ... | Background
The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves lowercase letters as much as programming. Yu-kun decided to write a scoring program for a new play that uses paper, circles, lines, and lowercase lett... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.