Score : 300 points
\nWe 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).
\nYou are initially in the top-left square, (1, 1).\nYou will travel to the bottom-right square, (2, N), by repeatedly moving right or down.
\nThe square (i, j) contains A_{i, j} candies.\nYou will collect all the candies you visit during the travel.\nThe top-left and bottom-right squares also contain candies, and you will also collect them.
\nAt most how many candies can you collect when you choose the best way to travel?
\nInput is given from Standard Input in the following format:
\nN\nA_{1, 1} A_{1, 2} ... A_{1, N}\nA_{2, 1} A_{2, 2} ... A_{2, N}\n\n
Print the maximum number of candies that can be collected.
\n5\n3 2 2 4 1\n1 2 2 2 1\n\n
14\n\n
The number of collected candies will be maximized when you:
\n4\n1 1 1 1\n1 1 1 1\n\n
5\n\n
You will always collect the same number of candies, regardless of how you travel.
\n7\n3 3 4 5 4 5 3\n5 3 4 4 2 3 2\n\n
29\n\n
1\n2\n3\n\n
5\n
Score : 100 points
\nTakahashi is distributing N balls to K persons.
\nIf each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?
\nInput is given from Standard Input in the following format:
\nN K\n\n
Print the maximum possible difference in the number of balls received.
\n3 2\n\n
1\n\n
The only way to distribute three balls to two persons so that each of them receives at least one ball is to give one ball to one person and give two balls to the other person.
\nThus, the maximum possible difference in the number of balls received is 1.
\n3 1\n\n
0\n\n
We have no choice but to give three balls to the only person, in which case the difference in the number of balls received is 0.
\n8 5\n\n
3\n\n
For example, if we give 1, 4, 1, 1, 1 balls to the five persons, the number of balls received between the person with the most balls and the person with the fewest balls would be 3, which is the maximum result.
Score : 100 points
\nWe have A balls with the string S written on each of them and B balls with the string T written on each of them.
\nFrom these balls, Takahashi chooses one with the string U written on it and throws it away.
\nFind the number of balls with the string S and balls with the string T that we have now.
Input is given from Standard Input in the following format:
\nS T\nA B\nU\n\n
Print the answer, with space in between.
\nred blue\n3 4\nred\n\n
2 4\n\n
Takahashi chose a ball with red
written on it and threw it away.\nNow we have two balls with the string S and four balls with the string T.
red blue\n5 5\nblue\n\n
5 4\n\n
Takahashi chose a ball with blue
written on it and threw it away.\nNow we have five balls with the string S and four balls with the string T.
Score: 300 points
\nWe 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.
\nAccording 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.
\nDetermine if he is correct.
Input is given from Standard Input in the following format:
\nc_{1,1} c_{1,2} c_{1,3}\nc_{2,1} c_{2,2} c_{2,3}\nc_{3,1} c_{3,2} c_{3,3}\n\n
If Takahashi's statement is correct, print Yes
; otherwise, print No
.
1 0 1\n2 1 2\n1 0 1\n\n
Yes\n\n
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.
\n2 2 2\n2 1 2\n2 2 2\n\n
No\n\n
Takahashi is incorrect in this case.
\n0 8 8\n0 8 8\n0 8 8\n\n
Yes\n\n
1 8 6\n2 9 7\n0 7 7\n\n
No\n
Score : 100 points
\nOn 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.
2017/01/
.Input is given from Standard Input in the following format:
\nS\n\n
Replace the first four characters in S with 2018
and print it.
2017/01/07\n\n
2018/01/07\n\n
2017/01/31\n\n
2018/01/31\n
Score : 200 points
\nTakahashi has N days of summer vacation.
\nHis teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.
\nHe cannot do multiple assignments on the same day, or hang out on a day he does an assignment.
\nWhat is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?
\nIf Takahashi cannot finish all the assignments during the vacation, print -1
instead.
Input is given from Standard Input in the following format:
\nN M\nA_1 ... A_M\n\n
Print the maximum number of days Takahashi can hang out during the vacation, or -1
.
41 2\n5 6\n\n
30\n\n
For example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.
\n10 2\n5 6\n\n
-1\n\n
He cannot finish his assignments.
\n11 2\n5 6\n\n
0\n\n
He can finish his assignments, but he will have no time to hang out.
\n314 15\n9 26 5 35 8 9 79 3 23 8 46 2 6 43 3\n\n
9\n
Score : 300 points
\nGiven is a positive integer N.\nHow many tuples (A,B,C) of positive integers satisfy A \\times B + C = N?
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the answer.
\n3\n\n
3\n\n
There are 3 tuples of integers that satisfy A \\times B + C = 3: (A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 1).
\n100\n\n
473\n\n
1000000\n\n
13969985\n
Score : 400 points
\nFor an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.
\nThen, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.
\nFind the maximum possible value of M_1 + M_2 + \\cdots + M_N.
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the maximum possible value of M_1 + M_2 + \\cdots + M_N.
\n2\n\n
1\n\n
When the permutation \\{P_1, P_2\\} = \\{2, 1\\} is chosen, M_1 + M_2 = 1 + 0 = 1.
\n13\n\n
78\n\n
1\n\n
0\n
Score : 200 points
\nKatsusando loves omelette rice.
\nBesides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.
\nTo prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like these foods or not.
\nThe i-th person answered that he/she only likes the A_{i1}-th, A_{i2}-th, ..., A_{iK_i}-th food.
\nFind the number of the foods liked by all the N people.
\nInput is given from Standard Input in the following format:
\nN M\nK_1 A_{11} A_{12} ... A_{1K_1}\nK_2 A_{21} A_{22} ... A_{2K_2}\n:\nK_N A_{N1} A_{N2} ... A_{NK_N}\n\n
Print the number of the foods liked by all the N people.
\n3 4\n2 1 3\n3 1 2 3\n2 3 2\n\n
1\n\n
As only the third food is liked by all the three people, 1 should be printed.
\n5 5\n4 2 3 4 5\n4 1 3 4 5\n4 1 2 4 5\n4 1 2 3 5\n4 1 2 3 4\n\n
0\n\n
Katsusando's hypothesis turned out to be wrong.
\n1 30\n3 5 10 30\n\n
3\n
Score : 300 points
\nN persons are standing in a row. The height of the i-th person from the front is A_i.
\nWe want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:
\nCondition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.
\nFind the minimum total height of the stools needed to meet this goal.
\nInput is given from Standard Input in the following format:
\nN\nA_1 \\ldots A_N\n\n
Print the minimum total height of the stools needed to meet the goal.
\n5\n2 1 5 4 3\n\n
4\n\n
If the persons stand on stools of heights 0, 1, 0, 1, and 2, respectively, their heights will be 2, 2, 5, 5, and 5, satisfying the condition.
\nWe cannot meet the goal with a smaller total height of the stools.
\n5\n3 3 3 3 3\n\n
0\n\n
Giving a stool of height 0 to everyone will work.
Score : 300 points
\nThere are N squares arranged in a row from left to right.
\nThe height of the i-th square from the left is H_i.
\nYou will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.
\nFind the maximum number of times you can move.
\nInput is given from Standard Input in the following format:
\nN\nH_1 H_2 ... H_N\n\n
Print the maximum number of times you can move.
\n5\n10 4 8 7 3\n\n
2\n\n
By landing on the third square from the left, you can move to the right twice.
\n7\n4 4 5 6 6 5 5\n\n
3\n\n
By landing on the fourth square from the left, you can move to the right three times.
\n4\n1 2 3 4\n\n
0\n
Score : 200 points
\nDetermine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
\nYou can use the following theorem:
\nTheorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.
\nInput is given from Standard Input in the following format:
\nN\nL_1 L_2 ... L_N\n\n
If an N-sided polygon satisfying the condition can be drawn, print Yes
; otherwise, print No
.
4\n3 8 5 1\n\n
Yes\n\n
Since 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can be drawn on a plane.
\n4\n3 8 4 1\n\n
No\n\n
Since 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon cannot be drawn on a plane.
\n10\n1 8 10 5 8 12 34 100 11 3\n\n
No\n
Score : 200 points
\nYou have decided to write a book introducing good restaurants.\nThere are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.\nNo two restaurants have the same score.
\nYou want to introduce the restaurants in the following order:
\nPrint the identification numbers of the restaurants in the order they are introduced in the book.
\nInput is given from Standard Input in the following format:
\nN\nS_1 P_1\n:\nS_N P_N\n\n
Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.
\n6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n\n
3\n4\n6\n1\n5\n2\n\n
The lexicographical order of the names of the three cities is kazan
< khabarovsk
< moscow
. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2.
10\nyakutsk 10\nyakutsk 20\nyakutsk 30\nyakutsk 40\nyakutsk 50\nyakutsk 60\nyakutsk 70\nyakutsk 80\nyakutsk 90\nyakutsk 100\n\n
10\n9\n8\n7\n6\n5\n4\n3\n2\n1\n
Score : 300 points
\nThere are N candles placed on a number line.\nThe i-th candle from the left is placed on coordinate x_i.\nHere, x_1 < x_2 < ... < x_N holds.
\nInitially, no candles are burning.\nSnuke decides to light K of the N candles.
\nNow, he is at coordinate 0.\nHe can move left and right along the line with speed 1.\nHe can also light a candle when he is at the same position as the candle, in negligible time.
\nFind the minimum time required to light K candles.
\nInput is given from Standard Input in the following format:
\nN K\nx_1 x_2 ... x_N\n\n
Print the minimum time required to light K candles.
\n5 3\n-30 -10 10 20 50\n\n
40\n\n
He should move and light candles as follows:
\n3 2\n10 20 30\n\n
20\n\n
1 1\n0\n\n
0\n\n
8 5\n-9 -7 -4 -3 1 2 3 4\n\n
10\n
Score : 300 points
\nThere are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.\nThere are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.
\nObs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.\nNote that Obs. i is also good when no observatory can be reached from Obs. i using just one road.
\nHow many good observatories are there?
\nInput is given from Standard Input in the following format:
\nN M\nH_1 H_2 ... H_N\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n\n
Print the number of good observatories.
\n4 3\n1 2 3 4\n1 3\n2 3\n2 4\n\n
2\n\n
From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.
\nFrom Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.
\nFrom Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.
\nFrom Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.
\nThus, the good observatories are Obs. 3 and 4, so there are two good observatories.
\n6 5\n8 6 9 1 2 1\n1 3\n4 2\n4 3\n4 6\n4 6\n\n
3\n
Score : 300 points
\nThere are N monsters, numbered 1, 2, ..., N.
\nInitially, the health of Monster i is A_i.
\nBelow, a monster with at least 1 health is called alive.
\nUntil there is only one alive monster, the following is repeated:
\nFind the minimum possible final health of the last monster alive.
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 ... A_N\n\n
Print the minimum possible final health of the last monster alive.
\n4\n2 10 8 40\n\n
2\n\n
When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.
\n4\n5 13 8 1000000000\n\n
1\n\n
3\n1000000000 1000000000 1000000000\n\n
1000000000\n
Score : 300 points
\nThere are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.)\nThe state of each piece is represented by a string S of length N.\nIf S_i=B
, the i-th piece from the left is showing black;\nIf S_i=W
, the i-th piece from the left is showing white.
Consider performing the following operation:
\nFind the maximum possible number of times this operation can be performed.
\nB
or W
Input is given from Standard Input in the following format:
\nS\n\n
Print the maximum possible number of times the operation can be performed.
\nBBW\n\n
2\n\n
The operation can be performed twice, as follows:
\nBWBWBW\n\n
6\n
Score : 200 points
\nWe have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).
\nAmong them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?
\nWe remind you that the distance between the origin and the point (p, q) can be represented as \\sqrt{p^2+q^2}.
\nInput is given from Standard Input in the following format:
\nN D\nX_1 Y_1\n\\vdots\nX_N Y_N\n\n
Print an integer representing the number of points such that the distance from the origin is at most D.
\n4 5\n0 5\n-2 4\n3 4\n4 -4\n\n
3\n\n
The distance between the origin and each of the given points is as follows:
\nThus, we have three points such that the distance from the origin is at most 5.
\n12 3\n1 1\n1 1\n1 1\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n\n
7\n\n
Multiple points may exist at the same coordinates.
\n20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n188810 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-153551 114185\n98784 -6820\n94111 -86268\n-30401 61477\n-55056 7872\n5901 -163796\n138819 -185986\n-69848 -96669\n\n
6\n
Score : 200 points
\nYou are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
\nThe input is given from Standard Input in the following format:
\ns\n\n
Print the string obtained by concatenating all the characters in the odd-numbered positions.
\natcoder\n\n
acdr\n\n
Extract the first character a
, the third character c
, the fifth character d
and the seventh character r
to obtain acdr
.
aaaa\n\n
aa\n\n
z\n\n
z\n\n
fukuokayamaguchi\n\n
fkoaaauh\n
Score : 400 points
\nGiven are integers A, B, and N.
\nFind the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.
\nHere floor(t) denotes the greatest integer not greater than the real number t.
\nInput is given from Standard Input in the following format:
\nA B N\n\n
Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.
\n5 7 4\n\n
2\n\n
When x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.
\n11 10 9\n\n
9\n
Score : 100 points
\nThere is an N-car train.
\nYou are given an integer i. Find the value of j such that the following statement is true: \"the i-th car from the front of the train is the j-th car from the back.\"
\nInput is given from Standard Input in the following format:
\nN i\n\n
Print the answer.
\n4 2\n\n
3\n\n
The second car from the front of a 4-car train is the third car from the back.
\n1 1\n\n
1\n\n
15 11\n\n
5\n
Score : 200 points
\nTakahashi has many red balls and blue balls. Now, he will place them in a row.
\nInitially, there is no ball placed.
\nTakahashi, who is very patient, will do the following operation 10^{100} times:
\nHow many blue balls will be there among the first N balls in the row of balls made this way?
\nInput is given from Standard Input in the following format:
\nN A B\n\n
Print the number of blue balls that will be there among the first N balls in the row of balls.
\n8 3 4\n\n
4\n\n
Let b
denote a blue ball, and r
denote a red ball. The first eight balls in the row will be bbbrrrrb
, among which there are four blue balls.
8 0 4\n\n
0\n\n
He placed only red balls from the beginning.
\n6 2 4\n\n
2\n\n
Among bbrrrr
, there are two blue balls.
Score: 200 points
\nThe restaurant AtCoder serves the following five dishes:
\nHere, the time to serve a dish is the time between when an order is placed and when the dish is delivered.
\nThis restaurant has the following rules on orders:
\nE869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered.
\nHere, he can order the dishes in any order he likes, and he can place an order already at time 0.
Input is given from Standard Input in the following format:
\nA\nB\nC\nD\nE\n\n
Print the earliest possible time for the last dish to be delivered, as an integer.
\n29\n20\n7\n35\n120\n\n
215\n\n
If we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta, ATC Hanbagu, APC Ramen, the earliest possible time for each order is as follows:
\nThere is no way to order the dishes in which the last dish will be delivered earlier than this.
\n101\n86\n119\n108\n57\n\n
481\n\n
If we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC Hanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as follows:
\nThere is no way to order the dishes in which the last dish will be delivered earlier than this.
\n123\n123\n123\n123\n123\n\n
643\n\n
This is the largest valid case.
Score : 100 points
\nTakahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible.\nWhen all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.
\nInput is given from Standard Input in the following format:
\nN K\n\n
Print the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.
\n7 3\n\n
1\n\n
When the users receive two, two and three crackers, respectively, the (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.
\n100 10\n\n
0\n\n
The crackers can be distributed evenly.
\n1 1\n\n
0\n
Score : 100 points
\nThere are N items, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), Item i has a weight of w_i and a value of v_i.
\nTaro has decided to choose some of the N items and carry them home in a knapsack.\nThe capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.
\nFind the maximum possible sum of the values of items that Taro takes home.
\nInput is given from Standard Input in the following format:
\nN W\nw_1 v_1\nw_2 v_2\n:\nw_N v_N\n\n
Print the maximum possible sum of the values of items that Taro takes home.
\n3 8\n3 30\n4 50\n5 60\n\n
90\n\n
Items 1 and 3 should be taken.\nThen, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.
\n1 1000000000\n1000000000 10\n\n
10\n\n
6 15\n6 5\n5 6\n6 4\n6 6\n3 5\n7 2\n\n
17\n\n
Items 2, 4 and 5 should be taken.\nThen, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.
Score : 100 points
\nYou are given a string S as input. This represents a valid date in the year 2019 in the yyyy/mm/dd
format. (For example, April 30, 2019 is represented as 2019/04/30
.)
Write a program that prints Heisei
if the date represented by S is not later than April 30, 2019, and prints TBD
otherwise.
yyyy/mm/dd
format.Input is given from Standard Input in the following format:
\nS\n\n
Print Heisei
if the date represented by S is not later than April 30, 2019, and print TBD
otherwise.
2019/04/30\n\n
Heisei\n\n
2019/11/01\n\n
TBD\n
Score : 400 points
\nGive a pair of integers (A, B) such that A^5-B^5 = X.\nIt is guaranteed that there exists such a pair for the given integer X.
\nInput is given from Standard Input in the following format:
\nX\n\n
Print A and B, with space in between.\nIf there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.
\nA B\n\n
33\n\n
2 -1\n\n
For A=2 and B=-1, A^5-B^5 = 33.
\n1\n\n
0 -1\n
Score : 300 points
\nGiven are N integers A_1,\\ldots,A_N.
\nFind the sum of A_i \\times A_j over all pairs (i,j) such that 1\\leq i < j \\leq N, modulo (10^9+7).
\nInput is given from Standard Input in the following format:
\nN\nA_1 \\ldots A_N\n\n
Print \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7).
\n3\n1 2 3\n\n
11\n\n
We have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.
\n4\n141421356 17320508 22360679 244949\n\n
437235829\n
Score : 200 points
\nAlice and Bob are controlling a robot. They each have one switch that controls the robot.
\nAlice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.
\nBob started holding down his button C second after the start-up, and released his button D second after the start-up.
\nFor how many seconds both Alice and Bob were holding down their buttons?
Input is given from Standard Input in the following format:
\nA B C D\n\n
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.
\n0 75 25 100\n\n
50\n\n
Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.
\nBob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.
\nTherefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.
0 33 66 99\n\n
0\n\n
Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.
\n10 90 20 80\n\n
60\n
Score : 300 points
\nGiven any integer x, Aoki can do the operation below.
\nOperation: Replace x with the absolute difference of x and K.
\nYou are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.
\nInput is given from Standard Input in the following format:
\nN K\n\n
Print the minimum possible value taken by N after Aoki does the operation zero or more times.
\n7 4\n\n
1\n\n
Initially, N=7.
\nAfter one operation, N becomes |7-4| = 3.
\nAfter two operations, N becomes |3-4| = 1, which is the minimum value taken by N.
\n2 6\n\n
2\n\n
N=2 after zero operations is the minimum.
\n1000000000000000000 1\n\n
0\n
Score : 200 points
\nTakahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.
\nGiven is a string S. Find the minimum number of hugs needed to make S palindromic.
\nInput is given from Standard Input in the following format:
\nS\n\n
Print the minimum number of hugs needed to make S palindromic.
\nredcoder\n\n
1\n\n
For example, we can change the fourth character to o
and get a palindrome redooder
.
vvvvvv\n\n
0\n\n
We might need no hugs at all.
\nabcdabc\n\n
2\n
Score : 200 points
\nGiven are strings s and t of length N each, both consisting of lowercase English letters.
\nLet us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.
\nInput is given from Standard Input in the following format:
\nN\nS T\n\n
Print the string formed.
\n2\nip cc\n\n
icpc\n\n
8\nhmhmnknk uuuuuuuu\n\n
humuhumunukunuku\n\n
5\naaaaa aaaaa\n\n
aaaaaaaaaa\n
Score : 200 points
\nWe have a board with H horizontal rows and W vertical columns of squares.\nThere is a bishop at the top-left square on this board.\nHow many squares can this bishop reach by zero or more movements?
\nHere the bishop can only move diagonally.\nMore formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds:
\nFor example, in the following figure, the bishop can move to any of the red squares in one move:
\nInput is given from Standard Input in the following format:
\nH \\ W\n\n
Print the number of squares the bishop can reach.
\n4 5\n\n
10\n\n
The bishop can reach the cyan squares in the following figure:
\n7 3\n\n
11\n\n
The bishop can reach the cyan squares in the following figure:
\n1000000000 1000000000\n\n
500000000000000000\n
Score : 100 points
\nHaving learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.
\nGiven are two integers A and B.
\nIf Takahashi can calculate A \\times B, print the result; if he cannot, print -1
instead.
Input is given from Standard Input in the following format:
\nA B\n\n
If Takahashi can calculate A \\times B, print the result; if he cannot, print -1
.
2 5\n\n
10\n\n
2 \\times 5 = 10.
\n5 10\n\n
-1\n\n
5\\times 10 = 50, but Takahashi cannot do this calculation, so print -1
instead.
9 9\n\n
81\n
Score : 300 points
\nThere are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.
\nAdjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.
\nUltimately, how many slimes will be there?
\nInput is given from Standard Input in the following format:
\nN\nS\n\n
Print the final number of slimes.
\n10\naabbbbaaca\n\n
5\n\n
Ultimately, these slimes will fuse into abaca
.
5\naaaaa\n\n
1\n\n
All the slimes will fuse into one.
\n20\nxxzaffeeeeddfkkkkllq\n\n
10\n
Score : 200 points
\nThere is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.\n(Assume that the positive x-axis points right, and the positive y-axis points up.)
\nTakahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).
\nGiven x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.
\nInput is given from Standard Input in the following format:
\nx_1 y_1 x_2 y_2\n\n
Print x_3,y_3,x_4 and y_4 as integers, in this order.
\n0 0 0 1\n\n
-1 1 -1 0\n\n
(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.\nNote that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.
\n2 3 6 6\n\n
3 10 -1 7\n\n
31 -41 -59 26\n\n
-126 -64 -36 -131\n
Score : 200 points
\nIn 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.
\nIt 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.
\nAssuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.
\nAssume also that the depth of the snow cover is always at least 1 meter.
\nInput is given from Standard Input in the following format:
\na b\n\n
If the depth of the snow cover is x meters, print x as an integer.
\n8 13\n\n
2\n\n
The heights of the two towers are 10 meters and 15 meters, respectively.\nThus, we can see that the depth of the snow cover is 2 meters.
\n54 65\n\n
1\n
Score : 200 points
\nFind the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the largest square number not exceeding N.
\n10\n\n
9\n\n
10 is not square, but 9 = 3 × 3 is. Thus, we print 9.
\n81\n\n
81\n\n
271828182\n\n
271821169\n
Score : 100 points
\nYou are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.
\nAn example of a trapezoid
\nFind the area of this trapezoid.
\nThe input is given from Standard Input in the following format:
\na\nb\nh\n\n
Print the area of the given trapezoid. It is guaranteed that the area is an integer.
\n3\n4\n2\n\n
7\n\n
When the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.
\n4\n4\n4\n\n
16\n\n
In this case, a parallelogram is given, which is also a trapezoid.
Score : 400 points
\nThere are N people standing in a queue from west to east.
\nGiven is a string S of length N representing the directions of the people.\nThe i-th person from the west is facing west if the i-th character of S is L
, and east if that character of S is R
.
A person is happy if the person in front of him/her is facing the same direction.\nIf no person is standing in front of a person, however, he/she is not happy.
\nYou can perform the following operation any number of times between 0 and K (inclusive):
\nOperation: Choose integers l and r such that 1 \\leq l \\leq r \\leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.
\nWhat is the maximum possible number of happy people you can have?
\nL
or R
.Input is given from Standard Input in the following format:
\nN K\nS\n\n
Print the maximum possible number of happy people after at most K operations.
\n6 1\nLRLRRL\n\n
3\n\n
If we choose (l, r) = (2, 5), we have LLLRLL
, where the 2-nd, 3-rd, and 6-th persons from the west are happy.
13 3\nLRRLRLRRLRLLR\n\n
9\n\n
10 1\nLLLLLRRRRR\n\n
9\n\n
9 2\nRRRLRLRLL\n\n
7\n
Score : 100 points
\nYou have three tasks, all of which need to be completed.
\nFirst, you can complete any one task at cost 0.
\nThen, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.
\nHere, |x| denotes the absolute value of x.
\nFind the minimum total cost required to complete all the task.
\nInput is given from Standard Input in the following format:
\nA_1 A_2 A_3\n\n
Print the minimum total cost required to complete all the task.
\n1 6 3\n\n
5\n\n
When the tasks are completed in the following order, the total cost will be 5, which is the minimum:
\n11 5 5\n\n
6\n\n
100 100 100\n\n
0\n
Score : 500 points
\nWe have N bulbs arranged on a number line, numbered 1 to N from left to right.\nBulb i is at coordinate i.
\nEach bulb has a non-negative integer parameter called intensity.\nWhen there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.\nInitially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:
\nFind the intensity of each bulb after the K operations.
\nInput is given from Standard Input in the following format:
\nN K\nA_1 A_2 \\ldots A_N\n\n
Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:
\nA{'}_1 A{'}_2 \\ldots A{'}_N\n\n
5 1\n1 0 0 1 0\n\n
1 2 2 1 2 \n\n
Initially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.\nSimilarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.
\n5 2\n1 0 0 1 0\n\n
3 3 4 4 3 \n
Score : 200 points
\nYou are given nonnegative integers a and b (a ≤ b), and a positive integer x.\nAmong the integers between a and b, inclusive, how many are divisible by x?
\nThe input is given from Standard Input in the following format:
\na b x\n\n
Print the number of the integers between a and b, inclusive, that are divisible by x.
\n4 8 2\n\n
3\n\n
There are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.
\n0 5 1\n\n
6\n\n
There are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.
\n9 9 2\n\n
0\n\n
There are no integer between 9 and 9, inclusive, that is divisible by 2.
\n1 1000000000000000000 3\n\n
333333333333333333\n\n
Watch out for integer overflows.
Score : 300 points
\nThere is an integer sequence A of length N whose values are unknown.
\nGiven is an integer sequence B of length N-1 which is known to satisfy the following:
\nB_i \\geq \\max(A_i, A_{i+1})
\nFind the maximum possible sum of the elements of A.
\nInput is given from Standard Input in the following format:
\nN\nB_1 B_2 ... B_{N-1}\n\n
Print the maximum possible sum of the elements of A.
\n3\n2 5\n\n
9\n\n
A can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.
\n2\n3\n\n
6\n\n
6\n0 153 10 10 23\n\n
53\n
Score : 100 points
\nThere are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively.\nPrint Yes
if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print No
otherwise.
Input is given from Standard Input in the following format:
\nA B C\n\n
Print Yes
if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print No
otherwise.
3 8 5\n\n
Yes\n\n
We pass the coordinate 5 on the straight way from the house at coordinate 3 to the house at coordinate 8.
\n7 3 1\n\n
No\n\n
10 2 4\n\n
Yes\n\n
31 41 59\n\n
No\n
Score : 100 points
\nYou are given an integer K.\nPrint the string obtained by repeating the string ACL
K times and concatenating them.
For example, if K = 3, print ACLACLACL
.
Input is given from Standard Input in the following format:
\nK\n\n
Print the string obtained by repeating the string ACL
K times and concatenating them.
3\n\n
ACLACLACL\n
Score : 100 points
\nPrint the K-th element of the following sequence of length 32:
\n1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51\n\n
Input is given from Standard Input in the following format:
\nK\n\n
Print the K-th element.
\n6\n\n
2\n\n
The 6-th element is 2.
\n27\n\n
5\n\n
The 27-th element is 5.
Score : 100 points
\nYou are given a grid with 2 rows and 3 columns of squares.\nThe color of the square at the i-th row and j-th column is represented by the character C_{ij}.
\nWrite a program that prints YES
if this grid remains the same when rotated 180 degrees, and prints NO
otherwise.
Input is given from Standard Input in the following format:
\nC_{11}C_{12}C_{13}\nC_{21}C_{22}C_{23}\n\n
Print YES
if this grid remains the same when rotated 180 degrees; print NO
otherwise.
pot\ntop\n\n
YES\n\n
This grid remains the same when rotated 180 degrees.
\ntab\nbet\n\n
NO\n\n
This grid does not remain the same when rotated 180 degrees.
\neye\neel\n\n
NO\n
Score : 100 points
\nYou have decided to give an allowance to your child depending on the outcome of the game that he will play now.
\nThe game is played as follows:
\n+
printed on it.Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.
\nInput is given from Standard Input in the following format:
\nA B C\n\n
Print the maximum possible amount of the allowance.
\n1 5 2\n\n
53\n\n
The amount of the allowance will be 53 when the panels are arranged as 52+1
, and this is the maximum possible amount.
9 9 9\n\n
108\n\n
6 6 7\n\n
82\n
Score : 300 points
\nThere are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
\nFor each square, you will perform either of the following operations once:
\nDetermine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.
\nInput is given from Standard Input in the following format:
\nN\nH_1 H_2 ... H_N\n\n
If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print Yes
; otherwise, print No
.
5\n1 2 1 1 3\n\n
Yes\n\n
You can achieve the objective by decreasing the height of only the second square from the left by 1.
\n4\n1 3 2 1\n\n
No\n\n
5\n1 2 3 4 5\n\n
Yes\n\n
1\n1000000000\n\n
Yes\n
Score : 200 points
\nTakahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.
\nThe problem has N test cases.
\nFor each test case i (1\\leq i \\leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is AC
, WA
, TLE
, and RE
, respectively.
See the Output section for the output format.
\nAC
, WA
, TLE
, or RE
.Input is given from Standard Input in the following format:
\nN\nS_1\n\\vdots\nS_N\n\n
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is AC
, WA
, TLE
, and RE
, respectively. Print the following:
AC x C_0\nWA x C_1\nTLE x C_2\nRE x C_3\n\n
6\nAC\nTLE\nAC\nAC\nWA\nTLE\n\n
AC x 3\nWA x 1\nTLE x 2\nRE x 0\n\n
We have 3, 1, 2, and 0 test case(s) for which the verdict is AC
, WA
, TLE
, and RE
, respectively.
10\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\n\n
AC x 10\nWA x 0\nTLE x 0\nRE x 0\n
Score : 300 points
\nThere are N cities on a number line. The i-th city is located at coordinate x_i.
\nYour objective is to visit all these cities at least once.
\nIn order to do so, you will first set a positive integer D.
\nThen, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:
\nFind the maximum value of D that enables you to visit all the cities.
\nHere, to visit a city is to travel to the coordinate where that city is located.
\nInput is given from Standard Input in the following format:
\nN X\nx_1 x_2 ... x_N\n\n
Print the maximum value of D that enables you to visit all the cities.
\n3 3\n1 7 11\n\n
2\n\n
Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.
\n3 81\n33 105 57\n\n
24\n\n
1 1\n1000000000\n\n
999999999\n
Score : 300 points
\nThe commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word \"bill\" refers to only these.
\nAccording 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.
\nInput is given from Standard Input in the following format:
\nN Y\n\n
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.
\n9 45000\n\n
4 0 5\n\n
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.
20 196000\n\n
-1 -1 -1\n\n
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.
\n1000 1234000\n\n
14 27 959\n\n
There are also many other possibilities.
\n2000 20000000\n\n
2000 0 0\n
Score: 100 points
\nTakahashi is solving quizzes. He has easily solved all but the last one.
\nThe last quiz has three choices: 1, 2, and 3.
\nWith his supernatural power, Takahashi has found out that the choices A and B are both wrong.
\nPrint the correct choice for this problem.
\nInput is given from Standard Input in the following format:
\nA\nB\n\n
Print the correct choice.
\n3\n1\n\n
2\n\n
When we know 3 and 1 are both wrong, the correct choice is 2.
\n1\n2\n\n
3\n
Score : 100 points
\nA string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.
\nGiven a string S, determine whether it is coffee-like.
Input is given from Standard Input in the following format:
\nS\n\n
If S is coffee-like, print Yes
; otherwise, print No
.
sippuu\n\n
Yes\n\n
In sippuu
, the 3-rd and 4-th characters are equal, and the 5-th and 6-th characters are also equal.
iphone\n\n
No\n\n
coffee\n\n
Yes\n
Score: 400 points
\nThere is a cave.
\nThe cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.
\nIt is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.
\nSince it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.
\nDetermine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
\nInput is given from Standard Input in the following format:
\nN M\nA_1 B_1\n:\nA_M B_M\n\n
If there is no way to place signposts satisfying the objective, print No
.
Otherwise, print N lines. The first line should contain Yes
, and the i-th line (2 \\leq i \\leq N) should contain the integer representing the room indicated by the signpost in Room i.
4 4\n1 2\n2 3\n3 4\n4 2\n\n
Yes\n1\n2\n2\n\n
If we place the signposts as described in the sample output, the following happens:
\nThus, the objective is satisfied.
\n6 9\n3 4\n6 1\n2 4\n5 3\n4 6\n1 5\n6 2\n4 5\n5 6\n\n
Yes\n6\n5\n5\n1\n1\n\n
If there are multiple solutions, any of them will be accepted.
Score : 400 points
\nTakahashi has a string S consisting of lowercase English letters.
\nStarting with this string, he will produce a new one in the procedure given as follows.
\nThe procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:
\nIf T_i = 1: reverse the string S.
\nIf T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.
\nHelp Takahashi by finding the final string that results from the procedure.
\nInput is given from Standard Input in the following format:
\nS\nQ\nQuery_1\n:\nQuery_Q\n\n
In the 3-rd through the (Q+2)-th lines, Query_i is one of the following:
\n1\n\n
which means T_i = 1, and:
\n2 F_i C_i\n\n
which means T_i = 2.
\nPrint the resulting string.
\na\n4\n2 1 p\n1\n2 2 c\n1\n\n
cpa\n\n
There will be Q = 4 operations. Initially, S is a
.
Operation 1: Add p
at the beginning of S. S becomes pa
.
Operation 2: Reverse S. S becomes ap
.
Operation 3: Add c
at the end of S. S becomes apc
.
Operation 4: Reverse S. S becomes cpa
.
Thus, the resulting string is cpa
.
a\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n\n
aabc\n\n
There will be Q = 6 operations. Initially, S is a
.
Operation 1: S becomes aa
.
Operation 2: S becomes baa
.
Operation 3: S becomes aab
.
Operation 4: S becomes aabc
.
Operation 5: S becomes cbaa
.
Operation 6: S becomes aabc
.
Thus, the resulting string is aabc
.
y\n1\n2 1 x\n\n
xy\n
Score: 100 points
\nThe cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.
\nWhen counting pencils in Japanese, the counter word \"本\" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of \"本\" in the phrase \"N 本\" for a positive integer N not exceeding 999 is as follows:
\nhon
when the digit in the one's place of N is 2, 4, 5, 7, or 9;pon
when the digit in the one's place of N is 0, 1, 6 or 8;bon
when the digit in the one's place of N is 3.Given N, print the pronunciation of \"本\" in the phrase \"N 本\".
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the answer.
\n16\n\n
pon\n\n
The digit in the one's place of 16 is 6, so the \"本\" in \"16 本\" is pronounced pon
.
2\n\n
hon\n\n
183\n\n
bon\n
Score : 300 points
\nThere are N people living on a number line.
\nThe i-th person lives at coordinate X_i.
\nYou are going to hold a meeting that all N people have to attend.
\nThe meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.
\nFind the minimum total points of stamina the N people have to spend.
\nInput is given from Standard Input in the following format:
\nN\nX_1 X_2 ... X_N\n\n
Print the minimum total stamina the N people have to spend.
\n2\n1 4\n\n
5\n\n
Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.
\nNote that you can hold the meeting only at an integer coordinate.
\n7\n14 14 2 13 56 2 37\n\n
2354\n
Score : 300 points
\nThere is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.\nHe can climb up one or two steps at a time.
\nHowever, the treads of the a_1-th, a_2-th, a_3-th, \\ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.
\nHow many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps?\nFind the count modulo 1\\ 000\\ 000\\ 007.
\nInput is given from Standard Input in the following format:
\nN M\na_1\na_2\n .\n .\n .\na_M\n\n
Print the number of ways to climb up the stairs under the condition, modulo 1\\ 000\\ 000\\ 007.
\n6 1\n3\n\n
4\n\n
There are four ways to climb up the stairs, as follows:
\n10 2\n4\n5\n\n
0\n\n
There may be no way to climb up the stairs without setting foot on the broken steps.
\n100 5\n1\n23\n45\n67\n89\n\n
608200469\n\n
Be sure to print the count modulo 1\\ 000\\ 000\\ 007.
Score : 300 points
\nTakahashi is organizing a party.
\nAt the party, each guest will receive one or more snack pieces.
\nTakahashi predicts that the number of guests at this party will be A or B.
\nFind the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.
\nWe assume that a piece cannot be divided and distributed to multiple guests.
\nInput is given from Standard Input in the following format:
\nA B\n\n
Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests.
\n2 3\n\n
6\n\n
When we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.
\n123 456\n\n
18696\n\n
100000 99999\n\n
9999900000\n
Score : 100 points
\nYou will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.
\nThe current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?
\nInput is given from Standard Input in the following format:
\nX\n\n
Print Yes
if you will turn on the air conditioner; print No
otherwise.
25\n\n
No\n\n
30\n\n
Yes\n
Score : 100 points
\nThere are N stones, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), the height of Stone i is h_i.
\nThere is a frog who is initially on Stone 1.\nHe will repeat the following action some number of times to reach Stone N:
\nFind the minimum possible total cost incurred before the frog reaches Stone N.
\nInput is given from Standard Input in the following format:
\nN K\nh_1 h_2 \\ldots h_N\n\n
Print the minimum possible total cost incurred.
\n5 3\n10 30 40 50 20\n\n
30\n\n
If we follow the path 1 → 2 → 5, the total cost incurred would be |10 - 30| + |30 - 20| = 30.
\n3 1\n10 20 10\n\n
20\n\n
If we follow the path 1 → 2 → 3, the total cost incurred would be |10 - 20| + |20 - 10| = 20.
\n2 100\n10 10\n\n
0\n\n
If we follow the path 1 → 2, the total cost incurred would be |10 - 10| = 0.
\n10 4\n40 10 20 70 80 10 20 70 80 60\n\n
40\n\n
If we follow the path 1 → 4 → 8 → 10, the total cost incurred would be |40 - 70| + |70 - 70| + |70 - 60| = 40.
Score : 100 points
\nN of us are going on a trip, by train or taxi.
\nThe train will cost each of us A yen (the currency of Japan).
\nThe taxi will cost us a total of B yen.
\nHow much is our minimum total travel expense?
\nInput is given from Standard Input in the following format:
\nN A B\n\n
Print an integer representing the minimum total travel expense.
\n4 2 9\n\n
8\n\n
The train will cost us 4 \\times 2 = 8 yen, and the taxi will cost us 9 yen, so the minimum total travel expense is 8 yen.
\n4 2 7\n\n
7\n\n
4 2 8\n\n
8\n
Score : 100 points
\nSnuke is going to open a contest named \"AtCoder s Contest\".\nHere, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
\nSnuke has decided to abbreviate the name of the contest as \"AxC\".\nHere, x is the uppercase English letter at the beginning of s.
\nGiven the name of the contest, print the abbreviation of the name.
\nThe input is given from Standard Input in the following format:
\nAtCoder s Contest\n\n
Print the abbreviation of the name of the contest.
\nAtCoder Beginner Contest\n\n
ABC\n\n
The contest in which you are participating now.
\nAtCoder Snuke Contest\n\n
ASC\n\n
This contest does not actually exist.
\nAtCoder X Contest\n\n
AXC\n
Score : 300 points
\nYou are given an integer N.
\nFor two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B.
\nFor example, F(3,11) = 2 since 3 has one digit and 11 has two digits.
\nFind the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \\times B.
The input is given from Standard Input in the following format:
\nN\n\n
Print the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \\times B.
\n10000\n\n
3\n\n
F(A,B) has a minimum value of 3 at (A,B)=(100,100).
\n1000003\n\n
7\n\n
There are two pairs (A,B) that satisfy the condition: (1,1000003) and (1000003,1). For these pairs, F(1,1000003)=F(1000003,1)=7.
\n9876543210\n\n
6\n
Score : 300 points
\nTakahashi has N balls. Initially, an integer A_i is written on the i-th ball.
\nHe would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.
\nFind the minimum number of balls that Takahashi needs to rewrite the integers on them.
\nInput is given from Standard Input in the following format:
\nN K\nA_1 A_2 ... A_N\n\n
Print the minimum number of balls that Takahashi needs to rewrite the integers on them.
\n5 2\n1 1 2 2 5\n\n
1\n\n
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.\nOn 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.
\n4 4\n1 1 2 2\n\n
0\n\n
Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.
\n10 3\n5 1 3 2 4 1 1 2 3 4\n\n
3\n
Score : 500 points
\nThere are N Snuke Cats numbered 1, 2, \\ldots, N, where N is even.
\nEach Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.
\nRecently, they learned the operation called xor (exclusive OR).
\n\nFor n non-negative integers x_1, x_2, \\ldots, x_n, their xor, x_1~\\textrm{xor}~x_2~\\textrm{xor}~\\ldots~\\textrm{xor}~x_n is defined as follows:\n
They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.
\nWe know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i.\nUsing this information, restore the integer written on the scarf of each Snuke Cat.
\nInput is given from Standard Input in the following format:
\nN\na_1 a_2 \\ldots a_N\n\n
Print a line containing N integers separated with space.
\nThe i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.
\nIf there are multiple possible solutions, you may print any of them.
\n4\n20 11 9 24\n\n
26 5 7 22\n\n
Thus, this output is consistent with the given information.
Score : 100 points
\nThere are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
\nThe input is given from Standard Input in the following format:
\nN\n\n
Print the necessary number of candies in total.
\n3\n\n
6\n\n
The answer is 1+2+3=6.
\n10\n\n
55\n\n
The sum of the integers from 1 to 10 is 55.
\n1\n\n
1\n\n
Only one child. The answer is 1 in this case.
Score : 200 points
\nWe have N weights indexed 1 to N. The \bmass of the weight indexed i is W_i.
\nWe will divide these weights into two groups: the weights with indices not greater than T, and those with indices greater than T, for some integer 1 \\leq T < N. Let S_1 be the sum of the masses of the weights in the former group, and S_2 be the sum of the masses of the weights in the latter group.
\nConsider all possible such divisions and find the minimum possible absolute difference of S_1 and S_2.
\nInput is given from Standard Input in the following format:
\nN\nW_1 W_2 ... W_{N-1} W_N\n\n
Print the minimum possible absolute difference of S_1 and S_2.
\n3\n1 2 3\n\n
0\n\n
If T = 2, S_1 = 1 + 2 = 3 and S_2 = 3, with the absolute difference of 0.
\n4\n1 3 1 1\n\n
2\n\n
If T = 2, S_1 = 1 + 3 = 4 and S_2 = 1 + 1 = 2, with the absolute difference of 2. We cannot have a smaller absolute difference.
\n8\n27 23 76 2 3 5 62 52\n\n
2\n
Score : 200 points
\nYou are given string S and T consisting of lowercase English letters.
\nDetermine if S equals T after rotation.
\nThat is, determine if S equals T after the following operation is performed some number of times:
\nOperation: Let S = S_1 S_2 ... S_{|S|}. Change S to S_{|S|} S_1 S_2 ... S_{|S|-1}.
\nHere, |X| denotes the length of the string X.
\nInput is given from Standard Input in the following format:
\nS\nT\n\n
If S equals T after rotation, print Yes
; if it does not, print No
.
kyoto\ntokyo\n\n
Yes\n\n
kyoto
becomes okyot
.okyot
becomes tokyo
.abc\narc\n\n
No\n\n
abc
does not equal arc
after any number of operations.
aaaaaaaaaaaaaaab\naaaaaaaaaaaaaaab\n\n
Yes\n
Score : 200 points
\nFind the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
\nInput is given from Standard Input in the following format:
\nN A B\n\n
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).
\n20 2 5\n\n
84\n\n
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.
\n10 1 2\n\n
13\n\n
100 4 16\n\n
4554\n
Score : 100 points
\nThere are N items, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), Item i has a weight of w_i and a value of v_i.
\nTaro has decided to choose some of the N items and carry them home in a knapsack.\nThe capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.
\nFind the maximum possible sum of the values of items that Taro takes home.
\nInput is given from Standard Input in the following format:
\nN W\nw_1 v_1\nw_2 v_2\n:\nw_N v_N\n\n
Print the maximum possible sum of the values of items that Taro takes home.
\n3 8\n3 30\n4 50\n5 60\n\n
90\n\n
Items 1 and 3 should be taken.\nThen, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.
\n5 5\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n\n
5000000000\n\n
The answer may not fit into a 32-bit integer type.
\n6 15\n6 5\n5 6\n6 4\n6 6\n3 5\n7 2\n\n
17\n\n
Items 2, 4 and 5 should be taken.\nThen, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.
Score : 200 points
\nTakahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \\ldots, Dish N) once.
\nThe i-th dish (1 \\leq i \\leq N) he ate was Dish A_i.
\nWhen he eats Dish i (1 \\leq i \\leq N), he gains B_i satisfaction points.
\nAdditionally, when he eats Dish i+1 just after eating Dish i (1 \\leq i \\leq N - 1), he gains C_i more satisfaction points.
\nFind the sum of the satisfaction points he gained.
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 ... A_N\nB_1 B_2 ... B_N\nC_1 C_2 ... C_{N-1}\n\n
Print the sum of the satisfaction points Takahashi gained, as an integer.
\n3\n3 1 2\n2 5 4\n3 6\n\n
14\n\n
Takahashi gained 14 satisfaction points in total, as follows:
\n4\n2 3 4 1\n13 5 8 24\n45 9 15\n\n
74\n\n
2\n1 2\n50 50\n50\n\n
150\n
Score : 300 points
\nN tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.
\nThe i-th tile from the left is painted black if the i-th character of S is 0
, and painted white if that character is 1
.
You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.
\nAt least how many tiles need to be repainted to satisfy the condition?
\n0
or 1
.Input is given from Standard Input in the following format:
\nS\n\n
Print the minimum number of tiles that need to be repainted to satisfy the condition.
\n000\n\n
1\n\n
The condition can be satisfied by repainting the middle tile white.
\n10010010\n\n
3\n\n
0\n\n
0\n
Score : 400 points
\nGiven is a string S consisting of digits from 1
through 9
.
Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:
\nCondition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.
\n1
through 9
.Input is given from Standard Input in the following format:
\nS\n\n
Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.
\n1817181712114\n\n
3\n\n
Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.
\n14282668646\n\n
2\n\n
2119\n\n
0\n\n
No pairs satisfy the condition.
Score : 300 points
\nFind the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.)
\nHere, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer.
\nIf multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print -1
.
Input is given from Standard Input in the following format:
\nA B\n\n
If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print -1
.
2 2\n\n
25\n\n
If the price of a product before tax is 25 yen, the amount of consumption tax levied on it is:
\nThus, the price of 25 yen satisfies the condition. There are other possible prices, such as 26 yen, but print the minimum such price, 25.
\n8 10\n\n
100\n\n
If the price of a product before tax is 100 yen, the amount of consumption tax levied on it is:
\n19 99\n\n
-1\n\n
There is no price before tax satisfying this condition, so print -1
.
Score : 200 points
\nThere are N mountains ranging from east to west, and an ocean to the west.
\nAt the top of each mountain, there is an inn. You have decided to choose where to stay from these inns.
\nThe height of the i-th mountain from the west is H_i.
\nYou can certainly see the ocean from the inn at the top of the westmost mountain.
\nFor the inn at the top of the i-th mountain from the west (i = 2, 3, ..., N), you can see the ocean if and only if H_1 \\leq H_i, H_2 \\leq H_i, ..., and H_{i-1} \\leq H_i.
\nFrom how many of these N inns can you see the ocean?
\nInput is given from Standard Input in the following format:
\nN\nH_1 H_2 ... H_N\n\n
Print the number of inns from which you can see the ocean.
\n4\n6 5 6 8\n\n
3\n\n
You can see the ocean from the first, third and fourth inns from the west.
\n5\n4 5 3 5 4\n\n
3\n\n
5\n9 5 6 8 4\n\n
1\n
Score : 400 points
\nWe have a string S of length N consisting of R
, G
, and B
.
Find the number of triples (i,~j,~k)~(1 \\leq i < j < k \\leq N) that satisfy both of the following conditions:
\nR
, G
, and B
.Input is given from Standard Input in the following format:
\nN\nS\n\n
Print the number of triplets in question.
\n4\nRRGB\n\n
1\n\n
Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.
\n39\nRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB\n\n
1800\n
Score : 200 points
\nYou are given positive integers A and B.
\nFind the K-th largest positive integer that divides both A and B.
\nThe input guarantees that there exists such a number.
\nInput is given from Standard Input in the following format:
\nA B K\n\n
Print the K-th largest positive integer that divides both A and B.
\n8 12 2\n\n
2\n\n
Three positive integers divides both 8 and 12: 1, 2 and 4.\nAmong them, the second largest is 2.
\n100 50 4\n\n
5\n\n
1 1 1\n\n
1\n
Score : 100 points
\nBased on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.\nGiven two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
\nInput is given from Standard Input in the following format:
\nx y\n\n
If x and y belong to the same group, print Yes
; otherwise, print No
.
1 3\n\n
Yes\n\n
2 4\n\n
No\n
Score : 300 points
\nThere are N people standing in a row from west to east.\nEach person is facing east or west.\nThe directions of the people is given as a string S of length N.\nThe 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.\nHere, we do not care which direction the leader is facing.
\nThe 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.\nFind the minimum number of people who have to change their directions.
\nE
or W
.Input is given from Standard Input in the following format:
\nN\nS\n\n
Print the minimum number of people who have to change their directions.
\n5\nWEEWW\n\n
1\n\n
Assume that we appoint the third person from the west as the leader.\nThen, the first person from the west needs to face east and has to turn around.\nThe 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.\nIt is not possible to have 0 people who have to change their directions, so the answer is 1.
\n12\nWEWEWEEEWWWE\n\n
4\n\n
8\nWWWWWEEE\n\n
3\n
Score : 300 points
\n1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:
\na
, b
, ..., z
;aa
, ab
, ac
, ..., zy
, zz
;aaa
, aab
, aac
, ..., zzy
, zzz
;aaaa
, aaab
, aaac
, ..., zzzy
, zzzz
;aaaaa
, aaaab
, ...;To sum it up, the dogs numbered 1, 2, \\cdots were respectively given the following names:
\na
, b
, ..., z
, aa
, ab
, ..., az
, ba
, bb
, ..., bz
, ..., za
, zb
, ..., zz
, aaa
, aab
, ..., aaz
, aba
, abb
, ..., abz
, ..., zzz
, aaaa
, ...
Now, Roger asks you:
\n\"What is the name for the dog numbered N?\"
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the answer to Roger's question as a string consisting of lowercase English letters.
\n2\n\n
b\n\n
27\n\n
aa\n\n
123456789\n\n
jjddja\n
Score : 200 points
\nAn integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9.
\nDetermine whether N is a multiple of 9.
\nInput is given from Standard Input in the following format:
\nN\n\n
If N is a multiple of 9, print Yes
; otherwise, print No
.
123456789\n\n
Yes\n\n
The sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so 123456789 is a multiple of 9.
\n0\n\n
Yes\n\n
31415926535897932384626433832795028841971693993751058209749445923078164062862089986280\n\n
No\n
Score : 100 points
\nShichi-Go-San (literally \"Seven-Five-Three\") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
\nTakahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?
\nInput is given from Standard Input in the following format:
\nX\n\n
If Takahashi's growth will be celebrated, print YES
; if it will not, print NO
.
5\n\n
YES\n\n
The growth of a five-year-old child will be celebrated.
\n6\n\n
NO\n\n
See you next year.
Score : 100 points
\nJoisino wants to evaluate the formula \"A op B\".\nHere, A and B are integers, and the binary operator op is either +
or -
.\nYour task is to evaluate the formula instead of her.
+
or -
.The input is given from Standard Input in the following format:
\nA op B\n\n
Evaluate the formula and print the result.
\n1 + 2\n\n
3\n\n
Since 1 + 2 = 3, the output should be 3.
\n5 - 7\n\n
-2\n
Score : 100 points
\nCompute A \\times B.
\nInput is given from Standard Input in the following format:
\nA B\n\n
Print the value A \\times B as an integer.
\n2 5\n\n
10\n\n
We have 2 \\times 5 = 10.
\n100 100\n\n
10000\n
Score : 100 points
\nTwo deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest.\nIn this game, an honest player always tells the truth, and an dishonest player always tell lies.\nYou are given two characters a and b as the input. Each of them is either H
or D
, and carries the following information:
If a=H
, AtCoDeer is honest; if a=D
, AtCoDeer is dishonest.\nIf b=H
, AtCoDeer is saying that TopCoDeer is honest; if b=D
, AtCoDeer is saying that TopCoDeer is dishonest.
Given this information, determine whether TopCoDeer is honest.
\nH
or a=D
.H
or b=D
.The input is given from Standard Input in the following format:
\na b\n\n
If TopCoDeer is honest, print H
. If he is dishonest, print D
.
H H\n\n
H\n\n
In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.
\nD H\n\n
D\n\n
In this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest.
\nD D\n\n
H\n
Score : 200 points
\nGiven are two strings S and T.
\nLet us change some of the characters in S so that T will be a substring of S.
\nAt least how many characters do we need to change?
\nHere, a substring is a consecutive subsequence. For example, xxx
is a substring of yxxxy
, but not a substring of xxyxx
.
Input is given from Standard Input in the following format:
\nS\nT\n\n
Print the minimum number of characters in S that need to be changed.
\ncabacc\nabc\n\n
1\n\n
For example, changing the fourth character a
in S to c
will match the second through fourth characters in S to T.
Since S itself does not have T as its substring, this number of changes - one - is the minimum needed.
\ncodeforces\natcoder\n\n
6\n
Score : 300 points
\nYou are given a string S of length N consisting of A
, C
, G
and T
. Answer the following Q queries:
AC
occurs as a substring?A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.
\nFor example, the substrings of ATCODER
include TCO
, AT
, CODER
, ATCODER
and (the empty string), but not
AC
.
A
, C
, G
or T
.Input is given from Standard Input in the following format:
\nN Q\nS\nl_1 r_1\n:\nl_Q r_Q\n\n
Print Q lines. The i-th line should contain the answer to the i-th query.
\n8 3\nACACTACG\n3 7\n2 3\n1 8\n\n
2\n0\n3\n\n
ACTAC
. In this string, AC
occurs twice as a substring.CA
. In this string, AC
occurs zero times as a substring.ACACTACG
. In this string, AC
occurs three times as a substring.Score : 300 points
\nLet f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:
\nGiven an integer N, find each of f(1),f(2),f(3),\\ldots,f(N).
\nInput is given from Standard Input in the following format:
\nN\n\n
Print N lines. The i-th line should contain the value f(i).
\n20\n\n
0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n\n
Score : 200 points
\nYou have a digit sequence S of length 4. You are wondering which of the following formats S is in:
\n01
for January), concatenated in this orderIf S is valid in only YYMM format, print YYMM
; if S is valid in only MMYY format, print MMYY
; if S is valid in both formats, print AMBIGUOUS
; if S is valid in neither format, print NA
.
Input is given from Standard Input in the following format:
\nS\n\n
Print the specified string: YYMM
, MMYY
, AMBIGUOUS
or NA
.
1905\n\n
YYMM\n\n
May XX19 is a valid date, but 19 is not valid as a month. Thus, this string is only valid in YYMM format.
\n0112\n\n
AMBIGUOUS\n\n
Both December XX01 and January XX12 are valid dates. Thus, this string is valid in both formats.
\n1700\n\n
NA\n\n
Neither 0 nor 17 is valid as a month. Thus, this string is valid in neither format.
Score : 200 points
\nSome number of chocolate pieces were prepared for a training camp.\nThe camp had N participants and lasted for D days.\nThe 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.\nAs a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.
\nFind the number of chocolate pieces prepared at the beginning of the camp.
\nInput is given from Standard Input in the following format:
\nN\nD X\nA_1\nA_2\n:\nA_N\n\n
Find the number of chocolate pieces prepared at the beginning of the camp.
\n3\n7 1\n2\n5\n10\n\n
8\n\n
The camp has 3 participants and lasts for 7 days.\nEach 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.
\n2\n8 20\n1\n10\n\n
29\n\n
5\n30 44\n26\n18\n81\n18\n6\n\n
56\n
Score : 300 points
\nThere are N cubes stacked vertically on a desk.
\nYou are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0
, and blue if that character is 1
.
You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.
\nAt most how many cubes can be removed?
\n0
or 1
.Input is given from Standard Input in the following format:
\nS\n\n
Print the maximum number of cubes that can be removed.
\n0011\n\n
4\n\n
All four cubes can be removed, by performing the operation as follows:
\n11011010001011\n\n
12\n\n
0\n\n
0\n
Score : 100 points
\nIn order to pass the entrance examination tomorrow, Taro has to study for T more hours.
\nFortunately, he can leap to World B where time passes X times as fast as it does in our world (World A).
\nWhile (X \\times t) hours pass in World B, t hours pass in World A.
\nHow many hours will pass in World A while Taro studies for T hours in World B?
\nInput is given from Standard Input in the following format:
\nT X\n\n
Print the number of hours that will pass in World A.
\nThe output will be regarded as correct when its absolute or relative error from the judge's output is at most 10^{-3}.
\n8 3\n\n
2.6666666667\n\n
While Taro studies for eight hours in World B where time passes three times as fast, 2.6666... hours will pass in World A.
\nNote that an absolute or relative error of at most 10^{-3} is allowed.
\n99 1\n\n
99.0000000000\n\n
1 100\n\n
0.0100000000\n
Score : 300 points
\nYou are given two non-negative integers L and R.\nWe will choose two integers i and j such that L \\leq i < j \\leq R.\nFind the minimum possible value of (i \\times j) \\mbox{ mod } 2019.
\nInput is given from Standard Input in the following format:
\nL R\n\n
Print the minimum possible value of (i \\times j) \\mbox{ mod } 2019 when i and j are chosen under the given condition.
\n2020 2040\n\n
2\n\n
When (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.
\n4 5\n\n
20\n\n
We have only one choice: (i, j) = (4, 5).
Score : 300 points
\nThere are N stones arranged in a row. Every stone is painted white or black.\nA string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is .
, and the stone is black if the character is #
.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.\nFind the minimum number of stones that needs to be recolored.
\n.
and #
.Input is given from Standard Input in the following format:
\nN\nS\n\n
Print the minimum number of stones that needs to be recolored.
\n3\n#.#\n\n
1\n\n
It is enough to change the color of the first stone to white.
\n5\n#.##.\n\n
2\n\n
9\n.........\n\n
0\n
Score : 100 points
\nServal is fighting with a monster.
\nThe health of the monster is H.
\nIn one attack, Serval can decrease the monster's health by A.\nThere is no other way to decrease the monster's health.
\nServal wins when the monster's health becomes 0 or below.
\nFind the number of attacks Serval needs to make before winning.
\nInput is given from Standard Input in the following format:
\nH A\n\n
Print the number of attacks Serval needs to make before winning.
\n10 4\n\n
3\n\n
Thus, Serval needs to make three attacks to win.
\n1 10000\n\n
1\n\n
10000 1\n\n
10000\n
Score : 300 points
\nGiven is a sequence of integers A_1, A_2, ..., A_N.\nIf its elements are pairwise distinct, print YES
; otherwise, print NO
.
Input is given from Standard Input in the following format:
\nN\nA_1 ... A_N\n\n
If the elements of the sequence are pairwise distinct, print YES
; otherwise, print NO
.
5\n2 6 1 4 5\n\n
YES\n\n
The elements are pairwise distinct.
\n6\n4 1 3 1 6 2\n\n
NO\n\n
The second and fourth elements are identical.
\n2\n10000000 10000000\n\n
NO\n
Score : 200 points
\nThere is a string S consisting of digits 1
, 2
, ..., 9
.\nLunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better.\nWhat is the minimum possible (absolute) difference between X and 753?
\n1
, 2
, ..., or 9
.Input is given from Standard Input in the following format:
\nS\n\n
Print the minimum possible difference between X and 753.
\n1234567876\n\n
34\n\n
Taking out the seventh to ninth characters results in X = 787, and the difference between this and 753 is 787 - 753 = 34. The difference cannot be made smaller, no matter where X is taken from.
\nNote that the digits cannot be rearranged. For example, taking out 567
and rearranging it to 765
is not allowed.
We cannot take out three digits that are not consecutive from S, either. For example, taking out the seventh digit 7
, the ninth digit 7
and the tenth digit 6
to obtain 776
is not allowed.
35753\n\n
0\n\n
If 753
itself can be taken out, the answer is 0.
1111111111\n\n
642\n\n
No matter where X is taken from, X = 111, with the difference 753 - 111 = 642.
Score : 200 points
\nGiven is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the number of positive integers less than or equal to N that have an odd number of digits.
\n11\n\n
9\n\n
Among the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \\ldots, 9.
\n136\n\n
46\n\n
In addition to 1, 2, \\ldots, 9, another 37 integers also have an odd number of digits: 100, 101, \\ldots, 136.
\n100000\n\n
90909\n
Score : 200 points
\nTakahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.
\nThe bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)
\nAssuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
\nInput is given from Standard Input in the following format:
\nX\n\n
Print the number of years it takes for Takahashi's balance to reach X yen or above for the first time.
\n103\n\n
3\n\n
Thus, it takes three years for the balance to reach 103 yen or above.
\n1000000000000000000\n\n
3760\n\n
1333333333\n\n
1706\n
Score : 100 points
\nTakahashi loves takoyaki - a ball-shaped snack.
\nWith a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.
\nHow long does it take to make N takoyaki?
\nInput is given from Standard Input in the following format:
\nN X T\n\n
Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.
\n20 12 6\n\n
12\n\n
He can make 12 pieces of takoyaki in the first 6 minutes and 8 more in the next 6 minutes, so he can make 20 in a total of 12 minutes.
\nNote that being able to make 12 in 6 minutes does not mean he can make 2 in 1 minute.
\n1000 1 1000\n\n
1000000\n\n
It seems to take a long time to make this kind of takoyaki.
Score : 300 points
\nA sequence a_1,a_2,... ,a_n is said to be /\\/\\/\\/ when the following conditions are satisfied:
\nYou are given a sequence v_1,v_2,...,v_n whose length is even.\nWe would like to make this sequence /\\/\\/\\/ by replacing some of its elements.\nFind the minimum number of elements that needs to be replaced.
\nInput is given from Standard Input in the following format:
\nn\nv_1 v_2 ... v_n\n\n
Print the minimum number of elements that needs to be replaced.
\n4\n3 1 3 2\n\n
1\n\n
The sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.
\n6\n105 119 105 119 105 119\n\n
0\n\n
The sequence 105,119,105,119,105,119 is /\\/\\/\\/.
\n4\n1 1 1 1\n\n
2\n\n
The elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/.
Score : 200 points
\nThere are N apple trees in a row. People say that one of them will bear golden apples.
\nWe want to deploy some number of inspectors so that each of these trees will be inspected.
\nEach inspector will be deployed under one of the trees. For convenience, we will assign numbers from 1 through N to the trees. An inspector deployed under the i-th tree (1 \\leq i \\leq N) will inspect the trees with numbers between i-D and i+D (inclusive).
\nFind the minimum number of inspectors that we need to deploy to achieve the objective.
\nInput is given from Standard Input in the following format:
\nN D\n\n
Print the minimum number of inspectors that we need to deploy to achieve the objective.
\n6 2\n\n
2\n\n
We can achieve the objective by, for example, placing an inspector under Tree 3 and Tree 4.
\n14 3\n\n
2\n\n
20 4\n\n
3\n
Score : 200 points
\nTakahashi and Aoki will have a battle using their monsters.
\nThe health and strength of Takahashi's monster are A and B, respectively, and those of Aoki's monster are C and D, respectively.
\nThe two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, Aoki's, ...\nHere, an attack decreases the opponent's health by the value equal to the attacker's strength.\nThe monsters keep attacking until the health of one monster becomes 0 or below. The person with the monster whose health becomes 0 or below loses, and the other person wins.
\nIf Takahashi will win, print Yes
; if he will lose, print No
.
Input is given from Standard Input in the following format:
\nA B C D\n\n
If Takahashi will win, print Yes
; if he will lose, print No
.
10 9 10 10\n\n
No\n\n
First, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.
\nNext, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.
\nTakahashi's monster is the first to have 0 or less health, so Takahashi loses.
\n46 4 40 5\n\n
Yes\n
Score : 200 points
\nTakahashi's house has only one socket.
\nTakahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
\nOne power strip with A sockets can extend one empty socket into A empty sockets.
\nFind the minimum number of power strips required.
\nInput is given from Standard Input in the following format:
\nA B\n\n
Print the minimum number of power strips required.
\n4 10\n\n
3\n\n
3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.
\n8 9\n\n
2\n\n
2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.
\n8 8\n\n
1\n
Score : 200 points
\nIt is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
\nYou are given an integer N. Find the N-th Lucas number.
\nHere, the i-th Lucas number L_i is defined as follows:
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the N-th Lucas number.
\n5\n\n
11\n\n
Thus, the 5-th Lucas number is 11.
\n86\n\n
939587134549734843\n
Score : 200 points
\nThere is a grid of squares with H horizontal rows and W vertical columns.\nThe square at the i-th row from the top and the j-th column from the left is represented as (i, j).\nEach square is black or white.\nThe color of the square is given as an H-by-W matrix (a_{i, j}).\nIf a_{i, j} is .
, the square (i, j) is white; if a_{i, j} is #
, the square (i, j) is black.
Snuke is compressing this grid.\nHe will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:
\nIt can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.\nFind the final state of the grid.
\n.
or #
.Input is given from Standard Input in the following format:
\nH W\na_{1, 1}...a_{1, W}\n:\na_{H, 1}...a_{H, W}\n\n
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.
\n4 4\n##.#\n....\n##.#\n.#.#\n\n
###\n###\n.##\n\n
The second row and the third column in the original grid will be removed.
\n3 3\n#..\n.#.\n..#\n\n
#..\n.#.\n..#\n\n
As there is no row or column that consists only of white squares, no operation will be performed.
\n4 5\n.....\n.....\n..#..\n.....\n\n
#\n\n
7 6\n......\n....#.\n.#....\n..#...\n..#...\n......\n.#..#.\n\n
..#\n#..\n.#.\n.#.\n#.#\n
Score: 100 points
\nTakahashi the Jumbo will practice golf.
\nHis objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).
\nIf he can achieve the objective, print OK
; if he cannot, print NG
.
Input is given from Standard Input in the following format:
\nK\nA B\n\n
If he can achieve the objective, print OK
; if he cannot, print NG
.
7\n500 600\n\n
OK\n\n
Among the multiples of 7, for example, 567 lies between 500 and 600.
\n4\n5 7\n\n
NG\n\n
No multiple of 4 lies between 5 and 7.
\n1\n11 11\n\n
OK\n
Score : 100 points
\nYou are given two integers A and B as the input. Output the value of A + B.
\nHowever, if A + B is 10 or greater, output error
instead.
Input is given from Standard Input in the following format:
\nA B\n\n
If A + B is 10 or greater, print the string error
(case-sensitive); otherwise, print the value of A + B.
6 3\n\n
9\n\n
6 4\n\n
error\n
Score : 300 points
\nTakahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively.\nAfter repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get:
\nHowever, if the absolute value of the answer exceeds 10^{18}, print Unfair
instead.
Input is given from Standard Input in the following format:
\nA B C K\n\n
Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times.\nIf the absolute value of the answer exceeds 10^{18}, print Unfair
instead.
1 2 3 1\n\n
1\n\n
After one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3, respectively. We should print 5-4=1.
\n2 3 2 0\n\n
-1\n\n
1000000000 1000000000 1000000000 1000000000000000000\n\n
0\n
Score : 200 points
\nWe have held a popularity poll for N items on sale. Item i received A_i votes.
\nFrom these N items, we will select M as popular items. However, we cannot select an item with less than \\dfrac{1}{4M} of the total number of votes.
\nIf M popular items can be selected, print Yes
; otherwise, print No
.
Input is given from Standard Input in the following format:
\nN M\nA_1 ... A_N\n\n
If M popular items can be selected, print Yes
; otherwise, print No
.
4 1\n5 4 2 1\n\n
Yes\n\n
There were 12 votes in total. The most popular item received 5 votes, and we can select it.
\n3 2\n380 19 1\n\n
No\n\n
There were 400 votes in total. The second and third most popular items received less than \\dfrac{1}{4\\times 2} of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.
\n12 3\n4 56 78 901 2 345 67 890 123 45 6 789\n\n
Yes\n
Score : 200 points
\nTakahashi is practicing shiritori alone again today.
\nShiritori is a game as follows:
\nIn this game, he is practicing to announce as many words as possible in ten seconds.
\nYou are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.
\nInput is given from Standard Input in the following format:
\nN\nW_1\nW_2\n:\nW_N\n\n
If every word announced by Takahashi satisfied the conditions, print Yes
; otherwise, print No
.
4\nhoge\nenglish\nhoge\nenigma\n\n
No\n\n
As hoge
is announced multiple times, the rules of shiritori was not observed.
9\nbasic\nc\ncpp\nphp\npython\nnadesico\nocaml\nlua\nassembly\n\n
Yes\n\n
8\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaa\naaaaaaa\n\n
No\n\n
3\nabc\narc\nagc\n\n
No\n
Score: 100 points
\nIn AtCoder Kingdom, Gregorian calendar is used, and dates are written in the \"year-month-day\" order, or the \"month-day\" order without the year.
\nFor 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.
\nHow many days from 2018-1-1 through 2018-a-b are Takahashi?
Input is given from Standard Input in the following format:
\na b\n\n
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.
\n5 5\n\n
5\n\n
There are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5.
\n2 1\n\n
1\n\n
There is only one day that is Takahashi: 1-1.
\n11 30\n\n
11\n\n
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.
Score : 300 points
\nThere is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H).\nYou are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.
\nInput is given from Standard Input in the following format:
\nW H x y\n\n
Print the maximum possible area of the part whose area is not larger than that of the other, followed by 1
if there are multiple ways to cut the rectangle and achieve that maximum, and 0
otherwise.
The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.
\n2 3 1 2\n\n
3.000000 0\n\n
The line x=1 gives the optimal cut, and no other line does.
\n2 2 1 1\n\n
2.000000 1\n
Score : 300 points
\nYou 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:
\nIt can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
\nInput is given from Standard Input in the following format:
\nA B C\n\n
Print the minimum number of operations required to make A, B and C all equal.
\n2 5 4\n\n
2\n\n
We can make A, B and C all equal by the following operations:
\n2 6 3\n\n
5\n\n
31 41 5\n\n
23\n
Score : 100 points
\nGiven is an integer x that is greater than or equal to 0, and less than or equal to 1.\nOutput 1 if x is equal to 0, or 0 if x is equal to 1.
\nInput is given from Standard Input in the following format:
\nx\n\n
Print 1 if x is equal to 0, or 0 if x is equal to 1.
\n1\n\n
0\n\n
0\n\n
1\n
Score : 200 points
\nWe have a permutation p = {p_1,\\ p_2,\\ ...,\\ p_n} of {1,\\ 2,\\ ...,\\ n}.
\nPrint the number of elements p_i (1 < i < n) that satisfy the following condition:
\nInput is given from Standard Input in the following format:
\nn\np_1 p_2 ... p_n\n\n
Print the number of elements p_i (1 < i < n) that satisfy the condition.
\n5\n1 3 5 4 2\n\n
2\n\n
p_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.
\n9\n9 6 3 2 5 8 7 4 1\n\n
5\n
Score : 200 points
\nThere are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.
\nTakahashi says: \"there are X animals in total in the garden, and they have Y legs in total.\" Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.
\nInput is given from Standard Input in the following format:
\nX Y\n\n
If there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes
; otherwise, print No
.
3 8\n\n
Yes\n\n
The statement \"there are 3 animals in total in the garden, and they have 8 legs in total\" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.
\n2 100\n\n
No\n\n
There is no combination of numbers of cranes and turtles in which this statement is correct.
\n1 2\n\n
Yes\n\n
We also consider the case in which there are only cranes or only turtles.
Score : 200 points
\nGiven is a string S. Replace every character in S with x
and print the result.
Input is given from Standard Input in the following format:
\nS\n\n
Replace every character in S with x
and print the result.
sardine\n\n
xxxxxxx\n\n
Replacing every character in S with x
results in xxxxxxx
.
xxxx\n\n
xxxx\n\n
gone\n\n
xxxx\n
Score : 300 points
\nHow many integer sequences A_1,A_2,\\ldots,A_N of length N satisfy all of the following conditions?
\nThe answer can be very large, so output it modulo 10^9 + 7.
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the answer modulo 10^9 + 7.
\n2\n\n
2\n\n
Two sequences \\{0,9\\} and \\{9,0\\} satisfy all conditions.
\n1\n\n
0\n\n
869121\n\n
2511445\n
Score : 100 points
\nThere are a total of A + B cats and dogs.\nAmong them, A are known to be cats, but the remaining B are not known to be either cats or dogs.
\nDetermine if it is possible that there are exactly X cats among these A + B animals.
\nInput is given from Standard Input in the following format:
\nA B X\n\n
If it is possible that there are exactly X cats, print YES
; if it is impossible, print NO
.
3 5 4\n\n
YES\n\n
If there are one cat and four dogs among the B = 5 animals, there are X = 4 cats in total.
\n2 2 6\n\n
NO\n\n
Even if all of the B = 2 animals are cats, there are less than X = 6 cats in total.
\n5 3 2\n\n
NO\n\n
Even if all of the B = 3 animals are dogs, there are more than X = 2 cats in total.
Score : 100 points
\nGiven is an integer N.
\nTakahashi chooses an integer a from the positive integers not greater than N with equal probability.
\nFind the probability that a is odd.
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the probability that a is odd.\nYour output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-6}.
\n4\n\n
0.5000000000\n\n
There are four positive integers not greater than 4: 1, 2, 3, and 4. Among them, we have two odd numbers: 1 and 3. Thus, the answer is \\frac{2}{4} = 0.5.
\n5\n\n
0.6000000000\n\n
1\n\n
1.0000000000\n
Score : 400 points
\nTakahashi is going to buy N items one by one.
\nThe price of the i-th item he buys is A_i yen (the currency of Japan).
\nHe has M discount tickets, and he can use any number of them when buying an item.
\nIf Y tickets are used when buying an item priced X yen, he can get the item for \\frac{X}{2^Y} (rounded down to the nearest integer) yen.
\nWhat is the minimum amount of money required to buy all the items?
\nInput is given from Standard Input in the following format:
\nN M\nA_1 A_2 ... A_N\n\n
Print the minimum amount of money required to buy all the items.
\n3 3\n2 13 8\n\n
9\n\n
We can buy all the items for 9 yen, as follows:
\n4 4\n1 9 3 5\n\n
6\n\n
1 100000\n1000000000\n\n
0\n\n
We can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.
\n10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n\n
9500000000\n
Score : 300 points
\nWhen 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.
\nYou are given N numbers X_1, X_2, ..., X_N, where N is an even number.\nFor 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.
\nFind B_i for each i = 1, 2, ..., N.
\nInput is given from Standard Input in the following format:
\nN\nX_1 X_2 ... X_N\n\n
Print N lines.\nThe i-th line should contain B_i.
\n4\n2 4 4 3\n\n
4\n3\n3\n4\n\n
2\n1 2\n\n
2\n1\n\n
6\n5 5 4 4 3 3\n\n
4\n4\n4\n4\n4\n4\n
Score : 200 points
\nThere are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.
\nOnly Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.
\nA string S is assigned indicating attributes of all participants. If the i-th character of string S is a
, this means the participant ranked i-th in the Qualification contests is a Japanese student; b
means the participant ranked i-th is an overseas student; and c
means the participant ranked i-th is neither of these.
Write a program that outputs for all the participants in descending rank either Yes
if they passed the Qualification contests or No
if they did not pass.
a
, b
and c
.Inputs are provided from Standard Input in the following form.
\nN A B\nS\n\n
Output N lines. On the i-th line, output Yes
if the i-th participant passed the Qualification contests or No
if that participant did not pass.
10 2 3\nabccabaabb\n\n
Yes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n\n
The first, second, fifth, sixth, and seventh participants pass the Qualification contests.
\n12 5 2\ncabbabaacaba\n\n
No\nYes\nYes\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nNo\nNo\n\n
The sixth participant is third among overseas students and thus does not pass the Qualification contests.
\n5 2 2\nccccc\n\n
No\nNo\nNo\nNo\nNo\n
You are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, …, b is positive, negative or zero.
\nThe input is given from Standard Input in the following format:
\na b\n\n
If the product is positive, print Positive
. If it is negative, print Negative
. If it is zero, print Zero
.
1 3\n\n
Positive\n\n
1×2×3=6 is positive.
\n-3 -1\n\n
Negative\n\n
(-3)×(-2)×(-1)=-6 is negative.
\n-1 1\n\n
Zero\n\n
(-1)×0×1=0.
Score : 300 points
\nAtCoDeer the deer is going on a trip in a two-dimensional plane.\nIn 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.
\nIf 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).\nNote that he cannot stay at his place.\nDetermine whether he can carry out his plan.
\nInput is given from Standard Input in the following format:
\nN\nt_1 x_1 y_1\nt_2 x_2 y_2\n:\nt_N x_N y_N\n\n
If AtCoDeer can carry out his plan, print Yes
; if he cannot, print No
.
2\n3 1 2\n6 1 1\n\n
Yes\n\n
For example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1), (1,0), then (1,1).
\n1\n2 100 100\n\n
No\n\n
It is impossible to be at (100,100) two seconds after being at (0,0).
\n2\n5 1 1\n100 1 1\n\n
No\n
Score: 200 points
\nToday, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.
\nAs the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.
Find the N-th smallest integer that would make Ringo happy.
\nInput is given from Standard Input in the following format:
\nD N\n\n
Print the N-th smallest integer that can be divided by 100 exactly D times.
\n0 5\n\n
5\n\n
The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...
\nThus, the 5-th smallest integer that would make Ringo happy is 5.
1 11\n\n
1100\n\n
The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \\ 000, 1 \\ 100, ...
\nThus, the integer we are seeking is 1 \\ 100.
2 85\n\n
850000\n\n
The integers that can be divided by 100 exactly twice are as follows: 10 \\ 000, 20 \\ 000, 30 \\ 000, ...
\nThus, the integer we are seeking is 850 \\ 000.
Score : 100 points
\nWe have two bottles for holding water.
\nBottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water.
\nBottle 2 contains C milliliters of water.
\nWe will transfer water from Bottle 2 to Bottle 1 as much as possible.
\nHow much amount of water will remain in Bottle 2?
\nInput is given from Standard Input in the following format:
\nA B C\n\n
Print the integer representing the amount of water, in milliliters, that will remain in Bottle 2.
\n6 4 3\n\n
1\n\n
We will transfer two milliliters of water from Bottle 2 to Bottle 1, and one milliliter of water will remain in Bottle 2.
\n8 3 9\n\n
4\n\n
12 3 7\n\n
0\n
Score: 300 points
\nMr. Infinity has a string S consisting of digits from 1
to 9
. Each time the date changes, this string changes as follows:
2
in S is replaced with 22
. Similarly, each 3
becomes 333
, 4
becomes 4444
, 5
becomes 55555
, 6
becomes 666666
, 7
becomes 7777777
, 8
becomes 88888888
and 9
becomes 999999999
. 1
remains as 1
.For example, if S is 1324
, it becomes 1333224444
the next day, and it becomes 133333333322224444444444444444
the day after next.\nYou are interested in what the string looks like after 5 \\times 10^{15} days. What is the K-th character from the left in the string after 5 \\times 10^{15} days?
Input is given from Standard Input in the following format:
\nS\nK\n\n
Print the K-th character from the left in Mr. Infinity's string after 5 \\times 10^{15} days.
\n1214\n4\n\n
2\n\n
The string S changes as follows:
\n1214
12214444
1222214444444444444444
12222222214444444444444444444444444444444444444444444444444444444444444444
The first five characters in the string after 5 \\times 10^{15} days is 12222
. As K=4, we should print the fourth character, 2
.
3\n157\n\n
3\n\n
The initial string is 3
. The string after 5 \\times 10^{15} days consists only of 3
.
299792458\n9460730472580800\n\n
2\n
Score : 100 points
\nThis contest, AtCoder Beginner Contest, is abbreviated as ABC.
\nWhen we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.
\nWhat is the abbreviation for the N-th round of ABC? Write a program to output the answer.
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the abbreviation for the N-th round of ABC.
\n100\n\n
ABC100\n\n
The 100th round of ABC is ABC100.
\n425\n\n
ABC425\n\n
999\n\n
ABC999\n
Score : 200 points
\nWe have sticks numbered 1, \\cdots, N. The length of Stick i (1 \\leq i \\leq N) is L_i.
\nIn how many ways can we choose three of the sticks with different lengths that can form a triangle?
\nThat is, find the number of triples of integers (i, j, k) (1 \\leq i < j < k \\leq N) that satisfy both of the following conditions:
\nInput is given from Standard Input in the following format:
\nN\nL_1 L_2 \\cdots L_N\n\n
Print the number of ways to choose three of the sticks with different lengths that can form a triangle.
\n5\n4 4 9 7 5\n\n
5\n\n
The following five triples (i, j, k) satisfy the conditions: (1, 3, 4), (1, 4, 5), (2, 3, 4), (2, 4, 5), and (3, 4, 5).
\n6\n4 5 4 3 3 5\n\n
8\n\n
We have two sticks for each of the lengths 3, 4, and 5. To satisfy the first condition, we have to choose one from each length.
\nThere is a triangle whose sides have lengths 3, 4, and 5, so we have 2 ^ 3 = 8 triples (i, j, k) that satisfy the conditions.
\n10\n9 4 6 1 9 6 10 6 6 8\n\n
39\n\n
2\n1 1\n\n
0\n\n
No triple (i, j, k) satisfies 1 \\leq i < j < k \\leq N, so we should print 0.
Score : 300 points
\nWe have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.
\nIt takes us A_i minutes to read the i-th book from the top on Desk A (1 \\leq i \\leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \\leq i \\leq M).
\nConsider the following action:
\nHow many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.
\nInput is given from Standard Input in the following format:
\nN M K\nA_1 A_2 \\ldots A_N\nB_1 B_2 \\ldots B_M\n\n
Print an integer representing the maximum number of books that can be read.
\n3 4 240\n60 90 120\n80 150 80 150\n\n
3\n\n
In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.
\nWe can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.
\n3 4 730\n60 90 120\n80 150 80 150\n\n
7\n\n
5 4 1\n1000000000 1000000000 1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000\n\n
0\n\n
Watch out for integer overflows.
Score : 300 points
\nYou are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.
\nInput is given from Standard Input in the following format:
\nA B C D\n\n
Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.
\n4 9 2 3\n\n
2\n\n
5 and 7 satisfy the condition.
\n10 40 6 8\n\n
23\n\n
314159265358979323 846264338327950288 419716939 937510582\n\n
532105071133627368\n
Score : 200 points
\nTakahashi has N blue cards and M red cards.\nA 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.
\nTakahashi 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.
\nHere, 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?
\nNote that the same string may be written on multiple cards.
\nInput is given from Standard Input in the following format:
\nN\ns_1\ns_2\n:\ns_N\nM\nt_1\nt_2\n:\nt_M\n\n
If Takahashi can earn at most X yen on balance, print X.
\n3\napple\norange\napple\n1\ngrape\n\n
2\n\n
He can earn 2 yen by announcing apple
.
3\napple\norange\napple\n5\napple\napple\napple\napple\napple\n\n
1\n\n
If he announces apple
, he will lose 3 yen. If he announces orange
, he can earn 1 yen.
1\nvoldemort\n10\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\n\n
0\n\n
If he announces voldemort
, he will lose 9 yen. If he announces orange
, for example, he can avoid losing a yen.
6\nred\nred\nblue\nyellow\nyellow\nred\n5\nred\nred\nyellow\ngreen\nblue\n\n
1\n
Score : 100 points
\nYou are given two integers A and B.\nFind the largest value among A+B, A-B and A \\times B.
\nInput is given from Standard Input in the following format:
\nA B\n\n
Print the largest value among A+B, A-B and A \\times B.
\n3 1\n\n
4\n\n
3+1=4, 3-1=2 and 3 \\times 1=3. The largest among them is 4.
\n4 -2\n\n
6\n\n
The largest is 4 - (-2) = 6.
\n0 0\n\n
0\n
Score : 100 points
\nTakahashi has K 500-yen coins. (Yen is the currency of Japan.)\nIf these coins add up to X yen or more, print Yes
; otherwise, print No
.
Input is given from Standard Input in the following format:
\nK X\n\n
If the coins add up to X yen or more, print Yes
; otherwise, print No
.
2 900\n\n
Yes\n\n
Two 500-yen coins add up to 1000 yen, which is not less than X = 900 yen.
\n1 501\n\n
No\n\n
One 500-yen coin is worth 500 yen, which is less than X = 501 yen.
\n4 2000\n\n
Yes\n\n
Four 500-yen coins add up to 2000 yen, which is not less than X = 2000 yen.
Score : 100 points
\nSnuke lives at position x on a number line.\nOn this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.
\nSnuke decided to get food delivery from the closer of stores A and B.\nFind out which store is closer to Snuke's residence.
\nHere, the distance between two points s and t on a number line is represented by |s-t|.
\nInput is given from Standard Input in the following format:
\nx a b\n\n
If store A is closer, print A
; if store B is closer, print B
.
5 2 7\n\n
B\n\n
The distances between Snuke's residence and stores A and B are 3 and 2, respectively.\nSince store B is closer, print B
.
1 999 1000\n\n
A\n
Score : 400 points
\nThere are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.
\nYou can take and complete at most one of these jobs in a day.
\nHowever, you cannot retake a job that you have already done.
\nFind the maximum total reward that you can earn no later than M days from today.
\nYou can already start working today.
\nInput is given from Standard Input in the following format:
\nN M\nA_1 B_1\nA_2 B_2\n\\vdots\nA_N B_N\n\n
Print the maximum total reward that you can earn no later than M days from today.
\n3 4\n4 3\n4 1\n2 2\n\n
5\n\n
You can earn the total reward of 5 by taking the jobs as follows:
\n5 3\n1 2\n1 3\n1 4\n2 1\n2 3\n\n
10\n\n
1 1\n2 1\n\n
0\n
Score: 200 points
\nA country decides to build a palace.
\nIn this country, the average temperature of a point at an elevation of x meters is T-x \\times 0.006 degrees Celsius.
\nThere are N places proposed for the place. The elevation of Place i is H_i meters.
\nAmong them, Princess Joisino orders you to select the place whose average temperature is the closest to A degrees Celsius, and build the palace there.
\nPrint the index of the place where the palace should be built.
\nIt is guaranteed that the solution is unique.
\nInput is given from Standard Input in the following format:
\nN\nT A\nH_1 H_2 ... H_N\n\n
Print the index of the place where the palace should be built.
\n2\n12 5\n1000 2000\n\n
1\n\n
Thus, the palace should be built at Place 1.
\n3\n21 -11\n81234 94124 52141\n\n
3\n
Score : 300 points
\nGiven is a positive integer L.\nFind the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.
\nInput is given from Standard Input in the following format:
\nL\n\n
Print the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\nYour output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.
\n3\n\n
1.000000000000\n\n
For example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.
\nOn the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.
\n999\n\n
36926037.000000000000\n
Score : 300 points
\nWe will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.
\nFor example, greenbin
is an anagram of beginner
. As seen here, when the same character occurs multiple times, that character must be used that number of times.
Given are N strings s_1, s_2, \\ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \\leq i < j \\leq N) such that s_i is an anagram of s_j.
\nInput is given from Standard Input in the following format:
\nN\ns_1\ns_2\n:\ns_N\n\n
Print the number of pairs of integers i, j (1 \\leq i < j \\leq N) such that s_i is an anagram of s_j.
\n3\nacornistnt\npeanutbomb\nconstraint\n\n
1\n\n
s_1 = acornistnt
is an anagram of s_3 = constraint
. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.
2\noneplustwo\nninemodsix\n\n
0\n\n
If there is no pair i, j such that s_i is an anagram of s_j, print 0.
\n5\nabaaaaaaaa\noneplustwo\naaaaaaaaba\ntwoplusone\naaaabaaaaa\n\n
4\n\n
Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.
Score : 100 points
\nTakahashi, who is A years old, is riding a Ferris wheel.
\nIt costs B yen (B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who are 5 years old or younger are free of charge. (Yen is the currency of Japan.)
\nFind the cost of the Ferris wheel for Takahashi.
\nInput is given from Standard Input in the following format:
\nA B\n\n
Print the cost of the Ferris wheel for Takahashi.
\n30 100\n\n
100\n\n
Takahashi is 30 years old now, and the cost of the Ferris wheel is 100 yen.
\n12 100\n\n
50\n\n
Takahashi is 12 years old, and the cost of the Ferris wheel is the half of 100 yen, that is, 50 yen.
\n0 100\n\n
0\n\n
Takahashi is 0 years old, and he can ride the Ferris wheel for free.
Score : 400 points
\nGiven is a positive integer N. Consider repeatedly applying the operation below on N:
\nFind the maximum number of times the operation can be applied.
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the maximum number of times the operation can be applied.
\n24\n\n
3\n\n
We can apply the operation three times by, for example, making the following choices:
\n1\n\n
0\n\n
We cannot apply the operation at all.
\n64\n\n
3\n\n
We can apply the operation three times by, for example, making the following choices:
\n1000000007\n\n
1\n\n
We can apply the operation once by, for example, making the following choice:
\n997764507000\n\n
7\n
Score : 300 points
\nIroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.
\nShe is shopping, and now paying at the cashier.\nHer total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).
\nHowever, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.
\nFind the amount of money that she will hand to the cashier.
\nThe input is given from Standard Input in the following format:
\nN K\nD_1 D_2 … D_K\n\n
Print the amount of money that Iroha will hand to the cashier.
\n1000 8\n1 3 4 5 6 7 8 9\n\n
2000\n\n
She dislikes all digits except 0 and 2.
\nThe smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.
\n9999 1\n0\n\n
9999\n
Score : 300 points
\nFind \\displaystyle{\\sum_{a=1}^{K}\\sum_{b=1}^{K}\\sum_{c=1}^{K} \\gcd(a,b,c)}.
\nHere \\gcd(a,b,c) denotes the greatest common divisor of a, b, and c.
\nInput is given from Standard Input in the following format:
\nK\n\n
Print the value of \\displaystyle{\\sum_{a=1}^{K}\\sum_{b=1}^{K}\\sum_{c=1}^{K} \\gcd(a,b,c)}.
\n2\n\n
9\n\n
\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2)\n=1+1+1+1+1+1+1+2=9
\nThus, the answer is 9.
\n200\n\n
10813692\n
Score : 300 points
\nA company has N members, who are assigned ID numbers 1, ..., N.
\nEvery member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.
\nWhen a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.
\nYou are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.
\nInput is given from Standard Input in the following format:
\nN\nA_2 ... A_N\n\n
For each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.
\n5\n1 1 2 2\n\n
2\n2\n0\n0\n0\n\n
The member numbered 1 has two immediate subordinates: the members numbered 2 and 3.
\nThe member numbered 2 has two immediate subordinates: the members numbered 4 and 5.
\nThe members numbered 3, 4, and 5 do not have immediate subordinates.
\n10\n1 1 1 1 1 1 1 1 1\n\n
9\n0\n0\n0\n0\n0\n0\n0\n0\n0\n\n
7\n1 2 3 4 5 6\n\n
1\n1\n1\n1\n1\n1\n0\n
Score : 100 points
\nIn some other world, today is December D-th.
\nWrite a program that prints Christmas
if D = 25, Christmas Eve
if D = 24, Christmas Eve Eve
if D = 23 and Christmas Eve Eve Eve
if D = 22.
Input is given from Standard Input in the following format:
\nD\n\n
Print the specified string (case-sensitive).
\n25\n\n
Christmas\n\n
22\n\n
Christmas Eve Eve Eve\n\n
Be sure to print spaces between the words.
Score : 100 points
\nYou are given three integers A, B and C.\nDetermine whether C is not less than A and not greater than B.
\nInput is given from Standard Input in the following format:
\nA B C\n\n
If the condition is satisfied, print Yes
; otherwise, print No
.
1 3 2\n\n
Yes\n\n
C=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes
.
6 5 4\n\n
No\n\n
C=4 is less than A=6, and thus the output should be No
.
2 2 2\n\n
Yes\n
Score : 100 points
\nWe have N+M balls, each of which has an integer written on it.
\nIt is known that:
Find the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.
\nIt can be shown that this count does not depend on the actual values written on the balls.
Input is given from Standard Input in the following format:
\nN M\n\n
Print the answer.
\n2 1\n\n
1\n\n
For example, let us assume that the numbers written on the three balls are 1,2,4.
\nThus, the answer is 1.
\n4 3\n\n
9\n\n
1 1\n\n
0\n\n
13 3\n\n
81\n\n
0 3\n\n
3\n
Score: 300 points
\nIn 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)!
\nThere are five means of transport in this empire:
\nFor each of them, one vehicle leaves the city at each integer time (time 0, 1, 2, ...).
\nThere is a group of N people at City 1, and they all want to go to City 6.
\nAt least how long does it take for all of them to reach there? \nYou can ignore the time needed to transfer.
Input is given from Standard Input in the following format:
\nN\nA\nB\nC\nD\nE\n\n
Print the minimum time required for all of the people to reach City 6, in minutes.
\n5\n3\n2\n4\n3\n5\n\n
7\n\n
One possible way to travel is as follows.\nFirst, there are N = 5 people at City 1, as shown in the following image:
\nIn the first minute, three people travels from City 1 to City 2 by train. Note that a train can only occupy at most three people.
\nIn the second minute, the remaining two people travels from City 1 to City 2 by train, and two of the three people who were already at City 2 travels to City 3 by bus. Note that a bus can only occupy at most two people.
\nIn the third minute, two people travels from City 2 to City 3 by train, and another two people travels from City 3 to City 4 by taxi.
\nFrom then on, if they continue traveling without stopping until they reach City 6, all of them can reach there in seven minutes.
\nThere is no way for them to reach City 6 in 6 minutes or less.
10\n123\n123\n123\n123\n123\n\n
5\n\n
All kinds of vehicles can occupy N = 10 people at a time.\nThus, if they continue traveling without stopping until they reach City 6, all of them can reach there in five minutes.
\n10000000007\n2\n3\n5\n7\n11\n\n
5000000008\n\n
Note that the input or output may not fit into a 32-bit integer type.
Score : 400 points
\nWe have a tree with N vertices numbered 1 to N.\nThe i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i.\nYour objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:
\nFind a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
\nInput is given from Standard Input in the following format:
\nN\nu_1 v_1 w_1\nu_2 v_2 w_2\n.\n.\n.\nu_{N - 1} v_{N - 1} w_{N - 1}\n\n
Print a coloring of the vertices that satisfies the condition, in N lines.\nThe i-th line should contain 0
if Vertex i is painted white and 1
if it is painted black.
If there are multiple colorings that satisfy the condition, any of them will be accepted.
\n3\n1 2 2\n2 3 1\n\n
0\n0\n1\n\n
5\n2 5 2\n2 3 10\n1 3 8\n3 4 2\n\n
1\n0\n1\n0\n1\n
Score: 300 points
\nTakahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.
\nA game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.
\nWhen a player correctly answers a question, each of the other N-1 players receives minus one (-1) point. There is no other factor that affects the players' scores.
\nAt the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive.
\nIn the last game, the players gave a total of Q correct answers, the i-th of which was given by Player A_i.\nFor Kizahashi, write a program that determines whether each of the N players survived this game.
\nInput is given from Standard Input in the following format:
\nN K Q\nA_1\nA_2\n.\n.\n.\nA_Q\n\n
Print N lines. The i-th line should contain Yes
if Player i survived the game, and No
otherwise.
6 3 4\n3\n1\n3\n2\n\n
No\nNo\nYes\nNo\nNo\nNo\n\n
In the beginning, the players' scores are (3, 3, 3, 3, 3, 3).
\nPlayers 1, 2, 4, 5 and 6, who have 0 points or lower, are eliminated, and Player 3 survives this game.
\n6 5 4\n3\n1\n3\n2\n\n
Yes\nYes\nYes\nYes\nYes\nYes\n\n
10 13 15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9\n\n
No\nNo\nNo\nNo\nYes\nNo\nNo\nNo\nYes\nNo\n
Score : 100 points
\nThe window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)
\nWe will close the window so as to minimize the total horizontal length of the uncovered part of the window.\nFind the total horizontal length of the uncovered parts of the window then.
\nInput is given from Standard Input in the following format:
\nA B\n\n
Print the total horizontal length of the uncovered parts of the window.
\n12 4\n\n
4\n\n
We have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.
\n20 15\n\n
0\n\n
If the window is completely covered, print 0.
\n20 30\n\n
0\n\n
Each curtain may be longer than the window.
Score : 100 points
\nYou are given three integers, A, B and C.
\nAmong them, two are the same, but the remaining one is different from the rest.
\nFor example, when A=5,B=7,C=5, A and C are the same, but B is different.
\nFind the one that is different from the rest among the given three integers.
Input is given from Standard Input in the following format:
\nA B C\n\n
Among A, B and C, print the integer that is different from the rest.
\n5 7 5\n\n
7\n\n
This is the same case as the one in the statement.
\n1 1 7\n\n
7\n\n
In this case, C is the one we seek.
\n-100 100 100\n\n
-100\n
Score : 200 points
\nSnuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes:
\nSnuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes.\nHow many triples of non-negative integers (r,g,b) achieve this?
\nInput is given from Standard Input in the following format:
\nR G B N\n\n
Print the answer.
\n1 2 3 4\n\n
4\n\n
Four triples achieve the objective, as follows:
\n13 1 4 3000\n\n
87058\n
Score : 100 points
\nHow many multiples of d are there among the integers between L and R (inclusive)?
\nInput is given from Standard Input in the following format:
\nL R d\n\n
Print the number of multiples of d among the integers between L and R (inclusive).
\n5 10 2\n\n
3\n\n
6 20 7\n\n
2\n\n
1 100 1\n\n
100\n
Score : 100 points
\nIt is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.
\nGiven an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.
\nInput is given from Standard Input in the following format:
\nr\n\n
Print an integer representing the area of the regular dodecagon.
\n4\n\n
48\n\n
The area of the regular dodecagon is 3 \\times 4^2 = 48.
\n15\n\n
675\n\n
80\n\n
19200\n
Score : 300 points
\nThere are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).
\nWe will collect all of these balls, by choosing two integers p and q such that p \\neq 0 or q \\neq 0 and then repeating the following operation:
\nFind the minimum total cost required to collect all the balls when we optimally choose p and q.
\nInput is given from Standard Input in the following format:
\nN\nx_1 y_1\n:\nx_N y_N\n\n
Print the minimum total cost required to collect all the balls.
\n2\n1 1\n2 2\n\n
1\n\n
If we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by collecting them in the order (1, 1), (2, 2).
\n3\n1 4\n4 6\n7 8\n\n
1\n\n
If we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by collecting them in the order (7, 8), (4, 6), (1, 4).
\n4\n1 1\n1 2\n2 1\n2 2\n\n
2\n
Score : 200 points
\nGiven are integers a,b,c and d.\nIf x and y are integers and a \\leq x \\leq b and c\\leq y \\leq d hold, what is the maximum possible value of x \\times y?
\nInput is given from Standard Input in the following format:
\na b c d\n\n
Print the answer.
\n1 2 1 1\n\n
2\n\n
If x = 1 and y = 1 then x \\times y = 1.\nIf x = 2 and y = 1 then x \\times y = 2.\nTherefore, the answer is 2.
\n3 5 -4 -2\n\n
-6\n\n
The answer can be negative.
\n-1000000000 0 -1000000000 0\n\n
1000000000000000000\n
Score: 400 points
\nKizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.
\nLet the current time be time 0. Kizahashi has N jobs numbered 1 to N.
\nIt takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.
\nKizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.
\nCan Kizahashi complete all the jobs in time? If he can, print Yes
; if he cannot, print No
.
Input is given from Standard Input in the following format:
\nN\nA_1 B_1\n.\n.\n.\nA_N B_N\n\n
If Kizahashi can complete all the jobs in time, print Yes
; if he cannot, print No
.
5\n2 4\n1 9\n1 8\n4 9\n3 12\n\n
Yes\n\n
He can complete all the jobs in time by, for example, doing them in the following order:
\nNote that it is fine to complete Job 3 exactly at the deadline, time 8.
\n3\n334 1000\n334 1000\n334 1000\n\n
No\n\n
He cannot complete all the jobs in time, no matter what order he does them in.
\n30\n384 8895\n1725 9791\n170 1024\n4 11105\n2 6\n578 1815\n702 3352\n143 5141\n1420 6980\n24 1602\n849 999\n76 7586\n85 5570\n444 4991\n719 11090\n470 10708\n1137 4547\n455 9003\n110 9901\n15 8578\n368 3692\n104 1286\n3 4\n366 12143\n7 6649\n610 2374\n152 7324\n4 7042\n292 11386\n334 5720\n\n
Yes\n
Score : 100 points
\nYou are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between.\nPrint the acronym formed from the uppercased initial letters of the words.
\nInput is given from Standard Input in the following format:
\ns_1 s_2 s_3\n\n
Print the answer.
\natcoder beginner contest\n\n
ABC\n\n
The initial letters of atcoder
, beginner
and contest
are a
, b
and c
. Uppercase and concatenate them to obtain ABC
.
resident register number\n\n
RRN\n\n
k nearest neighbor\n\n
KNN\n\n
async layered coding\n\n
ALC\n
Score : 100 points
\nWe will buy a product for N yen (the currency of Japan) at a shop.
\nIf we use only 1000-yen bills to pay the price, how much change will we receive?
\nAssume we use the minimum number of bills required.
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the amount of change as an integer.
\n1900\n\n
100\n\n
We will use two 1000-yen bills to pay the price and receive 100 yen in change.
\n3000\n\n
0\n\n
We can pay the exact price.
Score : 100 points
\nAtCoDeer has three cards, one red, one green and one blue.
\nAn integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.
\nWe will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.
\nIs this integer a multiple of 4?
Input is given from Standard Input in the following format:
\nr g b\n\n
If the three-digit integer is a multiple of 4, print YES
(case-sensitive); otherwise, print NO
.
4 3 2\n\n
YES\n\n
432 is a multiple of 4, and thus YES
should be printed.
2 3 4\n\n
NO\n\n
234 is not a multiple of 4, and thus NO
should be printed.
Score : 100 points
\nIn \"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).
\nA 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.
\no
or x
.Input is given from Standard Input in the following format:
\nS\n\n
Print the price of the bowl of ramen corresponding to S.
\noxo\n\n
900\n\n
The price of a ramen topped with two kinds of toppings, boiled egg and green onions, is 700 + 100 \\times 2 = 900 yen.
\nooo\n\n
1000\n\n
The price of a ramen topped with all three kinds of toppings is 700 + 100 \\times 3 = 1000 yen.
\nxxx\n\n
700\n\n
The price of a ramen without any toppings is 700 yen.
Score : 100 points
\nGiven an integer a as input, print the value a + a^2 + a^3.
\nInput is given from Standard Input in the following format:
\na\n\n
Print the value a + a^2 + a^3 as an integer.
\n2\n\n
14\n\n
When a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.
\nPrint the answer as an input. Outputs such as 14.0
will be judged as incorrect.
10\n\n
1110\n
Score : 100 points
\nA programming competition site AtCode regularly holds programming contests.
\nThe next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.
\nThe contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.
\nThe contest after the ARC is called AGC, which is rated for all contestants.
\nTakahashi's rating on AtCode is R. What is the next contest rated for him?
\nInput is given from Standard Input in the following format:
\nR\n\n
Print the name of the next contest rated for Takahashi (ABC
, ARC
or AGC
).
1199\n\n
ABC\n\n
1199 is less than 1200, so ABC will be rated.
\n1200\n\n
ARC\n\n
1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.
\n4208\n\n
AGC\n
Score : 300 points
\nTakahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.
\nMore specifically, in one move, he can go from coordinate x to x + D or x - D.
\nHe wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.
\nFind the minimum possible absolute value of the coordinate of the destination.
\nInput is given from Standard Input in the following format:
\nX K D\n\n
Print the minimum possible absolute value of the coordinate of the destination.
\n6 2 4\n\n
2\n\n
Takahashi is now at coordinate 6. It is optimal to make the following moves:
\nHere, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.
\n7 4 3\n\n
1\n\n
Takahashi is now at coordinate 7. It is optimal to make, for example, the following moves:
\nHere, the absolute value of the coordinate of the destination is 1, and we cannot make it smaller.
\n10 1 2\n\n
8\n\n
1000000000000000 1000000000000000 1000000000000000\n\n
1000000000000000\n\n
The answer can be enormous.
Score : 200 points
\nYou are given an integer sequence A of length N.\nFind the maximum absolute difference of two elements (with different indices) in A.
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 ... A_N\n\n
Print the maximum absolute difference of two elements (with different indices) in A.
\n4\n1 4 6 3\n\n
5\n\n
The maximum absolute difference of two elements is A_3-A_1=6-1=5.
\n2\n1000000000 1\n\n
999999999\n\n
5\n1 1 1 1 1\n\n
0\n
Score : 200 points
\nTakahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains 5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)
\nTakahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?
\n(We assume that there are six kinds of coins available: 500-yen, 100-yen, 50-yen, 10-yen, 5-yen, and 1-yen coins.)
\nInput is given from Standard Input in the following format:
\nX\n\n
Print the maximum number of happiness points that can be earned.
\n1024\n\n
2020\n\n
By exchanging his money so that he gets two 500-yen coins and four 5-yen coins, he gains 2020 happiness points, which is the maximum number of happiness points that can be earned.
\n0\n\n
0\n\n
He is penniless - or yenless.
\n1000000000\n\n
2000000000\n\n
He is a billionaire - in yen.
Score : 100 points
\nAn elementary school student Takahashi has come to a variety store.
\nHe 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?
\nNote that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
\nInput is given from Standard Input in the following format:
\nA B C\n\n
If Takahashi can buy the toy, print Yes
; if he cannot, print No
.
50 100 120\n\n
Yes\n\n
He has 50 + 100 = 150 yen, so he can buy the 120-yen toy.
\n500 100 1000\n\n
No\n\n
He has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.
\n19 123 143\n\n
No\n\n
There are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard to use.
\n19 123 142\n\n
Yes\n
Score : 200 points
\nWhen Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.
\nYou, the smartwatch, has found N routes to his home.
\nIf Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.
\nFind the smallest cost of a route that takes not longer than time T.
\nInput is given from Standard Input in the following format:
\nN T\nc_1 t_1\nc_2 t_2\n:\nc_N t_N\n\n
Print the smallest cost of a route that takes not longer than time T.
\nIf there is no route that takes not longer than time T, print TLE
instead.
3 70\n7 60\n1 80\n4 50\n\n
4\n\n
Thus, the cost 4 of the third route is the minimum.
\n4 3\n1 1000\n2 4\n3 1000\n4 500\n\n
TLE\n\n
There is no route that takes not longer than time T = 3.
\n5 9\n25 8\n5 9\n4 10\n1000 1000\n6 1\n\n
5\n
Score : 100 points
\nYou will be given a string S of length 3 representing the weather forecast for three days in the past.
\nThe i-th character (1 \\leq i \\leq 3) of S represents the forecast for the i-th day. S
, C
, and R
stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather on those three days.
\nThe i-th character (1 \\leq i \\leq 3) of S represents the actual weather on the i-th day. S
, C
, and R
stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
\nS
, C
, and R
.Input is given from Standard Input in the following format:
\nS\nT\n\n
Print the number of days for which the forecast was correct.
\nCSS\nCSR\n\n
2\n\n
Thus, the forecast was correct for two days in this case.
\nSSR\nSSR\n\n
3\n\n
RRR\nSSS\n\n
0\n
Score : 100 points
\nGiven are three integers A_1, A_2, and A_3.
\nIf A_1+A_2+A_3 is greater than or equal to 22, print bust
; otherwise, print win
.
Input is given from Standard Input in the following format:
\nA_1 A_2 A_3\n\n
If A_1+A_2+A_3 is greater than or equal to 22, print bust
; otherwise, print win
.
5 7 9\n\n
win\n\n
5+7+9=21, so print win
.
13 7 2\n\n
bust\n\n
13+7+2=22, so print bust
.
Score : 400 points
\nWe have N balls. The i-th ball has an integer A_i written on it.
\nFor each k=1, 2, ..., N, solve the following problem and print the answer.
Input is given from Standard Input in the following format:
\nN\nA_1 A_2 ... A_N\n\n
For each k=1,2,...,N, print a line containing the answer.
\n5\n1 1 2 1 2\n\n
2\n2\n3\n2\n3\n\n
Consider the case k=1 for example. The numbers written on the remaining balls are 1,2,1,2.
\nFrom these balls, there are two ways to choose two distinct balls so that the integers written on them are equal.
\nThus, the answer for k=1 is 2.
4\n1 2 3 4\n\n
0\n0\n0\n0\n\n
No two balls have equal numbers written on them.
\n5\n3 3 3 3 3\n\n
6\n6\n6\n6\n6\n\n
Any two balls have equal numbers written on them.
\n8\n1 2 1 4 2 1 4 1\n\n
5\n7\n5\n7\n7\n5\n7\n5\n
Score : 200 points
\nWe have a sequence p = {p_1,\\ p_2,\\ ...,\\ p_N} which is a permutation of {1,\\ 2,\\ ...,\\ N}.
\nYou can perform the following operation at most once: choose integers i and j (1 \\leq i < j \\leq N), and swap p_i and p_j. Note that you can also choose not to perform it.
\nPrint YES
if you can sort p in ascending order in this way, and NO
otherwise.
Input is given from Standard Input in the following format:
\nN\np_1 p_2 ... p_N\n\n
Print YES
if you can sort p in ascending order in the way stated in the problem statement, and NO
otherwise.
5\n5 2 3 4 1\n\n
YES\n\n
You can sort p in ascending order by swapping p_1 and p_5.
\n5\n2 4 3 5 1\n\n
NO\n\n
In this case, swapping any two elements does not sort p in ascending order.
\n7\n1 2 3 4 5 6 7\n\n
YES\n\n
p is already sorted in ascending order, so no operation is needed.
Score : 200 points
\nThere are N children, numbered 1, 2, ..., N.
\nSnuke has decided to distribute x sweets among them.\nHe needs to give out all the x sweets, but some of the children may get zero sweets.
\nFor each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets.\nSnuke is trying to maximize the number of happy children by optimally distributing the sweets.\nFind the maximum possible number of happy children.
\nInput is given from Standard Input in the following format:
\nN x\na_1 a_2 ... a_N\n\n
Print the maximum possible number of happy children.
\n3 70\n20 30 10\n\n
2\n\n
One optimal way to distribute sweets is (20, 30, 20).
\n3 10\n20 30 10\n\n
1\n\n
The optimal way to distribute sweets is (0, 0, 10).
\n4 1111\n1 10 100 1000\n\n
4\n\n
The optimal way to distribute sweets is (1, 10, 100, 1000).
\n2 10\n20 20\n\n
0\n\n
No children will be happy, no matter how the sweets are distributed.
Score : 300 points
\nThere is a circular pond with a perimeter of K meters, and N houses around them.
\nThe i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.
\nWhen traveling between these houses, you can only go around the pond.
\nFind the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.
\nInput is given from Standard Input in the following format:
\nK N\nA_1 A_2 ... A_N\n\n
Print the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.
\n20 3\n5 10 15\n\n
10\n\n
If you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.
\n20 3\n0 5 15\n\n
10\n\n
If you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.
Score : 200 points
\nYou have an integer variable x.\nInitially, x=0.
\nSome person gave you a string S of length N, and using the string you performed the following operation N times.\nIn the i-th operation, you incremented the value of x by 1 if S_i=I
, and decremented the value of x by 1 if S_i=D
.
Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
\nI
and D
occur in S.The input is given from Standard Input in the following format:
\nN\nS\n\n
Print the maximum value taken by x during the operations.
\n5\nIIDID\n\n
2\n\n
After each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively. Thus, the output should be 2, the maximum value.
\n7\nDDIDDII\n\n
0\n\n
The initial value x=0 is the maximum value taken by x, thus the output should be 0.
Score : 200 points
\nYou are given a string S of length N consisting of lowercase English letters.\nWe will cut this string at one position into two strings X and Y.\nHere, we would like to maximize the number of different letters contained in both X and Y.\nFind the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
\nInput is given from Standard Input in the following format:
\nN\nS\n\n
Print the largest possible number of different letters contained in both X and Y.
\n6\naabbca\n\n
2\n\n
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
.\nThere will never be three or more different letters contained in both X and Y, so the answer is 2.
10\naaaaaaaaaa\n\n
1\n\n
However we divide S, only a
will be contained in both X and Y.
45\ntgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir\n\n
9\n
Score : 200 points
\nA shop sells N kinds of fruits, Fruit 1, \\ldots, N, at prices of p_1, \\ldots, p_N yen per item, respectively. (Yen is the currency of Japan.)
\nHere, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.
\nInput is given from Standard Input in the following format:
\nN K\np_1 p_2 \\ldots p_N\n\n
Print an integer representing the minimum possible total price of fruits.
\n5 3\n50 100 80 120 80\n\n
210\n\n
This shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen, and 80 yen, respectively.
\nThe minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen when choosing Fruit 1, 3, and 5.
\n1 1\n1000\n\n
1000\n
Score : 100 points
\nThere are S sheep and W wolves.
\nIf the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.
\nIf the wolves will attack the sheep, print unsafe
; otherwise, print safe
.
Input is given from Standard Input in the following format:
\nS W\n\n
If the wolves will attack the sheep, print unsafe
; otherwise, print safe
.
4 5\n\n
unsafe\n\n
There are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.
\n100 2\n\n
safe\n\n
Many a sheep drive away two wolves.
\n10 10\n\n
unsafe\n
Score : 100 points
\nA Hitachi string is a concatenation of one or more copies of the string hi
.
For example, hi
and hihi
are Hitachi strings, while ha
and hii
are not.
Given a string S, determine whether S is a Hitachi string.
\nInput is given from Standard Input in the following format:
\nS\n\n
If S is a Hitachi string, print Yes
; otherwise, print No
.
hihi\n\n
Yes\n\n
hihi
is the concatenation of two copies of hi
, so it is a Hitachi string.
hi\n\n
Yes\n\n
ha\n\n
No\n
Score : 100 points
\nA 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.
\nTakahashi 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.
\nPrint Left
if the balance scale tips to the left; print Balanced
if it balances; print Right
if it tips to the right.
Input is given from Standard Input in the following format:
\nA B C D\n\n
Print Left
if the balance scale tips to the left; print Balanced
if it balances; print Right
if it tips to the right.
3 8 7 1\n\n
Left\n\n
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
.
3 4 5 2\n\n
Balanced\n\n
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
.
1 7 6 4\n\n
Right\n\n
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
.
Score : 200 points
\nYou have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.
\nYou can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.
\nYou planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.
\nYou want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples.
\nFind the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above.
\nWe can prove that this value is uniquely determined.
\nInput is given from Standard Input in the following format:
\nN L\n\n
Find the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat.
\n5 2\n\n
18\n\n
The flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively. The optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.
\n3 -1\n\n
0\n\n
The flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal choice is to eat Apple 2, so the answer is (-1)+1=0.
\n30 -50\n\n
-1044\n
Score : 200 points
\nThe development of algae in a pond is as follows.
\nLet the total weight of the algae at the beginning of the year i be x_i gram. For i≥2000, the following formula holds:
\nYou are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print them in order.
\nInput is given from Standard Input in the following format:
\nr D x_{2000}\n\n
Print 10 lines. The i-th line (1 ≤ i ≤ 10) should contain x_{2000+i} as an integer.
\n2 10 20\n\n
30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n\n
For example, x_{2001} = rx_{2000} - D = 2 \\times 20 - 10 = 30 and x_{2002} = rx_{2001} - D = 2 \\times 30 - 10 = 50.
\n4 40 60\n\n
200\n760\n3000\n11960\n47800\n191160\n764600\n3058360\n12233400\n48933560\n
Score : 200 points
\nOur world is one-dimensional, and ruled by two empires called Empire A and Empire B.
\nThe capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.
\nOne day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.
\nIf there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.
\nDetermine if war will break out.
\nInput is given from Standard Input in the following format:
\nN M X Y\nx_1 x_2 ... x_N\ny_1 y_2 ... y_M\n\n
If war will break out, print War
; otherwise, print No War
.
3 2 10 20\n8 15 13\n16 22\n\n
No War\n\n
The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.
\n4 2 -48 -1\n-20 -35 -91 -23\n-22 66\n\n
War\n\n
5 3 6 8\n-10 3 1 5 -100\n100 6 14\n\n
War\n
Score : 300 points
\nWe have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \\leq i \\leq H, 1 \\leq j \\leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is .
, and black if c_{i,j} is #
.
Consider doing the following operation:
\nYou are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
\n.
or #
.Input is given from Standard Input in the following format:
\nH W K\nc_{1,1}c_{1,2}...c_{1,W}\nc_{2,1}c_{2,2}...c_{2,W}\n:\nc_{H,1}c_{H,2}...c_{H,W}\n\n
Print an integer representing the number of choices of rows and columns satisfying the condition.
\n2 3 2\n..#\n###\n\n
5\n\n
Five choices below satisfy the condition.
\n2 3 4\n..#\n###\n\n
1\n\n
One choice, which is choosing nothing, satisfies the condition.
\n2 2 3\n##\n##\n\n
0\n\n
6 6 8\n..##..\n.#..#.\n#....#\n######\n#....#\n#....#\n\n
208\n
Score : 300 points
\nYou are given a string S consisting of lowercase English letters.\nAnother string T is initially empty.\nDetermine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:
\ndream
, dreamer
, erase
and eraser
.The input is given from Standard Input in the following format:
\nS\n\n
If it is possible to obtain S = T, print YES
. Otherwise, print NO
.
erasedream\n\n
YES\n\n
Append erase
and dream
at the end of T in this order, to obtain S = T.
dreameraser\n\n
YES\n\n
Append dream
and eraser
at the end of T in this order, to obtain S = T.
dreamerer\n\n
NO\n
Score : 100 points
\nTakahashi is meeting up with Aoki.
\nThey have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.
\nTakahashi will leave his house now and go straight to the place at a speed of S meters per minute.
\nWill he arrive in time?
\nInput is given from Standard Input in the following format:
\nD T S\n\n
If Takahashi will reach the place in time, print Yes
; otherwise, print No
.
1000 15 80\n\n
Yes\n\n
It takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters per minute. They have planned to meet in 15 minutes so he will arrive in time.
\n2000 20 100\n\n
Yes\n\n
It takes 20 minutes to go 2000 meters to the place at a speed of 100 meters per minute. They have planned to meet in 20 minutes so he will arrive just on time.
\n10000 1 1\n\n
No\n\n
He will be late.
Score : 100 points
\nYou are given a string S of length 3 consisting of a
, b
and c
. Determine if S can be obtained by permuting abc
.
a
, b
and c
.Input is given from Standard Input in the following format:
\nS\n\n
If S can be obtained by permuting abc
, print Yes
; otherwise, print No
.
bac\n\n
Yes\n\n
Swapping the first and second characters in bac
results in abc
.
bab\n\n
No\n\n
abc\n\n
Yes\n\n
aaa\n\n
No\n
Score : 100 points
\nYou went shopping to buy cakes and donuts with X yen (the currency of Japan).
\nFirst, you bought one cake for A yen at a cake shop.\nThen, you bought as many donuts as possible for B yen each, at a donut shop.
\nHow much do you have left after shopping?
\nInput is given from Standard Input in the following format:
\nX\nA\nB\n\n
Print the amount you have left after shopping.
\n1234\n150\n100\n\n
84\n\n
You have 1234 - 150 = 1084 yen left after buying a cake.\nWith this amount, you can buy 10 donuts, after which you have 84 yen left.
\n1000\n108\n108\n\n
28\n\n
579\n123\n456\n\n
0\n\n
7477\n549\n593\n\n
405\n
Score : 200 points
\nYou are given a positive integer X.\nFind the largest perfect power that is at most X.\nHere, 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.
\nInput is given from Standard Input in the following format:
\nX\n\n
Print the largest perfect power that is at most X.
\n10\n\n
9\n\n
There are four perfect powers that are at most 10: 1, 4, 8 and 9.\nWe should print the largest among them, 9.
\n1\n\n
1\n\n
999\n\n
961\n
Score : 200 points
\nYou are given a string S of length N consisting of lowercase English letters, and an integer K.\nPrint the string obtained by replacing every character in S that differs from the K-th character of S, with *
.
Input is given from Standard Input in the following format:
\nN\nS\nK\n\n
Print the string obtained by replacing every character in S that differs from the K-th character of S, with *
.
5\nerror\n2\n\n
*rr*r\n\n
The second character of S is r
. When we replace every character in error
that differs from r
with *
, we get the string *rr*r
.
6\neleven\n5\n\n
e*e*e*\n\n
9\neducation\n7\n\n
******i**\n
Score : 100 points
\nThere are N students in a school.
\nWe will divide these students into some groups, and in each group they will discuss some themes.
\nYou 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.
\nDivide the students so that the number of groups consisting of three or more students is maximized.
\nInput is given from Standard Input in the following format:
\nN\n\n
If you can form at most x groups consisting of three or more students, print x.
\n8\n\n
2\n\n
For example, you can form a group of three students and another of five students.
\n2\n\n
0\n\n
Sometimes you cannot form any group consisting of three or more students, regardless of how you divide the students.
\n9\n\n
3\n
Score : 100 points
\nDetermine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
\nInput is given from Standard Input in the following format:
\nN K\n\n
If we can choose K integers as above, print YES
; otherwise, print NO
.
3 2\n\n
YES\n\n
We can choose 1 and 3.
\n5 5\n\n
NO\n\n
31 10\n\n
YES\n\n
10 90\n\n
NO\n
Score : 100 points
\nTakahashi wants to be a member of some web service.
\nHe tried to register himself with the ID S, which turned out to be already used by another user.
\nThus, he decides to register using a string obtained by appending one character at the end of S as his ID.
\nHe is now trying to register with the ID T. Determine whether this string satisfies the property above.
\nInput is given from Standard Input in the following format:
\nS\nT\n\n
If T satisfies the property in Problem Statement, print Yes
; otherwise, print No
.
chokudai\nchokudaiz\n\n
Yes\n\n
chokudaiz
can be obtained by appending z
at the end of chokudai
.
snuke\nsnekee\n\n
No\n\n
snekee
cannot be obtained by appending one character at the end of snuke
.
a\naa\n\n
Yes\n
Score : 300 points
\nWe will play a one-player game using a number line and N pieces.
\nFirst, we place each of these pieces at some integer coordinate.
\nHere, multiple pieces can be placed at the same coordinate.
\nOur objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move:
\nMove: Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1.
\nNote that the coordinates where we initially place the pieces are already regarded as visited.
\nFind the minimum number of moves required to achieve the objective.
\nInput is given from Standard Input in the following format:
\nN M\nX_1 X_2 ... X_M\n\n
Find the minimum number of moves required to achieve the objective.
\n2 5\n10 12 1 2 14\n\n
5\n\n
The objective can be achieved in five moves as follows, and this is the minimum number of moves required.
\n3 7\n-10 -3 0 9 -100 2 17\n\n
19\n\n
100 1\n-100000\n\n
0\n
Score : 100 points
\nWe have a 3×3 square grid, where each square contains a lowercase English letters.\nThe letter in the square at the i-th row from the top and j-th column from the left is c_{ij}.
\nPrint 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.
\nInput is given from Standard Input in the following format:
\nc_{11}c_{12}c_{13}\nc_{21}c_{22}c_{23}\nc_{31}c_{32}c_{33}\n\n
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.
\nant\nobe\nrec\n\n
abc\n\n
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
.
edu\ncat\nion\n\n
ean\n
Score : 100 points
\nYou are given a three-digit positive integer N.
\nDetermine whether N is a palindromic number.
\nHere, a palindromic number is an integer that reads the same backward as forward in decimal notation.
Input is given from Standard Input in the following format:
\nN\n\n
If N is a palindromic number, print Yes
; otherwise, print No
.
575\n\n
Yes\n\n
N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes
.
123\n\n
No\n\n
N=123 becomes 321 when read backward, so it is not a palindromic number. You should print No
.
812\n\n
No\n
Score : 100 points
\nGiven is a three-digit integer N. Does N contain the digit 7?
\nIf so, print Yes
; otherwise, print No
.
Input is given from Standard Input in the following format:
\nN\n\n
If N contains the digit 7, print Yes
; otherwise, print No
.
117\n\n
Yes\n\n
117 contains 7 as its last digit.
\n123\n\n
No\n\n
123 does not contain the digit 7.
\n777\n\n
Yes\n
Score : 100 points
\nThere are two rectangles.\nThe lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B.\nThe lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.
\nPrint the area of the rectangle with the larger area.\nIf the two rectangles have equal areas, print that area.
\nThe input is given from Standard Input in the following format:
\nA B C D\n\n
Print the area of the rectangle with the larger area.\nIf the two rectangles have equal areas, print that area.
\n3 5 2 7\n\n
15\n\n
The first rectangle has an area of 3×5=15, and the second rectangle has an area of 2×7=14.\nThus, the output should be 15, the larger area.
\n100 600 200 300\n\n
60000\n
Score : 200 points
\nLet us define the FizzBuzz sequence a_1,a_2,... as follows:
\nFind the sum of all numbers among the first N terms of the FizzBuzz sequence.
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the sum of all numbers among the first N terms of the FizzBuzz sequence.
\n15\n\n
60\n\n
The first 15 terms of the FizzBuzz sequence are:
\n1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}
\nAmong them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.
\n1000000\n\n
266666333332\n\n
Watch out for overflow.
Score : 100 points
\nAtCoDeer the deer found two positive integers, a and b.\nDetermine whether the product of a and b is even or odd.
\nInput is given from Standard Input in the following format:
\na b\n\n
If the product is odd, print Odd
; if it is even, print Even
.
3 4\n\n
Even\n\n
As 3 × 4 = 12 is even, print Even
.
1 21\n\n
Odd\n\n
As 1 × 21 = 21 is odd, print Odd
.
Score : 300 points
\nCompute A \\times B, truncate its fractional part, and print the result as an integer.
\nInput is given from Standard Input in the following format:
\nA B\n\n
Print the answer as an integer.
\n198 1.10\n\n
217\n\n
We have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have the answer: 217.
\n1 0.01\n\n
0\n\n
1000000000000000 9.99\n\n
9990000000000000\n
Score : 200 points
\nYou are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
\nA pixel is the smallest element of an image, and in this problem it is a square of size 1×1.
\nAlso, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: .
corresponds to a white pixel, and #
corresponds to a black pixel.
\nThe image A is given as N strings A_1,...,A_N.
\nThe j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).
\nSimilarly, the template image B is given as M strings B_1,...,B_M.
\nThe j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
\n#
and .
.#
and .
.The input is given from Standard Input in the following format:
\nN M\nA_1\nA_2\n: \nA_N\nB_1\nB_2\n: \nB_M\n\n
Print Yes
if the template image B is contained in the image A. Print No
otherwise.
3 2\n#.#\n.#.\n#.#\n#.\n.#\n\n
Yes\n\n
The template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes
.
4 1\n....\n....\n....\n....\n#\n\n
No\n\n
The template image B, composed of a black pixel, is not contained in the image A composed of white pixels.
Score : 200 points
\nTakahashi loves numbers divisible by 2.
\nYou are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
\nHere, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
\nFor example,
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the answer.
\n7\n\n
4\n\n
4 can be divided by 2 twice, which is the most number of times among 1, 2, ..., 7.
\n32\n\n
32\n\n
1\n\n
1\n\n
100\n\n
64\n
Score : 500 points
\nYou are given a sequence with N integers: A = \\{ A_1, A_2, \\cdots, A_N \\}.\nFor each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:
\nFind the minimum number of colors required to satisfy the condition.
\nInput is given from Standard Input in the following format:
\nN\nA_1\n:\nA_N\n\n
Print the minimum number of colors required to satisfy the condition.
\n5\n2\n1\n4\n5\n3\n\n
2\n\n
We can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1, 4, and 5 blue.
\n4\n0\n0\n0\n0\n\n
4\n\n
We have to paint all the integers with distinct colors.
Score : 300 points
\nDolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
\nCurrently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
\nHere, both the x- and y-coordinates before and after each movement must be integers.
\nHe will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
\nHere, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
\nUnder this condition, find a shortest path for him.
The input is given from Standard Input in the following format:
\nsx sy tx ty\n\n
Print a string S that represents a shortest path for Dolphin.
\nThe i-th character in S should correspond to his i-th movement.
\nThe directions of the movements should be indicated by the following characters:
U
: UpD
: DownL
: LeftR
: RightIf there exist multiple shortest paths under the condition, print any of them.
\n0 0 1 2\n\n
UURDDLLUUURRDRDDDLLU\n\n
One possible shortest path is:
\n-2 -2 1 1\n\n
UURRURRDDDLLDLLULUUURRURRDDDLLDL\n
Score : 400 points
\nYou have N cards. On the i-th card, an integer A_i is written.
\nFor each j = 1, 2, ..., M in this order, you will perform the following operation once:
\nOperation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.
\nFind the maximum possible sum of the integers written on the N cards after the M operations.
\nInput is given from Standard Input in the following format:
\nN M\nA_1 A_2 ... A_N\nB_1 C_1\nB_2 C_2\n\\vdots\nB_M C_M\n\n
Print the maximum possible sum of the integers written on the N cards after the M operations.
\n3 2\n5 1 4\n2 3\n1 5\n\n
14\n\n
By replacing the integer on the second card with 5, the sum of the integers written on the three cards becomes 5 + 5 + 4 = 14, which is the maximum result.
\n10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4\n\n
338\n\n
3 2\n100 100 100\n3 99\n3 99\n\n
300\n\n
11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000\n\n
10000000001\n\n
The output may not fit into a 32-bit integer type.
Score: 400 points
\nQuickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.
\nThe N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.
\nWhen each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.
\nWhat is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 \\dots A_N\n\n
Print the maximum total comfort the N players can get.
\n4\n2 2 1 3\n\n
7\n\n
By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.
\nThey cannot get the total comfort greater than 7, so the answer is 7.
\n7\n1 1 1 1 1 1 1\n\n
6\n
Score: 200 points
\nTakahashi will do a tap dance. The dance is described by a string S where each character is L
, R
, U
, or D
. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character.
S is said to be easily playable if and only if it satisfies both of the following conditions:
\nR
, U
, or D
.L
, U
, or D
.Your task is to print Yes
if S is easily playable, and No
otherwise.
L
, R
, U
, or D
.Input is given from Standard Input in the following format:
\nS\n\n
Print Yes
if S is easily playable, and No
otherwise.
RUDLUDR\n\n
Yes\n\n
Every character in an odd position (1-st, 3-rd, 5-th, 7-th) is R
, U
, or D
.
Every character in an even position (2-nd, 4-th, 6-th) is L
, U
, or D
.
Thus, S is easily playable.
\nDULL\n\n
No\n\n
The 3-rd character is not R
, U
, nor D
, so S is not easily playable.
UUUUUUUUUUUUUUU\n\n
Yes\n\n
ULURU\n\n
No\n\n
RDULULDURURLRDULRLR\n\n
Yes\n
Score: 300 points
\nConsider an analog clock whose hour and minute hands are A and B centimeters long, respectively.
\nAn endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.
\nAt 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?
\nInput is given from Standard Input in the following format:
\nA B H M\n\n
Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.
\n3 4 9 0\n\n
5.00000000000000000000\n\n
The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.
\n3 4 10 40\n\n
4.56425719433005567605\n\n
The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.
\nScore : 100 points
\nWe call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
\nYou are given a 4-digit integer N. Answer the question: Is N good?
\nInput is given from Standard Input in the following format:
\nN\n\n
If N is good, print Yes
; otherwise, print No
.
1118\n\n
Yes\n\n
N is good, since it contains three consecutive 1.
\n7777\n\n
Yes\n\n
An integer is also good when all the digits are the same.
\n1234\n\n
No\n
Score : 300 points
\nIn a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0.\nYou are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \\leq k \\leq N), by repeating the following \"watering\" operation:
\nFind the minimum number of watering operations required to satisfy the condition.
\nInput is given from Standard Input in the following format:
\nN\nh_1 h_2 h_3 ...... h_N\n\n
Print the minimum number of watering operations required to satisfy the condition.
\n4\n1 2 2 1\n\n
2\n\n
The minimum number of watering operations required is 2.\nOne way to achieve it is:
\n5\n3 1 2 3 1\n\n
5\n\n
8\n4 23 75 0 23 96 50 100\n\n
221\n
Score : 300 points
\nFennec is fighting with N monsters.
\nThe health of the i-th monster is H_i.
\nFennec can do the following two actions:
\nThere is no way other than Attack and Special Move to decrease the monsters' health.
\nFennec wins when all the monsters' healths become 0 or below.
\nFind the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.
\nInput is given from Standard Input in the following format:
\nN K\nH_1 ... H_N\n\n
Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.
\n3 1\n4 1 5\n\n
5\n\n
By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.
\n8 9\n7 9 3 2 3 8 4 6\n\n
0\n\n
She can use Special Move on all the monsters.
\n3 0\n1000000000 1000000000 1000000000\n\n
3000000000\n\n
Watch out for overflow.
Score : 200 points
\nN friends of Takahashi has come to a theme park.
\nTo ride the most popular roller coaster in the park, you must be at least K centimeters tall.
\nThe i-th friend is h_i centimeters tall.
\nHow many of the Takahashi's friends can ride the roller coaster?
\nInput is given from Standard Input in the following format:
\nN K\nh_1 h_2 \\ldots h_N\n\n
Print the number of people among the Takahashi's friends who can ride the roller coaster.
\n4 150\n150 140 100 200\n\n
2\n\n
Two of them can ride the roller coaster: the first and fourth friends.
\n1 500\n499\n\n
0\n\n
5 1\n100 200 300 400 500\n\n
5\n
Score : 300 points
\nYou are playing the following game with Joisino.
\nThe numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?
\nInput is given from Standard Input in the following format:
\nN\nA_1\n:\nA_N\n\n
Print how many numbers will be written on the sheet at the end of the game.
\n3\n6\n2\n6\n\n
1\n\n
The game proceeds as follows:
\n6 is not written on the sheet, so write 6.
\n2 is not written on the sheet, so write 2.
\n6 is written on the sheet, so erase 6.
\nThus, the sheet contains only 2 in the end. The answer is 1.
\n4\n2\n5\n5\n2\n\n
0\n\n
It is possible that no number is written on the sheet in the end.
\n6\n12\n22\n16\n22\n18\n12\n\n
2\n
Score: 500 points
\nWe have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.
\nWe will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.
\nThe i-th and j-th sardines (i \\neq j) are on bad terms if and only if A_i \\cdot A_j + B_i \\cdot B_j = 0.
\nIn how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.
\nInput is given from Standard Input in the following format:
\nN\nA_1 B_1\n:\nA_N B_N\n\n
Print the count modulo 1000000007.
\n3\n1 2\n-1 1\n2 -1\n\n
5\n\n
There are five ways to choose the set of sardines, as follows:
\n10\n3 2\n3 2\n-1 1\n2 -1\n-3 -9\n-8 12\n7 7\n8 1\n8 2\n8 4\n\n
479\n
Score : 100 points
\nYou are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits \"1974\".
\nInput is given from Standard Input in the following format:
\nN_1 N_2 N_3 N_4\n\n
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits \"1974\", print YES
; if they cannot, print NO
.
1 7 9 4\n\n
YES\n\n
We can get 1974 by swapping N_2 and N_3.
\n1 9 7 4\n\n
YES\n\n
We already have 1974 before doing anything.
\n1 2 9 1\n\n
NO\n\n
4 9 0 8\n\n
NO\n
Score : 300 points
\nThere are N integers, A_1, A_2, ..., A_N, written on the blackboard.
\nYou will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.
\nFind the maximum possible greatest common divisor of the N integers on the blackboard after your move.
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 ... A_N\n\n
Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.
\n3\n7 6 8\n\n
2\n\n
If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.
\n3\n12 15 18\n\n
6\n\n
2\n1000000000 1000000000\n\n
1000000000\n\n
We can replace an integer with itself.
Score : 100 points
\nA biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation.
\nFind the total number of biscuits produced within T + 0.5 seconds after activation.
\nInput is given from Standard Input in the following format:
\nA B T\n\n
Print the total number of biscuits produced within T + 0.5 seconds after activation.
\n3 5 7\n\n
10\n\n
3 2 9\n\n
6\n\n
20 20 19\n\n
0\n
Score : 300 points
\nTakahashi loves the number 7 and multiples of K.
\nWhere is the first occurrence of a multiple of K in the sequence 7,77,777,\\ldots? (Also see Output and Sample Input/Output below.)
\nIf the sequence contains no multiples of K, print -1
instead.
Input is given from Standard Input in the following format:
\nK\n\n
Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4
.)
101\n\n
4\n\n
None of 7, 77, and 777 is a multiple of 101, but 7777 is.
\n2\n\n
-1\n\n
All elements in the sequence are odd numbers; there are no multiples of 2.
\n999983\n\n
999982\n
Score : 100 points
\nSmeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise.
\nYou are given Smeke's current rating, x. Print ABC
if Smeke will participate in ABC, and print ARC
otherwise.
The input is given from Standard Input in the following format:
\nx\n\n
Print the answer.
\n1000\n\n
ABC\n\n
Smeke's current rating is less than 1200, thus the output should be ABC
.
2000\n\n
ARC\n\n
Smeke's current rating is not less than 1200, thus the output should be ARC
.
Score : 100 points
\nPrint the circumference of a circle of radius R.
\nInput is given from Standard Input in the following format:
\nR\n\n
Print the circumference of the circle.\nYour output is considered correct if and only if its absolute or relative error from our answer is at most 10^{-2}.
\n1\n\n
6.28318530717958623200\n\n
Since we accept an absolute or relative error of at most 10^{-2}, 6.28 is also an acceptable output, but 6 is not.
\n73\n\n
458.67252742410977361942\n
Score : 100 points
\nIroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
\nTo create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
\nThe input is given from Standard Input in the following format:
\nA B C\n\n
If it is possible to construct a Haiku by using each of the phrases once, print YES
(case-sensitive). Otherwise, print NO
.
5 5 7\n\n
YES\n\n
Using three phrases of length 5, 5 and 7, it is possible to construct a Haiku.
\n7 7 5\n\n
NO\n
Score : 100 points
\nThere are two buttons, one of size A and one of size B.
\nWhen you press a button of size X, you get X coins and the size of that button decreases by 1.
\nYou will press a button twice. Here, you can press the same button twice, or press both buttons once.
\nAt most how many coins can you get?
\nInput is given from Standard Input in the following format:
\nA B\n\n
Print the maximum number of coins you can get.
\n5 3\n\n
9\n\n
You can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this is the maximum result.
\n3 4\n\n
7\n\n
6 6\n\n
12\n
Score : 100 points
\nThis contest is CODE FESTIVAL
.\nHowever, Mr. Takahashi always writes it CODEFESTIVAL
, omitting the single space between CODE
and FESTIVAL
.
So he has decided to make a program that puts the single space he omitted.
\nYou are given a string s with 12 letters.\nOutput the string putting a single space between the first 4 letters and last 8 letters in the string s.
\nThe input is given from Standard Input in the following format:
\ns\n\n
Print the string putting a single space between the first 4 letters and last 8 letters in the string s.\nPut a line break at the end.
\nCODEFESTIVAL\n\n
CODE FESTIVAL\n\n
Putting a single space between the first 4 letters and last 8 letters in CODEFESTIVAL
makes it CODE FESTIVAL
.
POSTGRADUATE\n\n
POST GRADUATE\n\n
ABCDEFGHIJKL\n\n
ABCD EFGHIJKL\n
Score : 100 points
\nIn K-city, there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
\nInput is given from Standard Input in the following format:
\nn m\n\n
Print the number of blocks in K-city.
\n3 4\n\n
6\n\n
There are six blocks, as shown below:
\n2 2\n\n
1\n\n
There are one block, as shown below:
\nScore : 100 points
\nAlice and Bob are playing One Card Poker.
\nOne Card Poker is a two-player game using playing cards.
Each card in this game shows an integer between 1
and 13
, inclusive.
\nThe strength of a card is determined by the number written on it, as follows:
Weak 2
< 3
< 4
< 5
< 6
< 7
< 8
< 9
< 10
< 11
< 12
< 13
< 1
Strong
One Card Poker is played as follows:
\nYou are watching Alice and Bob playing the game, and can see their hands.
\nThe number written on Alice's card is A, and the number written on Bob's card is B.
\nWrite a program to determine the outcome of the game.
The input is given from Standard Input in the following format:
\nA B\n\n
Print Alice
if Alice will win. Print Bob
if Bob will win. Print Draw
if the game will be drawn.
8 6\n\n
Alice\n\n
8
is written on Alice's card, and 6
is written on Bob's card.\nAlice has the stronger card, and thus the output should be Alice
.
1 1\n\n
Draw\n\n
Since their cards have the same number, the game will be drawn.
\n13 1\n\n
Bob\n
Score : 300 points
\nIn Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.
\nThere are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.
\nCat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.
\nHelp him.
\nInput is given from Standard Input in the following format:
\nN M\na_1 b_1\na_2 b_2\n:\na_M b_M\n\n
If it is possible to go to Island N by using two boat services, print POSSIBLE
; otherwise, print IMPOSSIBLE
.
3 2\n1 2\n2 3\n\n
POSSIBLE\n\n
4 3\n1 2\n2 3\n3 4\n\n
IMPOSSIBLE\n\n
You have to use three boat services to get to Island 4.
\n100000 1\n1 99999\n\n
IMPOSSIBLE\n\n
5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n\n
POSSIBLE\n\n
You can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.
Score : 400 points
\nGiven is a number sequence A of length N.
\nFind the number of integers i \\left(1 \\leq i \\leq N\\right) with the following property:
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 \\cdots A_N\n\n
Print the answer.
\n5\n24 11 8 3 16\n\n
3\n\n
The integers with the property are 2, 3, and 4.
\n4\n5 5 5 5\n\n
0\n\n
Note that there can be multiple equal numbers.
\n10\n33 18 45 28 8 19 89 86 2 4\n\n
5\n
Score : 100 points
\nTakahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.
\nAt least how many sheets of paper does he need?
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the answer.
\n5\n\n
3\n\n
By printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the 2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3 sheets of paper.
\n2\n\n
1\n\n
100\n\n
50\n
Score : 200 points
\nAtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W.\nIf we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W], as shown in the following figure:
\nAtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle.\nFind the minimum distance it needs to be moved.
\nThe input is given from Standard Input in the following format:
\nW a b\n\n
Print the minimum distance the second rectangle needs to be moved.
\n3 2 6\n\n
1\n\n
This input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1.
\n3 1 3\n\n
0\n\n
The rectangles are already connected, and thus no move is needed.
\n5 10 1\n\n
4\n
Score : 300 points
\nYou have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \\leq i \\leq N) is v_i.
\nWhen you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.
\nAfter you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.
\nInput is given from Standard Input in the following format:
\nN\nv_1 v_2 \\ldots v_N\n\n
Print a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.
\nYour output will be judged correct when its absolute or relative error from the judge's output is at most 10^{-5}.
\n2\n3 4\n\n
3.5\n\n
If you start with two ingredients, the only choice is to put both of them in the pot. The value of the ingredient resulting from the ingredients of values 3 and 4 is (3 + 4) / 2 = 3.5.
\nPrinting 3.50001
, 3.49999
, and so on will also be accepted.
3\n500 300 200\n\n
375\n\n
You start with three ingredients this time, and you can choose what to use in the first composition. There are three possible choices:
\nThus, the maximum possible value of the last ingredient remaining is 375.
\nPrinting 375.0
and so on will also be accepted.
5\n138 138 138 138 138\n\n
138\n
Score : 200 points
\nTakahashi has A cookies, and Aoki has B cookies.\nTakahashi will do the following action K times:
\nIn the end, how many cookies will Takahashi and Aoki have, respectively?
\nInput is given from Standard Input in the following format:
\nA B K\n\n
Print the numbers of Takahashi's and Aoki's cookies after K actions.
\n2 3 3\n\n
0 2\n\n
Takahashi will do the following:
\nThus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.
\n500000000000 500000000000 1000000000000\n\n
0 0\n\n
Watch out for overflows.
Score : 200 points
\nYou are given a string S consisting of lowercase English letters.\nFind the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S.\nIf every lowercase English letter occurs in S, print None
instead.
Input is given from Standard Input in the following format:
\nS\n\n
Print the lexicographically smallest lowercase English letter that does not occur in S.\nIf every lowercase English letter occurs in S, print None
instead.
atcoderregularcontest\n\n
b\n\n
The string atcoderregularcontest
contains a
, but does not contain b
.
abcdefghijklmnopqrstuvwxyz\n\n
None\n\n
This string contains every lowercase English letter.
\nfajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg\n\n
d\n
Score : 200 points
\nGiven N integers A_1, ..., A_N, compute A_1 \\times ... \\times A_N.
\nHowever, if the result exceeds 10^{18}, print -1
instead.
Input is given from Standard Input in the following format:
\nN\nA_1 ... A_N\n\n
Print the value A_1 \\times ... \\times A_N as an integer, or -1
if the value exceeds 10^{18}.
2\n1000000000 1000000000\n\n
1000000000000000000\n\n
We have 1000000000 \\times 1000000000 = 1000000000000000000.
\n3\n101 9901 999999000001\n\n
-1\n\n
We have 101 \\times 9901 \\times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1
instead.
31\n4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0\n\n
0\n
Score : 200 points
\nThe word internationalization
is sometimes abbreviated to i18n
.\nThis comes from the fact that there are 18 letters between the first i
and the last n
.
You are given a string s of length at least 3 consisting of lowercase English letters.\nAbbreviate s in the same way.
\nInput is given from Standard Input in the following format:
\ns\n\n
Print the abbreviation of s.
\ninternationalization\n\n
i18n\n\n
smiles\n\n
s4s\n\n
xyz\n\n
x1z\n
Score : 100 points
\nThere are N stones, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), the height of Stone i is h_i.
\nThere is a frog who is initially on Stone 1.\nHe will repeat the following action some number of times to reach Stone N:
\nFind the minimum possible total cost incurred before the frog reaches Stone N.
\nInput is given from Standard Input in the following format:
\nN\nh_1 h_2 \\ldots h_N\n\n
Print the minimum possible total cost incurred.
\n4\n10 30 40 20\n\n
30\n\n
If we follow the path 1 → 2 → 4, the total cost incurred would be |10 - 30| + |30 - 20| = 30.
\n2\n10 10\n\n
0\n\n
If we follow the path 1 → 2, the total cost incurred would be |10 - 10| = 0.
\n6\n30 10 60 10 60 50\n\n
40\n\n
If we follow the path 1 → 3 → 5 → 6, the total cost incurred would be |30 - 60| + |60 - 60| + |60 - 50| = 40.
Score : 400 points
\nThere are N persons called Person 1 through Person N.
\nYou are given M facts that \"Person A_i and Person B_i are friends.\" The same fact may be given multiple times.
\nIf X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.
\nTakahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.
\nAt least how many groups does he need to make?
\nInput is given from Standard Input in the following format:
\nN M\nA_1 B_1\n\\vdots\nA_M B_M\n\n
Print the answer.
\n5 3\n1 2\n3 4\n5 1\n\n
3\n\n
Dividing them into three groups such as \\{1,3\\}, \\{2,4\\}, and \\{5\\} achieves the goal.
\n4 10\n1 2\n2 1\n1 2\n2 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n\n
4\n\n
10 4\n3 1\n4 1\n5 9\n2 6\n\n
3\n
Score : 400 points
\nWe have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.
\nWe will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.
\nInput is given from Standard Input in the following format:
\nN K\np_1 ... p_N\n\n
Print the maximum possible value of the expected value of the sum of the numbers shown.
\nYour output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.
\n5 3\n1 2 2 4 5\n\n
7.000000000000\n\n
When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.
\n4 1\n6 6 6 6\n\n
3.500000000000\n\n
Regardless of which die we choose, the expected value of the number shown is 3.5.
\n10 4\n17 13 13 12 15 20 10 13 17 11\n\n
32.000000000000\n
Score : 100 points
\nWe have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S
, it means it was sunny on the i-th day; if that character is R
, it means it was rainy on that day.
Find the maximum number of consecutive rainy days in this period.
\nS
or R
.Input is given from Standard Input in the following format:
\nS\n\n
Print the maximum number of consecutive rainy days in the period.
\nRRS\n\n
2\n\n
We had rain on the 1-st and 2-nd days in the period. Here, the maximum number of consecutive rainy days is 2, so we should print 2.
\nSSS\n\n
0\n\n
It was sunny throughout the period. We had no rainy days, so we should print 0.
\nRSR\n\n
1\n\n
We had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we should print 1.
Score : 100 points
\nYou will be given an integer a and a string s consisting of lowercase English letters as input.
\nWrite a program that prints s if a is not less than 3200 and prints red
if a is less than 3200.
Input is given from Standard Input in the following format:
\na\ns\n\n
If a is not less than 3200, print s; if a is less than 3200, print red
.
3200\npink\n\n
pink\n\n
a = 3200 is not less than 3200, so we print s = pink
.
3199\npink\n\n
red\n\n
a = 3199 is less than 3200, so we print red
.
4049\nred\n\n
red\n\n
a = 4049 is not less than 3200, so we print s = red
.
Score : 100 points
\nYou are given two positive integers a and b.\nLet x be the average of a and b.\nPrint x rounded up to the nearest integer.
\nInput is given from Standard Input in the following format:
\na b\n\n
Print x rounded up to the nearest integer.
\n1 3\n\n
2\n\n
The average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.
\n7 4\n\n
6\n\n
The average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.
\n5 5\n\n
5\n
Score : 100 points
\nWe have three boxes A, B, and C, each of which contains an integer.
\nCurrently, the boxes A, B, and C contain the integers X, Y, and Z, respectively.
\nWe will now do the operations below in order. Find the content of each box afterward.
Input is given from Standard Input in the following format:
\nX Y Z\n\n
Print the integers contained in the boxes A, B, and C, in this order, with space in between.
\n1 2 3\n\n
3 1 2\n\n
After the contents of the boxes A and B are swapped, A, B, and C contain 2, 1, and 3, respectively.
\nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and 2, respectively.
100 100 100\n\n
100 100 100\n\n
41 59 31\n\n
31 41 59\n
Score : 200 points
\nSnuke has decided to construct a string that starts with A
and ends with Z
, by taking out a substring of a string s (that is, a consecutive part of s).
Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A
and ends with Z
.
A
and ends with Z
.The input is given from Standard Input in the following format:
\ns\n\n
Print the answer.
\nQWERTYASDFZXCV\n\n
5\n\n
By taking out the seventh through eleventh characters, it is possible to construct ASDFZ
, which starts with A
and ends with Z
.
ZABCZ\n\n
4\n\n
HASFJGHOGAKZZFEGA\n\n
12\n
Score: 100 points
\nM-kun is a competitor in AtCoder, whose highest rating is X.
\nIn this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:
What kyu does M-kun have?
\nInput is given from Standard Input in the following format:
\nX\n\n
Print the kyu M-kun has, as an integer.\nFor example, if he has 8-kyu, print 8
.
725\n\n
7\n\n
M-kun's highest rating is 725, which corresponds to 7-kyu.
\nThus, 7
is the correct output.
1600\n\n
2\n\n
M-kun's highest rating is 1600, which corresponds to 2-kyu.
\nThus, 2
is the correct output.
Score : 100 points
\nGiven is an integer r.
\nHow many times is the area of a circle of radius r larger than the area of a circle of radius 1?
\nIt can be proved that the answer is always an integer under the constraints given.
\nInput is given from Standard Input in the following format:
\nr\n\n
Print the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.
\n2\n\n
4\n\n
The area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.
\nNote that output must be an integer - for example, 4.0
will not be accepted.
100\n\n
10000\n
Score : 300 points
\nTakahashi is a teacher responsible for a class of N students.
\nThe students are given distinct student numbers from 1 to N.
\nToday, all the students entered the classroom at different times.
\nAccording to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).
\nFrom these records, reconstruct the order in which the students entered the classroom.
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 \\ldots A_N\n\n
Print the student numbers of the students in the order the students entered the classroom.
\n3\n2 3 1\n\n
3 1 2\n\n
First, student number 3 entered the classroom.
\nThen, student number 1 entered the classroom.
\nFinally, student number 2 entered the classroom.
\n5\n1 2 3 4 5\n\n
1 2 3 4 5\n\n
8\n8 2 7 3 4 5 6 1\n\n
8 2 4 5 6 7 3 1\n
Score : 200 points
\nThere are N positive integers written on a blackboard: A_1, ..., A_N.
\nSnuke can perform the following operation when all integers on the blackboard are even:
\nFind the maximum possible number of operations that Snuke can perform.
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 ... A_N\n\n
Print the maximum possible number of operations that Snuke can perform.
\n3\n8 12 40\n\n
2\n\n
Initially, [8, 12, 40] are written on the blackboard.\nSince all those integers are even, Snuke can perform the operation.
\nAfter the operation is performed once, [4, 6, 20] are written on the blackboard.\nSince 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.\nNow, 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.
\n4\n5 6 8 10\n\n
0\n\n
Since there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all.
\n6\n382253568 723152896 37802240 379425024 404894720 471526144\n\n
8\n
Score : 300 points
\nTakahashi is standing on a multiplication table with infinitely many rows and columns.
\nThe square (i,j) contains the integer i \\times j. Initially, Takahashi is standing at (1,1).
\nIn one move, he can move from (i,j) to either (i+1,j) or (i,j+1).
\nGiven an integer N, find the minimum number of moves needed to reach a square that contains N.
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the minimum number of moves needed to reach a square that contains the integer N.
\n10\n\n
5\n\n
(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.
\n50\n\n
13\n\n
(5, 10) can be reached in 13 moves.
\n10000000019\n\n
10000000018\n\n
Both input and output may be enormous.
Score : 100 points
\nYou are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the minimum positive integer divisible by both 2 and N.
\n3\n\n
6\n\n
6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.
\n10\n\n
10\n\n
999999999\n\n
1999999998\n
Score : 200 points
\nYou are visiting a large electronics store to buy a refrigerator and a microwave.
\nThe store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \\le i \\le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \\le j \\le B ) is sold at b_j yen.
\nYou have M discount tickets. With the i-th ticket ( 1 \\le i \\le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.
\nYou are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
\nInput is given from Standard Input in the following format:
\nA B M\na_1 a_2 ... a_A\nb_1 b_2 ... b_B\nx_1 y_1 c_1\n\\vdots\nx_M y_M c_M\n\n
Print the answer.
\n2 3 1\n3 3\n3 3 3\n1 2 1\n\n
5\n\n
With the ticket, you can get the 1-st refrigerator and the 2-nd microwave for 3+3-1=5 yen.
\n1 1 2\n10\n10\n1 1 5\n1 1 10\n\n
10\n\n
Note that you cannot use more than one ticket at a time.
\n2 2 1\n3 5\n3 5\n2 2 2\n\n
6\n\n
You can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is the minimum amount to pay in this case.\nNote that using a ticket is optional.
Score : 200 points
\nA ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \\leq i \\leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.
\nHow many times will the ball make a bounce where the coordinate is at most X?
\nInput is given from Standard Input in the following format:
\nN X\nL_1 L_2 ... L_{N-1} L_N\n\n
Print the number of times the ball will make a bounce where the coordinate is at most X.
\n3 6\n3 4 5\n\n
2\n\n
The ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two are less than or equal to 6.
\n4 9\n3 3 3 3\n\n
4\n\n
The ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which four are less than or equal to 9.
Score : 100 points
\nIn AtCoder City, there are three stations numbered 1, 2, and 3.
\nEach of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A
, Company A operates Station i; if S_i is B
, Company B operates Station i.
To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.
\nDetermine if there is a pair of stations that will be connected by a bus service.
\nA
or B
.Input is given from Standard Input in the following format:
\nS\n\n
If there is a pair of stations that will be connected by a bus service, print Yes
; otherwise, print No
.
ABA\n\n
Yes\n\n
Company A operates Station 1 and 3, while Company B operates Station 2.
\nThere will be a bus service between Station 1 and 2, and between Station 2 and 3, so print Yes
.
BBA\n\n
Yes\n\n
Company B operates Station 1 and 2, while Company A operates Station 3.
\nThere will be a bus service between Station 1 and 3, and between Station 2 and 3, so print Yes
.
BBB\n\n
No\n\n
Company B operates all the stations. Thus, there will be no bus service, so print No
.
Score : 300 points
\nGiven is a string S. Let T be the concatenation of K copies of S.\nWe can repeatedly perform the following operation: choose a character in T and replace it with a different character.\nFind the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.
\nInput is given from Standard Input in the following format:
\nS\nK\n\n
Print the minimum number of operations required.
\nissii\n2\n\n
4\n\n
T is issiiissii
. For example, we can rewrite it into ispiqisyhi
, and now any two adjacent characters are different.
qq\n81\n\n
81\n\n
cooooooooonteeeeeeeeeest\n999993333\n\n
8999939997\n
Score: 300 points
\nFind the minimum prime number greater than or equal to X.
\nA prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself.
\nFor example, 2, 3, and 5 are prime numbers, while 4 and 6 are not.
\nInput is given from Standard Input in the following format:
\nX\n\n
Print the minimum prime number greater than or equal to X.
\n20\n\n
23\n\n
The minimum prime number greater than or equal to 20 is 23.
\n2\n\n
2\n\n
X itself can be a prime number.
\n99992\n\n
100003\n
Score : 300 points
\nThere are N+1 towns. The i-th town is being attacked by A_i monsters.
\nWe have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.
\nWhat is the maximum total number of monsters the heroes can cooperate to defeat?
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 ... A_{N+1}\nB_1 B_2 ... B_N\n\n
Print the maximum total number of monsters the heroes can defeat.
\n2\n3 5 2\n4 5\n\n
9\n\n
If the heroes choose the monsters to defeat as follows, they can defeat nine monsters in total, which is the maximum result.
\n3\n5 6 3 8\n5 100 8\n\n
22\n\n
2\n100 1 1\n1 100\n\n
3\n
Score : 200 points
\nThere is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.
\nSnuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).
\nThen, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:
\nFind the area of the white region within the rectangle after he finished painting.
\nThe input is given from Standard Input in the following format:
\nW H N\nx_1 y_1 a_1\nx_2 y_2 a_2\n:\nx_N y_N a_N\n\n
Print the area of the white region within the rectangle after Snuke finished painting.
\n5 4 2\n2 1 1\n3 3 4\n\n
9\n\n
The figure below shows the rectangle before Snuke starts painting.
\nFirst, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:
\nThen, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:
\nNow, the area of the white region within the rectangle is 9.
\n5 4 3\n2 1 1\n3 3 4\n1 4 2\n\n
0\n\n
It is possible that the whole region within the rectangle is painted black.
\n10 10 5\n1 6 1\n4 1 3\n6 9 4\n9 4 2\n3 1 3\n\n
64\n
Score : 100 points
\nYou are given a 4-character string S consisting of uppercase English letters.\nDetermine if S consists of exactly two kinds of characters which both appear twice in S.
\nInput is given from Standard Input in the following format:
\nS\n\n
If S consists of exactly two kinds of characters which both appear twice in S, print Yes
; otherwise, print No
.
ASSA\n\n
Yes\n\n
S consists of A
and S
which both appear twice in S.
STOP\n\n
No\n\n
FFEE\n\n
Yes\n\n
FREE\n\n
No\n
Score : 300 points
\nYou drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.
\nHow many kinds of items did you get?
\nInput is given from Standard Input in the following format:
\nN\nS_1\n:\nS_N\n\n
Print the number of kinds of items you got.
\n3\napple\norange\napple\n\n
2\n\n
You got two kinds of items: apple
and orange
.
5\ngrape\ngrape\ngrape\ngrape\ngrape\n\n
1\n\n
4\naaaa\na\naaa\naa\n\n
4\n
Score : 100 points
\nThere are three airports A, B and C, and flights between each pair of airports in both directions.
\nA one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.
\nConsider a route where we start at one of the airports, fly to another airport and then fly to the other airport.
\nWhat is the minimum possible sum of the flight times?
\nInput is given from Standard Input in the following format:
\nP Q R\n\n
Print the minimum possible sum of the flight times.
\n1 3 4\n\n
4\n\n
The minimum of these is 4 hours.
\n3 2 3\n\n
5\n
Score : 400 points
\nYou have a sequence A composed of N positive integers: A_{1}, A_{2}, \\cdots, A_{N}.
\nYou will now successively do the following Q operations:
\nFor each i (1 \\leq i \\leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
\nInput is given from Standard Input in the following format:
\nN\nA_{1} A_{2} \\cdots A_{N}\nQ\nB_{1} C_{1}\nB_{2} C_{2}\n\\vdots\nB_{Q} C_{Q}\n\n
Print Q integers S_{i} to Standard Output in the following format:
\nS_{1}\nS_{2}\n\\vdots\nS_{Q}\n\n
Note that S_{i} may not fit into a 32-bit integer.
\n4\n1 2 3 4\n3\n1 2\n3 4\n2 4\n\n
11\n12\n16\n\n
Initially, the sequence A is 1,2,3,4.
\nAfter each operation, it becomes the following:
\n4\n1 1 1 1\n3\n1 2\n2 1\n3 5\n\n
8\n4\n4\n\n
Note that the sequence A may not contain an element whose value is B_{i}.
\n2\n1 2\n3\n1 100\n2 100\n100 1000\n\n
102\n200\n2000\n
Score : 100 points
\nSnuke is buying a bicycle.\nThe bicycle of his choice does not come with a bell, so he has to buy one separately.
\nHe has very high awareness of safety, and decides to buy two bells, one for each hand.
\nThe store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively.\nFind the minimum total price of two different bells.
\nInput is given from Standard Input in the following format:
\na b c\n\n
Print the minimum total price of two different bells.
\n700 600 780\n\n
1300\n\n
The minimum among these is 1300 yen.
\n10000 10000 10000\n\n
20000\n\n
Buying any two bells costs 20000 yen.
Score : 200 points
\nWe have a bingo card with a 3\\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.
\nThe MC will choose N numbers, b_1, b_2, \\cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.
\nDetermine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.
\nInput is given from Standard Input in the following format:
\nA_{1, 1} A_{1, 2} A_{1, 3}\nA_{2, 1} A_{2, 2} A_{2, 3}\nA_{3, 1} A_{3, 2} A_{3, 3}\nN\nb_1\n\\vdots\nb_N\n\n
If we will have a bingo, print Yes
; otherwise, print No
.
84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n\n
Yes\n\n
We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.
\n41 7 46\n26 89 2\n78 92 8\n5\n6\n45\n16\n57\n17\n\n
No\n\n
We will mark nothing.
\n60 88 34\n92 41 43\n65 73 48\n10\n60\n43\n88\n11\n48\n73\n65\n41\n92\n34\n\n
Yes\n\n
We will mark all the squares.
Score : 300 points
\nGiven is a permutation P_1, \\ldots, P_N of 1, \\ldots, N.\nFind the number of integers i (1 \\leq i \\leq N) that satisfy the following condition:
\nInput is given from Standard Input in the following format:
\nN\nP_1 ... P_N\n\n
Print the number of integers i that satisfy the condition.
\n5\n4 2 5 1 3\n\n
3\n\n
i=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.
\nSimilarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.
4\n4 3 2 1\n\n
4\n\n
All integers i (1 \\leq i \\leq N) satisfy the condition.
\n6\n1 2 3 4 5 6\n\n
1\n\n
Only i=1 satisfies the condition.
\n8\n5 7 4 2 6 8 1 3\n\n
4\n\n
1\n1\n\n
1\n
Score : 300 points
\nIf there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1
.
Input is given from Standard Input in the following format:
\nN M\ns_1 c_1\n\\vdots\ns_M c_M\n\n
Print the answer.
\n3 3\n1 7\n3 2\n1 7\n\n
702\n\n
702 satisfies the conditions - its 1-st and 3-rd digits are 7
and 2
, respectively - while no non-negative integer less than 702 satisfies them.
3 2\n2 1\n2 3\n\n
-1\n\n
3 1\n1 0\n\n
-1\n
Score : 200 points
\nThere are N gems. The value of the i-th gem is V_i.
\nYou will choose some of these gems, possibly all or none, and get them.
\nHowever, you need to pay a cost of C_i to get the i-th gem.
\nLet X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.
\nFind the maximum possible value of X-Y.
\nInput is given from Standard Input in the following format:
\nN\nV_1 V_2 ... V_N\nC_1 C_2 ... C_N\n\n
Print the maximum possible value of X-Y.
\n3\n10 2 5\n6 3 4\n\n
5\n\n
If we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10.\nWe have X-Y = 5 here, which is the maximum possible value.
\n4\n13 21 6 19\n11 30 6 15\n\n
6\n\n
1\n1\n50\n\n
0\n
Score : 100 points
\nAtCoder Inc. holds a contest every Saturday.
\nThere are two types of contests called ABC and ARC, and just one of them is held at a time.
\nThe company holds these two types of contests alternately: an ARC follows an ABC and vice versa.
\nGiven a string S representing the type of the contest held last week, print the string representing the type of the contest held this week.
\nABC
or ARC
.Input is given from Standard Input in the following format:
\nS\n\n
Print the string representing the type of the contest held this week.
\nABC\n\n
ARC\n\n
They held an ABC last week, so they will hold an ARC this week.
Score : 200 points
\nYou are given a string S. Each character of S is uppercase or lowercase English letter.\nDetermine if S satisfies all of the following conditions:
\nA
.C
between the third character from the beginning and the second to last character (inclusive).A
and C
mentioned above are lowercase.Input is given from Standard Input in the following format:
\nS\n\n
If S satisfies all of the conditions in the problem statement, print AC
; otherwise, print WA
.
AtCoder\n\n
AC\n\n
The first letter is A
, the third letter is C
and the remaining letters are all lowercase, so all the conditions are satisfied.
ACoder\n\n
WA\n\n
The second letter should not be C
.
AcycliC\n\n
WA\n\n
The last letter should not be C
, either.
AtCoCo\n\n
WA\n\n
There should not be two or more occurrences of C
.
Atcoder\n\n
WA\n\n
The number of C
should not be zero, either.
Score : 300 points
\nYou are given a sequence of length N: A_1, A_2, ..., A_N.\nFor each integer i between 1 and N (inclusive), answer the following question:
\nInput is given from Standard Input in the following format:
\nN\nA_1\n:\nA_N\n\n
Print N lines. The i-th line (1 \\leq i \\leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.
\n3\n1\n4\n3\n\n
4\n3\n4\n\n
2\n5\n5\n\n
5\n5\n
Score : 100 points
\nWe have five variables x_1, x_2, x_3, x_4, and x_5.
\nThe variable x_i was initially assigned a value of i.
\nSnuke chose one of these variables and assigned it 0.
\nYou are given the values of the five variables after this assignment.
\nFind out which variable Snuke assigned 0.
\nInput is given from Standard Input in the following format:
\nx_1 x_2 x_3 x_4 x_5\n\n
If the variable Snuke assigned 0 was x_i, print the integer i.
\n0 2 3 4 5\n\n
1\n\n
In this case, Snuke assigned 0 to x_1, so we should print 1.
\n1 2 0 4 5\n\n
3\n
Score : 400 points
\nGiven is a string S consisting of L
and R
.
Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left.
\nThe character written on the leftmost square is always R
, and the character written on the rightmost square is always L
.
Initially, one child is standing on each square.
\nEach child will perform the move below 10^{100} times:
\nL
denotes left, and R
denotes right.Find the number of children standing on each square after the children performed the moves.
\nL
or R
.R
and L
, respectively.Input is given from Standard Input in the following format:
\nS\n\n
Print the number of children standing on each square after the children performed the moves, in order from left to right.
\nRRLRL\n\n
0 1 2 1 1\n\n
RRLLLLRLRRLL\n\n
0 3 3 0 0 0 1 1 0 2 2 0\n\n
RRRLLRLLRRRLLLLL\n\n
0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0\n
Score : 200 points
\nYou are given an H × W grid.
\nThe squares in the grid are described by H strings, S_1,...,S_H.
\nThe 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).
\n.
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.
\n(Below, we will simply say \"adjacent\" for this meaning. For each square, there are at most eight adjacent squares.)
\nHe 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.
\n#
and .
.Input is given from Standard Input in the following format:
\nH W\nS_1\n:\nS_H\n\n
Print the H strings after the process.
\nThe 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).
3 5\n.....\n.#.#.\n.....\n\n
11211\n1#2#1\n11211\n\n
For example, let us observe the empty square at the first row from the top and first column from the left.
\nThere is one bomb square adjacent to this empty square: the square at the second row and second column.
\nThus, the .
corresponding to this empty square is replaced with 1
.
3 5\n#####\n#####\n#####\n\n
#####\n#####\n#####\n\n
It is possible that there is no empty square.
\n6 6\n#####.\n#.#.##\n####.#\n.#..#.\n#.##..\n#.#...\n\n
#####3\n#8#7##\n####5#\n4#65#2\n#5##21\n#4#310\n
Score : 500 points
\nWe have a two-dimensional grid with H \\times W squares. There are M targets to destroy in this grid - the position of the i-th target is \\left(h_i, w_i \\right).
\nTakahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.
\nTakahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.
\nInput is given from Standard Input in the following format:
\nH W M\nh_1 w_1\n\\vdots\nh_M w_M\n\n
Print the answer.
\n2 3 3\n2 2\n1 1\n1 3\n\n
3\n\n
We can destroy all the targets by placing the bomb at \\left(1, 2\\right).
\n3 3 4\n3 3\n3 1\n1 1\n1 2\n\n
3\n\n
5 5 10\n2 5\n4 3\n2 3\n5 5\n2 2\n5 4\n5 3\n5 1\n3 5\n1 4\n\n
6\n
Score : 200 points
\nN Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town.
\nThere are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \\cdots, A_{i, {d_i}}.
\nTakahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?
\nInput is given from Standard Input in the following format:
\nN K\nd_1\nA_{1, 1} \\cdots A_{1, d_1}\n\\vdots\nd_K\nA_{K, 1} \\cdots A_{K, d_K}\n\n
Print the answer.
\n3 2\n2\n1 3\n1\n3\n\n
1\n\n
Thus, there will be one victim: Snuke 2.
\n3 3\n1\n3\n1\n3\n1\n3\n\n
2\n
Score : 400 points
\nThere are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.
\nYou can perform the following operation on this integer sequence any number of times:
\nOperation: Choose an integer i satisfying 1 \\leq i \\leq N-1. Multiply both A_i and A_{i+1} by -1.
\nLet B_1, B_2, ..., B_N be the integer sequence after your operations.
\nFind the maximum possible value of B_1 + B_2 + ... + B_N.
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 ... A_N\n\n
Print the maximum possible value of B_1 + B_2 + ... + B_N.
\n3\n-10 5 -4\n\n
19\n\n
If we perform the operation as follows:
\nwe have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4 = 19, is the maximum possible result.
\n5\n10 -4 -8 -11 3\n\n
30\n\n
11\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000\n\n
10000000000\n\n
The output may not fit into a 32-bit integer type.
Score : 200 points
\nGiven are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.
\nOperation: Choose one character of S and replace it with a different character.
\nInput is given from Standard Input in the following format:
\nS\nT\n\n
Print the answer.
\ncupofcoffee\ncupofhottea\n\n
4\n\n
We can achieve the objective in four operations, such as the following:
\nc
with h
.f
with t
.f
with t
.e
with a
.abcde\nbcdea\n\n
5\n\n
apple\napple\n\n
0\n\n
No operations may be needed to achieve the objective.
Score : 200 points
\nHaving learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.
\nGiven an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes
; if it cannot, print No
.
Input is given from Standard Input in the following format:
\nN\n\n
If N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes
; if it cannot, print No
.
10\n\n
Yes\n\n
10 can be represented as, for example, 2 \\times 5.
\n50\n\n
No\n\n
50 cannot be represented as the product of two integers between 1 and 9.
\n81\n\n
Yes\n
Score : 400 points
\nA positive integer X is said to be a lunlun number if and only if the following condition is satisfied:
\nFor example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.
\nYou are given a positive integer K. Find the K-th smallest lunlun number.
\nInput is given from Standard Input in the following format:
\nK\n\n
Print the answer.
\n15\n\n
23\n\n
We will list the 15 smallest lunlun numbers in ascending order:
\n1,\n2,\n3,\n4,\n5,\n6,\n7,\n8,\n9,\n10,\n11,\n12,\n21,\n22,\n23.
\nThus, the answer is 23.
1\n\n
1\n\n
13\n\n
21\n\n
100000\n\n
3234566667\n\n
Note that the answer may not fit into the 32-bit signed integer type.
Score : 200 points
\nA string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:
\nDetermine whether S is a strong palindrome.
\nInput is given from Standard Input in the following format:
\nS\n\n
If S is a strong palindrome, print Yes
;\notherwise, print No
.
akasaka\n\n
Yes\n\n
akasaka
.aka
.aka
.\nAll of these are palindromes, so S is a strong palindrome.level\n\n
No\n\n
atcoder\n\n
No\n
Score: 100 points
\nIn AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectively.
\nTwo antennas can communicate directly if the distance between them is k or less, and they cannot if the distance is greater than k.
\nDetermine if there exists a pair of antennas that cannot communicate directly.
\nHere, assume that the distance between two antennas at coordinates p and q (p < q) is q - p.
Input is given from Standard Input in the following format:
\na\nb\nc\nd\ne\nk\n\n
Print :(
if there exists a pair of antennas that cannot communicate directly, and print Yay!
if there is no such pair.
1\n2\n4\n8\n9\n15\n\n
Yay!\n\n
In this case, there is no pair of antennas that cannot communicate directly, because:
\nand none of them is greater than 15. Thus, the correct output is Yay!
.
15\n18\n26\n35\n36\n18\n\n
:(\n\n
In this case, the distance between antennas A and D is 35 - 15 = 20 and exceeds 18, so they cannot communicate directly.\nThus, the correct output is :(
.
Score : 100 points
\nWe have two integers: A and B.
\nPrint the largest number among A + B, A - B, and A \\times B.
\nInput is given from Standard Input in the following format:
\nA B\n\n
Print the largest number among A + B, A - B, and A \\times B.
\n-13 3\n\n
-10\n\n
The largest number among A + B = -10, A - B = -16, and A \\times B = -39 is -10.
\n1 -33\n\n
34\n\n
The largest number among A + B = -32, A - B = 34, and A \\times B = -33 is 34.
\n13 3\n\n
39\n\n
The largest number among A + B = 16, A - B = 10, and A \\times B = 39 is 39.
Score : 400 points
\nGiven is an integer S.\nFind how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S.\nThe answer can be very large, so output it modulo 10^9 + 7.
\nInput is given from Standard Input in the following format:
\nS\n\n
Print the answer.
\n7\n\n
3\n\n
3 sequences satisfy the condition: \\{3,4\\}, \\{4,3\\} and \\{7\\}.
\n2\n\n
0\n\n
There are no sequences that satisfy the condition.
\n1729\n\n
294867501\n
Score : 200 points
\nAlice, Bob and Charlie are playing Card Game for Three, as below:
\na
, b
or c
written on it. The orders of the cards in the decks cannot be rearranged.a
, Alice takes the next turn.)You are given the initial decks of the players.\nMore specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way.
\nDetermine the winner of the game.
\na
, b
or c
.The input is given from Standard Input in the following format:
\nS_A\nS_B\nS_C\n\n
If Alice will win, print A
. If Bob will win, print B
. If Charlie will win, print C
.
aca\naccc\nca\n\n
A\n\n
The game will progress as below:
\na
. Alice takes the next turn.c
. Charlie takes the next turn.c
. Charlie takes the next turn.a
. Alice takes the next turn.a
. Alice takes the next turn.abcb\naacb\nbccc\n\n
C\n
Score : 200 points
\nLa Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each.\nDetermine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes.
\nInput is given from Standard Input in the following format:
\nN\n\n
If there is a way to buy some cakes and some doughnuts for exactly N dollars, print Yes
; otherwise, print No
.
11\n\n
Yes\n\n
If you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.
\n40\n\n
Yes\n\n
If you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.
\n3\n\n
No\n\n
The prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than 3 dollars, so there is no such way.
Score : 100 points
\nTakahashi is a member of a programming competition site, ButCoder.
\nEach member of ButCoder is assigned two values: Inner Rating and Displayed Rating.
\nThe Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests. Otherwise, the Displayed Rating will be their Inner Rating minus 100 \\times (10 - K) when the member has participated in K contests.
\nTakahashi has participated in N contests, and his Displayed Rating is R. Find his Inner Rating.
\nInput is given from Standard Input in the following format:
\nN R\n\n
Print his Inner Rating.
\n2 2919\n\n
3719\n\n
Takahashi has participated in 2 contests, which is less than 10, so his Displayed Rating is his Inner Rating minus 100 \\times (10 - 2) = 800.
\nThus, Takahashi's Inner Rating is 2919 + 800 = 3719.
\n22 3051\n\n
3051\n
Score : 100 points
\nGiven is a string S representing the day of the week today.
\nS is SUN
, MON
, TUE
, WED
, THU
, FRI
, or SAT
, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.
After how many days is the next Sunday (tomorrow or later)?
\nSUN
, MON
, TUE
, WED
, THU
, FRI
, or SAT
.Input is given from Standard Input in the following format:
\nS\n\n
Print the number of days before the next Sunday.
\nSAT\n\n
1\n\n
It is Saturday today, and tomorrow will be Sunday.
\nSUN\n\n
7\n\n
It is Sunday today, and seven days later, it will be Sunday again.
Score : 100 points
\nSnuke is giving cookies to his three goats.
\nHe has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins).
\nYour task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
\nInput is given from Standard Input in the following format:
\nA B\n\n
If it is possible to give cookies so that each of the three goats can have the same number of cookies, print Possible
; otherwise, print Impossible
.
4 5\n\n
Possible\n\n
If Snuke gives nine cookies, each of the three goats can have three cookies.
\n1 1\n\n
Impossible\n\n
Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.
Score : 100 points
\nAs a New Year's gift, Dolphin received a string s of length 19.
\nThe string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]
.
\nDolphin wants to convert the comma-separated string s into a space-separated string.
\nWrite a program to perform the conversion for him.
,
.The input is given from Standard Input in the following format:
\ns\n\n
Print the string after the conversion.
\nhappy,newyear,enjoy\n\n
happy newyear enjoy\n\n
Replace all the commas in happy,newyear,enjoy
with spaces to obtain happy newyear enjoy
.
haiku,atcoder,tasks\n\n
haiku atcoder tasks\n\n
abcde,fghihgf,edcba\n\n
abcde fghihgf edcba\n
Score : 100 points
\nTwo students of AtCoder Kindergarten are fighting over candy packs.
\nThere are three candy packs, each of which contains a, b, and c candies, respectively.
\nTeacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
\nNote that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
\nThe input is given from Standard Input in the following format:
\na b c\n\n
If it is possible to distribute the packs so that each student gets the same number of candies, print Yes
. Otherwise, print No
.
10 30 20\n\n
Yes\n\n
Give the pack with 30 candies to one student, and give the two packs with 10 and 20 candies to the other. Then, each gets 30 candies.
\n30 30 100\n\n
No\n\n
In this case, the student who gets the pack with 100 candies always has more candies than the other.
\nNote that every pack must be given to one of them.
\n56 25 31\n\n
Yes\n
Score : 200 points
\nIroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L.
\nShe will concatenate all of the strings in some order, to produce a long string.
\nAmong all strings that she can produce in this way, find the lexicographically smallest one.
\nHere, a string s=s_1s_2s_3...s_n is lexicographically smaller than another string t=t_1t_2t_3...t_m if and only if one of the following holds:\n
The input is given from Standard Input in the following format:
\nN L\nS_1\nS_2\n:\nS_N\n\n
Print the lexicographically smallest string that Iroha can produce.
\n3 3\ndxx\naxx\ncxx\n\n
axxcxxdxx\n\n
The following order should be used: axx
, cxx
, dxx
.
Score : 500 points
\nWe have N logs of lengths A_1,A_2,\\cdots A_N.
\nWe can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.
\nFind the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.
\nInput is given from Standard Input in the following format:
\nN K\nA_1 A_2 \\cdots A_N\n\n
Print an integer representing the answer.
\n2 3\n7 9\n\n
4\n\n
In this case, the longest length of a log will be 3.5, which is the shortest possible result. After rounding up to an integer, the output should be 4.
\n3 0\n3 4 5\n\n
5\n\n
10 10\n158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202\n\n
292638192\n
Score : 300 points
\nGiven are an integer X and an integer sequence of length N: p_1, \\ldots, p_N.
\nAmong the integers not contained in the sequence p_1, \\ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.
\nInput is given from Standard Input in the following format:
\nX N\np_1 ... p_N\n\n
Print the answer.
\n6 5\n4 7 10 6 5\n\n
8\n\n
Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.
\n10 5\n4 7 10 6 5\n\n
9\n\n
Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.
\n100 0\n\n\n
100\n\n
When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.
Score : 100 points
\nYou are given three strings A, B and C. Check whether they form a word chain.
\nMore formally, determine whether both of the following are true:
\nIf both are true, print YES
. Otherwise, print NO
.
a
- z
).Input is given from Standard Input in the following format:
\nA B C\n\n
Print YES
or NO
.
rng gorilla apple\n\n
YES\n\n
They form a word chain.
\nyakiniku unagi sushi\n\n
NO\n\n
A and B form a word chain, but B and C do not.
\na a a\n\n
YES\n\n
aaaaaaaaab aaaaaaaaaa aaaaaaaaab\n\n
NO\n
Score : 300 points
\nWe have N ID cards, and there are M gates.
\nWe can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards.
\nHow many of the ID cards allow us to pass all the gates alone?
\nInput is given from Standard Input in the following format:
\nN M\nL_1 R_1\nL_2 R_2\n\\vdots\nL_M R_M\n\n
Print the number of ID cards that allow us to pass all the gates alone.
\n4 2\n1 3\n2 4\n\n
2\n\n
Two ID cards allow us to pass all the gates alone, as follows:
\n10 3\n3 6\n5 7\n6 9\n\n
1\n\n
100000 1\n1 100000\n\n
100000\n
Score : 100 points
\nGiven are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.
\nInput is given from Standard Input in the following format:
\nS T\n\n
Print the resulting string.
\noder atc\n\n
atcoder\n\n
When S = oder
and T = atc
, concatenating T and S in this order results in atcoder
.
humu humu\n\n
humuhumu\n
Score: 200 points
\nWe have N cards. A number a_i is written on the i-th card.
\nAlice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
\nThe 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.
Input is given from Standard Input in the following format:
\nN\na_1 a_2 a_3 ... a_N\n\n
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
\n2\n3 1\n\n
2\n\n
First, Alice will take the card with 3. Then, Bob will take the card with 1.\nThe difference of their scores will be 3 - 1 = 2.
\n3\n2 7 4\n\n
5\n\n
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.
\n4\n20 18 2 18\n\n
18\n
Score : 200 points
\nTakahashi wants to gain muscle, and decides to work out at AtCoder Gym.
\nThe exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.\nThese buttons are numbered 1 through N.\nWhen Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i.\nWhen Button i is not lighten up, nothing will happen by pressing it.
\nInitially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
\nDetermine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
\nInput is given from Standard Input in the following format:
\nN\na_1\na_2\n:\na_N\n\n
Print -1 if it is impossible to lighten up Button 2.\nOtherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
\n3\n3\n1\n2\n\n
2\n\n
Press Button 1, then Button 3.
\n4\n3\n4\n1\n2\n\n
-1\n\n
Pressing Button 1 lightens up Button 3, and vice versa, so Button 2 will never be lighten up.
\n5\n3\n3\n4\n2\n4\n\n
3\n
Score : 200 points
\nWe have a grid with N rows and M columns of squares. Initially, all the squares are white.
\nThere is a button attached to each row and each column.\nWhen a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa.\nWhen a button attached to a column is pressed, the colors of all the squares in that column are inverted.
\nTakahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
\nInput is given from Standard Input in the following format:
\nN M K\n\n
If Takahashi can have exactly K black squares in the grid, print Yes
; otherwise, print No
.
2 2 2\n\n
Yes\n\n
Press the buttons in the order of the first row, the first column.
\n2 2 1\n\n
No\n\n
3 5 8\n\n
Yes\n\n
Press the buttons in the order of the first column, third column, second row, fifth column.
\n7 9 20\n\n
No\n
Score : 200 points
\nAn 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.
\nLunlun 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?
\nInput is given from Standard Input in the following format:
\nN\nd_1\n:\nd_N\n\n
Print the maximum number of layers in a kagami mochi that can be made.
\n4\n10\n8\n8\n6\n\n
3\n\n
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.
\n3\n15\n15\n15\n\n
1\n\n
When all the mochi have the same diameter, we can only have a 1-layered kagami mochi.
\n7\n50\n30\n50\n100\n50\n80\n30\n\n
4\n
Score: 200 points
\nM-kun has the following three cards:
\nHe is a genius magician who can do the following operation at most K times:
\nHis magic is successful if both of the following conditions are satisfied after the operations:
\nDetermine whether the magic can be successful.
\nInput is given from Standard Input in the following format:
\nA B C\nK\n\n
If the magic can be successful, print Yes
; otherwise, print No
.
7 2 5\n3\n\n
Yes\n\n
The magic will be successful if, for example, he does the following operations:
\n7 4 2\n3\n\n
No\n\n
He has no way to succeed in the magic with at most three operations.
Score : 200 points
\nThere are N points in a D-dimensional space.
\nThe coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}).
\nThe distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \\sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}.
\nHow many pairs (i, j) (i < j) are there such that the distance between the i-th point and the j-th point is an integer?
\nInput is given from Standard Input in the following format:
\nN D\nX_{11} X_{12} ... X_{1D}\nX_{21} X_{22} ... X_{2D}\n\\vdots\nX_{N1} X_{N2} ... X_{ND}\n\n
Print the number of pairs (i, j) (i < j) such that the distance between the i-th point and the j-th point is an integer.
\n3 2\n1 2\n5 5\n-2 8\n\n
1\n\n
The number of pairs with an integer distance is one, as follows:
\n3 4\n-3 7 8 2\n-12 1 10 2\n-2 8 9 3\n\n
2\n\n
5 1\n1\n2\n3\n4\n5\n\n
10\n
Score : 100 points
\nWe have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand.
\nHow many grams of sand will the upper bulb contains after t seconds?
\nThe input is given from Standard Input in the following format:
\nX t\n\n
Print the number of sand in the upper bulb after t second.
\n100 17\n\n
83\n\n
17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams.
\n48 58\n\n
0\n\n
All 48 grams of sand will be gone, resulting in 0 grams.
\n1000000000 1000000000\n\n
0\n
Score : 100 points
\nWe conducted a survey on newspaper subscriptions.\nMore specifically, we asked each of the N respondents the following two questions:
\nAs the result, A respondents answered \"yes\" to Question 1, and B respondents answered \"yes\" to Question 2.
\nWhat are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?
\nWrite a program to answer this question.
\nInput is given from Standard Input in the following format:
\nN A B\n\n
Print the maximum possible number and the minimum possible number of respondents subscribing to both newspapers, in this order, with a space in between.
\n10 3 5\n\n
3 0\n\n
In this sample, out of the 10 respondents, 3 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.
\nHere, the number of respondents subscribing to both newspapers is at most 3 and at least 0.
\n10 7 5\n\n
5 2\n\n
In this sample, out of the 10 respondents, 7 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.
\nHere, the number of respondents subscribing to both newspapers is at most 5 and at least 2.
\n100 100 100\n\n
100 100\n
Score : 300 points
\nThere are N people. The name of the i-th person is S_i.
\nWe would like to choose three people so that the following conditions are met:
\nM
, A
, R
, C
or H
.How many such ways are there to choose three people, disregarding order?
\nNote that the answer may not fit into a 32-bit integer type.
\nInput is given from Standard Input in the following format:
\nN\nS_1\n:\nS_N\n\n
If there are x ways to choose three people so that the given conditions are met, print x.
\n5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI\n\n
2\n\n
We can choose three people with the following names:
\nMASHIKE
, RUMOI
, HABORO
MASHIKE
, RUMOI
, HOROKANAI
Thus, we have two ways.
\n4\nZZ\nZZZ\nZ\nZZZZZZZZZZ\n\n
0\n\n
Note that there may be no ways to choose three people so that the given conditions are met.
\n5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO\n\n
7\n
Score : 200 points
\nWe have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.
\nWe will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?
\nInput is given from Standard Input in the following format:
\nA B C K\n\n
Print the maximum possible sum of the numbers written on the cards chosen.
\n2 1 1 3\n\n
2\n\n
Consider picking up two cards with 1s and one card with a 0.\nIn this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.
\n1 2 3 4\n\n
0\n\n
2000000000 0 0 2000000000\n\n
2000000000\n
Score: 300 points
\nWe have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.
\nPrint all strings that are written on the most number of votes, in lexicographical order.
\nInput is given from Standard Input in the following format:
\nN\nS_1\n:\nS_N\n\n
Print all strings in question in lexicographical order.
\n7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n\n
beet\nvet\n\n
beet
and vet
are written on two sheets each, while beat
, bed
, and bet
are written on one vote each. Thus, we should print the strings beet
and vet
.
8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n\n
buffalo\n\n
7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n\n
kick\n\n
4\nushi\ntapu\nnichia\nkun\n\n
kun\nnichia\ntapu\nushi\n
Score : 400 points
\nA maze is composed of a grid of H \\times W squares - H vertical, W horizontal.
\nThe square at the i-th row from the top and the j-th column from the left - (i,j) - is a wall if S_{ij} is #
and a road if S_{ij} is .
.
There is a magician in (C_h,C_w). He can do the following two kinds of moves:
\nIn either case, he cannot go out of the maze.
\nAt least how many times does he need to use the magic to reach (D_h, D_w)?
\n#
or .
..
.Input is given from Standard Input in the following format:
\nH W\nC_h C_w\nD_h D_w\nS_{11}\\ldots S_{1W}\n\\vdots\nS_{H1}\\ldots S_{HW}\n\n
Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print -1
instead.
4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#..\n\n
1\n\n
For example, by walking to (2,2) and then using the magic to travel to (4,4), just one use of magic is enough.
\nNote that he cannot walk diagonally.
\n4 4\n1 4\n4 1\n.##.\n####\n####\n.##.\n\n
-1\n\n
He cannot move from there.
\n4 4\n2 2\n3 3\n....\n....\n....\n....\n\n
0\n\n
No use of magic is needed.
\n4 5\n1 2\n2 5\n#.###\n####.\n#..##\n#..##\n\n
2\n
Score : 100 points
\nThere is always an integer in Takahashi's mind.
\nInitially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is +
or -
. When he eats +
, the integer in his mind increases by 1; when he eats -
, the integer in his mind decreases by 1.
The symbols Takahashi is going to eat are given to you as a string S. The i-th character in S is the i-th symbol for him to eat.
\nFind the integer in Takahashi's mind after he eats all the symbols.
\n+
or -
.Input is given from Standard Input in the following format:
\nS\n\n
Print the integer in Takahashi's mind after he eats all the symbols.
\n+-++\n\n
2\n\n
+
. After eating it, the integer in his mind becomes 1.-
. After eating it, the integer in his mind becomes 0.+
. After eating it, the integer in his mind becomes 1.+
. After eating it, the integer in his mind becomes 2.Thus, the integer in Takahashi's mind after he eats all the symbols is 2.
\n-+--\n\n
-2\n\n
----\n\n
-4\n
Score : 200 points
\nYou are given strings s and t, consisting of lowercase English letters.\nYou will create a string s' by freely rearranging the characters in s.\nYou will also create a string t' by freely rearranging the characters in t.\nDetermine whether it is possible to satisfy s' < t' for the lexicographic order.
\nFor a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:
\nFor example, xy
< xya
and atcoder
< atlas
.
Input is given from Standard Input in the following format:
\ns\nt\n\n
If it is possible to satisfy s' < t', print Yes
; if it is not, print No
.
yx\naxy\n\n
Yes\n\n
We can, for example, rearrange yx
into xy
and axy
into yxa
. Then, xy
< yxa
.
ratcode\natlas\n\n
Yes\n\n
We can, for example, rearrange ratcode
into acdeort
and atlas
into tslaa
. Then, acdeort
< tslaa
.
cd\nabc\n\n
No\n\n
No matter how we rearrange cd
and abc
, we cannot achieve our objective.
w\nww\n\n
Yes\n\n
zzz\nzzz\n\n
No\n
Score : 400 points
\nSnuke has N strings. The i-th string is s_i.
\nLet us concatenate these strings into one string after arranging them in some order.\nFind the maximum possible number of occurrences of AB
in the resulting string.
Input is given from Standard Input in the following format:
\nN\ns_1\n\\vdots\ns_N\n\n
Print the answer.
\n3\nABCA\nXBAZ\nBAD\n\n
2\n\n
For example, if we concatenate ABCA
, BAD
and XBAZ
in this order, the resulting string ABCABADXBAZ
has two occurrences of AB
.
9\nBEWPVCRWH\nZZNQYIJX\nBAVREA\nPA\nHJMYITEOX\nBCJHMRMNK\nBP\nQVFABZ\nPRGKSPUNA\n\n
4\n\n
7\nRABYBBE\nJOZ\nBMHQUVA\nBPA\nISU\nMCMABAOBHZ\nSZMEHMA\n\n
4\n
Score : 200 points
\nA sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:
\nThe first term s is given as input.
\nLet f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.
\na_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.
\nFind the minimum integer m that satisfies the following condition:
\nInput is given from Standard Input in the following format:
\ns\n\n
Print the minimum integer m that satisfies the condition.
\n8\n\n
5\n\n
a=\\{8,4,2,1,4,2,1,4,2,1,......\\}. As a_5=a_2, the answer is 5.
\n7\n\n
18\n\n
a=\\{7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,......\\}.
\n54\n\n
114\n
Score: 100 points
\nWe have two distinct integers A and B.
\nPrint the integer K such that |A - K| = |B - K|.
\nIf such an integer does not exist, print IMPOSSIBLE
instead.
Input is given from Standard Input in the following format:
\nA B\n\n
Print the integer K satisfying the condition.
\nIf such an integer does not exist, print IMPOSSIBLE
instead.
2 16\n\n
9\n\n
|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.
\n0 3\n\n
IMPOSSIBLE\n\n
No integer satisfies the condition.
\n998244353 99824435\n\n
549034394\n
Score : 500 points
\nWe have N integers. The i-th number is A_i.
\n\\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\\leq i < j \\leq N.
\n\\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\\ldots,A_N)=1.
\nDetermine if \\{A_i\\} is pairwise coprime, setwise coprime, or neither.
\nHere, GCD(\\ldots) denotes greatest common divisor.
\nInput is given from Standard Input in the following format:
\nN\nA_1 \\ldots A_N\n\n
If \\{A_i\\} is pairwise coprime, print pairwise coprime
; if \\{A_i\\} is setwise coprime, print setwise coprime
; if neither, print not coprime
.
3\n3 4 5\n\n
pairwise coprime\n\n
GCD(3,4)=GCD(3,5)=GCD(4,5)=1, so they are pairwise coprime.
\n3\n6 10 15\n\n
setwise coprime\n\n
Since GCD(6,10)=2, they are not pairwise coprime. However, since GCD(6,10,15)=1, they are setwise coprime.
\n3\n6 10 16\n\n
not coprime\n\n
GCD(6,10,16)=2, so they are neither pairwise coprime nor setwise coprime.
Score : 100 points
\nAn uppercase or lowercase English letter \\alpha will be given as input.\nIf \\alpha is uppercase, print A
; if it is lowercase, print a
.
A
- Z
) or lowercase (a
- z
) English letter.Input is given from Standard Input in the following format:
\nα\n\n
If \\alpha is uppercase, print A
; if it is lowercase, print a
.
B\n\n
A\n\n
B
is uppercase, so we should print A
.
a\n\n
a\n\n
a
is lowercase, so we should print a
.
Score : 200 points
\nGiven are a positive integer N and a string S of length N consisting of lowercase English letters.
\nDetermine whether the string is a concatenation of two copies of some string.\nThat is, determine whether there is a string T such that S = T + T.
\nInput is given from Standard Input in the following format:
\nN\nS\n\n
If S is a concatenation of two copies of some string, print Yes
; otherwise, print No
.
6\nabcabc\n\n
Yes\n\n
Let T = abc
, and S = T + T.
6\nabcadc\n\n
No\n\n
1\nz\n\n
No\n
Score : 100 points
\nThere is a hotel with the following accommodation fee:
\nTak is staying at this hotel for N consecutive nights.\nFind his total accommodation fee.
\nThe input is given from Standard Input in the following format:
\nN\nK\nX\nY\n\n
Print Tak's total accommodation fee.
\n5\n3\n10000\n9000\n\n
48000\n\n
The accommodation fee is as follows:
\nThus, the total is 48000 yen.
\n2\n3\n10000\n9000\n\n
20000\n
Score: 200 points
\nThere are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
\nWhat is the largest possible sum of the integers written on the blackboard after K operations?
\nInput is given from Standard Input in the following format:
\nA B C\nK\n\n
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.
\n5 3 11\n1\n\n
30\n\n
In this sample, 5, 3, 11 are initially written on the blackboard, and E869120 can perform the operation once.
\nThere are three choices:
If 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.
\n3 3 4\n2\n\n
22\n\n
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.
Score: 200 points
\nThe number 105 is quite special - it is odd but still it has eight divisors.\nNow, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?
\nInput is given from Standard Input in the following format:
\nN\n\n
Print the count.
\n105\n\n
1\n\n
Among the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.
\n7\n\n
0\n\n
1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.
Score : 200 points
\nYou are given two integers K and S.
\nThree variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
\nHow many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
The input is given from Standard Input in the following format:
\nK S\n\n
Print the number of the triples of X, Y and Z that satisfy the condition.
\n2 2\n\n
6\n\n
There are six triples of X, Y and Z that satisfy the condition:
\n5 15\n\n
1\n\n
The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z.
Score : 300 points
\nWe have N switches with \"on\" and \"off\" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.
\nBulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are \"on\" among these switches is congruent to p_i modulo 2.
\nHow many combinations of \"on\" and \"off\" states of the switches light all the bulbs?
\nInput is given from Standard Input in the following format:
\nN M\nk_1 s_{11} s_{12} ... s_{1k_1}\n:\nk_M s_{M1} s_{M2} ... s_{Mk_M}\np_1 p_2 ... p_M\n\n
Print the number of combinations of \"on\" and \"off\" states of the switches that light all the bulbs.
\n2 2\n2 1 2\n1 2\n0 1\n\n
1\n\n
There are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1.
\n2 3\n2 1 2\n1 1\n1 2\n0 0 1\n\n
0\n\n
Switch 1 has to be \"off\" to light Bulb 2 and Switch 2 has to be \"on\" to light Bulb 3, but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0.
\n5 2\n3 1 2 5\n2 2 3\n1 0\n\n
8\n
Score : 100 points
\nIn programming, hexadecimal notation is often used.
\nIn 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?
\nA
, B
, C
, D
, E
or F
.Input is given from Standard Input in the following format:
\nX Y\n\n
If X is smaller, print <
; if Y is smaller, print >
; if they are equal, print =
.
A B\n\n
<\n\n
10 < 11.
\nE C\n\n
>\n\n
14 > 12.
\nF F\n\n
=\n\n
15 = 15.
Score : 100 points
\nSnuke has a grid consisting of three squares numbered 1, 2 and 3.\nIn 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
.\nFind the number of squares on which Snuke will place a marble.
1
or 0
.Input is given from Standard Input in the following format:
\ns_{1}s_{2}s_{3}\n\n
Print the answer.
\n101\n\n
2\n\n
000\n\n
0\n\n
Score : 200 points
\nAtCoDeer the deer has found two positive integers, a and b.\nDetermine whether the concatenation of a and b in this order is a square number.
\nInput is given from Standard Input in the following format:
\na b\n\n
If the concatenation of a and b in this order is a square number, print Yes
; otherwise, print No
.
1 21\n\n
Yes\n\n
As 121 = 11 × 11, it is a square number.
\n100 100\n\n
No\n\n
100100 is not a square number.
\n12 10\n\n
No\n
Score : 100 points
\nIt is September 9 in Japan now.
\nYou are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
\nInput is given from Standard Input in the following format:
\nN\n\n
If 9 is contained in the decimal notation of N, print Yes
; if not, print No
.
29\n\n
Yes\n\n
The one's digit of 29 is 9.
\n72\n\n
No\n\n
72 does not contain 9.
\n91\n\n
Yes\n
Score : 200 points
\nPrint all the integers that satisfies the following in ascending order:
\nInput is given from Standard Input in the following format:
\nA B K\n\n
Print all the integers that satisfies the condition above in ascending order.
\n3 8 2\n\n
3\n4\n7\n8\n\n
4 8 3\n\n
4\n5\n6\n7\n8\n\n
2 9 100\n\n
2\n3\n4\n5\n6\n7\n8\n9\n
Score : 100 points
\nThe door of Snuke's laboratory is locked with a security code.
\nThe security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.
\nYou are given the current security code S. If S is hard to enter, print Bad
; otherwise, print Good
.
Input is given from Standard Input in the following format:
\nS\n\n
If S is hard to enter, print Bad
; otherwise, print Good
.
3776\n\n
Bad\n\n
The second and third digits are the same, so 3776 is hard to enter.
\n8080\n\n
Good\n\n
There are no two consecutive digits that are the same, so 8080 is not hard to enter.
\n1333\n\n
Bad\n\n
0024\n\n
Bad\n
Score : 400 points
\nAn altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \\leq i \\leq N) is given to you as a character c_i; R
stands for red and W
stands for white.
You can do the following two kinds of operations any number of times in any order:
\nAccording to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?
\nR
or W
.Input is given from Standard Input in the following format:
\nN\nc_{1}c_{2}...c_{N}\n\n
Print an integer representing the minimum number of operations needed.
\n4\nWWRR\n\n
2\n\n
For example, the two operations below will achieve the objective.
\nRWWR
.RWWW
.2\nRR\n\n
0\n\n
It can be the case that no operation is needed.
\n8\nWRWWRWRR\n\n
3\n
Score: 400 points
\nThe Kingdom of Takahashi has N towns, numbered 1 through N.
\nThere is one teleporter in each town. The teleporter in Town i (1 \\leq i \\leq N) sends you to Town A_i.
\nTakahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.
\nHelp the king by writing a program that answers this question.
\nInput is given from Standard Input in the following format:
\nN K\nA_1 A_2 \\dots A_N\n\n
Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.
\n4 5\n3 2 4 1\n\n
4\n\n
If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.
\n6 727202214173249351\n6 5 2 5 3 2\n\n
2\n
Score : 300 points
\nSnuke has N dogs and M monkeys. He wants them to line up in a row.
\nAs a Japanese saying goes, these dogs and monkeys are on bad terms. (\"ken'en no naka\", literally \"the relationship of dogs and monkeys\", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
\nHow many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).\nHere, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
\nInput is given from Standard Input in the following format:
\nN M\n\n
Print the number of possible arrangements, modulo 10^9+7.
\n2 2\n\n
8\n\n
We will denote the dogs by A
and B
, and the monkeys by C
and D
. There are eight possible arrangements: ACBD
, ADBC
, BCAD
, BDAC
, CADB
, CBDA
, DACB
and DBCA
.
3 2\n\n
12\n\n
1 8\n\n
0\n\n
100000 100000\n\n
530123477\n
Score: 100 points
\nThe weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...
\nGiven is a string S representing the weather in the town today. Predict the weather tomorrow.
\nSunny
, Cloudy
, or Rainy
.Input is given from Standard Input in the following format:
\nS\n\n
Print a string representing the expected weather tomorrow, in the same format in which input is given.
\nSunny\n\n
Cloudy\n\n
In Takahashi's town, a sunny day is followed by a cloudy day.
\nRainy\n\n
Sunny\n
Score: 100 points
\nA triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.
\nYou will be given three integers A, B, and C. If this triple is poor, print Yes
; otherwise, print No
.
Input is given from Standard Input in the following format:
\nA B C\n\n
If the given triple is poor, print Yes
; otherwise, print No
.
5 7 5\n\n
Yes\n\n
A and C are equal, but B is different from those two numbers, so this triple is poor.
\n4 4 4\n\n
No\n\n
A, B, and C are all equal, so this triple is not poor.
\n4 9 6\n\n
No\n\n
3 3 4\n\n
Yes\n
Score: 300 points
\nAtCoder Mart sells 1000000 of each of the six items below:
\nTakahashi wants to buy some of them that cost exactly X yen in total.\nDetermine whether this is possible.
\n(Ignore consumption tax.)
Input is given from Standard Input in the following format:
\nX\n\n
If it is possible to buy some set of items that cost exactly X yen in total, print 1
; otherwise, print 0
.
615\n\n
1\n\n
For example, we can buy one of each kind of item, which will cost 100+101+102+103+104+105=615 yen in total.
\n217\n\n
0\n\n
No set of items costs 217 yen in total.
Score : 100 points
\nFind the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.
\nInput is given from Standard Input in the following format:
\nK\n\n
Print the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).
\n3\n\n
2\n\n
Two pairs can be chosen: (2,1) and (2,3).
\n6\n\n
9\n\n
11\n\n
30\n\n
50\n\n
625\n
Score: 100 points
\nE869120 has A 1-yen coins and infinitely many 500-yen coins.
\nDetermine if he can pay exactly N yen using only these coins.
Input is given from Standard Input in the following format:
\nN\nA\n\n
If E869120 can pay exactly N yen using only his 1-yen and 500-yen coins, print Yes
; otherwise, print No
.
2018\n218\n\n
Yes\n\n
We can pay 2018 yen with four 500-yen coins and 18 1-yen coins, so the answer is Yes
.
2763\n0\n\n
No\n\n
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.
\n37\n514\n\n
Yes\n
Score : 400 points
\nThere are N empty boxes arranged in a row from left to right.\nThe integer i is written on the i-th box from the left (1 \\leq i \\leq N).
\nFor each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.
\nWe say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:
\nDoes there exist a good set of choices? If the answer is yes, find one good set of choices.
\nInput is given from Standard Input in the following format:
\nN\na_1 a_2 ... a_N\n\n
If a good set of choices does not exist, print -1
.
If a good set of choices exists, print one such set of choices in the following format:
\nM\nb_1 b_2 ... b_M\n\n
where M denotes the number of boxes that will contain a ball, and b_1,\\ b_2,\\ ...,\\ b_M are the integers written on these boxes, in any order.
\n3\n1 0 0\n\n
1\n1\n\n
Consider putting a ball only in the box with 1 written on it.
\nThus, the condition is satisfied, so this set of choices is good.
\n5\n0 0 0 0 0\n\n
0\n\n
Putting nothing in the boxes can be a good set of choices.
Score : 100 points
\nThree poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.\nWe will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.
\nDetermine whether the arrangement of the poles is beautiful.
\nInput is given from Standard Input in the following format:
\na b c\n\n
Print YES
if the arrangement of the poles is beautiful; print NO
otherwise.
2 4 6\n\n
YES\n\n
Since 4-2 = 6-4, this arrangement of poles is beautiful.
\n2 5 6\n\n
NO\n\n
Since 5-2 \\neq 6-5, this arrangement of poles is not beautiful.
\n3 2 1\n\n
YES\n\n
Since 1-2 = 2-3, this arrangement of poles is beautiful.
Score : 100 points
\nYou are given three integers A, B and C.
\nDetermine if there exists an equilateral triangle whose sides have lengths A, B and C.
\nInput is given from Standard Input in the following format:
\nA B C\n\n
If there exists an equilateral triangle whose sides have lengths A, B and C, print Yes
; otherwise, print No
.
2 2 2\n\n
Yes\n\n
3 4 5\n\n
No\n\n
Score : 300 points
\nTakahashi participated in a contest on AtCoder.
\nThe contest had N problems.
\nTakahashi made M submissions during the contest.
\nThe i-th submission was made for the p_i-th problem and received the verdict S_i (AC
or WA
).
The number of Takahashi's correct answers is the number of problems on which he received an AC
once or more.
The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC
once or more: the number of WA
s received before receiving an AC
for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties.
\nAC
or WA
.Input is given from Standard Input in the following format:
\nN M\np_1 S_1\n:\np_M S_M\n\n
Print the number of Takahashi's correct answers and the number of Takahashi's penalties.
\n2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n\n
2 2\n\n
In his second submission, he received an AC
on the first problem for the first time. Before this, he received one WA
on this problem.
In his fourth submission, he received an AC
on the second problem for the first time. Before this, he received one WA
on this problem.
Thus, he has two correct answers and two penalties.
\n100000 3\n7777 AC\n7777 AC\n7777 AC\n\n
1 0\n\n
Note that it is pointless to get an AC
more than once on the same problem.
6 0\n\n
0 0\n
Score : 100 points
\nYou are given positive integers A and B.
\nIf A is a divisor of B, print A + B; otherwise, print B - A.
\nInput is given from Standard Input in the following format:
\nA B\n\n
If A is a divisor of B, print A + B; otherwise, print B - A.
\n4 12\n\n
16\n\n
As 4 is a divisor of 12, 4 + 12 = 16 should be printed.
\n8 20\n\n
12\n\n
1 1\n\n
2\n\n
1 is a divisor of 1.
Score : 400 points
\nThere are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.
\nBetween these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \\leq i \\leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1).
\nWhen Mountain i (1 \\leq i \\leq N) receives 2x liters of rain, Dam i-1 and Dam i each accumulates x liters of water (Dam 0 is Dam N).
\nOne day, each of the mountains received a non-negative even number of liters of rain.
\nAs a result, Dam i (1 \\leq i \\leq N) accumulated a total of A_i liters of water.
\nFind the amount of rain each of the mountains received. We can prove that the solution is unique under the constraints of this problem.
\nInput is given from Standard Input in the following format:
\nN\nA_1 A_2 ... A_N\n\n
Print N integers representing the number of liters of rain Mountain 1, Mountain 2, ..., Mountain N received, in this order.
\n3\n2 2 4\n\n
4 0 4\n\n
If we assume Mountain 1, 2, and 3 received 4, 0, and 4 liters of rain, respectively, it is consistent with this input, as follows:
\n5\n3 8 7 5 5\n\n
2 4 12 2 8\n\n
3\n1000000000 1000000000 0\n\n
0 2000000000 0\n
Score : 200 points
\nYou are given a string S of length N.\nAmong its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings.
\nHere, a subsequence of a string is a concatenation of one or more characters from the string without changing the order.
\nInput is given from Standard Input in the following format:
\nN\nS\n\n
Print the number of the subsequences such that all characters are different, modulo 10^9+7.
\n4\nabcd\n\n
15\n\n
Since all characters in S itself are different, all its subsequences satisfy the condition.
\n3\nbaa\n\n
5\n\n
The answer is five: b
, two occurrences of a
, two occurrences of ba
. Note that we do not count baa
, since it contains two a
s.
5\nabcab\n\n
17\n
Score : 100 points
\nThree people, A, B and C, are trying to communicate using transceivers.\nThey are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively.\nTwo people can directly communicate when the distance between them is at most d meters.\nDetermine if A and C can communicate, either directly or indirectly.\nHere, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
\nInput is given from Standard Input in the following format:
\na b c d\n\n
If A and C can communicate, print Yes
; if they cannot, print No
.
4 7 9 3\n\n
Yes\n\n
A and B can directly communicate, and also B and C can directly communicate, so we should print Yes
.
100 10 1 2\n\n
No\n\n
They cannot communicate in this case.
\n10 10 10 1\n\n
Yes\n\n
There can be multiple people at the same position.
\n1 100 2 10\n\n
Yes\n
Score : 300 points
\nSnuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:
\nYou are given N and K. Find the probability that Snuke wins the game.
\nInput is given from Standard Input in the following format:
\nN K\n\n
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.
\n3 10\n\n
0.145833333333\n\n
Thus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} + \\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.
\n100000 5\n\n
0.999973749998\n