name
stringlengths
2
112
description
stringlengths
29
13k
private_tests
dict
public_tests
dict
generated_tests
dict
p00298 Mighty Man
There was a powerful school where powerful people gathered. At the athletic meet of the powerful school, powerful people march in a formation. While the powerhouses always want to show off their power, most of them don't want to walk on their own. So I thought that some of them would be at the bottom, and a lot of peo...
{ "input": [], "output": [] }
{ "input": [ "3\n150 120\n100 50\n80 100" ], "output": [ "1" ] }
{ "input": [ "3\n156 120\n100 50\n80 100", "3\n52 5\n100 85\n37 000", "3\n19 5\n000 49\n43 010", "3\n156 120\n100 50\n80 000", "3\n156 159\n100 50\n80 000", "3\n156 11\n100 50\n80 000", "3\n156 22\n100 50\n80 000", "3\n156 22\n100 50\n152 000", "3\n156 6\n100 50\n152 000", "3\n...
p00468 Party
problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks f...
{ "input": [], "output": [] }
{ "input": [ "6\n5\n1 2\n1 3\n3 4\n2 3\n4 5\n6\n5\n2 3\n3 4\n4 5\n5 6\n2 5\n0\n0" ], "output": [ "3\n0" ] }
{ "input": [ "6\n5\n1 2\n1 3\n3 4\n2 3\n4 5\n6\n5\n2 3\n3 4\n4 5\n5 6\n2 6\n0\n0", "6\n5\n1 2\n1 3\n3 4\n2 3\n4 5\n6\n5\n2 3\n3 4\n1 5\n5 6\n2 6\n0\n0", "6\n5\n1 2\n1 3\n3 5\n2 3\n4 5\n6\n5\n2 3\n3 4\n1 5\n6 6\n2 6\n0\n0", "6\n5\n1 2\n1 3\n3 5\n2 3\n4 5\n6\n5\n2 3\n3 4\n1 5\n1 6\n2 6\n0\n0", "6\n5...
p00660 High and Low Cube
I came to the summer festival with the elementary school students in my neighborhood. To put it bluntly, it plays the role of a guardian, but the smell of yakisoba and takoyaki in the store, and the sound of fireworks that can be heard from time to time, are still exciting even at this age. But today I have to keep an ...
{ "input": [], "output": [] }
{ "input": [ ".......#######......................#######..............\n.......#.....#......................#..-..#..............\n.......#.|...#......................#.|.|.#..............\n.......#.....#......................#..-..#..............\n.......#.|...#......................#.|...#..............\n........
{ "input": [ ".......#######......................#######..............\n.......#.....#......................#..-..#..............\n.......#.|...#......................#.|.|.#..............\n.......#.....#......................#..-..#..............\n.......#.|...#......................#.|...#..............\n........
p00803 Starship Hakodate-maru
The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls. There, however, is an inconvenience. The shapes of the fuel containers #1 and #2 are always cubic and regular tetrahedral respectively. Both of the fuel containers should b...
{ "input": [], "output": [] }
{ "input": [ "100\n64\n50\n20\n151200\n0" ], "output": [ "99\n64\n47\n20\n151200" ] }
{ "input": [ "100\n84\n50\n20\n151200\n0", "100\n84\n50\n20\n150323\n0", "100\n160\n50\n20\n150323\n0", "100\n64\n50\n17\n151200\n0", "100\n50\n50\n20\n151200\n0", "100\n63\n50\n20\n150323\n0", "100\n5\n50\n17\n151200\n0", "100\n50\n74\n20\n151200\n0", "100\n69\n50\n20\n150323\n0",...
p00934 L Jumps
Example Input 3 2 4 0 2 2 -2 -2 -2 2 Output 15
{ "input": [], "output": [] }
{ "input": [ "3 2 4 0\n2 2\n-2 -2\n-2 2" ], "output": [ "15" ] }
{ "input": [ "3 2 4 0\n2 2\n-2 -2\n-2 0", "3 2 4 0\n2 2\n-2 -3\n-2 2", "3 2 4 -1\n2 2\n-2 -2\n-2 0", "3 2 2 0\n2 2\n-2 -3\n-2 2", "3 2 2 0\n2 2\n-2 -3\n-1 2", "3 2 2 0\n2 2\n-2 -2\n-1 2", "3 2 4 0\n1 2\n-3 -2\n-2 0", "3 2 4 0\n2 1\n-2 -2\n-2 2", "3 2 4 -1\n2 2\n-1 -2\n-2 0", "3...
p01067 Circles and Ray
Problem N circles are given on the two-dimensional plane, each of which has no intersection. In addition, each circle is assigned a number from 1 to N. You can place any number of half-lines such that the endpoints are on the circumference of the first circle. Find out how many half lines must be installed in order f...
{ "input": [], "output": [] }
{ "input": [ "5\n0 0 5\n0 10 1\n10 0 1\n-10 0 1\n0 -10 1", "4\n1 2 3\n12 2 2\n7 6 2\n1 9 3", "3\n0 0 2\n3 3 1\n6 1 1" ], "output": [ "4", "2", "1" ] }
{ "input": [ "5\n0 0 5\n0 10 1\n10 0 1\n-10 0 1\n0 -10 2", "3\n0 -1 2\n3 3 1\n6 1 1", "3\n0 -1 2\n3 3 1\n4 1 1", "4\n1 1 3\n12 2 2\n10 6 1\n1 9 3", "5\n0 0 7\n0 10 1\n10 0 1\n-10 0 1\n0 -10 1", "4\n1 1 3\n12 2 2\n7 6 2\n1 9 3", "5\n0 0 5\n0 17 1\n10 0 1\n-10 0 1\n0 -10 2", "3\n0 -1 2\n...
p01200 Resource
Dr. Keith Miller is a researcher who studies the history of Island of Constitutional People’s Country (ICPC). Many studies by him and his colleagues have revealed various facts about ICPC. Although it is a single large island today, it was divided in several smaller islands in some ancient period, and each island was r...
{ "input": [], "output": [] }
{ "input": [ "2 3\n10.00\n3 10 10 20 10 10 20\n4 30 10 40 10 40 20 30 20\n1.00 3 0 0 10 0 0 10\n0.50 4 20 15 25 15 25 20 20 20\n0.75 6 40 35 50 40 40 50 30 50 25 45 30 40\n4 1\n5.00\n3 0 0 24 0 0 24\n3 50 0 50 24 26 0\n3 0 50 0 26 24 50\n3 50 50 26 50 50 26\n1.00 4 25 0 50 25 25 50 0 25\n0 0" ], "output": [ ...
{ "input": [ "2 3\n10.00\n3 10 10 20 10 10 20\n4 30 10 40 10 40 20 30 20\n1.00 3 0 0 10 0 0 10\n0.50 4 20 15 25 15 25 20 20 20\n0.75 6 40 35 50 40 40 50 30 50 25 45 30 40\n4 1\n5.00\n3 0 0 24 0 0 24\n3 50 0 50 24 26 0\n3 0 50 0 26 24 28\n3 50 50 26 50 50 26\n1.00 4 25 0 50 25 25 50 0 25\n0 0", "2 3\n10.00\n3 ...
p01337 The Number of the Real Roots of a Cubic Equation
Description Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively. The number of roots shall be counted including the multiple roots. Input The input consists of multiple test cases, and the number is rec...
{ "input": [], "output": [] }
{ "input": [ "2\n1 3 3 1\n-10 0 0 0" ], "output": [ "0 3\n0 0" ] }
{ "input": [ "2\n1 3 3 1\n-10 0 0 1", "2\n1 4 3 1\n-14 0 0 1", "2\n1 3 5 1\n-10 0 0 0", "2\n1 3 9 1\n-10 0 1 0", "2\n1 4 3 0\n-1 0 1 1", "2\n1 1 3 1\n-10 -1 0 0", "2\n1 4 3 0\n-1 -1 1 1", "2\n1 4 3 0\n-1 0 0 0", "2\n1 4 3 0\n-1 0 1 0", "2\n2 4 3 0\n-1 0 1 0", "2\n1 0 0 1\n-...
p01504 AYBABTU
There is a tree that has n nodes and n-1 edges. There are military bases on t out of the n nodes. We want to disconnect the bases as much as possible by destroying k edges. The tree will be split into k+1 regions when we destroy k edges. Given the purpose to disconnect the bases, we only consider to split in a way that...
{ "input": [], "output": [] }
{ "input": [ "2 2 1\n1 2 1\n1\n2\n4 3 2\n1 2 1\n1 3 2\n1 4 3\n2\n3\n4\n0 0 0" ], "output": [ "Case 1: 1\nCase 2: 3" ] }
{ "input": [ "2 2 0\n1 2 1\n1\n2\n4 3 2\n1 2 1\n1 3 2\n1 4 3\n2\n3\n4\n0 0 0", "2 2 1\n1 2 1\n1\n2\n4 3 2\n1 2 1\n1 3 2\n1 4 2\n2\n3\n4\n0 0 0", "2 2 1\n1 2 1\n1\n2\n4 3 2\n1 2 1\n1 3 4\n1 4 3\n2\n3\n4\n0 0 0", "2 2 0\n1 2 1\n1\n2\n4 3 2\n1 2 1\n2 3 2\n2 4 3\n2\n3\n4\n0 0 0", "2 2 0\n1 2 1\n1\n2\n...
p01675 The J-th Number
I - The J-th Number Problem Statement You are given N empty arrays, t_1, ..., t_n. At first, you execute M queries as follows. * add a value v to array t_i (a \leq i \leq b) Next, you process Q following output queries. * output the j-th number of the sequence sorted all values in t_i (x \leq i \leq y) Input ...
{ "input": [], "output": [] }
{ "input": [ "5 4 1\n1 5 1\n1 1 3\n4 5 1\n3 4 2\n1 3 4" ], "output": [ "2" ] }
{ "input": [ "5 4 1\n1 5 1\n1 1 3\n4 5 1\n3 4 2\n1 3 2", "8 4 1\n1 7 1\n1 1 3\n4 5 2\n3 4 2\n1 1 2", "5 4 1\n1 5 1\n1 1 3\n7 5 1\n3 4 2\n1 3 4", "5 4 2\n1 5 1\n0 1 3\n4 5 1\n3 4 2\n1 3 2", "5 4 1\n1 5 1\n2 1 3\n4 8 -1\n3 4 4\n1 3 4", "8 4 1\n1 7 1\n1 1 5\n4 5 2\n3 4 2\n1 1 2", "8 4 1\n2 -1...
p01819 Where is the Boundary
Example Input 2 1 WE Output 1 2
{ "input": [], "output": [] }
{ "input": [ "2 1\nWE" ], "output": [ "1 2" ] }
{ "input": [ "3 1\nWE", "3 0\nWE", "1 1\nWE", "1 0\nWE", "2 0\nWE", "4 0\nWE", "3 0\nEW", "1 0\nEW", "2 1\nEW", "4 0\nEW", "5 0\nEW", "1 0\nEX", "4 0\nFW", "3 0\nFW", "2 0\nFW", "2 0\nWF", "1 1\nWD", "1 0\nVE", "2 0\nEW", "7 0\nEW", "...
p01952 Tiny Room
You are an employee of Automatic Cleaning Machine (ACM) and a member of the development team of Intelligent Circular Perfect Cleaner (ICPC). ICPC is a robot that cleans up the dust of the place which it passed through. Your task is an inspection of ICPC. This inspection is performed by checking whether the center of I...
{ "input": [], "output": [] }
{ "input": [ "4 20 20 1\n10 0\n20 10\n10 20\n0 10", "1 3 3 1\n114 514", "2 5 55 1\n0 0\n30 40", "2 5 49 1\n0 0\n30 40" ], "output": [ "Yes", "Yes", "Yes", "No" ] }
{ "input": [], "output": [] }
p02101 Let's Go To School
Problem Gaccho loses motivation as the final exam approaches and often misses school. There are N days left until the final exam. Gaccho's motivation on day i is Xi, and the motivation needed to go to school on day i is Yi. Gaccho goes to school only on days when Xi ≥ Yi. Haji, who was worried about Gaccho, decided to...
{ "input": [], "output": [] }
{ "input": [ "5 5\n1 1\n1 2\n1 2\n1 3\n1 3", "3 10\n1 6\n5 10\n0 5" ], "output": [ "4", "2" ] }
{ "input": [ "6 5\n1 1\n1 2\n1 2\n1 3\n1 3", "3 10\n1 9\n5 10\n0 5", "3 7\n1 9\n5 10\n0 5", "6 5\n0 1\n1 2\n1 2\n2 3\n1 3", "3 18\n1 6\n5 5\n0 5", "0 8\n1 2\n5 20\n0 5", "6 6\n0 0\n1 2\n2 0\n0 3\n2 2", "6 5\n1 1\n1 2\n1 2\n2 3\n1 3", "3 7\n1 9\n5 10\n0 2", "6 9\n0 1\n1 2\n1 2\n...
p02239 Breadth First Search
Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$. Constraints * $1 \leq n \leq 100$ Input In the first line, an integer $n$ denoting the number of vertic...
{ "input": [], "output": [] }
{ "input": [ "4\n1 2 2 4\n2 1 4\n3 0\n4 1 3" ], "output": [ "1 0\n2 1\n3 2\n4 1" ] }
{ "input": [ "4\n1 2 1 4\n2 1 4\n3 0\n4 1 3", "4\n1 2 1 4\n2 1 4\n3 0\n4 1 4", "4\n1 2 2 4\n2 1 4\n3 0\n4 1 1", "4\n1 2 2 4\n2 1 1\n3 0\n4 1 3", "4\n1 2 1 1\n2 1 4\n3 0\n4 1 4", "4\n1 2 2 1\n2 1 1\n3 0\n4 1 3", "4\n1 2 1 4\n3 1 4\n3 0\n4 1 2", "4\n1 2 3 4\n4 1 4\n3 -1\n3 1 0", "4\n...
p02385 Dice III
Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical. Co...
{ "input": [], "output": [] }
{ "input": [ "1 2 3 4 5 6\n6 5 4 3 2 1", "1 2 3 4 5 6\n6 2 4 3 5 1" ], "output": [ "No", "Yes" ] }
{ "input": [ "1 2 3 2 5 6\n6 5 4 3 2 1", "1 2 3 2 5 6\n6 1 4 3 2 1", "1 2 3 2 5 6\n6 0 4 3 2 1", "1 2 3 2 5 6\n6 0 4 3 4 1", "1 2 3 2 7 6\n6 0 4 3 4 1", "1 2 3 2 7 3\n6 0 4 3 4 1", "1 2 2 2 7 6\n6 0 4 3 4 1", "1 2 2 2 7 9\n6 0 4 3 4 1", "1 2 2 2 7 9\n6 0 4 5 4 1", "1 0 2 2 7 9\...
aba14a
Ramkumar loves to solve riddles one day SpojSathyagave him a riddle to solve. Sathya will give him pair of integers a and b. Ramkumar has to find the largest number in the range [a,b] inclusive which can be represented as product of atleast two prime numbers. But ramkumar is busy in watching "Arrow" he is asking your ...
{ "input": [], "output": [] }
{ "input": [ "2\n5 11\n7 35" ], "output": [ "10 \n35" ] }
{ "input": [], "output": [] }
chefbro
Chef's younger brother is in town. He's a big football fan and has a very important match to watch tonight. But the Chef wants to watch the season finale of MasterChef which will be aired at the same time. Now they don't want to fight over it like they used to when they were little kids. They want to decide it in a fai...
{ "input": [], "output": [] }
{ "input": [ "1\n1\n2 2" ], "output": [ "MasterChef" ] }
{ "input": [], "output": [] }
digrot
For any positive integer, we define a digit rotation as either moving the first digit to the end of the number (left digit rotation), or the last digit to the front of the number (right digit rotation). For example, the number 12345 could be left digit rotated to 23451, or right digit rotated to 51234. If there are any...
{ "input": [], "output": [] }
{ "input": [ "6\n12345\n54321\n10901\n211011\n7\n90" ], "output": [ "51234\n54321\n11090\n211011\n7\n9\n" ] }
{ "input": [ "6\n12345\n43634\n10901\n211011\n7\n90", "6\n12345\n43634\n21427\n211011\n7\n90", "6\n12345\n43634\n21427\n211011\n7\n166", "6\n23325\n43634\n21427\n211011\n7\n166", "6\n23325\n43634\n21427\n211011\n1\n166", "6\n1466\n43634\n21427\n211011\n1\n166", "6\n1466\n20536\n21427\n2110...
insoma5
The planet of XANDOR was famous in the intergalactic empire for being home to the Carden - a race of super-intelligent computer scientists that were held in high regard for their achievements in the Intergalactic Mind Game Olympiads. The Carden decided to build a huge computer to answer questions related to Life, the U...
{ "input": [], "output": [] }
{ "input": [ "T.F+T*F" ], "output": [ "5" ] }
{ "input": [], "output": [] }
nf03
Given a string of letters in the input, return a string in the output with each words written in reverse order. Spaces and punctuations must not change their position. Numbers may be present in a string. The end of the string will have a "." without the quotes. Input Input string Output Output String Example Inp...
{ "input": [], "output": [] }
{ "input": [ "Welcome to NITMASFEST." ], "output": [ "emocleW ot TSEFSAMTIN. \n" ] }
{ "input": [ "Welcome tp NITMASFEST.", "Welcome tp MITMASFEST.", "Welcome tp MITLASFEST.", "Welcome sp MITLASFEST.", "Welbome sp MITLASFEST.", "Welbome sp MJTLASFEST.", "Welbome sp MJTLASFERT.", "Welbome ps MJTLASFERT.", "Welbome os MJTLASFERT.", "Welcome ot NITMASFEST.", "...
sanskar
Alok-nath is man of equality. He needs your help to divide his “sanskars” evenly amongst all his followers. By doing this, Alok-nath can create equality amongst his followers and he'll be called a true “sanskari”. Alok-nath has N sanskars, and K followers. Each sanskar is given a numerical value which shows its intensi...
{ "input": [], "output": [] }
{ "input": [ "2\n5 3\n1 2 4 5 6\n5 3\n1 2 4 5 7" ], "output": [ "yes\nno" ] }
{ "input": [ "2\n5 3\n1 2 4 4 6\n5 3\n1 2 4 5 7", "2\n1 3\n0 2 6 4 6\n5 3\n1 2 0 1 2", "2\n5 3\n1 2 5 4 6\n5 3\n1 2 4 5 8", "2\n5 3\n1 2 4 4 6\n5 3\n1 2 0 5 7", "2\n5 3\n1 2 4 4 6\n5 3\n0 2 0 5 7", "2\n1 3\n1 2 4 4 6\n5 3\n0 2 0 5 7", "2\n1 3\n1 2 4 4 6\n5 3\n1 2 0 5 7", "2\n1 3\n1 2 4...
1474_A. Puzzle From the Future
In the 2022 year, Mike found two binary integers a and b of length n (both of them are written only by digits 0 and 1) that can have leading zeroes. In order not to forget them, he wanted to construct integer d in the following way: * he creates an integer c as a result of bitwise summing of a and b without transfe...
{ "input": [], "output": [] }
{ "input": [ "5\n1\n0\n3\n011\n3\n110\n6\n111000\n6\n001011\n" ], "output": [ "\n1\n110\n100\n101101\n101110\n" ] }
{ "input": [ "5\n1\n0\n3\n011\n3\n110\n6\n111100\n6\n001011\n", "5\n1\n0\n3\n011\n3\n111\n6\n111100\n6\n001011\n", "5\n1\n0\n3\n011\n3\n110\n6\n011000\n6\n001011\n", "5\n1\n0\n3\n011\n3\n110\n6\n011100\n6\n001011\n", "5\n1\n0\n3\n111\n3\n110\n6\n011000\n6\n001011\n", "5\n1\n0\n3\n011\n3\n110\n...
64_B. Expression
You are given a line «n#m», where «n» and «m» are digits, and «#» is a sign «+» or «-». Print the value of the given expression. Input The only given line has a string in form «n#m», where «n» and «m» are digits (from 0 to 9), and «#» is a sign «+» or «-». Output Print the value of the given expression. Examples ...
{ "input": [], "output": [] }
{ "input": [ "1-5\n" ], "output": [ "-4\n" ] }
{ "input": [], "output": [] }
benny-and-subsets
This problem is about a little pig named Benny. Benny was given an array of N integers and another separate integer X. Benny has to find the number of subsets (not necessarily contiguous) of A such that Bitwise XOR of all elements contained within the subset evaluates to X. Probably, you have already guessed that she ...
{ "input": [], "output": [] }
{ "input": [ "6 3\n1 2 3 0 100500 100500\n\nSAMPLE" ], "output": [ "8" ] }
{ "input": [], "output": [] }
rachels-exhibition-visit
Rachel works at a big Raf Laurens. There is a big event coming up and she has to select dresses for an exhibition. She has N dresses numbered 1 to N. There are total 62 types of dresses, each represented by a different alphanumeric character (a-z, A-Z, 0-9). The N dresses are represented by a string S of length N of al...
{ "input": [], "output": [] }
{ "input": [ "2\n5 3 3 4\nAbcAb\nAbZ\n9 2 1 2\nadebfgbhd\nab\n\nSAMPLE" ], "output": [ "3\n33" ] }
{ "input": [], "output": [] }
shil-and-wave-seqeuncemonk
Given a sequence A1 , A2 , A3 .. AN of length N . Find total number of wave subsequences having length greater than 1. Wave subsequence of sequence A1 , A2 , A3 .. AN is defined as a set of integers i1 , i2 .. ik such that Ai1 < Ai2 > Ai3 < Ai4 .... or Ai1 > Ai2 < Ai3 > Ai4 .... and i1 < i2 < ...< ik.Two subseq...
{ "input": [], "output": [] }
{ "input": [ "5\n1 3 5 4 2\n\nSAMPLE" ], "output": [ "17" ] }
{ "input": [], "output": [] }
p02538 ACL Beginner Contest - Replace Digits
You have a string S of length N. Initially, all characters in S are `1`s. You will perform queries Q times. In the i-th query, you are given two integers L_i, R_i and a character D_i (which is a digit). Then, you must replace all characters from the L_i-th to the R_i-th (inclusive) with D_i. After each query, read th...
{ "input": [], "output": [] }
{ "input": [ "8 5\n3 6 2\n1 4 7\n3 8 3\n2 2 2\n4 5 1", "200000 1\n123 456 7" ], "output": [ "11222211\n77772211\n77333333\n72333333\n72311333", "641437905" ] }
{ "input": [ "149688 1\n123 456 7", "8 5\n3 6 2\n1 4 7\n3 8 4\n2 2 2\n4 5 1", "200000 1\n123 348 7", "70116 1\n123 456 7", "8 5\n3 6 2\n1 4 7\n3 8 4\n2 2 1\n4 5 1", "70116 1\n134 456 7", "8 5\n5 6 2\n1 4 7\n3 8 3\n2 2 2\n4 5 1", "149688 1\n123 456 6", "70116 1\n123 456 8", "8 5...
p02669 AtCoder Grand Contest 044 - Pay to Win
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the num...
{ "input": [], "output": [] }
{ "input": [ "5\n11 1 2 4 8\n11 1 2 2 8\n32 10 8 5 4\n29384293847243 454353412 332423423 934923490 1\n900000000000000000 332423423 454353412 934923490 987654321" ], "output": [ "20\n19\n26\n3821859835\n23441258666" ] }
{ "input": [ "5\n11 1 4 4 8\n11 1 2 2 8\n32 10 8 5 4\n29384293847243 454353412 332423423 934923490 1\n900000000000000000 332423423 454353412 934923490 987654321", "5\n11 1 4 4 8\n15 1 2 2 8\n32 10 8 5 4\n29384293847243 454353412 332423423 1011333844 1\n900000000000000000 332423423 454353412 934923490 98765432...
p02798 Keyence Programming Contest 2020 - Swap and Flip
We have N cards numbered 1, 2, ..., N. Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N, with the red numbers facing up. Determine whether it is ...
{ "input": [], "output": [] }
{ "input": [ "5\n28 15 22 43 31\n20 22 43 33 32", "4\n1 2 3 4\n5 6 7 8", "3\n3 4 3\n3 2 3", "5\n4 46 6 38 43\n33 15 18 27 37", "2\n2 1\n1 2" ], "output": [ "-1", "0", "1", "3", "-1" ] }
{ "input": [ "5\n28 15 22 43 30\n20 22 43 33 32", "4\n1 2 3 4\n5 6 8 8", "3\n3 4 3\n3 0 3", "5\n4 46 6 31 43\n33 15 18 27 37", "4\n1 2 3 2\n5 6 7 8", "4\n2 1 3 3\n5 0 4 16", "4\n1 2 5 0\n18 7 16 0", "2\n2 0\n1 2", "4\n1 2 3 4\n5 0 8 8", "3\n3 4 3\n3 0 5", "5\n4 26 6 31 43\n...
p02934 AtCoder Beginner Contest 138 - Resistors in Parallel
Given is a sequence of N integers A_1, \ldots, A_N. Find the (multiplicative) inverse of the sum of the inverses of these numbers, \frac{1}{\frac{1}{A_1} + \ldots + \frac{1}{A_N}}. Constraints * 1 \leq N \leq 100 * 1 \leq A_i \leq 1000 Input Input is given from Standard Input in the following format: N A_1 A_2 \...
{ "input": [], "output": [] }
{ "input": [ "2\n10 30", "1\n1000", "3\n200 200 200" ], "output": [ "7.5", "1000", "66.66666666666667" ] }
{ "input": [ "2\n14 30", "1\n1001", "3\n283 200 200", "2\n14 38", "1\n1100", "3\n99 200 200", "2\n17 38", "1\n1110", "3\n77 200 200", "2\n17 24", "1\n0110", "3\n77 251 200", "2\n10 24", "1\n0100", "3\n77 314 200", "2\n10 15", "3\n77 143 200", "2\...
p03071 AtCoder Beginner Contest 124 - Buttons
There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get? Constraints * All values i...
{ "input": [], "output": [] }
{ "input": [ "3 4", "5 3", "6 6" ], "output": [ "7", "9", "12" ] }
{ "input": [ "6 4", "10 3", "4 3", "12 3", "9 2", "2 3", "15 3", "2 1", "18 3", "14 2", "2 2", "1 1", "1 0", "5 5", "5 2", "8 2", "0 -1", "-1 11", "0 0", "-1 -1", "-1 -2", "-1 16", "-2 -22", "-3 -22", "-4 -16", "-2...
p03213 AtCoder Beginner Contest 114 - 756
You are given an integer N. Among the divisors of N! (= 1 \times 2 \times ... \times N), how many Shichi-Go numbers (literally "Seven-Five numbers") are there? Here, a Shichi-Go number is a positive integer that has exactly 75 divisors. Constraints * 1 \leq N \leq 100 * N is an integer. Input Input is given from S...
{ "input": [], "output": [] }
{ "input": [ "9", "100", "10" ], "output": [ "0", "543", "1" ] }
{ "input": [ "11", "4", "17", "20", "36", "25", "14", "29", "30", "46", "42", "72", "59", "52", "67", "26", "78", "57", "44", "60", "88", "97", "84", "91", "74", "77", "93", "3", "16", "2", "6",...
p03362 AtCoder Beginner Contest 096 - Five Five Everywhere
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the following conditions: * a_i (1 \leq i \leq N) is a prime number at most 55 555. * The values of a_1, a_2, ..., a_N are all different. * In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite n...
{ "input": [], "output": [] }
{ "input": [ "6", "8", "5" ], "output": [ "2 3 5 7 11 13", "2 5 7 13 19 37 67 79", "3 5 7 11 31" ] }
{ "input": [ "10", "14", "12", "20", "27", "13", "50", "17", "1", "2", "3", "4", "7", "15", "16", "35", "24", "11", "32", "43", "26", "19", "9", "52", "21", "18", "28", "25", "36", "22", "40", ...
p03520 CODE FESTIVAL 2017 Elimination Tournament Round 1 (Parallel) - Ancient Tree Record
Snuke found a record of a tree with N vertices in ancient ruins. The findings are as follows: * The vertices of the tree were numbered 1,2,...,N, and the edges were numbered 1,2,...,N-1. * Edge i connected Vertex a_i and b_i. * The length of each edge was an integer between 1 and 10^{18} (inclusive). * The sum of the ...
{ "input": [], "output": [] }
{ "input": [ "4\n1 2\n2 3\n3 4\n8 6 6 8", "15\n9 10\n9 15\n15 4\n4 13\n13 2\n13 11\n2 14\n13 6\n11 1\n1 12\n12 3\n12 7\n2 5\n14 8\n1154 890 2240 883 2047 2076 1590 1104 1726 1791 1091 1226 841 1000 901", "5\n1 2\n1 3\n1 4\n1 5\n10 13 16 19 22" ], "output": [ "1\n2\n1", "5\n75\n2\n6\n7\n50\n10\...
{ "input": [ "15\n9 10\n9 15\n15 4\n4 13\n13 2\n13 11\n2 14\n13 6\n11 1\n1 12\n12 3\n12 7\n2 5\n14 8\n1154 890 2240 883 2930 2076 1590 1104 1726 1791 1091 1226 841 1000 901", "5\n1 2\n1 3\n1 4\n1 5\n5 13 16 19 22", "15\n9 10\n9 15\n15 4\n4 13\n13 2\n13 11\n2 14\n13 6\n11 1\n1 12\n12 3\n11 7\n2 5\n14 8\n11...
p03685 AtCoder Regular Contest 076 - Connected?
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}). The objective is to draw a curve connecting the pair of points where the same integer i...
{ "input": [], "output": [] }
{ "input": [ "4 2 3\n0 1 3 1\n1 1 4 1\n2 0 2 2", "5 5 7\n0 0 2 4\n2 3 4 5\n3 5 5 2\n5 5 5 4\n0 3 5 1\n2 2 4 4\n0 5 4 1", "2 2 4\n0 0 2 2\n2 0 0 1\n0 2 1 2\n1 1 2 1", "1 1 2\n0 0 1 1\n1 0 0 1" ], "output": [ "YES", "YES", "NO", "NO" ] }
{ "input": [ "4 3 3\n0 1 3 1\n1 1 4 1\n2 0 2 2", "2 2 4\n0 0 2 2\n2 0 0 1\n0 2 1 2\n1 1 2 0", "5 5 7\n0 0 2 4\n2 3 4 5\n3 5 5 2\n5 5 5 4\n0 3 5 1\n2 2 1 4\n0 5 4 1", "4 3 3\n0 1 3 1\n1 1 4 1\n0 0 2 2", "5 5 7\n0 0 2 4\n2 3 4 5\n3 5 5 2\n5 5 5 4\n0 4 5 1\n2 2 1 4\n0 5 4 1", "2 2 4\n0 0 2 2\n2 0...
p03838 AtCoder Grand Contest 008 - Simple Calculator
Snuke has a calculator. It has a display and two buttons. Initially, the display shows an integer x. Snuke wants to change this value into another integer y, by pressing the following two buttons some number of times in arbitrary order: * Button A: When pressed, the value on the display is incremented by 1. * Button ...
{ "input": [], "output": [] }
{ "input": [ "10 20", "-10 -20", "10 -10" ], "output": [ "10", "12", "1" ] }
{ "input": [ "15 20", "-10 -3", "19 -10", "-10 -2", "8 -10", "28 0", "28 2", "9 -14", "28 3", "1 -14", "53 3", "1 -20", "53 6", "0 -20", "53 0", "84 0", "137 0", "250 0", "110 0", "010 0", "10 34", "-10 -23", "15 40", "26 ...
p04005 AtCoder Grand Contest 004 - Divide a Cuboid
We have a rectangular parallelepiped of size A×B×C, built with blocks of size 1×1×1. Snuke will paint each of the A×B×C blocks either red or blue, so that: * There is at least one red block and at least one blue block. * The union of all red blocks forms a rectangular parallelepiped. * The union of all blue blocks for...
{ "input": [], "output": [] }
{ "input": [ "2 2 4", "3 3 3", "5 3 5" ], "output": [ "0", "9", "15" ] }
{ "input": [ "2 1 4", "1 3 3", "5 5 5", "3 1 1", "3 5 5", "3 3 5", "5 1 5", "19 9 5", "1 7 7", "3 1 4", "1 3 5", "6 1 4", "6 2 4", "0 2 4", "0 2 5", "3 3 0", "3 1 7", "6 1 0", "6 2 3", "1 2 4", "0 2 1", "3 1 0", "6 5 5", "...
p00091 Blur
There is a "cloth" of 10 × 10 squares as shown in Fig. 1, and the squares are indicated by a pair of X-coordinate and Y-coordinate values ​​as shown in (1 and 2). The coordinate value is an integer starting from 0. For example, the coordinates of ◎ in Figure 1 are (1, 2). Dye is made by adding dye to this "cloth" littl...
{ "input": [], "output": [] }
{ "input": [ "2\n0 0 0 0 0 0 0 0 0 0\n0 0 0 1 0 0 0 0 0 0\n0 0 1 1 1 0 0 0 0 0\n0 0 0 1 0 0 0 1 1 1\n0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0" ], "output": [ "3 2 1\n8 4 2" ] }
{ "input": [], "output": [] }
p00223 Stray Twins
Takayuki and Kazuyuki are good twins, but their behavior is exactly the opposite. For example, if Takayuki goes west, Kazuyuki goes east, and if Kazuyuki goes north, Takayuki goes south. Currently the two are in a department store and are in different locations. How can two people who move in the opposite direction mee...
{ "input": [], "output": [] }
{ "input": [ "6 6\n2 4\n6 2\n0 0 0 0 1 0\n0 1 0 0 0 0\n0 1 0 0 0 0\n0 0 0 1 0 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n3 3\n1 1\n3 3\n0 0 0\n0 1 0\n0 0 0\n0 0" ], "output": [ "3\nNA" ] }
{ "input": [ "6 6\n2 4\n6 2\n0 0 0 0 1 0\n0 1 1 0 0 0\n0 1 0 0 0 0\n0 0 0 1 0 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n3 3\n1 1\n3 3\n0 0 0\n0 1 0\n0 0 0\n0 0", "6 6\n2 4\n6 2\n0 0 0 0 1 0\n0 1 1 0 0 0\n0 1 0 0 0 0\n0 0 0 1 1 0\n0 0 0 0 0 1\n0 0 0 0 0 0\n3 3\n1 2\n3 3\n0 0 0\n0 1 0\n0 0 0\n0 0", "6 6\n2 3\n6 1\n0 0 0...
p00385 Disk
A mysterious device was discovered in an ancient ruin. The device consists of a disc with integers inscribed on both sides, a bundle of cards with an integer written on each of them and a pedestal within which the cards are placed. The disc rotates when the bundle of cards is put into the pedestal. Only one side of the...
{ "input": [], "output": [] }
{ "input": [ "5 3 1\n1 -2 0\n2 3", "5 7 5\n0 0 3 3 3 3 3\n1 2\n2 3\n3 4\n4 5\n5 6" ], "output": [ "-3", "1\n2\n3\n4\n5" ] }
{ "input": [ "5 3 1\n1 -4 0\n2 3", "5 3 1\n1 -4 1\n2 3", "15 3 1\n1 0 1\n2 3", "5 7 5\n0 0 3 3 3 3 3\n1 2\n2 3\n3 5\n4 5\n5 6", "2 3 1\n1 -4 0\n2 3", "10 3 1\n0 -4 1\n2 3", "5 7 5\n0 0 3 3 3 3 3\n1 2\n1 3\n3 5\n4 5\n5 6", "9 3 1\n1 -2 0\n2 3", "10 3 1\n1 -7 1\n2 3", "15 3 1\n2 ...
p00601 Dominating Set
What you have in your hands is a map of Aizu-Wakamatsu City. The lines on this map represent streets and the dots are street corners. Lion Dor Company is going to build food stores at some street corners where people can go to buy food. It is unnecessary and expensive to build a food store on every corner. Their plan i...
{ "input": [], "output": [] }
{ "input": [ "5 4\n0 1\n0 4\n1 2\n3 4\n5 4\n0 1\n0 4\n1 2\n3 4\n0 0" ], "output": [ "2\n2" ] }
{ "input": [ "5 4\n0 1\n0 4\n1 2\n1 4\n5 4\n0 1\n0 4\n1 2\n3 4\n0 0", "5 4\n0 1\n0 4\n1 2\n1 4\n5 4\n0 1\n0 4\n1 0\n3 4\n0 0", "5 4\n0 2\n0 4\n1 2\n1 4\n5 4\n0 1\n0 4\n1 0\n3 4\n0 0", "5 4\n0 1\n0 4\n1 2\n1 0\n5 4\n0 1\n0 4\n1 2\n3 4\n0 0", "8 4\n0 1\n0 4\n2 2\n1 0\n5 4\n0 1\n0 4\n1 2\n3 4\n0 0", ...
p00737 Twirling Robot
Let's play a game using a robot on a rectangular board covered with a square mesh (Figure D-1). The robot is initially set at the start square in the northwest corner facing the east direction. The goal of this game is to lead the robot to the goal square in the southeast corner. <image> Figure D-1: Example of a boar...
{ "input": [], "output": [] }
{ "input": [ "8 3\n0 0 0 0 0 0 0 1\n2 3 0 1 4 0 0 1\n3 3 0 0 0 0 0 4\n9 9 1 9\n4 4\n3 3 4 0\n1 2 4 4\n1 1 1 0\n0 2 4 4\n8 7 2 1\n2 8\n2 2\n4 1\n0 4\n1 3\n1 0\n2 1\n0 3\n1 4\n1 9 3 1\n0 0" ], "output": [ "1\n11\n6" ] }
{ "input": [ "8 3\n0 0 0 0 0 0 0 1\n2 3 0 1 4 0 0 1\n3 3 0 0 0 0 0 4\n9 9 1 9\n4 4\n3 3 4 0\n1 2 4 4\n1 1 1 0\n0 2 2 4\n8 7 2 1\n2 8\n2 2\n4 1\n0 4\n1 3\n1 0\n2 1\n0 3\n1 4\n1 9 3 1\n0 0", "8 3\n0 0 0 0 0 0 0 1\n2 3 0 1 4 0 0 1\n3 3 0 0 0 0 0 4\n9 9 1 9\n4 4\n3 3 4 0\n1 2 4 4\n1 1 1 0\n0 2 2 4\n8 7 2 1\n2 8\n...
p00877 Separate Points
Numbers of black and white points are placed on a plane. Let's imagine that a straight line of infinite length is drawn on the plane. When the line does not meet any of the points, the line divides these points into two groups. If the division by such a line results in one group consisting only of black points and the ...
{ "input": [], "output": [] }
{ "input": [ "3 3\n100 700\n200 200\n600 600\n500 100\n500 300\n800 500\n3 3\n100 300\n400 600\n400 100\n600 400\n500 900\n300 300\n3 4\n300 300\n500 300\n400 600\n100 100\n200 900\n500 900\n800 100\n1 2\n300 300\n100 100\n500 500\n1 1\n100 100\n200 100\n2 2\n0 0\n500 700\n1000 1400\n1500 2100\n2 2\n0 0\n1000 100...
{ "input": [ "3 3\n100 700\n200 200\n600 600\n500 100\n500 300\n800 500\n3 3\n100 300\n400 600\n400 100\n600 400\n500 900\n300 300\n3 4\n300 300\n935 300\n400 600\n100 100\n200 900\n500 900\n800 100\n1 2\n300 300\n100 100\n500 500\n1 1\n100 100\n200 100\n2 2\n0 0\n500 700\n1000 1400\n1500 2100\n2 2\n0 0\n1000 100...
p01008 Last One
Problem You decide to play a weird game with your friend A, who loves gathering. Given a set S of non-negative integers consisting of n elements that can be duplicated. Each element contained in the set S is a non-negative pi-ary number. With Steps 1 to 3 below as one turn for the set S, you and your opponent repeat ...
{ "input": [], "output": [] }
{ "input": [ "1\n10 1", "3\n25 53AI\n43 3BI0\n62 pn6", "2\n10 1\n10 1" ], "output": [ "win", "win", "lose" ] }
{ "input": [ "1\n18 1", "2\n5 1\n10 1", "3\n25 52AI\n43 3BI0\n62 pn6", "1\n28 1", "3\n25 52AI\n45 3BI0\n62 pn6", "1\n54 1", "3\n25 52AI\n45 3AI0\n62 pn6", "3\n25 52AI\n45 3AI0\n55 pn6", "3\n25 52AI\n45 3AI0\n55 pm6", "3\n25 52AI\n42 3AI0\n55 pm6", "3\n25 52@I\n42 3AI0\n55 p...
p01140 Square Route
Square Route Square root English text is not available in this practice contest. Millionaire Shinada, who has decided to build a new mansion, is wondering in which city to build the new mansion. To tell the truth, Mr. Shinada is a strange person who likes squares very much, so he wants to live in a city with as many...
{ "input": [], "output": [] }
{ "input": [ "3 3\n1\n1\n4\n2\n3\n1\n1 2\n10\n10\n10\n0 0" ], "output": [ "6\n2" ] }
{ "input": [ "3 3\n1\n1\n4\n2\n3\n1\n1 2\n10\n4\n10\n0 0", "3 3\n1\n1\n4\n0\n3\n1\n1 2\n10\n4\n10\n0 0", "3 3\n1\n1\n1\n2\n3\n1\n1 2\n10\n10\n10\n0 0", "3 3\n1\n0\n4\n2\n3\n1\n1 2\n10\n4\n10\n0 0", "3 3\n1\n1\n1\n1\n3\n1\n1 2\n10\n10\n10\n0 0", "3 3\n1\n0\n4\n2\n3\n2\n1 2\n10\n4\n10\n0 0", ...
p01279 Defend the Bases
A country Gizevom is being under a sneak and fierce attack by their foe. They have to deploy one or more troops to every base immediately in order to defend their country. Otherwise their foe would take all the bases and declare "All your base are belong to us." You are asked to write a program that calculates the min...
{ "input": [], "output": [] }
{ "input": [ "2 2\n10 20 1\n0 10 1\n0 10\n10 0\n0 0" ], "output": [ "14.14213562" ] }
{ "input": [ "2 2\n10 20 1\n0 10 1\n0 10\n18 0\n0 0", "2 2\n10 20 1\n0 10 1\n0 10\n1 0\n0 0", "2 2\n10 20 2\n0 10 1\n0 10\n1 0\n0 0", "2 2\n10 20 1\n0 10 1\n0 11\n8 0\n0 -1", "2 2\n10 20 2\n0 3 1\n1 11\n8 0\n0 -1", "2 2\n11 20 1\n0 10 1\n0 10\n1 0\n0 0", "2 2\n10 20 1\n-1 10 1\n0 11\n18 0\...
p01449 Space-Time Sugoroku Road
All space-time unified dimension sugoroku tournament. You are representing the Earth in the 21st century in the tournament, which decides only one Sugoroku absolute champion out of more than 500 trillion participants. The challenge you are currently challenging is one-dimensional sugoroku with yourself as a frame. Sta...
{ "input": [], "output": [] }
{ "input": [ "11\n0\n0\n-2\n0\n-4\n1\n-1\n2\n0\n0\n0", "12\n0\n0\n7\n0\n2\n0\n0\n3\n-6\n-2\n1\n0", "8\n0\n4\n-1\n1\n-2\n-2\n0\n0" ], "output": [ "3", "1", "2" ] }
{ "input": [ "11\n0\n1\n-2\n0\n-4\n1\n-1\n2\n0\n0\n0", "12\n0\n0\n7\n0\n2\n0\n0\n3\n-5\n-2\n1\n0", "8\n0\n4\n-1\n1\n0\n-2\n0\n0", "12\n0\n-1\n7\n0\n2\n0\n0\n3\n-5\n-2\n1\n0", "8\n0\n4\n-2\n1\n0\n-2\n0\n0", "12\n0\n-1\n7\n0\n2\n0\n-1\n3\n-5\n-2\n1\n0", "8\n0\n4\n-2\n1\n0\n0\n0\n0", "12\...
p01599 Train King
Problem I: Train King Roland has been given a mission of dangerous material transfer by Train King. The material is stored in the station A and subject to being transferred to the station B. He will bring it by direct trains between A and B, one (or zero) unit per ride. Your task is to write a program to find out the...
{ "input": [], "output": [] }
{ "input": [ "5 5\n10 0 100\n10 200 300\n10 400 500\n10 600 700\n10 800 900\n10 100 200\n10 300 400\n10 500 600\n10 700 800\n10 900 1000", "1 1\n10 100 0\n10 100 0" ], "output": [ "5", "10" ] }
{ "input": [ "5 5\n20 0 100\n10 200 300\n10 400 500\n10 600 700\n10 800 900\n10 100 200\n10 300 400\n10 500 600\n10 700 800\n10 900 1000", "1 1\n20 100 0\n10 100 0", "2 1\n20 100 0\n10 100 0", "5 5\n20 0 100\n10 200 300\n10 400 500\n10 600 700\n10 1051 900\n10 100 200\n10 300 400\n10 500 600\n10 700 8...
p01755 AI
A robot, a wall, and a goal are installed on the board, and a program that describes the behavior pattern of the robot is given. The given program is represented by the following EBNF. Program: = {statement}; Statement: = if statement | while statement | action statement; if statement: = "[", condition, program, "]"...
{ "input": [], "output": [] }
{ "input": [ "5 7\n\n.#g..#\n.###.#\ns....#\n\n{T{~C^}>}", "5 3\n###\n#g#\n#.#\n#s#\n###\n^<^<vv", "5 7\n\n.#g..#\n.###.#\ns....#\n\n{T{~C^}<}", "5 3\n\ng#\n.#\ns#\n\n^<^<vv" ], "output": [ "-1", "5", "17", "5" ] }
{ "input": [ "5 11\n\n.#g..#\n.###.#\ns....#\n\n{T{~C^}>}", "5 3\n#$#\n#g#\n#.#\n#s#\n###\n^<^<vv", "5 7\n\n.#g..#\n.###.#\ns....#\n\n}<}^C~{T{", "5 3\n\nh#\n.#\ns#\n\n^<^<vv", "5 3\n$$#\n#g#\n#.#\n#s#\n###\n^<^<vv", "5 7\n\n.#g..#\n.###.#\ns....#\n\n}~}^C<{T{", "5 3\n\ng#\n#.\ns#\n\n^<^<v...
p01895 Fuda
This issue is a reactive issue. It is necessary to create a program that derives the correct answer by interactively responding to the program prepared on the server side. Example Input Output
{ "input": [], "output": [] }
{ "input": [ "" ], "output": [ "" ] }
{ "input": [], "output": [] }
p02032 Divisor Game
C: Divisor Game problem tsutaj is trying to play about a few games. In a divisor game, a natural number N of 2 or more is given first, and then the game progresses according to the following procedure. * Declare one integer from the divisors of N other than N. However, at this time, it is not possible to declare a ...
{ "input": [], "output": [] }
{ "input": [ "18" ], "output": [ "2 5" ] }
{ "input": [ "2", "25", "30", "40", "14", "48", "52", "8", "60", "120", "72", "324", "100", "16", "64", "256", "32", "128", "330", "560", "1008", "180", "288", "216", "3690", "192", "504", "432", "5184"...
p02175 Strange Plants
problem A mysterious $ X $ [cm] plant grows in one place. This plant has the following mysterious properties. * Say "nobiro" to this plant and it will grow $ A $ [cm]. * Say "tidime" to this plant and it will grow $ B $ [cm]. * If you say "karero" to this plant, it will be $ 0 $ [cm]. However, this plant does not ...
{ "input": [], "output": [] }
{ "input": [ "10 30 10\n3\nnobiro\nnobiro\ntidime" ], "output": [ "80" ] }
{ "input": [ "10 30 10\n0\nnobiro\nnobiro\ntidime", "18 30 10\n0\nnobiro\nnobiro\ntidime", "15 30 9\n0\nnoairo\noribon\nmidite", "23 30 9\n0\nnoairo\noribon\nmidite", "44 30 5\n0\nnoairo\nnobiro\ntidime", "59 30 5\n0\noriaon\nnobiro\ntieimd", "83 48 5\n0\norioan\nnobiro\ndmifit", "31 4...
p02318 Edit Distance (Levenshtein Distance)
Find the edit distance between given two words s1 and s2. The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations: * insertion: Insert a character at a particular position. * deletion: Delete a character at a particular posi...
{ "input": [], "output": [] }
{ "input": [ "icpc\nicpc", "acac\nacm" ], "output": [ "0", "2" ] }
{ "input": [ "icpc\nipcc", "`cac\nacm", "icpb\ncbio", "cpci\nipcc", "`cad\nacm", "cpci\nccpi", "`cac\nbcm", "icpc\nccpi", "`cac\nmcb", "ibpc\nccpi", "`cab\nmcb", "icpb\nccpi", "`cab\nbcm", "icpb\nccip", "_cac\nmcb", "icpb\nccio", "_cca\nmcb", "_c...
p02463 Set Union
Find the union of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$. Constraints * $1 \leq n, m \leq 200,000$ * $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ * $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ Input The input is given in the following format. $n$ $a_0 \; a_1 \; ... \; a...
{ "input": [], "output": [] }
{ "input": [ "3\n1 5 8\n2\n5 9" ], "output": [ "1\n5\n8\n9" ] }
{ "input": [ "3\n1 5 8\n2\n5 8", "3\n1 5 15\n2\n5 8", "3\n1 5 15\n2\n5 9", "3\n1 6 15\n2\n5 9", "3\n1 3 8\n2\n5 8", "3\n1 5 15\n2\n5 11", "3\n1 6 15\n1\n5 9", "3\n1 5 15\n1\n5 11", "3\n2 6 15\n1\n5 9", "3\n1 5 15\n1\n4 11", "3\n2 6 15\n2\n5 9", "3\n2 9 15\n2\n5 9", ...
binop
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market. She purchases the string A and tries to convert it to string B by...
{ "input": [], "output": [] }
{ "input": [ "2\n101\n010\n1111\n1010" ], "output": [ "Lucky Chef\n2\nUnlucky Chef\n" ] }
{ "input": [ "2\n101\n011\n1111\n1010", "2\n001\n111\n1111\n1010", "2\n111\n110\n1111\n1010", "2\n110\n110\n1111\n1010", "2\n110\n110\n1011\n1010", "2\n010\n110\n0011\n1010", "2\n000\n110\n0011\n1010", "2\n001\n110\n0011\n1010", "2\n111\n010\n0011\n1110", "2\n110\n110\n0011\n10...
cnr
Chef has a special affection for sets of binary strings of equal length which have same numbers of 1's. Given three integers n, k and m, your task is to find the the lexicographically m^th smallest string among strings which have length n and have k 1's. If no such string exists output -1. Tips: To see what lexic...
{ "input": [], "output": [] }
{ "input": [ "1\n3 2 2" ], "output": [ "101\n" ] }
{ "input": [ "1\n3 2 3", "1\n3 3 3", "1\n6 3 3", "1\n6 4 3", "1\n6 4 6", "1\n3 1 3", "1\n9 3 3", "1\n6 5 3", "1\n8 4 6", "1\n12 3 3", "1\n8 2 6", "1\n3 1 2", "1\n12 3 0", "1\n8 2 8", "1\n8 3 8", "1\n12 4 1", "1\n8 1 8", "1\n12 7 1", "1\n8 1 2...
frjump
Chef likes to travel a lot. Every day Chef tries to visit as much cities as possible. Recently he had a quite a few trips of great Chefland for learning various recipes. Chefland had N cities numbered from 1 to N. People in Chefland are very friendly, friendliness of i-th city is given by Fi. Before starting of each t...
{ "input": [], "output": [] }
{ "input": [ "5\n1 2 3 4 5\n3\n2 1\n1 3 10\n2 2" ], "output": [ "1 120\n5 50" ] }
{ "input": [ "5\n1 2 3 4 5\n3\n2 1\n1 3 7\n2 2", "5\n1 1 3 4 5\n3\n2 1\n1 3 7\n2 2", "5\n1 2 3 4 3\n3\n2 1\n1 3 7\n2 2", "5\n1 2 4 4 5\n3\n2 1\n1 3 10\n2 2", "5\n1 2 3 4 3\n3\n2 1\n1 3 13\n2 2", "5\n1 2 3 4 5\n3\n2 1\n1 1 10\n2 2", "5\n1 2 3 4 5\n3\n2 1\n1 3 6\n2 2", "5\n2 1 3 4 5\n3\n...
lpair
Today is the reunion of all chefs in the world. Our Chef wants to make this moment more happier. He arranged a mass wedding in this reunion. For this, he made a strange stage and drew two horizontal parallel lines on the stage. There are N unmarried male chefs in the reunion and he gave each male chef i an unique numbe...
{ "input": [], "output": [] }
{ "input": [ "3\n2 3\n3 6\n5 4", "4\n5 12\n10 11\n11 9\n30 1" ], "output": [ "1", "6" ] }
{ "input": [ "3\n2 1\n3 6\n5 4", "4\n5 12\n10 11\n11 14\n30 1", "4\n5 0\n10 11\n11 14\n30 1", "4\n5 12\n10 11\n11 9\n36 1", "4\n5 0\n10 11\n11 7\n30 1", "4\n5 12\n10 13\n11 9\n30 1", "3\n1 4\n6 14\n0 0", "3\n2 1\n3 0\n5 4", "3\n2 3\n3 10\n5 4", "4\n5 12\n10 22\n11 14\n30 1", ...
primpatt
There is a very large field, colored white and divided into squares. There is a coordinate system attached to the field: y-axis goes from south to north and x-axis goes from west to east. Sides of the squares are parallel to the axes. There is a robot in the (0, 0) square. Robot starts to move in spiral as depicted. Fi...
{ "input": [], "output": [] }
{ "input": [ "8\n0 0\n1 0\n1 1\n0 1\n3 3\n-3 -3\n-1 2\n0 -3" ], "output": [ "1\n1\n0\n0\n1\n1\n2\n2" ] }
{ "input": [], "output": [] }
tashift
You are given two strings A and B of the same length. Each string contains N Lower case Latin character (from 'a' to 'z'). A shift operation will remove the first character of a string and add the same character at the end of that string. For example after you perform a shift operation on a string 'abcd', the new strin...
{ "input": [], "output": [] }
{ "input": [ "5\nccadd\nbddcc" ], "output": [ "3\n" ] }
{ "input": [ "5\nccade\nbddcc", "5\nccade\nccdcb", "5\nddacc\nbddcc", "5\nddacc\nccddb", "5\nccade\nbcdcc", "5\ncacde\nccdcb", "5\nc`cde\nccdcb", "5\ncbade\nccdcb", "5\ncacde\nccccb", "5\nc`cde\nccdca", "5\ncbace\nccdcb", "5\ncacde\nbcccb", "5\nc`cde\ncbdcb", "5...
1036_C. Classy Numbers
Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contain...
{ "input": [], "output": [] }
{ "input": [ "4\n1 1000\n1024 1024\n65536 65536\n999999 1000001\n" ], "output": [ " 1000\n 1\n 0\n ...
{ "input": [ "4\n1 1010\n1024 1024\n65536 65536\n999999 1000001\n", "4\n1 1010\n1024 1024\n65536 65536\n967877 1000001\n", "4\n1 1010\n217 1024\n65536 65536\n967877 1000001\n", "4\n1 1010\n217 1024\n65536 65536\n967877 1010001\n", "4\n1 1000\n1024 1024\n65536 128338\n999999 1000001\n", "4\n1 1...
1225_B2. TV Subscriptions (Hard Version)
The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequence of integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the show, the episode of which will be shown in i-th day. The...
{ "input": [], "output": [] }
{ "input": [ "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n" ], "output": [ "2\n1\n4\n5\n" ] }
{ "input": [ "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 12 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 4 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 4 2 6 5 6 5 8 9 8 9 3\n", "4\n5 2 2\n1 2 1 2 2\n9 3 3\n3 3 3 2 2 4 1 1 1\n4 18 4\n10 8 6 4\n16 10 ...
1353_D. Constructing the Array
You are given an array a of length n consisting of zeros. You perform n actions with this array: during the i-th action, the following sequence of operations appears: 1. Choose the maximum by length subarray (continuous subsegment) consisting only of zeros, among all such segments choose the leftmost one; 2. Let ...
{ "input": [], "output": [] }
{ "input": [ "6\n1\n2\n3\n4\n5\n6\n" ], "output": [ "1 \n1 2 \n2 1 3 \n3 1 2 4 \n2 4 1 3 5 \n3 4 1 5 2 6 \n" ] }
{ "input": [ "6\n1\n2\n3\n4\n4\n6\n", "6\n1\n3\n3\n4\n5\n6\n", "6\n1\n3\n3\n4\n4\n6\n", "6\n1\n2\n3\n4\n1\n6\n", "6\n1\n3\n2\n4\n4\n6\n", "6\n1\n2\n4\n4\n5\n6\n", "6\n1\n3\n3\n4\n10\n6\n", "6\n1\n1\n3\n4\n4\n6\n", "6\n1\n2\n3\n4\n1\n3\n", "6\n1\n3\n2\n8\n4\n6\n", "6\n1\n4\n...
331_B1. Shave Beaver!
The Smart Beaver has recently designed and built an innovative nanotechnologic all-purpose beaver mass shaving machine, "Beavershave 5000". Beavershave 5000 can shave beavers by families! How does it work? Very easily! There are n beavers, each of them has a unique id from 1 to n. Consider a permutation a1, a2, ..., a...
{ "input": [], "output": [] }
{ "input": [ "5\n1 3 4 2 5\n6\n1 1 5\n1 3 4\n2 2 3\n1 1 5\n2 1 5\n1 1 5\n" ], "output": [ "2\n1\n3\n5\n" ] }
{ "input": [ "5\n1 3 4 2 5\n6\n1 1 5\n1 3 4\n2 2 3\n1 1 5\n2 1 5\n1 2 5\n", "5\n1 3 4 2 5\n6\n1 1 5\n2 3 4\n2 2 3\n1 1 5\n2 1 5\n1 2 5\n", "5\n1 3 4 2 5\n6\n1 1 1\n2 3 4\n2 2 3\n1 1 5\n2 1 5\n1 2 5\n", "5\n1 3 4 2 5\n6\n1 1 5\n1 3 4\n2 2 3\n1 1 5\n2 1 2\n1 2 5\n", "5\n1 3 4 2 5\n6\n1 1 5\n1 3 4\n2...
661_E. Divisibility Check
You are given an array of integers. Check whether there exists a number in this array which is divisible by all other numbers in this array. Output 1, if such a number exists, and 0 otherwise. Input The only line of the input contains a list of space-separated integers ai (1 ≤ ai ≤ 100) — elements of the array. The s...
{ "input": [], "output": [] }
{ "input": [ "6 12 4\n", "3 13\n", "26 13 12\n" ], "output": [ "1\n", "0\n", "0\n" ] }
{ "input": [], "output": [] }
685_E. Travelling Through the Snow Queen's Kingdom
Gerda is travelling to the palace of the Snow Queen. The road network consists of n intersections and m bidirectional roads. Roads are numbered from 1 to m. Snow Queen put a powerful spell on the roads to change the weather conditions there. Now, if Gerda steps on the road i at the moment of time less or equal to i, s...
{ "input": [], "output": [] }
{ "input": [ "5 4 6\n1 2\n2 3\n3 4\n3 5\n1 3 1 4\n1 3 2 4\n1 4 4 5\n1 4 4 1\n2 3 1 4\n2 2 2 3\n" ], "output": [ "Yes\nYes\nYes\nNo\nNo\nYes\n" ] }
{ "input": [ "5 4 6\n1 2\n2 3\n3 4\n3 5\n1 3 2 4\n1 3 2 4\n1 4 4 5\n1 4 4 1\n2 3 1 4\n2 2 2 3\n", "5 4 6\n1 2\n2 3\n3 4\n3 5\n1 3 2 4\n1 3 2 4\n1 4 4 5\n1 4 4 1\n2 3 1 4\n2 1 2 3\n", "5 4 6\n1 2\n1 3\n3 4\n3 5\n1 3 2 4\n1 3 2 4\n1 4 4 5\n1 4 4 1\n2 3 1 4\n2 1 2 3\n", "8 4 6\n1 2\n2 1\n3 4\n3 5\n1 3 2 ...
anagrams-revisited-26
Arnab is a robber and he has managed to rob N different strings from Akash. Now he decides to sell these strings in the market to make some profit. But, of all the strings he has, he wants to find the size of the largest anagram group so that he can easily sell that one first and make maximum profit initially. Help him...
{ "input": [], "output": [] }
{ "input": [ "5\nab\nba\ncab\nbca\ncba\n\nSAMPLE" ], "output": [ "3\n" ] }
{ "input": [ "5\naa\nba\ncab\nbca\ncba\n\nSAMPLE", "5\naa\nba\ncab\nbca\ncb`\n\nSAMPLE", "5\n`a\ndb\ncaa\nbcb\nabc\n\nLAMPSE", "5\nab\nca\ncab\nbca\ncba\n\nSAMPLE", "5\nab\nda\ncab\nbca\ncba\n\nSAMPLE", "5\naa\nab\ncab\nbca\ncb`\n\nSAMPLE", "5\n`b\nda\ncab\nbca\ncba\n\nSAMPLE", "5\nab\...
center-in-mass-2
You are studying a swarm of N fireflies. Each firefly is moving in a straight line at a constant speed. You are standing at the center of the universe, at position (0, 0, 0). Each firefly has the same mass, and you want to know how close the center of the swarm will get to your location (the origin). You know the posi...
{ "input": [], "output": [] }
{ "input": [ "1\n3\n3 0 -4 0 0 3\n-3 -2 -1 3 0 0\n-3 -1 2 0 3 0\n\nSAMPLE" ], "output": [ "Case #1: 0.00000000 1.00000000" ] }
{ "input": [], "output": [] }
roy-and-rangoli-1
Its Diwali time and little Roy thought of an interesting design for Rangoli. He created an N x N grid. Roy fills some of the cells of grid with red color. Cell located at ith row and jth column is colored if i+j is prime. Consider Zero-based numbering of grid. (See Sample Test Case Explanation for clarification) Roy ...
{ "input": [], "output": [] }
{ "input": [ "3\n\nSAMPLE" ], "output": [ "5\n" ] }
{ "input": [ "3\n\nSAMOLE", "3\n\nSAMNLE", "3\n\nSAMNLD", "3\n\nSLMNAD", "3\n\nDANMLS", "3\n\nMANDLS", "3\n\nSLDNAM", "3\n\nMANDKS", "3\n\nMANDKT", "3\n\nNAMDKT", "3\n\nMAMDKT", "3\n\nMAMCKT", "3\n\nLAMCKT", "3\n\nTKCMAL", "3\n\nKTCMAL", "3\n\nKSCMAL", ...
p02604 M-SOLUTIONS Programming Contest 2020 - M's Solution
New AtCoder City has an infinite grid of streets, as follows: * At the center of the city stands a clock tower. Let (0, 0) be the coordinates of this point. * A straight street, which we will call East-West Main Street, runs east-west and passes the clock tower. It corresponds to the x-axis in the two-dimensional coor...
{ "input": [], "output": [] }
{ "input": [ "8\n2 2 286017\n3 1 262355\n2 -2 213815\n1 -3 224435\n-2 -2 136860\n-3 -1 239338\n-2 2 217647\n-1 3 141903", "5\n3 5 400\n5 3 700\n5 5 1000\n5 7 700\n7 5 400", "6\n2 5 1000\n5 2 1100\n5 5 1700\n-2 -5 900\n-5 -2 600\n-5 -5 2200", "3\n1 2 300\n3 3 600\n1 4 800" ], "output": [ "25767...
{ "input": [ "8\n2 2 286017\n3 1 262355\n2 -2 213815\n1 -3 224435\n-2 -2 136860\n-3 -1 239338\n-2 1 217647\n-1 3 141903", "5\n3 5 400\n5 3 700\n5 5 1000\n4 7 700\n7 5 400", "6\n2 4 1000\n5 2 1100\n5 5 1700\n-2 -5 900\n-5 -2 600\n-5 -5 2200", "3\n1 2 300\n3 3 600\n1 4 1273", "8\n2 2 456035\n3 1 262...
p02735 AtCoder Grand Contest 043 - Range Flip Find Route
Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be good if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one sq...
{ "input": [], "output": [] }
{ "input": [ "2 2\n.\n.#", "4 4\n..##\n...\n.\n.", "5 5\n.#.#.\n.#.#\n.#.#.\n.#.#\n.#.#.", "3 3\n.##\n.#.\n##.", "3 3\n.##\n.#.\n." ], "output": [ "2", "0", "4", "1", "1" ] }
{ "input": [ "2 2\n.\n#.", "4 4\n##..\n...\n.\n.", "1 7\n#.#/\n-..\n0\n,", "3 3\n.##\n.#-\n.", "2 2\n.\n$.", "4 4\n##..\n...\n-\n.", "2 3\n.##\n.#-\n.", "2 2\n.\n/#", "7 4\n..##\n...\n.\n.", "3 3\n.##\n.#.\n##-", "2 1\n.\n#.", "3 4\n##..\n...\n.\n.", "3 3\n.##\n.-#\...
p02869 NIKKEI Programming Contest 2019-2 - Non-triangular Triplets
Given are positive integers N and K. Determine if the 3N integers K, K+1, ..., K+3N-1 can be partitioned into N triples (a_1,b_1,c_1), ..., (a_N,b_N,c_N) so that the condition below is satisfied. Any of the integers K, K+1, ..., K+3N-1 must appear in exactly one of those triples. * For every integer i from 1 to N, a_...
{ "input": [], "output": [] }
{ "input": [ "3 3", "1 1" ], "output": [ "-1", "1 2 3" ] }
{ "input": [ "3 6", "1 0", "1 -1", "1 -2", "1 -4", "1 -3", "1 -7", "1 -12", "1 -5", "1 -10", "1 -20", "1 -33", "1 -36", "1 -26", "1 -9", "1 -6", "1 -8", "1 -16", "1 2", "6 6", "0 2", "5 6", "-1 2", "7 6", "0 1", "8...
p03004 AtCoder Beginner Contest 130 - Minimum Bounding Box
There are N points in a two-dimensional plane. The initial coordinates of the i-th point are (x_i, y_i). Now, each point starts moving at a speed of 1 per second, in a direction parallel to the x- or y- axis. You are given a character d_i that represents the specific direction in which the i-th point moves, as follows:...
{ "input": [], "output": [] }
{ "input": [ "2\n0 3 D\n3 0 L", "20\n6 -10 R\n-4 -9 U\n9 6 D\n-3 -2 R\n0 7 D\n4 5 D\n10 -10 U\n-1 -8 U\n10 -6 D\n8 -5 U\n6 4 D\n0 3 D\n7 9 R\n9 -4 R\n3 10 D\n1 9 U\n1 -6 U\n9 -8 R\n6 7 D\n7 -3 D", "5\n-7 -10 U\n7 -6 U\n-8 7 D\n-3 3 D\n0 -6 R" ], "output": [ "0", "273", "97.5" ] }
{ "input": [ "20\n6 -10 R\n-4 -9 U\n9 6 D\n-3 -2 R\n0 7 D\n4 5 D\n10 -10 U\n-1 -8 U\n10 -6 D\n8 -5 U\n6 4 D\n0 3 D\n7 9 R\n9 -4 R\n3 10 D\n1 9 U\n1 -6 U\n9 -8 R\n9 7 D\n7 -3 D", "5\n-7 -10 U\n7 -6 U\n-8 7 D\n-4 3 D\n0 -6 R", "5\n-7 -10 U\n7 -6 U\n-8 7 D\n-8 3 D\n1 -6 R", "2\n0 3 D\n3 1 L", "20\n6 ...
p03144 NIKKEI Programming Contest 2019 - Jewels
There are N jewels, numbered 1 to N. The color of these jewels are represented by integers between 1 and K (inclusive), and the color of Jewel i is C_i. Also, these jewels have specified values, and the value of Jewel i is V_i. Snuke would like to choose some of these jewels to exhibit. Here, the set of the chosen jew...
{ "input": [], "output": [] }
{ "input": [ "8 4\n3 2\n2 3\n4 5\n1 7\n3 11\n4 13\n1 17\n2 19", "15 5\n3 87\n1 25\n1 27\n3 58\n2 85\n5 19\n5 39\n1 58\n3 12\n4 13\n5 54\n4 100\n2 33\n5 13\n2 55", "5 2\n1 1\n1 2\n1 3\n2 4\n2 5", "5 2\n1 1\n1 2\n2 3\n2 4\n2 5" ], "output": [ "-1\n24\n-1\n46\n-1\n64\n-1\n77", "-1\n145\n173\n...
{ "input": [ "15 5\n3 87\n1 25\n1 27\n3 58\n2 85\n5 19\n5 39\n1 58\n3 12\n4 14\n5 54\n4 100\n2 33\n5 13\n2 55", "5 2\n1 1\n1 2\n1 3\n2 3\n2 5", "5 2\n1 1\n1 2\n2 3\n2 4\n1 5", "5 2\n1 1\n1 2\n1 3\n2 6\n2 5", "15 5\n3 87\n1 25\n1 27\n3 58\n2 85\n5 19\n5 39\n1 58\n3 12\n4 13\n5 54\n4 100\n2 33\n5 4\...
p03288 AtCoder Beginner Contest 104 - Rated for Me
A programming competition site AtCode regularly holds programming contests. The next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200. The contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800. The contest after the ARC is called AG...
{ "input": [], "output": [] }
{ "input": [ "1199", "1200", "4208" ], "output": [ "ABC", "ARC", "AGC" ] }
{ "input": [ "91", "2343", "4178", "256", "17", "120", "23", "29", "46", "10", "51", "11", "57", "26", "69", "42", "45", "35", "32", "62", "34", "44", "60", "38", "65", "54", "48", "94", "1", "2", ...
p03444 AtCoder Petrozavodsk Contest 001 - Generalized Insertion Sort
You are given a rooted tree with N vertices. The vertices are numbered 0, 1, ..., N-1. The root is Vertex 0, and the parent of Vertex i (i = 1, 2, ..., N-1) is Vertex p_i. Initially, an integer a_i is written in Vertex i. Here, (a_0, a_1, ..., a_{N-1}) is a permutation of (0, 1, ..., N-1). You can execute the followi...
{ "input": [], "output": [] }
{ "input": [ "5\n0 1 2 3\n2 4 0 1 3", "5\n0 1 2 2\n4 3 1 2 0" ], "output": [ "2\n3\n4", "3\n4\n3\n1" ] }
{ "input": [ "5\n0 1 0 3\n2 4 0 1 3", "5\n0 1 2 2\n2 4 0 1 3", "5\n0 1 1 3\n2 4 0 1 3", "5\n0 0 2 2\n4 3 1 2 0", "5\n0 1 0 2\n4 3 1 2 0", "5\n0 0 1 3\n2 4 0 1 3", "5\n0 0 2 3\n4 3 1 2 0", "5\n0 0 1 2\n2 4 0 1 3", "5\n0 1 2 3\n4 3 1 2 0", "5\n0 1 2 1\n4 3 1 2 0", "5\n0 1 0 0...
p03604 AtCoder Regular Contest 083 - Collecting Balls
There are 2N balls in the xy-plane. The coordinates of the i-th of them is (x_i, y_i). Here, x_i and y_i are integers between 1 and N (inclusive) for all i, and no two balls occupy the same coordinates. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the type-A r...
{ "input": [], "output": [] }
{ "input": [ "4\n1 1\n2 2\n3 3\n4 4\n1 2\n2 1\n3 4\n4 3", "8\n6 2\n5 1\n6 8\n7 8\n6 5\n5 7\n4 3\n1 4\n7 6\n8 3\n2 8\n3 6\n3 2\n8 5\n1 5\n5 8", "2\n1 1\n1 2\n2 1\n2 2", "3\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3", "4\n3 2\n1 2\n4 1\n4 2\n2 2\n4 4\n2 1\n1 3" ], "output": [ "4480", "82060779", ...
{ "input": [ "8\n6 2\n5 1\n6 8\n7 8\n6 5\n5 7\n2 3\n1 4\n7 6\n8 3\n2 8\n3 6\n3 2\n8 5\n1 5\n5 8", "4\n1 1\n4 2\n3 3\n4 4\n1 2\n2 1\n3 4\n4 3", "8\n6 2\n5 1\n6 8\n7 8\n6 5\n5 7\n4 3\n1 4\n7 6\n8 3\n2 8\n3 6\n3 2\n4 5\n1 5\n5 8", "3\n1 1\n1 2\n1 0\n2 1\n2 2\n2 3", "3\n1 1\n1 2\n2 1\n2 0\n1 3\n4 3", ...
p03765 AtCoder Regular Contest 071 - TrBBnsformBBtion
Let us consider the following operations on a string consisting of `A` and `B`: 1. Select a character in a string. If it is `A`, replace it with `BB`. If it is `B`, replace with `AA`. 2. Select a substring that is equal to either `AAA` or `BBB`, and delete it from the string. For example, if the first operation is ...
{ "input": [], "output": [] }
{ "input": [ "AAAAABBBBAAABBBBAAAA\nBBBBAAABBBBBBAAAAABB\n10\n2 15 2 13\n2 13 6 16\n1 13 2 20\n4 20 3 20\n1 18 9 19\n2 14 1 11\n3 20 3 15\n6 16 1 17\n4 18 8 20\n7 20 3 14", "BBBAAAABA\nBBBBA\n4\n7 9 2 5\n7 9 1 4\n1 7 2 5\n1 7 2 4" ], "output": [ "YES\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO", "YES...
{ "input": [ "AAAAABBBBAAABBBBAAAA\nBBBBAAABBBBBBAAAAABB\n10\n2 15 2 13\n2 13 6 16\n1 13 2 20\n4 20 6 20\n1 18 9 19\n2 14 1 11\n3 20 3 15\n6 16 1 17\n4 18 8 20\n7 20 3 14", "BBBAAAABA\nBBBBA\n4\n7 9 2 5\n7 9 1 4\n1 7 2 5\n1 6 2 4", "AAAAABBBBAAABBBBAAAA\nBBBBAAABBBBBBAAAAABB\n10\n2 15 2 13\n2 13 6 16\n1 1...
p03933 square869120Contest #3 - Circle and Many Triangles
Input The input is given from Standard Input in the following format: > $N \ K$ Output * Please output the $K$-th triangle area. * Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than $10^{−9}$. Constraints * $3 \le N \le 200,000$ * $1 \le K \le \...
{ "input": [], "output": [] }
{ "input": [ "4 3", "12 220", "6 9" ], "output": [ "1.0000000000000", "1.29903810568", "0.86602540378" ] }
{ "input": [ "4 4", "6 6", "7 4", "11 1", "5 6", "6 15", "8 4", "7 12", "11 14", "13 11", "17 11", "12 4", "9 1", "5 1", "7 23", "8 14", "6 20", "20 11", "29 7", "21 4", "10 1", "10 23", "17 18", "53 7", "15 1", "1...
p00026 Dropping Ink
As shown in the following figure, there is a paper consisting of a grid structure where each cell is indicated by (x, y) coordinate system. We are going to put drops of ink on the paper. A drop comes in three different sizes: Large, Medium, and Small. From the point of fall, the ink sinks into surrounding cells as sho...
{ "input": [], "output": [] }
{ "input": [ "2,5,3\n3,6,1\n3,4,2\n4,5,2\n3,6,3\n2,4,1" ], "output": [ "77\n5" ] }
{ "input": [ "2,5,3\n3,6,1\n3,4,2\n4,5,2\n3,6,3\n1,4,1", "2,5,3\n1,6,3\n3,4,2\n4,5,2\n3,6,3\n2,4,1", "2,5,3\n3,6,1\n2,4,2\n4,5,2\n3,6,3\n1,4,1", "2,5,3\n3,6,1\n3,4,2\n5,5,2\n3,6,3\n1,4,1", "2,5,3\n3,6,1\n2,4,2\n4,6,2\n3,6,3\n1,4,1", "2,5,3\n3,6,1\n3,4,2\n4,5,2\n3,6,3\n2,4,2", "1,5,3\n1,6,3...
p00157 Russian Dolls
<image> Matryoshka is a wooden doll in the shape of a female figure and is a typical Russian folk craft. Matryoshka has a nested structure in which smaller dolls are contained inside a large doll, and is composed of multiple dolls of different sizes. In order to have such a nested structure, the body of each doll has ...
{ "input": [], "output": [] }
{ "input": [ "6\n1 1\n4 3\n6 5\n8 6\n10 10\n14 14\n5\n2 2\n5 4\n6 6\n9 8\n15 10\n4\n1 1\n4 3\n6 5\n8 6\n3\n2 2\n5 4\n6 6\n4\n1 1\n4 3\n6 5\n8 6\n4\n10 10\n12 11\n18 15\n24 20\n0" ], "output": [ "9\n6\n8" ] }
{ "input": [ "6\n1 1\n4 3\n6 5\n8 6\n10 10\n14 14\n5\n2 1\n5 4\n6 6\n9 8\n15 10\n4\n1 1\n4 3\n6 5\n8 6\n3\n2 2\n5 4\n6 6\n4\n1 1\n4 3\n6 5\n8 6\n4\n10 10\n12 11\n18 15\n24 20\n0", "6\n1 1\n4 3\n6 5\n8 6\n10 10\n14 14\n5\n2 2\n5 4\n6 6\n9 8\n15 10\n4\n1 1\n4 3\n6 5\n8 6\n3\n2 2\n5 4\n6 6\n4\n1 2\n4 3\n6 5\n8 6...
p00314 Programming Contest
A programming contest will be held at White Tiger University this year as well. There are several questions in the contest, each of which is assigned a score according to the difficulty level. The executive committee decided to calculate the score for each team based on the following rules, taking into account both th...
{ "input": [], "output": [] }
{ "input": [ "7\n5 4 3 10 2 4 1", "3\n1 1 100", "4\n11 15 58 1" ], "output": [ "4", "1", "3" ] }
{ "input": [ "7\n5 4 3 14 2 4 1", "3\n1 0 100", "3\n2 0 100", "7\n0 1 5 37 2 4 1", "7\n5 4 3 14 2 7 1", "7\n5 4 2 14 2 7 1", "7\n5 4 4 14 2 7 1", "7\n5 4 4 14 1 7 1", "7\n10 4 4 14 1 7 1", "7\n10 4 4 14 1 7 2", "7\n10 4 4 14 1 3 2", "7\n10 4 4 23 1 3 2", "7\n10 4 4 ...
p00484 Books
There is a long-established secondhand bookstore called JOI secondhand bookstore in your town, and you often use the JOI secondhand bookstore. Each book has a standard price, and you can buy it at that price if you go to the JOI secondhand bookstore. At the JOI secondhand bookstore, books are classified into 10 genres...
{ "input": [], "output": [] }
{ "input": [ "7 4\n14 1\n13 2\n12 3\n14 2\n8 2\n16 3\n11 2" ], "output": [ "60" ] }
{ "input": [ "7 4\n14 1\n13 2\n12 3\n26 2\n8 2\n16 3\n11 2", "7 4\n4 1\n13 2\n12 3\n48 2\n8 2\n16 5\n11 2", "7 4\n4 1\n13 2\n11 3\n48 3\n8 2\n16 5\n11 2", "7 5\n4 1\n13 2\n11 3\n48 3\n8 2\n16 5\n11 2", "7 5\n4 1\n13 2\n11 3\n48 3\n8 2\n23 5\n11 2", "7 5\n4 1\n13 2\n11 3\n43 3\n8 2\n23 5\n11 2"...
p00670 Spellcasters
There are n wizards. They are numbered from 1 to n, and the i-th wizard has the magical power ri (1 ≤ i ≤ n). Now they are confronting a powerful wizard, whose enemy's magical power is S. n Wizards are good at fighting together, especially two people. When two wizards cooperate, the magical power is simply the sum, and...
{ "input": [], "output": [] }
{ "input": [ "3 7\n1\n3\n10\n0 0" ], "output": [ "2" ] }
{ "input": [ "3 7\n1\n6\n10\n0 0", "3 11\n0\n3\n10\n0 0", "3 7\n2\n6\n10\n0 0", "3 7\n1\n0\n5\n0 0", "3 7\n0\n3\n10\n0 0", "3 7\n1\n3\n16\n0 0", "3 7\n1\n3\n25\n0 0", "3 11\n0\n3\n18\n0 0", "3 7\n1\n1\n25\n0 0", "3 11\n0\n3\n20\n0 0", "3 1\n0\n3\n10\n0 0", "3 7\n1\n0\n1...
p00813 GIGA Universe Cup
Following FIFA World Cup, a larger competition called ``GIGA Universe Cup'' is taking place somewhere in our universe. Both FIFA World Cup and GIGA Universe Cup are two rounds competitions that consist of the first round, also known as ``group league,'' and the second called ``final tournament.'' In the first round, pa...
{ "input": [], "output": [] }
{ "input": [ "5\n_____*AAA__BBB__CCC__DDD\n*AAA_______0-0__0-0___-_\n_BBB_____________-___0-0\n_CCC_________________0-0\n_DDD____________________\n______CHN__CRC__TUR_*BRA\n_CHN_______0-2___-___0-4\n_CRC____________1-1___-_\n_TUR_________________1-2\n*BRA____________________\n______CMR_*KSA__GER__IRL\n_CMR_______...
{ "input": [ "5\n_____*AAA__BBB__CCC__DDD\n*AAA_______0-0__0-0___-_\n_BBB_____________-___0-0\n_CCC_________________0-0\n_DDD____________________\n______CHN__CRC__TUR_*BRA\n_CHN_______0-2___-___0-4\n_CRC____________1-1___-_\n_TUR_________________1-2\n*BRA______________^_____\n______CMR_*KSA__GER__IRL\n_CMR_______...
p00944 Post Office Investigation
Example Input 8 8 1 2 1 3 2 4 2 5 2 8 3 5 3 6 4 7 1000 100 100 10 10 10 1 1 3 2 8 6 2 4 7 2 7 8 Output 1000 10 100
{ "input": [], "output": [] }
{ "input": [ "8 8\n1 2\n1 3\n2 4\n2 5\n2 8\n3 5\n3 6\n4 7\n1000\n100\n100\n10\n10\n10\n1\n1\n3\n2 8 6\n2 4 7\n2 7 8" ], "output": [ "1000\n10\n100" ] }
{ "input": [ "8 8\n1 2\n1 3\n2 4\n2 5\n2 8\n3 5\n1 6\n4 7\n1000\n100\n100\n10\n10\n10\n1\n1\n3\n2 8 6\n2 4 7\n2 7 8", "8 8\n1 2\n1 3\n2 4\n2 5\n2 8\n3 5\n1 6\n4 7\n1000\n100\n100\n10\n10\n10\n1\n1\n3\n2 8 6\n2 4 6\n2 7 8", "8 8\n1 2\n1 3\n2 4\n2 5\n3 8\n3 5\n3 6\n4 7\n1000\n100\n100\n10\n10\n10\n1\n1\n3\n...
p01077 Curling Puzzle
Problem There is a puzzle game where you move curling stones and stack them exactly on the goal square. The detailed rules are as follows. The field consists of H × W squares, with stones placed in some squares at the beginning. There is only one goal square, and no stone is placed on the goal square from the beginni...
{ "input": [], "output": [] }
{ "input": [ "3 6\n......\n.o..@.\n......", "6 4\n....\n.oo.\n.oo.\n....\n.@..\n....", "1 10\no........@" ], "output": [ "no", "yes", "yes" ] }
{ "input": [ "3 6\n...../\n.o..@.\n......", "6 4\n....\n.oo.\n.o.o\n....\n.@..\n....", "6 4\n....\n.oo.\n.o.o\n....\n.@-.\n....", "6 4\n....\n.oo.\n.o.o\n/...\n.@-.\n....", "6 4\n....\n.oo.\n.o.o\n.../\n.@-.\n....", "6 4\n./..\n.oo.\n.o.o\n.../\n.@-.\n....", "6 4\n./-.\n.oo.\n.o.o\n.../\n....
p01211 Spirograph
Some of you might have seen instruments like the figure below. <image> Figure 1: Spirograph There are a fixed circle (indicated by A in the figure) and a smaller interior circle with some pinholes (indicated by B). By putting a pen point through one of the pinholes and then rolling the circle B without slipping arou...
{ "input": [], "output": [] }
{ "input": [ "3 2 1\n3 2 0\n0 0 0" ], "output": [ "13.36\n6.28" ] }
{ "input": [ "3 3 1\n3 2 0\n0 0 0", "3 3 1\n3 2 1\n0 0 0", "3 4 1\n3 2 0\n0 0 0", "3 1 1\n3 2 0\n0 0 0", "3 3 1\n6 2 1\n0 0 -1", "3 1 2\n3 2 0\n0 0 0", "3 3 1\n9 2 1\n0 0 -1", "3 1 2\n3 2 1\n0 0 0", "3 1 2\n3 2 2\n0 0 -1", "3 3 1\n3 2 0\n1 0 0", "6 3 1\n3 2 1\n0 0 0", "...
p01347 How to Create a Good Game
A video game company called ICPC (International Company for Playing and Competing) is now developing a new arcade game. The new game features a lot of branches. This makes the game enjoyable for everyone, since players can choose their routes in the game depending on their skills. Rookie players can choose an easy rout...
{ "input": [], "output": [] }
{ "input": [ "4 6\n0 1 5\n0 2 5\n0 3 5\n1 2 5\n1 3 5\n2 3 5", "2 1\n0 1 10", "3 3\n0 1 5\n1 2 3\n0 2 2" ], "output": [ "20", "0", "6" ] }
{ "input": [ "3 3\n0 1 5\n1 2 3\n1 2 2", "2 1\n0 1 13", "3 3\n0 1 5\n1 2 2\n0 2 2", "3 3\n0 1 5\n1 2 5\n1 2 2", "3 3\n0 1 5\n1 2 6\n0 2 2", "3 3\n0 1 9\n1 2 6\n0 2 2", "3 3\n0 1 13\n1 2 6\n0 2 2", "3 3\n0 1 5\n1 2 3\n1 2 1", "3 3\n0 1 9\n1 2 6\n0 2 3", "3 3\n0 1 1\n1 2 6\n0 2 3...
p01527 Tree Planting
Problem statement Mr. K, a student of the magic department of a certain university, lives in a vast mansion. There was a forest behind the mansion, but there were places where no trees were growing. I felt that it would look bad from the mansion as it was, so Mr. K decided to plant a tree in a place where no trees wer...
{ "input": [], "output": [] }
{ "input": [ "4 4\n0 0 0 1\n0 1 1 0\n0 1 1 0\n1 0 0 0" ], "output": [ "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1" ] }
{ "input": [ "4 4\n0 0 0 1\n0 1 1 0\n1 1 1 0\n1 0 0 0", "4 4\n0 0 0 1\n0 0 1 0\n1 1 1 0\n1 0 0 0", "2 4\n0 0 0 1\n0 1 1 0\n1 1 1 0\n1 0 0 0", "4 4\n0 0 0 0\n0 0 1 0\n1 1 1 0\n1 0 0 0", "4 4\n0 0 0 0\n0 0 0 0\n1 1 1 0\n1 0 0 0", "2 2\n0 0 0 1\n0 1 1 0\n1 1 1 0\n2 0 0 0", "2 2\n0 1 0 1\n0 1 ...
p01685 Overwriting Game
Problem Statement You have a rectangular board with square cells arranged in $H$ rows and $W$ columns. The rows are numbered $1$ through $H$ from top to bottom, and the columns are numbered $1$ through $W$ from left to right. The cell at the row $i$ and the column $j$ is denoted by $(i, j)$. Each cell on the board is ...
{ "input": [], "output": [] }
{ "input": [ "1 2\nBB\n\nWW\n\n2 1\nB\nW\n\nB\nW\n\n2 2\nBW\nBW\n\nWW\nWW\n\n3 4\nBBBB\nBBBB\nBBBB\n\nWWWW\nWWWW\nWWWW\n\n5 5\nBBBBB\nBBBBB\nBBBBB\nBBBBB\nBBBBB\n\nBBBBB\nBBBWB\nBBBBB\nBWBBB\nBBBBB\n\n0 0" ], "output": [ "6.0000000000\n0.0000000000\n12.8571428571\n120.0000000000\n23795493.8449918639" ] ...
{ "input": [ "1 2\nBB\n\nWW\n\n2 1\nB\nW\n\nB\nW\n\n2 2\nCW\nBW\n\nWW\nWW\n\n3 4\nBBBB\nBBBB\nBBBB\n\nWWWW\nWWWW\nWWWW\n\n5 5\nBBBBB\nBBBBB\nBBBBB\nBBBBB\nBBBBB\n\nBBBBB\nBBBWB\nBBBBB\nBWBBB\nBBBBB\n\n0 0", "1 2\nBB\n\nWW\n\n2 1\nB\nW\n\nB\nW\n\n2 2\nCW\nBW\n\nWW\nWW\n\n3 4\nBBBB\nBBBB\nBBBB\n\nWWWW\nWWWW\nWW...
p01829 Change a Password
Example Input 201 Output 701
{ "input": [], "output": [] }
{ "input": [ "201" ], "output": [ "701" ] }
{ "input": [ "27", "36", "44", "57", "76", "148", "2", "4", "3", "5", "7", "87", "43", "98", "81", "106", "145", "225", "1", "10", "6", "8", "171", "79", "177", "116", "119", "18", "368", "16", ...
p01964 Revenge of the Endless BFS
Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on a directed graph. An example of pseudo code of BFS is as follows: 1: $current \leftarrow \{start\_vertex\}$ 2: $visited \leftarrow current$ 3: while $visited \ne$ the set of all the verti...
{ "input": [], "output": [] }
{ "input": [ "4 4\n1 2\n2 3\n3 4\n4 1", "4 5\n1 2\n2 3\n3 4\n4 1\n1 3", "5 13\n4 2\n2 4\n1 2\n5 4\n5 1\n2 1\n5 3\n4 3\n1 5\n4 5\n2 3\n5 2\n1 3" ], "output": [ "-1", "7", "3" ] }
{ "input": [ "4 4\n1 2\n2 3\n3 6\n4 1", "5 13\n4 2\n2 4\n1 2\n5 4\n5 1\n2 1\n5 2\n4 3\n1 5\n4 5\n2 3\n5 2\n1 3", "5 13\n4 2\n2 4\n1 2\n5 4\n6 1\n2 1\n5 3\n4 3\n1 3\n4 5\n2 3\n5 2\n1 3", "5 13\n4 4\n1 5\n1 2\n5 4\n5 1\n2 1\n5 2\n4 3\n2 5\n4 5\n2 3\n5 2\n1 3", "5 13\n4 4\n2 4\n1 2\n5 4\n5 1\n0 1\n5 ...
p02111 Clock
Problem Gaccho has his favorite watch. One day the minute hand of the clock came off and I lost it somewhere. However, Gaccho wants to keep using the watch and wants to read the time with only the short hand. Output the time (hour h, minute m) for the information θ of the short hand. A clock is a so-called analog clo...
{ "input": [], "output": [] }
{ "input": [ "100", "0", "45" ], "output": [ "3 20", "0 0", "1 30" ] }
{ "input": [ "110", "-1", "1", "-2", "2", "-3", "-4", "-6", "-7", "-8", "-13", "-14", "-23", "4", "-33", "3", "-22", "6", "-28", "12", "-46", "14", "-51", "19", "-40", "36", "-66", "44", "-101", "16...
p02251 Change Making
You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need. Constraints * $ 1 \ le n \ le 10 ^ 9 $ Input $ n $ The integer $ n $ is given in a line. output Print the minimum number of coins...
{ "input": [], "output": [] }
{ "input": [ "100", "54321" ], "output": [ "4", "2175" ] }
{ "input": [ "000", "97162", "010", "164898", "110", "251195", "111", "83071", "4499", "011", "7154", "1073", "1295", "1296", "2383", "581", "305", "173", "338", "169", "161", "327", "1135", "2208", "1630", "2083",...
p02399 A / B Problem
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number) Constraints * 1 ≤ a, b ≤ 109 Input Two integers a and b are given in a line. Output Print d, r and f separated by a space in a line. For ...
{ "input": [], "output": [] }
{ "input": [ "3 2" ], "output": [ "1 1 1.50000" ] }
{ "input": [ "0 2", "1 2", "5 2", "-1 2", "1 3", "5 3", "1 5", "2 3", "1 1", "4 2", "-1 1", "-2 1", "2 6", "7 2", "-3 2", "8 3", "1 9", "-1 3", "2 5", "-1 4", "4 1", "-2 4", "3 6", "11 2", "13 3", "-1 5", "3 -1...
amr14i
Virat Kohli and Rohit Sharma are warming up for the World Cup at the Brisbane Cricket Ground, commonly known as "The Gabba". Their coach has asked them to go to the ground at the crack of dawn, and then jog around the stadium in laps. The Cricket Ground has poles spaced equally apart and numbered sequentially from 1 to...
{ "input": [], "output": [] }
{ "input": [ "2\n4 1 4 2 3\n5 3 10 1 2" ], "output": [ "1\n3" ] }
{ "input": [], "output": [] }
chfans
Chef is studying Rotational Motion in physics. Here is preparing for Engineering Entrance exam. He's stuck in a problem. Which states that "Two fans, each with a single blade are rotating one above the other, about the same axis of rotation and both blades have the same length. Consider the blade as a rod. Both the fan...
{ "input": [], "output": [] }
{ "input": [ "3\n1 2\n6 5\n1 -2" ], "output": [ "1\n1\n3" ] }
{ "input": [ "3\n1 2\n6 5\n1 -4", "3\n1 2\n6 5\n2 -4", "3\n2 2\n6 5\n2 -1", "3\n4 2\n9 5\n2 -1", "3\n4 2\n9 5\n2 -2", "3\n1 2\n7 5\n1 -2", "3\n1 2\n6 5\n1 -6", "3\n7 2\n9 5\n2 -1", "3\n2 2\n7 5\n1 -2", "3\n1 2\n12 5\n1 -6", "3\n4 2\n6 8\n2 -2", "3\n5 2\n9 5\n1 -2", ...
dynainv
You are given a permutation A of the first N positive integers. You are also given Q queries to perform one-by-one, the i-th is defined by a pair Xi Yi and has the meaning that you swap the Xi-th number in the permutation with the Yi-th one. After performing each query you should output the number of inversions in the ...
{ "input": [], "output": [] }
{ "input": [ "5 1\n1 2 3 4 5\n2 3" ], "output": [ "1" ] }
{ "input": [ "5 1\n1 2 3 4 5\n2 5", "5 1\n1 2 3 7 5\n2 4", "5 1\n1 2 3 4 5\n2 4", "5 1\n1 2 3 4 5\n4 4", "9 1\n1 2 3 7 5\n2 4", "5 1\n1 2 3 4 5\n3 4", "9 1\n1 0 3 7 5\n2 4", "9 1\n2 0 3 7 5\n2 4", "9 1\n2 0 3 7 5\n2 0", "9 1\n1 2 3 4 5\n2 3", "5 1\n1 2 3 6 5\n4 4", "5 1...
kgp14a
Liliputs are holding a drawing competition for K kids, but with K human-sized pencils stolen from humans. In order to make life easier for the kids, the organizers want to give a pencil to each kid in a way such that the sum of the absolute differences of the height of a kid and the length of the pencil assigned to him...
{ "input": [], "output": [] }
{ "input": [ "2\n5\n51 60 51 72 70 \n65 60 88 72 88 \n4 \n123 234 188 175 \n219 334 122 233" ], "output": [ "Case 1: 69 \nCase 2: 190" ] }
{ "input": [ "2\n5\n51 60 51 72 70 \n65 60 72 72 88 \n4 \n123 234 188 175 \n219 334 122 233", "2\n5\n51 60 51 72 18 \n65 60 72 72 88 \n4 \n123 234 188 175 \n219 334 122 233", "2\n5\n51 60 51 72 18 \n65 60 29 72 88 \n4 \n123 234 188 175 \n219 334 122 233", "2\n5\n51 60 51 72 18 \n65 60 29 72 88 \n4 \n1...