name
stringlengths
2
112
description
stringlengths
29
13k
private_tests
dict
public_tests
dict
generated_tests
dict
p00610 Cleaning Robot 2
Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful. First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has N × N rooms arranged in...
{ "input": [], "output": [] }
{ "input": [ "2 1\n2 3\n6 4\n0 0" ], "output": [ "..\n..\n\nNo\n\n..EEEE\n..E..E\nEEE..E\nE..EEE\nE..E..\nEEEE.." ] }
{ "input": [ "3 1\n2 3\n6 4\n0 0", "4 1\n2 3\n6 4\n0 0", "3 1\n4 3\n6 4\n0 0", "4 1\n1 3\n6 6\n0 0", "5 1\n4 3\n6 6\n0 0", "8 1\n1 3\n6 6\n0 0", "5 1\n4 3\n12 4\n0 0", "8 1\n1 3\n2 6\n0 0", "5 1\n4 3\n23 4\n0 0", "16 1\n1 3\n2 6\n0 0", "19 1\n1 3\n2 6\n0 0", "34 1\n1 6\...
p00748 Pollock's conjecture
The nth triangular number is defined as the sum of the first n positive integers. The nth tetrahedral number is defined as the sum of the first n triangular numbers. It is easy to show that the nth tetrahedral number is equal to n(n+1)(n+2) ⁄ 6. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+...
{ "input": [], "output": [] }
{ "input": [ "40\n14\n5\n165\n120\n103\n106\n139\n0" ], "output": [ "2 6\n2 14\n2 5\n1 1\n1 18\n5 35\n4 4\n3 37" ] }
{ "input": [ "40\n14\n5\n165\n120\n133\n106\n139\n0", "40\n14\n5\n98\n120\n133\n106\n139\n0", "40\n14\n5\n98\n120\n133\n106\n150\n0", "40\n14\n5\n70\n120\n133\n106\n150\n0", "40\n14\n9\n70\n120\n133\n106\n150\n0", "40\n14\n9\n70\n72\n133\n106\n150\n0", "40\n14\n9\n29\n72\n133\n106\n150\n0"...
p00886 Towns along a Highway
There are several towns on a highway. The highway has no forks. Given the distances between the neighboring towns, we can calculate all distances from any town to others. For example, given five towns (A, B, C, D and E) and the distances between neighboring towns like in Figure C.1, we can calculate the distance matrix...
{ "input": [], "output": [] }
{ "input": [ "2\n1\n3\n5 3 2\n3\n6 3 2\n5\n9 8 7 6 6 4 3 2 2 1\n6\n9 8 8 7 6 6 5 5 3 3 3 2 2 1 1\n6\n11 10 9 8 7 6 6 5 5 4 3 2 2 1 1\n7\n72 65 55 51 48 45 40 38 34 32 27 25 24 23 21 17 14 13 11 10 7\n20\n190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171\n170 169 168 167 166 165 164 1...
{ "input": [ "2\n1\n3\n5 3 2\n3\n6 3 2\n5\n9 8 7 6 6 4 3 2 2 1\n6\n9 8 8 7 6 6 5 5 3 3 3 2 2 1 1\n6\n11 10 9 8 7 6 6 5 5 4 3 2 2 1 1\n7\n72 65 55 51 48 45 40 38 34 32 27 25 24 23 21 17 14 13 11 10 7\n20\n190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171\n170 169 168 167 166 165 164 1...
p01017 Yu-kun Likes Rectangles
Background The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves rectangles as much as programming. Yu-kun decided to write a program to calculate the maximum score that can be obtained, thinking of a new play to ge...
{ "input": [], "output": [] }
{ "input": [ "4 4\n10 2 -1 6\n8 1 -100 41\n22 47 32 11\n-41 99 12 -8\n1 0 0 1\n0 0 1 0\n0 1 0 1\n0 0 1 0\n2 3\n1 0 1\n0 1 0", "3 4\n4 1 9 1\n9 1 -1 3\n2 -4 1 10\n1 1 0 1\n0 1 1 1\n1 1 0 0\n1 4\n1 1 1 1", "3 3\n5 1 3\n2 5 9\n0 1 5\n1 0 0\n0 1 1\n0 1 1\n1 1\n1" ], "output": [ "193", "NA", "9...
{ "input": [ "4 4\n10 2 -1 6\n8 1 -100 41\n22 47 32 11\n-41 99 12 -8\n1 0 0 1\n0 0 2 0\n0 1 0 1\n0 0 1 0\n2 3\n1 0 1\n0 1 0", "3 4\n4 1 9 1\n9 2 -1 3\n2 -4 1 10\n1 1 0 1\n0 1 1 1\n1 1 0 0\n1 4\n1 1 1 1", "3 3\n5 1 3\n4 5 9\n0 1 5\n1 0 0\n0 1 1\n0 1 1\n1 1\n1", "3 3\n5 1 3\n4 5 9\n0 1 5\n1 0 0\n0 1 2\n...
p01150 Eight Princes
Once upon a time in a kingdom far, far away, there lived eight princes. Sadly they were on very bad terms so they began to quarrel every time they met. One day, the princes needed to seat at the same round table as a party was held. Since they were always in bad mood, a quarrel would begin whenever: * A prince took t...
{ "input": [], "output": [] }
{ "input": [ "8\n16\n17\n0" ], "output": [ "0\n0\n685440" ] }
{ "input": [ "8\n6\n17\n0", "8\n23\n17\n0", "8\n6\n3\n0", "8\n0\n17\n0", "8\n30\n17\n0", "8\n6\n23\n0", "8\n23\n33\n0", "8\n1\n0\n0", "8\n30\n24\n0", "8\n6\n21\n0", "8\n40\n33\n0", "8\n15\n33\n0", "8\n5\n25\n0", "8\n23\n2\n0", "8\n39\n33\n0", "8\n52\n24\...
p01289 Strange Couple
Alice and Bob are going to drive from their home to a theater for a date. They are very challenging - they have no maps with them even though they don’t know the route at all (since they have just moved to their new home). Yes, they will be going just by their feeling. The town they drive can be considered as an undir...
{ "input": [], "output": [] }
{ "input": [ "5 1 5\n1 0 1 0 0\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0" ], "output": [ "8.50000000" ] }
{ "input": [ "5 1 5\n0 0 1 0 0\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n1 0 1 0 1\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 1 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n1 0 1 0 1\n0 2 1 0 0\n2 0 0 1 0\n1 0 0 1 0\n0 2 1 0 1\n0 0 0 1 0\n0 0 0", "5 1 5\n1 1 1 0 1\n0 2 1 0 0\n2 0 0 1 0\n1 ...
p01458 Kth Sentence
A student, Kita_masa, is taking an English examination. In this examination, he has to write a sentence of length m. Since he completely forgot the English grammar, he decided to consider all sentences of length m constructed by concatenating the words he knows and write the K-th sentence among the candidates sorted i...
{ "input": [], "output": [] }
{ "input": [ "3 3 6\na\naa\nb", "2 10 2\nhello\nworld", "2 59 1000000000000000000\na\nb" ], "output": [ "aba", "helloworld", "-" ] }
{ "input": [ "3 3 4\na\naa\nb", "3 3 4\nb\naa\nb", "3 3 1\na\naa\nb", "2 10 0\nhello\nworld", "2 67 1000000000000000000\na\nb", "3 3 4\nc\naa\nb", "2 12 0\nhello\nworld", "2 132 1000000000000000000\na\nb", "3 5 4\nc\naa\nb", "2 12 1\nhello\nworld", "2 69 1000000000000000000...
p01609 One
One Problem Statement A beautiful mountain range can be seen from the train window. The window is a rectangle with the coordinates of the lower left corner (0, 0) and the coordinates of the upper right corner (W, H). N peaks can be seen from the window, and the i-th peak has the shape of an upwardly convex parabola y...
{ "input": [], "output": [] }
{ "input": [ "20 20 2\n-1 10 10\n-2 10 5", "15 100 2\n-2 5 100\n-2 10 100", "20 20 1\n-1 10 10" ], "output": [ "21.520346288593280", "126.921542730127873", "21.520346288593280" ] }
{ "input": [ "20 20 2\n-1 10 10\n-2 10 9", "20 20 2\n-1 18 10\n-2 10 9", "20 20 2\n-1 18 10\n-2 10 3", "20 28 1\n-2 15 10", "20 28 1\n-2 15 16", "13 20 2\n-1 10 10\n-2 10 5", "20 20 2\n-1 10 7\n-2 10 9", "20 20 2\n-1 18 12\n-2 10 9", "20 20 2\n-1 18 8\n-2 10 3", "11 28 1\n-2 15...
p01770 Arojam's Mask
Problem statement You are a hero. The world in which the hero is traveling consists of N cities and M roads connecting different cities. Road i connects town a_i and town b_i and can move in both directions. The purpose of the brave is to start from town S and move to town T. S and T are different cities. The hero ca...
{ "input": [], "output": [] }
{ "input": [ "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n3 4 7\n4 5 2" ], "output": [ "9" ] }
{ "input": [ "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 2\n1 2\n6 7\n3 4 7\n4 5 2", "8 5 2 0 5 5\n0 1\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 4", "8 5 2 0 5 5\n0 2\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 4", "8 5 2 0 3 5\n0 2\n0 3\n0 6\n1 2\n6 7\n1 4 7\n4 5 4", "8 5 2 0 1 ...
p01904 Minimum Enclosing Rectangle
G: Minimum Enclosing Rectangle-Minimum Enclosing Rectangle- story Hello everyone! It's Airi Aiza from the Hachimori Naka Prokon Club. Suddenly, I want everyone to solve the problem that Airi couldn't solve before. I solved the A problem of ICPC2010 in this front activity, but the problem at that time was difficult. ...
{ "input": [], "output": [] }
{ "input": [ "1" ], "output": [ "1" ] }
{ "input": [ "001", "001" ], "output": [ "1.000000000\n", "1.000000000\n" ] }
p02042 ABSum
problem Given a sequence $ A $ of length $ N $. You can swap the $ i $ th and $ j $ th ($ 0 \ leq i, j \ leq N-1 $) elements of a sequence up to $ M $ times. Find the maximum value of $ \ sum_ {i = 0} ^ {N -1} abs (A_i --i) $ in the sequence created by the operation. output Find the maximum value of $ \ sum_ {i =...
{ "input": [], "output": [] }
{ "input": [ "5 2\n0 3 2 1 4" ], "output": [ "12" ] }
{ "input": [ "5 2\n0 1 2 1 4", "5 2\n0 1 0 1 0", "5 2\n0 1 0 1 -1", "5 3\n-1 1 0 2 -1", "2 2\n0 1 2 1 4", "1 2\n0 1 0 1 0", "4 3\n0 1 0 2 -1", "2 3\n-1 1 0 2 -1", "2 3\n-2 1 0 2 -1", "5 2\n0 0 4 1 4", "5 2\n0 0 4 2 4", "2 3\n0 0 -1 2 -1", "9 1\n1 0 4 2 0", "9 1\...
p02185 Many Decimal Integers
D: Many Decimal Integers problem Given a string S consisting only of numbers (0-9) and a string T consisting only of numbers and `?`. S and T are the same length. Consider changing each `?` That exists in T to one of the numbers from 0 to 9 to create the string T'consisting of only numbers. At this time, it must be ...
{ "input": [], "output": [] }
{ "input": [ "73\n6?" ], "output": [ "645" ] }
{ "input": [ "73\n?6", "73\n@6", "73\n5?", "73\n?5", "73\n4?", "73\n?4", "73\n?8", "73\n?7", "73\n7?", "73\n?3", "73\n3?", "73\n?9", "73\n?2", "73\n70", "73\n1?", "73\n27", "73\n?1", "73\n49", "73\n72", "73\n59", "73\n?0", "73\n69...
p02327 Largest Rectangle
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s. Constraints * 1 ≤ H, W ≤ 1,400 Input H W c1,1 c1,2 ... c1,W c2,1 c2,2 ... c2,W : cH,1 cH,2 ... cH,W In the first line, two integers H and W separated by a space character are given. In the following...
{ "input": [], "output": [] }
{ "input": [ "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 1 0\n0 0 0 1 0" ], "output": [ "6" ] }
{ "input": [ "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "4 5\n0 0 1 0 0\n1 0 0 0 0\n0 0 0 0 1\n0 0 0 1 0", "1 5\n0 0 1 0 0\n1 0 0 0 1\n0 0 0 1 0\n0 0 0 1 0", "0 5\n0 0 1 -1 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0", "1 5\n1 0 1 0 1\n2 0 -1 0 1\n0 -1 0 0 0\n0 0 0 1 0", "4 5\n1 0 1 1 0\n1 0 0 ...
p02472 Addition of Big Integers
Addition of Big Integers Given two integers $A$ and $B$, compute the sum, $A + B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the sum in a line. Constraints * $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$ Sample Input 1 5 8 Sample Output 1 13 S...
{ "input": [], "output": [] }
{ "input": [ "5 8" ], "output": [ "13" ] }
{ "input": [ "9 8", "17 8", "17 12", "17 16", "21 16", "41 16", "58 16", "58 30", "109 30", "195 30", "302 30", "552 30", "47 30", "87 30", "87 37", "139 37", "139 39", "107 39", "107 73", "107 60", "107 79", "107 51", "8 51",...
bico
The much anticipated video game "BiCo Grid" has been released. The rules of "Bico Grid" are very simple. The game field is a 100x100 matrix, where each cell is either a blocked cell, or a cell with some number of coins. For a regular player the look of the field seems pretty random, but the programmer in you recognizes...
{ "input": [], "output": [] }
{ "input": [ "3\n3 2 5\n3 3 10\n5 4 7" ], "output": [ "2\n3 2 \n1\n10 \n3\n5 1 1" ] }
{ "input": [ "3\n3 2 5\n3 1 10\n5 4 7", "3\n4 2 5\n2 1 10\n5 2 7", "3\n3 2 5\n1 1 7\n5 4 7", "3\n3 2 8\n2 1 10\n5 4 7", "3\n3 2 4\n1 1 7\n5 4 7", "3\n3 2 11\n2 1 10\n5 4 7", "3\n3 2 5\n3 1 4\n5 4 7", "3\n4 2 5\n2 1 10\n5 4 9", "3\n3 2 8\n2 1 10\n5 4 5", "3\n3 2 4\n2 1 10\n5 4 7...
cng
In the country of Numberia, there is a city called Primeland. Sherry is one of the rich inhabitants of the city, who likes to collect coins of various denominations. Coins in primeland are little strange , they are only available in prime denominations (i.e as coins of value 2,3,5 etc.).Sherry is taking a tour of the c...
{ "input": [], "output": [] }
{ "input": [ "2\n3 5\n2 3" ], "output": [ "7\n1" ] }
{ "input": [ "2\n3 7\n2 3", "2\n3 7\n2 5", "2\n3 7\n0 5", "2\n3 7\n-1 5", "2\n3 7\n-1 7", "2\n2 7\n-1 7", "2\n2 6\n-1 7", "2\n0 6\n-1 7", "2\n0 12\n-1 7", "2\n0 2\n-1 7", "2\n-1 2\n-1 7", "2\n-2 2\n-1 7", "2\n-2 1\n-1 7", "2\n-2 0\n-1 7", "2\n-2 0\n-1 4", ...
frgtnlng
Forgotten languages (also known as extinct languages) are languages that are no longer in use. Such languages were, probably, widely used before and no one could have ever imagined that they will become extinct at some point. Unfortunately, that is what happened to them. On the happy side of things, a language may be d...
{ "input": [], "output": [] }
{ "input": [ "2\n3 2\npiygu ezyfo rzotm\n1 piygu\n6 tefwz tefwz piygu ezyfo tefwz piygu\n4 1\nkssdy tjzhy ljzym kegqz\n4 kegqz kegqz kegqz vxvyj" ], "output": [ "YES YES NO\nNO NO NO YES\n" ] }
{ "input": [ "2\n3 2\npiygu ezyfo rzotm\n1 piygu\n6 tefwz tefwz piygu ezyfo tefwz piygu\n4 1\nkssdy tjzhy ljzym kegqz\n4 kegqz kegqz kegqz vxvzj", "2\n3 2\npiygt ezyfo rzotm\n1 piygu\n6 tefwz tefwz piygu ezyfo tefwz phygu\n4 1\nkssdy tjzhy ljzym kegqz\n4 kegqz kegqz kegqz vxvzj", "2\n3 2\npiygu e{yfo rzot...
lowsum
The Head Chef is studying the motivation and satisfaction level of his chefs . The motivation and satisfaction of a Chef can be represented as an integer . The Head Chef wants to know the N th smallest sum of one satisfaction value and one motivation value for various values of N . The satisfaction and motivation v...
{ "input": [], "output": [] }
{ "input": [ "1\n3 1\n1 2 3\n4 5 6\n4" ], "output": [ "7" ] }
{ "input": [ "1\n3 1\n1 4 3\n4 5 6\n4", "1\n6 1\n1 4 3\n4 5 6\n1", "1\n6 1\n0 4 3\n4 5 6\n1", "1\n3 1\n1 2 1\n4 5 6\n4", "1\n10 1\n1 4 4\n4 2 12\n1", "1\n10 1\n1 4 4\n4 2 12\n0", "1\n10 1\n1 4 4\n4 2 13\n0", "1\n3 1\n1 4 3\n4 10 6\n4", "1\n6 1\n0 8 6\n2 5 6\n1", "1\n10 1\n1 4 4...
prime1
Shridhar wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers. Input The first line contains t, the number of test cases (less then or equal to 10). Followed by t lines which contain two numbers m and n (1 ≤ m ≤ n ≤ 1000000000, n-...
{ "input": [], "output": [] }
{ "input": [ "2\n1 10\n3 5" ], "output": [ "2\n3\n5\n7\n3\n5\n" ] }
{ "input": [ "2\n1 10\n4 5", "2\n1 10\n7 6", "2\n1 10\n3 7", "2\n1 5\n22 5", "2\n1 10\n1 7", "2\n1 10\n1 6", "2\n1 5\n1 7", "2\n1 6\n1 6", "2\n2 4\n1 9", "2\n4 10\n22 3", "2\n4 5\n22 4", "2\n1 8\n3 5", "2\n1 10\n6 11", "2\n1 4\n1 6", "2\n1 18\n28 3", "2\...
tapalin
Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish. For the given positive integer N, your ta...
{ "input": [], "output": [] }
{ "input": [ "5\n1\n2\n3\n4\n100" ], "output": [ "26\n52\n728\n1404\n508533804\n" ] }
{ "input": [ "5\n1\n3\n3\n4\n100", "5\n1\n2\n3\n4\n110", "5\n1\n2\n1\n4\n110", "5\n1\n4\n1\n4\n110", "5\n1\n2\n3\n4\n101", "5\n1\n3\n3\n4\n110", "5\n1\n2\n3\n4\n111", "5\n1\n2\n2\n4\n110", "5\n1\n4\n1\n4\n100", "5\n1\n2\n3\n5\n100", "5\n2\n3\n3\n4\n110", "5\n1\n2\n6\n4\...
1036_B. Diagonal Walking v.2
Mikhail walks on a Cartesian plane. He starts at the point (0, 0), and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0, 0), he can go to any of the following points in one move: * (1, 0); * (1, 1); * (0, 1); * (-1, 1); * (-1, 0); * (-1, -1);...
{ "input": [], "output": [] }
{ "input": [ "3\n2 2 3\n4 3 7\n10 1 9\n" ], "output": [ "1\n6\n-1\n" ] }
{ "input": [ "3\n2 2 3\n4 3 7\n7 1 9\n", "3\n2 2 3\n4 3 9\n7 1 9\n", "3\n2 2 3\n6 1 9\n7 1 1\n", "3\n2 1 3\n6 1 9\n7 0 2\n", "3\n2 0 3\n3 1 9\n13 0 2\n", "3\n4 0 3\n3 1 9\n13 0 2\n", "3\n7 0 0\n3 1 5\n22 0 2\n", "3\n1 0 0\n5 0 5\n22 0 2\n", "3\n1 0 1\n5 0 5\n22 0 2\n", "3\n1 0 ...
1290_A. Mind Control
You and your n - 1 friends have found an array of integers a_1, a_2, ..., a_n. You have decided to share it in the following way: All n of you stand in a line in a particular order. Each minute, the person at the front of the line chooses either the first or the last element of the array, removes it, and keeps it for h...
{ "input": [], "output": [] }
{ "input": [ "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 2 1\n2 2 0\n1 2\n" ], "output": [ "8\n4\n1\n1\n" ] }
{ "input": [ "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 1 1\n2 2 0\n1 2\n", "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n", "4\n6 3 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 2 3\n1 2 2 1\n2 2 0\n1 2\n", "4\n6 3 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 6\n4 2 1\n1 2 2 1\n2 2 0\n1 2\n...
661_D. Maximal Difference
You are given an array of integers ai. Find the largest absolute value of difference between adjacent elements of the array max(abs(ai - ai + 1)). Input The only line of the input contains a list of space-separated integers ai (1 ≤ ai ≤ 100) — elements of the array. The size of the array is between 2 and 10, inclusiv...
{ "input": [], "output": [] }
{ "input": [ "2 10 4 8 6 12\n", "3 3\n" ], "output": [ "8\n", "0\n" ] }
{ "input": [], "output": [] }
72_I. Goofy Numbers
The non-negative integer a is a divisor of the non-negative integer b if and only if there exists a positive integer c such that a × c = b. Some numbers are really interesting. Commander Surena defines some interesting properties for non-negative integers: * An integer is happy if it is divisible by at least one o...
{ "input": [], "output": [] }
{ "input": [ "99\n", "29994\n", "23\n" ], "output": [ "happier\n", "happy\n", "upset\n" ] }
{ "input": [], "output": [] }
diamonds-4
Roman loved diamonds. Monica decided to give him a beautiful gift on Valentine's Day. Her idea of diamonds was different though. She lit up all the windows of her rectangular building with N floors and M windows on each floor, with 2 shapes - / or \ . According to her, a diamond was made when such a shape was created: ...
{ "input": [], "output": [] }
{ "input": [ "1\n2 4\n/ \\ / \\\n\\ / \\ /\n\nSAMPLE" ], "output": [ "2\n" ] }
{ "input": [ "1\n2 4\n/ \\ / \\\n\\ / \\ /\n\nELPMAS", "1\n2 4\n/ \\ / \\\n\\ / ] /\n\nSAMPLE", "1\n2 4\n. \\ / \\\n\\ / ] /\n\nSAMPLE", "1\n2 2\n/ \\ / \\\n\\ / \\ /\n\nELPMAS", "1\n2 4\n/ \\ / [\n\\ / ] /\n\nSAMPLE", "1\n1 2\n/ \\ / \\\n\\ / \\ /\n\nELPMAS", "1\n2 4\n/ \\ / [\n\\ / ^ /\n...
geeky-alice-and-naughty-bob
One day Alice was experimenting with the numbers to make new algorithms. He introduce a new term Rsum. Rsum of any number is defined as number obtained by iterative summing of digits of the given number until single digit number is obtained. For example: 365 --> (3+6+5) = 14 14 --> 1+4 = 5 Rsum(365)=5 Naughty...
{ "input": [], "output": [] }
{ "input": [ "2\n1 3\n3 4\n\nSAMPLE" ], "output": [ "9\n12" ] }
{ "input": [ "2\n1 3\n3 4\n\nSAMPLF", "2\n1 3\n4 4\n\nSAMPLF", "2\n1 2\n3 4\n\nSAMPLE", "2\n0 3\n2 4\n\nSAMPLF", "2\n1 0\n3 4\n\nSAMPLE", "2\n0 3\n0 4\n\nSAMPLF", "2\n0 5\n0 4\n\nSAMPLF", "2\n1 0\n1 4\n\nSAMPME", "2\n0 1\n1 4\n\nSAMPLF", "2\n0 1\n2 4\n\nSAMPKF", "2\n0 -1\n1...
lazy-boy-off-to-class-i
All the students in NIT are very lazy. They want to have maximum time for rest. But due to college rules, they must maintain 75% attendance at the end of every week. Given the schedule of a week, tell them what is the maximum amount of time they might have for resting. NOTE: Each day has 24 hrs. i.e. 24x60x60 second...
{ "input": [], "output": [] }
{ "input": [ "1\n3 60 70 80 90 100 200\n3 50 70 100 120 150 200\n3 50 80 90 100 200 220\n3 80 100 110 115 200 210\n3 10 20 40 50 60 100\n3 10 50 60 80 90 100\n3 50 80 90 100 200 300\n\nSAMPLE" ], "output": [ "604555\n" ] }
{ "input": [ "1\n3 60 70 80 90 100 200\n3 50 70 100 120 150 200\n3 50 80 90 100 200 279\n3 80 100 110 115 200 210\n3 10 20 40 50 60 100\n3 10 50 60 80 90 100\n3 50 80 90 100 200 300\n\nSAMPLE", "1\n3 60 70 80 90 100 200\n3 50 70 100 120 150 200\n3 50 80 90 100 200 279\n3 80 100 110 115 200 210\n3 10 20 40 50 ...
roy-and-profile-picture
Roy wants to change his profile picture on Facebook. Now Facebook has some restriction over the dimension of picture that we can upload. Minimum dimension of the picture can be L x L, where L is the length of the side of square. Now Roy has N photos of various dimensions. Dimension of a photo is denoted as W x H wh...
{ "input": [], "output": [] }
{ "input": [ "180\n3\n640 480\n120 300\n180 180\n\nSAMPLE" ], "output": [ "CROP IT\nUPLOAD ANOTHER\nACCEPTED\n" ] }
{ "input": [ "180\n3\n640 480\n120 300\n180 180\n\nSAMELP", "180\n3\n640 908\n120 300\n297 180\n\nSAMELP", "180\n2\n640 908\n120 300\n297 180\n\nSAMELP", "180\n3\n717 340\n241 300\n180 180\n\nSAMELP", "180\n2\n972 69\n48 300\n361 180\n\nSALELP", "180\n1\n353 480\n120 300\n180 180\n\nSAMPLE", ...
valentine-shopping-4
As it is the Valentines month, Puchi's girlfriend asks him to take her shopping. He, being the average bloke, does not have a lot of money to spend. Hence, decides to buy each item from the shop that offers the best price on it. His girlfriend wants to buy N items. Each item is available on M shops . Being the Valenti...
{ "input": [], "output": [] }
{ "input": [ "2\n1 3\n20 20 50\n30 20 0\n60 50 0\n2 2\n20 20 20\n30 20 40\n10 100 90\n35 60 50\n\nSAMPLE" ], "output": [ "3\n2 1\n" ] }
{ "input": [ "2\n1 3\n20 20 50\n30 20 0\n60 50 0\n0 2\n20 20 20\n30 20 40\n10 100 90\n35 60 50\n\nSAMPLE", "2\n1 3\n20 20 50\n30 20 0\n60 4 0\n0 2\n20 20 20\n38 38 40\n10 100 90\n35 60 50\n\nSAMPLE", "2\n1 3\n20 20 50\n30 20 0\n60 4 0\n1 2\n20 20 20\n38 38 40\n10 100 90\n35 60 50\n\nSAMPLE", "2\n1 3\n...
p02603 M-SOLUTIONS Programming Contest 2020 - Road to Millionaire
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the n...
{ "input": [], "output": [] }
{ "input": [ "2\n157 193", "7\n100 130 130 130 115 115 150", "6\n200 180 160 140 120 100" ], "output": [ "1216", "1685", "1000" ] }
{ "input": [ "2\n157 145", "7\n100 130 243 130 115 115 150", "6\n200 237 160 140 120 100", "2\n157 218", "7\n100 130 243 130 115 115 271", "6\n200 237 160 233 120 100", "2\n103 218", "7\n110 130 243 130 115 115 271", "7\n110 130 136 130 115 115 271", "6\n200 237 119 233 121 100...
p02734 AtCoder Beginner Contest 159 - Knapsack for All Segments
Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{...
{ "input": [], "output": [] }
{ "input": [ "10 10\n3 1 4 1 5 9 2 6 5 3", "5 8\n9 9 9 9 9", "3 4\n2 2 4" ], "output": [ "152", "0", "5" ] }
{ "input": [ "10 10\n3 1 4 1 5 9 2 6 2 3", "3 4\n2 2 6", "10 10\n3 1 4 1 5 9 1 6 2 3", "3 4\n2 2 2", "6 10\n3 1 4 1 5 9 1 6 2 3", "3 4\n1 2 1", "3 4\n1 3 1", "10 10\n3 1 4 1 5 9 2 6 4 3", "5 8\n14 9 9 9 9", "10 10\n3 1 4 1 5 9 2 6 0 3", "10 10\n5 1 4 1 5 9 1 6 2 3", "6 ...
p02868 NIKKEI Programming Contest 2019-2 - Shortest Path on a Line
We have N points numbered 1 to N arranged in a line in this order. Takahashi decides to make an undirected graph, using these points as the vertices. In the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph. The i-th operation is as follows: * The operation uses integers L_i ...
{ "input": [], "output": [] }
{ "input": [ "4 3\n1 3 2\n2 4 3\n1 4 6", "10 7\n1 5 18\n3 4 8\n1 3 5\n4 7 10\n5 9 8\n6 10 5\n8 10 3", "4 2\n1 2 1\n3 4 2" ], "output": [ "5", "28", "-1" ] }
{ "input": [ "10 7\n1 5 18\n3 4 8\n1 3 5\n4 7 10\n5 9 8\n6 10 5\n8 10 5", "4 2\n1 2 2\n3 4 2", "10 7\n1 5 18\n3 4 8\n1 3 5\n4 7 10\n5 9 8\n6 10 5\n5 10 5", "10 7\n1 5 18\n3 4 8\n1 3 5\n4 7 10\n3 9 8\n6 10 5\n5 10 5", "10 7\n1 5 18\n3 4 13\n1 3 5\n4 7 10\n3 9 1\n6 10 5\n5 10 5", "4 2\n1 2 1\n1 ...
p03003 AtCoder Beginner Contest 130 - Common Subsequence
You are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive). In how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content? Here the subsequence of A is a sequence obtained by removing zero or ...
{ "input": [], "output": [] }
{ "input": [ "10 9\n9 6 5 7 5 9 8 5 6 7\n8 6 8 5 5 7 9 9 7", "20 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "4 4\n3 4 5 6\n3 4 5 6", "2 2\n1 1\n1 1", "2 2\n1 3\n3 1" ], "output": [ "191", "846527861", "16", "6", "3" ] }
{ "input": [ "10 9\n9 6 5 7 5 9 8 5 6 7\n8 5 8 5 5 7 9 9 7", "20 20\n1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "4 4\n0 4 5 6\n3 4 5 6", "2 2\n1 6\n3 1", "20 20\n1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "20 20\n1...
p03143 NIKKEI Programming Contest 2019 - Weights on Vertices and Edges
There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i. We would like to remove zero o...
{ "input": [], "output": [] }
{ "input": [ "10 9\n81 16 73 7 2 61 86 38 90 28\n6 8 725\n3 10 12\n1 4 558\n4 9 615\n5 6 942\n8 9 918\n2 7 720\n4 7 292\n7 10 414", "4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18", "6 10\n4 4 1 1 1 7\n3 5 19\n2 5 20\n4 5 8\n1 6 16\n2 3 9\n3 6 16\n3 4 1\n2 6 20\n2 4 19\n1 2 9" ], "output": [ "8", ...
{ "input": [ "4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 21\n3 4 18", "4 4\n2 3 1 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18", "4 4\n2 3 5 7\n1 4 7\n1 2 9\n1 3 15\n3 4 18", "6 10\n2 4 1 1 1 7\n3 5 19\n2 5 8\n4 5 5\n1 6 16\n2 5 9\n3 6 16\n3 4 1\n2 6 20\n1 4 19\n1 2 9", "6 10\n2 8 1 1 1 7\n3 5 19\n2 5 8\n4 5 5\n1 6 16\n2...
p03287 AtCoder Beginner Contest 105 - Candy Distribution
There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies. You will take out the candies from some consecutive boxes and distribute them evenly to M children. Such being the case, find the number of the pairs (l, r) that satisfy the following: * l and r are both integers...
{ "input": [], "output": [] }
{ "input": [ "10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "13 17\n29 7 5 7 9 51 7 13 8 55 42 9 81", "3 2\n4 1 5" ], "output": [ "25", "6", "3" ] }
{ "input": [ "10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000010 1000000000 1000000000", "13 17\n29 7 5 7 18 51 7 13 8 55 42 9 81", "10 400000000\n1000000000 1100000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000010 1000000000 100000000...
p03443 AtCoder Petrozavodsk Contest 001 - Colorful Doors
There is a bridge that connects the left and right banks of a river. There are 2 N doors placed at different positions on this bridge, painted in some colors. The colors of the doors are represented by integers from 1 through N. For each k (1 \leq k \leq N), there are exactly two doors painted in Color k. Snuke decide...
{ "input": [], "output": [] }
{ "input": [ "2\n010", "2\n001", "3\n10101", "6\n00111011100", "3\n10110" ], "output": [ "Yes\n1 1 2 2", "No", "No", "Yes\n1 6 1 2 3 4 4 2 3 5 6 5", "Yes\n1 3 2 1 2 3" ] }
{ "input": [ "2\n110", "2\n000", "2\n111", "3\n00100", "3\n01000", "3\n00000", "3\n11110", "3\n01111", "3\n11011", "6\n10101011010", "6\n10111011010", "3\n01010", "3\n10111", "3\n11101", "3\n00010", "6\n10011001010", "3\n01101", "6\n11011011010",...
p03603 AtCoder Regular Contest 083 - Bichrome Tree
We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i. To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight. Snuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to all...
{ "input": [], "output": [] }
{ "input": [ "3\n1 1\n4 3 2", "8\n1 1 1 3 4 5 5\n4 1 6 2 2 1 3 3", "1\n\n0", "3\n1 2\n1 2 3" ], "output": [ "POSSIBLE", "POSSIBLE", "POSSIBLE", "IMPOSSIBLE" ] }
{ "input": [ "3\n1 1\n6 3 2", "8\n1 2 2 3 4 5 5\n4 1 6 2 2 1 3 3", "8\n1 1 1 3 4 5 5\n6 1 6 2 2 1 3 3", "1\n\n1", "3\n1 1\n6 6 2", "1\n\n2", "3\n1 1\n3 6 2", "1\n\n3", "3\n1 1\n3 6 4", "8\n1 1 2 3 4 5 5\n4 1 6 2 2 1 3 3", "3\n1 1\n6 3 0", "8\n1 1 1 3 4 5 5\n5 1 6 2 2 1 ...
p03762 AtCoder Beginner Contest 058 - ###
On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i. For ever...
{ "input": [], "output": [] }
{ "input": [ "3 3\n1 3 4\n1 3 6", "6 5\n-790013317 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677" ], "output": [ "60", "835067060" ] }
{ "input": [ "6 5\n-983443749 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677", "6 5\n-983443749 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 1151847131", "6 5\n-244028396 -192321079 95834122 418379342 586...
p03932 square869120Contest #3 - Souvenirs
Input The input is given from standard input in the following format. > $H \ W$ $a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}$ $a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}$ $\vdots \ \ \ \ \ \ \ \ \ \ \vdots \ \ \ \ \ \ \ \ \ \ \vdots$ $a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}$ Output * Print the maximum number of souvenirs...
{ "input": [], "output": [] }
{ "input": [ "6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8", "3 3\n1 0 5\n2 2 3\n4 2 4" ], "output": [ "97", "21" ] }
{ "input": [ "6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 10 1 8 2 8", "3 3\n1 0 5\n1 2 3\n4 2 4", "6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n1 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 10 1 8 2 8", "3 3\n1 0 5\n1 2 3\n4 2 5", "6 6\n1 2 3 4 5 6\n8 8 9 0 2 0\n1 1 4 1 5 9\n2 6 5 3 5 8\...
p00025 Hit and Blow
Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers: * The number of numbers which have the same place with numbers A imagined (Hit) * The number of numbers included (but different place) in the numbers A imagined (Blow) For example, if A imagin...
{ "input": [], "output": [] }
{ "input": [ "9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 2" ], "output": [ "1 1\n3 0" ] }
{ "input": [ "9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 0", "9 1 8 2\n6 1 5 9\n4 6 8 2\n2 6 3 0", "9 1 8 2\n4 1 5 9\n2 6 8 2\n4 6 3 0", "9 1 8 2\n6 2 5 9\n4 6 8 2\n4 6 3 0", "9 1 8 2\n6 2 5 9\n4 6 8 2\n4 9 3 0", "9 1 8 2\n6 1 2 9\n4 6 13 2\n2 6 3 1", "9 1 8 2\n6 1 5 9\n8 6 13 2\n2 7 3 1", "9 1 ...
p00156 Moats around the Castle
Now, a ninja is planning to sneak into the castle tower from outside the castle. This ninja can easily run on the ground and swim in the moat, but he is not very good at climbing up from the moat, so he wants to enter the moat as few times as possible. Create a program that takes a sketch of the castle as input and ou...
{ "input": [], "output": [] }
{ "input": [ "5 5\n.###.\n#...#\n#.&.#\n#...#\n.###.\n18 15\n..####....####....\n####..####....####\n#...............##\n.#.############.##\n#..#..........#.##\n.#.#.########.#.##\n#..#.#......#.#.##\n.#.#....&...#.#.##\n#..#........#.#.##\n.#.#.########.#.##\n#..#..........#.##\n.#.############.##\n#...............
{ "input": [ "5 5\n.###.\n...#\n.&.#\n...#\n.###.\n18 15\n..####....####....\n..####....####\n...............##\n.#.############.##\n..#..........#.##\n.#.#.########.#.##\n##.#.#......#.#..\n.#.#....&...#.#.##\n..#........#.#.##\n.#.#.########.#.##\n..#..........#.##\n.#.############.##\n...............##\n.#####...
p00313 Secret Investigation
The secret organization AiZu AnalyticS has launched a top-secret investigation. There are N people targeted, with identification numbers from 1 to N. As an AZAS Information Strategy Investigator, you have decided to determine the number of people in your target who meet at least one of the following conditions: * Thos...
{ "input": [], "output": [] }
{ "input": [ "5\n3 1 2 3\n2 4 5\n2 3 4", "100\n3 1 100 4\n0\n2 2 3" ], "output": [ "1", "2" ] }
{ "input": [ "5\n3 1 2 3\n2 4 5\n2 2 4", "5\n3 1 2 1\n2 4 5\n2 3 4", "5\n3 1 2 3\n2 4 5\n2 3 2", "5\n3 1 4 3\n2 4 5\n2 3 4", "100\n3 1 100 4\n0\n2 4 3", "5\n3 2 4 3\n2 4 5\n2 3 4", "100\n3 0 100 4\n0\n2 4 3", "100\n3 0 000 4\n0\n2 4 3", "100\n3 1 100 4\n-1\n2 2 3", "5\n3 1 2 5\...
p00483 Planetary Exploration
After a long journey, the super-space-time immigrant ship carrying you finally discovered a planet that seems to be habitable. The planet, named JOI, is a harsh planet with three types of terrain, "Jungle," "Ocean," and "Ice," as the name implies. A simple survey created a map of the area around the planned residence. ...
{ "input": [], "output": [] }
{ "input": [ "4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n3 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7" ], "output": [ "1 3 2\n3 5 2\n0 1 0\n10 11 7" ] }
{ "input": [ "4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 7 4 7\n2 2 3 6\n2 2 2 2\n1 1 1 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO...
p00669 K Cards
One day, the teacher came up with the following game. The game uses n cards with one number from 1 to 10 and proceeds as follows. 1. The teacher pastes n cards on the blackboard in a horizontal row so that the numbers can be seen, and declares an integer k (k ≥ 1) to the students. For n cards arranged in a horizontal...
{ "input": [], "output": [] }
{ "input": [ "4 2\n2\n3\n7\n5\n0 0" ], "output": [ "0" ] }
{ "input": [ "4 2\n4\n3\n7\n5\n0 0", "4 2\n1\n6\n4\n5\n0 0", "4 2\n8\n3\n10\n5\n0 0", "4 2\n4\n3\n7\n1\n0 0", "4 2\n4\n1\n14\n3\n0 0", "4 2\n8\n3\n16\n5\n0 0", "4 2\n4\n3\n11\n1\n0 0", "4 2\n9\n5\n16\n5\n0 0", "4 2\n2\n2\n1\n5\n0 0", "4 2\n1\n6\n2\n5\n0 0", "4 2\n8\n3\n1\n5...
p00812 Equals are Equals
Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink. His hea...
{ "input": [], "output": [] }
{ "input": [ "a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\n2 b 2 a\n.\n108 a\n2 2 3 3 3 a\n4 a^1 27\n.\n." ], "output": [ "yes\nno\n.\nno\nyes\n.\nyes\nyes\n." ] }
{ "input": [ "a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\n2 b 2 a\n.\n169 a\n2 2 3 3 3 a\n4 a^1 27\n.\n.", "a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 3\n2 b 2 a\n.\n108 a\n2 2 3 3 3 a\n4 a^1 27\n.\n.", "a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) ...
p00943 Routing a Marathon Race
Example Input 6 6 3 1 9 4 3 6 1 2 1 4 2 6 5 4 6 5 3 2 Output 17
{ "input": [], "output": [] }
{ "input": [ "6 6\n3\n1\n9\n4\n3\n6\n1 2\n1 4\n2 6\n5 4\n6 5\n3 2" ], "output": [ "17" ] }
{ "input": [ "6 6\n3\n1\n7\n4\n3\n6\n1 2\n1 4\n2 6\n5 4\n6 5\n3 2", "6 6\n3\n1\n9\n7\n3\n6\n1 2\n1 4\n2 6\n5 4\n6 5\n3 2", "6 6\n3\n1\n9\n4\n2\n6\n1 2\n1 4\n2 6\n5 4\n6 5\n3 2", "6 6\n3\n1\n7\n4\n3\n6\n1 2\n1 4\n2 6\n5 5\n6 5\n3 2", "6 6\n3\n1\n7\n4\n2\n6\n1 2\n1 4\n2 6\n5 5\n6 5\n3 2", "6 6\n...
p01076 Graph Making
Problem There are n vertices that are not connected to any of the vertices. An undirected side is stretched between each vertex. Find out how many sides can be stretched when the diameter is set to d. The diameter represents the largest of the shortest distances between two vertices. Here, the shortest distance is the...
{ "input": [], "output": [] }
{ "input": [ "4 2", "5 1", "4 3" ], "output": [ "5", "10", "3" ] }
{ "input": [ "0 1", "4 5", "6 5", "0 2", "4 1", "-1 1", "6 9", "0 8", "8 1", "6 3", "0 9", "1 8", "11 1", "8 3", "0 12", "1 10", "19 1", "8 2", "0 6", "2 8", "9 1", "0 11", "-1 11", "1 11", "-2 11", "0 4", "-3 ...
p01210 Speed
Do you know Speed? It is one of popular card games, in which two players compete how quick they can move their cards to tables. To play Speed, two players sit face-to-face first. Each player has a deck and a tableau assigned for him, and between them are two tables to make a pile on, one in left and one in right. A ta...
{ "input": [], "output": [] }
{ "input": [ "1\nSA\n1\nC2\n2\nSA HA\n2\nC2 C3\n5\nS3 S5 S8 S9 S2\n3\nH7 H3 H4\n10\nH7 CJ C5 CA C6 S2 D8 DA S6 HK\n10\nC2 D6 D4 H5 DJ CX S8 S9 D3 D5\n0" ], "output": [ "A wins.\nB wins.\nB wins.\nA wins." ] }
{ "input": [ "1\nSA\n1\nC2\n2\nSA HA\n2\nC2 C3\n5\nS3 S5 S8 S9 S2\n3\nH7 H3 H4\n10\nH7 CJ C5 CA C6 S2 D8 DA S6 HK\n10\nC2 D6 D4 H5 DJ CX 8S S9 D3 D5\n0", "1\nSA\n1\nC2\n2\nSA HA\n2\nC2 C3\n5\nS3 S5 S8 S9 S2\n3\nH7 H4 H4\n10\nH7 CJ C5 CA C6 S2 D8 DA S6 HK\n10\nC2 D6 D4 H5 DJ CX 8S S9 D3 D5\n0", "1\nSA\n1\n...
p01346 Ropeway
On a small island, there are two towns Darkside and Sunnyside, with steep mountains between them. There’s a company Intertown Company of Package Conveyance; they own a ropeway car between Darkside and Sunnyside and are running a transportation business. They want maximize the revenue by loading as much package as possi...
{ "input": [], "output": [] }
{ "input": [ "3 3 2 1\n1 1 4", "3 3 2 1\n1 4 1" ], "output": [ "Yes", "No" ] }
{ "input": [ "3 3 2 1\n1 1 0", "3 6 1 1\n2 2 0", "3 6 2 1\n1 1 0", "3 6 2 1\n1 2 0", "3 6 2 1\n2 2 0", "3 6 1 1\n2 2 1", "3 4 1 1\n2 2 1", "3 4 2 1\n2 2 1", "3 3 2 2\n1 1 4", "3 3 2 0\n1 4 1", "3 3 2 0\n1 1 0", "3 6 2 2\n1 1 0", "3 6 1 1\n1 2 0", "3 6 1 1\n2 2 -...
p01516 Milky Way
Milky Way Milky Way English text is not available in this practice contest. The Milky Way Transportation Corporation is a travel agency that plans and manages interstellar travel tours. The Milky Way Transportation Corporation is planning a project called "Milky Way Crossing Orihime Hikoboshi Experience Tour". This ...
{ "input": [], "output": [] }
{ "input": [ "" ], "output": [ "" ] }
{ "input": [], "output": [] }
p01684 Venn Diagram
Problem Statement Alice is a private teacher. One of her job is to prepare the learning materials for her student. Now, as part of the materials, she is drawing a Venn diagram between two sets $A$ and $B$. Venn diagram is a diagram which illustrates the relationships among one or more sets. For example, a Venn diagra...
{ "input": [], "output": [] }
{ "input": [ "10 5 1 1 0\n10 5 2 2 1\n10 10 70 70 20\n0 0 0 0 0" ], "output": [ "1 1 0.564189584 3 1 0.564189584\n1 1 0.797884561 1.644647246 1 0.797884561\nimpossible" ] }
{ "input": [ "10 5 1 1 0\n10 5 2 2 1\n10 10 71 70 20\n0 0 0 0 0", "10 5 1 1 0\n10 8 2 2 1\n10 10 71 70 20\n0 0 0 0 0", "10 5 1 1 1\n10 8 2 2 1\n10 10 71 70 20\n0 0 0 0 0", "10 5 1 0 0\n10 5 2 2 1\n10 10 71 70 20\n0 0 0 0 0", "17 5 1 1 0\n10 8 2 2 1\n10 10 71 70 20\n0 0 0 0 0", "10 5 1 1 1\n10 ...
p01828 M and A
Example Input acmicpc tsukuba Output No
{ "input": [], "output": [] }
{ "input": [ "acmicpc\ntsukuba" ], "output": [ "No" ] }
{ "input": [ "acmicpc\nttukuba", "acmpcic\nttukuba", "acmpcid\nttukuba", "acmpcid\nttakubu", "acmqcid\nttakubu", "aciqcmd\nttakubu", "aciqcmd\ntt`kubu", "aciqcmd\ntu`ktbu", "dmcqica\ntu`ktbu", "dmcqica\ntu`jtbu", "dmcqica\nut`jtbu", "dmcqica\ntt`jtbu", "dmcqicb\ntt`...
p01963 Separate String
You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$. For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \\{a, ab, b\\}$. * $a,b,a,b$ * $a,b,ab$ * $ab,a,b$ * $ab,ab$ Your task is to count the n...
{ "input": [], "output": [] }
{ "input": [ "3\na\nb\nab\nabab", "3\na\nb\nc\nxyz", "10\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaaaaaa\naaaaaaaa\naaaaaaaaa\naaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "7\nabc\nab\nbc\na\nb\nc\naa\naaabcbccababbc" ], "output": [ "4", "0", "461695029", "160" ] }
{ "input": [ "3\na\nb\nba\nabab", "3\na\nb\nc\nxy{", "10\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaaaaaa\na`aaaaaa\naaaaaaaaa\naaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "10\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaaaaaa\na`aaaaaa\naaaaaaaaa\naaaaaabaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ...
p02110 Settler
Problem There are N vacant lots on the two-dimensional plane. Numbers from 1 to N are assigned to each vacant lot. Every vacant lot is so small that it can be considered a point. The i-th vacant lot exists at (xi, yi). Taro chose just K from these N vacant lots and decided to build a building in those vacant lots. Ho...
{ "input": [], "output": [] }
{ "input": [ "4 3\n2 1\n1 2\n1 3\n2 4", "5 3\n5 7\n5 6\n6 8\n20 20\n4 8", "3 2\n2 1\n1 2\n1 3" ], "output": [ "-1", "2\n3\n4", "1\n3" ] }
{ "input": [ "3 3\n2 1\n1 2\n1 3\n2 4", "5 3\n2 7\n5 6\n6 8\n20 20\n4 8", "3 2\n0 1\n1 2\n1 3", "3 2\n0 1\n2 2\n1 3", "5 3\n5 7\n5 6\n6 8\n20 24\n4 8", "5 1\n0 5\n5 6\n6 8\n20 20\n4 8", "5 3\n5 7\n5 6\n6 8\n20 24\n0 8", "5 2\n5 7\n5 6\n6 8\n20 24\n0 8", "5 3\n2 7\n5 9\n6 8\n18 20\n...
p02250 Multiple String Matching
Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i. Constraints * 1 ≤ length of T ≤ 1000000 * 1 ≤ length of P_i ≤ 1000 * 1 ≤ Q ≤ 10000 * The input consists of alphabetical characters and digits Input In the first line, a text T is given. In the second lin...
{ "input": [], "output": [] }
{ "input": [ "aabaaa\n4\naa\nba\nbb\nxyz" ], "output": [ "1\n1\n0\n0" ] }
{ "input": [ "aabaaa\n4\nab\nba\nbb\nxyz", "aabaaa\n4\nab\nba\nba\nxyz", "aabaaa\n4\nba\nbb\nac\nzyx", "aabaaa\n4\nca\nab\nba\nzyx", "aacaaa\n4\nba\nb`\nac\nzyx", "aacaaa\n4\nca\nb`\nac\nzyx", "aabaaa\n4\na`\nab\nca\nyzx", "aadaaa\n4\nca\nb`\nca\nzyx", "aabaaa\n4\nab\nab\nba\nxyz",...
p02398 How Many Divisors?
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b. Constraints * 1 ≤ a, b, c ≤ 10000 * a ≤ b Input Three integers a, b and c are given in a line separated by a single space. Output Print the number of divisors in a line. Example Inp...
{ "input": [], "output": [] }
{ "input": [ "5 14 80" ], "output": [ "3" ] }
{ "input": [ "7 14 80", "7 4 80", "1 1 80", "9 22 80", "5 20 80", "7 25 80", "1 23 80", "2 23 80", "4 32 80", "4 32 120", "6 18 0", "4 17 0", "3 26 0", "4 30 0", "2 26 0", "7 6 80", "7 1 80", "5 14 149", "13 14 80", "9 4 80", "7 8 80"...
cb03
The problem is very simple. For every string given as input, you need to tell us the number of subsequences of it that are palindromes (need not necessarily be distinct). Note that the empty string is not a palindrome. For example, the palindromic subsequences of "aab" are: "a", "a", "b", "aa", and the method returns...
{ "input": [], "output": [] }
{ "input": [ "3\naab\ndddd\nthisisapalindromeemordnilapasisiht" ], "output": [ "4\n15\n814157" ] }
{ "input": [], "output": [] }
crypt05
Problem Statement A Mathematics professor walked into her class. She wanted to test her students’ abilities and hence, gave them a series: 1,1,2,3,5,8…. And asked them to predict the number at a given position. Write a program to do exactly that. Your task is to take numbers as input (one per line), and print the corr...
{ "input": [], "output": [] }
{ "input": [ "5\n99\n0" ], "output": [ "5\n218922995834555169026" ] }
{ "input": [ "5\n92\n0", "5\n55\n0", "5\n30\n0", "5\n42\n0", "5\n49\n0", "5\n27\n0", "5\n9\n0", "5\n10\n0", "5\n130\n0", "5\n151\n0", "5\n14\n0", "5\n68\n0", "5\n89\n0", "5\n22\n0", "5\n4\n0", "5\n17\n0", "5\n212\n0", "5\n18\n0", "5\n129\n0",...
guess
Alice and Bob, both have to drink water. But they both don't want to go, so they will play a game to decide who will fetch water for both of them. Alice will choose a number randomly between 1 and N (both inclusive) and Bob will choose a number randomly between 1 and M (both inclusive). Both will write their numbers on...
{ "input": [], "output": [] }
{ "input": [ "3\n1 1\n1 2\n2 3" ], "output": [ "0/1\n1/2\n1/2\n" ] }
{ "input": [ "3\n1 1\n1 3\n2 3", "3\n1 2\n1 3\n2 3", "3\n1 1\n1 1\n2 3", "3\n1 1\n2 1\n2 3", "3\n1 3\n1 3\n2 2", "3\n1 1\n2 1\n1 3", "3\n1 2\n2 1\n2 3", "3\n1 3\n1 6\n2 2", "3\n1 1\n1 1\n1 3", "3\n1 1\n1 6\n3 3", "3\n2 6\n1 5\n5 2", "3\n1 2\n2 1\n1 3", "3\n1 5\n1 3\...
mes
Problem description One of the Engineer friends of John, Mr. Dev tried to develop an encryption algorithm which can send strings of words wirelessly between two devices connected through Wi-Fi. On completing the design of algorithm, John decides to test his algorithm on real devices. To test his algorithm on device, De...
{ "input": [], "output": [] }
{ "input": [ "2\nHe is a good programmer\nhp is a pool Probgrammer\nProgram\nprpgreamp" ], "output": [ "4\n3" ] }
{ "input": [], "output": [] }
reciicha
Help Saurabh with his Chemistry Assignment. Saurabh has been given a chemistry assignment by Ruby Mam. Though the assignment is simple but Saurabh has to watch India vs Pakistan Match and he has no time to do the assignment by himself. So Saurabh wants you to do his assignment so that he doesn’t get scolded by Ruby Mam...
{ "input": [], "output": [] }
{ "input": [ "2\n1 2\n2 1" ], "output": [ "2\n2" ] }
{ "input": [], "output": [] }
traveler
Chef likes to travel very much. He plans some travel routes and wants to know their lengths. He hired you to make these calculations. But be careful, some of the routes are incorrect. There may be some misspelling in city names or there will be no road between some two consecutive cities in the route. Also note that Ch...
{ "input": [], "output": [] }
{ "input": [ "5\nDonetsk Kiev New-York Miami Hollywood\n9\nDonetsk Kiev 560\nKiev New-York 7507\nNew-York Miami 1764\nMiami Hollywood 28\nHollywood Miami 30\nMiami New-York 1764\nKiev Donetsk 550\nHollywood New-York 1736\nNew-York Hollywood 1738\n13\n5 Donetsk Kiev New-York Miami Hollywood\n5 Hollywood Miami New-...
{ "input": [ "5\nDonetsk Kiev New-York Miami Hollywood\n9\nDonetsk Kiev 560\nKiev New-York 7507\nNew-York Miami 1764\nMiami Hollywood 28\nHollywood Miami 30\nMiami New-York 1764\nKiev Donetsk 550\nHollywood New-York 1736\nNew-York Hollywood 1738\n13\n5 Donetsk Kiev New-York Miami Hollywood\n5 Hlolywood Miami New-...
1251_E1. Voting (Easy Version)
The only difference between easy and hard versions is constraints. Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you. There are n voters, and two ways to convince each of them to vote for you. The first way to convince the i-th voter is to pay him p_i coins....
{ "input": [], "output": [] }
{ "input": [ "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n" ], "output": [ "8\n0\n7\n" ] }
{ "input": [ "3\n3\n1 5\n2 10\n2 4\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n1 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5\n", "3\n3\n1 5\n2 10\n2 8\n7\n0 1\n1 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 0\n2 8\n2 7\n4 4\n5 5\n", ...
1294_D. MEX maximizing
Recall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples: * for the array [0, 0, 1, 0, 2] MEX equals to 3 because numbers 0, 1 and 2 are presented in the array and 3 is the minimum non-negative integer not presented in the array; * for the array [1, 2, 3, 4] MEX eq...
{ "input": [], "output": [] }
{ "input": [ "4 3\n1\n2\n1\n2\n", "7 3\n0\n1\n2\n2\n0\n0\n10\n" ], "output": [ "0\n0\n0\n0\n", "1\n2\n3\n3\n4\n4\n7\n" ] }
{ "input": [ "4 3\n1\n2\n1\n3\n", "3 3\n0\n1\n2\n2\n0\n0\n10\n", "4 2\n1\n2\n1\n0\n", "4 2\n1\n3\n1\n0\n", "4 2\n1\n3\n2\n0\n", "4 2\n0\n3\n2\n0\n", "3 2\n0\n6\n2\n0\n", "2 3\n0\n0\n3\n-1\n", "3 3\n0\n0\n1\n-2\n", "3 3\n1\n0\n1\n-2\n", "1 3\n1\n0\n1\n1\n", "1 5\n0\n0\n1...
1468_J. Road Reform
There are n cities and m bidirectional roads in Berland. The i-th road connects the cities x_i and y_i, and has the speed limit s_i. The road network allows everyone to get from any city to any other city. The Berland Transport Ministry is planning a road reform. First of all, maintaining all m roads is too costly, ...
{ "input": [], "output": [] }
{ "input": [ "4\n4 5 7\n4 1 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 2\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2 17\n3 1 15\n2 3 10\n1 4 14\n2 5 8\n" ], "output": [ "\n1\n3\n0\n0\n" ] }
{ "input": [ "4\n4 5 7\n4 2 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 2\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2 17\n3 1 15\n2 3 10\n1 4 14\n2 5 8\n", "4\n4 5 7\n4 2 3\n1 2 5\n2 3 8\n2 4 1\n3 4 4\n4 6 5\n1 2 1\n1 3 1\n1 4 4\n2 4 1\n4 3 1\n3 2 1\n3 2 10\n1 2 8\n1 3 10\n5 5 15\n1 2...
1543_B. Customising the Track
Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of them. The track which passes through this highway can be divided into n sub-tracks. You are given an array a where a_i represents the number of traffic cars in the i-th sub-track. You def...
{ "input": [], "output": [] }
{ "input": [ "3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 5 2 1 7 10 4\n" ], "output": [ "0\n4\n21\n" ] }
{ "input": [ "3\n3\n1 2 3\n4\n0 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 2 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 7 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 1 3 10 4\n", "3\n3\n1 1 3\n4\n1 1 1 0\n10\n8 3 6 11 4 2 2 5 10 4\n", "...
312_D. Cats Transport
Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straight road across the farm and n hills along the road, numbered from 1 to n from left to right. The distance between hill i and (i - 1) is di meters. The feeders live in hill 1. One day, the cats went out to play. Cat i went o...
{ "input": [], "output": [] }
{ "input": [ "4 6 2\n1 3 5\n1 0\n2 1\n4 9\n1 10\n2 10\n3 12\n" ], "output": [ "3\n" ] }
{ "input": [ "4 6 2\n1 3 5\n1 0\n2 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 1\n1 0\n2 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 2\n1 0\n2 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 5\n1 0\n4 1\n4 4\n1 10\n2 10\n3 12\n", "4 6 2\n1 3 1\n1 0\n2 1\n4 4\n1 17\n2 10\n3 12\n", "4 6 2\n1 3 5\n1 0\n4 2\n4...
primestring
Alice has just learnt about primeStrings. A string is a primeString if the number of distinct alphabets used in the string is a prime and also the number of occurrences of each alphabet in the string is also a prime. Given a String you need to tell if it is a primeString or not. Input: First line contains T which is t...
{ "input": [], "output": [] }
{ "input": [ "3\nababb\nabcab\naabbccdd\n\nSAMPLE" ], "output": [ "YES\nNO\nNO\n" ] }
{ "input": [ "3\nababb\nabcab\naabbccdd\n\nS@MPLE", "3\nababc\nabcab\nddccbbaa\n\nS@MPLE", "3\nababc\nbabba\ndcdcbbaa\n\nS@MPLE", "3\naabbb\nbabba\naabbccdd\n\nEAMOSL", "3\nbbaba\nabcbc\nccbcbbaa\n\nSM>OLD", "3\ncbaac\nbacab\nacaccadd\n\nELPM@S", "3\nababb\nabcab\nddccbbaa\n\nS@MPLE", ...
saxie-and-strings
Saxie is a programming enthusiast. He has always been amazed by the beauty of strings. He always dreams of going to Byteland and playing with strings. One day he had a nightmare that Dr. Evil had attacked the strings. When he came forward to protect the strings, Dr. Evil asked him if every substring of S has its revers...
{ "input": [], "output": [] }
{ "input": [ "2\naba\nax\n\nSAMPLE" ], "output": [ "YES\nNO\n" ] }
{ "input": [ "2\naba\nxa\n\nSAMPLE", "2\naab\n`x\n\nTAMPLE", "2\naba\nx`\n\nSAMPLE", "2\naba\n`x\n\nSAMPLE", "2\naba\n`x\n\nTAMPLE", "2\naab\nx`\n\nTAMPLE", "2\nbaa\nx`\n\nTAMPLE", "2\naab\nxa\n\nTAMPLE", "2\nbaa\nxa\n\nTAMPLE", "2\nbaa\nxa\n\nTMAPLE", "2\nbaa\nxb\n\nTMAPLE...
who-will-survive-in-the-end
Ali baba did a trick on the forty thieves and was able to trap them inside a big cave which was the home of wild wolves. The thieves are without any weapons, only the chief of the thieves has knife. With no weapons they will not be able to fight with the wolves, so they decide to kill themselves rather than being eate...
{ "input": [], "output": [] }
{ "input": [ "4\n5\n11\n45\n23987443\n\nSAMPLE" ], "output": [ "3\n7\n27\n14420455\n" ] }
{ "input": [ "4\n5\n11\n45\n28960650\n\nSAMPLE", "4\n5\n11\n45\n19738501\n\nSAMPLE", "4\n5\n6\n45\n19738501\n\nSAMPLE", "4\n5\n6\n73\n19738501\n\nRALPME", "4\n5\n6\n73\n28777926\n\nRALPME", "4\n7\n6\n73\n28777926\n\nEMPLAR", "4\n7\n6\n88\n28777926\n\nEMPLAR", "4\n7\n6\n88\n10757916\n\n...
p02630 AtCoder Beginner Contest 171 - Replacing
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}. You will now successively do the following Q operations: * In the i-th operation, you replace every element whose value is B_{i} with C_{i}. For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th...
{ "input": [], "output": [] }
{ "input": [ "2\n1 2\n3\n1 100\n2 100\n100 1000", "4\n1 2 3 4\n3\n1 2\n3 4\n2 4", "4\n1 1 1 1\n3\n1 2\n2 1\n3 5" ], "output": [ "102\n200\n2000", "11\n12\n16", "8\n4\n4" ] }
{ "input": [ "4\n1 2 3 3\n3\n1 2\n3 4\n2 4", "4\n2 1 1 1\n3\n1 2\n2 1\n3 5", "4\n1 2 3 3\n3\n1 2\n3 4\n0 4", "4\n0 1 1 1\n3\n1 2\n2 1\n3 5", "4\n1 3 3 3\n3\n1 2\n3 4\n0 4", "4\n1 3 4 3\n3\n1 2\n3 4\n0 4", "4\n0 1 1 1\n3\n1 4\n2 1\n5 10", "4\n0 2 4 3\n3\n1 2\n3 4\n0 4", "4\n0 1 1 1\...
p02761 AtCoder Beginner Contest 157 - Guess The Number
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`. * The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) * The s_i-th digit from the left is c_i. \left(i ...
{ "input": [], "output": [] }
{ "input": [ "3 1\n1 0", "3 3\n1 7\n3 2\n1 7", "3 2\n2 1\n2 3" ], "output": [ "-1", "702", "-1" ] }
{ "input": [ "3 3\n1 14\n3 2\n1 7", "3 0\n2 1\n2 3", "3 1\n2 1\n1 3", "3 1\n0 1\n1 0", "3 3\n1 7\n3 4\n1 7", "3 2\n2 0\n1 3", "3 3\n0 2\n3 2\n1 1", "3 2\n3 0\n2 6", "1 1\n0 1\n1 0", "2 1\n0 1\n1 0", "2 0\n0 0\n2 3", "3 3\n2 7\n3 2\n1 1", "3 2\n2 0\n3 6", "3 1\n2...
p02896 AtCoder Grand Contest 039 - Min Product Sum
For each of the K^{NM} ways to write an integer between 1 and K (inclusive) in every square in a square grid with N rows and M columns, find the value defined below, then compute the sum of all those K^{NM} values, modulo D. * For each of the NM squares, find the minimum among the N+M-1 integers written in the square'...
{ "input": [], "output": [] }
{ "input": [ "2 3 4 998244353", "31 41 59 998244353", "2 2 2 998244353" ], "output": [ "127090", "827794103", "35" ] }
{ "input": [ "2 3 2 998244353", "31 27 59 998244353", "2 5 2 998244353", "36 27 59 998244353", "2 5 3 998244353", "36 48 59 998244353", "1 5 3 998244353", "36 48 23 998244353", "1 4 3 998244353", "36 83 23 998244353", "34 83 23 998244353", "14 83 23 998244353", "14 ...
p03031 AtCoder Beginner Contest 128 - Switches
We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M. Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2. How ...
{ "input": [], "output": [] }
{ "input": [ "2 2\n2 1 2\n1 2\n0 1", "5 2\n3 1 2 5\n2 2 3\n1 0", "2 3\n2 1 2\n1 1\n1 2\n0 0 1" ], "output": [ "1", "8", "0" ] }
{ "input": [ "2 2\n2 1 2\n1 2\n0 0", "4 2\n2 1 2\n1 2\n0 1", "5 2\n1 1 2 5\n2 2 3\n1 0", "2 3\n2 1 2\n1 1\n1 2\n0 0 -1", "4 0\n1 1 2\n1 2\n0 1", "1 0\n0 1 4\n1 1\n0 1\n0 0 -1", "9 2\n3 1 2 5\n2 2 3\n1 0", "7 2\n2 1 2\n1 1\n0 1", "8 0\n2 1 2\n1 1\n1 2\n0 0 -1", "6 0\n-4 0 2\n-1 ...
p03172 Educational DP Contest - Candies
There are N children, numbered 1, 2, \ldots, N. They have decided to share K candies among themselves. Here, for each i (1 \leq i \leq N), Child i must receive between 0 and a_i candies (inclusive). Also, no candies should be left over. Find the number of ways for them to share candies, modulo 10^9 + 7. Here, two way...
{ "input": [], "output": [] }
{ "input": [ "2 0\n0 0", "1 10\n9", "4 100000\n100000 100000 100000 100000", "3 4\n1 2 3" ], "output": [ "1", "0", "665683269", "5" ] }
{ "input": [ "1 10\n17", "4 100000\n101000 100000 100000 100000", "1 10\n3", "4 101000\n101000 100000 100100 101000", "4 110000\n101000 100000 100000 100000", "4 100100\n101000 100000 100100 101000", "4 001000\n101000 100000 100100 101000", "4 110000\n101100 100000 100000 100000", ...
p03318 AtCoder Beginner Contest 101 - Snuke Numbers
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds. Given an integer K, list the K smallest Snuke numbers. Constraints * 1 \leq K...
{ "input": [], "output": [] }
{ "input": [ "10" ], "output": [ "1\n2\n3\n4\n5\n6\n7\n8\n9\n19" ] }
{ "input": [ "18", "7", "5", "8", "2", "6", "15", "4", "1", "11", "17", "3", "12", "9", "13", "20", "16", "14", "23", "29", "22", "35", "25", "26", "28", "41", "37", "31", "19", "21", "44", ...
p03474 AtCoder Beginner Contest 084 - Postal Code
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom. Constraints * 1≤A,B≤5 * |S|=A+B+1 * S consists of `-` and di...
{ "input": [], "output": [] }
{ "input": [ "1 2\n7444", "3 4\n269-6650", "1 1\n---" ], "output": [ "No", "Yes", "No" ] }
{ "input": [ "2 2\n7444", "6 4\n269-6650", "1 2\n---", "0 2\n7444", "6 8\n269-6650", "1 0\n---", "0 2\n5343", "6 1\n269-6650", "1 0\n-,-", "0 1\n5343", "6 2\n269-6650", "1 0\n-+-", "-1 1\n5343", "6 2\n0566-962", "1 -1\n-+-", "-1 1\n10506", "6 3\n0566...
p03637 AtCoder Beginner Contest 069 - 4-adjacent
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. ...
{ "input": [], "output": [] }
{ "input": [ "6\n2 7 1 8 2 8", "3\n1 4 1", "3\n1 10 100", "2\n1 1", "4\n1 2 3 4" ], "output": [ "Yes", "Yes", "Yes", "No", "No" ] }
{ "input": [ "6\n2 7 2 8 2 8", "3\n-1 1 1", "3\n0 4 1", "3\n2 10 100", "4\n2 2 3 4", "6\n4 7 2 8 2 8", "3\n0 1 1", "3\n0 10 100", "4\n0 2 3 4", "6\n6 7 2 8 2 8", "3\n0 11 100", "4\n0 2 3 7", "6\n6 7 0 8 2 8", "3\n-1 1 0", "3\n0 11 101", "6\n6 7 0 8 2 5",...
p03794 Mujin Programming Challenge 2017 - Oriented Tree
There is a tree T with N vertices, numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i. Snuke is constructing a directed graph T' by arbitrarily assigning direction to each edge in T. (There are 2^{N - 1} different ways to construct T'.) For a fixed T', we will define d(s,\ t) fo...
{ "input": [], "output": [] }
{ "input": [ "4\n1 2\n2 3\n3 4", "10\n2 4\n2 5\n8 3\n10 7\n1 6\n2 8\n9 5\n8 6\n10 6", "4\n1 2\n1 3\n1 4", "6\n1 2\n1 3\n1 4\n2 5\n2 6" ], "output": [ "6", "102", "2", "14" ] }
{ "input": [ "10\n2 4\n2 5\n1 3\n10 7\n1 6\n2 8\n9 5\n8 6\n10 6", "4\n1 2\n1 3\n2 4", "10\n2 4\n2 5\n1 3\n3 7\n1 6\n2 8\n9 5\n8 6\n10 6", "10\n2 4\n2 5\n8 3\n10 7\n1 6\n2 8\n9 7\n8 6\n10 6", "10\n2 4\n2 5\n1 3\n10 7\n1 6\n2 8\n9 5\n8 6\n10 2", "10\n2 4\n2 5\n8 3\n10 7\n1 6\n2 8\n9 5\n8 6\n10 5...
p03963 AtCoder Beginner Contest 046 - Painting Balls with AtCoDeer
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls. Constraints * 1≦N≦1000 * 2≦K≦1000 * The correct answer i...
{ "input": [], "output": [] }
{ "input": [ "2 2", "1 10" ], "output": [ "2", "10" ] }
{ "input": [ "1 2", "1 1", "1 4", "1 8", "0 8", "0 13", "0 7", "0 12", "1 12", "1 3", "0 3", "0 0", "0 -1", "1 -1", "1 0", "-1 -1", "-2 -1", "-3 -1", "-3 0", "1 -2", "2 3", "0 -2", "0 4", "2 8", "0 5", "0 9", "...
p00054 Sum of Nth decimal places
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n. s = f (1) + f (2) + ... + f (n) Create a program that reads a, b, n, outputs s, and exits. Input The input consists of multiple dataset...
{ "input": [], "output": [] }
{ "input": [ "1 2 3\n2 3 4\n5 4 3\n4 3 2" ], "output": [ "5\n24\n7\n6" ] }
{ "input": [ "1 2 1\n2 3 4\n5 4 3\n4 3 2", "1 2 1\n2 3 4\n5 4 3\n7 4 2", "1 2 1\n2 3 2\n5 4 3\n7 3 2", "1 2 1\n2 3 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 2", "1 2 1\n2 4 3\n5 4 3\n7 3 1", "1 2 1\n2 4 3\n5 1 3\n7 3 1", "2 2 1\n2 4 3\n5 1 3\n7 3 1", "2 1 1\n2 4 2\n5 1 3\n8 3 1",...
p00184 Tsuruga Castle
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai. <image> We decided to conduct...
{ "input": [], "output": [] }
{ "input": [ "8\n71\n34\n65\n11\n41\n39\n6\n5\n4\n67\n81\n78\n65\n0" ], "output": [ "2\n1\n0\n2\n1\n0\n2\n0\n0\n0\n0\n0\n0\n4" ] }
{ "input": [ "8\n71\n34\n65\n11\n41\n39\n3\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n12\n39\n6\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n0\n41\n39\n3\n5\n4\n67\n81\n78\n65\n0", "8\n71\n34\n65\n11\n12\n39\n6\n5\n4\n16\n81\n78\n65\n0", "8\n71\n34\n65\n0\n41\n39\n3\n5\n4\n67\n81\n78\n21\n0", ...
p00340 Rectangle
The educational program (AHK Education) of the Aiz Broadcasting Association broadcasts a handicraft program for children, "Play with Tsukuro". Today is the time to make a rectangle with sticks, but I would like to see if I can make a rectangle using the four sticks I prepared. However, the stick must not be cut or brok...
{ "input": [], "output": [] }
{ "input": [ "1 1 2 2", "4 4 4 10", "2 1 1 2", "1 1 3 4" ], "output": [ "yes", "no", "yes", "no" ] }
{ "input": [ "0 1 2 2", "0 0 2 2", "0 4 4 10", "2 0 1 2", "1 1 0 4", "-1 1 2 2", "1 4 4 10", "2 0 2 2", "1 1 0 6", "-1 4 4 10", "2 0 2 4", "0 1 0 6", "-1 0 2 2", "-1 1 4 10", "2 0 3 4", "0 1 1 6", "-1 0 3 2", "-2 1 4 10", "2 0 3 2", "0 0 ...
p00534 Silk Road
problem In the area where Kazakhstan is now located, there used to be a trade route called the "Silk Road". There are N + 1 cities on the Silk Road, numbered from west as city 0, city 1, ..., city N. The distance between city i -1 and city i (1 ≤ i ≤ N) is Di. JOI, a trader, decided to start from city 0, go through ...
{ "input": [], "output": [] }
{ "input": [ "3 5\n10\n25\n15\n50\n30\n15\n40\n30" ], "output": [ "1125" ] }
{ "input": [ "3 5\n10\n25\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n7\n50\n30\n6\n40\n30", "1 5\n10\n38\n7\n50\n30\n6\n40\n30", "3 5\n10\n25\n15\n50\n30\n15\n12\n30", "3 5\n1\n25\n15\n50\n30\n6\n40\n30", "3 5\n10\n38\n18\n50\n30\n6\n40\n30", "3 5\n10\...
p00698 Missing Numbers
Toshizo is the manager of a convenience store chain in Hakodate. Every day, each of the stores in his chain sends him a table of the products that they have sold. Toshizo's job is to compile these figures and calculate how much the stores have sold in total. The type of a table that is sent to Toshizo by the stores lo...
{ "input": [], "output": [] }
{ "input": [ "3 3\n? ? 70 105\n? 50 ? 150\n30 60 90 180\n45 150 240 435\n\n2 2\n? ? 40\n? ? 40\n40 40 80\n\n2 3\n? 30 40 90\n50 60 70 180\n70 90 110 270\n\n0" ], "output": [ "-5\n40\n20\n80\n\nNO\n\n20" ] }
{ "input": [ "3 3\n? ? 70 105\n? 50 ? 150\n30 60 90 180\n45 150 240 435\n\n2 2\n? ? 40\n? ? 40\n40 40 80\n\n2 3\n? 30 40 90\n50 100 70 180\n70 90 110 270\n\n0", "3 3\n? ? 70 105\n? 21 ? 150\n30 60 90 180\n45 150 240 435\n\n2 2\n? ? 40\n? ? 40\n40 40 80\n\n2 3\n? 30 40 90\n50 100 108 180\n70 90 110 270\n\n0", ...
p00839 Organize Your Train
In the good old Hachioji railroad station located in the west of Tokyo, there are several parking lines, and lots of freight trains come and go every day. All freight trains travel at night, so these trains containing various types of cars are settled in your parking lines early in the morning. Then, during the daytim...
{ "input": [], "output": [] }
{ "input": [ "3 5\n0W 1W\n0W 2W\n0W 2E\n0E 1E\n1E 2E\naabbccdee\n-\n-\n-\n-\nbbaadeecc\n3 3\n0E 1W\n1E 2W\n2E 0W\naabb\nbbcc\naa\nbbbb\ncc\naaaa\n3 4\n0E 1W\n0E 2E\n1E 2W\n2E 0W\nababab\n-\n-\naaabbb\n-\n-\n0 0" ], "output": [ "4\n2\n5" ] }
{ "input": [ "3 5\n0W 1W\n0W 2W\n0W 2E\n0E 1E\n1E 2E\naabbcdcee\n-\n-\n-\n-\nbbaadeecc\n3 3\n0E 1W\n1E 2W\n2E 0W\naabb\nbbcc\naa\nbbbb\ncc\naaaa\n3 4\n0E 1W\n0E 2E\n1E 2W\n2E 0W\nababab\n-\n-\naaabbb\n-\n-\n0 0", "3 5\n0W 1W\n0W 2W\n0W 2E\n0E 1E\n1E 2E\naabbccdee\n-\n-\n-\n-\nbbaadeecc\n3 3\n0E 1W\n0E 2W\n2E ...
p00971 Shortest Common Non-Subsequence
Shortest Common Non-Subsequence A subsequence of a sequence $P$ is a sequence that can be derived from the original sequence $P$ by picking up some or no elements of $P$ preserving the order. For example, "ICPC" is a subsequence of "MICROPROCESSOR". A common subsequence of two sequences is a subsequence of both seque...
{ "input": [], "output": [] }
{ "input": [ "0101\n1100001" ], "output": [ "0010" ] }
{ "input": [ "0101\n1101001", "0101\n1100000", "0101\n1101000", "0101\n0001000", "0101\n0011001", "0101\n0110001", "0101\n1111001", "0101\n1001001", "0101\n0001101", "0101\n0101001", "0101\n0100101", "0101\n1000110", "0101\n1001010", "0101\n0110010", "0101\n...
p01103 A Garden with Ponds
A Garden with Ponds Mr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features. His design method is unique: he first decides the location of ponds and design them with the terrain features intact. According to his unique design procedure, all of his ponds are rectangular with simple ...
{ "input": [], "output": [] }
{ "input": [ "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3 3 4 3 3\n3 1 0 2 3\n3 3 4 3 2\n7 7\n1 1 1 1 1 0 0\n1 0 0 0 1 0 0\n1 0 1 1 1 1 1\n1 0 1 0 1 0 1\n1 1 1 1 1 0 1\n0 0 1 0 0 0 1\n0 0 1 1 1 1 1\n6 6\n1 1 1 1 2 2\n1 0 0 2 0 2\n1 0 0 2 0 2\n3 3 3 9 9 9\n3 0 0 9 0 9\n3 3 3 9 9 9\n0 0" ], "output": [ "0\n3\n1\n9" ...
{ "input": [ "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3 3 4 3 3\n3 1 0 2 3\n3 3 4 3 2\n7 7\n1 1 1 1 1 0 0\n1 0 0 0 1 0 0\n1 0 1 1 1 1 1\n1 0 1 0 1 0 1\n1 1 1 1 1 0 1\n0 0 2 0 0 0 1\n0 0 1 1 1 1 1\n6 6\n1 1 1 1 2 2\n1 0 0 2 0 2\n1 0 0 2 0 2\n3 3 3 9 9 9\n3 0 0 9 0 9\n3 3 3 9 9 9\n0 0", "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3...
p01240 Oil Company
Irving & Cohen Petroleum Corporation has decided to develop a new oil field in an area. A preliminary survey has been done and they created a detailed grid map of the area which indicates the reserve of oil. They are now planning to construct mining plants on several grid blocks according this map, but they decided no...
{ "input": [], "output": [] }
{ "input": [ "2\n2 2\n2 3\n3 5\n3 2\n4 1 1\n2 1 4" ], "output": [ "Case 1: 7\nCase 2: 8" ] }
{ "input": [ "2\n2 2\n2 3\n3 5\n3 2\n4 1 1\n2 1 0", "2\n2 0\n2 3\n3 5\n3 2\n4 1 1\n2 1 0", "2\n2 0\n2 3\n3 5\n3 3\n4 1 1\n2 1 0", "2\n1 1\n2 3\n3 5\n3 3\n4 1 1\n2 2 0", "2\n1 1\n2 2\n3 5\n3 3\n4 1 1\n2 2 0", "2\n1 1\n2 2\n3 5\n3 3\n6 1 1\n2 2 0", "2\n1 1\n2 3\n3 5\n5 3\n6 1 1\n4 2 0", ...
p01402 Anipero
Problem E: Anipero The long and short summer, which had been hot, was about to end. One day in late August, a person who likes 2D and his senior slip participated in an event called Anipero Summer Live, commonly known as Anipero. Anipero is the largest anime song live event in Japan where various anime song artists ga...
{ "input": [], "output": [] }
{ "input": [ "100 2 2 2\nA 5 6\nB 7 8\nC 1 2\nD 3 4\n27 2 3 3\nA 8 10\nB 8 10\nC 6 7\nD 5 4\nE 8 9\n27 2 3 2\nA 8 10\nB 8 10\nC 6 7\nD 5 4\nE 8 9\n44 3 6 5\nYamatoNoHito 9 10\nZettoNoHito 9 10\nTMR 10 10\nSkillNoGroup 8 10\nNanaSama 6 9\nFRPSD 6 8\nMagi3rdDeshi 5 7\nMagi13thDeshi 2 2\nMagicalItoh 4 6\n0 0 0 0" ...
{ "input": [ "100 2 2 2\nA 5 6\nB 7 8\nC 1 2\nD 3 4\n27 2 3 3\nA 8 10\nB 8 10\nC 5 7\nD 5 4\nE 8 9\n27 2 3 2\nA 8 10\nB 8 10\nC 6 7\nD 5 4\nE 8 9\n44 3 6 5\nYamatoNoHito 9 10\nZettoNoHito 9 10\nTMR 10 10\nSkillNoGroup 8 10\nNanaSama 6 9\nFRPSD 6 8\nMagi3rdDeshi 5 7\nMagi13thDeshi 2 2\nMagicalItoh 4 6\n0 0 0 0", ...
p01556 ConvexCut
A convex polygon consisting of N vertices is given. The coordinates of each vertex are represented counterclockwise by (X1, Y1), (X2, Y2), ……, (XN, YN). No matter what straight line passes through the point P, find the coordinates of the point P so that the areas of the two convex polygons obtained after cutting are eq...
{ "input": [], "output": [] }
{ "input": [ "4\n100 100\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n0 0" ], "output": [ "50.00000 50.00000", "NA" ] }
{ "input": [ "4\n000 100\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n1 0", "4\n000 101\n0 100\n0 0\n100 0", "3\n100 100\n0 100\n1 1", "4\n000 101\n0 000\n0 0\n100 0", "3\n100 100\n0 000\n1 1", "4\n000 101\n0 000\n0 0\n110 0", "3\n100 100\n1 000\n1 1", "4\n000 100\n0 000\n0 0\n110 0", ...
p01711 Idempotent Filter
Problem Statement Let's consider operations on monochrome images that consist of hexagonal pixels, each of which is colored in either black or white. Because of the shape of pixels, each of them has exactly six neighbors (e.g. pixels that share an edge with it.) "Filtering" is an operation to determine the color of a...
{ "input": [], "output": [] }
{ "input": [ "00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111\n10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111\n0101010101010101010101010101010101010101...
{ "input": [ "00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111\n10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111\n0101010101010101010101010101010101010101...
p01856 Typhoon
Problem statement There is a town with a size of H in the north-south direction and W in the east-west direction. In the town, square plots with a side length of 1 are maintained without gaps, and one house is built in each plot. A typhoon broke out over a section of the town, causing damage and then changing to an e...
{ "input": [], "output": [] }
{ "input": [ "7 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0" ], "output": [ "4 2 2 2" ] }
{ "input": [ "14 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0", "10 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0", "18 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 2 0\n0 3 3 3 0\n0 2 2 2 0\n0 1 1 1 0\n0 0 0 0 0", "6 5\n0 0 0 0 0\n0 1 1 1 0\n0 2 2 ...
p01991 Namo.. Cut
C: Namo .. Cut problem -Defeat the mysterious giant jellyfish, codenamed "Nari"- "Nari" has a very strong vitality, so if you don't keep cutting quickly, it will be revived in a blink of an eye. We are making trial and error every day to find out how to cut "Nari" efficiently. In the process, you needed the help of ...
{ "input": [], "output": [] }
{ "input": [ "3\n1 2\n1 3\n2 3\n1\n1 3" ], "output": [ "2" ] }
{ "input": [ "3\n1 2\n1 3\n2 3\n1\n1 2", "3\n1 2\n1 3\n3 3\n1\n1 2", "3\n2 2\n1 3\n2 1\n2\n2 3", "3\n1 2\n1 3\n2 3\n2\n2 3", "3\n2 2\n1 3\n3 3\n1\n1 2", "3\n2 2\n1 3\n3 3\n1\n1 4", "3\n2 2\n1 3\n2 3\n1\n1 4", "3\n1 2\n1 1\n2 3\n1\n1 3", "3\n2 2\n1 3\n2 3\n1\n1 8", "3\n1 1\n1 1\...
p02137 Special Chat
Problem The popular video posting site "ZouTube" is now in the midst of an unprecedented "virtual ZouTuber" boom. Among them, the one that has been attracting particular attention recently is the junior virtual ZouTuber "Aizumarim (commonly known as Azurim)". As a big fan of Azlim, you're going to send her a "special...
{ "input": [], "output": [] }
{ "input": [ "1333", "5700", "100000" ], "output": [ "1000", "5500", "100000" ] }
{ "input": [ "2178", "9648", "000000", "1978", "3066", "4226", "2548", "5031", "1305", "110000", "5613", "638", "3852", "10955", "7666", "6581", "12541", "6338", "12473", "9117", "4887", "15157", "21170", "10359", "388...
p02278 Minimum Cost Sort
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number of times. Write a program which reports the minimal total cost to...
{ "input": [], "output": [] }
{ "input": [ "4\n4 3 2 1", "5\n1 5 3 4 2" ], "output": [ "10", "7" ] }
{ "input": [ "4\n8 3 2 1", "5\n0 5 3 4 2", "5\n0 5 3 1 2", "5\n1 8 3 4 2", "5\n0 9 3 1 2", "5\n1 8 3 4 0", "5\n0 15 3 1 2", "5\n1 5 3 8 2", "5\n0 5 6 4 2", "5\n0 5 3 1 4", "5\n0 19 3 1 2", "4\n3 5 2 1", "5\n0 5 6 4 3", "5\n0 12 3 1 4", "5\n0 17 3 1 4", "...
p02425 Bit Flag
A state with $n$ flags of ON or OFF can be represented by a sequence of bits where $0, 1, ..., n-1$ -th flag corresponds to 1 (ON) or 0 (OFF). The state can be managed by the corresponding decimal integer, because the sequence of bits is a binary representation where each bit is 0 or 1. Given a sequence of bits with 6...
{ "input": [], "output": [] }
{ "input": [ "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n0 2\n0 3\n3 3\n4\n5\n6\n7\n8" ], "output": [ "1\n0\n1\n0\n0\n1\n0\n3\n13" ] }
{ "input": [ "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n1 2\n0 3\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n0 2\n0 6\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n2 2\n2 1\n0 0\n0 1\n0 2\n0 6\n3 3\n4\n5\n6\n7\n8", "14\n1 0\n1 1\n1 2\n2 1\n0 0\n0 1\n0 2\n0 3\n3 3\n4\n5\n6\n7\n7", "14\n1 0\n1 1\n1 2\n2...
appuzzle
Arithmetic and geometric Progressions are 2 of the well known progressions in maths. Arithmetic progression (AP) is a set in which the difference between 2 numbers in constant. for eg, 1,3,5,7,9....In this series the difference between 2 numbers is 2.The task here is very simple indeed. You will be given the 3rd term ,...
{ "input": [], "output": [] }
{ "input": [ "1\n3 8 55" ], "output": [ "10\n1 2 3 4 5 6 7 8 9 10" ] }
{ "input": [ "1\n3 14 55", "1\n3 14 83", "1\n3 14 99", "1\n3 4 95", "1\n6 4 95", "1\n6 4 142", "1\n6 4 261", "1\n1 4 261", "1\n1 4 240", "1\n1 4 228", "1\n1 4 245", "1\n1 4 448", "1\n1 6 448", "1\n1 6 482", "1\n1 2 482", "1\n2 2 482", "1\n2 2 3", ...
cielrcpt
Tomya is a girl. She loves Chef Ciel very much. Tomya like a positive integer p, and now she wants to get a receipt of Ciel's restaurant whose total price is exactly p. The current menus of Ciel's restaurant are shown the following table. Name of Menuprice eel flavored water1 deep-fried eel bones2 clear soup made w...
{ "input": [], "output": [] }
{ "input": [ "4\n10\n256\n255\n4096" ], "output": [ "2\n1\n8\n2\n" ] }
{ "input": [ "4\n10\n376\n255\n4096", "4\n10\n376\n255\n3088", "4\n11\n376\n255\n3088", "4\n11\n376\n255\n4598", "4\n11\n73\n255\n4598", "4\n11\n73\n255\n2919", "4\n8\n73\n255\n2919", "4\n8\n73\n94\n2919", "4\n14\n73\n94\n2919", "4\n14\n92\n94\n2919", "4\n17\n92\n94\n2919",...
exebit01
Pratyush, a six year old kid has just learnt how to write 1 through 1000 in decimal number system(DNS). Being a very curious kid, he made some modifications in DNS and removed the digits 0 through 3 and 7 through 9. So the only digits remaining to be used are 4, 5 and 6. He started enumerating numbers with these digits...
{ "input": [], "output": [] }
{ "input": [ "5\n3\n13\n45\n64\n1000000000" ], "output": [ "6\n444\n4456\n4664\n5446456455646565564" ] }
{ "input": [], "output": [] }