info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"1 5\\n1#2#3\\n\", \"4 5\\n11..2\\n#..22\\n#.323\\n.#333\", \"10 10\\n###..#.#.#\\n#....####.\\n##1###.#.#\\n#.11######\\n##11#####.\\n..#####..#\\n####...#.3\\n.#.#..2223\\n#####..#33\\n#.########\\n\", \"3 1\\n3\\n1\\n2\\n\", \"10 10\\n##.#.##.##\\n#.#..####.\\n#.###.333.\\n..#..#3.2#\\n...#...
The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided that a road between the states should be built to guarantee so that on...
0
{"tests": "{\"inputs\": [\"67\\n\", \"17\\n\", \"3\\n\", \"1\\n\", \"6\\n\", \"99999997\\n\", \"9999995\\n\", \"2222222\\n\", \"5\\n\", \"113\\n\", \"111\\n\", \"2048\\n\", \"99999978\\n\", \"11\\n\", \"999999937\\n\", \"115\\n\", \"444\\n\", \"9999993\\n\", \"999999998\\n\", \"1024\\n\", \"99999990\\n\", \"22\\n\", \"...
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples. For example, tripl...
0.25
{"tests": "{\"inputs\": [\"5\\n8 7 4 8 3\\n4 2 5 3 7\\n\", \"10\\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\\n862552539 873867121 975802175 647540462 425058513 132645393 542726039 946723283 689442435 88379179\\n\", \"100\\n1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3...
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, b2, ..., bn] of length n each which he uses to ask people some quite p...
0
{"tests": "{\"inputs\": [\"3\\n3\\n4\\n6\\n\", \"1\\n508427854\\n\", \"1\\n827388716\\n\", \"1\\n596007358\\n\", \"10\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n10\\n\", \"1\\n322647200\\n\", \"1\\n398561321\\n\", \"1\\n212055293\\n\", \"1\\n68376796\\n\", \"1\\n256575928\\n\", \"1\\n221526930\\n\", \"10\\n1\\n2\\n3\\n4\\n5...
Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level. Ivan decided that there should be exactly ni vertices in the graph representing level i, and the edges have to be bidirectional. When c...
0
{"tests": "{\"inputs\": [\"4\\n1\\n1\\n1\\n\", \"8\\n1\\n1\\n1\\n1\\n3\\n3\\n3\\n\", \"7\\n1\\n1\\n1\\n2\\n2\\n2\\n\", \"7\\n1\\n1\\n1\\n3\\n3\\n3\\n\", \"3\\n1\\n1\\n\", \"12\\n1\\n1\\n1\\n2\\n5\\n5\\n5\\n5\\n1\\n2\\n2\\n\", \"13\\n1\\n2\\n2\\n2\\n1\\n6\\n6\\n6\\n1\\n10\\n10\\n10\\n\", \"9\\n1\\n1\\n1\\n1\\n2\\n6\\n6\...
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent. Let...
0
{"tests": "{\"inputs\": [\"6\\nRURUUR\\n\", \"1\\nU\\n\", \"7\\nURRRUUU\\n\", \"2\\nUR\\n\", \"7\\nURURRUR\\n\", \"7\\nRRRRRRR\\n\", \"2\\nUU\\n\", \"100\\nRUURUURRUURUUUUURRUUURRRRUURRURRURRRRUUUUUURRUURRRRURUUURUURURRRRRURUURRUURUURRUUURUUUUUURRUUUURUUUR\\n\", \"15\\nRUURRRRURRUUUUU\\n\", \"6\\nUURRRU\\n\", \"2\\nRU\...
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The world can be represented by the first quadrant of a plane and the wall is built along the identity line (...
0
{"tests": "{\"inputs\": [\"10 1 1\\n0 9\\n0 5\\n\", \"10 2 4\\n3 7\\n8 10\\n0 10\\n3 4\\n8 1\\n1 2\\n\", \"10 1 1\\n0 9\\n1 5\\n\", \"1 1 1\\n0 1\\n0 100000\\n\", \"10 3 3\\n0 3\\n4 8\\n9 10\\n0 89516\\n9 30457\\n2 31337\\n\", \"2000 1 1\\n0 2000\\n0 100000\\n\", \"100 50 1\\n1 2\\n3 4\\n5 6\\n7 8\\n9 10\\n11 12\\n13 1...
Polycarp lives on a coordinate line at the point x = 0. He goes to his friend that lives at the point x = a. Polycarp can move only from left to right, he can pass one unit of length each second. Now it's raining, so some segments of his way are in the rain. Formally, it's raining on n non-intersecting segments, the i...
0
{"tests": "{\"inputs\": [\"3\\n#$%\\n\\nSAMPLE\", \"10\\n<=>?@ABCDE\", \"2\\n#$\", \"10\\nEDCBA@?>=<\", \"2\\n$#\", \"3\\n#$%\\n\\nSAMPLF\", \"10\\nEDBBA@?>=<\", \"2\\n##\", \"3\\n#$%\\n\\nSFMPLA\", \"10\\n<=>?@ABBDE\", \"2\\n%#\", \"3\\n##%\\n\\nSFMPLA\", \"10\\n<=>??ABBDE\", \"2\\n#%\", \"3\\n##%\\n\\nSFMPAL\", \"10\...
Recently in a class of Computer Networks, little Roy learned to calculate Hamming Distance between two strings of equal length. During practical session, Roy's teacher gave him a string of length L with all distinct characters. Teacher asked him to find the number of permutations of the string such that the hamming di...
0.875
{"tests": "{\"inputs\": [\"3 7\\n-10 -3 0 9 -100 2 17\", \"2 5\\n10 12 1 2 14\", \"100 1\\n-100000\", \"3 7\\n-10 -1 0 9 -100 2 17\", \"100 1\\n-151489\", \"3 7\\n-8 -1 0 9 -100 2 17\", \"3 7\\n-10 -3 0 9 -100 2 18\", \"2 5\\n10 12 1 4 14\", \"6 7\\n-8 -1 0 9 -100 2 17\", \"2 5\\n10 12 1 4 21\", \"2 7\\n-8 -1 0 9 -100 ...
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: Move...
0.25
{"tests": "{\"inputs\": [\"7 5\\n2\\n1\\n1\\n3\\n2\\n1\\n2\\n-1\\n3\\n2\\n-3\", \"7 5\\n2\\n1\\n2\\n3\\n2\\n1\\n2\\n-1\\n3\\n2\\n-3\", \"7 5\\n2\\n0\\n2\\n3\\n2\\n1\\n2\\n-1\\n3\\n2\\n-3\", \"7 5\\n2\\n1\\n1\\n3\\n2\\n1\\n2\\n-1\\n1\\n2\\n-3\", \"7 5\\n2\\n1\\n1\\n0\\n2\\n1\\n2\\n-1\\n1\\n2\\n-3\", \"7 5\\n2\\n1\\n2\\n...
problem You are a traveler traveling on the JOI Highway. The JOI Highway is a road that extends straight from east to west, and there are n post towns on the JOI Highway. Numbered. The westernmost post town on the JOI highway is post town 1, and the easternmost post town is post town n. You have decided to depart fro...
0.25
{"tests": "{\"inputs\": [\"3 3\\n0 0\\n3 0\\n0 4\\n1 2\\n2 3\\n3 1\", \"6 6\\n0 0\\n0 1\\n1 0\\n30 0\\n0 40\\n30 40\\n1 2\\n2 3\\n3 1\\n4 5\\n5 6\\n6 4\", \"4 3\\n0 0\\n-100 0\\n100 0\\n0 100\\n1 2\\n1 3\\n1 4\", \"6 7\\n2 0\\n6 0\\n8 2\\n6 3\\n0 5\\n1 7\\n1 2\\n2 3\\n3 4\\n4 1\\n5 1\\n5 4\\n5 6\", \"3 3\\n0 0\\n3 0\\n...
Nicholas Y. Alford was a cat lover. He had a garden in a village and kept many cats in his garden. The cats were so cute that people in the village also loved them. One day, an evil witch visited the village. She envied the cats for being loved by everyone. She drove magical piles in his garden and enclosed the cats w...
0
{"tests": "{\"inputs\": [\"2 1 1 1 10\\n1 2 3\\n2 4\\n2 1 1 1 9\\n1 2 3\\n2 4\\n4 2 2 4 50\\n1 2 5\\n3 4 5\\n2 15\\n3 15\\n4 6 3 1 29\\n1 2 20\\n3 2 10\\n4 1 5\\n3 1 5\\n2 4 3\\n3 4 4\\n2 1\\n4 5\\n3 3\\n0 0 0 0 0\", \"2 1 1 1 10\\n1 2 3\\n2 4\\n2 1 1 1 9\\n1 2 3\\n2 4\\n4 2 2 4 50\\n1 2 5\\n3 4 5\\n2 15\\n3 7\\n4 6 3 ...
Problem Statement You are now participating in the Summer Training Camp for Programming Contests with your friend Jiro, who is an enthusiast of the ramen chain SIRO. Since every SIRO restaurant has its own tasteful ramen, he wants to try them at as many different restaurants as possible in the night. He doesn't have p...
0
{"tests": "{\"inputs\": [\"1\\n1337\\n\", \"8\\n9 4 1 7 10 1 6 5\\n1 2\\n2 3\\n1 4\\n1 5\\n5 6\\n5 7\\n5 8\\n\", \"2\\n12345 65432\\n2 1\\n\", \"1\\n617\\n\", \"8\\n9 4 1 7 10 1 1 5\\n1 2\\n2 3\\n1 4\\n1 5\\n5 6\\n5 7\\n5 8\\n\", \"8\\n9 4 1 7 10 1 1 10\\n1 2\\n2 3\\n1 4\\n1 5\\n5 6\\n5 7\\n5 8\\n\", \"8\\n9 4 1 8 10 1...
You are given a tree consisting exactly of n vertices. Tree is a connected undirected graph with n-1 edges. Each vertex v of this tree has a value a_v assigned to it. Let dist(x, y) be the distance between the vertices x and y. The distance between the vertices is the number of edges on the simple path between them. ...
0.125
{"tests": "{\"inputs\": [\"4 5\\nGWGGW\\nGGWGG\\nGWGGG\\nWGGGG\\n\", \"3 3\\nGWW\\nWWW\\nWWG\\n\", \"1 1\\nG\\n\", \"150 1\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nW\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\nG\\...
You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either gras...
0.25
{"tests": "{\"inputs\": [\"4 5\\n300 10001 20 20\\n2 1 3\\n1 1 310\\n2 1 3\\n2 3 3\\n2 3 4\\n\", \"2 1\\n100000000 200000000\\n2 1 2\\n\", \"12 1\\n1 90 100 1000 10000 100000 1000000 10000000 100000000 100000010 100000020 100000021\\n2 1 12\\n\", \"1 1\\n1\\n2 1 1\\n\", \"11 1\\n1 10 100 1000 10000 100000 1000000 10000...
Let's define a balanced multiset the following way. Write down the sum of all elements of the multiset in its decimal representation. For each position of that number check if the multiset includes at least one element such that the digit of the element and the digit of the sum at that position are the same. If that ho...
0
{"tests": "{\"inputs\": [\"4\\n1 1 2\\n2 10 4\\n5 2 3\\n3 2 2\\n\", \"1\\n99999971 99999989 2\\n\", \"1\\n12 73 200000000\\n\", \"3\\n3 7 2\\n2 9 2\\n999999937 999999929 2\\n\", \"1\\n9532069 5631144 8332312\\n\", \"5\\n1 1000000000 999999998\\n1 1000000000 999999999\\n1 1000000000 1000000000\\n1000000000 1000000000 2\...
You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor. You must paint a fence which consists of 10^{100} planks in two colors in the following way (suppose planks are numbered from ...
0
{"tests": "{\"inputs\": [\"10\\n3 5 1 3\\n0 0 1\\n2 1 4\\n2 5 2 3\\n1 0\\n3 2\\n1 20 2 4\\n0\\n16\\n6 20 2 5\\n1 1 0 1 0 0\\n0 8 2 9 11 6\\n4 16 3 6\\n1 0 1 1\\n8 3 5 6\\n6 20 3 6\\n0 1 0 0 1 0\\n20 11 3 20 16 17\\n7 17 1 6\\n1 1 0 1 0 0 0\\n1 7 0 11 10 15 10\\n6 17 2 6\\n0 0 1 0 0 1\\n7 6 3 7 10 12\\n5 17 2 5\\n1 1 1 ...
Petya has come to the math exam and wants to solve as many problems as possible. He prepared and carefully studied the rules by which the exam passes. The exam consists of n problems that can be solved in T minutes. Thus, the exam begins at time 0 and ends at time T. Petya can leave the exam at any integer time from 0...
0
{"tests": "{\"inputs\": [\"5\\na\\nabcdfdcecba\\nabbaxyzyx\\ncodeforces\\nacbba\\n\", \"1\\ndafgdwwdgfadzvovgrddrgvovz\\n\", \"1\\nzzzzzagaadeaaaaffadkkkkkkzzzzzzz\\n\", \"1\\nrdgduvvudgdrbwhlpiiplhwb\\n\", \"1\\nalahmavaaaaaaaavamhalazdadaapaohrggrhoapaadadz\\n\", \"1\\nafdamvaavarravaavmadfazeaaaaahpaiaaiaphaaaaaez\\...
This is the easy version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task. You are given a string s, consisting of lowercase English letters. Find the longest string, t, which satisfies the fol...
0
{"tests": "{\"inputs\": [\"5 6\\n\", \"3 3\\n\", \"2 2\\n\", \"2 5\\n\", \"6 5\\n\", \"5 1\\n\", \"8 5\\n\", \"9 6\\n\", \"7 1\\n\", \"3 9\\n\", \"7 3\\n\", \"4 2\\n\", \"5 2\\n\", \"8 3\\n\", \"7 4\\n\", \"4 8\\n\", \"3 5\\n\", \"1 1\\n\", \"6 4\\n\", \"2 1\\n\", \"2 8\\n\", \"2 9\\n\", \"4 5\\n\", \"9 7\\n\", \"2 4\\...
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse. He's got problems wi...
0
{"tests": "{\"inputs\": [\"3\\n3\\n2 6\\n4 1\\n5 3\\n\", \"3\\n6\\n3 2\\n5 4\\n2 4\\n\", \"2\\n4\\n2 6\\n5 4\\n\", \"96\\n4\\n1 5\\n5 1\\n6 5\\n2 1\\n2 1\\n2 6\\n6 5\\n6 5\\n6 2\\n2 6\\n1 5\\n6 5\\n1 5\\n2 6\\n6 5\\n5 6\\n2 1\\n2 6\\n1 2\\n1 5\\n2 6\\n2 6\\n2 1\\n1 5\\n5 1\\n1 2\\n2 6\\n2 6\\n6 5\\n1 5\\n2 1\\n2 6\\n1 ...
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left). <imag...
0
{"tests": "{\"inputs\": [\"15\\n1/3 2/1\\n3 1\\n6 2\\n4 2\\n2 5\\n4 5\\n6 6\\n3 4\\n1 6\\n2 1\\n7 4\\n9 3\\n5 3\\n1 3\\n15 5\\n12 4\\n\", \"5\\n0/17 74/0\\n68877 18122\\n96115 84747\\n71027 43746\\n31622 3444\\n93281 34803\\n\", \"5\\n3/18 18/17\\n49797 95131\\n5075 96918\\n91898 7865\\n91852 41070\\n12076 45049\\n\", ...
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the...
0
{"tests": "{\"inputs\": [\"2\\n1234\\n\", \"2\\n9911\\n\", \"12\\n254163163934611135461589\\n\", \"1\\n21\\n\", \"4\\n00013213\\n\", \"1\\n01\\n\", \"5\\n9823921785\\n\", \"18\\n112233445566778899112233445566778899\\n\", \"18\\n101011411002041200101000000000001000\\n\", \"15\\n051911296923361789993851872792\\n\", \"18\...
There is a new TV game on BerTV. In this game two players get a number A consisting of 2n digits. Before each turn players determine who will make the next move. Each player should make exactly n moves. On it's turn i-th player takes the leftmost digit of A and appends it to his or her number Si. After that this leftmo...
0.125
{"tests": "{\"inputs\": [\"10 3 3\\n1010100011\\n1 3\\n1 6\\n4 9\\n\", \"10 3 6\\n0010010010\\n1 3\\n4 6\\n7 9\\n1 6\\n4 9\\n1 9\\n\", \"10 1 3\\n0000000001\\n10 10\\n1 2\\n1 8\\n\", \"1 1 1\\n1\\n1 1\\n\", \"1 1 1\\n0\\n1 1\\n\", \"2 2 2\\n10\\n1 2\\n1 2\\n\", \"10 1 3\\n1111111111\\n1 7\\n2 8\\n9 9\\n\", \"10 1 3\\n1...
Inna loves sweets very much. She has n closed present boxes lines up in a row in front of her. Each of these boxes contains either a candy (Dima's work) or nothing (Sereja's work). Let's assume that the boxes are numbered from 1 to n, from left to right. As the boxes are closed, Inna doesn't know which boxes contain c...
0.875
{"tests": "{\"inputs\": [\"3\\n2 3\\n1 4\\n1 4\\n\", \"3\\n5 5\\n3 3\\n1 1\\n\", \"4\\n1 1\\n1 1\\n1 1\\n1 1\\n\", \"3\\n5 5\\n3 3\\n2 2\\n\", \"4\\n4 4\\n1 1\\n2 2\\n2 2\\n\", \"50\\n97 97\\n61 61\\n59 59\\n29 29\\n13 13\\n7 7\\n5 5\\n3 3\\n1 1\\n3 3\\n1 1\\n13 13\\n11 11\\n9 9\\n3 3\\n1 1\\n1 1\\n1 1\\n27 27\\n25 25\...
Notice that the memory limit is non-standard. Recently Arthur and Sasha have studied correct bracket sequences. Arthur understood this topic perfectly and become so amazed about correct bracket sequences, so he even got himself a favorite correct bracket sequence of length 2n. Unlike Arthur, Sasha understood the topic...
0
{"tests": "{\"inputs\": [\"7\\n-1 3\\n1 2\\n1 1\\n1 4\\n4 5\\n4 3\\n5 2\\n\", \"20\\n-1 100\\n1 35\\n1 22\\n1 28\\n1 2\\n1 8\\n1 17\\n1 50\\n5 37\\n1 25\\n1 29\\n5 21\\n4 16\\n2 39\\n1 41\\n3 28\\n3 30\\n2 36\\n2 26\\n14 17\\n\", \"2\\n-1 1\\n1 2\\n\", \"3\\n-1 1\\n1 2\\n1 3\\n\", \"4\\n-1 1\\n1 100\\n1 100\\n1 100\\n\...
One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior. We will call person a a subordinates of another person b, if either b is an immediate...
0
{"tests": "{\"inputs\": [\"7\\n\", \"3\\n\", \"82\\n\", \"720\\n\", \"1239\\n\", \"9999\\n\", \"4938\\n\", \"9562\\n\", \"6143\\n\", \"7274\\n\", \"30\\n\", \"3112\\n\", \"28\\n\", \"8865\\n\", \"5\\n\", \"2023\\n\", \"1936\\n\", \"9998\\n\", \"9798\\n\", \"4999\\n\", \"1\\n\", \"513\\n\", \"9146\\n\", \"9648\\n\", \"9...
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction <image> as a sum of three distinct positive fractions in form <image>. Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that <image...
0.125
{"tests": "{\"inputs\": [\"4\\n\", \"5\\n\", \"3\\n\", \"10264\\n\", \"217\\n\", \"7\\n\", \"777777\\n\", \"47248\\n\", \"13\\n\", \"301\\n\", \"1034\\n\", \"6\\n\", \"6486\\n\", \"225481\\n\", \"1\\n\", \"403\\n\", \"6726\\n\", \"43\\n\", \"9\\n\", \"21352\\n\", \"999811\\n\", \"10000\\n\", \"999998\\n\", \"51\\n\", \...
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them. The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playin...
0
{"tests": "{\"inputs\": [\"1 1\\n\", \"7 6\\n\", \"2 2\\n\", \"1000000000 999982505\\n\", \"100 9\\n\", \"2 1\\n\", \"4 4\\n\", \"3 2\\n\", \"999963734 999994456\\n\", \"5 4\\n\", \"5 5\\n\", \"7 8\\n\", \"957985574 24997558\\n\", \"965161805 908862070\\n\", \"10 11\\n\", \"1 2\\n\", \"1000 996\\n\", \"1033090 7376359\...
At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each ot...
0.25
{"tests": "{\"inputs\": [\"4\\n-1 5\\n1 6\\n3 5\\n2 3\\n\\nSAMPLE\", \"21\\n10 18\\n5 9\\n4 -6\\n13 1\\n17 -10\\n-8 19\\n-13 19\\n17 -20\\n-12 5\\n10 0\\n14 -14\\n12 -4\\n15 -13\\n0 -18\\n-17 -11\\n-3 19\\n-10 12\\n0 -17\\n-6 -13\\n-6 -2\\n20 2\", \"37\\n7 -14\\n18 -6\\n-20 -20\\n-15 12\\n5 18\\n6 7\\n-10 -2\\n-17 -17\...
Aarav has just graduated from the university. Now he is going to travel along his country. More precisely: there are N cities with integer coordinates. His plan is to travel between each pair of the cities. The distance between city A with coordinates (x1, y1) and city B with coordinates (x2, y2) is equal to |x1 - x2...
0.875
{"tests": "{\"inputs\": [\"2\\n-XX-XXXX-XXX-\\n-XX--XXXX---XXX-\\n\\nSAMPLE\", \"2\\n-XXXXX-X-XXX-\\n-XX--XXXX---XXX-\\n\\nSAMPLE\", \"2\\n-XXXXX-X-XXX-\\n-XXX---XXXX--XX-\\n\\nSAMPLE\", \"2\\n-XXX-X-XXXXX-\\n-XX--XXXX---XXX-\\n\\nELPMAS\", \"2\\n-XXX-X-XXXXX-\\n-XXX---XXXX--XX-\\n\\nELPMAS\", \"2\\n-XXXXX-X-XXX-\\n-XX...
Each digit of a number is represented by a cluster of adjacent X, with spaces between neighboring clusters. The digit is determined by the number of X in the cluster. For example, the number 243 would be represented by the following pattern -XX-XXXX-XXX- So to represent 0 the pattern will be -- (2 dashes without a...
0
{"tests": "{\"inputs\": [\"3\\n1 5\\n4 2\\n6 3\", \"6\\n19 92\\n64 64\\n78 48\\n57 33\\n73 6\\n95 73\", \"4\\n1 5\\n2 6\\n3 7\\n4 8\", \"3\\n2 5\\n4 2\\n6 3\", \"6\\n19 92\\n64 64\\n78 48\\n57 33\\n142 6\\n95 73\", \"4\\n1 5\\n2 6\\n0 7\\n4 8\", \"3\\n1 5\\n4 4\\n6 3\", \"6\\n19 92\\n64 64\\n29 48\\n57 33\\n142 6\\n95 ...
We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i. In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weight is {\rm min}(A_x,B_y). We will consider a directed cycle in thi...
0
{"tests": "{\"inputs\": [\"10\\n4 5 1 1 4 5 12 3 5 4\\n0\", \"10\\n4 5 1 1 4 5 12 3 6 4\\n0\", \"10\\n4 5 1 1 4 5 12 3 0 5\\n0\", \"10\\n4 5 1 1 3 5 14 3 0 5\\n0\", \"10\\n4 5 1 1 3 10 14 3 0 5\\n0\", \"10\\n4 5 1 0 3 10 14 3 0 5\\n0\", \"10\\n1 5 1 0 3 10 14 3 0 5\\n0\", \"10\\n1 5 1 0 3 4 27 0 0 5\\n0\", \"10\\n2 5 1...
There is a frequency operation in the conversion operation of a finite number sequence. The conversion result of the sequence $ S = \\ {s_1, s_2, ... s_n \\} $ is a sequence of the same length. If the result is $ C = \\ {c_1, c_2, ..., c_n \\} $, then $ c_i $ represents the number of $ s_i $ in the sequence $ S $. For...
0.25
{"tests": "{\"inputs\": [\"4\\n6 4\\n6 4\\n6 4\\n6 4\\n2\\n5 3\\n5 3\\n8\\n4 2\\n4 2\\n4 2\\n4 2\\n4 2\\n4 2\\n4 2\\n4 2\\n6\\n4 6\\n1 5\\n2 3\\n5 3\\n2 4\\n4 2\\n0\", \"4\\n6 4\\n6 4\\n6 4\\n6 4\\n2\\n5 3\\n5 3\\n8\\n4 2\\n4 2\\n4 2\\n4 2\\n4 2\\n4 2\\n4 2\\n4 2\\n6\\n3 6\\n1 5\\n2 3\\n5 3\\n2 4\\n4 2\\n0\", \"4\\n6 4...
Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotating, and may rol...
0
{"tests": "{\"inputs\": [\"100 100 1 1\\n50 0 50 100 50\\n640 480 1 1\\n0 0 640 480 100\\n0 0 0 0\", \"100 100 1 1\\n50 0 50 100 50\\n640 480 1 2\\n0 0 640 480 100\\n0 0 0 0\", \"100 100 1 1\\n62 0 50 100 50\\n640 480 1 1\\n0 0 640 480 100\\n0 0 0 0\", \"100 100 1 1\\n50 0 50 100 50\\n640 480 1 2\\n0 0 640 480 110\\n0 ...
Nathan O. Davis is challenging a kind of shooter game. In this game, enemies emit laser beams from outside of the screen. A laser beam is a straight line with a certain thickness. Nathan moves a circular-shaped machine within the screen, in such a way it does not overlap a laser beam. As in many shooters, the machine i...
0
{"tests": "{\"inputs\": [\"2 3\\n1 5 7\\n2 3 1\\n1 2\\n\", \"1 4\\n1 1 2 1\\n1 3\\n\", \"3 3\\n2 0 1\\n1 0 0\\n0 0 0\\n1 1\\n\", \"13 8\\n5 7 7 7 9 1 10 7\\n2 10 5 4 5 4 9 1\\n8 6 10 8 10 9 9 5\\n7 10 9 8 6 7 5 8\\n1 6 4 2 4 9 3 10\\n10 4 4 6 5 6 6 4\\n7 5 3 9 8 5 1 3\\n9 6 1 9 10 5 3 7\\n6 3 7 6 9 9 1 6\\n8 6 5 9 1 9 ...
Vasya has got a magic matrix a of size n × m. The rows of the matrix are numbered from 1 to n from top to bottom, the columns are numbered from 1 to m from left to right. Let a_{ij} be the element in the intersection of the i-th row and the j-th column. Vasya has also got a chip. Initially, the chip is in the intersec...
0.125
{"tests": "{\"inputs\": [\"3\\n1 9 3\\n8 6 7\\n4 2 5\\n\", \"6\\n32 17 18 23 26 33\\n7 36 22 3 1 5\\n30 9 8 34 27 21\\n16 6 35 28 4 25\\n29 19 24 13 11 12\\n2 20 15 14 31 10\\n\", \"10\\n38 18 27 74 94 4 45 82 83 88\\n73 95 50 40 28 59 47 19 58 60\\n23 75 14 22 97 81 3 85 87 6\\n56 80 30 62 57 90 5 41 69 44\\n72 46 70 ...
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily 8 × 8, but it still is N × N. Each square has some number written on it, all the numbers are from 1 to N^2 and all the numbers are pairwise distinct. The j-th square in the i-th row has a number A_{ij} written on it. In your...
0
{"tests": "{\"inputs\": [\"5 1\\n\", \"2 2\\n\", \"4 2\\n\", \"44 1\\n\", \"4291 2145\\n\", \"2266 1133\\n\", \"1023 999\\n\", \"5000 888\\n\", \"5000 3378\\n\", \"2029 360\\n\", \"9 1\\n\", \"2563 1281\\n\", \"40 24\\n\", \"8 2\\n\", \"5000 539\\n\", \"2944 2468\\n\", \"8 4\\n\", \"10 9\\n\", \"530 530\\n\", \"5000 1\...
Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible. There are n manholes in the room which are situated on one line, but, unfortunately, all the manholes are clo...
0
{"tests": "{\"inputs\": [\"3\\n3 5 2 3 2 4\\n\", \"1\\n3 6\\n\", \"1\\n2750131 199999\\n\", \"1\\n3 2\\n\", \"1\\n68914 137828\\n\", \"2\\n1327 1847 2654 283\\n\", \"100\\n3 3 2 2 3 2 3 2 2 2 2 3 3 2 2 2 2 2 3 3 3 2 3 3 3 2 2 2 3 3 2 3 2 2 3 2 3 2 2 2 3 2 3 3 3 2 3 3 3 2 2 3 3 3 3 3 2 3 2 2 2 3 3 3 2 3 3 3 3 2 2 3 2 3 ...
Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 ⋅ 10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations: 1. Firstly, let the array b be equal to the array a; 2. Secondly, for each i f...
0
{"tests": "{\"inputs\": [\"5\\n9 3 5 7 3\\n5 8 1 4 5\\n\", \"1\\n7\\n4\\n\", \"3\\n1 2 9\\n10 1 1\\n\", \"1\\n5\\n8\\n\", \"100\\n1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 ...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 ⋅ n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each row). Students are numbered from 1 to n in each row in order from ...
0.625
{"tests": "{\"inputs\": [\"200000 3\\n7 9\\n9 8\\n4 5\\n\", \"14 8\\n1 2\\n2 7\\n3 4\\n6 3\\n5 7\\n3 8\\n6 8\\n11 12\\n\", \"500 5\\n100 300\\n200 400\\n420 440\\n430 450\\n435 460\\n\", \"200000 1\\n1 200000\\n\", \"3 1\\n1 3\\n\", \"974 5\\n100 300\\n200 400\\n420 440\\n430 450\\n435 460\\n\", \"5 1\\n1 3\\n\", \"974...
You're given an undirected graph with n nodes and m edges. Nodes are numbered from 1 to n. The graph is considered harmonious if and only if the following property holds: * For every triple of integers (l, m, r) such that 1 ≤ l < m < r ≤ n, if there exists a path going from node l to node r, then there exists a pat...
0
{"tests": "{\"inputs\": [\"5\\n11011\\n3\\n1 3 3\\n1 4 2\\n1 2 3\\n\", \"3\\n010\\n3\\n1 3 1\\n1 3 1\\n3 2 1\\n\", \"10\\n1100111011\\n10\\n10 10 1\\n5 4 5\\n6 10 1\\n10 10 1\\n10 10 1\\n5 5 4\\n6 10 1\\n4 6 4\\n10 10 1\\n6 10 1\\n\", \"50\\n01110100101100100100011001100001110010010000000101\\n50\\n27 18 7\\n22 35 2\\n...
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string s starting from the l-th character and ending with the r-th character as s[l .....
0
{"tests": "{\"inputs\": [\"++++[&gt;,.&lt;-]\\n\", \",.\\n\", \"-[..[]+>>.>,]>.+]>.]>[.>+,>+\\n\", \".<>.+]>],>><\\n\", \"+,+><[>..,]-.[.++[>-<<-,-.>,.>]+,<,]]<[>,-+,.-[+,[.[<.-[].+>[,>-.>>]-[-][+,>>-,+<-,<.+-.+[.,\\n\", \"<.,+.><[,.+<[,.,<-,[>,\\n\", \"[-.].+<<]---+[+-+-[,[[[,]-<[-[[><>]\\n\", \",]+>.],,+->+>-[]][><,-...
Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm...
0
{"tests": "{\"inputs\": [\"4\\n8 4 7\\n1 2\\n2 3\\n1 4\\n4 5\\n4 6\\n1 7\\n7 8\\n4 3 2\\n4 3\\n1 2\\n2 3\\n9 3 5\\n1 2\\n2 3\\n3 4\\n1 5\\n5 6\\n6 7\\n1 8\\n8 9\\n16 15 12\\n1 2\\n2 3\\n1 4\\n4 5\\n5 6\\n6 7\\n4 8\\n8 9\\n8 10\\n10 11\\n11 12\\n11 13\\n13 14\\n10 15\\n15 16\\n\", \"4\\n8 4 7\\n1 2\\n2 3\\n1 4\\n4 5\\n4...
There is an undirected tree of n vertices, connected by n-1 bidirectional edges. There is also a snake stuck inside of this tree. Its head is at vertex a and its tail is at vertex b. The snake's body occupies all vertices on the unique simple path between a and b. The snake wants to know if it can reverse itself — tha...
0
{"tests": "{\"inputs\": [\"3 3\\n2 3 1000000\\n4 0 4\\n3 0 1000000\\n4 0 1\\n2 0 5\\n3 1 1000000\\n\", \"3 0\\n3 1 1000000\\n1 1 1000000\\n2 1 1000000\\n\", \"1 1\\n500000 1 1000000\\n500000 0 999999\\n\", \"0 0\\n\", \"1 1\\n83893 0 1000000\\n507509 0 668083\\n\", \"0 1\\n242110 453990 1000000\\n\", \"1 1\\n231451 171...
There is a square of size 10^6 × 10^6 on the coordinate plane with four points (0, 0), (0, 10^6), (10^6, 0), and (10^6, 10^6) as its vertices. You are going to draw segments on the plane. All segments are either horizontal or vertical and intersect with at least one side of the square. Now you are wondering how many ...
0
{"tests": "{\"inputs\": [\"4\\n6 4\\n2 2 8 6 9 4\\n10 8\\n1 1 1 5 2 4 4 8 6 7\\n1 1\\n666\\n2 2\\n2 4\\n\", \"4\\n6 4\\n1 2 8 6 9 4\\n10 8\\n1 1 1 5 2 4 4 8 6 7\\n1 1\\n666\\n2 2\\n2 4\\n\", \"4\\n6 4\\n1 2 8 3 9 4\\n10 8\\n1 1 1 5 2 4 4 8 6 7\\n1 1\\n666\\n2 2\\n2 4\\n\", \"4\\n6 4\\n1 2 8 3 11 4\\n10 8\\n1 1 1 5 2 4 ...
You are given an array a_1, a_2, …, a_n consisting of n positive integers and a positive integer m. You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want. Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the pos...
0
{"tests": "{\"inputs\": [\"7\\n\\n1 1\\n3 3\\n2 2\\n\\n2 5\\n2 1\\n2 3\\n\\n1000 42\\n1000 1\\n1000 1000\\n\\n1 10\\n3 10\\n2 10\\n\\n3 8\\n7 8\\n3 7\\n\\n2 1\\n4 1\\n1 1\\n\\n1 344\\n1 10\\n1 1\\n\", \"7\\n\\n1 1\\n3 3\\n2 2\\n\\n2 5\\n2 1\\n2 3\\n\\n1000 42\\n1000 1\\n1000 1000\\n\\n1 10\\n3 10\\n2 10\\n\\n3 8\\n7 8\...
There are three cells on an infinite 2-dimensional grid, labeled A, B, and F. Find the length of the shortest path from A to B if: * in one move you can go to any of the four adjacent cells sharing a side; * visiting the cell F is forbidden (it is an obstacle). Input The first line contains an integer t (1 ≤ ...
0.125
{"tests": "{\"inputs\": [\"6\\n1 2 1 1 4 1\\n\", \"5\\n1 0 1 0 1\\n\", \"2\\n2 1\\n\", \"3\\n2 4 2\\n\", \"2\\n1 1\\n\", \"3\\n1 1 1\\n\", \"20\\n1 6 8 9 10 10 11 11 10 10 9 6 6 6 6 4 3 2 1 0\\n\", \"3\\n0 2 1\\n\", \"3\\n2 2 1\\n\", \"2\\n2 4\\n\", \"2\\n1 3\\n\", \"1\\n1\\n\", \"5\\n1 0 2 1 0\\n\", \"20\\n2 2 4 5 5 6...
Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function does the following: function rangeIncrement(l,...
0
{"tests": "{\"inputs\": [\"5\\n1 2\\n2 4\\n2 4\\n6 4\\n2 1\\n\", \"100\\n5 0\\n6 4\\n1 6\\n2 2\\n4 0\\n0 4\\n4 4\\n4 0\\n6 6\\n0 2\\n3 2\\n0 4\\n0 4\\n2 0\\n4 4\\n0 4\\n2 6\\n4 2\\n1 4\\n2 5\\n2 0\\n3 2\\n1 4\\n5 4\\n4 2\\n2 4\\n4 0\\n0 1\\n6 4\\n2 1\\n5 4\\n4 0\\n5 6\\n4 1\\n2 4\\n6 1\\n6 4\\n2 5\\n2 4\\n3 3\\n5 4\\n6...
You have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so that any two dominoes touched with the sides that had the same number of points? You can rotate the dominoes, changing the left and the ri...
0
{"tests": "{\"inputs\": [\"4\\n0 1 1 0\\n\", \"1\\n0\\n\", \"2\\n1 1\\n\", \"5\\n0 0 0 0 1\\n\", \"6\\n0 0 0 0 0 1\\n\", \"4\\n1 0 1 1\\n\", \"20\\n1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0\\n\", \"6\\n1 1 1 1 0 0\\n\", \"5\\n1 1 1 1 0\\n\", \"5\\n1 0 1 0 1\\n\", \"6\\n0 0 0 0 0 0\\n\", \"5\\n0 0 0 1 0\\n\", \"6\\n0 1 1 ...
Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is written by using character '<image>', and the arguments and the result of the implication are written as '0' (false) and '1' (true...
0
{"tests": "{\"inputs\": [\"4 1\\n\", \"1 3\\n\", \"3 1\\n\", \"30 5\\n\", \"999899988 13\\n\", \"999999999 111111111\\n\", \"1000000000 999999999\\n\", \"999999999 1000000000\\n\", \"999999998 111111111\\n\", \"861651807 2239668\\n\", \"405262931 391908625\\n\", \"829050416 2523498\\n\", \"11 3\\n\", \"836218485 172089...
There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x. Input Only one line containing two positiv...
0.25
{"tests": "{\"inputs\": [\"2\\n4 1 3 2 5 6\\n4 6 5\\n1 2 3\\n4\\n\", \"3\\n5 4 1 2 6 3 7 8 9\\n5 6 2\\n9 3 4\\n1 7 8\\n4\\n\", \"3\\n5 4 1 2 6 3 7 8 9\\n5 6 2\\n9 3 4\\n1 7 8\\n8\\n\", \"1\\n2 3 1\\n2 3 1\\n2\\n\", \"3\\n1 2 3 4 5 6 7 8 9\\n1 2 3\\n4 5 9\\n6 7 8\\n5\\n\", \"2\\n6 4 5 1 3 2\\n6 1 3\\n4 5 2\\n6\\n\", \"5...
Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and a...
0
{"tests": "{\"inputs\": [\"8\\n1 2 1 2 1 2 1 2\\n2 1 2 1 2 1 2 1\\n\", \"4\\n1 7 2 3\\n8 1 1 3\\n\", \"10\\n44 22 14 9 93 81 52 64 3 99\\n43 23 13 10 92 82 51 65 2 100\\n\", \"1\\n1\\n1\\n\", \"10\\n1 5 4 3 2 1 5 8 2 3\\n1 1 1 1 5 5 5 5 5 5\\n\", \"1\\n1000000000\\n1000000000\\n\", \"20\\n31 16 20 30 19 35 8 11 20 45 1...
Little Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle works as follows: in the morning he should leave the house and go to some post office. In the office he receives a portion of letters and a car. Then ...
0
{"tests": "{\"inputs\": [\"oXoxoXo\\n\", \"bod\\n\", \"ER\\n\", \"oiio\\n\", \"uuuu\\n\", \"iOi\\n\", \"VxrV\\n\", \"A\\n\", \"lxl\\n\", \"o\\n\", \"iii\\n\", \"ipOqi\\n\", \"uu\\n\", \"uuu\\n\", \"O\\n\", \"AAWW\\n\", \"Db\\n\", \"OuO\\n\", \"JL\\n\", \"tt\\n\", \"ii\\n\", \"NNNN\\n\", \"iIcamjTRFH\\n\", \"T\\n\", \"p...
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half. <image> English alphabet You are given a...
0
{"tests": "{\"inputs\": [\"WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\\n\", \"ABC??FGHIJK???OPQR?TUVWXY?\\n\", \"AABCDEFGHIJKLMNOPQRSTUVW??M\\n\", \"??????????????????????????\\n\", \"LLVYUOXHBHUZSAPUMQEKWSQAFRKSMEENXDQYOPQFXNNFXSRBGXFUIRBFJDSDKQIDMCPPTWRJOZCRHZYZPBVUJPQXHNALAOCJDTTBDZWYDBVPMNSQNVMLHHUJAOIWFSEJE...
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not n...
0.125
{"tests": "{\"inputs\": [\"4\\n1 3 4 2\\n\", \"8\\n6 8 3 4 7 2 1 5\\n\", \"1\\n1\\n\", \"11\\n10 8 9 4 3 5 1 11 7 2 6\\n\", \"100\\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 ...
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then...
0
{"tests": "{\"inputs\": [\"3 2 2\\n4 1 3\\n\", \"2 3 1\\n2 3\\n\", \"5 10 7\\n98765 78654 25669 45126 98745\\n\", \"2 7597 8545\\n74807 22362\\n\", \"1 1 1000000000\\n100\\n\", \"5 2 9494412\\n5484 254 1838 18184 9421\\n\", \"95 97575868 5\\n4612 1644 3613 5413 5649 2419 5416 3926 4610 4419 2796 5062 2112 1071 3790 422...
It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right. Unfortunately, Joe ...
0
{"tests": "{\"inputs\": [\"0010100\\n\", \"111\\n\", \"0101001000\\n\", \"01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\...
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences o...
0
{"tests": "{\"inputs\": [\"8\\n\\nSAMPLE\", \"3\", \"200\", \"45\", \"8\\n\\nSAMQLE\", \"5\", \"84\", \"6\", \"66\", \"4\", \"10\", \"12\", \"15\", \"29\", \"14\", \"20\", \"34\", \"47\", \"85\", \"101\", \"100\", \"111\", \"110\", \"192\", \"188\", \"28\", \"32\", \"41\", \"22\", \"46\", \"44\", \"27\", \"9\", \"8\\n\...
A Magic Fraction for N is one that has the following properties: It is a proper fraction (The value is < 1) It cannot be reduced further (The GCD of the numerator and the denominator is 1) The product of the numerator and the denominator is factorial of N. i.e. if a/b is the fraction, then a*b = N! Examples of Magic F...
0
{"tests": "{\"inputs\": [\"6\\n4 1 3 1 6 2\", \"2\\n10000000 10000000\", \"5\\n2 6 1 4 5\", \"6\\n4 1 3 1 6 1\", \"2\\n10000100 10000000\", \"5\\n2 9 1 4 5\", \"6\\n4 1 3 1 2 1\", \"2\\n10000100 10001000\", \"5\\n2 9 1 3 5\", \"6\\n4 1 3 1 2 0\", \"2\\n10000100 10101000\", \"5\\n2 9 0 3 5\", \"6\\n4 1 3 2 2 0\", \"2\\n...
Given is a sequence of integers A_1, A_2, ..., A_N. If its elements are pairwise distinct, print `YES`; otherwise, print `NO`. Constraints * 2 ≤ N ≤ 200000 * 1 ≤ A_i ≤ 10^9 * All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output If the elements...
0.875
{"tests": "{\"inputs\": [\"10\\naaaaaaaaaa\", \"6\\naabbca\", \"45\\ntgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir\", \"10\\naaabaaaaaa\", \"6\\n`abbca\", \"45\\ntgxgdqkyjphyzutjjtllptdfxocrylqfqjynmfbfucbir\", \"45\\ntgxgtqkyjfhyzutjjdllptdpxrbrylqfqjynmfbfucbio\", \"45\\nbnxgtqkykfhyzutjjdllptdpxrtrylqfqjygmfbftcbio\...
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when ...
0.25
{"tests": "{\"inputs\": [\"4\\n4\\n0,1,1500\\n0,2,2000\\n1,2,600\\n1,3,500\\n0\", \"4\\n4\\n0,1,1500\\n0,2,2000\\n1,2,600\\n2,3,500\\n0\", \"4\\n4\\n0,1,1500\\n0,2,2000\\n1,2,600\\n2,3,400\\n0\", \"4\\n4\\n0,1,0500\\n0,2,2000\\n0,2,600\\n2,3,400\\n0\", \"4\\n4\\n0,1,0400\\n0002,2,0\\n0,2,600\\n2,3,400\\n0\", \"4\\n4\\n...
Aizuwakamatsu City is known as the "City of History". About 400 years ago, the skeleton of the castle town was created by Gamo Ujisato, but after that, it became the central city of the Aizu clan 230,000 stones, whose ancestor was Hoshina Masayuki, the half-brother of Tokugawa's third shogun Iemitsu. Developed. Many to...
0.125
{"tests": "{\"inputs\": [\"100 5\\n101 101 5 5\\n110 110 2 3\\n-112 -100 9 11\\n-208 160 82 90\\n-110 108 10 2\\n10 11\\n15 0 5 1\\n25 0 5 1\\n35 0 5 1\\n45 0 5 1\\n55 0 5 1\\n65 0 5 1\\n75 0 5 1\\n85 0 5 1\\n95 0 5 1\\n-20 0 5 20\\n-30 0 500 5\\n0 0\", \"100 5\\n101 101 5 5\\n110 110 2 3\\n-112 -100 9 11\\n-208 160 82...
In 40XX, the Earth was invaded by aliens! Already most of the Earth has been dominated by aliens, leaving Tsuruga Castle Fortress as the only remaining defense base. Suppression units are approaching the Tsuruga Castle Fortress one after another. <image> But hope remains. The ultimate defense force weapon, the ultra...
0
{"tests": "{\"inputs\": [\"8\\n1 1\\n4 4\\n1 1 4 1\\n1 1 1 4\\n3 1 3 4\\n4 3 5 3\\n2 4 3 5\\n4 1 4 4\\n3 3 2 2\\n1 4 4 4\\n9\\n1 5\\n5 1\\n5 4 5 1\\n1 5 1 1\\n1 5 5 1\\n2 3 2 4\\n5 4 1 5\\n3 2 2 1\\n4 2 4 1\\n1 1 5 1\\n5 3 4 3\\n11\\n5 5\\n1 0\\n3 1 5 1\\n4 3 4 2\\n3 1 5 5\\n2 3 2 2\\n1 0 1 2\\n1 2 3 4\\n3 4 5 5\\n1 0 ...
Your task in this problem is to create a program that finds the shortest path between two given locations on a given street map, which is represented as a collection of line segments on a plane. <image> Figure 4 is an example of a street map, where some line segments represent streets and the others are signs indicat...
0
{"tests": "{\"inputs\": [\"2 1 100\\n100 100 10\\n0 100 1\", \"2 2 50\\n30 0 1\\n30 50 2\", \"2 2 50\\n30 50 1\\n30 50 2\", \"3 1 100\\n50 1 1\\n50 1 1\\n50 1 1\", \"2 1 100\\n100 100 10\\n0 100 0\", \"2 2 50\\n30 0 1\\n30 50 1\", \"1 2 50\\n30 50 1\\n30 50 2\", \"3 1 100\\n50 1 2\\n50 1 1\\n50 1 1\", \"3 1 000\\n7 2 2...
N people run a marathon. There are M resting places on the way. For each resting place, the i-th runner takes a break with probability P_i percent. When the i-th runner takes a break, he gets rest for T_i time. The i-th runner runs at constant speed V_i, and the distance of the marathon is L. You are requested to com...
0
{"tests": "{\"inputs\": [\"25\", \"5\", \"1\", \"83160\", \"18\", \"9\", \"0\", \"10614\", \"3\", \"5401\", \"2\", \"12\", \"4\", \"6\", \"30\", \"16\", \"65420\", \"3315\", \"36\", \"64\", \"32\", \"4557\", \"3807\", \"26789\", \"54\", \"1584\", \"20928\", \"90\", \"5664\", \"96\", \"144\", \"001\", \"684\", \"5418\",...
You received a card with an integer $S$ and a multiplication table of infinite size. All the elements in the table are integers, and an integer at the $i$-th row from the top and the $j$-th column from the left is $A_{i,j} = i \times j$ ($i,j \geq 1$). The table has infinite size, i.e., the number of the rows and the n...
0.625
{"tests": "{\"inputs\": [\"3\\n0 0 1 0 0 1 1 1\\n0 0 1 0 2 1 1 2\\n-1 0 1 0 0 1 0 -1\", \"3\\n0 0 1 0 0 1 1 1\\n0 0 1 0 2 1 1 2\\n-1 1 1 0 0 1 0 -1\", \"3\\n0 1 1 0 0 1 1 1\\n-1 0 1 0 2 1 1 2\\n-1 1 0 0 0 1 0 -1\", \"3\\n0 1 1 0 0 1 1 1\\n-1 0 1 1 2 1 1 2\\n-1 1 0 0 0 1 0 -1\", \"3\\n0 1 1 0 0 1 1 1\\n-1 0 1 1 1 1 1 2\...
For given two segments s1 and s2, print the distance between them. s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3. Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xpi, ypi ≤ 10000 * p0 ≠ p1 and p2 ≠ p3. Input The entire input looks like: q (the number of queries) 1st query 2nd query ... qth...
0.125
{"tests": "{\"inputs\": [\"3 6 2 3 3\\n1 2 1 3\\n1 4 3 4\\n1 2 2 3\\n\", \"100000000 100000000 100000000 100000000 1\\n100000000 100000000 100000000 1\\n\", \"1 1 1 1 1\\n1 1 1 1\\n\", \"1 0 1 1 1\\n1 1 1 1\\n\", \"1 0 1 2 1\\n1 1 1 2\\n\", \"1 0 1 2 1\\n2 1 1 2\\n\", \"1 0 1 2 1\\n3 1 0 1\\n\", \"1 0 2 2 1\\n3 1 0 1\\...
You are looking at the floor plan of the Summer Informatics School's new building. You were tasked with SIS logistics, so you really care about travel time between different locations: it is important to know how long it would take to get from the lecture room to the canteen, or from the gym to the server room. The bu...
0.625
{"tests": "{\"inputs\": [\"5 10\\n1 15\\n5 3\\n6 11\\n7 2\\n11 22\\n\", \"3 5\\n1 8\\n2 19\\n3 11\\n\", \"10 8\\n1 16\\n23 27\\n26 2\\n32 21\\n38 50\\n51 53\\n62 79\\n77 97\\n94 18\\n100 5\\n\", \"9 985\\n227 166\\n325 695\\n408 426\\n548 491\\n627 627\\n733 288\\n802 59\\n924 471\\n933 492\\n\", \"1 235\\n15 210\\n\",...
Vasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit. Vasya has n problems to choose from. They are numbered from 1 to n. The difficulty of the i-th problem is d_i. Moreover, the problems are given in the increasing order by the...
0.75
{"tests": "{\"inputs\": [\"3\\n80 60 60\\n\", \"2\\n6 5\\n\", \"3\\n100 50 50\\n\", \"4\\n51 25 99 25\\n\", \"8\\n100 40 60 60 60 60 60 60\\n\", \"5\\n2 1 1 1 4\\n\", \"4\\n100 50 51 100\\n\", \"4\\n40 20 29 80\\n\", \"7\\n5 1 2 3 4 5 6\\n\", \"100\\n100 48 48 22 21 27 51 43 53 34 54 37 45 37 27 53 39 53 37 44 55 44 56...
Alice is the leader of the State Refactoring Party, and she is about to become the prime minister. The elections have just taken place. There are n parties, numbered from 1 to n. The i-th party has received a_i seats in the parliament. Alice's party has number 1. In order to become the prime minister, she needs to b...
0.5
{"tests": "{\"inputs\": [\"3 3 2\\n3 1\\n2 2\\n\", \"3 3 2\\n2 2\\n2 1\\n\", \"3 3 8\\n1 2\\n1 3\\n2 1\\n2 2\\n2 3\\n3 1\\n3 2\\n3 3\\n\", \"48145 89209 5\\n3 1\\n3 2\\n3 3\\n2 3\\n1 3\\n\", \"2 2 2\\n1 2\\n2 2\\n\", \"10 10 46\\n5 4\\n3 5\\n5 3\\n3 2\\n6 6\\n3 7\\n7 5\\n3 6\\n6 3\\n10 3\\n5 7\\n5 6\\n10 7\\n7 6\\n5 5\...
Alice got a new doll these days. It can even walk! Alice has built a maze for the doll and wants to test it. The maze is a grid with n rows and m columns. There are k obstacles, the i-th of them is on the cell (x_i, y_i), which means the cell in the intersection of the x_i-th row and the y_i-th column. However, the d...
0
{"tests": "{\"inputs\": [\"6\\nabbbbb\\n\", \"4\\nbcda\\n\", \"8\\nbacabcab\\n\", \"7\\ncddcbcb\\n\", \"100\\nmxjrojjwtrauhhccftvjsyfyfsnbdnwjfltyjetsylbddrkoqjxbmientcowknrecfqcvxfgsbymwyvakmbulhvrxzvzbygajtgc\\n\", \"8\\naaaaaaaa\\n\", \"100\\nyltrygcqmgjzsxoahbvovspancmoaltdrxgjnxwxbrehubvradguoqgiodzanljxtszdutuzgc...
You are given a string s consisting of lowercase Latin letters. Let the length of s be |s|. You may perform several operations on this string. In one operation, you can choose some index i and remove the i-th character of s (s_i) if at least one of its adjacent characters is the previous letter in the Latin alphabet f...
0
{"tests": "{\"inputs\": [\"5\\n2\\n01\\n10\\n5\\n01011\\n11100\\n2\\n01\\n01\\n10\\n0110011011\\n1000110100\\n1\\n0\\n1\\n\", \"5\\n2\\n01\\n10\\n5\\n01011\\n11100\\n2\\n01\\n01\\n10\\n0110011011\\n1000110100\\n1\\n0\\n1\\n\", \"5\\n2\\n01\\n10\\n5\\n01011\\n11100\\n2\\n01\\n01\\n10\\n0100011011\\n1000110100\\n1\\n0\\n...
This is the hard version of the problem. The difference between the versions is the constraint on n and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings a and b of length n (a binary string is a string consisting of symbols 0 and 1). In ...
0
{"tests": "{\"inputs\": [\"2\\n5 16\\n1 2 8 4 8\\n6 10\\n2 8 8 2 2 8\\n\", \"2\\n5 13\\n1 2 8 4 8\\n6 10\\n2 8 8 2 2 8\\n\", \"2\\n5 13\\n1 2 8 2 8\\n6 10\\n4 8 8 2 2 8\\n\", \"2\\n5 12\\n1 4 8 4 8\\n6 10\\n2 8 8 2 2 8\\n\", \"2\\n5 8\\n1 2 8 2 8\\n6 11\\n4 8 8 2 2 8\\n\", \"2\\n5 12\\n1 2 8 4 8\\n6 12\\n2 2 8 2 2 8\\n...
You are given n rectangles, each of height 1. Each rectangle's width is a power of 2 (i. e. it can be represented as 2^x for some non-negative integer x). You are also given a two-dimensional box of width W. Note that W may or may not be a power of 2. Moreover, W is at least as large as the width of the largest recta...
0.75
{"tests": "{\"inputs\": [\"1 1\\n\", \"4 6\\n\", \"9 7\\n\", \"136749 183300\\n\", \"100000 1\\n\", \"18 3\\n\", \"10000 10000\\n\", \"121147 78249\\n\", \"121146 78249\\n\", \"1 100000\\n\", \"2954 1977\\n\", \"38 36\\n\", \"10 10\\n\", \"89671 32487\\n\", \"6 6\\n\", \"25580 17318\\n\", \"200000 199999\\n\", \"199585...
There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules: * Red-green tower is consisting of some number of levels; * Let the red-green tower consist of n levels, then the first level of this tower should consist of n blocks, second level — of n...
0
{"tests": "{\"inputs\": [\"5 70\\n200 170 40\\n\", \"1 1\\n2 1 3\\n\", \"20 40\\n9958 9799 30\\n\", \"23 4\\n5 2 13\\n\", \"46 20\\n4 2 35\\n\", \"38 3\\n47 16 4\\n\", \"39 42\\n35 19 12\\n\", \"5527 8154\\n3974 3550 1639\\n\", \"11 13\\n24 15 37\\n\", \"4 120\\n5112 3000 130\\n\", \"200 1000\\n3 2 10000\\n\", \"200 10...
Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the ro...
0
{"tests": "{\"inputs\": [\"4 1 2\\n\", \"8954 4025 7157\\n\", \"1006 9237 1123\\n\", \"6222 7124 6784\\n\", \"5992 2773 6869\\n\", \"6995 4636 8251\\n\", \"1736 5628 2595\\n\", \"100000000 100000000 0\\n\", \"2793 175 3594\\n\", \"100000000 50000000 0\\n\", \"4755 6759 4899\\n\", \"28258585 6194848 49146833\\n\", \"371...
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met anoth...
0
{"tests": "{\"inputs\": [\"3\\n\", \"2\\n\", \"20\\n\", \"9\\n\", \"181\\n\", \"261\\n\", \"8\\n\", \"121\\n\", \"351\\n\", \"71\\n\", \"141\\n\", \"361\\n\", \"1\\n\", \"61\\n\", \"301\\n\", \"392\\n\", \"10\\n\", \"321\\n\", \"161\\n\", \"151\\n\", \"41\\n\", \"251\\n\", \"241\\n\", \"395\\n\", \"271\\n\", \"101\\n\"...
It is known that passages in Singer house are complex and intertwined. Let's define a Singer k-house as a graph built by the following process: take complete binary tree of height k and add edges from each vertex to all its successors, if they are not yet present. <image> Singer 4-house Count the number of non-empty ...
0
{"tests": "{\"inputs\": [\"5 4\\n1 2\\n3 4\\n5 4\\n3 5\\n\", \"17 15\\n1 8\\n1 12\\n5 11\\n11 9\\n9 15\\n15 5\\n4 13\\n3 13\\n4 3\\n10 16\\n7 10\\n16 7\\n14 3\\n14 4\\n17 6\\n\", \"5 10\\n1 2\\n1 3\\n1 4\\n1 5\\n2 3\\n2 4\\n2 5\\n3 4\\n3 5\\n4 5\\n\", \"5 5\\n1 2\\n2 3\\n3 4\\n4 1\\n3 5\\n\", \"5 10\\n1 2\\n2 3\\n3 4\\...
You are given an undirected graph consisting of n vertices and m edges. Your task is to find the number of connected components which are cycles. Here are some definitions of graph theory. An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of vertices....
0.625
{"tests": "{\"inputs\": [\"3 3\\n1 2 1\\n2 1 1\\n1 3 2\", \"1 1\\n1 1 1\", \"2 2\\n1 2 1\\n2 1 1\", \"5 5\\n1 2 1\\n2 1 1\\n1 3 2\\n4 5 1\\n5 4 1\", \"6 3\\n1 2 1\\n2 1 1\\n1 3 2\", \"2 2\\n1 2 1\\n1 1 1\", \"5 5\\n1 2 1\\n3 1 1\\n1 3 2\\n4 5 1\\n5 4 1\", \"5 5\\n1 2 1\\n3 1 1\\n1 3 2\\n1 5 1\\n5 4 1\", \"2 1\\n1 1 1\"...
We have N boxes numbered 1 to N, and M balls numbered 1 to M. Currently, Ball i is in Box A_i. You can do the following operation: * Choose a box containing two or more balls, pick up one of the balls from that box, and put it into another box. Since the balls are very easy to break, you cannot move Ball i more th...
0
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5\", \"3\\n2 3 1\", \"8\\n8 2 7 3 4 5 6 1\", \"3\\n1 3 2\", \"3\\n3 1 2\", \"5\\n1 3 2 4 5\", \"5\\n2 3 1 4 5\", \"8\\n8 1 7 3 4 5 6 2\", \"3\\n3 2 1\", \"3\\n2 1 3\", \"3\\n1 2 3\", \"3\\n1 3 2\", \"3\\n1 2 3\", \"3\\n3 1 2\", \"3\\n2 1 3\", \"3\\n3 2 1\"], \"outputs\": [\"30\", ...
Given is a permutation P of \\{1, 2, \ldots, N\\}. For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R. Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}. Constraints * 2 \le N \le 10^5 * 1 \le P_i \le N * P_i \neq P_j (i \neq j) * All values...
0
{"tests": "{\"inputs\": [\"7\\n1\\n2\\n1\\n3\\n1\\n4\", \"4\\n4\\n4\\n1\", \"5\\n1\\n1\\n2\\n4\", \"7\\n1\\n2\\n2\\n3\\n1\\n4\", \"5\\n1\\n1\\n1\\n4\", \"5\\n1\\n0\\n1\\n3\", \"7\\n1\\n4\\n2\\n3\\n1\\n3\", \"5\\n0\\n0\\n1\\n3\", \"4\\n3\\n4\\n0\", \"7\\n1\\n4\\n2\\n3\\n1\\n4\", \"5\\n1\\n1\\n1\\n3\", \"7\\n1\\n4\\n2\\n...
N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The struct...
0
{"tests": "{\"inputs\": [\"8 4\\n2 1 3 1 1 5 1 3\\n2 3 2 4 1 0 2 1\\n0 3 1 2 1 1 4 2\\n1 2 3 2 1 1 5 4\\n0 2 0 1 1 3 2 1\\n1 3 1 2 2 4 3 2\\n5 1 2 1 4 1 1 5\\n4 1 1 0 1 2 2 1\\n2 -1 -1 -1\\n0 3 -1 -1\\n-1 2 2 4\\n-1 1 -1 1\\n5 3\\n1 0 2 3 5\\n2 3 7 2 1\\n2 5 4 2 2\\n8 9 0 3 3\\n3 6 0 4 7\\n-1 -1 2\\n-1 3 5\\n0 4 -1\\n...
Mr. A came to Aizu for sightseeing. You can overlook the Aizu Basin from the window of the hotel where you stayed. As I was looking at the scenery, I noticed a piece of the photo on the floor. Apparently I took the outside view from the window. "Which area did you take?" A asked, holding the photo so that the view outs...
0
{"tests": "{\"inputs\": [\"4\\naa\\nabba\\nabcd\\nabcde\", \"4\\naa\\nabba\\nbbcd\\nabcde\", \"4\\nab\\nabba\\nbbcd\\nedcba\", \"4\\nb`\\nabba\\nbcbe\\nbbced\", \"4\\n`b\\nabba\\nbebe\\nbecbd\", \"4\\n`b\\naabb\\nbebe\\nbecbd\", \"4\\n`c\\naabb\\nbebe\\nbecce\", \"4\\ne`\\na`bb\\nbbee\\neddeb\", \"4\\ne`\\na`ba\\nbbee\...
RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in Figure B-1. <image> Figure B-1: Layout of the exchange lines A freight train consists of 2 to 72 freight cars. There are 26 types of freight cars, which are d...
0
{"tests": "{\"inputs\": [\"4 4 1\\n3 1 2\\n2 2 3\\n3 3 4\\n1 3 4\\n0 0 0\", \"4 4 1\\n3 1 2\\n2 2 4\\n3 3 4\\n1 3 4\\n0 0 0\", \"4 4 1\\n3 1 2\\n2 2 3\\n4 3 4\\n1 3 4\\n0 0 0\", \"4 4 1\\n3 1 2\\n2 2 4\\n3 3 4\\n1 1 4\\n0 0 0\", \"4 4 1\\n0 1 2\\n2 2 3\\n3 3 4\\n0 3 4\\n0 0 0\", \"4 3 1\\n3 1 2\\n0 1 3\\n4 3 4\\n1 0 1\...
The mayor of Amida, the City of Miracle, is not elected like any other city. Once exhausted by long political struggles and catastrophes, the city has decided to leave the fate of all candidates to the lottery in order to choose all candidates fairly and to make those born under the lucky star the mayor. I did. It is a...
0
{"tests": "{\"inputs\": [\"0 7 3 1\", \"1 7 2 2\\n0 1 1 2\", \"1 7 3 1\\n1 1 2 2\", \"1 4 2 2\\n0 1 1 2\", \"0 7 2 1\", \"1 5 3 1\\n1 1 2 2\", \"2 4 2 2\\n0 1 1 2\", \"1 5 3 1\\n1 1 2 4\", \"2 4 2 2\\n0 2 1 2\", \"1 5 3 1\\n1 1 3 4\", \"2 4 2 2\\n0 2 2 2\", \"2 4 4 2\\n0 2 1 2\", \"2 3 4 2\\n0 2 1 2\", \"2 3 4 2\\n-1 2...
Angry Birds is a mobile game of a big craze all over the world. You were convinced that it was a waste of time to play the game, so you decided to create an automatic solver. <image> You are describing a routine that optimizes the white bird's strategy to defeat a pig (enemy) by hitting an egg bomb. The white bird fo...
0
{"tests": "{\"inputs\": [\"LXRR\\n\", \"X\\n\", \"RXXRLRRLRR\\n\", \"RXRRXXXRXXRR\\n\", \"XRRLXRRRLRLXXLRRLRXL\\n\", \"RXLLRXXLLRLRLLXXXXRXXRLLRRRRXLLRRLXXLRXXLXLRLLLLLRXLRXLXRXLXLRRXXRRLXLXLRLRXRXLXXXLRXLLXLRRRRXRLLXRRLLRRXRRRLRLLRLRXXXRLXLXLLLRXXLLXLRXXLLLRLXRRXRLXLXXXXXXLXRXXRXXXRXLXXRRXLLXRRXLXXRRXLXXRLXLXXLXRXXRLR...
Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wrong steps or — horror of horrors! — stops for a while. For example, i...
0
{"tests": "{\"inputs\": [\"6\\n6 3\\nabcbac\\n3 6\\naaa\\n7 1000\\nabczgyo\\n5 4\\nababa\\n20 10\\naaebdbabdbbddaadaadc\\n20 5\\necbedececacbcbccbdec\\n\", \"1\\n7 1782\\nabcabca\\n\", \"1\\n364 1485\\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccc...
The store sells n beads. The color of each bead is described by a lowercase letter of the English alphabet ("a"–"z"). You want to buy some beads to assemble a necklace from them. A necklace is a set of beads connected in a circle. For example, if the store sells beads "a", "b", "c", "a", "c", "c", then you can assemb...
0.625
{"tests": "{\"inputs\": [\"2 2\\n\", \"4 3\\n\", \"2020 2021\\n\", \"4 4\\n\", \"1000 1000\\n\", \"10 19\\n\", \"3 3\\n\", \"8 8\\n\", \"2019 2018\\n\", \"4 1\\n\", \"3 1\\n\", \"1848 1937\\n\", \"2000 2000\\n\", \"2 1\\n\", \"4 2\\n\", \"2021 2\\n\", \"9 9\\n\", \"101 100\\n\", \"7 7\\n\", \"999 2013\\n\", \"598 319\\...
There is a grid with n rows and m columns. Every cell of the grid should be colored either blue or yellow. A coloring of the grid is called stupid if every row has exactly one segment of blue cells and every column has exactly one segment of yellow cells. In other words, every row must have at least one blue cell, an...
0
{"tests": "{\"inputs\": [\"gerald.agapov1991@gmail.com\\n\", \".asd123__..@\\n\", \"a___@1.r\\n\", \"x@x.x@x.x_e_@r1.com\\n\", \"@\\n\", \"_@0.z\\n\", \"0000000a@000a111.r\\n\", \"a@0.\\n\", \"@0.z\\n\", \"@1.r\\n\", \"0@0.x\\n\", \"a@r.z\\n\", \"a@0z\\n\", \"a@.z\\n\", \"a_0.z\\n\", \"a0.z\\n\", \"@.\\n\", \"a@0._\\n\...
One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day. Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume ...
0.125
{"tests": "{\"inputs\": [\"3\\n3\\n2\\n1\\n\", \"3\\n1\\n2\\n3\\n\", \"1\\n139\\n\", \"100\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18\\n18...
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possibl...
0.125
{"tests": "{\"inputs\": [\"4 3\\n4 10 14 1\\n3 6 6 0\\n2 3 3 1\\n\", \"4 2\\n3 4 5 1\\n2 3 3 1\\n\", \"4 2\\n3 4 6 1\\n4 12 15 1\\n\", \"3 1\\n3 4 6 0\\n\", \"1 1\\n1 1 1 0\\n\", \"1 0\\n\", \"4 3\\n4 10 14 1\\n3 7 6 0\\n2 3 3 1\\n\", \"4 2\\n3 4 5 1\\n2 3 6 1\\n\", \"1 1\\n1 1 1 1\\n\", \"4 3\\n4 10 26 1\\n3 7 6 0\\n2...
Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the nodes of the tree such tha...
0.875
{"tests": "{\"inputs\": [\"2 2 2 2\\nULD\\n\", \"3 4 2 2\\nUURDRDRL\\n\", \"4 4 2 2\\nDRUL\\n\", \"1 2 1 2\\nLR\\n\", \"1 1 1 1\\nURDLUURRDDLLURDL\\n\", \"15 17 8 9\\nURRDLUULLDDDRRUR\\n\", \"2 1 1 1\\nD\\n\", \"15 17 8 9\\nURRDLUULLDDRR\\n\", \"15 17 8 9\\nURRDLU\\n\", \"15 17 8 9\\nURRDLUULLDDR\\n\", \"15 17 8 9\\nUR...
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be i...
0.25
{"tests": "{\"inputs\": [\"3 6\\n1 1 1\\n\", \"3 1\\n1 0 1\\n\", \"2 2\\n1 1\\n\", \"4 1000000000000000000\\n0 4 4 5\\n\", \"4 999999999000531216\\n8 7 4 6\\n\", \"8 1000000000000000000\\n1 1 0 0 0 0 0 0\\n\", \"6 1000000000000000000\\n1 1 0 1 0 1\\n\", \"5 152742477016321721\\n0 0 2 6 2\\n\", \"4 1000000000000000000\\...
Consider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that yi is equal to the sum of first i elements of array x (0 ≤ i ≤ m). You have an infinite sequence of arrays A0, A1, A2..., where A0 is given in the input, and for each i ≥ 1 Ai = p(Ai - 1). Als...
0
{"tests": "{\"inputs\": [\"2\\n3 4 500 800 600\\n1 5 10 -20 -30\\n\\nSAMPLE\", \"2\\n3 4 611 800 600\\n1 5 10 -20 -30\\n\\nSAMPLE\", \"2\\n3 7 611 800 600\\n1 5 10 -20 -30\\n\\nSAMPLE\", \"2\\n6 7 611 800 600\\n1 5 10 -20 -30\\n\\nSAMPLE\", \"2\\n5 7 611 800 600\\n1 5 10 -20 -30\\n\\nSAMPLE\", \"2\\n9 7 611 800 600\\n1...
Today Oz is playing with his game-board. He has N coins of type-1 and M coins of type-2. Also the game-board has N squares of type-1 and M squares of type-2. In this game Oz must place one coin into each square. After placing all coins Oz will get a score based on his coin placement strategy . His score calculation i...
0.125
{"tests": "{\"inputs\": [\"2\\n0 10\\n.5 720\\n\\nSAMPLE\", \"10\\n0.18645496223766345 360\\n0.17989902622977394 360\\n0.45262248490623425 360\\n0.04663296744034651 360\\n0.12725823257381275 360\\n0.2895663014860297 48\\n0.05625277914818627 360\\n0.11455689444280615 360\\n0.46003084917418513 360\\n0.17986394802612649 3...
It's the rainy season again, and the city experiences frequent showers throughout the day. The weather report says that there is a P probability of rainfalls today. Raj has to step out for a meeting at the office, and would like to know the probability that it rains during the time he is on the way. Input: The first...
0.75
{"tests": "{\"inputs\": [\"6\\n100 -100 -100 -100 100 -100\", \"6\\n1 2 -6 4 5 3\", \"2\\n-1000 100000\", \"5\\n-1 -2 -3 -4 -5\", \"6\\n000 -100 -100 -100 100 -100\", \"6\\n1 2 -6 0 5 3\", \"2\\n-40 100000\", \"5\\n-1 -2 -5 -4 -5\", \"6\\n1 2 -6 0 9 3\", \"2\\n-64 100000\", \"6\\n000 1 -100 -100 100 -100\", \"2\\n-64 1...
We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of ...
0.25
{"tests": "{\"inputs\": [\"65\\n98\", \"7\\n9\", \"271828182845904523\\n314159265358979323\", \"65\\n110\", \"271828182845904523\\n328419650112448238\", \"271828182845904523\\n491516385100905315\", \"65\\n158\", \"7\\n8\", \"65\\n181\", \"271828182845904523\\n636593337042278053\", \"271828182845904523\\n112881636457854...
Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are? Constraints * 1 ≤ A ≤ B < 2^{60} * A and B are integers. Input The input is given from Standard Input in the following format: ...
0
{"tests": "{\"inputs\": [\"?D-C'KOPUA\", \"?D-C'KOQUA\", \"?D-B'KOQUA\", \"AUQOK'B-D?\", \"-UQOK'BAD?\", \"-UQOK'BBD?\", \"-UQNK'BBD?\", \"?DBB'KNQU-\", \".UQNK'BBD?\", \".UPNK'BBD?\", \".UPNK'BCD?\", \".UPNKB'CD?\", \"?DKC'-OPUA\", \"AUQOK'C-D?\", \"-UQPK'BAD?\", \"-UQOKBB'D?\", \"-UQNK'CBD?\", \"?-BB'KNQUD\", \"?DBB'...
Hiroshi:? D-C'KOPUA Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today. Hiroshi: Here. <image> Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of charact...
0
{"tests": "{\"inputs\": [\"6 5\\n1 1 . 0 0 4\\n1 . . . . .\\n. . 2 2 . .\\n. . 2 2 3 3\\nP . . . . .\\n5\\n0 50 5 10\\n1 20 0 10\\n2 10 5 15\\n3 150 3 5\\n4 100 8 9\\n0 0\", \"6 5\\n1 1 . 0 0 4\\n1 . . . . .\\n. . 2 2 . .\\n. . 2 2 3 3\\nP . - . . .\\n5\\n0 50 5 10\\n1 20 0 10\\n2 10 5 15\\n3 150 3 5\\n4 100 8 9\\n0 0\...
Better things, cheaper. There is a fierce battle at the time sale held in some supermarkets today. "LL-do" here in Aizu is one such supermarket, and we are holding a slightly unusual time sale to compete with other chain stores. In a general time sale, multiple products are cheaper at the same time, but at LL-do, the t...
0
{"tests": "{\"inputs\": [\"3 10\\n0\\n1 1\\n2 2 3\\n4 20\\n2 1 2\\n1 3\\n1 4\\n2 5\\n2 1 2\\n0\\n0\\n3 3\\n0\\n1 1\\n2 2 3\\n0 0\", \"3 10\\n0\\n1 1\\n2 2 3\\n4 20\\n2 1 2\\n1 3\\n1 4\\n1 5\\n2 1 2\\n0\\n0\\n3 3\\n0\\n1 1\\n2 2 3\\n0 0\", \"3 8\\n0\\n1 1\\n2 2 3\\n4 7\\n2 1 2\\n1 3\\n1 4\\n1 5\\n2 1 2\\n0\\n0\\n3 6\\n0...
There are n cups of different sizes and three trays (bon festivals) A, B, and C, and these cups are placed on top of each of the three trays in a pile. However, in any tray, the smallest cup in the tray is on the bottom, the second smallest cup is on top, and the third smallest cup is on top, in ascending order. .. For...
0