info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"2\\n4\\n\\n3\\n\\n2\\n\\n5\\n\\n3\", \"2\\n4\\n3 1 4 2\\n5\\n2 5 3 4 1\\n\", \"2\\n4\\n3 1 4 2\\n5\\n2 5 3 4 1\\n\", \"24\\n4\\n3 2 1 4\\n4\\n4 2 1 3\\n4\\n1 2 3 4\\n4\\n4 3 1 2\\n4\\n1 3 4 2\\n4\\n3 1 2 4\\n4\\n1 3 2 4\\n4\\n2 1 4 3\\n4\\n4 2 3 1\\n4\\n4 1 2 3\\n4\\n1 2 4 3\\n4\\n1 4 2 3\\n4...
This is an interactive problem! Nastia has a hidden permutation p of length n consisting of integers from 1 to n. You, for some reason, want to figure out the permutation. To do that, you can give her an integer t (1 ≤ t ≤ 2), two different indices i and j (1 ≤ i, j ≤ n, i ≠ j), and an integer x (1 ≤ x ≤ n - 1). Dep...
0
{"tests": "{\"inputs\": [\"3\\n2 3 5\\n\", \"3\\n4663018 4080080 6848370\\n\", \"2\\n5555 1242323\\n\", \"6\\n3835302 971984 8706888 1080445 2224695 1093317\\n\", \"50\\n3987477 8934938 4067156 6712855 7269334 5039822 9533601 9335400 5992073 2619268 438734 8620973 4347619 4307947 2249161 815221 7615258 8244100 8341666 ...
Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The n destinations are described by a non-negative integers sequence a1, a2, ..., an. The number ak represents t...
0.125
{"tests": "{\"inputs\": [\"3 1\\n2 2\\n\", \"3 6\\n1 1\\n2 2\\n3 1\\n3 2\\n2 3\\n3 3\\n\", \"3 7\\n1 1\\n2 2\\n3 1\\n1 3\\n3 2\\n2 3\\n3 3\\n\", \"500 1\\n182 425\\n\", \"3 1\\n1 3\\n\", \"6 1\\n1 4\\n\", \"499 1\\n372 498\\n\", \"8 12\\n4 2\\n1 5\\n3 7\\n4 3\\n8 2\\n5 4\\n4 1\\n6 5\\n6 7\\n5 2\\n1 4\\n8 3\\n\", \"5 25...
George loves graphs. Most of all, he loves interesting graphs. We will assume that a directed graph is interesting, if it meets the following criteria: * The graph doesn't contain any multiple arcs; * There is vertex v (we'll call her the center), such that for any vertex of graph u, the graph contains arcs (u, ...
0
{"tests": "{\"inputs\": [\"4 3 4\\nH 2\\nV 2\\nV 3\\nV 1\\n\", \"7 6 5\\nH 4\\nV 3\\nV 5\\nH 2\\nV 1\\n\", \"2 2 1\\nH 1\\n\", \"200000 200000 1\\nH 1\\n\", \"2 2 2\\nH 1\\nV 1\\n\", \"10 10 10\\nV 6\\nH 8\\nV 4\\nV 8\\nH 2\\nH 5\\nV 9\\nH 7\\nH 3\\nV 7\\n\", \"2 2 1\\nV 1\\n\", \"2 2 2\\nV 1\\nH 1\\n\", \"2 4 1\\nH 2\...
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how. In order not to waste time, he decided to practice t...
0.75
{"tests": "{\"inputs\": [\"7 6\\n5 7 7 4 6 6 2\\n1 2\\n2 3\\n2 6\\n1 7\\n4 7\\n3 5\\n\", \"10 4\\n1 5 2 9 1 3 4 2 1 7\\n2 4\\n3 8\\n7 10\\n1 9\\n\", \"2 2\\n0 0\\n1 2\\n1 2\\n\", \"2 2\\n0 100000000\\n1 2\\n1 2\\n\", \"3 6\\n10 20 30\\n1 2\\n1 3\\n2 3\\n1 2\\n2 3\\n1 3\\n\", \"3 6\\n100000000 99999999 0\\n1 2\\n1 3\\n2...
A function <image> is called Lipschitz continuous if there is a real constant K such that the inequality |f(x) - f(y)| ≤ K·|x - y| holds for all <image>. We'll deal with a more... discrete version of this term. For an array <image>, we define it's Lipschitz constant <image> as follows: * if n < 2, <image> * if n ...
0.375
{"tests": "{\"inputs\": [\"3 2\\n1 2\\n3 2\\n\", \"4 5\\n2 1\\n1 3\\n2 3\\n4 2\\n4 3\\n\", \"5 10\\n4 3\\n4 1\\n2 1\\n1 3\\n5 1\\n5 3\\n5 4\\n2 5\\n2 3\\n2 4\\n\", \"2 1\\n2 1\\n\", \"4 6\\n1 4\\n4 2\\n2 3\\n1 2\\n1 3\\n4 3\\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 10\\n2 1\\n5 ...
While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots o...
0.5
{"tests": "{\"inputs\": [\"12\\n1 1 2 2 4 4 3 3 1 10 8\\n\", \"7\\n1 2 1 1 4 4\\n\", \"3\\n1 2\\n\", \"10\\n1 2 2 2 5 4 6 5 6\\n\", \"85\\n1 1 2 2 4 6 1 3 6 3 3 11 9 14 12 5 8 11 16 19 12 17 2 19 1 24 6 2 6 6 24 3 20 1 1 1 17 8 4 25 31 32 39 12 35 23 31 26 46 9 37 7 5 23 41 41 39 9 11 54 36 54 28 15 25 58 56 18 23 70 6...
Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit any city h...
0
{"tests": "{\"inputs\": [\"3\\nteama 10\\nteamb 20\\nteamc 40\\n2\\n10 20\\nteama\\n\", \"2\\nteama 10\\nteamb 10\\n2\\n10 10\\nteamb\\n\", \"10\\njcfdh 1000000\\nchk 1000000\\nkga 1000000\\nbeh 1000000\\ngeg 1000000\\nhaj 1000000\\nagah 1000000\\ndhk 1000000\\nhj 1000000\\ndb 1000000\\n5\\n1000000 1000000 1000000 1000...
Vasya plays the Need For Brake. He plays because he was presented with a new computer wheel for birthday! Now he is sure that he will win the first place in the championship in his favourite racing computer game! n racers take part in the championship, which consists of a number of races. After each race racers are a...
0
{"tests": "{\"inputs\": [\"3 4 4\\n....\\n###.\\n....\\n1 1 3 1\\n\", \"2 2 1\\n.#\\n#.\\n1 1 2 2\\n\", \"3 4 1\\n....\\n###.\\n....\\n1 1 3 1\\n\", \"4 4 4\\n...#\\n.#.#\\n....\\n##..\\n1 1 3 4\\n\", \"10 10 1\\n##########\\n#.........\\n#.#######.\\n#.#.....#.\\n#.#.###.#.\\n#.#.#.#.#.\\n#.#.#.#.#.\\n#.#.#...#.\\n#.#...
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks. Formally, her room can be represented as a field of n × m cells, each cell of which is empty or littered with cans. Olya drank a lot of energy drink, so now she can run k meters per second. Each second she chooses...
0.875
{"tests": "{\"inputs\": [\"10\\n331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951\\n226011312 266003835 342809544 504667531 529814910 684873393 817026985 844010788 993949858 1031395667\\n\", \"5\\n12 7 87 22 11\\n18 39 9 12 16\\n\", \"3\\n8 4 13\\n17 2 7\\n\", \"5\\n134 ...
Alice has a very important message M consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice generates a random key K of the length equal to the message's length. Alice computes the bitwise xor of each element of the m...
0.375
{"tests": "{\"inputs\": [\"1\\n\\nSAMPLE\", \"2\", \"1\\n\\nSANPLE\", \"1\\n\\nSANQLE\", \"1\\n\\nSNAQLE\", \"1\\n\\nSEAQLN\", \"1\\n\\nSEAQNL\", \"1\\n\\nSEARNL\", \"1\\n\\nSEARNM\", \"1\\n\\nMNRAES\", \"1\\n\\nSNRAEM\", \"1\\n\\nMEARNS\", \"1\\n\\nLEARNS\", \"1\\n\\nKEARNS\", \"1\\n\\nKEANRS\", \"1\\n\\nSRNAEK\", \"1...
Mr. Hahn, our very own DJ, was seeing Chester and Mike fighting over such questions lately. Being a geek himself, he thought of showing off his skills and gave the both of them a question. He gave them a single positive integer, N. For all the numbers under 10^N(inclusive) they had to add the square of the digits of ...
0
{"tests": "{\"inputs\": [\"The\\nquick\\nbrown\\nfox\\npragyan\\njumped\\nover\\nthe\\nlazy\\ndog\", \"The\\nquick\\nbrown\\nfox\\njumped\\nover\\nthe\\nlazy\\ndog\\npragya\\npragy\\npra\\nragyan\\noragyan\\npragyam\\npRaGYAN\\nAny\\ninput\\nbeyond\\nthis\\nshould\\nnot\\nbe\\nprocessed\", \"Far\\nout\\nin\\nthe\\nunch...
Problem Statement: You are one of the organizers of Pragyan.Having worked so hard to ensure success of the event, you are able to spot the word "pragyan" in any text. You are given a stream of character strings and you need to output them till you find the word "pragyan".Stop processing after NOTE: The word "pragyan"...
0.875
{"tests": "{\"inputs\": [\"2\\n2\\n3\\n\\nSAMPLE\", \"2\\n2\\n3\", \"10\\n387\\n56\\n92\\n346\\n648\\n76\\n864\\n75\\n654\\n456\", \"2\\n2\\n6\", \"10\\n387\\n56\\n92\\n346\\n10\\n76\\n864\\n75\\n654\\n456\", \"2\\n4\\n3\\n\\nSAMPLE\", \"2\\n2\\n5\", \"10\\n313\\n56\\n92\\n346\\n10\\n76\\n864\\n75\\n654\\n456\", \"10\\...
A binary string of length N is a string of N characters, where each character is either 0 or 1. Wet Shark makes a list binStrings, consisting of all 2^N N-digit binary strings. For each string X in binStrings, Wet Shark runs a function ZeroShark(X), defined as follows (psuedocode): bool ZeroShark(x): //note the zero...
0
{"tests": "{\"inputs\": [\"PD?D??P\", \"P?P?\", \"PDPD???\", \"?P?P\", \"DDPP???\", \"??PP\", \"DDPO???\", \"??OP\", \"DDPO?>?\", \"??OO\", \"?>?OPDD\", \"@?OP\", \"?>?PPDD\", \"@?PO\", \"DDPP?>?\", \"@?PN\", \"DDPP?>@\", \"NP?@\", \"DDPP??@\", \"@P?N\", \"@DPP??D\", \"@P@N\", \"D??PPD@\", \"?P@N\", \"D??PPC@\", \"NP@?...
For a string S consisting of the uppercase English letters `P` and `D`, let the doctoral and postdoctoral quotient of S be the total number of occurrences of `D` and `PD` in S as contiguous substrings. For example, if S = `PPDDP`, it contains two occurrences of `D` and one occurrence of `PD` as contiguous substrings, s...
0.25
{"tests": "{\"inputs\": [\"1 3\\n3 4\\n3 5\\n3 6\\n4 6\\n4 7\\n4 7\\n5 6\\n6 7\\n5 8\\n5 8\\n6 8\\n6 9\\n7 9\\n8 9\\n9 2\\n0 0\\n1 3\\n3 4\\n3 4\\n4 2\\n0 0\", \"1 3\\n3 4\\n3 5\\n3 6\\n4 6\\n4 7\\n4 7\\n5 6\\n6 7\\n5 8\\n5 8\\n3 8\\n6 9\\n7 9\\n8 9\\n9 2\\n0 0\\n1 3\\n3 4\\n3 4\\n4 2\\n0 0\", \"1 3\\n3 4\\n3 5\\n3 6\\...
In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate and other clan. However, when it came time to decide the sharing rou...
0
{"tests": "{\"inputs\": [\"4 5\\n1 2 10\\n1 3 15\\n2 3 5\\n2 4 3\\n3 4 10\\n2\\n1 4 10 LoveLetter\\n2 3 20 Greetings\\n3 3\\n1 2 1\\n2 3 1\\n3 1 1\\n3\\n1 2 1 BusinessMailC\\n2 3 1 BusinessMailB\\n3 1 1 BusinessMailA\\n0 0\", \"4 5\\n1 2 10\\n1 3 15\\n2 3 5\\n2 4 3\\n3 4 10\\n2\\n1 4 10 LoveLetter\\n2 3 13 Greetings\\n...
The postal system in the area where Masa lives has changed a bit. In this area, each post office is numbered consecutively from 1 to a different number, and mail delivered to a post office is intended from that post office via several post offices. Delivered to the post office. Mail "forwarding" is only done between sp...
0
{"tests": "{\"inputs\": [\"2 1\", \"100 50\", \"4 1\", \"110 50\", \"4 0\", \"010 50\", \"110 89\", \"110 12\", \"010 4\", \"010 1\", \"3 2\", \"3 1\", \"010 6\", \"010 2\", \"010 3\", \"011 1\", \"011 2\", \"15 1\", \"14 1\", \"7 1\", \"22 2\", \"22 4\", \"011 6\", \"100 10\", \"100 9\", \"011 10\", \"6 4\", \"010 7\"...
Problem C: Earn Big A group of N people is trying to challenge the following game to earn big money. First, N participants are isolated from each other. From this point, they are not allowed to contact each other, or to leave any information for other participants. The game organizer leads each participant, one by on...
0.375
{"tests": "{\"inputs\": [\"7 8 3\", \"1000000000000000000 1000000000000000000 1000\", \"5 10 3\", \"1 1 2\", \"2 10 1\", \"10 8 3\", \"1000000000000000000 1000000000000000000 1001\", \"5 2 3\", \"10 8 6\", \"2 2 2\", \"1 10 1\", \"10 6 6\", \"2 3 2\", \"2 10 2\", \"2 11 2\", \"3 5 3\", \"6 5 3\", \"6 5 2\", \"6 8 2\", ...
Problem There are $ M $ type characters. Use them to create a string of length $ N $. How many strings are used that have $ K $ or more? Find too much divided by $ 998244353 $. Here, the difference between two strings of length $ N $ is defined as follows. * If the two strings are $ S = S_1S_2 \ ldots S_N $, $ T = T...
0.125
{"tests": "{\"inputs\": [\"-3 0\\n2 2 2\", \"0 0\\n2 2 2\", \"-3 0\\n3 2 2\", \"-1 0\\n2 2 2\", \"-4 0\\n3 2 2\", \"1 0\\n2 2 2\", \"-4 -1\\n3 2 2\", \"1 0\\n4 2 2\", \"-4 -1\\n2 2 2\", \"-4 -1\\n4 2 2\", \"-4 -1\\n4 2 3\", \"-4 -1\\n4 2 6\", \"-4 -1\\n8 2 6\", \"-8 -1\\n8 2 6\", \"-8 -2\\n8 2 6\", \"-8 -2\\n8 2 0\", \...
Find the tangent lines between a point $p$ and a circle $c$. Constraints * $-1,000 \leq px, py, cx, cy \leq 1,000$ * $1 \leq r \leq 1,000$ * Distance between $p$ and the center of $c$ is greater than the radius of $c$. Input The input is given in the following format. $px \; py$ $cx \; cy \; r$ $px$ and $py$ repr...
0.25
{"tests": "{\"inputs\": [\"4 5 5\\n3 5 2 0 4\\n4 2 5 4\\n0 0 0 0 1\\n1 0 1 0 0\\n0 1 0 0 0\\n1 1 1 0 0\\n\", \"3 7 3\\n2 3 0 0 2 0 1\\n2 1 3\\n1 0 0 0 1 0 0\\n0 0 0 0 0 0 1\\n1 1 0 0 0 0 0\\n\", \"2 58 77\\n0 0 0 0 6 0 0 0 40 0 0 0 0 22 0 0 41 74 0 0 0 0 0 0 0 15 0 0 60 5 69 0 0 30 0 0 23 60 0 35 0 0 0 0 0 0 69 0 0 0 0...
Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny. He has a special interest to create difficult problems for others to solve. This time, with many 1 × 1 × 1 toy bricks, he builds up a 3-dimensional object. We can describe ...
0.125
{"tests": "{\"inputs\": [\"3 3\\n1 2 3\\n2 0 4\\n4 5 6\\n\", \"3 3\\n1 2 3\\n2 3 4\\n3 4 2\\n\", \"4 5\\n1 3 5 6 7\\n3 0 7 0 9\\n5 0 0 0 10\\n8 9 10 11 12\\n\", \"3 3\\n1 2 3\\n3 0 4\\n4 5 6\\n\", \"3 3\\n1 2 3\\n2 3 4\\n3 5 5\\n\", \"3 3\\n2999 3000 4000\\n3000 0 7000\\n4000 6000 8000\\n\", \"8 5\\n2 3 6 7 9\\n4 0 0 0...
In this problem, a n × m rectangular matrix a is called increasing if, for each row of i, when go from left to right, the values strictly increase (that is, a_{i,1}<a_{i,2}<...<a_{i,m}) and for each column j, when go from top to bottom, the values strictly increase (that is, a_{1,j}<a_{2,j}<...<a_{n,j}). In a given ma...
0.125
{"tests": "{\"inputs\": [\"2\\n1 1\\n0 0\\n\", \"2\\n1 1\\n1 1\\n\", \"2\\n42 1337\\n13 420\\n\", \"3\\n1 2\\n1 2\\n1 2\\n\", \"10\\n2139 77689\\n7692 31588\\n39321 54942\\n48988 55097\\n46970 54864\\n61632 70126\\n4240 37374\\n69600 79133\\n69308 91118\\n12408 56672\\n\", \"50\\n16 47\\n24 34\\n12 78\\n72 91\\n68 98\\...
An online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared n problems; and since the platform is very popular, 998244351 coder from all over the world is going to solve them. For each problem, the authors estimated the number of people who would solve it: fo...
0
{"tests": "{\"inputs\": [\"3\\nRRRR\\nRSP\\nS\\n\", \"3\\nRRRR\\nRSP\\nS\\n\", \"3\\nRRRR\\nSSP\\nS\\n\", \"3\\nQRRR\\nRSP\\nS\\n\", \"3\\nRRRR\\nSSP\\nR\\n\", \"3\\nQRRR\\nRSP\\nR\\n\", \"3\\nRRSR\\nSSP\\nS\\n\", \"3\\nRRTR\\nSSP\\nS\\n\", \"3\\nSRRR\\nSSP\\nR\\n\", \"3\\nRRTR\\nSSP\\nR\\n\", \"3\\nRRQR\\nRSP\\nR\\n\"...
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string s = s_1 s_2 ... s_{n} of length n where each letter is either R, S or P. While initializing, the bot is choosing a starting index pos (1 ≤ pos ≤ n), and then it can play any numbe...
0.125
{"tests": "{\"inputs\": [\"3\\n33 27\\n6 10\\n5 6\\n100 200\\n10 10\\n5 5\\n1 19\\n1 3\\n19 5\\n\", \"9\\n475033014 267058742\\n26843 148652\\n850113755 279316120\\n871120869 885251487\\n51363 15651\\n220811492 256297120\\n473761699 194406678\\n38725 23371\\n167395720 333327477\\n107541472 19164492\\n74340 1113\\n65438...
You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. You can carry at most p units and your follower — at most f units. ...
0.625
{"tests": "{\"inputs\": [\"3\\n5\\n2 1 2 1 1\\n4\\n9 2 2 2\\n1\\n998244353\\n\", \"3\\n5\\n2 1 2 1 1\\n4\\n11 2 2 2\\n1\\n998244353\\n\", \"3\\n5\\n1 1 2 1 1\\n4\\n11 2 2 2\\n1\\n998244353\\n\", \"3\\n5\\n2 2 2 1 1\\n4\\n11 2 2 2\\n1\\n998244353\\n\", \"3\\n5\\n1 1 1 1 1\\n4\\n11 2 3 2\\n1\\n998244353\\n\", \"3\\n5\\n1...
In the 2050 Conference, some people from the competitive programming community meet together and are going to take a photo. The n people form a line. They are numbered from 1 to n from left to right. Each of them either holds a cardboard with the letter 'C' or a cardboard with the letter 'P'. Let C=\\{c_1,c_2,...,c_m\...
0
{"tests": "{\"inputs\": [\"7\\n3 1 6 7\\n4 3 5 2 9\\n2 8 1\\n4 3 7 6 4\\n3 2 5 9\\n3 6 3 8\\n3 4 2 9\\n\", \"4\\n5 2 6 10 8 3\\n1 7\\n2 10 4\\n2 9 5\\n\", \"5\\n3 12 10 19\\n5 1 4 18 11 13\\n4 17 15 2 6\\n4 3 12 18 10\\n4 2 8 5 9\\n\", \"10\\n1 77966\\n1 79480\\n1 94920\\n1 53920\\n1 15585\\n1 57339\\n1 1585\\n1 91802\...
Paw the Spider is making a web. Web-making is a real art, Paw has been learning to do it his whole life. Let's consider the structure of the web. <image> There are n main threads going from the center of the web. All main threads are located in one plane and divide it into n equal infinite sectors. The sectors are in...
0.375
{"tests": "{\"inputs\": [\"10 3\\nabab\\nbab\\n\", \"541 9\\nbxhwcmunbdxcatppdsw\\nshbppncwbnsxxnxunwsbncpdchcbcspdcppdchmbbcuapphpdxbpcswcxpxpdscxpddbcppdxhpxbuxxdbpdpuudb\\n\", \"8058035 2\\nrioqrqetkzfbldjiemsfzbhzfnwywmxxgdpyl\\ngfmhefhyyndzmsbfnefmwmpxfxfhflzplgoxfrrdxilibzlephlezisfztsfitnrzrilzmtipzofkrwlmhnifdz...
Let's introduce the designation <image>, where x is a string, n is a positive integer and operation " + " is the string concatenation operation. For example, [abc, 2] = abcabc. We'll say that string s can be obtained from string t, if we can remove some characters from string t and obtain string s. For example, string...
0
{"tests": "{\"inputs\": [\"3 3\\n100 100 100\\n100 1 100\\n100 100 100\\n\", \"3 3\\n0 0 0\\n0 10000 0\\n0 0 0\\n\", \"3 3\\n1 10 1\\n1 10 1\\n1 10 1\\n\", \"3 3\\n0 0 0\\n0 100 0\\n0 0 0\\n\", \"4 5\\n87882 40786 3691 85313 46694\\n28884 16067 3242 97367 78518\\n4250 35501 9780 14435 19004\\n64673 65438 56977 64495 27...
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column. Iahub starts with ...
0
{"tests": "{\"inputs\": [\"2 2\\n\", \"6 1\\n\", \"6 3\\n\", \"94444 9\\n\", \"50000 50000\\n\", \"1 8\\n\", \"100000 5001\\n\", \"50323 7\\n\", \"24236 90163\\n\", \"51520 73331\\n\", \"54230 31747\\n\", \"3 6\\n\", \"99999 1111\\n\", \"26946 99523\\n\", \"3 10\\n\", \"99999 99999\\n\", \"53513 34040\\n\", \"50000 100...
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game. The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, ...
0.875
{"tests": "{\"inputs\": [\"1 0\\n0 1\\n\", \"1 2\\n3 4\\n\", \"12 180\\n79 47\\n\", \"116954418 255136645\\n-851641472 174491320\\n\", \"95145788 53456393\\n42406028 83987544\\n\", \"-2665612 -7693032\\n-2861368 -6201836\\n\", \"-67 -77\\n-56 -75\\n\", \"-2 1\\n1 -2\\n\", \"-718 -387\\n972 972\\n\", \"-1 -1\\n1 0\\n\",...
The determinant of a matrix 2 × 2 is defined as follows: <image> A matrix is called degenerate if its determinant is equal to zero. The norm ||A|| of a matrix A is defined as a maximum of absolute values of its elements. You are given a matrix <image>. Consider any degenerate matrix B such that norm ||A - B|| is m...
0
{"tests": "{\"inputs\": [\"2\\n1 1\\n1 -1\\n-1 1\\n-1 -1\\n1 1\\n2 2\\n4 4\\n6 6\\n\", \"1\\n7434523 11523154\\n7611807 5876512\\n3910524 11523154\\n3373024 5876512\\n\", \"1\\n-100000000 -100000000\\n100000000 -100000000\\n-100000000 100000000\\n100000000 99999999\\n\", \"1\\n3 0\\n5 0\\n4 9\\n5 9\\n\", \"1\\n35 23\\n...
Group of Berland scientists, with whom you have a close business relationship, makes a research in the area of peaceful nuclear energy. In particular, they found that a group of four nanobots, placed on a surface of a plate, can run a powerful chain reaction under certain conditions. To be precise, researchers introd...
0
{"tests": "{\"inputs\": [\"11\\n0 0 0 1 1 0 1 0 0 1 1\\n1 2\\n1 3\\n2 4\\n2 5\\n5 6\\n5 7\\n3 8\\n3 9\\n3 10\\n9 11\\n\", \"4\\n0 0 0 0\\n1 2\\n2 3\\n3 4\\n\", \"2\\n1 0\\n2 1\\n\", \"1\\n0\\n\", \"15\\n0 1 0 0 1 1 0 1 1 1 1 1 0 1 0\\n10 7\\n10 3\\n10 8\\n5 7\\n13 14\\n8 13\\n15 4\\n15 13\\n5 2\\n9 3\\n11 15\\n13 6\\n1...
Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n vertices in the tree, each of them is painted black or white. Anton doesn't like multicolored trees, so he wants to change the tree such that all vertices have the same color (black or white). To c...
0
{"tests": "{\"inputs\": [\"4\\nivan 3 123 123 456\\nivan 2 456 456\\nivan 8 789 3 23 6 56 9 89 2\\ndasha 2 23 789\\n\", \"3\\nkarl 2 612 12\\npetr 1 12\\nkatya 1 612\\n\", \"2\\nivan 1 00123\\nmasha 1 00123\\n\", \"1\\negew 5 3 123 23 1234 134\\n\", \"20\\nl 6 02 02 2 02 02 2\\nl 8 8 8 8 2 62 13 31 3\\ne 9 0 91 0 0 60 ...
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri...
0
{"tests": "{\"inputs\": [\"3\\n0 10 20\\n10 0 -100\\n20 -100 0\", \"4\\n0 1000000000 1000000000 1000000000\\n1000000000 0 1000000000 1000000000\\n1000000000 1000000000 0 -1\\n1000000000 1000000000 -1 0\", \"16\\n0 5 -4 -5 -8 -4 7 2 -4 0 7 0 2 -3 7 7\\n5 0 8 -9 3 5 2 -7 2 -7 0 -1 -4 1 -1 9\\n-4 8 0 -9 8 9 3 1 4 9 6 6 -6...
There are N rabbits, numbered 1, 2, \ldots, N. For each i, j (1 \leq i, j \leq N), the compatibility of Rabbit i and j is described by an integer a_{i, j}. Here, a_{i, i} = 0 for each i (1 \leq i \leq N), and a_{i, j} = a_{j, i} for each i and j (1 \leq i, j \leq N). Taro is dividing the N rabbits into some number of...
0
{"tests": "{\"inputs\": [\"7\\n1 2\\n2 3\\n2 4\\n4 5\\n4 6\\n6 7\", \"10\\n1 2\\n2 3\\n3 4\\n2 5\\n6 5\\n6 7\\n7 8\\n5 9\\n10 5\", \"8\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n5 7\\n5 8\", \"7\\n1 2\\n2 3\\n2 4\\n2 5\\n4 6\\n6 7\", \"7\\n1 4\\n2 3\\n2 4\\n4 5\\n4 6\\n6 7\", \"7\\n1 4\\n2 3\\n2 4\\n4 5\\n7 6\\n6 7\", \"7\\n1 4\\...
Takahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc. A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i. He would like to make one as follows: * Specify two non-negative integers A and B. * Pr...
0
{"tests": "{\"inputs\": [\"2\\n2 2\", \"4\\n3 3 3 3\", \"7\\n27 0 0 0 0 0 0\", \"3\\n1 0 3\", \"10\\n1000 193 256 777 0 1 1192 1234567891011 48 425\", \"2\\n2 4\", \"4\\n3 3 3 2\", \"10\\n1000 193 256 777 0 2 1192 1234567891011 48 425\", \"2\\n2 7\", \"10\\n1000 193 256 777 0 2 1192 2138223215855 48 425\", \"2\\n0 7\",...
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) * Determine the largest element in the sequence (if there is more than...
0.375
{"tests": "{\"inputs\": [\"7 7\\n1 3\\n2 7\\n3 4\\n4 5\\n4 6\\n5 6\\n6 7\", \"3 3\\n1 2\\n1 3\\n2 3\", \"7 4\\n1 3\\n2 7\\n3 4\\n4 5\\n4 6\\n5 6\\n6 7\", \"7 7\\n1 3\\n2 7\\n3 4\\n4 5\\n4 1\\n5 6\\n6 7\", \"7 7\\n1 3\\n2 7\\n3 4\\n4 5\\n4 6\\n4 6\\n6 7\", \"7 4\\n1 4\\n2 7\\n3 4\\n4 5\\n4 6\\n5 6\\n6 7\", \"7 7\\n1 5\\...
You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and vi...
0.75
{"tests": "{\"inputs\": [\"15\\n3\\n1\\n4\\n1\\n5\\n9\\n2\\n6\\n5\\n3\\n5\\n8\\n9\\n7\\n9\", \"3\\n3\\n2\\n5\", \"15\\n3\\n1\\n4\\n1\\n5\\n9\\n2\\n6\\n5\\n3\\n5\\n8\\n9\\n6\\n9\", \"3\\n3\\n2\\n10\", \"3\\n6\\n2\\n10\", \"3\\n6\\n3\\n10\", \"3\\n7\\n3\\n10\", \"3\\n7\\n5\\n10\", \"3\\n7\\n9\\n10\", \"3\\n7\\n13\\n10\",...
N people are waiting in a single line in front of the Takahashi Store. The cash on hand of the i-th person from the front of the line is a positive integer A_i. Mr. Takahashi, the shop owner, has decided on the following scheme: He picks a product, sets a positive integer P indicating its price, and shows this product...
0
{"tests": "{\"inputs\": [\"6 6\\n6\\n1 1\\n6 1\\n3 2\\n3 5\\n1 6\\n5 6\\n2\\n1 3\\n5 3\\n6 6\\n6\\n3 2\\n3 5\\n6 1\\n1 1\\n1 6\\n5 6\\n2\\n2 3\\n5 3\\n0 0\", \"6 6\\n6\\n1 1\\n6 1\\n3 2\\n3 5\\n1 6\\n5 6\\n2\\n1 3\\n5 3\\n6 6\\n6\\n3 2\\n3 5\\n6 1\\n1 1\\n1 6\\n5 6\\n2\\n2 3\\n6 3\\n0 0\", \"6 6\\n6\\n1 1\\n6 1\\n3 2\\...
Convenience store Deven Eleven is planning to open its first store in Aizuwakamatsu City to expand its business. There are already many other convenience stores in Aizuwakamatsu, so the place to open a new store is likely to be the key to success. Under the premise that "customers use the convenience store closest to t...
0
{"tests": "{\"inputs\": [\"4 5\\nWRWRW\\nBWRWB\\nWRWRW\\nRWBWR\", \"4 5\\nWRWRW\\nBRWWB\\nWRWRW\\nRWBWR\", \"4 5\\nWRWRW\\nBWRWB\\nWRWRW\\nRWBWQ\", \"4 5\\nWQWRW\\nBWRXB\\nRVWRW\\nWQBWQ\", \"4 3\\nWQWRW\\nBWRXB\\nRVWRW\\nRWBWQ\", \"4 5\\nWQWRW\\nBWRXC\\nRVWRW\\nWQBWQ\", \"4 10\\nWRWQW\\nBWRXB\\nRVWRW\\nRWBWQ\", \"4 0\\...
problem President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red. Chairman K is trying to repaint some of the squares on this flag to make i...
0
{"tests": "{\"inputs\": [\"19\", \"0\", \"26\", \"25\", \"23\", \"5\", \"4\", \"1\", \"8\", \"38\", \"47\", \"48\", \"75\", \"138\", \"149\", \"132\", \"374\", \"315\", \"933\", \"945\", \"456\", \"942\", \"2139\", \"1374\", \"3723\", \"18\", \"14\", \"7\", \"2\", \"3\", \"12\", \"15\", \"16\", \"17\", \"6\", \"20\", \...
Fast Forwarding Mr. Anderson frequently rents video tapes of his favorite classic films. Watching the films so many times, he has learned the precise start times of his favorite scenes in all such films. He now wants to find how to wind the tape to watch his favorite scene as quickly as possible on his video player. ...
0
{"tests": "{\"inputs\": [\"3\\n10 40\\n10 40\\n20 30\", \"4\\n1 2\\n2 3\\n3 4\\n4 1\", \"3\\n10 40\\n15 40\\n20 30\", \"4\\n1 2\\n3 3\\n3 4\\n4 1\", \"3\\n10 40\\n15 40\\n40 30\", \"4\\n1 2\\n3 3\\n3 7\\n4 1\", \"4\\n2 2\\n3 3\\n3 7\\n4 1\", \"3\\n10 40\\n15 40\\n20 32\", \"4\\n2 4\\n3 3\\n3 7\\n4 1\", \"3\\n10 36\\n15...
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to gain dexterity that never mistypes by carefully stacking blocks. Since there are many building blocks, let's build a tall tower. There are N blocks, and the i-th (...
0.125
{"tests": "{\"inputs\": [\"aaaaaa\\naaaaaa\", \"abcbcdbc\\nabc\", \"baaaaaaaa\\nb\", \"aaaaaa\\naaaaab\", \"bbcbcdbc\\nabc\", \"aaaaaa\\nbbaaaa\", \"bbcbcdbc\\nbca\", \"aaaaaa\\nbaaaaa\", \"bbcbcdbc\\nacb\", \"aaaaaa\\nbbaa`a\", \"cbdcbcbb\\nbca\", \"aaaaaa\\nbaba`a\", \"cbdcbcbb\\nbda\", \"aaaaab\\nbaba`a\", \"ccdcbcb...
The unlucky Ikta-kun has rewritten the important character string T that he had to a different character string T'by the virus. It is known that the virus has rewritten one letter of T to a different letter. That is, T and T'are different by exactly one character. In order to restore T, Ikta prepared a document S in wh...
0.875
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5\", \"5\\n0 2 3 4 5\", \"5\\n1 2 1 4 5\", \"5\\n0 4 3 13 4\", \"5\\n0 2 3 4 8\", \"5\\n0 2 3 4 14\", \"5\\n0 1 3 4 5\", \"5\\n0 2 3 4 2\", \"5\\n0 2 3 8 2\", \"5\\n0 2 3 13 2\", \"5\\n0 2 3 13 4\", \"5\\n0 4 3 9 4\", \"5\\n0 4 3 12 4\", \"5\\n1 4 3 12 4\", \"5\\n2 4 3 12 4\", \"5...
problem Given the sequence $ A $ of length $ N $. The $ i $ item in $ A $ is $ A_i $. You can do the following for this sequence: * $ 1 \ leq i \ leq N --Choose the integer i that is 1 $. Swap the value of $ A_i $ with the value of $ A_ {i + 1} $. Find the minimum number of operations required to make $ A $ a sequ...
0.125
{"tests": "{\"inputs\": [\"5\\nyou\\nate\\nmy\\nhum\\ntoast\", \"7\\nshe\\nsells\\nsea\\nshells\\nby\\nthe\\nseashore\", \"7\\nshf\\nsells\\nsea\\nshells\\nby\\nthe\\nseashore\", \"7\\nshf\\nsells\\nsea\\nshells\\nby\\nteh\\nseashore\", \"7\\nshf\\nsells\\nsea\\nshells\\nby\\nthd\\nseashore\", \"7\\nshf\\nsells\\nsea\\...
Problem Here is a list of strings. Let's take a break and play with shiritori. Shiritori is performed according to the following rules. 1. First of all, select one of your favorite strings from the list and exclude that string from the list. 2. Next, select one character string from the list in which the last charact...
0.5
{"tests": "{\"inputs\": [\"16\\ninsert 35 99\\ninsert 3 80\\ninsert 1 53\\ninsert 14 25\\ninsert 80 76\\ninsert 42 3\\ninsert 86 47\\ninsert 21 12\\ninsert 7 10\\ninsert 6 90\\nprint\\nfind 21\\nfind 22\\ndelete 35\\ndelete 99\\nprint\", \"16\\ninsert 35 99\\ninsert 3 80\\ninsert 1 53\\ninsert 14 25\\ninsert 80 76\\nin...
A binary search tree can be unbalanced depending on features of data. For example, if we insert $n$ elements into a binary search tree in ascending order, the tree become a list, leading to long search times. One of strategies is to randomly shuffle the elements to be inserted. However, we should consider to maintain t...
0.75
{"tests": "{\"inputs\": [\"5\\n0 1\\n0 2\\n0 3\\n1 1\\n2\", \"5\\n0 1\\n0 2\\n0 2\\n1 1\\n2\", \"5\\n0 1\\n0 2\\n0 2\\n0 1\\n2\", \"5\\n0 1\\n0 2\\n0 3\\n0 1\\n2\", \"5\\n0 1\\n0 2\\n0 4\\n1 1\\n2\", \"5\\n0 1\\n0 2\\n0 4\\n0 0\\n2\", \"5\\n0 1\\n0 0\\n0 2\\n0 0\\n2\", \"5\\n0 1\\n0 0\\n0 1\\n0 0\\n2\", \"5\\n0 1\\n0 0...
For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor. * insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted elem...
0
{"tests": "{\"inputs\": [\"2\\n7\\nabcbdca\\n3\\nabb\", \"2\\n0\\nabcbdca\\n3\\nabb\", \"2\\n7\\nacdbcba\\n3\\nabb\", \"2\\n0\\nabcbdca\\n3\\naba\", \"2\\n0\\nabcbeca\\n3\\ncba\", \"2\\n0\\nbcdacaa\\n3\\ndbb\", \"2\\n1\\nacdbcaa\\n3\\nbba\", \"2\\n1\\nbcdacaa\\n3\\nbbb\", \"2\\n1\\n`bcdaca\\n3\\nbba\", \"2\\n1\\nacebbb...
Chef loves palindromes. Chef initially has odd number of charachters. Chef wants to create a palindrome of maximum even length using these characters. For this Chef needs to discard one character. Help Chef find the character which needs to be discarded so that he can use the rest characters in any order to form a pali...
0
{"tests": "{\"inputs\": [\"1\\n4\\n\", \"4\\n5 2 2 1\\n\", \"8\\n4 5 2 2 1 3 5 5\\n\", \"172\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
You are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i. Let's say, that two squares i and j belong to the same connected component if c_i = c_j, and c_i = c_k for all k satisfying i < k < j. In other words, all squares on the segment fro...
0
{"tests": "{\"inputs\": [\"3\\n10 3\\n1 32 1\\n23 4\\n16 1 4 1\\n20 5\\n2 1 16 1 8\\n\", \"3\\n8 3\\n1 32 1\\n23 4\\n16 1 4 1\\n20 5\\n2 1 16 1 8\\n\", \"3\\n14 3\\n1 32 1\\n23 4\\n16 1 4 1\\n20 5\\n2 1 16 2 8\\n\", \"3\\n14 3\\n1 32 1\\n14 4\\n16 1 4 1\\n26 5\\n2 1 16 2 8\\n\", \"3\\n8 3\\n1 32 1\\n23 4\\n16 1 4 1\\n6...
You have a bag of size n. Also you have m boxes. The size of i-th box is a_i, where each a_i is an integer non-negative power of two. You can divide boxes into two parts of equal size. Your goal is to fill the bag completely. For example, if n = 10 and a = [1, 1, 32] then you have to divide the box of size 32 into tw...
0
{"tests": "{\"inputs\": [\"2\\n4 6\\n1 2\\n1 3\\n2 3\\n2 4\\n3 4\\n3 4\\n7 6\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 7\\n\", \"2\\n4 6\\n1 2\\n1 3\\n2 3\\n2 4\\n1 4\\n3 4\\n7 6\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 7\\n\", \"2\\n4 6\\n1 2\\n1 3\\n2 3\\n3 4\\n1 4\\n3 4\\n7 6\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 7\\n\", \"2\\n4 6\\n1...
Arthur owns a ski resort on a mountain. There are n landing spots on the mountain numbered from 1 to n from the top to the foot of the mountain. The spots are connected with one-directional ski tracks. All tracks go towards the foot of the mountain, so there are no directed cycles formed by the tracks. There are at mos...
0
{"tests": "{\"inputs\": [\"4 3\\n*..\\n.*.\\n..*\\n...\\n\", \"5 5\\n..*..\\n.....\\n**...\\n**...\\n**...\\n\", \"4 4\\n.*..\\n*...\\n...*\\n..*.\\n\", \"3 4\\n..**\\n*...\\n....\\n\", \"3 4\\n..**\\n*...\\n....\\n\", \"4 3\\n..*\\n.*.\\n..*\\n...\\n\", \"4 4\\n.*..\\n..*.\\n...*\\n..*.\\n\", \"3 4\\n..*)\\n*...\\n......
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
0
{"tests": "{\"inputs\": [\"3\\nadd two numbers\\n3\\n1 add\\n2 two two\\n3 numbers numbers numbers\\n\", \"3\\nadd two decimals\\n5\\n4 please two decimals add\\n5 decimals want to be added\\n4 two add decimals add\\n4 add one two three\\n7 one plus two plus three equals six\\n\", \"4\\nthese papers are formulas\\n3\\n...
A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem — a severe torcoder coordinator Ivan does not accept any Lesha's probl...
0
{"tests": "{\"inputs\": [\"4\\n0 0\\n0 2\\n2 2\\n2 0\\n\", \"4\\n0 1\\n0 -1\\n-2 0\\n4 0\\n\", \"3\\n0 0\\n1 1\\n2 2\\n\", \"3\\n7912 -2027\\n1545 -3358\\n9223 -3223\\n\", \"5\\n-5 -5\\n0 0\\n-1 -1\\n2 2\\n3 3\\n\", \"3\\n0 0\\n1 1\\n2 0\\n\", \"30\\n2080 -7802\\n-9162 281\\n7597 1070\\n3037 -4229\\n2055 -1004\\n-1178 ...
Luyi has n circles on the plane. The i-th circle is centered at (xi, yi). At the time zero circles start to grow simultaneously. In other words, the radius of each circle at time t (t > 0) is equal to t. The circles are drawn as black discs on an infinite white plane. So at each moment the plane consists of several bla...
0
{"tests": "{\"inputs\": [\"4\\n1 3 2 5\\n\", \"1\\n4\\n\", \"4\\n1 5 2 3\\n\", \"2\\n5 4\\n\", \"32\\n9 71 28 214 98 204 27 156 27 201 247 103 191 108 54 166 28 182 116 42 225 192 76 205 41 134 248 78 191 223 108 140\\n\", \"24\\n29 65 79 75 21 61 87 83 65 61 37 44 49 86 48 37 28 21 67 43 30 20 81 55\\n\", \"88\\n114 1...
The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson. Nam created a sequence a consisting of n (1 ≤ n ≤ 105) elements a1, a2, ..., an (1 ≤ ai ≤ 105). A subsequence ai1,...
0
{"tests": "{\"inputs\": [\"5\\n3 100\\n0 0\\n3 4\\n60 70\\n100 100\\n10 10\\n5 12\\n\", \"1\\n1 500\\n5 5\\n1 2\\n\", \"3\\n2 17\\n0 0\\n1 0\\n35 27\\n0 5\\n\", \"12\\n10 186\\n-267 -417\\n-410 930\\n-354 852\\n-132 -613\\n-342 356\\n212 220\\n319 475\\n-674 124\\n-900 -647\\n986 326\\n-412 -744\\n909 628\\n871 -153\\n...
The commanding officers decided to drop a nuclear bomb on the enemy's forces. You are ordered to determine the power of the warhead that needs to be used. The enemy has N strategically important objects. Their positions are known due to the intelligence service. The aim of the strike is to deactivate at least K import...
0
{"tests": "{\"inputs\": [\"4 4\\n(())\\n\", \"4 1\\n(\\n\", \"4 3\\n(((\\n\", \"2 2\\n)(\\n\", \"2 2\\n))\\n\", \"1542 282\\n())())()((()(()))()((())()))((())(()))))(()()))(())((()))()((()())())()))((())(((()(())((()()())((((())))((()((((()(()()))))(()(()()(())()((())())())))))()()())))(()((((()))(()(()(()(()))())((()(...
As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings! The sequence of round brackets is called valid if and only if: 1...
0
{"tests": "{\"inputs\": [\"4 4 3\\n1 2 2\\n2 4 1\\n1 3 1\\n3 4 2\\n\", \"5 11 23\\n1 2 3\\n2 3 4\\n3 4 5\\n4 5 6\\n1 3 4\\n2 4 5\\n3 5 6\\n1 4 2\\n2 5 3\\n1 5 2\\n3 2 30\\n\", \"10 16 63\\n1 2 1\\n2 10 1\\n1 3 1\\n3 10 1\\n1 4 1\\n4 10 1\\n1 5 1\\n5 10 1\\n1 6 1\\n6 10 1\\n1 7 1\\n7 10 1\\n1 8 1\\n8 10 1\\n1 9 1\\n9 10...
Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city. In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in can be represented as a directed graph with n nodes and m edges. Each edge ...
0
{"tests": "{\"inputs\": [\"4 1 2\\n1 3\\n1 2\\n\", \"3 3 1\\n2\\n1 2\\n1 3\\n2 3\\n\", \"6 4 2\\n1 4\\n1 2\\n2 3\\n4 5\\n5 6\\n\", \"5 2 2\\n1 2\\n1 3\\n2 4\\n\", \"10 10 3\\n2 5 6\\n1 3\\n4 1\\n4 3\\n5 3\\n3 9\\n8 4\\n9 4\\n5 10\\n8 7\\n10 8\\n\", \"1 0 1\\n1\\n\", \"20 4 5\\n1 3 9 10 20\\n5 6\\n1 2\\n7 9\\n4 10\\n\",...
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world. There is at most one...
0
{"tests": "{\"inputs\": [\"1\\n5\\n\", \"2\\n1\\n2\\n\", \"2\\n34\\n44\\n\", \"3\\n34\\n44\\n21\\n\", \"6\\n34\\n44\\n21\\n55\\n1\\n36\\n\", \"124\\n34\\n44\\n21\\n55\\n1\\n36\\n53\\n31\\n58\\n59\\n11\\n40\\n20\\n32\\n43\\n48\\n16\\n5\\n35\\n20\\n21\\n36\\n15\\n2\\n11\\n56\\n58\\n2\\n40\\n47\\n29\\n21\\n4\\n21\\n1\\n25...
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: * The game starts with n piles of stones indexed from 1 to n. The i-th pile contains si stones. * The players make their moves alternatively. A move ...
0
{"tests": "{\"inputs\": [\"15 2\\n4\\nUURL\\n8\\nLRLLLLLLLL\\n\", \"1 1\\n1\\nU\\n\", \"7 10\\n3\\nLLULULLLR\\n4\\nLUUURLLLUURRU\\n1\\nULURR\\n6\\nLURLLLLRLR\\n2\\nULULURU\\n7\\nRRUUUURLRLR\\n7\\nUUURRULRRLUL\\n7\\nULLLRUULULR\\n6\\nUURRLL\\n6\\nRULUUULLRLLLUULL\\n\", \"1 1\\n1\\nL\\n\", \"4503599627370495 1\\n22517998...
T is a complete binary tree consisting of n vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree have the same depth (distance from the root). So n is a number such that n ...
0
{"tests": "{\"inputs\": [\"5\\n10 21 10 21 10\\n\", \"3\\n141 592 653\\n\", \"3\\n25987 64237 88891\\n\", \"5\\n25539 29221 6895 82089 18673\\n\", \"47\\n53046 58090 55185 8100 43578 1253 7226 13049 75567 73065 19920 48836 28243 45633 75475 74628 11853 68351 90922 89500 81315 71161 34816 49875 82337 2727 27746 37878 79...
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be ...
0
{"tests": "{\"inputs\": [\"2\\n5 3\\n3 5\\n\", \"2\\n3 5\\n5 3\\n\", \"50\\n7 1\\n4 8\\n9 3\\n9 3\\n2 4\\n5 9\\n1 5\\n1 4\\n7 6\\n4 8\\n3 6\\n2 8\\n5 1\\n8 9\\n7 4\\n7 2\\n2 4\\n7 9\\n8 7\\n3 8\\n1 7\\n4 5\\n7 2\\n6 4\\n6 1\\n4 8\\n5 6\\n4 3\\n6 5\\n6 4\\n6 9\\n2 5\\n9 3\\n3 4\\n3 4\\n9 3\\n7 9\\n5 8\\n1 6\\n5 1\\n8 3\...
You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator. Today you are late, so there are queues on some floors already. For each person you know the floor where he currently is and the floor he wants to reach. Also, you...
0
{"tests": "{\"inputs\": [\"5\\naacbb\\n2\\na c\\na b\\n\\nSAMPLE\", \"5\\naacbb\\n2\\nb c\\na b\\n\\nSAMPLE\", \"5\\naacbb\\n2\\na b\\na b\\n\\nSAMPLE\", \"5\\naacbb\\n2\\nb c\\na c\\n\\nSEMPLA\", \"5\\naacbb\\n2\\na a\\na b\\n\\nELOLAS\", \"5\\naacbc\\n2\\na c\\na b\\n\\nSAMPLE\", \"5\\naacbb\\n2\\nc c\\na b\\n\\nSEMP...
Given a string S of length N consisting of only lower-case English alphabets, you will be asked to process Q queries over it . In each query you will be given two lower case characters X and Y. Your task is to find out the number of such substrings of the the string S which have the characters X and Y on either of its...
0.125
{"tests": "{\"inputs\": [\"1\\n1\\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2\\n\\nSAMPLE\", \"1\\n1\\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 0 1 2 3 1 2\\n\\nSAMPLE\", \"1\\n1\\n1 2 3 1 2 3 1 2 3 1 2 4 2 2 3 1 2 1 0 2 0 1 5 3 1 2\\n\\nELPMAS\", \"1\\n1\\n1 2 3 1 2 3 1 2 3 1 4 4 2 3 3 1 2 1 0 0 -1 1 5 3 1 2\\...
Abhimanyu simply drew two triangles, as shown in the picture below: He says this, Amazing painting 1. Then he drew two more triangles, as shown in the picture below: He says this, Amazing painting 2. Similarly he defined Amazing painting 3, 4, 5, ..., N. Now he starts finding the points where two lines meet or int...
0
{"tests": "{\"inputs\": [\"100\", \"311114770564041497\", \"3\", \"80182456107003087\", \"5\", \"158461871566595116\", \"10\", \"186455597317386972\", \"20\", \"181678330976250080\", \"39\", \"93932089064978059\", \"70\", \"71578367286808432\", \"93\", \"3327794342327297\", \"139\", \"6269486129073601\", \"22\", \"1139...
Given is an integer S. Find a combination of six integers X_1,Y_1,X_2,Y_2,X_3, and Y_3 that satisfies all of the following conditions: * 0 \leq X_1,Y_1,X_2,Y_2,X_3,Y_3 \leq 10^9 * The area of the triangle in a two-dimensional plane whose vertices are (X_1,Y_1),(X_2,Y_2), and (X_3,Y_3) is S/2. We can prove that ther...
0
{"tests": "{\"inputs\": [\"6\\n7\\n5 2\\n1 4\\n3 5\\n4 2\\n1 6\\n6 4\\n3 4\", \"6\\n7\\n5 2\\n1 4\\n3 5\\n8 2\\n1 6\\n6 4\\n3 4\", \"6\\n7\\n7 2\\n1 4\\n3 5\\n8 2\\n1 6\\n6 4\\n2 4\", \"6\\n7\\n3 2\\n1 4\\n6 5\\n3 2\\n1 6\\n6 4\\n3 4\", \"6\\n7\\n5 2\\n1 4\\n3 5\\n8 2\\n2 6\\n6 4\\n3 4\", \"6\\n7\\n3 2\\n1 4\\n3 1\\n4 ...
A serious incident happened at Taro's house, which loves steamed buns. One of the three steamed buns offered at the Buddhist altar in the Japanese-style room was gone. When Taro, who was aiming for a snack someday, started an investigation to find the criminal, it turned out that there were many people who entered the ...
0
{"tests": "{\"inputs\": [\"4 2\\n0 2\\n1 2\", \"10 3\\n2 1\\n4 1\\n9 2\", \"5 3\\n0 1\\n2 1\\n3 1\", \"1 2\\n0 2\\n1 2\", \"4 3\\n2 1\\n4 1\\n9 2\", \"3 3\\n0 1\\n2 1\\n3 1\", \"4 2\\n0 2\\n1 4\", \"10 3\\n2 1\\n4 1\\n9 1\", \"5 3\\n0 1\\n2 1\\n5 1\", \"10 3\\n0 1\\n4 1\\n9 2\", \"8 3\\n4 1\\n8 1\\n11 3\", \"10 3\\n0 1...
Background The site of Mr. A's house, which lives in a certain city, is surrounded by white walls. Feeling unsatisfied with the wall, Mr. A decided to invite the children in the neighborhood to paint the wall freely. Ask the children to choose their favorite section of the wall and paint it. So how was the wall painte...
0
{"tests": "{\"inputs\": [\"19\", \"5\", \"2\", \"68\", \"2286\", \"7\", \"1\", \"4\", \"27\", \"8\", \"3\", \"49\", \"6\", \"82\", \"75\", \"123\", \"188\", \"13\", \"12\", \"14\", \"24\", \"9\", \"10\", \"15\", \"11\", \"48\", \"18\", \"50\", \"45\", \"31\", \"194\", \"310\", \"30\", \"17\", \"16\", \"28\", \"70\", \"...
When Mr. Kay was browsing a certain SNS as usual, the problem that "there are people who can solve IQ150 or more" came to the timeline. Mr. Kay has an IQ of over 150, so he solved the problem in an instant without even looking at it. For him, he doesn't have to work on such a mystery. It is enough to leave it to the co...
0.375
{"tests": "{\"inputs\": [\"5\\n8 6 9 1 20\", \"5\\n8 6 9 1 0\", \"5\\n0 6 9 1 0\", \"5\\n1 1 1 1 0\", \"5\\n0 1 1 2 4\", \"5\\n0 6 6 1 0\", \"5\\n0 5 6 1 0\", \"5\\n0 5 6 2 0\", \"5\\n0 5 6 3 0\", \"5\\n0 4 6 3 0\", \"5\\n-1 4 6 3 0\", \"5\\n-1 4 9 3 0\", \"5\\n-1 4 0 3 0\", \"5\\n-1 4 -1 3 0\", \"5\\n0 4 -1 3 0\", \"5...
Auction square1001 You were watching a certain auction. An auction is a transaction in which when there are a large number of buyers and the number of items is limited, the one with the highest price is given the right to buy. (From the 7th edition of the Shinmei Kokugo Dictionary) The rules of the auction here are ...
0.125
{"tests": "{\"inputs\": [\"7 3\\n1 7 7 4 8 1 6\", \"7 3\\n1 7 7 4 6 1 6\", \"7 3\\n1 7 3 4 6 1 6\", \"7 3\\n1 7 0 4 6 1 6\", \"7 3\\n0 7 7 4 8 1 6\", \"7 3\\n1 7 7 4 6 1 0\", \"7 3\\n0 7 7 4 8 2 6\", \"7 3\\n1 7 7 5 6 1 0\", \"7 2\\n1 7 0 4 5 1 6\", \"7 3\\n1 7 7 3 6 1 0\", \"7 3\\n1 2 3 3 6 1 8\", \"7 3\\n0 7 7 8 12 2...
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $L$, find the minimum of each possible sub-arrays with size $L$ and print them from the beginning. For example, for an array $\\{1, 7, 7, 4, 8, 1, 6\\}$ and $L = 3$, the possible sub-arrays with size $L = 3$ includes $\\{1, 7, 7\\}$, $\\{7, 7, ...
0
{"tests": "{\"inputs\": [\"2\\n276\\n762\", \"2\\n473\\n762\", \"2\\n473\\n370\", \"2\\n336\\n432\", \"2\\n438\\n861\", \"2\\n286\\n861\", \"2\\n64\\n10\", \"2\\n15\\n10\", \"2\\n7\\n18\", \"2\\n276\\n1324\", \"2\\n924\\n762\", \"2\\n143\\n370\", \"2\\n473\\n589\", \"2\\n48\\n675\", \"2\\n48\\n665\", \"2\\n64\\n6\", \"...
The Head Chef has received his id from the Association of Byteland . He wants to know the numerical rank of his number among the numbers that can be formed by the exact same digits ( i.e. among numbers having same number of 0's , 1's ... 9's as his id ) . Note that id's can start with 0 . Given a number, find the rank...
0.5
{"tests": "{\"inputs\": [\"4\\n1 1 1 1\\n\", \"5\\n3 2 5 4 10\\n\", \"5\\n1 2 1 3 6\\n\", \"8\\n10 4 7 6 14 4 2 2\\n\", \"2\\n1000000000 1\\n\", \"2\\n6 16\\n\", \"19\\n3 1 16 11 12 10 3 13 12 9 1 9 8 4 19 16 19 3 3\\n\", \"19\\n10 10 8 11 6 1 6 13 8 20 8 14 9 18 18 7 5 20 6\\n\", \"2\\n921 921\\n\", \"11\\n3 10 20 13 ...
You went to the store, selling n types of chocolates. There are a_i chocolates of type i in stock. You have unlimited amount of cash (so you are not restricted by any prices) and want to buy as many chocolates as possible. However if you buy x_i chocolates of type i (clearly, 0 ≤ x_i ≤ a_i), then for all 1 ≤ j < i at ...
0
{"tests": "{\"inputs\": [\"2\\n3\\n3 2 1\\n4\\n1 3 4 2\\n\", \"2\\n3\\n3 2 1\\n4\\n1 3 7 2\\n\", \"2\\n3\\n3 4 1\\n4\\n1 3 7 2\\n\", \"2\\n3\\n3 4 1\\n4\\n1 5 8 2\\n\", \"2\\n3\\n3 2 1\\n4\\n1 5 8 2\\n\", \"2\\n3\\n6 2 1\\n4\\n1 5 8 2\\n\", \"2\\n3\\n3 4 1\\n4\\n1 5 14 2\\n\", \"2\\n3\\n3 4 1\\n4\\n1 5 6 2\\n\", \"2\\n...
Given a permutation p of length n, find its subsequence s_1, s_2, …, s_k of length at least 2 such that: * |s_1-s_2|+|s_2-s_3|+…+|s_{k-1}-s_k| is as big as possible over all subsequences of p with length at least 2. * Among all such subsequences, choose the one whose length, k, is as small as possible. If mul...
0
{"tests": "{\"inputs\": [\"5\\n3\\naab\\nbcc\\n4\\ncabc\\nabcb\\n3\\nabc\\ntsr\\n4\\naabd\\ncccd\\n5\\nabcbd\\nbcdda\\n\", \"10\\n1\\na\\nb\\n1\\nb\\na\\n3\\nabc\\ndef\\n1\\nt\\nt\\n2\\nrt\\ntr\\n2\\nrt\\ntt\\n2\\nrt\\nrr\\n3\\nasd\\nqrt\\n1\\ns\\nt\\n1\\nr\\nt\\n\", \"4\\n2\\nee\\nfe\\n3\\nlml\\nmji\\n3\\nqoq\\nqpp\\n...
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter y Koa selects must be strictly greater alphabetically than x (read statement for better understanding). You can make hacks in these problems independently. Koa the Koala has two...
0
{"tests": "{\"inputs\": [\"4\\n4\\n1 -2 3 -4\\n3\\n0 0 0\\n5\\n1 -1 1 -1 1\\n6\\n40 -31 -9 0 13 -40\\n\", \"1\\n5\\n1 1 2 -4 -6\\n\", \"1\\n50\\n-27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -27 27 -6 27 -27 27 -27 27 -27 -4 -27 -47 -27 27\...
You are given an array of n integers a_1,a_2,...,a_n. You have to create an array of n integers b_1,b_2,...,b_n such that: * The array b is a rearrangement of the array a, that is, it contains the same values and each value appears the same number of times in the two arrays. In other words, the multisets \\{a_1,a_...
0
{"tests": "{\"inputs\": [\"3\\n11\\nantontrygub\\n15\\nbestcoordinator\\n19\\ntrywatchinggurabruh\\n\", \"1\\n200\\ntbyrguruybtgtybugryrtbugbrgyutruygbtyrgtubrtgybubguytrbtyrugtyugrbuygrtbtrguybybrutgtbgurybygrtugytubrtuyrbgytbugrtrgyburtbygubygtrurbugyttuygbrutbgyrubgrtytugybrytbgurugrbtygtybrurbygutrtgbyubuyrtgrb\\n\...
A string b is a subsequence of a string a if b can be obtained from a by deletion of several (possibly, zero or all) characters. For example, "xy" is a subsequence of "xzyw" and "xy", but not "yx". You are given a string a. Your task is to reorder the characters of a so that "trygub" is not a subsequence of the result...
0
{"tests": "{\"inputs\": [\"4\\n11 3\\n01000000001\\n10 2\\n0110100101\\n5 2\\n10101\\n3 100\\n000\\n\", \"2\\n3 1\\n111\\n2 2\\n00\\n\", \"1\\n5 42069\\n11011\\n\", \"1\\n11 1000000000\\n11111111101\\n\", \"1\\n11 1\\n10000100001\\n\", \"1\\n3 1000000000\\n101\\n\", \"1\\n4 1000000000\\n1010\\n\", \"1\\n5 1000000000\\n...
<image> William really likes the cellular automaton called "Game of Life" so he decided to make his own version. For simplicity, William decided to define his cellular automaton on an array containing n cells, with each cell either being alive or dead. Evolution of the array in William's cellular automaton occurs ite...
0.875
{"tests": "{\"inputs\": [\"5 3\\n0 2 4\\n1 3 1\\n0 8 3\\n0 20 10\\n1 5 5\\n\", \"3 5\\n0 2 3\\n1 9 10\\n0 4 4\\n\", \"3 3\\n0 1 100\\n0 2 1\\n1 100 100\\n\", \"2 1\\n0 1 1\\n1 2 1\\n\", \"3 10\\n0 9 1\\n0 10 10\\n1 20 1\\n\", \"3 2\\n0 1 1\\n0 2 2\\n1 4 2\\n\", \"2 1\\n0 1 1\\n0 2 1\\n\", \"3 3\\n0 2 1\\n0 3 2\\n1 5 10...
The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. <image> One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters a...
0
{"tests": "{\"inputs\": [\"6\\n2 2 1 3 4 1\\n\", \"3\\n2 2 9\\n\", \"7\\n99 100 1 2 3 4 5\\n\", \"2\\n1 1\\n\", \"10\\n1 2 3 4 1 2 3 4 5 6\\n\", \"1\\n5\\n\", \"5\\n3 3 1 2 3\\n\", \"1\\n1\\n\", \"100\\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1...
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is it...
0.875
{"tests": "{\"inputs\": [\"2 1\\n1 2\\n\", \"4 3\\n1 2\\n1 3\\n1 4\\n\", \"4 3\\n1 3\\n2 4\\n3 4\\n\", \"6 4\\n3 2\\n1 3\\n6 5\\n4 6\\n\", \"4 3\\n1 3\\n1 4\\n3 4\\n\", \"3 1\\n1 2\\n\", \"5 9\\n4 3\\n4 2\\n3 1\\n5 1\\n4 1\\n2 1\\n5 2\\n3 2\\n5 4\\n\", \"4 2\\n2 3\\n1 4\\n\", \"4 4\\n1 2\\n4 1\\n3 4\\n3 1\\n\", \"20 55...
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties: * G has exactly n vertices, numbered from 1 to...
0
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5\\n\", \"3\\n1 3 2\\n\", \"5\\n2 2 3 4 5\\n\", \"3\\n229 232 444\\n\", \"8\\n1 5 6 8 3 1 7 3\\n\", \"5\\n1 2 10 3 4\\n\", \"20\\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\\n\", \"3\\n3 2 1\\n\", \"3\\n3 4 13\\n\", \"1\\n10\\n\", \"18\\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\\n\",...
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element be...
0.875
{"tests": "{\"inputs\": [\"8 9\\n1 2\\n2 3\\n3 1\\n4 5\\n5 6\\n6 7\\n7 8\\n8 4\\n7 2\\n3\\n1 8\\n1 4\\n3 8\\n\", \"6 6\\n1 2\\n2 3\\n3 1\\n4 5\\n5 6\\n6 4\\n3\\n1 3\\n4 6\\n1 6\\n\", \"12 12\\n5 1\\n5 11\\n1 11\\n8 11\\n8 9\\n5 12\\n6 9\\n7 11\\n9 3\\n9 10\\n4 12\\n10 2\\n78\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n...
You are given an undirected graph with n vertices. There are no edge-simple cycles with the even length in it. In other words, there are no cycles of even length that pass each edge at most once. Let's enumerate vertices from 1 to n. You have to answer q queries. Each query is described by a segment of vertices [l; r...
0.125
{"tests": "{\"inputs\": [\"5 4 5\\n1 2\\n2 3\\n3 4\\n4 1\\n\", \"9 9 1\\n1 2\\n1 3\\n2 3\\n1 5\\n5 6\\n6 1\\n1 8\\n9 8\\n7 1\\n\", \"2333 1 1\\n1 2\\n\", \"1 0 1\\n\", \"30 30 28\\n16 28\\n5 30\\n7 17\\n6 1\\n12 28\\n15 28\\n14 30\\n25 11\\n25 10\\n25 8\\n12 30\\n27 5\\n30 10\\n22 14\\n30 13\\n20 27\\n15 25\\n24 20\\n2...
There are n cities and m roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities reachable from the capital? New roads will also be one-way. Input The first line of input consists of three integers ...
0
{"tests": "{\"inputs\": [\"0 0 1 2\", \"-2 -2 1 1\", \"-1 0 1 2\", \"-2 -2 1 2\", \"-1 0 1 4\", \"-1 0 1 0\", \"-2 -2 0 4\", \"-2 0 1 0\", \"-4 -2 0 4\", \"0 0 1 0\", \"-4 -4 0 4\", \"-4 0 0 4\", \"-4 0 0 0\", \"0 0 0 2\", \"-2 -1 1 1\", \"-1 -1 1 2\", \"-2 -3 1 2\", \"-2 -2 -1 2\", \"-2 -2 0 5\", \"-4 -1 0 4\", \"0 0 ...
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x- and y-coordinates before and after each movement must ...
0
{"tests": "{\"inputs\": [\"4\\n0 2\\n0 0\\n-1 0\\n1 0\", \"4\\n0 1\\n1 0\\n0 0\\n1 1\", \"9\\n-1 1\\n0 1\\n1 1\\n-1 0\\n0 0\\n1 0\\n-1 -1\\n0 -1\\n1 -1\", \"4\\n0 1\\n1 -1\\n0 0\\n1 1\", \"3\\n-1 -1\\n0 0\\n1 1\", \"4\\n0 2\\n0 0\\n-2 0\\n1 0\", \"4\\n0 1\\n1 -1\\n0 -1\\n1 1\", \"3\\n-2 -1\\n0 0\\n1 1\", \"4\\n0 1\\n1 ...
Open Binary and Object Group organizes a programming contest every year. Mr. Hex belongs to this group and joins the judge team of the contest. This year, he created a geometric problem with its solution for the contest. The problem required a set of points forming a line-symmetric polygon for the input. Preparing the ...
0
{"tests": "{\"inputs\": [\"5 5\\n-38 -71 -293 75 1\\n-158 -38 -405 66 1\\n-236 -303 157 266 1\\n316 26 411 190 1\\n207 -312 -27 196 1\\n-50 292 -375 -401 389 -389\\n460 278 409 -329 -303 411\\n215 -220 -200 309 -474 300\\n261 -494 -87 -300 123 -463\\n386 378 486 -443 -64 299\", \"5 1\\n0 10 0 5 2\\n0 20 0 5 12\\n0 30 0...
In 20XX AD, a school competition was held. The tournament has finally left only the final competition. You are one of the athletes in the competition. The competition you participate in is to compete for the time it takes to destroy all the blue objects placed in the space. Athletes are allowed to bring in competition...
0.125
{"tests": "{\"inputs\": [\"3\\n1 2 0 0\\n1 2 0 0\", \"3\\n1 2 0 0\\n1 2 1 0\", \"3\\n1 2 0 0\\n1 2 1 -1\", \"3\\n1 2 0 0\\n2 2 1 0\", \"3\\n1 2 0 0\\n2 2 2 0\", \"3\\n1 2 0 0\\n2 2 0 0\", \"3\\n1 1 0 0\\n2 2 0 0\", \"3\\n1 2 1 0\\n2 2 0 0\", \"3\\n1 2 1 0\\n3 2 0 0\", \"3\\n2 2 1 0\\n3 2 0 0\", \"3\\n2 2 1 0\\n3 2 0 1\...
Problem statement You and AOR Ika are preparing for a graph problem in competitive programming. Generating input cases is AOR Ika-chan's job. The input case for that problem is a directed graph of the $ N $ vertices. The vertices are numbered from $ 1 $ to $ N $. Edges may contain self-loops, but not multiple edges. ...
0.625
{"tests": "{\"inputs\": [\"9\\n0 blue 4\\n0 red 1\\n0 white 5\\n1 red\\n1 blue\\n2 red\\n1 black\\n1 red\\n3 w z\", \"9\\n0 blue 4\\n0 red 1\\n0 white 5\\n1 rdd\\n1 blue\\n2 red\\n1 black\\n1 red\\n3 w z\", \"9\\n0 blue 4\\n0 red 1\\n0 white 5\\n1 rdd\\n1 blte\\n2 red\\n1 black\\n1 red\\n3 w z\", \"9\\n0 blue 4\\n0 red...
For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that each key in $M$ must be unique. * insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$. * get($key$): Print the value with the specified $...
0
{"tests": "{\"inputs\": [\"1\\n1010110010 10110\", \"1\\n1010110110 10110\", \"1\\n1010100110 10110\", \"1\\n0010100110 10110\", \"1\\n0010100110 00110\", \"1\\n0000100110 10110\", \"1\\n0000100110 10100\", \"1\\n0001100110 10100\", \"1\\n0001100100 10100\", \"1\\n0001100100 00100\", \"1\\n0101100100 00100\", \"1\\n101...
Given two binary strings, A (of length 10) and B (of length 5), output 1 if B is a substring of A and 0 otherwise. Input The first line contains the number of test cases n. This is followed by n lines each consisting of pairs of binary strings A and B separated by a single space. Output output 1 if B is a sub...
0.75
{"tests": "{\"inputs\": [\"4\\n2\\n4\\n8\\n10\", \"4\\n2\\n6\\n8\\n10\", \"4\\n2\\n4\\n2\\n10\", \"4\\n1\\n6\\n10\\n10\", \"4\\n2\\n4\\n0\\n8\", \"4\\n1\\n6\\n10\\n6\", \"4\\n2\\n4\\n2\\n7\", \"4\\n1\\n11\\n23\\n11\", \"4\\n4\\n11\\n9\\n16\", \"4\\n1\\n16\\n1\\n10\", \"4\\n4\\n11\\n18\\n16\", \"4\\n0\\n21\\n9\\n17\", \...
Given an array of n non-negative integers: A1, A2, …, AN. Your mission is finding a pair of integers Au, Av (1 ≤ u < v ≤ N) such that (Au and Av) is as large as possible. And is a bit-wise operation which is corresponding to & in C++ and Java.   Input The first line of the input contains a single integer N. The ith ...
0.5
{"tests": "{\"inputs\": [\"1 10 1 10 2\\n\", \"5 6 8 10 1\\n\", \"1 1000000000 1 1000000000 49\\n\", \"4 7 4 7 2\\n\", \"47 95 18 147 4\\n\", \"1 1000 1 1000 14\\n\", \"8548 8554575 895 9954448 47\\n\", \"1 1000000000 488 744444444 748\\n\", \"7 7 4 4 2\\n\", \"1 6 2 4 1\\n\", \"1 10000 1 10000 6\\n\", \"4 7 1 10000000...
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya and his friend Vasya play an interesting game. Petya randomly chooses an integer p from the in...
0.25
{"tests": "{\"inputs\": [\"3\\n3\\n6 10 15\\n2\\n4 9\\n23\\n437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961\\n\", \"1\\n1\\n4\\n\", \"1\\n4\\n529 529 529 961\\n\", \"3\\n3\\n6 10 15\\n2\\n4 9\\n23\\n171 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 6...
A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97. Alice is given a sequence of n composite numbers a_1,a_2,…,a_n. She wants to choos...
0.25
{"tests": "{\"inputs\": [\"2\\n5\\n1 2 3 4 5\\n7\\n3 2 4 5 1 6 7\\n\", \"1\\n2\\n1 2\\n\", \"1\\n5\\n1 3 4 2 5\\n\", \"4\\n6\\n1 5 3 4 2 6\\n6\\n5 1 3 4 2 6\\n6\\n1 5 3 4 6 2\\n6\\n5 1 3 4 6 2\\n\", \"3\\n3\\n1 2 3\\n4\\n3 1 2 4\\n7\\n6 4 1 7 3 5 2\\n\", \"1\\n7\\n3 2 4 1 7 6 5\\n\", \"1\\n4\\n2 1 3 4\\n\", \"1\\n6\\n2...
Patrick likes to play baseball, but sometimes he will spend so many hours hitting home runs that his mind starts to get foggy! Patrick is sure that his scores across n sessions follow the identity permutation (ie. in the first game he scores 1 point, in the second game he scores 2 points and so on). However, when he ch...
0
{"tests": "{\"inputs\": [\"7 2\\n1 2 1 1 3 5 1\\n3 5\\n\", \"5 0\\n4 3 1 2 3\\n\", \"3 3\\n1 3 2\\n1 2 3\\n\", \"10 3\\n1 3 5 6 12 9 8 10 13 15\\n2 4 9\\n\", \"4 2\\n1 1 2 2\\n2 4\\n\", \"50 35\\n69 2 3 15 16 18 18 20 21 22 33 31 38 47 50 42 50 13 1 58 58 59 60 67 61 52 61 61 64 65 33 28 66 4 8 96 32 68 69 74 83 84 85 ...
You are given an array of n integers a_1, a_2, ..., a_n, and a set b of k distinct integers from 1 to n. In one operation, you may choose two integers i and x (1 ≤ i ≤ n, x can be any integer) and assign a_i := x. This operation can be done only if i does not belong to the set b. Calculate the minimum number of opera...
0
{"tests": "{\"inputs\": [\"7 2 4\\n\", \"3 7 6\\n\", \"6243 60593 42244\\n\", \"7487 17563 1102\\n\", \"1 2 2\\n\", \"43003 70913 71178\\n\", \"46084 75979 30535\\n\", \"60489 34395 34632\\n\", \"100000 10 10\\n\", \"38133 49787 9840\\n\", \"76730 91851 71438\\n\", \"28598 12497 10464\\n\", \"72657 93778 50943\\n\", \"...
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n. Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible. If there are multiple "nearest" fractions, choose...
0
{"tests": "{\"inputs\": [\"5\\n\", \"74\\n\", \"625\\n\", \"177\\n\", \"787\\n\", \"2\\n\", \"305\\n\", \"194\\n\", \"659\\n\", \"334\\n\", \"400\\n\", \"721\\n\", \"1000\\n\", \"75\\n\", \"362\\n\", \"395\\n\", \"817\\n\", \"979\\n\", \"9999\\n\", \"593\\n\", \"755\\n\", \"586\\n\", \"851\\n\", \"497\\n\", \"906\\n\",...
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the sq...
0
{"tests": "{\"inputs\": [\"9\\n-2 0 -1 0 -1 2 1 0 -1\\n\", \"2\\n2 1\\n\", \"50\\n-6 1 -3 7 -5 -5 4 0 3 -5 1 2 -1 0 7 0 6 3 -5 4 4 3 -7 -1 4 4 -5 3 7 1 4 2 6 -4 0 3 -3 -2 -3 1 -5 3 -4 2 -2 7 -1 3 -7 4\\n\", \"1\\n0\\n\", \"24\\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2\\n\", \"5\\n1 0 1 -2 1\\n\", \"8\\...
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday. Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality ai > aj holds. Jeff c...
0
{"tests": "{\"inputs\": [\"abc\\n3\\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\\n\", \"pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpv...
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where <image> Now DZY has a string s. He wants to insert k lowercase ...
0.5
{"tests": "{\"inputs\": [\"3\\n555\\n\", \"4\\n1234\\n\", \"2\\n95\\n\", \"1\\n2\\n\", \"12\\n836544897832\\n\", \"6\\n576825\\n\", \"15\\n000000000000007\\n\", \"14\\n11122233344455\\n\", \"10\\n3312667105\\n\", \"7\\n4424368\\n\", \"15\\n999999999999990\\n\", \"2\\n66\\n\", \"13\\n1337251172966\\n\", \"1\\n8\\n\", \"...
Drazil is playing a math game with Varda. Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>. First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then th...
0