info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"2 \\n3 \\n4\\n\\nSAMPLE\", \"19\\n1\\n10\\n100\\n1000\\n10000\\n100000\\n1000000\\n10000000\\n100000000\\n1000000000\\n9\\n99\\n999\\n9999\\n99999\\n999999\\n9999999\\n99999999\\n999999999\", \"19\\n1\\n10\\n100\\n1000\\n10000\\n100000\\n1000000\\n10000000\\n100000000\\n1000000000\\n9\\n99\\n...
Roy has a wooden log (tree trunk) of length L units. Since the log is too heavy for him to lift, he wants to cut it into pieces. He can lift pieces of length 1 or 2 units. He wonders in how many ways can he make such pieces of the wooden log. Now Roy is too lazy, so he would also like to finish cutting with minim...
0.25
{"tests": "{\"inputs\": [\"4\\n4\\n6\\n10\\n1000000000\", \"4\\n4\\n6\\n15\\n1000000000\", \"4\\n2\\n6\\n15\\n1001000000\", \"4\\n0\\n0\\n15\\n1001000000\", \"4\\n0\\n0\\n24\\n1001000000\", \"4\\n0\\n0\\n24\\n1001000001\", \"4\\n4\\n6\\n10\\n1100000000\", \"4\\n4\\n6\\n30\\n1000000000\", \"4\\n2\\n10\\n15\\n1000000000\...
Given is an integer N. Snuke will choose integers s_1, s_2, n_1, n_2, u_1, u_2, k_1, k_2, e_1, and e_2 so that all of the following six conditions will be satisfied: * 0 \leq s_1 < s_2 * 0 \leq n_1 < n_2 * 0 \leq u_1 < u_2 * 0 \leq k_1 < k_2 * 0 \leq e_1 < e_2 * s_1 + s_2 + n_1 + n_2 + u_1 + u_2 + k_1 + k_2 + e_1 + e_...
0
{"tests": "{\"inputs\": [\"7 3\", \"1000000000 1000000000\", \"4 5\", \"7 0\", \"1001000000 1000000000\", \"6 5\", \"1001000000 1100000000\", \"3 5\", \"1001000010 1100000000\", \"3 6\", \"1001000010 1100100000\", \"1001000011 1100100000\", \"3 1\", \"9 -1\", \"1001000011 1000100000\", \"3 2\", \"1001000011 1000000000\...
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the to...
0.125
{"tests": "{\"inputs\": [\"4\\n5 0\\n9 1\\n3 10\\n11 3\\n1\\n999983 20\\n0\", \"4\\n5 -1\\n9 1\\n3 10\\n11 3\\n1\\n999983 20\\n0\", \"4\\n5 -1\\n9 1\\n3 10\\n8 3\\n1\\n999983 20\\n0\", \"4\\n3 -1\\n14 1\\n3 10\\n8 3\\n1\\n999983 20\\n0\", \"4\\n3 -1\\n14 1\\n3 24\\n8 3\\n1\\n999983 20\\n0\", \"4\\n5 0\\n9 1\\n3 10\\n8 ...
The king of a country loves prime numbers and gambling. The unit of currency in this country is called prime. As of November 1, 2007, Prime's cross-yen rate was just prime at 9973, so the King is overjoyed. Subsidiary coins with 1/101 prime as one subprime are used in this country. The government of this country has d...
0
{"tests": "{\"inputs\": [\"5 5\\n3 bread milk banana\\n2 milk cornflakes\\n3 potato bread milk\\n4 cornflakes bread milk butter\\n2 potato bread\", \"5 2\\n3 bread milk banana\\n2 milk cornflakes\\n3 potato bread milk\\n4 cornflakes bread milk butter\\n2 potato bread\", \"5 5\\n3 bread milk banana\\n2 milk cornflakes\\...
On the Internet shopping site, on the same page as the product that the user is currently viewing, some other products that other users have bought in the past along with the product that they are currently viewing are displayed. It is believed that sales can be increased by presenting products that are considered to b...
0
{"tests": "{\"inputs\": [\"2 3\\n0.900 0.500 0.100\\n0.500 0.500 0.500\", \"2 3\\n0.900 0.500 0.100\\n0.500 0.500 0.6797862263528347\", \"2 3\\n0.900 0.500 0.15231283420683542\\n0.500 0.500 0.6797862263528347\", \"2 3\\n0.900 0.500 0.15231283420683542\\n0.500 1.0377402291803903 0.6797862263528347\", \"2 3\\n0.900 0.500...
The rabbit, who successfully defeated the ambushed enemy, succeeded in advancing the hero into the enemy's castle. When the hero released the cats trapped in the castle dungeon, some of them were the hero's. It will help me. According to the cats, to reach the Demon King in the back of the castle, you will have to go ...
0
{"tests": "{\"inputs\": [\"4\\n3 1 4 1\\n\", \"4\\n3 1 4 4\\n\", \"5\\n3 1 4 1 5\\n\", \"3\\n2 1 4\\n\", \"59\\n0 0 0 5000 0 0 0 5000 5000 0 5000 0 0 0 5000 0 0 0 0 0 0 0 0 0 5000 0 0 0 0 5000 0 5000 0 5000 0 0 5000 0 5000 0 0 0 0 0 0 5000 0 0 0 0 5000 0 0 0 5000 0 0 0 5000\\n\", \"11\\n5000 5000 5000 5000 5000 5000 0 ...
[Æsir - CHAOS](https://soundcloud.com/kivawu/aesir-chaos) [Æsir - V.](https://soundcloud.com/kivawu/aesir-v) "Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect. The time right now...... 00:01:12...... It's time." The emotion samples are now sufficient. After almost 3 ...
0
{"tests": "{\"inputs\": [\"4\\n3\\n1 2 3\\n4\\n3 1 2 4\\n3\\n2 3 1\\n6\\n2 4 6 1 3 5\\n\", \"4\\n3\\n1 2 3\\n4\\n3 1 2 4\\n3\\n2 3 1\\n6\\n2 4 12 1 3 5\\n\", \"4\\n3\\n1 2 3\\n4\\n3 1 2 2\\n3\\n2 1 1\\n6\\n2 4 7 1 6 10\\n\", \"4\\n3\\n1 0 4\\n4\\n3 1 2 4\\n3\\n2 3 1\\n6\\n2 4 6 1 5 1\\n\", \"4\\n3\\n1 2 3\\n4\\n3 1 2 4...
You are given an array a of length n, which initially is a permutation of numbers from 1 to n. In one operation, you can choose an index i (1 ≤ i < n) such that a_i < a_{i + 1}, and remove either a_i or a_{i + 1} from the array (after the removal, the remaining parts are concatenated). For example, if you have the ar...
0
{"tests": "{\"inputs\": [\"5\\n01?01\\n\", \"12\\n???1??????1?\\n\", \"6\\n11?000\\n\", \"1\\n0\\n\", \"1\\n1\\n\", \"1\\n?\\n\", \"5\\n10?10\\n\", \"6\\n01?000\\n\", \"5\\n10?00\\n\", \"5\\n01?00\\n\", \"12\\n?1?1????????\\n\", \"6\\n000?11\\n\", \"6\\n00?011\\n\", \"5\\n10?01\\n\", \"6\\n01?001\\n\", \"6\\n010?01\\n\...
Alice and Bob play a game. The game consists of several sets, and each set consists of several rounds. Each round is won either by Alice or by Bob, and the set ends when one of the players has won x rounds in a row. For example, if Bob won five rounds in a row and x = 2, then two sets ends. You know that Alice and Bob...
0
{"tests": "{\"inputs\": [\"4\\n3\\n1 5 3\\n5\\n2 2 2 2 2\\n6\\n1 6 2 5 2 10\\n5\\n1 6 2 5 1\\n\", \"4\\n3\\n1 5 3\\n5\\n2 2 2 2 2\\n6\\n1 6 2 5 2 10\\n5\\n1 6 2 4 1\\n\", \"4\\n3\\n2 7 3\\n5\\n3 3 2 2 4\\n6\\n1 6 2 2 2 10\\n5\\n1 3 0 4 1\\n\", \"4\\n3\\n2 5 3\\n5\\n2 2 2 2 2\\n6\\n1 6 2 5 2 10\\n5\\n1 6 2 4 1\\n\", \"4...
You are given a sequence of n integers a_1, a_2, ..., a_n. Let us call an index j (2 ≤ j ≤ {{n-1}}) a hill if a_j > a_{{j+1}} and a_j > a_{{j-1}}; and let us call it a valley if a_j < a_{{j+1}} and a_j < a_{{j-1}}. Let us define the intimidation value of a sequence as the sum of the number of hills and the number of v...
0.25
{"tests": "{\"inputs\": [\"3\\n1 2\\n2 3\\n\", \"5\\n1 3\\n1 2\\n4 5\\n3 4\\n\", \"5\\n1 2\\n1 3\\n1 4\\n1 5\\n\", \"8\\n2 5\\n1 7\\n4 1\\n2 1\\n8 7\\n6 1\\n3 1\\n\", \"1\\n\", \"2\\n2 1\\n\", \"8\\n4 6\\n6 7\\n2 5\\n4 5\\n3 4\\n1 2\\n7 8\\n\", \"3\\n3 1\\n3 2\\n\", \"13\\n1 2\\n1 7\\n7 8\\n7 11\\n8 9\\n8 10\\n11 12\\n...
Let F_k denote the k-th term of Fibonacci sequence, defined as below: * F_0 = F_1 = 1 * for any integer n ≥ 0, F_{n+2} = F_{n+1} + F_n You are given a tree with n vertices. Recall that a tree is a connected undirected graph without cycles. We call a tree a Fib-tree, if its number of vertices equals F_k for som...
0
{"tests": "{\"inputs\": [\"3 2\\n1 2\\n2 7\\n1 3\\n\", \"20 19\\n2 47\\n1 37\\n1 48\\n2 42\\n2 48\\n1 38\\n2 47\\n1 48\\n2 47\\n1 41\\n2 46\\n1 28\\n1 49\\n1 45\\n2 34\\n1 43\\n2 29\\n1 46\\n2 45\\n2 18\\n\", \"10 14\\n2 230\\n2 516\\n2 527\\n2 172\\n2 854\\n2 61\\n1 52\\n2 154\\n2 832\\n2 774\\n\", \"5 3\\n1 9\\n2 9\\...
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b...
0.25
{"tests": "{\"inputs\": [\"13\\n\", \"6\\n\", \"153\\n\", \"99\\n\", \"154\\n\", \"3\\n\", \"98\\n\", \"1000000000000\\n\", \"571684826707\\n\", \"152\\n\", \"663938115190\\n\", \"903398973606\\n\", \"420182289478\\n\", \"155\\n\", \"1\\n\", \"4\\n\", \"178573947413\\n\", \"1894100308\\n\", \"2\\n\", \"156\\n\", \"71\\...
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of n playing cards. Let's describe the house they want to make: 1. The house consists of some non-zero number of floors. 2. Each ...
0.875
{"tests": "{\"inputs\": [\"&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;\\n\", \"&lt;table&gt;\\n&lt;tr&gt;\\n&lt;td&gt;\\n&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/\\ntd\\n&gt;&lt;/tr&gt;&lt;tr\\n&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/...
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully. A string is a bHTML table, if it satisfies the grammar: TABLE ::= <table>ROWS</table> ROWS ::= ROW | ROW ROWS ROW ::= <tr>CELLS</tr> ...
0
{"tests": "{\"inputs\": [\"4\\n2 1 3\\n2 4 2\\n\", \"3\\n1 2\\n2 1 3\\n\", \"10\\n8 1 6 5 3 8 7 10 4\\n2 9 2\\n\", \"9\\n8 4 8 5 6 3 2 7 1\\n1 9\\n\", \"10\\n2 7 5\\n8 9 3 2 4 6 8 1 10\\n\", \"7\\n6 3 5 2 1 6 4\\n1 7\\n\", \"10\\n9 8 7 6 2 3 5 4 10 1\\n1 9\\n\", \"5\\n4 1 5 3 2\\n1 4\\n\", \"5\\n2 2 1\\n3 4 5 3\\n\", \...
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game. The rules are following. On each turn a fi...
0.625
{"tests": "{\"inputs\": [\"4 1\\n1 1 2 2\\n1 9 2 10\\n9 9 10 10\\n9 1 10 2\\n\", \"3 1\\n1 1 2 2\\n2 2 3 3\\n3 3 4 4\\n\", \"3 0\\n1 1 2 2\\n1 1 1000000000 1000000000\\n1 3 8 12\\n\", \"2 1\\n1 1 1000000000 1000000000\\n100 200 200 300\\n\", \"1 0\\n1 1 100 100\\n\", \"2 1\\n1 1 1000000000 2\\n1 1 2 1000000000\\n\", \"...
Edo has got a collection of n refrigerator magnets! He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be posit...
0
{"tests": "{\"inputs\": [\"1 1\\n1\\n\", \"3 5\\n1 5 3\\n\", \"1 2\\n1\\n\", \"15 15\\n2 1 2 3 2 3 4 5 6 5 6 5 6 5 6\\n\", \"5 3\\n2 3 4 5 6\\n\", \"18 27\\n2 3 4 3 4 5 6 7 8 9 10 9 8 9 8 9 10 9\\n\", \"14 14\\n2 3 4 5 6 7 8 9 10 11 12 13 14 15\\n\", \"4 4\\n2 3 2 3\\n\", \"9 9\\n2 1 2 3 4 5 6 5 6\\n\", \"4 4\\n2 1 2 3...
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win! On the show a dog needs to eat as many bowls of dog food as poss...
0
{"tests": "{\"inputs\": [\"2\\n1254756\\n4\\n1 5\\n54789623\\n6\\n2 6\\n\\nSAMPLE\", \"2\\n1254756\\n4\\n1 4\\n54789623\\n6\\n2 6\\n\\nSAMPLE\", \"2\\n1254756\\n4\\n1 4\\n9318821\\n6\\n2 6\\n\\nSAMPLE\", \"2\\n1254756\\n8\\n1 4\\n9318821\\n6\\n2 6\\n\\nSAMPLE\", \"2\\n1254756\\n4\\n1 5\\n54789623\\n10\\n2 6\\n\\nSAMPLE...
Rakesh is very good in divisibility. He can easily tell the number is divisible by the given number or not. To make him work harder his teacher changed the question slightly. He will give the number and the other number with which the first number is divisible or not to make it complicated he will mention the range in ...
0.25
{"tests": "{\"inputs\": [\"1\\n2\\n\\nSAMPLE\", \"1\\n2\\n\\nSAMOLE\", \"1\\n1\\n\\nSAMOLE\", \"1\\n3\\n\\nSAMOLE\", \"1\\n4\\n\\nSAMOLD\", \"1\\n7\\n\\nDLOMAS\", \"1\\n6\\n\\nMLODAS\", \"1\\n5\\n\\nMOLDAS\", \"1\\n8\\n\\nMOLDAS\", \"1\\n16\\n\\nMOLDAS\", \"1\\n0\\n\\nRBEMPO\", \"1\\n13\\n\\nDLOMAS\", \"1\\n9\\n\\nMLOD...
Let there be a set of size N. Power set of a set S, denoted by P(S) is the set of all subsets of S, including the empty set and the S itself. Set A is said to be subset of set B if all elements of A are contained in B. Empty set is always a subset of any non-empty set. Similarly any set is subset of itself. Set A i...
0.625
{"tests": "{\"inputs\": [\"5\\n1 2\\n1 3\\n3 4\\n3 5\", \"5\\n1 2\\n1 3\\n2 4\\n3 5\", \"5\\n1 2\\n2 3\\n2 4\\n3 5\", \"5\\n1 3\\n2 3\\n2 4\\n3 5\", \"5\\n1 2\\n4 3\\n2 3\\n2 5\", \"5\\n5 2\\n1 4\\n2 4\\n3 5\", \"5\\n3 2\\n1 3\\n3 4\\n4 5\", \"5\\n1 3\\n2 3\\n1 4\\n3 5\", \"5\\n3 2\\n1 3\\n2 4\\n3 5\", \"5\\n3 2\\n1 3\...
We have a tree with N vertices. The vertices are numbered 1 to N, and the i-th edge connects Vertex a_i and Vertex b_i. Takahashi loves the number 3. He is seeking a permutation p_1, p_2, \ldots , p_N of integers from 1 to N satisfying the following condition: * For every pair of vertices (i, j), if the distance betw...
0
{"tests": "{\"inputs\": [\"2 100\\n85 2 3\\n60 1 1\", \"10 1000\\n451 4593 6263\\n324 310 6991\\n378 1431 7068\\n71 1757 9218\\n204 3676 4328\\n840 6221 9080\\n684 1545 8511\\n709 5467 8674\\n862 6504 9835\\n283 4965 9980\", \"2 100\\n85 2 3\\n60 10 10\", \"1 100000\\n31415 2718 2818\", \"2 100\\n85 2 6\\n60 1 1\", \"1...
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows: * For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive). * Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exa...
0
{"tests": "{\"inputs\": [\"4\\n1 2 3 4\\n1 2\\n1 3\\n1 4\", \"7\\n-2 7 5 6 -8 3 4\\n1 2\\n2 3\\n2 4\\n1 5\\n5 6\\n5 7\", \"10\\n3 4 9 6 1 5 -1 10 -10 -10\\n7 4\\n5 6\\n8 1\\n9 5\\n7 1\\n10 3\\n2 8\\n4 10\\n9 2\", \"6\\n10 -1 10 -1 10 -1\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\", \"8\\n-2 3 6 -2 -2 -5 3 2\\n3 4\\n7 6\\n6 2\\n8 2\...
The server in company A has a structure where N devices numbered 1, 2, ..., N are connected with N - 1 cables. The i-th cable connects Device U_i and Device V_i. Any two different devices are connected through some number of cables. Each device v (1 \leq v \leq N) has a non-zero integer A_v, which represents the follo...
0
{"tests": "{\"inputs\": [\"5 400\\n3 1 4 1 5\", \"3 6\\n1 4 3\", \"6 20\\n10 4 3 10 25 2\", \"1 400\\n3 1 4 1 5\", \"3 6\\n1 7 3\", \"3 6\\n1 5 2\", \"3 7\\n1 5 0\", \"4 590\\n0 1 1 1 5\", \"5 1135\\n1 1 1 2 5\", \"1 734\\n3 1 4 1 5\", \"3 6\\n1 7 2\", \"1 734\\n3 1 4 0 5\", \"1 1126\\n3 1 4 0 5\", \"3 6\\n1 5 0\", \"1...
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is unnecessary...
0.5
{"tests": "{\"inputs\": [\"1\\ny eazqyp pnop pngtg ye obmpngt xmybp mr lygw\", \"1\\nx eazqyp pnop pngtg ye obmpngt xmybp mr lygw\", \"1\\nx pyqzae pnop pngtg ye obmpngt xmybp mr lygw\", \"1\\nx pyqzae pnop pngtg ye onmpbgt xmybp mr lygw\", \"1\\nx pyqzae pnop pngtg ye pnmobgt xmybp mr lygw\", \"1\\nx pyqzae pnop pngtg...
One of the simple ciphers is the affine cipher. First, replace the letters a to z with the numbers a = 0, b = 1, c = 2, ..., x = 23, y = 24, z = 25 and 0 to 25. Then replace the original alphabet with the following formula. $ F (\ gamma) = (\ alpha \ cdot \ gamma + \ beta) $ mod $ 26 $ However, mod 26 represents the ...
0.75
{"tests": "{\"inputs\": [\"-2 1 -1 1 1 1 1 2\\n1 0 2 1 2 2 3 3\\n5\", \"-2 1 -1 1 1 1 1 2\\n1 0 2 1 2 2 0 3\\n5\", \"-4 1 -1 1 1 1 1 2\\n1 0 2 1 2 2 3 3\\n5\", \"-2 1 -2 1 1 1 1 2\\n1 0 2 1 2 2 0 3\\n5\", \"-4 1 -1 1 1 1 1 2\\n1 0 1 1 2 2 3 3\\n5\", \"-2 1 -2 1 1 0 1 2\\n1 0 2 1 2 2 0 3\\n5\", \"-2 1 -2 1 1 0 1 3\\n1 0...
You have to organize a wedding party. The program of the party will include a concentration game played by the bride and groom. The arrangement of the concentration game should be easy since this game will be played to make the party fun. We have a 4x4 board and 8 pairs of cards (denoted by `A' to `H') for the concent...
0
{"tests": "{\"inputs\": [\"700 300 200\\n500 200 300\\n500 200 500\\n275 110 330\\n275 110 385\\n648 375 4002\\n3 1 10000\\n0 0 0\", \"700 300 200\\n500 200 300\\n500 200 500\\n275 110 330\\n275 010 385\\n648 375 4002\\n3 1 10000\\n0 0 0\", \"700 300 200\\n500 200 300\\n500 200 500\\n275 110 330\\n275 010 385\\n1067 37...
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put fou...
0.375
{"tests": "{\"inputs\": [\"6\\n5 2\\n10 30 40 70 100\\n7 3\\n3 6 10 17 21 26 28\\n1 1\\n100\\n2 1\\n0 1000000\\n3 5\\n30 70 150\\n6 4\\n0 10 20 30 40 50\", \"6\\n5 2\\n10 30 40 70 100\\n7 3\\n3 4 10 17 21 26 28\\n1 1\\n100\\n2 1\\n0 1000000\\n3 5\\n30 70 150\\n6 4\\n0 10 20 30 40 50\", \"6\\n5 2\\n10 30 40 70 100\\n7 3...
This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can install the generators wherever you like, but in order for electricity to be supp...
0
{"tests": "{\"inputs\": [\"1 10\\n3 3\\nAAA\\nABA\\nCCC\\n3\\nA 0\\nB 5\\nC 9\\n3\\nD 2\\nR 1\\nU 2\\n5\\n10\\n10\\n10\\n10\\n10\\n100 100\\n10 10\\nTHISISAPEN\\nTHISISAPEN\\nTHISISAPEN\\nTHISISAPEN\\nTHISISAPEN\\nTHISISAPEN\\nTHISISAPEN\\nTHISISAPEN\\nTHISISAPEN\\nTHISISAPEN\\n8\\nT 0\\nH 1\\nI 2\\nS 3\\nA 4\\nP 5\\nE...
The cave, called "Mass of Darkness", had been a agitating point of the evil, but the devil king and all of his soldiers were destroyed by the hero and the peace is there now. One day, however, the hero was worrying about the rebirth of the devil king, so he decided to ask security agency to patrol inside the cave. Th...
0
{"tests": "{\"inputs\": [\"4\\n1 2 3 4\\n1 2 3 4\\n1 2 3 4\\n1 2 3 4\\n1 2 3 4\\n1 2 3 4\\n1 2 3 4\\n1 2 3 4\\noooo\\noooo\\noooo\\noooo\", \"3\\n1 1 1\\n1 1 1\\n1 1 1\\n1 1 1\\n1 1 1\\n1 1 1\\no..\\n.o.\\n..o\", \"3\\n1 1 1\\n1 1 1\\n1 1 1\\n1 1 1\\n1 1 1\\n1 1 1\\no.o\\n...\\n.o.\", \"4\\n1 2 3 4\\n1 2 3 4\\n1 2 3 4\...
Taro is an elementary school student and has graffiti on the back of the leaflet. At one point, Taro came up with the next game. * Write n × n grid-like squares. * The initial state of each square is either marked or unmarked. * Erase or write these circles so that there is always exactly one circle no matter which co...
0
{"tests": "{\"inputs\": [\"1 2\\n4\\n5 5\\n15 5\\n15 15\\n5 15\\n0 10\\n20 10\", \"1 2\\n4\\n5 5\\n15 5\\n15 24\\n5 15\\n0 10\\n20 10\", \"1 3\\n4\\n10 6\\n15 5\\n15 24\\n5 15\\n0 10\\n20 7\", \"2 1\\n4\\n10 5\\n29 1\\n15 19\\n5 20\\n0 10\\n20 7\", \"2 4\\n4\\n10 5\\n15 5\\n15 24\\n5 17\\n0 10\\n20 7\", \"1 2\\n4\\n10 ...
E-Election campaign Problem Statement You are a supporter of Mr. X, a candidate for the next election. Mr. X is planning a street speech in front of the station and intends to give a speech in a place that can be seen by as many voters as possible. The front of the station is given as a two-dimensional plane with $ ...
0
{"tests": "{\"inputs\": [\"5\\n2 1\\n1 0\\n2 0\\n3 2\\n0 3\\n\", \"8\\n2 2\\n1 4\\n2 3\\n3 1\\n3 4\\n1 1\\n4 3\\n1 2\\n\", \"9\\n1 4\\n2 3\\n3 4\\n4 3\\n2 2\\n1 2\\n1 1\\n3 1\\n5 3\\n\", \"1\\n1000000000 1000000000\\n\", \"9\\n1 1\\n3 4\\n4 3\\n1 4\\n1 2\\n3 1\\n2 3\\n2 2\\n1 5\\n\", \"39\\n27 47\\n30 9\\n18 28\\n49 16...
Maksim walks on a Cartesian plane. Initially, he stands at the point (0, 0) and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point (0, 0), he can go to any of the following points in one move: * (1, 0); * (0, 1); * (-1, 0); * (0, -...
0
{"tests": "{\"inputs\": [\"16\\nfun while return var { } ( ) , ; &gt; = + ++ - --\\n9\\nfun fib(num) { # compute fibs\\n var return_value = 1, prev = 0, temp;\\n while (num &gt; 0) {\\n temp = return_value; return_value = return_value + prev;\\n prev = temp;\\n num--;\\n }\\n return return_value;\\n}\\n\",...
International Coding Procedures Company (ICPC) writes all its code in Jedi Script (JS) programming language. JS does not get compiled, but is delivered for execution in its source form. Sources contain comments, extra whitespace (including trailing and leading spaces), and other non-essential features that make them qu...
0
{"tests": "{\"inputs\": [\"8\\nBBBGBRRR\\n\", \"9\\nRBGRRBRGG\\n\", \"13\\nBBRRRRGGGGGRR\\n\", \"5\\nGBBRG\\n\", \"3\\nRGG\\n\", \"500\\nBRGRRBBGGRBBRBBGGGRBGBGRGRRBRRRBGRBGBRGGGRBBRRBBBRGGBGBBBGGGRGRBBBRBGGBRGGGBRGGRBRGBBGBRRGGBGRGBGGGGGRBBRGBGGRBGGGRBRGGBBGRBBRRRGBRRBGGBGBGGGGRBGRGRRGGGBRBRRGBGGGRBRBBGBBGGBRBGBRRGGRR...
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland). You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garlan...
0
{"tests": "{\"inputs\": [\"4\\nabcd\\ngg\\ncodeforces\\nabaca\\n\", \"1\\nheaghhcgfb\\n\", \"1\\ndgeegbeabh\\n\", \"1\\neefbhgeabache\\n\", \"1\\nzcbacx\\n\", \"4\\nabcd\\ngg\\ncodeforces\\nabaca\\n\", \"1\\nzyy\\n\", \"100\\nc\\nda\\na\\nee\\ned\\ndb\\nece\\nab\\nabe\\nd\\neeb\\na\\nbab\\nbbd\\nc\\ncab\\nc\\nbda\\ndb\...
You are given a string, consisting of lowercase Latin letters. A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions (1, 2) — "ab" and (2, 3) — "ba". Letters 'a' and 'z' aren't considered neighbou...
0
{"tests": "{\"inputs\": [\"cbacacacbcbababacbcb\\n\", \"abc\\n\", \"cacbac\\n\", \"bcacabcbabacacbcbcbcbabacbcacacbcacababc\\n\", \"abababacacacbcbcbc\\n\", \"babababcbcbacacac\\n\", \"acab\\n\", \"abacbc\\n\", \"acbcbabacacbcbab\\n\", \"bacbac\\n\", \"abababcbacacacbcbc\\n\", \"bcb\\n\", \"ababacacacbc\\n\", \"cbcacbc...
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it? The book contains a single string of characters "a", "...
0
{"tests": "{\"inputs\": [\"2\\n1 2\\n1 2\\n\", \"7\\n5 2 3 6 7 1 4\\n2 3 6 7 1 4 5\\n\", \"5\\n3 5 2 1 4\\n4 3 2 5 1\\n\", \"2\\n1 2\\n2 1\\n\", \"2\\n0 2\\n0 2\\n\", \"2\\n2 1\\n1 2\\n\", \"2\\n0 1\\n0 1\\n\", \"2\\n2 1\\n2 1\\n\"], \"outputs\": [\"0\\n\", \"6\\n\", \"2\\n\", \"1\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"...
Consider a tunnel on a one-way road. During a particular day, n cars numbered from 1 to n entered and exited the tunnel exactly once. All the cars passed through the tunnel at constant speeds. A traffic enforcement camera is mounted at the tunnel entrance. Another traffic enforcement camera is mounted at the tunnel ex...
0
{"tests": "{\"inputs\": [\"998244352 1337 5000\\n\", \"1 1 1\\n\", \"1 1 5000\\n\", \"2 2 2\\n\", \"213292922 8067309 5000\\n\", \"569716410 849619604 5000\\n\", \"232213466 585535513 4789\\n\", \"251134010 189925189 5000\\n\", \"588636954 730833344 5000\\n\", \"232213466 585535513 5000\\n\", \"213292922 8067309 44\\n\...
Consider the following experiment. You have a deck of m cards, and exactly one card is a joker. n times, you do the following: shuffle the deck, take the top card of the deck, look at it and return it into the deck. Let x be the number of times you have taken the joker out of the deck during this experiment. Assuming ...
0
{"tests": "{\"inputs\": [\"3\\n(()\\n\", \"8\\n))((())(\\n\", \"51\\n))((((((((()))(())()(()(()())()(()(())(())()())))))\\n\", \"4\\n((()\\n\", \"100\\n((()()))(()()))(())))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()((())(\\n\", \"10\\n))))((((()\\n\", \"10\\n)()()()()(\\n\", \"100\\n)))))...
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. The teacher gave Dmitry's class a very strange task — she asked every student...
0.125
{"tests": "{\"inputs\": [\"5\\n0 1 5 2 6\\n\", \"7\\n6 9 8 7 3 5 2\\n\", \"7\\n32 35 2 20 52 59 28\\n\", \"3\\n4 9 1\\n\", \"109\\n74 18 237 179 195 112 156 11 72 68 173 202 78 250 224 251 107 55 186 144 57 62 28 210 132 64 93 6 211 0 174 163 248 226 167 246 46 102 253 180 121 56 151 35 150 254 168 201 242 118 190 158 ...
For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k written on them. * For every i from 1 to k: find such j (1 ≤ j ≤ k, j≠ i), for which (b_i ⊕ b_j) is the smallest among all such j,...
0
{"tests": "{\"inputs\": [\"5 1\\n1 2\\n1 3\\n5 2\\n4 3\\n0 3 2 4 4\\n\", \"3 3\\n1 3\\n1 2\\n1 2 3\\n\", \"3 1\\n3 1\\n3 2\\n1 2 3\\n\", \"4 3\\n1 2\\n1 3\\n3 4\\n1000000000 999999999 0 1\\n\", \"3 20\\n1 2\\n1 3\\n1 2 3\\n\", \"6 1\\n1 2\\n1 3\\n3 4\\n2 5\\n5 6\\n1 3 3 4 5 0\\n\", \"3 3\\n1 3\\n1 2\\n1 3 3\\n\", \"6 1...
Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has n nodes (numbered 1 to n, with some node r as its root). There are a_i presents are hanging from the i-th node. Before beginning the game, a special integer k is chosen. The game proceeds as follows: * Alice begin...
0
{"tests": "{\"inputs\": [\"2 1\\n\", \"10 7\\n\", \"1000000000000 1\\n\", \"3 2\\n\", \"4 2\\n\", \"1000 998\\n\", \"8 5\\n\", \"442 42\\n\", \"3 1\\n\", \"695928431619 424778620208\\n\", \"13 8\\n\", \"1000000000000 3\\n\", \"628625247282 464807889701\\n\", \"293 210\\n\", \"1000000000000 999999999998\\n\", \"78787878...
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting t...
0.75
{"tests": "{\"inputs\": [\"aabcd\\n\", \"aabc\\n\", \"bbbcccddd\\n\", \"asbbsha\\n\", \"aabbcccdd\\n\", \"qqqqaaaccdd\\n\", \"abcd\\n\", \"aaabbbcccdddeee\\n\", \"aaabb\\n\", \"acc\\n\", \"azz\\n\", \"aaaabbcccccdd\\n\", \"aaacccb\\n\", \"bababab\\n\", \"ttttt\\n\", \"aaadd\\n\", \"aaabbbccc\\n\", \"aaabbccdd\\n\", \"o...
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of lowercase Latin letters. At once you can choose any position in th...
0
{"tests": "{\"inputs\": [\"5\\n9 7 8 6 5\\n1 1\\n2 1\\n3 1\\n4 1\\n\", \"5\\n2 5 1 4 6\\n1 7\\n1 1\\n3 5\\n3 6\\n\", \"5\\n1000000000 1000000000 1000000000 1000000000 1000000000\\n1 1000000000\\n2 1000000000\\n3 1000000000\\n4 1000000000\\n\", \"10\\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100...
Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges). Let's define dist(v, u) as the sum of the inte...
0.125
{"tests": "{\"inputs\": [\"4 4\\n\", \"3 2\\n\", \"50 57129577186267\\n\", \"6 12\\n\", \"50 161245081749292\\n\", \"5 3\\n\", \"49 40394027154620\\n\", \"7 15\\n\", \"49 36309684494664\\n\", \"50 250144743882708\\n\", \"49 140149194635018\\n\", \"5 10\\n\", \"6 2\\n\", \"6 19\\n\", \"50 8840088596980\\n\", \"6 4\\n\",...
One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if on...
0
{"tests": "{\"inputs\": [\"2\\nh\\ns\\n\", \"4\\nssh\\nhs\\ns\\nhhhs\\n\", \"100\\nh\\nshh\\nh\\nhs\\nshh\\nhh\\nh\\nssh\\nhss\\nh\\nhh\\nh\\nh\\nh\\nh\\nh\\nh\\nh\\nh\\nh\\nhh\\nh\\nh\\nh\\nh\\nhhh\\nh\\nh\\nhhh\\nsh\\nhh\\nhs\\nh\\nh\\nshs\\nh\\nh\\nh\\nshh\\nhs\\nhs\\nh\\nh\\nh\\nhhh\\nh\\nhhs\\nhh\\nh\\nssh\\nh\\nh...
Pushok the dog has been chasing Imp for a few hours already. <image> Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner. While moving, the robot generates a string t consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string t as the number of occurrences of strin...
0
{"tests": "{\"inputs\": [\"3\\n10\\n100\\n1000\\n\\nSAMPLE\", \"3\\n12\\n100\\n1000\\n\\nSAMPLE\", \"3\\n12\\n100\\n1100\\n\\nSAMPLE\", \"3\\n12\\n110\\n1100\\n\\nSAMPLE\", \"3\\n20\\n110\\n1100\\n\\nSAMPLE\", \"3\\n20\\n111\\n1100\\n\\nSAMPLE\", \"3\\n25\\n111\\n1100\\n\\nSAMPLE\", \"3\\n25\\n110\\n1100\\n\\nSANPLE\",...
This is a fact for almost all the students out there that Mathematics subject is a very fearful subject for them. And no wonder this fact is also true for our friend Primo. But to challenge his fear he went to the Mathe-Matica Town for his summer vacations. In Mathe-Matica town every person is assigned a Friend Score...
0
{"tests": "{\"inputs\": [\"3 3 1\\n3 2\", \"100000 100000 0\", \"10 10 14\\n4 3\\n2 2\\n7 3\\n9 10\\n7 7\\n8 1\\n10 10\\n5 4\\n3 4\\n2 8\\n6 4\\n4 4\\n5 8\\n9 2\", \"3 6 1\\n3 2\", \"100001 100000 0\", \"10 10 14\\n4 3\\n2 2\\n7 3\\n9 10\\n7 9\\n8 1\\n10 10\\n5 4\\n3 4\\n2 8\\n6 4\\n4 4\\n5 8\\n9 2\", \"100101 100000 0...
Takahashi and Aoki will play a game using a grid with H rows and W columns of square cells. There are N obstacles on this grid; the i-th obstacle is at (X_i,Y_i). Here, we represent the cell at the i-th row and j-th column (1 \leq i \leq H, 1 \leq j \leq W) by (i,j). There is no obstacle at (1,1), and there is a piece ...
0
{"tests": "{\"inputs\": [\"1.0,0.0,-1.0,0.0,1.0,1.0\\n1.0,0.0,0.0,-1.0,3.0,0.0\\n0.0,1.0,0.0,-1.0,1.0,1.0\", \"1.0,0.0,-1.0,0.0,1.0,1.0\\n1.0,0.0,0.0,-1.0,0.0,0.3\\n0.0,1.0,0.0,-1.0,1.0,1.0\", \"1.0,0.0,-1.0,0.0,1.0,1.0\\n1.0,0.0,0.0,-1.0,3.0,0.0\\n1.0,1.0,0.0,-1.0,1.0,1.0\", \"1.0,0.0,-1.0,0.0,1.0,2.0\\n1.0,0.0,0.0,-1...
Read a set of coordinates of three different points P1 (x1, y1), P2 (x2, y2), Q (xq, yq) on the plane, and line symmetry with point Q with the straight line passing through point P1 point P2 as the axis of symmetry. Create a program that outputs the point R (x, y) at the position of. Note that the point Q is not on its...
0.75
{"tests": "{\"inputs\": [\"5 4 6\\n1 6\\n2 4\\n3 3\\n4 4\\n5 1\\n6 2\\n0 0 1 0 0\\n0 0 0 2 0\\n0 0 0 3 0\\n0 4 5 0 6\\n3 3 1\\n1 9\\n0 0 1\\n0 0 0\\n0 0 0\\n4 4 4\\n1 6\\n2 2\\n3 4\\n4 4\\n0 1 0 0\\n0 0 0 2\\n0 0 3 0\\n0 4 0 0\\n0 0 0\", \"5 4 6\\n1 6\\n2 4\\n3 3\\n4 4\\n5 1\\n6 2\\n0 0 1 0 0\\n0 0 0 2 0\\n0 0 0 3 0\\n...
Housing maker Yamada House has launched a new featured product, a land for sale in a green home town with a rich environment such as schools and hospitals. This lot is divided into multiple lots and you can buy as many as you like, but the shape of the land with the lots you buy must be rectangular (including squares)....
0
{"tests": "{\"inputs\": [\"10 3\\n0\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n1 5 7\\n0 2 5\\n1 5 7\", \"10 10\\n289383\\n930886\\n692777\\n636915\\n747793\\n238335\\n885386\\n760492\\n516649\\n641421\\n2 7 368690\\n1 3 6\\n0 2 6\\n1 1 8\\n0 2 9\\n2 2 665123\\n1 5 9\\n0 2 8\\n2 7 961393\\n1 1 2\", \"10 3\\n0\\n1\\n2\\n3\\n...
Given n numbers a0, a1, ..., an-1 and q. I want you to perform appropriate processing for q queries. The query has the following three types of operations. * Shift the value Given a pair of l and r. (l <r) Circular shift the value from al to ar. 0 1 2 3 4 5 6 7 8 9 Is given the query l = 2, r = 5. The shifted numb...
0
{"tests": "{\"inputs\": [\"4 5 1 3 4\\n1 2 5\\n2 3 5\\n2 4 5\\n1 3 8\\n1 4 8\\n0 0 0 0 0\", \"4 5 1 3 4\\n1 2 5\\n2 3 9\\n2 4 5\\n1 3 8\\n1 4 8\\n0 0 0 0 0\", \"4 5 1 3 4\\n1 2 5\\n2 3 9\\n2 4 5\\n1 3 3\\n1 4 8\\n0 0 0 0 0\", \"6 5 1 3 4\\n1 2 5\\n4 3 5\\n2 3 5\\n1 3 8\\n1 4 8\\n0 0 0 0 0\", \"4 5 1 3 4\\n1 2 5\\n2 3 5...
In 21XX, humanity finally began a plan to relocate to Mars. Selected as the first group of immigrants to Mars, you are assigned to the Administrative Center of Mars to deal with various problems that occur on Mars. The biggest problem at the moment of the Central Bureau is securing an independent supply and demand cycl...
0
{"tests": "{\"inputs\": [\"6\\nonetwo2\\n-\\nonetwo1\\nonetwo2\\n-\\nonetwo1\\n7\\nv\\ntopbottom2\\nonetwo2\\n-\\nonetwo1\\ntopbottom1\\n-\\n6\\nbaz2\\nfoo2\\nbaz1v\\nbar2\\nfoo1\\nbar1\\n0\", \"6\\nonetwo2\\n-\\nonetwo1\\nonetwo2\\n-\\nonetwo1\\n7\\nv\\ntopbottom2\\nonetwo2\\n-\\nonetwo1\\ntopbottom1\\n-\\n6\\nbaz2\\n...
Taro, a junior high school student, is working on his homework. Today's homework is to read Chinese classic texts. As you know, Japanese language shares the (mostly) same Chinese characters but the order of words is a bit different. Therefore the notation called "returning marks" was invented in order to read Chinese ...
0
{"tests": "{\"inputs\": [\"3 2\\n3 1 5\\n2 4\", \"3 2\\n3 1 5\\n2 5\", \"3 2\\n2 1 5\\n2 5\", \"3 2\\n2 1 3\\n2 5\", \"3 2\\n2 2 3\\n2 5\", \"3 1\\n2 4 3\\n2 5\", \"3 2\\n2 4 3\\n2 4\", \"3 2\\n1 4 3\\n2 4\", \"3 2\\n1 4 3\\n4 5\", \"3 2\\n0 4 3\\n4 1\", \"3 1\\n0 4 3\\n4 1\", \"3 1\\n0 0 3\\n4 2\", \"3 1\\n0 1 3\\n4 2...
H: Mercy Santa Claus found a group doing programming even though it was Christmas. Santa Claus felt sorry for them, so he decided to give them a cake. There are $ N $ types of cream, and the taste is $ A_1, A_2, A_3, \ dots, A_N $. There are $ M $ types of sponges, and the taste is $ B_1, B_2, B_3, \ dots, B_M $. ...
0
{"tests": "{\"inputs\": [\"4\\n1 2 3 4\\n2\\n2 4\", \"4\\n1 2 3 4\\n3\\n1 2 5\", \"4\\n1 2 3 0\\n2\\n2 4\", \"4\\n1 2 4 1\\n2\\n1 4\", \"4\\n1 2 3 4\\n3\\n1 0 5\", \"4\\n1 2 3 0\\n2\\n1 4\", \"4\\n1 2 3 8\\n3\\n1 0 5\", \"4\\n1 2 3 1\\n2\\n1 4\", \"4\\n1 2 3 8\\n3\\n1 0 8\", \"4\\n1 2 3 8\\n4\\n1 0 8\", \"4\\n1 2 4 1\\...
For given two sequneces $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$, determine whether all elements of $B$ are included in $A$. Note that, elements of $A$ and $B$ are sorted by ascending order respectively. Constraints * $1 \leq n, m \leq 200,000$ * $-1,000,000,000 \leq a_0 < a_1 < ... <...
0.875
{"tests": "{\"inputs\": [\"7\\n1 5 7 8 10 3 1\\n\", \"19\\n3 3 7 9 8 8 8 8 7 7 7 7 5 3 3 3 3 8 8\\n\", \"5\\n1 1 4 2 2\\n\", \"20\\n5 3 3 2 5 5 3 3 5 1 2 5 1 3 3 4 2 5 5 5\\n\", \"1\\n50\\n\", \"100\\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4...
Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a_1, a_2, …, a_n of key numbers: the more a number is, the closer it is to the right end of the piano keyboard. Paul is very clever and knows that the essential thing is...
0
{"tests": "{\"inputs\": [\"5 10\\n3 1 4 2 4\\n\", \"10 10\\n9 1 1 1 1 1 1 1 1 1\\n\", \"5 7\\n2 3 5 4 1\\n\", \"1 2\\n2\\n\", \"2 1\\n1 1\\n\", \"1 1\\n1\\n\", \"100 2000\\n31 21 8 4 15 6 3 20 22 16 47 14 35 1 21 22 15 26 19 21 17 44 7 1 15 40 45 22 2 30 46 1 20 90 56 28 24 65 43 8 9 12 38 1 47 8 13 35 20 47 12 8 24 6 ...
Alyona has recently bought a miniature fridge that can be represented as a matrix with h rows and 2 columns. Initially there is only one shelf at the bottom of the fridge, but Alyona can install arbitrary number of shelves inside the fridge between any two rows. A shelf is two cells wide, does not occupy any space but ...
0
{"tests": "{\"inputs\": [\"WORD\\n\", \"APRILFOOL\\n\", \"JUROR\\n\", \"NEAT\\n\", \"CODER\\n\", \"YES\\n\", \"AI\\n\", \"BRIGHT\\n\", \"SOURPUSS\\n\", \"SUSHI\\n\", \"WAYS\\n\", \"DODO\\n\", \"STATUSQUO\\n\", \"KHAKI\\n\", \"WEEVIL\\n\", \"WAXY\\n\", \"CROUP\\n\", \"BURG\\n\", \"PUZZLES\\n\", \"PHRASE\\n\", \"QUA\\n\"...
Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input NEAT Output YES Input WORD Output NO Input CODER Output NO Input APRILFOOL Output NO Input AI O...
0
{"tests": "{\"inputs\": [\"10 10\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n1 10\\n\", \"2 5\\n3 1 2 3\\n3 3 4 5\\n\", \"4 4\\n2 1 2\\n2 2 3\\n2 3 4\\n2 4 1\\n\", \"3 10\\n4 6 10 1 9\\n9 6 1 8 10 4 9 5 7 2\\n8 3 10 6 8 2 4 5 1\\n\", \"10 100\\n4 51 22 73 78\\n1 52\\n5 49 74 100 14 80\\n1 6\\n2 98 65\\n5 79...
Dora the explorer has decided to use her money after several years of juicy royalties to go shopping. What better place to shop than Nlogonia? There are n stores numbered from 1 to n in Nlogonia. The i-th of these stores offers a positive integer a_i. Each day among the last m days Dora bought a single integer from s...
0.5
{"tests": "{\"inputs\": [\"7 15\\n1 2 3 4 5 6 7\\n\", \"5 100\\n80 40 40 40 60\\n\", \"14 70\\n2 8 10 1 10 6 10 6 9 4 10 10 10 9\\n\", \"10 50\\n9 9 9 9 9 9 9 9 9 9\\n\", \"3 299\\n100 100 100\\n\", \"19 95\\n1 9 5 5 9 8 9 6 3 7 1 1 6 7 4 4 4 2 10\\n\", \"17 85\\n1 2 10 3 10 9 1 6 6 5 9 2 10 1 3 3 7\\n\", \"2 100\\n1 9...
The only difference between easy and hard versions is constraints. A session has begun at Beland State University. Many students are taking exams. Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following: *...
0.5
{"tests": "{\"inputs\": [\"3 4\\n4 6\\n10 -2\\n8 -1\\n\", \"3 2\\n300 -300\\n1 299\\n1 123\\n\", \"5 20\\n45 -6\\n34 -15\\n10 34\\n1 27\\n40 -45\\n\", \"20 1000\\n29531 141\\n29892 277\\n29544 141\\n29825 -194\\n29846 164\\n29595 25\\n28975 -249\\n29926 -108\\n29920 -99\\n29232 -238\\n29892 -284\\n29757 270\\n29828 122...
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is r units. Some very rich customers asked him to complete some projects for their companies. To complete ...
0
{"tests": "{\"inputs\": [\"5 7\\n2 2 8 6 9\\n1 2\\n1 3\\n2 4\\n3 2\\n4 5\\n2 5\\n1 5\\n2\\n\", \"10 12\\n1 7 1 9 3 3 6 30 1 10\\n1 2\\n1 3\\n3 5\\n5 7\\n2 3\\n5 4\\n6 9\\n4 6\\n3 7\\n6 8\\n9 4\\n9 10\\n6\\n\", \"3 2\\n1 1335 2\\n2 1\\n3 2\\n2\\n\", \"28 31\\n0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 2 1 0 1 0 0 1 1 1 0\\n9 7...
Alex decided to go on a touristic trip over the country. For simplicity let's assume that the country has n cities and m bidirectional roads connecting them. Alex lives in city s and initially located in it. To compare different cities Alex assigned each city a score w_i which is as high as interesting city seems to A...
0
{"tests": "{\"inputs\": [\"1\\n4\\nPPAP\\n\", \"3\\n12\\nAPPAPPPAPPPP\\n3\\nAAP\\n3\\nPPA\\n\", \"10\\n1\\nA\\n1\\nP\\n2\\nAP\\n2\\nPA\\n8\\nPPPPAPPP\\n8\\nPPPPPPPA\\n8\\nAPPPPPPP\\n8\\nPPPPPPAP\\n8\\nPPPPPAPP\\n8\\nPPPAPPPP\\n\", \"16\\n4\\nPPPP\\n4\\nAPPP\\n4\\nPAPP\\n4\\nAAPP\\n4\\nPPAP\\n4\\nAPAP\\n4\\nPAAP\\n4\\nA...
It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another. Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P": * "A" corresponds to an angry...
0.5
{"tests": "{\"inputs\": [\"5 5 2\\n2 0 2\\n1 0 3 4\\n2 2 4\\n1 0 1 3\\n2 4 2\\n\", \"5 5 2\\n2 0 2\\n1 0 1 4\\n2 2 4\\n1 0 1 3\\n2 4 2\\n\", \"5 10 2\\n2 0 2\\n1 0 3 4\\n2 2 4\\n1 0 1 3\\n2 4 2\\n\", \"1 5 2\\n2 0 2\\n1 0 1 4\\n2 2 4\\n1 0 1 3\\n2 4 2\\n\", \"1 5 4\\n2 0 2\\n1 0 1 4\\n7 2 4\\n1 0 1 3\\n2 4 1\\n\", \"1 ...
You are given a rooted tree. Each vertex contains a_i tons of gold, which costs c_i per one ton. Initially, the tree consists only a root numbered 0 with a_0 tons of gold and price c_0 per ton. There are q queries. Each query has one of two types: 1. Add vertex i (where i is an index of query) as a son to some ver...
0.25
{"tests": "{\"inputs\": [\"3\\n3 3 2\\n\", \"7\\n2 3 1 3 4 4 1\\n\", \"9\\n2 5 6 7 4 1 9 6 8\\n\", \"7\\n3 1 2 5 6 7 4\\n\", \"7\\n2 3 1 3 4 4 1\\n\", \"20\\n20 10 16 14 9 20 6 20 14 19 17 13 16 13 14 8 8 8 8 19\\n\", \"2\\n2 1\\n\", \"3\\n2 3 1\\n\", \"5\\n5 3 5 2 3\\n\", \"4\\n2 4 4 3\\n\", \"100\\n13 71 16 92 25 53 ...
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
0
{"tests": "{\"inputs\": [\"2\\n10\\n79\\n\", \"10\\n630\\n624\\n85\\n955\\n757\\n841\\n967\\n377\\n932\\n309\\n\", \"10\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"10\\n392\\n605\\n903\\n154\\n293\\n383\\n422\\n717\\n719\\n896\\n\", \"10\\n447\\n806\\n891\\n730\\n371\\n351\\n7\\n102\\n394\\n549\\n\", \"10\\n317\\n3...
Yaroslav likes algorithms. We'll describe one of his favorite algorithms. 1. The algorithm receives a string as the input. We denote this input string as a. 2. The algorithm consists of some number of command. Сommand number i looks either as si >> wi, or as si <> wi, where si and wi are some possibly empty strin...
0
{"tests": "{\"inputs\": [\"4 9\\n1 4 3\\n2 4\\n3 3 1\\n1 2 3\\n2 2\\n3 1 2\\n1 3 1\\n2 2\\n3 1 3\\n\", \"5 10\\n1 2 1\\n1 3 2\\n2 3\\n1 4 3\\n1 5 4\\n2 5\\n3 1 2\\n2 5\\n2 5\\n2 5\\n\", \"10 10\\n2 9\\n1 2 1\\n1 3 2\\n3 1 1\\n3 1 1\\n2 3\\n3 1 1\\n3 1 1\\n3 1 2\\n3 1 1\\n\", \"5 10\\n2 1\\n1 1 2\\n1 2 3\\n2 1\\n3 2 2\\...
There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place: * either employee y became the boss of employee x (at that, employee x didn't have a bos...
0.625
{"tests": "{\"inputs\": [\"16\\n1 1\\n1 5\\n3 5\\n3 7\\n2 7\\n2 9\\n6 9\\n6 7\\n5 7\\n5 3\\n4 3\\n4 4\\n3 4\\n3 2\\n5 2\\n5 1\\n1 1\\n\", \"6\\n0 0\\n0 1\\n1 1\\n1 2\\n2 2\\n2 0\\n0 0\\n\", \"24\\n-10000 -10000\\n-10000 9998\\n9998 9998\\n9998 -10000\\n-6364 -10000\\n-6364 6362\\n6362 6362\\n6362 -6364\\n-2728 -6364\\n...
Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the Ox axis from west to east, and th...
0.375
{"tests": "{\"inputs\": [\"7 3\\nabb 2\\naaa -3\\nbba -1\\nzyz -4\\nabb 5\\naaa 7\\nxyx 4\\n\", \"2 5\\nabcde 10000\\nabcde 10000\\n\", \"3 1\\na 1\\na 2\\na 3\\n\", \"10 10\\nnjxbzflaka -1\\nfelbvvtkja 6\\ngxiuztqkcw 5\\naomvscmtti 6\\njsqmkoyuca -2\\nwckqtzuixg 5\\najktvvblef -5\\nittmcsvmoa -1\\nakalfzbxjn 10\\nacuy...
Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them presented to him a string si having the same length n. We denote the beauty of the i-th string by ai. It can happen that ai is negative — that means that Santa doesn't find this s...
0
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5\\n1 2\\n2 3\\n3 4\\n4 5\\n\", \"5\\n1 2 7 6 7\\n1 5\\n5 3\\n3 4\\n2 4\\n\", \"7\\n38 -29 87 93 39 28 -55\\n1 2\\n2 5\\n3 2\\n2 4\\n1 7\\n7 6\\n\", \"2\\n999999999 1000000000\\n2 1\\n\", \"5\\n-1 -1000000000 -1 -2 -1\\n5 2\\n1 2\\n3 2\\n4 1\\n\", \"3\\n-1000000000 -999999999 -100...
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. <image> There are n banks, numbered from 1 to n. There are also n - 1 wires connecting the ...
0
{"tests": "{\"inputs\": [\"5 6 3\\n1 2 3 4 5\\n1 2 3 4 5 6\\n1 1 10\\n1 1 -9\\n1 5 -1\\n\", \"1 1 1\\n937982044\\n179683049\\n1 1 821220804\\n\", \"1 1 1\\n937982044\\n15017817\\n1 1 821220804\\n\", \"5 6 3\\n1 2 3 4 5\\n2 2 3 4 5 6\\n1 1 10\\n1 1 -9\\n1 5 -1\\n\", \"1 1 1\\n289198726\\n15017817\\n1 1 821220804\\n\", \...
Dr. Evil is interested in math and functions, so he gave Mahmoud and Ehab array a of length n and array b of length m. He introduced a function f(j) which is defined for integers j, which satisfy 0 ≤ j ≤ m - n. Suppose, ci = ai - bi + j. Then f(j) = |c1 - c2 + c3 - c4... cn|. More formally, <image>. Dr. Evil wants Ma...
0.75
{"tests": "{\"inputs\": [\"2\\n2 4\\n1 2\\n\\nSAMPLE\", \"10\\n538 29108 5606 27262 6813 27707 20066 27675 10965 14760 \\n1338 2767 2817 2255 2088 3969 795 1296 1624 793\", \"10\\n538 29108 5606 27262 6813 27707 20066 11993 10965 14760 \\n1338 2767 2817 2255 2088 3969 795 1296 1624 793\", \"2\\n2 2\\n1 2\\n\\nSAMPLE\",...
It has been truly said that love is not meant for everyone. Let me introduce you to a very sad story of my friend Broken Amit. Yes several times he has been left heartbroken. Looking at his poor condition even God is pity on him. God has given Amit a very nice opportunity to Kiss as many girls as he likes . There ar...
0
{"tests": "{\"inputs\": [\"2\\n1 1 4\\n7 3 5\\n\\nSAMPLE\", \"2\\n1 1 4\\n7 3 5\", \"2\\n1 1 4\\n7 4 5\", \"2\\n1 1 4\\n6 2 0\\n\\nSAMPLE\", \"2\\n1 0 4\\n6 1 1\\n\\nELOMAS\", \"2\\n1 1 4\\n6 2 -1\\n\\nSAMPLE\", \"2\\n1 1 1\\n6 1 0\\n\\nSAMPLE\", \"2\\n1 0 1\\n6 1 1\\n\\nELOMAS\", \"2\\n1 1 8\\n6 2 1\\n\\nELOMAS\", \"2...
An infinite army of ants is marching on an infinite 2-D plane. Since ants are disciplined, here's how they march: each ant chooses exactly one x coordinate and moves along it in positive y direction, starting from (x, 0). There exists exactly one ant for each x coordinate on that plane and hence there are infinite ants...
0.5
{"tests": "{\"inputs\": [\"2\\n1\\n6\\n2\\n5 8\\n\\nSAMPLE\", \"2\\n1\\n6\\n2\\n10 8\\n\\nSAMPLE\", \"2\\n1\\n6\\n2\\n10 5\\n\\nSAMPLE\", \"2\\n1\\n6\\n2\\n5 8\\n\\nS@MPLE\", \"2\\n1\\n6\\n2\\n10 3\\n\\nSAMPLE\", \"2\\n1\\n6\\n2\\n10 6\\n\\nSAMPLD\", \"2\\n1\\n9\\n2\\n10 3\\n\\nSAMPLE\", \"2\\n1\\n4\\n2\\n10 5\\n\\nRAM...
Oz and nakul have N robots, and they want to assign a distinct integer to each robot so that they can easily identify them. Also robots have already expressed their preferences to Oz and nakul. The k-th robot wants an integer between 1 and MAX[k], inclusive. Oz and nakul must obey the preferences of all their robots. N...
0
{"tests": "{\"inputs\": [\"27\\n18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49\", \"5\\n-1000 -100 -10 0 10\", \"6\\n1 2 3 4 5 6\", \"10\\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\", \"27\\n18 -28 18 28 -...
Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. ...
0.125
{"tests": "{\"inputs\": [\"201920181\\n\", \"3121\\n\", \"1000000000000000000000000000000000\\n\", \"6\\n\", \"11\\n\", \"13\\n\", \"31\\n\", \"1670000\\n\", \"10\\n\", \"10000170\\n\", \"4\\n\", \"12\\n\", \"14139582796\\n\", \"604500\\n\", \"40041\\n\", \"22\\n\", \"24\\n\", \"2812886\\n\", \"1872104158\\n\", \"44341...
Polycarp likes numbers that are divisible by 3. He has a huge number s. Polycarp wants to cut from it the maximum number of numbers that are divisible by 3. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after m such cuts, there will be m+1 parts in total. Poly...
0
{"tests": "{\"inputs\": [\"7\\n4 1 2 2 1 5 3\\n\", \"4\\n1 1 1 1\\n\", \"11\\n-5 -4 -3 -2 -1 0 1 2 3 4 5\\n\", \"100\\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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 ...
This problem is given in two editions, which differ exclusively in the constraints on the number n. You are given an array of integers a[1], a[2], ..., a[n]. A block is a sequence of contiguous (consecutive) elements a[l], a[l+1], ..., a[r] (1 ≤ l ≤ r ≤ n). Thus, a block is defined by a pair of indices (l, r). Find a...
0
{"tests": "{\"inputs\": [\"4\\n5 2\\n00000\\n00111\\n1 5\\n1 3\\n2 1\\n00\\n01\\n1 2\\n10 6\\n1111111111\\n0110001110\\n1 10\\n5 9\\n7 10\\n1 7\\n3 5\\n6 10\\n5 2\\n10000\\n11000\\n2 5\\n1 3\\n\", \"1\\n4 1\\n0011\\n0011\\n1 4\\n\", \"1\\n4 1\\n0011\\n0111\\n1 4\\n\", \"1\\n4 1\\n0011\\n0011\\n4 4\\n\", \"4\\n5 2\\n000...
Nezzar has a binary string s of length n that he wants to share with his best friend, Nanako. Nanako will spend q days inspecting the binary string. At the same time, Nezzar wants to change the string s into string f during these q days, because it looks better. It is known that Nanako loves consistency so much. On th...
0.25
{"tests": "{\"inputs\": [\"2\\n4\\n0 1\\n0 2\\n2 3\\n2\\n1 0\\n\", \"2\\n4\\n0 1\\n1 2\\n2 3\\n2\\n1 0\\n\", \"2\\n4\\n0 1\\n1 2\\n1 3\\n2\\n1 0\\n\", \"2\\n4\\n0 1\\n1 2\\n0 3\\n2\\n1 0\\n\", \"2\\n4\\n0 1\\n0 2\\n0 3\\n2\\n1 0\\n\", \"2\\n4\\n0 1\\n1 3\\n2 3\\n2\\n1 0\\n\", \"2\\n4\\n0 3\\n1 2\\n2 3\\n2\\n1 0\\n\", \...
You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (including end points) is k. The MEX of a sequence of integers is the smallest non-n...
0
{"tests": "{\"inputs\": [\"9\\n\", \"4\\n\", \"6\\n\", \"89\\n\", \"15\\n\", \"91\\n\", \"76\\n\", \"80\\n\", \"96\\n\", \"72\\n\", \"79\\n\", \"5\\n\", \"74\\n\", \"97\\n\", \"47\\n\", \"50\\n\", \"3\\n\", \"7\\n\", \"94\\n\", \"20\\n\", \"75\\n\", \"66\\n\", \"46\\n\", \"14\\n\", \"71\\n\", \"22\\n\", \"81\\n\", \"56...
Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j. L...
0
{"tests": "{\"inputs\": [\"2\\n\", \"3\\n\", \"1\\n\", \"14\\n\", \"38\\n\", \"25\\n\", \"22\\n\", \"26\\n\", \"20\\n\", \"34\\n\", \"8\\n\", \"32\\n\", \"16\\n\", \"30\\n\", \"28\\n\", \"18\\n\", \"37\\n\", \"10\\n\", \"39\\n\", \"35\\n\", \"15\\n\", \"27\\n\", \"12\\n\", \"31\\n\", \"24\\n\", \"5\\n\", \"19\\n\", \"6...
Consider the following equation: <image> where sign [a] represents the integer part of number a. Let's find all integer z (z > 0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means that there are no such positive integers x and y (x, y > 0), for which the ...
0
{"tests": "{\"inputs\": [\"11\\n.RRRLLLLL..\\n\", \"9\\n..RRLL...\\n\", \"13\\n....LLLLLL...\\n\", \"3\\n.L.\\n\", \"3\\n.R.\\n\", \"4\\n.RL.\\n\", \"17\\n.......RRRRR.....\\n\", \"13\\n...LLLLLL....\\n\", \"17\\n.....RRRRR.......\\n\", \"4\\n..RL\\n\", \"17\\n......RRRRR......\\n\"], \"outputs\": [\"2 4\\n\", \"3 4\\n...
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint ...
0
{"tests": "{\"inputs\": [\"ABBBCBDB\\n\", \"ABRACADABRA\\n\", \"AB\\n\", \"ABACBCABACACB\\n\", \"ZZ\\n\", \"THISISTHELASTTEST\\n\", \"ABBCDEFB\\n\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\\n\", \"THISISATEST\\n\", \"LEHLLLLLLHAFGEGLLHAFDLHHLLLLLDGGEHGGHLLLLLLLLDFLCBLLEFLLCBLLCGLEDLGGLECLDGLEHLLLGELLLEGLLLLGDLLLDALD\\n\", \"Z\\n\...
You will receive 5 points for solving this problem. Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using t...
0
{"tests": "{\"inputs\": [\"2 2\\n1 2\\n2 1\\n\", \"2 2\\n1 2\\n2 0\\n\", \"2 3\\n1 2 3\\n2 3 4\\n\", \"2 2\\n0 2\\n2 1\\n\", \"1 1\\n3\\n\", \"3 2\\n3 0\\n1 3\\n3 1\\n\", \"2 2\\n2 1\\n0 2\\n\", \"2 2\\n0 1000000000\\n1000000000 57\\n\", \"2 2\\n2 0\\n1 2\\n\", \"2 3\\n1 3 3\\n3 0 1\\n\", \"3 2\\n3 1\\n3 0\\n1 3\\n\", ...
Vasya had two arrays consisting of non-negative integers: a of size n and b of size m. Vasya chose a positive integer k and created an n × m matrix v using the following formula: <image> Vasya wrote down matrix v on a piece of paper and put it in the table. A year later Vasya was cleaning his table when he found a p...
0
{"tests": "{\"inputs\": [\"1 0\\nc\\nb\\n\", \"3 2\\nabc\\nxyc\\n\", \"1 0\\nz\\nz\\n\", \"2 2\\nbb\\ncb\\n\", \"1 1\\na\\nc\\n\", \"20 2\\nywpcwcwgkhdeonzbeamf\\ngdcmwcwgkhdeonzbeamf\\n\", \"5 2\\nabaac\\nbbbaa\\n\", \"3 1\\nlos\\nlns\\n\", \"7 4\\nycgdbph\\nfdtapch\\n\", \"10 6\\nrnsssbuiaq\\npfsbsbuoay\\n\", \"5 1\\...
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ...
0
{"tests": "{\"inputs\": [\"4 26\\nbear\\n\", \"2 7\\naf\\n\", \"3 1000\\nhey\\n\", \"10 100\\naddaiyssyp\\n\", \"2 49\\nzz\\n\", \"2 1\\nzz\\n\", \"1 24\\ny\\n\", \"4 17\\nrzsq\\n\", \"1 24\\nz\\n\", \"2 48\\nab\\n\", \"1 8\\nc\\n\", \"5 24\\nizrqp\\n\", \"1 25\\na\\n\", \"1 25\\nz\\n\", \"1 26\\na\\n\", \"2 9\\nbc\\n\...
Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only. The distance between two letters is defined as the difference between their positions in the alphabet. For example, <image>, and <image>. Also, the distance between two nice strings is defined as t...
0.125
{"tests": "{\"inputs\": [\"2\\n0 0\\n0 0\", \"3\\n0 0 0\\n2 7 0\\n0 0 4\\n3 0 8\\n0 5 4\", \"3\\n0 0 0\\n0 0 0\\n0 0 0\\n\", \"3\\n0 3 2\\n5 0 7\\n4 8 0\\n\", \"2\\n0 238487454\\n54154238 0\\n\", \"2\\n0 0\\n0 0\\n\", \"3\\n0 0 0\\n0 0 1\\n0 0 0\\n\", \"2\\n0 238487454\\n98139073 0\\n\", \"2\\n0 0\\n1 0\\n\", \"2\\n1 0...
This is an interactive problem. In the interaction section below you will see the information about flushing the output. In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden n by n matrix M. Let Mi, j denote the entry i-th row and j-th column of the matrix. The rows and col...
0
{"tests": "{\"inputs\": [\"3 2\\nNO NO\\n\", \"9 8\\nYES NO\\n\", \"8 3\\nNO NO YES YES YES NO\\n\", \"10 5\\nYES NO YES NO YES NO\\n\", \"30 2\\nYES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES\\n\", \"3 2\\nYES YES\\n\", \"8 3\\nYES NO YES NO YES NO\\...
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?). A group of soldiers is effective if and only if their names...
0
{"tests": "{\"inputs\": [\"5 2\\n50 110 130 40 120\\n\", \"4 1\\n2 3 4 1\\n\", \"24 4\\n33 27 12 65 19 6 46 33 57 2 21 50 73 13 59 69 51 45 39 1 6 64 39 27\\n\", \"10 4\\n810 8527 9736 3143 2341 6029 7474 707 2513 2023\\n\", \"11 3\\n412 3306 3390 2290 1534 316 1080 2860 253 230 3166\\n\", \"2 2\\n1 1000000000\\n\", \"...
Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo i has a contrast vi. In order for the processing to be truly of high quality, the application must receive at least k photos with contrasts which differ as little as possible. Evlampiy already k...
0
{"tests": "{\"inputs\": [\"2 1\\n\", \"2 4\\n\", \"100 1\\n\", \"100 3\\n\", \"101 1\\n\", \"4 100\\n\", \"3 1\\n\", \"3 3\\n\", \"4 101\\n\", \"3 2\\n\", \"101 4\\n\", \"1 1\\n\", \"2 101\\n\", \"2 2\\n\", \"1 101\\n\", \"1 2\\n\", \"101 2\\n\", \"3 101\\n\", \"4 2\\n\", \"1 100\\n\", \"4 1\\n\", \"3 100\\n\", \"101 3...
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating." The class can be represented as a matrix with n rows and m col...
0
{"tests": "{\"inputs\": [\"10 8\\n10 13 15 16 17 19 20 22 24 25\\n\", \"4 4\\n1 3 5 7\\n\", \"3 1\\n2 5 10\\n\", \"5 3\\n4 6 8 9 10\\n\", \"3 5\\n1 2 10\\n\", \"5 2\\n4 6 8 9 10\\n\", \"5 1000000000\\n1 2 3 999999999 1000000000\\n\", \"30 5\\n102 104 105 107 108 109 110 111 116 118 119 122 127 139 140 142 145 157 166 1...
An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme. Three distinct states i, j and k are selected, where i < j < k. After that the following process happens: ...
0.375
{"tests": "{\"inputs\": [\"1\\nBC\\nDA\\n\\nSAMPLE\", \"10\\nIAADIGED\\nFGAAAJFH\\nGAEDDHCD\\nICICDCDH\\nJAAHBJGH\\nFBEIIJBE\\nAEHAHAHD\\nEIAHJCDJ\\nGEGEEDGE\\nHEJJIHFA\\nAHJHHGEC\\nGEDBGBAE\\nGBIFIIIB\\nCBHJDAGG\\nABJCCJBC\\nFHEDFDBD\\nEAAHFJEB\\nBBEFGDBB\\nJCGHCGHG\\nAGCEDGGA\", \"10\\nIAADIGED\\nFGAAAJFH\\nGAEDDHCD\...
Again a simple task from Oz! He has given you two strings STR1 and STR2. Each character of both strings is from the set {A, B, C, D, E, F, G, H, I, J}. You can perform 3 types of conversions on string STR1 : Replace a character(except 'J') by next character from the set. i.e "ABE" to "ACE" Replace a character(excep...
0
{"tests": "{\"inputs\": [\"hack\\n\\nSAMPLE\", \"hack\", \"hkca\", \"hkba\", \"hjca\\n\\nSAMPLE\", \"hbka\", \"hbkb\", \"hbjb\", \"bkbh\", \"bkbi\", \"bibk\", \"ackh\\n\\nELNPAR\", \"aibk\", \"acki\\n\\nELNPAR\", \"bkci\", \"bkch\", \"ackj\\n\\nELNPBR\", \"ckbh\", \"hbkc\", \"hkbc\", \"jkca\\n\\nRBPNLD\", \"hlbc\", \"c...
After a furious battle Pirate Jack won a battle against Captain Luthur. Pirate Jack found a golden chest from Luthur's treasures. But the problem is that Luthur's coders have locked this chest. You have found the function which Luthurs Coders wrote to lock this chest: void hack(string s) { for(int i = s.length()-1...
0.25
{"tests": "{\"inputs\": [\"3\\n8 3\\n0 1\\n4 8\", \"1\\n1 1\", \"2\\n1 2\\n3 2\", \"2\\n1 3\\n3 1\", \"1\\n0 0\", \"2\\n1 5\\n5 1\", \"3\\n8 3\\n-1 1\\n5 8\", \"2\\n0 2\\n3 1\", \"2\\n0 1\\n3 2\", \"2\\n1 4\\n5 2\", \"3\\n8 3\\n-1 0\\n4 8\", \"1\\n2 2\", \"1\\n-1 -1\", \"2\\n1 0\\n1 2\", \"2\\n2 3\\n2 1\", \"1\\n3 3\",...
You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, ter...
0
{"tests": "{\"inputs\": [\"3\\n2 5\\n6 1\\n3 7\", \"4\\n3 7\\n2 9\\n8 16\\n10 8\", \"3\\n2 5\\n6 1\\n3 13\", \"4\\n3 7\\n2 9\\n8 17\\n10 8\", \"4\\n3 7\\n2 9\\n8 6\\n10 8\", \"4\\n3 7\\n2 9\\n8 6\\n10 11\", \"3\\n2 2\\n4 1\\n5 13\", \"4\\n0 7\\n2 9\\n8 33\\n10 2\", \"4\\n6 7\\n2 9\\n9 2\\n10 0\", \"3\\n2 2\\n0 0\\n5 18...
Takahashi is an expert of Clone Jutsu, a secret art that creates copies of his body. On a number line, there are N copies of Takahashi, numbered 1 through N. The i-th copy is located at position X_i and starts walking with velocity V_i in the positive direction at time 0. Kenus is a master of Transformation Jutsu, an...
0
{"tests": "{\"inputs\": [\"abc\", \"aba\", \"abcab\", \"abb\", \"aaa\", \"baa\", \"bacba\", \"bba\", \"badba\", \"aa`\", \"aab\", \"cadba\", \"`aa\", \"bca\", \"dadba\", \"`ab\", \"acb\", \"ddaba\", \"``b\", \"aca\", \"dd`ba\", \"`_b\", \"bb`\", \"dd`b`\", \"b_`\", \"`bb\", \"ddb``\", \"c_`\", \"`cb\", \"ddba`\", \"`_c...
There is a string s of length 3 or greater. No two neighboring characters in s are equal. Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first: * Remove one of the characters in s, excluding both ends. However, a character cannot b...
0
{"tests": "{\"inputs\": [\"3\", \"10\", \"1\", \"2\", \"16\", \"0\", \"9\", \"-2\", \"4\", \"-4\", \"5\", \"8\", \"-7\", \"-13\", \"-8\", \"-11\", \"13\", \"14\", \"-16\", \"-18\", \"11\", \"-21\", \"-37\", \"-19\", \"24\", \"-38\", \"-27\", \"44\", \"-47\", \"-48\", \"-78\", \"-33\", \"-73\", \"-57\", \"-123\", \"28\"...
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total? Constraints * 1≦N≦100 Input The input is given from Standard Inpu...
0.875
{"tests": "{\"inputs\": [\"2 1 0 5\\n3 1 1 3\\n2 2 1 3\\n0 0 0 0\", \"2 1 0 5\\n3 1 2 3\\n2 2 1 3\\n0 0 0 0\", \"2 1 0 5\\n3 1 2 0\\n2 2 1 3\\n0 0 0 0\", \"2 1 0 5\\n3 1 2 6\\n2 2 1 3\\n0 0 0 0\", \"2 1 0 7\\n3 1 0 0\\n2 2 1 3\\n0 0 0 0\", \"2 1 0 1\\n2 1 0 0\\n2 2 1 3\\n0 0 0 0\", \"2 1 -1 5\\n4 1 2 0\\n2 2 1 3\\n0 0 ...
Consider the following game. There are k pairs of n cards with numbers from 1 to n written one by one. Shuffle these kn cards well to make piles of k cards and arrange them in a horizontal row. The i-th (k-card) pile from the left of the n piles created in this way is called "mountain i". <image> The game starts at ...
0
{"tests": "{\"inputs\": [\"CBA\\ncba\\ncCa\\nX\\nZY\\nZ\\n-\", \"CBA\\ncba\\ncCa\\nX\\nYZ\\nZ\\n-\", \"CBA\\ncba\\ncCa\\nY\\nYZ\\nZ\\n-\", \"CBA\\ncca\\ncCa\\nX\\nZY\\nZ\\n-\", \"CAB\\ncba\\ncCa\\nX\\nYZ\\nZ\\n-\", \"CAB\\ncca\\ncCa\\nX\\nYZ\\nZ\\n-\", \"CAA\\ncca\\ncCa\\nX\\nYZ\\nZ\\n-\", \"CBA\\nabc\\naCc\\nX\\nZY\\n...
Nantendo Co., Ltd. has released a game software called Packet Monster. This game was intended to catch, raise, and fight monsters, and was a very popular game all over the world. This game had features not found in traditional games. There are two versions of this game, Red and Green, and the monsters that can be caug...
0
{"tests": "{\"inputs\": [\"3 5\\n###.#\\n#####\\n###..\\n4 5\\n.#.##\\n.####\\n####.\\n##.#.\\n8 8\\n.#.#.#.#\\n########\\n.######.\\n########\\n.######.\\n########\\n.######.\\n########\\n8 8\\n.#.#.#.#\\n########\\n.##.#.#.\\n##....##\\n.##.###.\\n##...###\\n.##.###.\\n###.#.##\\n4 4\\n####\\n####\\n####\\n####\\n0 0...
Amber Claes Maes, a patissier, opened her own shop last month. She decided to submit her work to the International Chocolate Patissier Competition to promote her shop, and she was pursuing a recipe of sweet chocolate bars. After thousands of trials, she finally reached the recipe. However, the recipe required high skil...
0
{"tests": "{\"inputs\": [\"4\\n1 1\\n4 2\\n2 4\\n3 4\", \"4\\n0 1\\n4 2\\n2 4\\n3 4\", \"4\\n0 1\\n4 2\\n2 1\\n3 4\", \"4\\n-1 1\\n4 3\\n1 1\\n3 4\", \"4\\n-1 1\\n4 2\\n1 1\\n3 8\", \"4\\n-1 1\\n4 4\\n1 0\\n3 8\", \"4\\n1 2\\n4 2\\n2 4\\n3 4\", \"4\\n1 2\\n4 2\\n2 4\\n3 7\", \"4\\n0 1\\n4 3\\n2 1\\n2 4\", \"4\\n-2 1\\n...
Problem statement There is a rational number sequence $ X_0, X_1, X_2, ..., X_N $. Each term is defined as follows. 1. $ X_0 = 0 $ 2. $ X_i = X_ {i-1} $ $ op_i $ $ Y_i $ ($ 1 \ leq i \ leq N $). However, $ op_i $ is $ + $, $ − $, $ × $, $ ÷ $ Either. Find $ X_N $. Constraint * $ 1 \ leq N \ leq 10 ^ 5 $ * $ 1 \...
0