contest_id int64 50 2.01k | problem_id stringlengths 4 6 | problem_key stringclasses 32 values | name stringlengths 5 59 | statement stringlengths 19 3.14k ⌀ | input_format stringlengths 13 1.99k | output_format stringlengths 8 1.65k | examples stringlengths 54 5.15k | notes stringclasses 522 values | datasource stringclasses 2 values |
|---|---|---|---|---|---|---|---|---|---|
75 | 075B | B | B - Minesweeper | You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). . stands for an empty square, and # stands for a square containing a bomb.
Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.
Print the strings after the process. | 1 \leq H,W \leq 50
S_i is a string of length W consisting of # and ..```
H W
S_1
:
S_H
``` | Print the H strings after the process. The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W). | [{"input": ["3 5\r\n.....\r\n.#.#.\r\n....."], "output": ["11211\r\n1#2#1\r\n11211"], "explanation": "For example, let us observe the empty square at the first row from the top and first column from the left. There is one bomb square adjacent to this empty square: the square at the second row and second column. Thus, the . corresponding to this empty square is replaced with 1."}, {"input": ["3 5\r\n#####\r\n#####\r\n#####"], "output": ["#####\r\n#####\r\n#####"], "explanation": "It is possible that there is no empty square."}, {"input": ["6 6\r\n#####.\r\n#.#.##\r\n####.#\r\n.#..#.\r\n#.##..\r\n#.#..."], "output": ["#####3\r\n#8#7##\r\n####5#\r\n4#65#2\r\n#5##21\r\n#4#310"], "explanation": ""}] | null | AtC |
75 | 075C | C | C - Bridge | You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.
An edge whose removal disconnects the graph is called a bridge. Find the number of the edges that are bridges among the M edges. | 2 \leq N \leq 50
N-1 \leq M \leq min(N(N−1)⁄2,50)
1 \leq a_i<b_i \leq N
The given graph does not contain self-loops and double edges.
The given graph is connected.```
N M
a_1 b_1
a_2 b_2
:
a_M b_M
``` | Print the number of the edges that are bridges among the M edges. | [{"input": ["7 7\r\n1 3\r\n2 7\r\n3 4\r\n4 5\r\n4 6\r\n5 6\r\n6 7"], "output": ["4"], "explanation": "The figure below shows the given graph:\nThe edges shown in red are bridges. There are four of them."}, {"input": ["3 3\r\n1 2\r\n1 3\r\n2 3"], "output": ["0"], "explanation": "It is possible that there is no bridge."}, {"input": ["6 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6"], "output": ["5"], "explanation": "It is possible that every edge is a bridge."}] | null | AtC |
75 | 075D | D | D - Axis-Parallel Rectangle | We have N points in a two-dimensional plane. The coordinates of the i-th point (1 \leq i \leq N) are (x_i,y_i). Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior. Here, points on the sides of the rectangle are considered to be in the interior. Find the minimum possible area of such a rectangle. | 2 \leq K \leq N \leq 50
-10^9 \leq x_i,y_i \leq 10^9 (1 \leq i \leq N)
x_i≠x_j (1 \leq i<j \leq N)
y_i≠y_j (1 \leq i<j \leq N)
All input values are integers. (Added at 21:50 JST)```
N K
x_1 y_1
:
x_{N} y_{N}
``` | Print the minimum possible area of a rectangle that satisfies the condition. | [{"input": ["4 4\r\n1 4\r\n3 3\r\n6 2\r\n8 1"], "output": ["21"], "explanation": "One rectangle that satisfies the condition with the minimum possible area has the following vertices: (1,1), (8,1), (1,4) and (8,4). Its area is (8-1) \u00d7 (4-1) = 21."}, {"input": ["4 2\r\n0 0\r\n1 1\r\n2 2\r\n3 3"], "output": ["1"], "explanation": ""}, {"input": ["4 3\r\n-1000000000 -1000000000\r\n1000000000 1000000000\r\n-999999999 999999999\r\n999999999 -999999999"], "output": ["3999999996000000001"], "explanation": "Watch out for integer overflows."}] | null | AtC |
76 | 076A | A | A - Rating Goal | Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows:
Let the current rating of the user be a. Suppose that the performance of the user in the contest is b. Then, the new rating of the user will be the avarage of a and b.
For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.
Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it. | 0 \leq R, G \leq 4500
All input values are integers.```
R
G
``` | Print the performance required to achieve the objective. | [{"input": ["2002\r\n2017"], "output": ["2032"], "explanation": "Takahashi's current rating is 2002. If his performance in the contest is 2032, his rating will be the average of 2002 and 2032, which is equal to the desired rating, 2017."}, {"input": ["4500\r\n0"], "output": ["-4500"], "explanation": "Although the current and desired ratings are between 0 and 4500, the performance of a user can be below 0."}] | null | AtC |
76 | 076B | B | B - Addition and Multiplication | Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value:
Operation A: The displayed value is doubled. Operation B: The displayed value increases by K.
Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations. | 1 \leq N, K \leq 10
All input values are integers.```
N
K
``` | Print the minimum possible value displayed in the board after N operations. | [{"input": ["4\r\n3"], "output": ["10"], "explanation": "The value will be minimized when the operations are performed in the following order: A, A, B, B. In this case, the value will change as follows: 1 \u2192 2 \u2192 4 \u2192 7 \u2192 10."}, {"input": ["10\r\n10"], "output": ["76"], "explanation": "The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B. In this case, the value will change as follows: 1 \u2192 2 \u2192 4 \u2192 8 \u2192 16 \u2192 26 \u2192 36 \u2192 46 \u2192 56 \u2192 66 \u2192 76.\nBy the way, this contest is AtCoder Beginner Contest 076."}] | null | AtC |
76 | 076C | C | C - Dubious Document 2 | E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.
One more thing he found is a sheet of paper with the following facts written on it:
Condition 1: The string S contains a string T as a contiguous substring. Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.
Print the string S. If such a string does not exist, print UNRESTORABLE. | 1 \leq |S'|, |T| \leq 50
S' consists of lowercase English letters and ?.
T consists of lowercase English letters.```
S
T'
``` | Print the string S. If such a string does not exist, print UNRESTORABLE instead. | [{"input": ["?tc????\r\ncoder"], "output": ["atcoder"], "explanation": "There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder. Among them, the lexicographically smallest is atcoder, so we can say S = atcoder."}, {"input": ["??p??d??\r\nabc"], "output": ["UNRESTORABLE"], "explanation": "There is no string that satisfies Condition 1, so the string S does not exist."}] | null | AtC |
76 | 076D | D | D - AtCoder Express | In the year 2168, AtCoder Inc., which is much larger than now, is starting a limited express train service called AtCoder Express.
In the plan developed by the president Takahashi, the trains will run as follows:
A train will run for (t_1 + t_2 + t_3 + ... + t_N) seconds. In the first t_1 seconds, a train must run at a speed of at most v_1 m/s (meters per second). Similarly, in the subsequent t_2 seconds, a train must run at a speed of at most v_2 m/s, and so on.
According to the specifications of the trains, the acceleration of a train must be always within ±1m/s^2. Additionally, a train must stop at the beginning and the end of the run.
Find the maximum possible distance that a train can cover in the run. | 1 \leq N \leq 100
1 \leq t_i \leq 200
1 \leq v_i \leq 100
All input values are integers.```
N
t_1 t_2 t_3 … t_N
v_1 v_2 v_3 … v_N
``` | Print the maximum possible that a train can cover in the run. Output is considered correct if its absolute difference from the judge's output is at most 10^{-3}. | [{"input": ["1\r\n100\r\n30"], "output": ["2100.000000000000000"], "explanation": "\nThe maximum distance is achieved when a train runs as follows:\nThe total distance covered is 450 + 1200 + 450 = 2100 meters."}, {"input": ["2\r\n60 50\r\n34 38"], "output": ["2632.000000000000000"], "explanation": "\nThe maximum distance is achieved when a train runs as follows:\nThe total distance covered is 578 + 884 + 144 + 304 + 722 = 2632 meters."}, {"input": ["3\r\n12 14 2\r\n6 2 7"], "output": ["76.000000000000000"], "explanation": "\nThe maximum distance is achieved when a train runs as follows:\nThe total distance covered is 18 + 12 + 16 + 28 + 2 = 76 meters."}, {"input": ["1\r\n9\r\n10"], "output": ["20.250000000000000000"], "explanation": "\nThe maximum distance is achieved when a train runs as follows:\nThe total distance covered is 10.125 + 10.125 = 20.25 meters."}, {"input": ["10\r\n64 55 27 35 76 119 7 18 49 100\r\n29 19 31 39 27 48 41 87 55 70"], "output": ["20291.000000000000"], "explanation": ""}] | null | AtC |
77 | 077A | A | A - Rotation | You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}.
Write a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise. | C_{i,j}(1 \leq i \leq 2, 1 \leq j \leq 3) is a lowercase English letter.```
C_{11}C_{12}C_{13}
C_{21}C_{22}C_{23}
``` | Print YES if this grid remains the same when rotated 180 degrees; print NO otherwise. | [{"input": ["pot\r\ntop"], "output": ["YES"], "explanation": "This grid remains the same when rotated 180 degrees."}, {"input": ["tab\r\nbet"], "output": ["NO"], "explanation": "This grid does not remain the same when rotated 180 degrees."}, {"input": ["eye\r\neel"], "output": ["NO"], "explanation": ""}] | null | AtC |
77 | 077B | B | B - Around Square | Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer. | 1 \leq N \leq 10^9
N is an integer.```
N
``` | Print the largest square number not exceeding N. | [{"input": ["10"], "output": ["9"], "explanation": "10 is not square, but 9 = 3 \u00d7 3 is. Thus, we print 9."}, {"input": ["81"], "output": ["81"], "explanation": ""}, {"input": ["271828182"], "output": ["271821169"], "explanation": ""}] | null | AtC |
77 | 077C | C | C - Snuke Festival | The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.
He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different. | 1 \leq N \leq 10^5
1 \leq A_i \leq 10^9(1\leq i\leq N)
1 \leq B_i \leq 10^9(1\leq i\leq N)
1 \leq C_i \leq 10^9(1\leq i\leq N)
All input values are integers.```
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N
``` | Print the number of different altars that Ringo can build. | [{"input": ["2\r\n1 5\r\n2 4\r\n3 6"], "output": ["3"], "explanation": "The following three altars can be built:"}, {"input": ["3\r\n1 1 1\r\n2 2 2\r\n3 3 3"], "output": ["27"], "explanation": ""}, {"input": ["6\r\n3 14 159 2 6 53\r\n58 9 79 323 84 6\r\n2643 383 2 79 50 288"], "output": ["87"], "explanation": ""}] | null | AtC |
77 | 077D | D | D - Small Multiple | Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K. | 2 \leq K \leq 10^5
K is an integer.```
K
``` | Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K. | [{"input": ["6"], "output": ["3"], "explanation": "12=6\u00d72 yields the smallest sum."}, {"input": ["41"], "output": ["5"], "explanation": "11111=41\u00d7271 yields the smallest sum."}, {"input": ["79992"], "output": ["36"], "explanation": ""}] | null | AtC |
78 | 078A | A | A - HEX | In programming, hexadecimal notation is often used.
In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters A, B, C, D, E and F are used to represent the values 10, 11, 12, 13, 14 and 15, respectively.
In this problem, you are given two letters X and Y. Each X and Y is A, B, C, D, E or F.
When X and Y are seen as hexadecimal numbers, which is larger? | Each X and Y is A, B, C, D, E or F.```
X Y
``` | If X is smaller, print <; if Y is smaller, print >; if they are equal, print =. | [{"input": ["A B"], "output": ["<"], "explanation": "10 < 11."}, {"input": ["E C"], "output": [">"], "explanation": "14 > 12."}, {"input": ["F F"], "output": ["="], "explanation": "15 = 15."}] | null | AtC |
78 | 078B | B | B - ISU | We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.
We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person.
At most how many people can sit on the seat? | All input values are integers.
1 \leq X, Y, Z \leq 10^5
Y+2Z \leq X```
X Y Z
``` | Print the answer. | [{"input": ["13 3 1"], "output": ["3"], "explanation": "There is just enough room for three, as shown below:\nFigure"}, {"input": ["12 3 1"], "output": ["2"], "explanation": ""}, {"input": ["100000 1 1"], "output": ["49999"], "explanation": ""}, {"input": ["64146 123 456"], "output": ["110"], "explanation": ""}, {"input": ["64145 123 456"], "output": ["109"], "explanation": ""}] | null | AtC |
78 | 078C | C | C - HSI | Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is YES or NO.
When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds.
Now, he goes through the following process:
Submit the code. Wait until the code finishes execution on all the cases. If the code fails to correctly solve some of the M cases, submit it again. Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer). | All input values are integers.
1 \leq N \leq 100
1 \leq M \leq {\rm min}(N, 5)```
N M
``` | Print X, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, X is an integer not exceeding 10^9. | [{"input": ["1 1"], "output": ["3800"], "explanation": "In this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with 1/2 probability in 1900 milliseconds.\nThe code will succeed in one attempt with 1/2 probability, in two attempts with 1/4 probability, and in three attempts with 1/8 probability, and so on.\nThus, the answer is 1900 \\times 1/2 + (2 \\times 1900) \\times 1/4 + (3 \\times 1900) \\times 1/8 + ... = 3800."}, {"input": ["10 2"], "output": ["18400"], "explanation": "The code will take 1900 milliseconds in each of the 2 cases, and 100 milliseconds in each of the 10-2=8 cases. The probability of the code correctly solving all the cases is 1/2 \\times 1/2 = 1/4."}, {"input": ["100 5"], "output": ["608000"], "explanation": ""}] | null | AtC |
78 | 078D | D | D - ABS | We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i.
Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action:
Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.
The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.
X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game? | All input values are integers.
1 \leq N \leq 2000
1 \leq Z, W, a_i \leq 10^9```
N Z W
a_1 a_2 ... a_N
``` | Print the score. | [{"input": ["3 100 100\r\n10 1000 100"], "output": ["900"], "explanation": "If X draws two cards first, Y will draw the last card, and the score will be |1000 - 100| = 900."}, {"input": ["3 100 1000\r\n10 100 100"], "output": ["900"], "explanation": "If X draws all the cards first, the score will be |1000 - 100| = 900."}, {"input": ["5 1 1\r\n1 1 1 1 1"], "output": ["0"], "explanation": ""}, {"input": ["1 1 1\r\n1000000000"], "output": ["999999999"], "explanation": ""}] | null | AtC |
79 | 079A | A | A - Good Integer | We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good? | 1000 ≤ N ≤ 9999
N is an integer.```
N
``` | If N is good, print Yes; otherwise, print No. | [{"input": ["1118"], "output": ["Yes"], "explanation": "N is good, since it contains three consecutive 1."}, {"input": ["7777"], "output": ["Yes"], "explanation": "An integer is also good when all the digits are the same."}, {"input": ["1234"], "output": ["No"], "explanation": ""}] | null | AtC |
79 | 079B | B | B - Lucas Number | It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
L_0=2 L_1=1 L_i=L_{i-1}+L_{i-2} (i≥2) | 1≤N≤86
It is guaranteed that the answer is less than 10^{18}.
N is an integer.```
N
``` | Print the N-th Lucas number. | [{"input": ["5"], "output": ["11"], "explanation": "Thus, the 5-th Lucas number is 11."}, {"input": ["86"], "output": ["939587134549734843"], "explanation": ""}] | null | AtC |
79 | 079C | C | C - Train Ticket | Sitting in a station waiting room, Joisino is gazing at her train ticket.
The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).
In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.
The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted. | 0≤A,B,C,D≤9
All input values are integers.
It is guaranteed that there is a solution.```
ABCD
``` | Print the formula you made, including the part =7.
Use the signs + and -.
Do not print a space between a digit and a sign. | [{"input": ["1222"], "output": ["1+2+2+2=7"], "explanation": "This is the only valid solution."}, {"input": ["0290"], "output": ["0-2+9+0=7"], "explanation": "0 - 2 + 9 - 0 = 7 is also a valid solution."}, {"input": ["3242"], "output": ["3+2+4-2=7"], "explanation": ""}] | null | AtC |
79 | 079D | D | D - Wall | Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
If A_{i,j}≠-1, the square contains a digit A_{i,j}. If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end. | 1≤H,W≤200
1≤c_{i,j}≤10^3 (i≠j)
c_{i,j}=0 (i=j)
-1≤A_{i,j}≤9
All input values are integers.
There is at least one digit on the wall.```
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}
``` | Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end. | [{"input": ["2 4\r\n0 9 9 9 9 9 9 9 9 9\r\n9 0 9 9 9 9 9 9 9 9\r\n9 9 0 9 9 9 9 9 9 9\r\n9 9 9 0 9 9 9 9 9 9\r\n9 9 9 9 0 9 9 9 9 2\r\n9 9 9 9 9 0 9 9 9 9\r\n9 9 9 9 9 9 0 9 9 9\r\n9 9 9 9 9 9 9 0 9 9\r\n9 9 9 9 2 9 9 9 0 9\r\n9 2 9 9 9 9 9 9 9 0\r\n-1 -1 -1 -1\r\n8 1 1 8"], "output": ["12"], "explanation": "To turn a single 8 into 1, it is optimal to first turn 8 into 4, then turn 4 into 9, and finally turn 9 into 1, costing 6 MP.\nThe wall contains two 8s, so the minimum total MP required is 6\u00d72=12."}, {"input": ["5 5\r\n0 999 999 999 999 999 999 999 999 999\r\n999 0 999 999 999 999 999 999 999 999\r\n999 999 0 999 999 999 999 999 999 999\r\n999 999 999 0 999 999 999 999 999 999\r\n999 999 999 999 0 999 999 999 999 999\r\n999 999 999 999 999 0 999 999 999 999\r\n999 999 999 999 999 999 0 999 999 999\r\n999 999 999 999 999 999 999 0 999 999\r\n999 999 999 999 999 999 999 999 0 999\r\n999 999 999 999 999 999 999 999 999 0\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n1 1 1 1 1"], "output": ["0"], "explanation": "Note that she may not need to change any digit."}, {"input": ["3 5\r\n0 4 3 6 2 7 2 5 3 3\r\n4 0 5 3 7 5 3 7 2 7\r\n5 7 0 7 2 9 3 2 9 1\r\n3 6 2 0 2 4 6 4 2 3\r\n3 5 7 4 0 6 9 7 6 7\r\n9 8 5 2 2 0 4 7 6 5\r\n5 4 6 3 2 3 0 5 4 3\r\n3 6 2 3 4 2 4 0 8 9\r\n4 6 5 4 3 5 3 2 0 8\r\n2 1 3 4 5 7 8 6 4 0\r\n3 5 2 6 1\r\n2 5 3 2 1\r\n6 9 2 5 6"], "output": ["47"], "explanation": ""}] | null | AtC |
80 | 080A | A | A - Parking | You are parking at a parking lot. You can choose from the following two fee plans:
Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. Plan 2: The fee will be B yen, regardless of the duration.
Find the minimum fee when you park for N hours. | 1≤N≤20
1≤A≤100
1≤B≤2000
All input values are integers.```
N A B
``` | When the minimum fee is x yen, print the value of x. | [{"input": ["7 17 120"], "output": ["119"], "explanation": "Thus, the minimum fee is 119 yen."}, {"input": ["5 20 100"], "output": ["100"], "explanation": "The fee might be the same in the two plans."}, {"input": ["6 18 100"], "output": ["100"], "explanation": ""}] | null | AtC |
80 | 080B | B | B - Harshad Number | An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.
Given an integer N, determine whether it is a Harshad number. | 1?N?10^8
N is an integer.```
N
``` | Print Yes if N is a Harshad number; print No otherwise. | [{"input": ["12"], "output": ["Yes"], "explanation": "f(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number."}, {"input": ["57"], "output": ["No"], "explanation": "f(57)=5+7=12. Since 57 is not divisible by 12, 12 is not a Harshad number."}, {"input": ["148"], "output": ["No"], "explanation": ""}] | null | AtC |
80 | 080C | C | C - Shopping Street | Joisino is planning to open a shop in a shopping street.
Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.
There are already N stores in the street, numbered 1 through N.
You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.
Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.
Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period. | 1≤N≤100
0≤F_{i,j,k}≤1
For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.
-10^7≤P_{i,j}≤10^7
All input values are integers.```
N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}
``` | Print the maximum possible profit of Joisino's shop. | [{"input": ["1\r\n1 1 0 1 0 0 0 1 0 1\r\n3 4 5 6 7 8 9 -2 -3 4 -2"], "output": ["8"], "explanation": "If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit."}, {"input": ["2\r\n1 1 1 1 1 0 0 0 0 0\r\n0 0 0 0 0 1 1 1 1 1\r\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1\r\n0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1"], "output": ["-2"], "explanation": "Note that a shop must be open during at least one period, and the profit may be negative."}, {"input": ["3\r\n1 1 1 1 1 1 0 0 1 1\r\n0 1 0 1 1 1 1 0 1 0\r\n1 0 1 1 0 1 0 1 0 1\r\n-8 6 -2 -8 -8 4 8 7 -6 2 2\r\n-9 2 0 1 7 -5 0 -2 -6 5 5\r\n6 -6 7 -9 6 -5 8 0 -9 -7 -7"], "output": ["23"], "explanation": ""}] | null | AtC |
80 | 080D | D | D - Recording | Joisino is planning to record N TV programs with recorders.
The TV can receive C channels numbered 1 through C.
The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i.
Here, there will never be more than one program that are broadcast on the same channel at the same time.
When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T).
Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded. | 1≤N≤10^5
1≤C≤30
1≤s_i<t_i≤10^5
1≤c_i≤C
If c_i=c_j and i≠j, either t_i≤s_j or s_i≥t_j.
All input values are integers.```
N C
s_1 t_1 c_1
:
s_N t_N c_N
``` | When the minimum required number of recorders is x, print the value of x. | [{"input": ["3 2\r\n1 7 2\r\n7 8 1\r\n8 12 1"], "output": ["2"], "explanation": "Two recorders can record all the programs, for example, as follows:"}, {"input": ["3 4\r\n1 3 2\r\n3 4 4\r\n1 4 3"], "output": ["3"], "explanation": "There may be a channel where there is no program to record."}, {"input": ["9 4\r\n56 60 4\r\n33 37 2\r\n89 90 3\r\n32 43 1\r\n67 68 3\r\n49 51 3\r\n31 32 3\r\n70 71 1\r\n11 12 3"], "output": ["2"], "explanation": ""}] | null | AtC |
81 | 081A | A | A - Placing Marbles | Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either 0 or 1 is written. The number written in Square i is s_i.
Snuke will place a marble on each square that says 1. Find the number of squares on which Snuke will place a marble. | Each of s_1, s_2 and s_3 is either 1 or 0.```
s_{1}s_{2}s_{3}
``` | Print the answer. | [{"input": ["101"], "output": ["2"], "explanation": ""}, {"input": ["000"], "output": ["0"], "explanation": ""}] | null | AtC |
81 | 081B | B | B - Shift only | There are N positive integers written on a blackboard: A_1, ..., A_N.
Snuke can perform the following operation when all integers on the blackboard are even:
Replace each integer X on the blackboard by X divided by 2.
Find the maximum possible number of operations that Snuke can perform. | 1 \leq N \leq 200
1 \leq A_i \leq 10^9```
N
A_1 A_2 ... A_N
``` | Print the maximum possible number of operations that Snuke can perform. | [{"input": ["3\r\n8 12 40"], "output": ["2"], "explanation": "Initially, [8, 12, 40] are written on the blackboard. Since all those integers are even, Snuke can perform the operation.\nAfter the operation is performed once, [4, 6, 20] are written on the blackboard. Since all those integers are again even, he can perform the operation.\nAfter the operation is performed twice, [2, 3, 10] are written on the blackboard. Now, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.\nThus, Snuke can perform the operation at most twice."}, {"input": ["4\r\n5 6 8 10"], "output": ["0"], "explanation": "Since there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all."}, {"input": ["6\r\n382253568 723152896 37802240 379425024 404894720 471526144"], "output": ["8"], "explanation": ""}] | null | AtC |
81 | 081C | C | C - Not so Diverse | Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.
He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.
Find the minimum number of balls that Takahashi needs to rewrite the integers on them. | 1 \leq K \leq N \leq 200000
1 \leq A_i \leq N
All input values are integers.```
N K
A_1 A_2 ... A_N
``` | Print the minimum number of balls that Takahashi needs to rewrite the integers on them. | [{"input": ["5 2\r\n1 1 2 2 5"], "output": ["1"], "explanation": "For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2. On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1."}, {"input": ["4 4\r\n1 1 2 2"], "output": ["0"], "explanation": "Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything."}, {"input": ["10 3\r\n5 1 3 2 4 1 1 2 3 4"], "output": ["3"], "explanation": ""}] | null | AtC |
81 | 081D | D | D - Non-decreasing | Snuke has an integer sequence, a, of length N. The i-th element of a (1-indexed) is a_{i}.
He can perform the following operation any number of times:
Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y.
He would like to perform this operation between 0 and 2N times (inclusive) so that a satisfies the condition below. Show one such sequence of operations. It can be proved that such a sequence of operations always exists under the constraints in this problem.
Condition: a_1 \leq a_2 \leq ... \leq a_{N} | 2 \leq N \leq 50
-10^{6} \leq a_i \leq 10^{6}
All input values are integers.```
N
a_1 a_2 ... a_{N}
``` | Let m be the number of operations in your solution. In the first line, print m. In the i-th of the subsequent m lines, print the numbers x and y chosen in the i-th operation, with a space in between. The output will be considered correct if m is between 0 and 2N (inclusive) and a satisfies the condition after the m operations. | [{"input": ["3\r\n-2 5 -1"], "output": ["2\r\n2 3\r\n3 3"], "explanation": ""}, {"input": ["2\r\n-1 -3"], "output": ["1\r\n2 1"], "explanation": ""}, {"input": ["5\r\n0 0 0 0 0"], "output": ["0"], "explanation": ""}] | null | AtC |
82 | 082A | A | A - Round Up the Mean | You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer. | a and b are integers.
1 \leq a, b \leq 100```
a b
``` | Print x rounded up to the nearest integer. | [{"input": ["1 3"], "output": ["2"], "explanation": "The average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2."}, {"input": ["7 4"], "output": ["6"], "explanation": "The average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6."}, {"input": ["5 5"], "output": ["5"], "explanation": ""}] | null | AtC |
82 | 082B | B | B - Two Anagrams | You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order. | The lengths of s and t are between 1 and 100 (inclusive).
s and t consists of lowercase English letters.```
s
t
``` | If it is possible to satisfy s' < t', print Yes; if it is not, print No. | [{"input": ["yx\r\naxy"], "output": ["Yes"], "explanation": "We can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa."}, {"input": ["ratcode\r\natlas"], "output": ["Yes"], "explanation": "We can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort < tslaa."}, {"input": ["cd\r\nabc"], "output": ["No"], "explanation": "No matter how we rearrange cd and abc, we cannot achieve our objective."}, {"input": ["w\r\nww"], "output": ["Yes"], "explanation": ""}, {"input": ["zzz\r\nzzz"], "output": ["No"], "explanation": ""}] | null | AtC |
82 | 082C | C | C - Good Sequence | You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a good sequence.
Here, an sequence b is a good sequence when the following condition holds true:
For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be a good sequence. | 1 \leq N \leq 10^5
a_i is an integer.
1 \leq a_i \leq 10^9```
N
a_1 a_2 ... a_N
``` | Print the minimum number of elements that needs to be removed so that a will be a good sequence. | [{"input": ["4\r\n3 3 3 3"], "output": ["1"], "explanation": "We can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence."}, {"input": ["5\r\n2 4 1 4 2"], "output": ["2"], "explanation": "We can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good sequence."}, {"input": ["6\r\n1 2 2 3 3 3"], "output": ["0"], "explanation": ""}, {"input": ["1\r\n1000000000"], "output": ["1"], "explanation": "Remove one occurrence of 10^9. Then, () is a good sequence."}, {"input": ["8\r\n2 7 1 8 2 8 1 8"], "output": ["5"], "explanation": ""}] | null | AtC |
82 | 082D | D | D - FT Robot | A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x-axis direction.
This robot will be given an instruction sequence s. s consists of the following two kinds of letters, and will be executed in order from front to back.
F : Move in the current direction by distance 1. T : Turn 90 degrees, either clockwise or counterclockwise.
The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable. | s consists of F and T.
1 \leq |s| \leq 8 000
x and y are integers.
|x|, |y| \leq |s|```
s
x y
``` | If the objective is achievable, print Yes; if it is not, print No. | [{"input": ["FTFFTFFF\r\n4 2"], "output": ["Yes"], "explanation": "The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T."}, {"input": ["FTFFTFFF\r\n-2 -2"], "output": ["Yes"], "explanation": "The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T."}, {"input": ["FF\r\n1 0"], "output": ["No"], "explanation": ""}, {"input": ["TF\r\n1 0"], "output": ["No"], "explanation": ""}, {"input": ["FFTTFF\r\n0 0"], "output": ["Yes"], "explanation": "The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T."}, {"input": ["TTTT\r\n1 0"], "output": ["No"], "explanation": ""}] | null | AtC |
83 | 083A | A | A - Libra | A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right. | 1\leq A,B,C,D \leq 10
All input values are integers.```
A B C D
``` | Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right. | [{"input": ["3 8 7 1"], "output": ["Left"], "explanation": "The total weight of the masses on the left pan is 11, and the total weight of the masses on the right pan is 8. Since 11>8, we should print Left."}, {"input": ["3 4 5 2"], "output": ["Balanced"], "explanation": "The total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print Balanced."}, {"input": ["1 7 6 4"], "output": ["Right"], "explanation": "The total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print Right."}] | null | AtC |
83 | 083B | B | B - Some Sums | Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). | 1 \leq N \leq 10^4
1 \leq A \leq B \leq 36
All input values are integers.```
N A B
``` | Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). | [{"input": ["20 2 5"], "output": ["84"], "explanation": "Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84."}, {"input": ["10 1 2"], "output": ["13"], "explanation": ""}, {"input": ["100 4 16"], "output": ["4554"], "explanation": ""}] | null | AtC |
83 | 083C | C | C - Multiple Gift | As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below:
A consists of integers between X and Y (inclusive). For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | 1 \leq X \leq Y \leq 10^{18}
All input values are integers.```
X Y
``` | Print the maximum possible length of the sequence. | [{"input": ["3 20"], "output": ["3"], "explanation": "The sequence 3,6,18 satisfies the conditions."}, {"input": ["25 100"], "output": ["3"], "explanation": ""}, {"input": ["314159265 358979323846264338"], "output": ["31"], "explanation": ""}] | null | AtC |
83 | 083D | D | D - Wide Flip | You are given a string S consisting of 0 and 1. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times.
Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is 0, replace it with 1; if S_i is 1, replace it with 0. | 1\leq |S|\leq 10^5
S_i(1\leq i\leq N) is either 0 or 1.```
S
``` | Print the maximum integer K such that we can turn all the characters of S into 0 by repeating the operation some number of times. | [{"input": ["010"], "output": ["2"], "explanation": "We can turn all the characters of S into 0 by the following operations:"}, {"input": ["100000000"], "output": ["8"], "explanation": ""}, {"input": ["00001111"], "output": ["4"], "explanation": ""}] | null | AtC |
84 | 084A | A | A - New Year | How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December? | 1≤M≤23
M is an integer.```
M
``` | If we have x hours until New Year at M o'clock on 30th, December, print x. | [{"input": ["21"], "output": ["27"], "explanation": "We have 27 hours until New Year at 21 o'clock on 30th, December."}, {"input": ["12"], "output": ["36"], "explanation": ""}] | null | AtC |
84 | 084B | B | B - 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. | 1≤A,B≤5
|S|=A+B+1
S consists of - and digits from 0 through 9.```
A B
S
``` | Print Yes if S follows the postal code format in AtCoder Kingdom; print No otherwise. | [{"input": ["3 4\r\n269-6650"], "output": ["Yes"], "explanation": "The (A+1)-th character of S is -, and the other characters are digits from 0 through 9, so it follows the format."}, {"input": ["1 1\r\n---"], "output": ["No"], "explanation": "S contains unnecessary -s other than the (A+1)-th character, so it does not follow the format."}, {"input": ["1 2\r\n7444"], "output": ["No"], "explanation": ""}] | null | AtC |
84 | 084C | C | C - Special Trains | A railroad running from west to east in Atcoder Kingdom is now complete.
There are N stations on the railroad, numbered 1 through N from west to east.
Tomorrow, the opening ceremony of the railroad will take place.
On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.
The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.
Here, it is guaranteed that F_i divides S_i.
That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains.
For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains. | 1≤N≤500
1≤C_i≤100
1≤S_i≤10^5
1≤F_i≤10
S_i%F_i=0
All input values are integers.```
N
C_1 S_1 F_1
:
C_{N-1} S_{N-1} F_{N-1}
``` | Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x. | [{"input": ["3\r\n6 5 1\r\n1 10 1"], "output": ["12\r\n11\r\n0"], "explanation": "We will travel from Station 1 as follows:\nWe will travel from Station 2 as follows:\nNote that we should print 0 for Station 3."}, {"input": ["4\r\n12 24 6\r\n52 16 4\r\n99 2 2"], "output": ["187\r\n167\r\n101\r\n0"], "explanation": ""}, {"input": ["4\r\n12 13 1\r\n44 17 17\r\n66 4096 64"], "output": ["4162\r\n4162\r\n4162\r\n0"], "explanation": ""}] | null | AtC |
84 | 084D | D | D - 2017-like Number | We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.
You are given Q queries.
In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i. | 1≤Q≤10^5
1≤l_i≤r_i≤10^5
l_i and r_i are odd.
All input values are integers.```
Q
l_1 r_1
:
l_Q r_Q
``` | Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query. | [{"input": ["1\r\n3 7"], "output": ["2"], "explanation": "Thus, the response to the first query should be 2."}, {"input": ["4\r\n13 13\r\n7 11\r\n7 11\r\n2017 2017"], "output": ["1\r\n0\r\n0\r\n1"], "explanation": "Note that 2017 is also similar to 2017."}, {"input": ["6\r\n1 53\r\n13 91\r\n37 55\r\n19 51\r\n73 91\r\n13 49"], "output": ["4\r\n4\r\n1\r\n1\r\n1\r\n2"], "explanation": ""}] | null | AtC |
85 | 085A | A | A - Already 2018 | On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd format. For example, January 23, 2018 should be written as 2018/01/23.
After finishing the document, she noticed that she had mistakenly wrote 2017 at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to 2018 and prints it. | S is a string of length 10.
The first eight characters in S are 2017/01/.
The last two characters in S are digits and represent an integer between 1 and 31 (inclusive).```
S
``` | Replace the first four characters in S with 2018 and print it. | [{"input": ["2017/01/07"], "output": ["2018/01/07"], "explanation": ""}, {"input": ["2017/01/31"], "output": ["2018/01/31"], "explanation": ""}] | null | AtC |
85 | 085B | B | B - Kagami Mochi | An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.
Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? | 1 ≤ N ≤ 100
1 ≤ d_i ≤ 100
All input values are integers.```
N
d_1
:
d_N
``` | Print the maximum number of layers in a kagami mochi that can be made. | [{"input": ["4\r\n10\r\n8\r\n8\r\n6"], "output": ["3"], "explanation": "If we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers."}, {"input": ["3\r\n15\r\n15\r\n15"], "output": ["1"], "explanation": "When all the mochi have the same diameter, we can only have a 1-layered kagami mochi."}, {"input": ["7\r\n50\r\n30\r\n50\r\n100\r\n50\r\n80\r\n30"], "output": ["4"], "explanation": ""}] | null | AtC |
85 | 085C | C | C - Otoshidama | The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.
According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough. | 1 ≤ N ≤ 2000
1000 ≤ Y ≤ 2 × 10^7
N is an integer.
Y is a multiple of 1000.```
N Y
``` | If the total value of N bills cannot be Y yen, print -1 -1 -1.
If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. | [{"input": ["9 45000"], "output": ["4 0 5"], "explanation": "If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0 is also correct."}, {"input": ["20 196000"], "output": ["-1 -1 -1"], "explanation": "When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen."}, {"input": ["1000 1234000"], "output": ["14 27 959"], "explanation": "There are also many other possibilities."}, {"input": ["2000 20000000"], "output": ["2000 0 0"], "explanation": ""}] | null | AtC |
85 | 085D | D | D - Katana Thrower | You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:
Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.
The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total? | 1 ≤ N ≤ 10^5
1 ≤ H ≤ 10^9
1 ≤ a_i ≤ b_i ≤ 10^9
All input values are integers.```
N H
a_1 b_1
:
a_N b_N
``` | Print the minimum total number of attacks required to vanish the monster. | [{"input": ["1 10\r\n3 5"], "output": ["3"], "explanation": "You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster."}, {"input": ["2 10\r\n3 5\r\n2 6"], "output": ["2"], "explanation": "In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster."}, {"input": ["4 1000000000\r\n1 1\r\n1 10000000\r\n1 30000000\r\n1 99999999"], "output": ["860000004"], "explanation": ""}, {"input": ["5 500\r\n35 44\r\n28 83\r\n46 62\r\n31 79\r\n40 43"], "output": ["9"], "explanation": ""}] | null | AtC |
86 | 086A | A | A - Product | AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. | 1 ≤ a,b ≤ 10000
a and b are integers.```
a b
``` | If the product is odd, print Odd; if it is even, print Even. | [{"input": ["3 4"], "output": ["Even"], "explanation": "As 3 \u00d7 4 = 12 is even, print Even."}, {"input": ["1 21"], "output": ["Odd"], "explanation": "As 1 \u00d7 21 = 21 is odd, print Odd."}] | null | AtC |
86 | 086B | B | B - 1 21 | AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number. | 1 ≤ a,b ≤ 100
a and b are integers.```
a b
``` | If the concatenation of a and b in this order is a square number, print Yes; otherwise, print No. | [{"input": ["1 21"], "output": ["Yes"], "explanation": "As 121 = 11 \u00d7 11, it is a square number."}, {"input": ["100 100"], "output": ["No"], "explanation": "100100 is not a square number."}, {"input": ["12 10"], "output": ["No"], "explanation": ""}] | null | AtC |
86 | 086C | C | C - Traveling | AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that he cannot stay at his place. Determine whether he can carry out his plan. | 1 ≤ N ≤ 10^5
0 ≤ x_i ≤ 10^5
0 ≤ y_i ≤ 10^5
1 ≤ t_i ≤ 10^5
t_i < t_{i+1} (1 ≤ i ≤ N-1)
All input values are integers.```
N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N
``` | If AtCoDeer can carry out his plan, print Yes; if he cannot, print No. | [{"input": ["2\r\n3 1 2\r\n6 1 1"], "output": ["Yes"], "explanation": "For example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1), (1,0), then (1,1)."}, {"input": ["1\r\n2 100 100"], "output": ["No"], "explanation": "It is impossible to be at (100,100) two seconds after being at (0,0)."}, {"input": ["2\r\n5 1 1\r\n100 1 1"], "output": ["No"], "explanation": ""}] | null | AtC |
86 | 086D | D | D - Checker | AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square. Below is an example of a checked pattern of side 3:
AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If c_i is B, it means that he wants to paint the square (x_i,y_i) black; if c_i is W, he wants to paint the square (x_i,y_i) white. At most how many desires can he satisfy at the same time? | 1 ≤ N ≤ 10^5
1 ≤ K ≤ 1000
0 ≤ x_i ≤ 10^9
0 ≤ y_i ≤ 10^9
If i ≠ j, then (x_i,y_i) ≠ (x_j,y_j).
c_i is B or W.
N, K, x_i and y_i are integers.```
N K
x_1 y_1 c_1
x_2 y_2 c_2
:
x_N y_N c_N
``` | Print the maximum number of desires that can be satisfied at the same time. | [{"input": ["4 3\r\n0 1 W\r\n1 2 W\r\n5 3 B\r\n5 4 B"], "output": ["4"], "explanation": "He can satisfy all his desires by painting as shown in the example above."}, {"input": ["2 1000\r\n0 0 B\r\n0 1 W"], "output": ["2"], "explanation": ""}, {"input": ["6 2\r\n1 2 B\r\n2 1 W\r\n2 2 B\r\n1 0 B\r\n0 6 W\r\n4 5 W"], "output": ["4"], "explanation": ""}] | null | AtC |
87 | 087A | A | A - Buying Sweets | You went shopping to buy cakes and donuts with X yen (the currency of Japan).
First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop.
How much do you have left after shopping? | 1 \leq A, B \leq 1 000
A + B \leq X \leq 10 000
X, A and B are integers.```
X
A
B
``` | Print the amount you have left after shopping. | [{"input": ["1234\r\n150\r\n100"], "output": ["84"], "explanation": "You have 1234 - 150 = 1084 yen left after buying a cake. With this amount, you can buy 10 donuts, after which you have 84 yen left."}, {"input": ["1000\r\n108\r\n108"], "output": ["28"], "explanation": ""}, {"input": ["579\r\n123\r\n456"], "output": ["0"], "explanation": ""}, {"input": ["7477\r\n549\r\n593"], "output": ["405"], "explanation": ""}] | null | AtC |
87 | 087B | B | B - Coins | You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total?
Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. | 0 \leq A, B, C \leq 50
A + B + C \geq 1
50 \leq X \leq 20 000
A, B and C are integers.
X is a multiple of 50.```
A
B
C
X
``` | Print the number of ways to select coins. | [{"input": ["2\r\n2\r\n2\r\n100"], "output": ["2"], "explanation": "There are two ways to satisfy the condition:"}, {"input": ["5\r\n1\r\n0\r\n150"], "output": ["0"], "explanation": "Note that the total must be exactly X yen."}, {"input": ["30\r\n40\r\n50\r\n6000"], "output": ["213"], "explanation": ""}] | null | AtC |
87 | 087C | C | C - Candies | We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to travel? | 1 \leq N \leq 100
1 \leq A_{i, j} \leq 100 (1 \leq i \leq 2, 1 \leq j \leq N)```
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
``` | Print the maximum number of candies that can be collected. | [{"input": ["5\r\n3 2 2 4 1\r\n1 2 2 2 1"], "output": ["14"], "explanation": "The number of collected candies will be maximized when you:"}, {"input": ["4\r\n1 1 1 1\r\n1 1 1 1"], "output": ["5"], "explanation": "You will always collect the same number of candies, regardless of how you travel."}, {"input": ["7\r\n3 3 4 5 4 5 3\r\n5 3 4 4 2 3 2"], "output": ["29"], "explanation": ""}, {"input": ["1\r\n2\r\n3"], "output": ["5"], "explanation": ""}] | null | AtC |
87 | 087D | D | D - People on a Line | There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate.
You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds.
It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information. | 1 \leq N \leq 100 000
0 \leq M \leq 200 000
1 \leq L_i, R_i \leq N (1 \leq i \leq M)
0 \leq D_i \leq 10 000 (1 \leq i \leq M)
L_i \neq R_i (1 \leq i \leq M)
If i \neq j, then (L_i, R_i) \neq (L_j, R_j) and (L_i, R_i) \neq (R_j, L_j).
D_i are integers.```
N M
L_1 R_1 D_1
L_2 R_2 D_2
:
L_M R_M D_M
``` | If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print Yes; if it does not exist, print No. | [{"input": ["3 3\r\n1 2 1\r\n2 3 1\r\n1 3 2"], "output": ["Yes"], "explanation": "Some possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102, 103)."}, {"input": ["3 3\r\n1 2 1\r\n2 3 1\r\n1 3 5"], "output": ["No"], "explanation": "If the first two pieces of information are correct, x_3 - x_1 = 2 holds, which is contradictory to the last piece of information."}, {"input": ["4 3\r\n2 1 1\r\n2 3 5\r\n3 4 2"], "output": ["Yes"], "explanation": ""}, {"input": ["10 3\r\n8 7 100\r\n7 9 100\r\n9 8 100"], "output": ["No"], "explanation": ""}, {"input": ["100 0"], "output": ["Yes"], "explanation": ""}] | null | AtC |
88 | 088A | A | A - Infinite Coins | E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins. | N is an integer between 1 and 10000 (inclusive).
A is an integer between 0 and 1000 (inclusive).```
N
A
``` | If E869120 can pay exactly N yen using only his 1-yen and 500-yen coins, print Yes; otherwise, print No. | [{"input": ["2018\r\n218"], "output": ["Yes"], "explanation": "We can pay 2018 yen with four 500-yen coins and 18 1-yen coins, so the answer is Yes."}, {"input": ["2763\r\n0"], "output": ["No"], "explanation": "When we have no 1-yen coins, we can only pay a multiple of 500 yen using only 500-yen coins. Since 2763 is not a multiple of 500, we cannot pay this amount."}, {"input": ["37\r\n514"], "output": ["Yes"], "explanation": ""}] | null | AtC |
88 | 088B | B | B - Card Game for Two | We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score. | N is an integer between 1 and 100 (inclusive).
a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).```
N
a_1 a_2 a_3 ... a_N
``` | Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores. | [{"input": ["2\r\n3 1"], "output": ["2"], "explanation": "First, Alice will take the card with 3. Then, Bob will take the card with 1. The difference of their scores will be 3 - 1 = 2."}, {"input": ["3\r\n2 7 4"], "output": ["5"], "explanation": "First, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2."}, {"input": ["4\r\n20 18 2 18"], "output": ["18"], "explanation": ""}] | null | AtC |
88 | 088C | C | C - Takahashi's Information | We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct. | c_{i, j} \ (1 \leq i \leq 3, 1 \leq j \leq 3) is an integer between 0 and 100 (inclusive).```
c_{1,1} c_{1,2} c_{1,3}
c_{2,1} c_{2,2} c_{2,3}
c_{3,1} c_{3,2} c_{3,3}
``` | If Takahashi's statement is correct, print Yes; otherwise, print No. | [{"input": ["1 0 1\r\n2 1 2\r\n1 0 1"], "output": ["Yes"], "explanation": "Takahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1."}, {"input": ["2 2 2\r\n2 1 2\r\n2 2 2"], "output": ["No"], "explanation": "Takahashi is incorrect in this case."}, {"input": ["0 8 8\r\n0 8 8\r\n0 8 8"], "output": ["Yes"], "explanation": ""}, {"input": ["1 8 6\r\n2 9 7\r\n0 7 7"], "output": ["No"], "explanation": ""}] | null | AtC |
88 | 088D | D | D - Grid Repainting | We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares.
The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is .; if square (i, j) is initially painted by black, s_{i, j} is #. | H is an integer between 2 and 50 (inclusive).
W is an integer between 2 and 50 (inclusive).
s_{i, j} is . or # (1 \leq i \leq H, 1 \leq j \leq W).
s_{1, 1} and s_{H, W} are ..```
H W
s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W}
s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W}
: :
s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}
``` | Print the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed. | [{"input": ["3 3\r\n..#\r\n#..\r\n..."], "output": ["2"], "explanation": "The score 2 can be achieved by changing the color of squares as follows:\n"}, {"input": ["10 37\r\n.....................................\r\n...#...####...####..###...###...###..\r\n..#.#..#...#.##....#...#.#...#.#...#.\r\n..#.#..#...#.#.....#...#.#...#.#...#.\r\n.#...#.#..##.#.....#...#.#.###.#.###.\r\n.#####.####..#.....#...#..##....##...\r\n.#...#.#...#.#.....#...#.#...#.#...#.\r\n.#...#.#...#.##....#...#.#...#.#...#.\r\n.#...#.####...####..###...###...###..\r\n....................................."], "output": ["209"], "explanation": ""}] | null | AtC |
89 | 089A | A | A - Grouping 2 | There are N students in a school.
We will divide these students into some groups, and in each group they will discuss some themes.
You think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.
Divide the students so that the number of groups consisting of three or more students is maximized. | 1 \leq N \leq 1000
All input values are integers.```
N
``` | If you can form at most x groups consisting of three or more students, print x. | [{"input": ["8"], "output": ["2"], "explanation": "For example, you can form a group of three students and another of five students."}, {"input": ["2"], "output": ["0"], "explanation": "Sometimes you cannot form any group consisting of three or more students, regardless of how you divide the students."}, {"input": ["9"], "output": ["3"], "explanation": ""}] | null | AtC |
89 | 089B | B | B - Hina Arare | In Japan, people make offerings called hina arare, colorful crackers, on March 3.
We have a bag that contains N hina arare. (From here, we call them arare.)
It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.
We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: P, white: W, green: G, yellow: Y.
If the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four. | 1 \leq N \leq 100
S_i is P, W, G or Y.
There always exist i, j and k such that S_i=P, S_j=W and S_k=G.```
N
S_1 S_2 ... S_N
``` | If the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four. | [{"input": ["6\r\nG W Y P Y W"], "output": ["Four"], "explanation": "The bag contained arare in four colors, so you should print Four."}, {"input": ["9\r\nG W W G P W P G G"], "output": ["Three"], "explanation": "The bag contained arare in three colors, so you should print Three."}, {"input": ["8\r\nP Y W G Y W Y Y"], "output": ["Four"], "explanation": ""}] | null | AtC |
89 | 089C | C | C - March | There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
The name of every chosen person begins with M, A, R, C or H. There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type. | 1 \leq N \leq 10^5
S_i consists of uppercase English letters.
1 \leq |S_i| \leq 10
S_i \neq S_j (i \neq j)```
N
S_1
:
S_N
``` | If there are x ways to choose three people so that the given conditions are met, print x. | [{"input": ["5\r\nMASHIKE\r\nRUMOI\r\nOBIRA\r\nHABORO\r\nHOROKANAI"], "output": ["2"], "explanation": "We can choose three people with the following names:\nMASHIKE, RUMOI, HABORO\nMASHIKE, RUMOI, HOROKANAI\nThus, we have two ways."}, {"input": ["4\r\nZZ\r\nZZZ\r\nZ\r\nZZZZZZZZZZ"], "output": ["0"], "explanation": "Note that there may be no ways to choose three people so that the given conditions are met."}, {"input": ["5\r\nCHOKUDAI\r\nRNG\r\nMAKOTO\r\nAOKI\r\nRINGO"], "output": ["7"], "explanation": ""}] | null | AtC |
89 | 089D | D | D - Practical Skill Test | We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).
The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}.
You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points.
You now have to take Q practical tests of your ability as a magical girl.
The i-th test will be conducted as follows:
Initially, a piece is placed on the square where the integer L_i is written. Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i. Here, it is guaranteed that R_i-L_i is a multiple of D.
Initially, a piece is placed on the square where the integer L_i is written.
Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i.
Here, it is guaranteed that R_i-L_i is a multiple of D.
For each test, find the sum of magic points consumed during that test. | 1 \leq H,W \leq 300
1 \leq D \leq H×W
1 \leq A_{i,j} \leq H×W
A_{i,j} \neq A_{x,y} ((i,j) \neq (x,y))
1 \leq Q \leq 10^5
1 \leq L_i \leq R_i \leq H×W
(R_i-L_i) is a multiple of D.```
H W D
A_{1,1} A_{1,2} ... A_{1,W}
:
A_{H,1} A_{H,2} ... A_{H,W}
Q
L_1 R_1
:
L_Q R_Q
``` | For each test, print the sum of magic points consumed during that test.
Output should be in the order the tests are conducted. | [{"input": ["3 3 2\r\n1 4 3\r\n2 5 7\r\n8 9 6\r\n1\r\n4 8"], "output": ["5"], "explanation": "4 is written in Square (1,2).\n6 is written in Square (3,3).\n8 is written in Square (3,1).\nThus, the sum of magic points consumed during the first test is (|3-1|+|3-2|)+(|3-3|+|1-3|)=5."}, {"input": ["4 2 3\r\n3 7\r\n1 4\r\n5 2\r\n6 8\r\n2\r\n2 2\r\n2 2"], "output": ["0\r\n0"], "explanation": "Note that there may be a test where the piece is not moved at all, and there may be multiple identical tests."}, {"input": ["5 5 4\r\n13 25 7 15 17\r\n16 22 20 2 9\r\n14 11 12 1 19\r\n10 6 23 8 18\r\n3 21 5 24 4\r\n3\r\n13 13\r\n2 10\r\n13 13"], "output": ["0\r\n5\r\n0"], "explanation": ""}] | null | AtC |
90 | 090A | A | A - Diagonal String | We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}.
Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right. | Input consists of lowercase English letters.```
c_{11}c_{12}c_{13}
c_{21}c_{22}c_{23}
c_{31}c_{32}c_{33}
``` | Print the string of length 3 that can be obtained by concatenating the letters on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right. | [{"input": ["ant\r\nobe\r\nrec"], "output": ["abc"], "explanation": "The letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid are a, b and c from top-right to bottom-left. Concatenate these letters and print abc."}, {"input": ["edu\r\ncat\r\nion"], "output": ["ean"], "explanation": ""}] | null | AtC |
90 | 090B | B | B - Palindromic Numbers | Find the number of palindromic numbers among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward. | 10000 \leq A \leq B \leq 99999
All input values are integers.```
A B
``` | Print the number of palindromic numbers among the integers between A and B (inclusive). | [{"input": ["11009 11332"], "output": ["4"], "explanation": "There are four integers that satisfy the conditions: 11011, 11111, 11211 and 11311."}, {"input": ["31415 92653"], "output": ["612"], "explanation": ""}] | null | AtC |
90 | 090C | C | C - Flip,Flip, and Flip...... | There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.
We will perform the following operation once for each square contains a card:
For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.
It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations. | 1 \leq N,M \leq 10^9
All input values are integers.```
N M
``` | Print the number of cards that face down after all the operations. | [{"input": ["2 2"], "output": ["0"], "explanation": "We will flip every card in any of the four operations. Thus, after all the operations, all cards face up."}, {"input": ["1 7"], "output": ["5"], "explanation": "After all the operations, all cards except at both ends face down."}, {"input": ["314 1592"], "output": ["496080"], "explanation": ""}] | null | AtC |
90 | 090D | D | D - Remainder Reminder | Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had. | 1 \leq N \leq 10^5
0 \leq K \leq N-1
All input values are integers.```
N K
``` | Print the number of possible pairs that he may have had. | [{"input": ["5 2"], "output": ["7"], "explanation": "There are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5)."}, {"input": ["10 0"], "output": ["100"], "explanation": ""}, {"input": ["31415 9265"], "output": ["287927211"], "explanation": ""}] | null | AtC |
91 | 091A | A | A - Two Coins | An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. | All input values are integers.
1 \leq A, B \leq 500
1 \leq C \leq 1000```
A B C
``` | If Takahashi can buy the toy, print Yes; if he cannot, print No. | [{"input": ["50 100 120"], "output": ["Yes"], "explanation": "He has 50 + 100 = 150 yen, so he can buy the 120-yen toy."}, {"input": ["500 100 1000"], "output": ["No"], "explanation": "He has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy."}, {"input": ["19 123 143"], "output": ["No"], "explanation": "There are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard to use."}, {"input": ["19 123 142"], "output": ["Yes"], "explanation": ""}] | null | AtC |
91 | 091B | B | B - Two Colors Card Game | Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.
Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.
Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)
At most how much can he earn on balance?
Note that the same string may be written on multiple cards. | N and M are integers.
1 \leq N, M \leq 100
s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.```
N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M
``` | If Takahashi can earn at most X yen on balance, print X. | [{"input": ["3\r\napple\r\norange\r\napple\r\n1\r\ngrape"], "output": ["2"], "explanation": "He can earn 2 yen by announcing apple."}, {"input": ["3\r\napple\r\norange\r\napple\r\n5\r\napple\r\napple\r\napple\r\napple\r\napple"], "output": ["1"], "explanation": "If he announces apple, he will lose 3 yen. If he announces orange, he can earn 1 yen."}, {"input": ["1\r\nvoldemort\r\n10\r\nvoldemort\r\nvoldemort\r\nvoldemort\r\nvoldemort\r\nvoldemort\r\nvoldemort\r\nvoldemort\r\nvoldemort\r\nvoldemort\r\nvoldemort"], "output": ["0"], "explanation": "If he announces voldemort, he will lose 9 yen. If he announces orange, for example, he can avoid losing a yen."}, {"input": ["6\r\nred\r\nred\r\nblue\r\nyellow\r\nyellow\r\nred\r\n5\r\nred\r\nred\r\nyellow\r\ngreen\r\nblue"], "output": ["1"], "explanation": ""}] | null | AtC |
91 | 091C | C | C - 2D Plane 2N Points | On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).
A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.
At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs. | All input values are integers.
1 \leq N \leq 100
0 \leq a_i, b_i, c_i, d_i < 2N
a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.
b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.```
N
a_1 b_1
a_2 b_2
:
a_N b_N
c_1 d_1
c_2 d_2
:
c_N d_N
``` | Print the maximum number of friendly pairs. | [{"input": ["3\r\n2 0\r\n3 1\r\n1 3\r\n4 2\r\n0 4\r\n5 5"], "output": ["2"], "explanation": "For example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5)."}, {"input": ["3\r\n0 0\r\n1 1\r\n5 2\r\n2 3\r\n3 4\r\n4 5"], "output": ["2"], "explanation": "For example, you can pair (0, 0) and (2, 3), then (1, 1) and (3, 4)."}, {"input": ["2\r\n2 2\r\n3 3\r\n0 0\r\n1 1"], "output": ["0"], "explanation": "It is possible that no pair can be formed."}, {"input": ["5\r\n0 0\r\n7 3\r\n2 2\r\n4 8\r\n1 6\r\n8 5\r\n6 9\r\n5 4\r\n9 1\r\n3 7"], "output": ["5"], "explanation": ""}, {"input": ["5\r\n0 0\r\n1 1\r\n5 5\r\n6 6\r\n7 7\r\n2 2\r\n3 3\r\n4 4\r\n8 8\r\n9 9"], "output": ["4"], "explanation": ""}] | null | AtC |
91 | 091D | D | D - Two Sequences | You are given two integer sequences, each of length N: a_1, ..., a_N and b_1, ..., b_N.
There are N^2 ways to choose two integers i and j such that 1 \leq i, j \leq N. For each of these N^2 pairs, we will compute a_i + b_j and write it on a sheet of paper. That is, we will write N^2 integers in total.
Compute the XOR of these N^2 integers.
Definition of XOR
The XOR of integers c_1, c_2, ..., c_m is defined as follows:
Let the XOR be X. In the binary representation of X, the digit in the 2^k's place (0 \leq k; k is an integer) is 1 if there are an odd number of integers among c_1, c_2, ...c_m whose binary representation has 1 in the 2^k's place, and 0 if that number is even.
For example, let us compute the XOR of 3 and 5. The binary representation of 3 is 011, and the binary representation of 5 is 101, thus the XOR has the binary representation 110, that is, the XOR is 6.
| All input values are integers.
1 \leq N \leq 200,000
0 \leq a_i, b_i < 2^{28}```
N
a_1 a_2 ... a_N
b_1 b_2 ... b_N
``` | Print the result of the computation. | [{"input": ["2\r\n1 2\r\n3 4"], "output": ["2"], "explanation": "On the sheet, the following four integers will be written: 4(1+3), 5(1+4), 5(2+3) and 6(2+4)."}, {"input": ["6\r\n4 6 0 0 3 3\r\n0 5 6 5 0 3"], "output": ["8"], "explanation": ""}, {"input": ["5\r\n1 2 3 4 5\r\n1 2 3 4 5"], "output": ["2"], "explanation": ""}, {"input": ["1\r\n0\r\n0"], "output": ["0"], "explanation": ""}] | null | AtC |
92 | 092A | A | A - Traveling Budget | You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket.
Find the minimum total fare when the optimal choices are made for trains and buses. | 1 \leq A \leq 1 000
1 \leq B \leq 1 000
1 \leq C \leq 1 000
1 \leq D \leq 1 000
All input values are integers.```
A
B
C
D
``` | Print the minimum total fare. | [{"input": ["600\r\n300\r\n220\r\n420"], "output": ["520"], "explanation": "The train fare will be 600 yen if you buy ordinary tickets, and 300 yen if you buy an unlimited ticket. Thus, the optimal choice for trains is to buy an unlimited ticket for 300 yen. On the other hand, the optimal choice for buses is to buy ordinary tickets for 220 yen.\nTherefore, the minimum total fare is 300 + 220 = 520 yen."}, {"input": ["555\r\n555\r\n400\r\n200"], "output": ["755"], "explanation": ""}, {"input": ["549\r\n817\r\n715\r\n603"], "output": ["1152"], "explanation": ""}] | null | AtC |
92 | 092B | B | B - Chocolate | Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp. | 1 \leq N \leq 100
1 \leq D \leq 100
1 \leq X \leq 100
1 \leq A_i \leq 100 (1 \leq i \leq N)
All input values are integers.```
N
D X
A_1
A_2
:
A_N
``` | Find the number of chocolate pieces prepared at the beginning of the camp. | [{"input": ["3\r\n7 1\r\n2\r\n5\r\n10"], "output": ["8"], "explanation": "The camp has 3 participants and lasts for 7 days. Each participant eats chocolate pieces as follows:\nSince the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8."}, {"input": ["2\r\n8 20\r\n1\r\n10"], "output": ["29"], "explanation": ""}, {"input": ["5\r\n30 44\r\n26\r\n18\r\n81\r\n18\r\n6"], "output": ["56"], "explanation": ""}] | null | AtC |
92 | 092C | C | C - Traveling Plan | There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.
You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.
However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.
For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled. | 2 \leq N \leq 10^5
-5000 \leq A_i \leq 5000 (1 \leq i \leq N)
All input values are integers.```
N
A_1 A_2 ... A_N
``` | Print N lines. In the i-th line, print the total cost of travel during the trip when the visit to Spot i is canceled. | [{"input": ["3\r\n3 5 -1"], "output": ["12\r\n8\r\n10"], "explanation": "Spot 1, 2 and 3 are at the points with coordinates 3, 5 and -1, respectively. For each i, the course of the trip and the total cost of travel when the visit to Spot i is canceled, are as follows:"}, {"input": ["5\r\n1 1 1 2 0"], "output": ["4\r\n4\r\n4\r\n2\r\n4"], "explanation": ""}, {"input": ["6\r\n-679 -2409 -3258 3095 -3291 -4462"], "output": ["21630\r\n21630\r\n19932\r\n8924\r\n21630\r\n19288"], "explanation": ""}] | null | AtC |
92 | 092D | D | D - Grid Components | You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section:
Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100. The set of the squares painted white is divided into exactly A connected components. The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the conditions specified in Constraints section. If there are multiple solutions, any of them may be printed. | 1 \leq A \leq 500
1 \leq B \leq 500```
A B
``` | Output should be in the following format: | [{"input": ["2 3"], "output": ["3 3\r\n##.\r\n..#\r\n#.#"], "explanation": "This output corresponds to the grid below:"}, {"input": ["7 8"], "output": ["3 5\r\n#.#.#\r\n.#.#.\r\n#.#.#"], "explanation": ""}, {"input": ["1 1"], "output": ["4 2\r\n..\r\n#.\r\n##\r\n##"], "explanation": ""}, {"input": ["3 14"], "output": ["8 18\r\n..................\r\n..................\r\n....##.......####.\r\n....#.#.....#.....\r\n...#...#....#.....\r\n..#.###.#...#.....\r\n.#.......#..#.....\r\n#.........#..####."], "explanation": ""}] | null | AtC |
93 | 093A | A | A - abc of ABC | You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc. | |S|=3
S consists of a, b and c.```
S
``` | If S can be obtained by permuting abc, print Yes; otherwise, print No. | [{"input": ["bac"], "output": ["Yes"], "explanation": "Swapping the first and second characters in bac results in abc."}, {"input": ["bab"], "output": ["No"], "explanation": ""}, {"input": ["abc"], "output": ["Yes"], "explanation": ""}, {"input": ["aaa"], "output": ["No"], "explanation": ""}] | null | AtC |
93 | 093B | B | B - Small and Large Integers | Print all the integers that satisfies the following in ascending order:
Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers. | 1 \leq A \leq B \leq 10^9
1 \leq K \leq 100
All values in input are integers.```
A B K
``` | Print all the integers that satisfies the condition above in ascending order. | [{"input": ["3 8 2"], "output": ["3\r\n4\r\n7\r\n8"], "explanation": ""}, {"input": ["4 8 3"], "output": ["4\r\n5\r\n6\r\n7\r\n8"], "explanation": ""}, {"input": ["2 9 100"], "output": ["2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9"], "explanation": ""}] | null | AtC |
93 | 093C | C | C - Same Integers | You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:
Choose two among A, B and C, then increase both by 1. Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly performing these operations. | 0 \leq A,B,C \leq 50
All values in input are integers.```
A B C
``` | Print the minimum number of operations required to make A, B and C all equal. | [{"input": ["2 5 4"], "output": ["2"], "explanation": "We can make A, B and C all equal by the following operations:"}, {"input": ["2 6 3"], "output": ["5"], "explanation": ""}, {"input": ["31 41 5"], "output": ["23"], "explanation": ""}] | null | AtC |
93 | 093D | D | D - Worst Case | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.
The score of a participant is the product of his/her ranks in the two contests.
Process the following Q queries:
In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | 1 \leq Q \leq 100
1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)
All values in input are integers.```
Q
A_1 B_1
:
A_Q B_Q
``` | For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's. | [{"input": ["8\r\n1 4\r\n10 5\r\n3 3\r\n4 11\r\n8 9\r\n22 40\r\n8 36\r\n314159265 358979323"], "output": ["1\r\n12\r\n4\r\n11\r\n14\r\n57\r\n31\r\n671644785"], "explanation": "Let us denote a participant who was ranked x-th in the first contest and y-th in the second contest as (x,y).\nIn the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1."}] | null | AtC |
94 | 094A | A | A - Cats and Dogs | There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.
Determine if it is possible that there are exactly X cats among these A + B animals. | 1 \leq A \leq 100
1 \leq B \leq 100
1 \leq X \leq 200
All values in input are integers.```
A B X
``` | If it is possible that there are exactly X cats, print YES; if it is impossible, print NO. | [{"input": ["3 5 4"], "output": ["YES"], "explanation": "If there are one cat and four dogs among the B = 5 animals, there are X = 4 cats in total."}, {"input": ["2 2 6"], "output": ["NO"], "explanation": "Even if all of the B = 2 animals are cats, there are less than X = 6 cats in total."}, {"input": ["5 3 2"], "output": ["NO"], "explanation": "Even if all of the B = 3 animals are dogs, there are more than X = 2 cats in total."}] | null | AtC |
94 | 094B | B | B - Toll Gates | There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right.
Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N.
Find the minimum cost incurred before reaching the goal. | 1 \leq N \leq 100
1 \leq M \leq 100
1 \leq X \leq N - 1
1 \leq A_1 < A_2 < ... < A_M \leq N
A_i \neq X
All values in input are integers.```
N M X
A_1 A_2 ... A_M
``` | Print the minimum cost incurred before reaching the goal. | [{"input": ["5 3 3\r\n1 2 4"], "output": ["1"], "explanation": "The optimal solution is as follows:\nIn this case, the total cost incurred is 1."}, {"input": ["7 3 2\r\n4 5 6"], "output": ["0"], "explanation": "We may be able to reach the goal at no cost."}, {"input": ["10 7 5\r\n1 2 3 4 6 8 9"], "output": ["3"], "explanation": ""}] | null | AtC |
94 | 094C | C | C - Many Medians | When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N. | 2 \leq N \leq 200000
N is even.
1 \leq X_i \leq 10^9
All values in input are integers.```
N
X_1 X_2 ... X_N
``` | Print N lines. The i-th line should contain B_i. | [{"input": ["4\r\n2 4 4 3"], "output": ["4\r\n3\r\n3\r\n4"], "explanation": ""}, {"input": ["2\r\n1 2"], "output": ["2\r\n1"], "explanation": ""}, {"input": ["6\r\n5 5 4 4 3 3"], "output": ["4\r\n4\r\n4\r\n4\r\n4\r\n4"], "explanation": ""}] | null | AtC |
94 | 094D | D | D - Binomial Coefficients | Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted. | 2 \leq n \leq 10^5
0 \leq a_i \leq 10^9
a_1,a_2,...,a_n are pairwise distinct.
All values in input are integers.```
n
a_1 a_2 ... a_n
``` | Print a_i and a_j that you selected, with a space in between. | [{"input": ["5\r\n6 9 4 2 11"], "output": ["11 6"], "explanation": "\\rm{comb}(a_i,a_j) for each possible selection is as follows:\nThus, we should print 11 and 6."}, {"input": ["2\r\n100 0"], "output": ["100 0"], "explanation": ""}] | null | AtC |
95 | 095A | A | A - Something on It | In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions).
A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is o, it means the ramen should be topped with boiled egg; if that character is x, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen.
Write a program that, when S is given, prints the price of the corresponding bowl of ramen. | S is a string of length 3.
Each character in S is o or x.```
S
``` | Print the price of the bowl of ramen corresponding to S. | [{"input": ["oxo"], "output": ["900"], "explanation": "The price of a ramen topped with two kinds of toppings, boiled egg and green onions, is 700 + 100 \\times 2 = 900 yen."}, {"input": ["ooo"], "output": ["1000"], "explanation": "The price of a ramen topped with all three kinds of toppings is 700 + 100 \\times 3 = 1000 yen."}, {"input": ["xxx"], "output": ["700"], "explanation": "The price of a ramen without any toppings is 700 yen."}] | null | AtC |
95 | 095B | B | B - Bitter Alchemy | Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.
Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:
For each of the N kinds of doughnuts, make at least one doughnut of that kind.
At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition. | 2 ≤ N ≤ 100
1 ≤ m_i ≤ 1000
m_1 + m_2 + ... + m_N ≤ X ≤ 10^5
All values in input are integers.```
N X
m_1
m_2
:
m_N
``` | Print the maximum number of doughnuts that can be made under the condition. | [{"input": ["3 1000\r\n120\r\n100\r\n140"], "output": ["9"], "explanation": "She has 1000 grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes 120 + 100 + 140 = 360 grams of Moto. From the 640 grams of Moto that remains here, she can make additional six Doughnuts 2. This is how she can made a total of nine doughnuts, which is the maximum."}, {"input": ["4 360\r\n90\r\n90\r\n90\r\n90"], "output": ["4"], "explanation": "Making one doughnut for each of the four kinds consumes all of her Moto."}, {"input": ["5 3000\r\n150\r\n130\r\n150\r\n130\r\n110"], "output": ["26"], "explanation": ""}] | null | AtC |
95 | 095C | C | C - Half and Half | "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.
Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas. | 1 ≤ A, B, C ≤ 5000
1 ≤ X, Y ≤ 10^5
All values in input are integers.```
A B C X Y
``` | Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas. | [{"input": ["1500 2000 1600 3 2"], "output": ["7900"], "explanation": "It is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza."}, {"input": ["1500 2000 1900 3 2"], "output": ["8500"], "explanation": "It is optimal to directly buy three A-pizzas and two B-pizzas."}, {"input": ["1500 2000 500 90000 100000"], "output": ["100000000"], "explanation": "It is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas and 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that is fine."}] | null | AtC |
95 | 095D | D | D - Static Sushi | "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger. | 1 ≤ N ≤ 10^5
2 ≤ C ≤ 10^{14}
1 ≤ x_1 < x_2 < ... < x_N < C
1 ≤ v_i ≤ 10^9
All values in input are integers.```
N C
x_1 v_1
x_2 v_2
:
x_N v_N
``` | If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. | [{"input": ["3 20\r\n2 80\r\n9 120\r\n16 1"], "output": ["191"], "explanation": "There are three sushi on the counter with a circumference of 20 meters. If he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories. If he walks seven more meters clockwise, he can eat a sushi of 120 kilocalories. If he leaves now, the total nutrition taken in is 200 kilocalories, and the total energy consumed is 9 kilocalories, thus he can take in 191 kilocalories on balance, which is the largest possible value."}, {"input": ["3 20\r\n2 80\r\n9 1\r\n16 120"], "output": ["192"], "explanation": "The second and third sushi have been swapped. Again, if he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories. If he walks six more meters counterclockwise this time, he can eat a sushi of 120 kilocalories. If he leaves now, the total nutrition taken in is 200 kilocalories, and the total energy consumed is 8 kilocalories, thus he can take in 192 kilocalories on balance, which is the largest possible value."}, {"input": ["1 100000000000000\r\n50000000000000 1"], "output": ["0"], "explanation": "Even though the only sushi is so far that it does not fit into a 32-bit integer, its nutritive value is low, thus he should immediately leave without doing anything."}, {"input": ["15 10000000000\r\n400000000 1000000000\r\n800000000 1000000000\r\n1900000000 1000000000\r\n2400000000 1000000000\r\n2900000000 1000000000\r\n3300000000 1000000000\r\n3700000000 1000000000\r\n3800000000 1000000000\r\n4000000000 1000000000\r\n4100000000 1000000000\r\n5200000000 1000000000\r\n6600000000 1000000000\r\n8000000000 1000000000\r\n9300000000 1000000000\r\n9700000000 1000000000"], "output": ["6500000000"], "explanation": "All these sample inputs above are included in the test set for the partial score."}] | null | AtC |
96 | 096A | A | A - Day of Takahashi | In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi? | a is an integer between 1 and 12 (inclusive).
b is an integer between 1 and 31 (inclusive).
2018-a-b is a valid date in Gregorian calendar.```
a b
``` | Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi. | [{"input": ["5 5"], "output": ["5"], "explanation": "There are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5."}, {"input": ["2 1"], "output": ["1"], "explanation": "There is only one day that is Takahashi: 1-1."}, {"input": ["11 30"], "output": ["11"], "explanation": "There are eleven days that are Takahashi: 1-1, 2-2, 3-3, 4-4, 5-5, 6-6, 7-7, 8-8, 9-9, 10-10 and 11-11."}] | null | AtC |
96 | 096B | B | B - Maximum Sum | There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations? | A, B and C are integers between 1 and 50 (inclusive).
K is an integer between 1 and 10 (inclusive).```
A B C
K
``` | Print the largest possible sum of the integers written on the blackboard after K operations by E869220. | [{"input": ["5 3 11\r\n1"], "output": ["30"], "explanation": "In this sample, 5, 3, 11 are initially written on the blackboard, and E869120 can perform the operation once. There are three choices:\nIf he chooses 3., the sum of the integers written on the board afterwards is 5 + 3 + 22 = 30, which is the largest among 1. through 3."}, {"input": ["3 3 4\r\n2"], "output": ["22"], "explanation": "E869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows:\nThen, the sum of the integers eventually written on the blackboard is 3 + 3 + 16 = 22."}] | null | AtC |
96 | 096C | C | C - Grid Repainting 2 | We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= .. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective. | H is an integer between 1 and 50 (inclusive).
W is an integer between 1 and 50 (inclusive).
For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is # or ..```
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
``` | If square1001 can achieve his objective, print Yes; if he cannot, print No. | [{"input": ["3 3\r\n.#.\r\n###\r\n.#."], "output": ["Yes"], "explanation": "One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.\n"}, {"input": ["5 5\r\n#.#.#\r\n.#.#.\r\n#.#.#\r\n.#.#.\r\n#.#.#"], "output": ["No"], "explanation": "square1001 cannot achieve his objective here."}, {"input": ["11 11\r\n...#####...\r\n.##.....##.\r\n#..##.##..#\r\n#..##.##..#\r\n#.........#\r\n#...###...#\r\n.#########.\r\n.#.#.#.#.#.\r\n##.#.#.#.##\r\n..##.#.##..\r\n.##..#..##."], "output": ["Yes"], "explanation": ""}] | null | AtC |
96 | 096D | D | D - 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 number.
If there are multiple such sequences, printing any of them is accepted. | N is an integer between 5 and 55 (inclusive).```
N
``` | Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between. | [{"input": ["5"], "output": ["3 5 7 11 31"], "explanation": "Let us see if this output actually satisfies the conditions. First, 3, 5, 7, 11 and 31 are all different, and all of them are prime numbers. The only way to choose five among them is to choose all of them, whose sum is a_1+a_2+a_3+a_4+a_5=57, which is a composite number. There are also other possible outputs, such as 2 3 5 7 13, 11 13 17 19 31 and 7 11 5 31 3."}, {"input": ["6"], "output": ["2 3 5 7 11 13"], "explanation": "Thus, the sequence 2 3 5 7 11 13 satisfies the conditions."}, {"input": ["8"], "output": ["2 5 7 13 19 37 67 79"], "explanation": ""}] | null | AtC |
97 | 097A | A | A - Colorful Transceivers | Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate. | 1 ≤ a,b,c ≤ 100
1 ≤ d ≤ 100
All values in input are integers.```
a b c d
``` | If A and C can communicate, print Yes; if they cannot, print No. | [{"input": ["4 7 9 3"], "output": ["Yes"], "explanation": "A and B can directly communicate, and also B and C can directly communicate, so we should print Yes."}, {"input": ["100 10 1 2"], "output": ["No"], "explanation": "They cannot communicate in this case."}, {"input": ["10 10 10 1"], "output": ["Yes"], "explanation": "There can be multiple people at the same position."}, {"input": ["1 100 2 10"], "output": ["Yes"], "explanation": ""}] | null | AtC |
97 | 097B | B | B - Exponential | You are given a positive integer X. Find the largest perfect power that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2. | 1 ≤ X ≤ 1000
X is an integer.```
X
``` | Print the largest perfect power that is at most X. | [{"input": ["10"], "output": ["9"], "explanation": "There are four perfect powers that are at most 10: 1, 4, 8 and 9. We should print the largest among them, 9."}, {"input": ["1"], "output": ["1"], "explanation": ""}, {"input": ["999"], "output": ["961"], "explanation": ""}] | null | AtC |
97 | 097C | C | C - K-th Substring | You are given a string s. Among the different substrings of s, print the K-th lexicographically smallest one.
A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not. Also, we say that substrings are different when they are different as strings.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | 1 ≤ |s| ≤ 5000
s consists of lowercase English letters.
1 ≤ K ≤ 5
s has at least K different substrings.```
s
K
``` | Print the K-th lexicographically smallest substring of K. | [{"input": ["aba\r\n4"], "output": ["b"], "explanation": "s has five substrings: a, b, ab, ba and aba. Among them, we should print the fourth smallest one, b. Note that we do not count a twice."}, {"input": ["atcoderandatcodeer\r\n5"], "output": ["andat"], "explanation": ""}, {"input": ["z\r\n1"], "output": ["z"], "explanation": ""}] | null | AtC |
97 | 097D | D | D - Equals | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized:
Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.
Find the maximum possible number of i such that p_i = i after operations. | 2 ≤ N ≤ 10^5
1 ≤ M ≤ 10^5
p is a permutation of integers from 1 through N.
1 ≤ x_j,y_j ≤ N
x_j ≠ y_j
If i ≠ j, \{x_i,y_i\} ≠ \{x_j,y_j\}.
All values in input are integers.```
N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M
``` | Print the maximum possible number of i such that p_i = i after operations. | [{"input": ["5 2\r\n5 3 1 4 2\r\n1 3\r\n5 4"], "output": ["2"], "explanation": "If we perform the operation by choosing j=1, p becomes 1 3 5 4 2, which is optimal, so the answer is 2."}, {"input": ["3 2\r\n3 2 1\r\n1 2\r\n2 3"], "output": ["3"], "explanation": "If we perform the operation by, for example, choosing j=1, j=2, j=1 in this order, p becomes 1 2 3, which is obviously optimal. Note that we may choose the same j any number of times."}, {"input": ["10 8\r\n5 3 6 8 7 10 9 1 2 4\r\n3 1\r\n4 1\r\n5 9\r\n2 5\r\n6 5\r\n3 5\r\n8 9\r\n7 9"], "output": ["8"], "explanation": ""}, {"input": ["5 1\r\n1 2 3 4 5\r\n1 5"], "output": ["5"], "explanation": "We do not have to perform the operation."}] | null | AtC |
98 | 098A | A | A - Add Sub Mul | You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. | -1000 \leq A,B \leq 1000
All values in input are integers.```
A B
``` | Print the largest value among A+B, A-B and A \times B. | [{"input": ["3 1"], "output": ["4"], "explanation": "3+1=4, 3-1=2 and 3 \\times 1=3. The largest among them is 4."}, {"input": ["4 -2"], "output": ["6"], "explanation": "The largest is 4 - (-2) = 6."}, {"input": ["0 0"], "output": ["0"], "explanation": ""}] | null | AtC |
98 | 098B | B | B - Cut and Count | You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position. | 2 \leq N \leq 100
|S| = N
S consists of lowercase English letters.```
N
S
``` | Print the largest possible number of different letters contained in both X and Y. | [{"input": ["6\r\naabbca"], "output": ["2"], "explanation": "If we cut the string between the third and fourth letters into X = aab and Y = bca, the letters contained in both X and Y are a and b. There will never be three or more different letters contained in both X and Y, so the answer is 2."}, {"input": ["10\r\naaaaaaaaaa"], "output": ["1"], "explanation": "However we divide S, only a will be contained in both X and Y."}, {"input": ["45\r\ntgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir"], "output": ["9"], "explanation": ""}] | null | AtC |
98 | 098C | C | C - Attention | There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = E, and west if S_i = W.
You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.
The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions. | 2 \leq N \leq 3 \times 10^5
|S| = N
S_i is E or W.```
N
S
``` | Print the minimum number of people who have to change their directions. | [{"input": ["5\r\nWEEWW"], "output": ["1"], "explanation": "Assume that we appoint the third person from the west as the leader. Then, the first person from the west needs to face east and has to turn around. The other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case. It is not possible to have 0 people who have to change their directions, so the answer is 1."}, {"input": ["12\r\nWEWEWEEEWWWE"], "output": ["4"], "explanation": ""}, {"input": ["8\r\nWWWWWEEE"], "output": ["3"], "explanation": ""}] | null | AtC |
98 | 098D | D | D - Xor Sum 2 | There is an integer sequence A of length N.
Find the number of the pairs of integers l and r (1 \leq l \leq r \leq N) that satisfy the following condition:
A_l\ xor\ A_{l+1}\ xor\ ...\ xor\ A_r = A_l\ +\ A_{l+1}\ +\ ...\ +\ A_r
Here, xor denotes the bitwise exclusive OR.
Definition of XOR
The XOR of integers c_1, c_2, ..., c_m is defined as follows:
Let the XOR be X. In the binary representation of X, the digit in the 2^k's place (0 \leq k; k is an integer) is 1 if there are an odd number of integers among c_1, c_2, ...c_m whose binary representation has 1 in the 2^k's place, and 0 if that number is even.
For example, let us compute the XOR of 3 and 5. The binary representation of 3 is 011, and the binary representation of 5 is 101, thus the XOR has the binary representation 110, that is, the XOR is 6.
| 1 \leq N \leq 2 \times 10^5
0 \leq A_i < 2^{20}
All values in input are integers.```
N
A_1 A_2 ... A_N
``` | Print the number of the pairs of integers l and r (1 \leq l \leq r \leq N) that satisfy the condition. | [{"input": ["4\r\n2 5 4 6"], "output": ["5"], "explanation": "(l,r)=(1,1),(2,2),(3,3),(4,4) clearly satisfy the condition. (l,r)=(1,2) also satisfies the condition, since A_1\\ xor\\ A_2 = A_1\\ +\\ A_2 = 7. There are no other pairs that satisfy the condition, so the answer is 5."}, {"input": ["9\r\n0 0 0 0 0 0 0 0 0"], "output": ["45"], "explanation": ""}, {"input": ["19\r\n885 8 1 128 83 32 256 206 639 16 4 128 689 32 8 64 885 969 1"], "output": ["37"], "explanation": ""}] | null | AtC |
99 | 099A | A | A - ABD | Decades have passed since the beginning of AtCoder Beginner Contest.
The contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?
In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.
You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. | 1 \leq N \leq 1998
N is an integer.```
N
``` | Print the first three characters of the label of the N-th round of AtCoder Beginner Contest. | [{"input": ["999"], "output": ["ABC"], "explanation": "The 999-th round of AtCoder Beginner Contest is labeled as ABC999."}, {"input": ["1000"], "output": ["ABD"], "explanation": "The 1000-th round of AtCoder Beginner Contest is labeled as ABD001."}, {"input": ["1481"], "output": ["ABD"], "explanation": "The 1481-th round of AtCoder Beginner Contest is labeled as ABD482."}] | null | AtC |
99 | 099B | B | B - Stone Monument | In some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.
It had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.
Assuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.
Assume also that the depth of the snow cover is always at least 1 meter. | 1 \leq a < b < 499500(=1+2+3+...+999)
All values in input are integers.
There is no input that contradicts the assumption.```
a b
``` | If the depth of the snow cover is x meters, print x as an integer. | [{"input": ["8 13"], "output": ["2"], "explanation": "The heights of the two towers are 10 meters and 15 meters, respectively. Thus, we can see that the depth of the snow cover is 2 meters."}, {"input": ["54 65"], "output": ["1"], "explanation": ""}] | null | AtC |
99 | 099C | C | C - Strange Bank | To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:
1 yen (the currency of Japan) 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
1 yen (the currency of Japan)
6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew. | 1 \leq N \leq 100000
N is an integer.```
N
``` | If at least x operations are required to withdraw exactly N yen in total, print x. | [{"input": ["127"], "output": ["4"], "explanation": "By withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations."}, {"input": ["3"], "output": ["3"], "explanation": "By withdrawing 1 yen three times, we can withdraw 3 yen in three operations."}, {"input": ["44852"], "output": ["16"], "explanation": ""}] | null | AtC |
99 | 099D | D | D - Good Grid | There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left.
These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}.
We say the grid is a good grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N:
If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same. If (i+j) \% 3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different.
Here, X \% Y represents X modulo Y.
We will repaint zero or more squares so that the grid will be a good grid.
For a square, the wrongness when the color of the square is X before repainting and Y after repainting, is D_{X,Y}.
Find the minimum possible sum of the wrongness of all the squares. | 1 \leq N \leq 500
3 \leq C \leq 30
1 \leq D_{i,j} \leq 1000 (i \neq j),D_{i,j}=0 (i=j)
1 \leq c_{i,j} \leq C
All values in input are integers.```
N C
D_{1,1} ... D_{1,C}
:
D_{C,1} ... D_{C,C}
c_{1,1} ... c_{1,N}
:
c_{N,1} ... c_{N,N}
``` | If the minimum possible sum of the wrongness of all the squares is x, print x. | [{"input": ["2 3\r\n0 1 1\r\n1 0 1\r\n1 4 0\r\n1 2\r\n3 3"], "output": ["3"], "explanation": "In this case, the sum of the wrongness of all the squares is 3.\nNote that D_{i,j} \\neq D_{j,i} is possible."}, {"input": ["4 3\r\n0 12 71\r\n81 0 53\r\n14 92 0\r\n1 1 2 1\r\n2 1 1 2\r\n2 2 1 3\r\n1 1 2 2"], "output": ["428"], "explanation": ""}] | null | AtC |
100 | 100A | A | A - Happy Birthday! | E869120's and square1001's 16-th birthday is coming soon. Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces, respectively, when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of pieces of cake? | A and B are integers between 1 and 16 (inclusive).
A+B is at most 16.```
A B
``` | If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print Yay!; otherwise, print :(. | [{"input": ["5 4"], "output": ["Yay!"], "explanation": "Both of them can take desired number of pieces as follows:"}, {"input": ["8 8"], "output": ["Yay!"], "explanation": "Both of them can take desired number of pieces as follows:"}, {"input": ["11 4"], "output": [":("], "explanation": "In this case, there is no way for them to take desired number of pieces, unfortunately."}] | null | AtC |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.