Dataset Viewer
Auto-converted to Parquet Duplicate
contest_id
int64
50
2.01k
problem_id
stringlengths
4
6
problem_key
stringclasses
32 values
name
stringlengths
5
59
statement
stringlengths
19
3.14k
input_format
stringlengths
13
1.99k
output_format
stringlengths
8
1.65k
examples
stringlengths
54
5.15k
notes
stringclasses
522 values
datasource
stringclasses
2 values
50
050A
A
A - Addition and Subtraction Easy
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either + or -. Your task is to evaluate the formula instead of her.
1≦A,B≦10^9 op is either + or -.``` A op B ```
Evaluate the formula and print the result.
[{"input": ["1 + 2"], "output": ["3"], "explanation": "Since 1 + 2 = 3, the output should be 3."}, {"input": ["5 - 7"], "output": ["-2"], "explanation": ""}]
null
AtC
50
050B
B
B - Contest with Drinks Easy
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N). Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds. It does not affect the time to solve the other problems. A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her.
All input values are integers. 1≦N≦100 1≦T_i≦10^5 1≦M≦100 1≦P_i≦N 1≦X_i≦10^5``` N T_1 T_2 ... T_N M P_1 X_1 P_2 X_2 : P_M X_M ```
For each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.
[{"input": ["3\r\n2 1 4\r\n2\r\n1 1\r\n2 3"], "output": ["6\r\n9"], "explanation": "If Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.\nIf Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds."}, {"input": ["5\r\n7 2 3 8 5\r\n3\r\n4 2\r\n1 7\r\n4 13"], "output": ["19\r\n25\r\n30"], "explanation": ""}]
null
AtC
50
050C
C
C - Lining Up
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i. Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
1≦N≦10^5 0≦A_i≦N-1``` N A_1 A_2 ... A_N ```
Print the number of the possible orders in which they were standing, modulo 10^9+7.
[{"input": ["5\r\n2 4 4 0 2"], "output": ["4"], "explanation": "There are four possible orders, as follows:"}, {"input": ["7\r\n6 4 0 2 4 0 2"], "output": ["0"], "explanation": "Any order would be inconsistent with the reports, thus the answer is 0."}, {"input": ["8\r\n7 5 1 1 7 3 5 3"], "output": ["16"], "explanation": ""}]
null
AtC
50
050D
D
D - Xor Sum
You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.
1≦N≦10^{18}``` N ```
Print the number of the possible pairs of integers u and v, modulo 10^9+7.
[{"input": ["3"], "output": ["5"], "explanation": "The five possible pairs of u and v are:\nu=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)\nu=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.\uff09\nu=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.\uff09\nu=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.\uff09\nu=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.\uff09"}, {"input": ["1422"], "output": ["52277"], "explanation": ""}, {"input": ["1000000000000000000"], "output": ["787014179"], "explanation": ""}]
null
AtC
51
051A
A
A - Haiku
As a New Year's gift, Dolphin received a string s of length 19. The string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]. Dolphin wants to convert the comma-separated string s into a space-separated string. Write a program to perform the conversion for him.
The length of s is 19. The sixth and fourteenth characters in s are ,. The other characters in s are lowercase English letters.``` s ```
Print the string after the conversion.
[{"input": ["happy,newyear,enjoy"], "output": ["happy newyear enjoy"], "explanation": "Replace all the commas in happy,newyear,enjoy with spaces to obtain happy newyear enjoy."}, {"input": ["haiku,atcoder,tasks"], "output": ["haiku atcoder tasks"], "explanation": ""}, {"input": ["abcde,fghihgf,edcba"], "output": ["abcde fghihgf edcba"], "explanation": ""}]
null
AtC
51
051B
B
B - Sum of Three Integers
You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?
2≤K≤2500 0≤S≤3K K and S are integers.``` K S ```
Print the number of the triples of X, Y and Z that satisfy the condition.
[{"input": ["2 2"], "output": ["6"], "explanation": "There are six triples of X, Y and Z that satisfy the condition:"}, {"input": ["5 15"], "output": ["1"], "explanation": "The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z."}]
null
AtC
51
051D
D
D - Candidates of No Shortest Paths
You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i. Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). A connected graph is a graph where there is a path between every pair of different vertices. Find the number of the edges that are not contained in any shortest path between any pair of different vertices.
2≤N≤100 N-1≤M≤min(N(N-1)/2,1000) 1≤a_i,b_i≤N 1≤c_i≤1000 c_i is an integer. The given graph contains neither self-loops nor double edges. The given graph is connected.``` N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M ```
Print the number of the edges in the graph that are not contained in any shortest path between any pair of different vertices.
[{"input": ["3 3\r\n1 2 1\r\n1 3 1\r\n2 3 3"], "output": ["1"], "explanation": "In the given graph, the shortest paths between all pairs of different vertices are as follows:\nThus, the only edge that is not contained in any shortest path, is the edge of length 3 connecting vertex 2 and vertex 3, hence the output should be 1."}, {"input": ["3 2\r\n1 2 1\r\n2 3 1"], "output": ["0"], "explanation": "Every edge is contained in some shortest path between some pair of different vertices."}]
null
AtC
52
052A
A
A - Two Rectangles
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D. Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
All input values are integers. 1≤A≤10^4 1≤B≤10^4 1≤C≤10^4 1≤D≤10^4``` A B C D ```
Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
[{"input": ["3 5 2 7"], "output": ["15"], "explanation": "The first rectangle has an area of 3\u00d75=15, and the second rectangle has an area of 2\u00d77=14. Thus, the output should be 15, the larger area."}, {"input": ["100 600 200 300"], "output": ["60000"], "explanation": ""}]
null
AtC
52
052B
B
B - Increment Decrement
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In 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).
1≤N≤100 |S|=N No characters except I and D occur in S.``` N S ```
Print the maximum value taken by x during the operations.
[{"input": ["5\r\nIIDID"], "output": ["2"], "explanation": "After each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively. Thus, the output should be 2, the maximum value."}, {"input": ["7\r\nDDIDDII"], "output": ["0"], "explanation": "The initial value x=0 is the maximum value taken by x, thus the output should be 0."}]
null
AtC
52
052C
C
C - Factors of Factorial
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
1≤N≤10^3``` N ```
Print the number of the positive divisors of N!, modulo 10^9+7.
[{"input": ["3"], "output": ["4"], "explanation": "There are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4."}, {"input": ["6"], "output": ["30"], "explanation": ""}, {"input": ["1000"], "output": ["972926972"], "explanation": ""}]
null
AtC
52
052D
D
D - Walk and Teleport
There are N towns on a line running east-west. The towns are numbered 1 through N, in order from west to east. Each point on the line has a one-dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of town i is X_i. You are now at town 1, and you want to visit all the other towns. You have two ways to travel: Walk on the line. Your fatigue level increases by A each time you travel a distance of 1, regardless of direction. Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered. Walk on the line. Your fatigue level increases by A each time you travel a distance of 1, regardless of direction. Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered. Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways.
All input values are integers. 2≤N≤10^5 1≤X_i≤10^9 For all i(1≤i≤N-1), X_i<X_{i+1}. 1≤A≤10^9 1≤B≤10^9``` N A B X_1 X_2 ... X_N ```
Print the minimum possible total increase of your fatigue level when you visit all the towns.
[{"input": ["4 2 5\r\n1 2 5 7"], "output": ["11"], "explanation": "From town 1, walk a distance of 1 to town 2, then teleport to town 3, then walk a distance of 2 to town 4. The total increase of your fatigue level in this case is 2\u00d71+5+2\u00d72=11, which is the minimum possible value."}, {"input": ["7 1 100\r\n40 43 45 105 108 115 124"], "output": ["84"], "explanation": "From town 1, walk all the way to town 7. The total increase of your fatigue level in this case is 84, which is the minimum possible value."}, {"input": ["7 1 2\r\n24 35 40 68 72 99 103"], "output": ["12"], "explanation": "Visit all the towns in any order by teleporting six times. The total increase of your fatigue level in this case is 12, which is the minimum possible value."}]
null
AtC
53
053A
A
A - ABC/ARC
Smeke 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. You are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, and print ARC otherwise.
1 ≦ x ≦ 3{,}000 x is an integer.``` x ```
Print the answer.
[{"input": ["1000"], "output": ["ABC"], "explanation": "Smeke's current rating is less than 1200, thus the output should be ABC."}, {"input": ["2000"], "output": ["ARC"], "explanation": "Smeke's current rating is not less than 1200, thus the output should be ARC."}]
null
AtC
53
053B
B
B - A to Z String
Snuke 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.
1 ≦ |s| ≦ 200{,}000 s consists of uppercase English letters. There exists a substring of s that starts with A and ends with Z.``` s ```
Print the answer.
[{"input": ["QWERTYASDFZXCV"], "output": ["5"], "explanation": "By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z."}, {"input": ["ZABCZ"], "output": ["4"], "explanation": ""}, {"input": ["HASFJGHOGAKZZFEGA"], "output": ["12"], "explanation": ""}]
null
AtC
53
053C
C
C - X: Yet Another Die Game
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation: Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward. For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back. Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.
1 ≦ x ≦ 10^{15} x is an integer.``` x ```
Print the answer.
[{"input": ["7"], "output": ["2"], "explanation": ""}, {"input": ["149696127901"], "output": ["27217477801"], "explanation": ""}]
null
AtC
53
053D
D
D - Card Eater
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
3 ≦ N ≦ 10^{5} N is odd. 1 ≦ A_i ≦ 10^{5} A_i is an integer.``` N A_1 A_2 A_3 ... A_{N} ```
Print the answer.
[{"input": ["5\r\n1 2 1 3 7"], "output": ["3"], "explanation": "One optimal solution is to perform the operation once, taking out two cards with 1 and one card with 2. One card with 1 and another with 2 will be eaten, and the remaining card with 1 will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: 1, 3 and 7."}, {"input": ["15\r\n1 3 5 2 1 3 2 8 8 6 2 6 11 1 1"], "output": ["7"], "explanation": ""}]
null
AtC
54
054A
A
A - One Card Poker
Alice and Bob are playing One Card Poker. One Card Poker is a two-player game using playing cards. Each card in this game shows an integer between 1 and 13, inclusive. The 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: You are watching Alice and Bob playing the game, and can see their hands. The number written on Alice's card is A, and the number written on Bob's card is B. Write a program to determine the outcome of the game.
1≦A≦13 1≦B≦13 A and B are integers.``` A B ```
Print Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn.
[{"input": ["8 6"], "output": ["Alice"], "explanation": "8 is written on Alice's card, and 6 is written on Bob's card. Alice has the stronger card, and thus the output should be Alice."}, {"input": ["1 1"], "output": ["Draw"], "explanation": "Since their cards have the same number, the game will be drawn."}, {"input": ["13 1"], "output": ["Bob"], "explanation": ""}]
null
AtC
54
054B
B
B - Template Matching
You 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. A pixel is the smallest element of an image, and in this problem it is a square of size 1×1. Also, 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. The image A is given as N strings A_1,...,A_N. The 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). Similarly, the template image B is given as M strings B_1,...,B_M. The 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.
1≦M≦N≦50 A_i is a string of length N consisting of # and .. B_i is a string of length M consisting of # and ..``` N M A_1 A_2 : A_N B_1 B_2 : B_M ```
Print Yes if the template image B is contained in the image A. Print No otherwise.
[{"input": ["3 2\r\n#.#\r\n.#.\r\n#.#\r\n#.\r\n.#"], "output": ["Yes"], "explanation": "The template image B is identical to the upper-left 2 \u00d7 2 subimage and the lower-right 2 \u00d7 2 subimage of A. Thus, the output should be Yes."}, {"input": ["4 1\r\n....\r\n....\r\n....\r\n....\r\n#"], "output": ["No"], "explanation": "The template image B, composed of a black pixel, is not contained in the image A composed of white pixels."}]
null
AtC
54
054C
C
C - One-stroke Path
You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. Figure 4: another example of a path that does not satisfy the condition
2≦N≦8 0≦M≦N(N-1)/2 1≦a_i<b_i≦N The given graph contains neither self-loops nor double edges.``` N M a_1 b_1 a_2 b_2 : a_M b_M ```
Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once.
[{"input": ["3 3\r\n1 2\r\n1 3\r\n2 3"], "output": ["2"], "explanation": "The given graph is shown in the following figure:\nThe following two paths satisfy the condition:"}, {"input": ["7 7\r\n1 3\r\n2 7\r\n3 4\r\n4 5\r\n4 6\r\n5 6\r\n6 7"], "output": ["1"], "explanation": "This test case is the same as the one described in the problem statement."}]
null
AtC
54
054D
D
D - Mixing Experiment
Dolphin is planning to generate a small amount of a certain chemical substance C. In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b. He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy. The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock. The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan). Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C. Find the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact.
1≦N≦40 1≦a_i,b_i≦10 1≦c_i≦100 1≦M_a,M_b≦10 gcd(M_a,M_b)=1 a_i, b_i, c_i, M_a and M_b are integers.``` N M_a M_b a_1 b_1 c_1 a_2 b_2 c_2 : a_N b_N c_N ```
Print the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C, print -1 instead.
[{"input": ["3 1 1\r\n1 2 1\r\n2 1 2\r\n3 3 10"], "output": ["3"], "explanation": "The amount of money spent will be minimized by purchasing the packages of chemicals 1 and 2. In this case, the mixture of the purchased chemicals will contain 3 grams of the substance A and 3 grams of the substance B, which are in the desired ratio: 3:3=1:1. The total price of these packages is 3 yen."}, {"input": ["1 1 10\r\n10 10 10"], "output": ["-1"], "explanation": "The ratio 1:10 of the two substances A and B cannot be satisfied by purchasing any combination of the packages. Thus, the output should be -1."}]
null
AtC
55
055A
A
A - Restaurant
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
1 ≤ N ≤ 100``` N ```
Print the answer.
[{"input": ["20"], "output": ["15800"], "explanation": "So far, Snuke has paid 16000 yen, and the restaurant has paid back 200 yen. Thus, the answer is 15800."}, {"input": ["60"], "output": ["47200"], "explanation": "Snuke has paid 48000 yen for 60 meals, and the restaurant has paid back 800 yen."}]
null
AtC
55
055B
B
B - Training Camp
Snuke loves working out. He is now exercising N times. Before he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
1 ≤ N ≤ 10^{5}``` N ```
Print the answer modulo 10^{9}+7.
[{"input": ["3"], "output": ["6"], "explanation": ""}, {"input": ["10"], "output": ["3628800"], "explanation": ""}, {"input": ["100000"], "output": ["457992974"], "explanation": "Print the answer modulo 10^{9}+7."}]
null
AtC
55
055C
C
C - Scc Puzzle
Snuke loves puzzles. Today, he is working on a puzzle using S- and c-shaped pieces. In this puzzle, you can combine two c-shaped pieces into one S-shaped piece, as shown in the figure below: Snuke decided to create as many Scc groups as possible by putting together one S-shaped piece and two c-shaped pieces. Find the maximum number of Scc groups that can be created when Snuke has N S-shaped pieces and M c-shaped pieces.
1 ≤ N,M ≤ 10^{12}``` N M ```
Print the answer.
[{"input": ["1 6"], "output": ["2"], "explanation": "Two Scc groups can be created as follows:"}, {"input": ["12345 678901"], "output": ["175897"], "explanation": ""}]
null
AtC
55
055D
D
D - Menagerie
Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is o, the animal said that the two neighboring animals are of the same species, and if s_i is x, the animal said that the two neighboring animals are of different species. More formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise. Similarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1.
3 ≤ N ≤ 10^{5} s is a string of length N consisting of o and x.``` N s ```
If there does not exist an valid assignment that is consistent with s, print -1. Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s.
[{"input": ["6\r\nooxoox"], "output": ["SSSWWS"], "explanation": "For example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.\nLet us remind you: if the neiboring animals are of the same species, a sheep answers o and a wolf answers x. If the neiboring animals are of different species, a sheep answers x and a wolf answers o."}, {"input": ["3\r\noox"], "output": ["-1"], "explanation": "Print -1 if there is no valid assignment of species."}, {"input": ["10\r\noxooxoxoox"], "output": ["SSWWSSSWWS"], "explanation": ""}]
null
AtC
56
056A
A
A - HonestOrDishonest
Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You 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. If 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.
a=H or a=D. b=H or b=D.``` a b ```
If TopCoDeer is honest, print H. If he is dishonest, print D.
[{"input": ["H H"], "output": ["H"], "explanation": "In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest."}, {"input": ["D H"], "output": ["D"], "explanation": "In this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest."}, {"input": ["D D"], "output": ["H"], "explanation": ""}]
null
AtC
56
056B
B
B - NarrowRectanglesEasy
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If 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: AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.
All input values are integers. 1≤W≤10^5 1≤a,b≤10^5``` W a b ```
Print the minimum distance the second rectangle needs to be moved.
[{"input": ["3 2 6"], "output": ["1"], "explanation": "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."}, {"input": ["3 1 3"], "output": ["0"], "explanation": "The rectangles are already connected, and thus no move is needed."}, {"input": ["5 10 1"], "output": ["4"], "explanation": ""}]
null
AtC
56
056C
C
C - Go Home
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
X is an integer. 1≤X≤10^9``` X ```
Print the earliest possible time for the kangaroo to reach coordinate X.
[{"input": ["6"], "output": ["3"], "explanation": "The kangaroo can reach his nest at time 3 by jumping to the right three times, which is the earliest possible time."}, {"input": ["2"], "output": ["2"], "explanation": "He can reach his nest at time 2 by staying at his position during the first second, and jumping to the right at the next second."}, {"input": ["11"], "output": ["5"], "explanation": ""}]
null
AtC
56
056D
D
D - No Need
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i, he judges whether it is unnecessary or not, as follows: If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.
All input values are integers. 1≤N≤5000 1≤K≤5000 1≤a_i≤10^9 (1≤i≤N)``` N K a_1 a_2 ... a_N ```
Print the number of the unnecessary cards.
[{"input": ["3 6\r\n1 4 3"], "output": ["1"], "explanation": "There are two good sets: {2,3} and {1,2,3}.\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is also good. Thus, card 1 is unnecessary.\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is NOT unnecessary.\nNeither is card 3 for a similar reason, hence the answer is 1."}, {"input": ["5 400\r\n3 1 4 1 5"], "output": ["5"], "explanation": "In this case, there is no good set. Therefore, all the cards are unnecessary."}, {"input": ["6 20\r\n10 4 3 10 25 2"], "output": ["3"], "explanation": ""}]
null
AtC
57
057A
A
A - Remaining Time
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder. In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock". The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.
0 \leq A,B \leq 23 A and B are integers.``` A B ```
Print the hour of the starting time of the contest in 24-hour time.
[{"input": ["9 12"], "output": ["21"], "explanation": "In this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time."}, {"input": ["19 0"], "output": ["19"], "explanation": "The contest has just started."}, {"input": ["23 2"], "output": ["1"], "explanation": "The contest will begin at 1 o'clock the next day."}]
null
AtC
57
057B
B
B - Checkpoints
There are N students and M checkpoints on the xy-plane. The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j). When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance. The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|. Here, |x| denotes the absolute value of x. If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index. Which checkpoint will each student go to?
1 \leq N,M \leq 50 -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8 All input values are integers.``` N M a_1 b_1 : a_N b_N c_1 d_1 : c_M d_M ```
Print N lines. The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.
[{"input": ["2 2\r\n2 0\r\n0 0\r\n-1 0\r\n1 0"], "output": ["2\r\n1"], "explanation": "The Manhattan distance between the first student and each checkpoint is:\nThe nearest checkpoint is checkpoint 2. Thus, the first line in the output should contain 2.\nThe Manhattan distance between the second student and each checkpoint is:\nWhen there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain 1."}, {"input": ["3 4\r\n10 10\r\n-10 -10\r\n3 3\r\n1 2\r\n2 3\r\n3 5\r\n3 5"], "output": ["3\r\n1\r\n2"], "explanation": "There can be multiple checkpoints at the same coordinates."}, {"input": ["5 5\r\n-100000000 -100000000\r\n-100000000 100000000\r\n100000000 -100000000\r\n100000000 100000000\r\n0 0\r\n0 0\r\n100000000 100000000\r\n100000000 -100000000\r\n-100000000 100000000\r\n-100000000 -100000000"], "output": ["5\r\n4\r\n3\r\n2\r\n1"], "explanation": ""}]
null
AtC
57
057C
C
C - Digits in Multiplication
You are given an integer N. For 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. For example, F(3,11) = 2 since 3 has one digit and 11 has two digits. Find the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.
1 \leq N \leq 10^{10} N is an integer.``` 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.
[{"input": ["10000"], "output": ["3"], "explanation": "F(A,B) has a minimum value of 3 at (A,B)=(100,100)."}, {"input": ["1000003"], "output": ["7"], "explanation": "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."}, {"input": ["9876543210"], "output": ["6"], "explanation": ""}]
null
AtC
57
057D
D
D - Maximum Average Sets
You are given N items. The value of the i-th item (1 \leq i \leq N) is v_i. Your have to select at least A and at most B of these items. Under this condition, find the maximum possible arithmetic mean of the values of selected items. Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
1 \leq N \leq 50 1 \leq A,B \leq N 1 \leq v_i \leq 10^{15} Each v_i is an integer.``` N A B v_1 v_2 ... v_N ```
Print two lines. The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}. The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
[{"input": ["5 2 2\r\n1 2 3 4 5"], "output": ["4.500000\r\n1"], "explanation": "The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5. There is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1."}, {"input": ["4 2 3\r\n10 20 10 10"], "output": ["15.000000\r\n3"], "explanation": "There can be multiple ways to select items so that the mean of the values will be maximized."}, {"input": ["5 1 5\r\n1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996"], "output": ["1000000000000000.000000\r\n1"], "explanation": ""}]
null
AtC
58
058A
A
A - ι⊥l
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We 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. Determine whether the arrangement of the poles is beautiful.
1 \leq a,b,c \leq 100 a, b and c are integers.``` a b c ```
Print YES if the arrangement of the poles is beautiful; print NO otherwise.
[{"input": ["2 4 6"], "output": ["YES"], "explanation": "Since 4-2 = 6-4, this arrangement of poles is beautiful."}, {"input": ["2 5 6"], "output": ["NO"], "explanation": "Since 5-2 \\neq 6-5, this arrangement of poles is not beautiful."}, {"input": ["3 2 1"], "output": ["YES"], "explanation": "Since 1-2 = 2-3, this arrangement of poles is beautiful."}]
null
AtC
58
058B
B
B - ∵∴∵
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd-numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
O and E consists of lowercase English letters (a - z). 1 \leq |O|,|E| \leq 50 |O| - |E| is either 0 or 1.``` O E ```
Print the original password.
[{"input": ["xyz\r\nabc"], "output": ["xaybzc"], "explanation": "The original password is xaybzc. Extracting the characters at the odd-numbered positions results in xyz, and extracting the characters at the even-numbered positions results in abc."}, {"input": ["atcoderbeginnercontest\r\natcoderregularcontest"], "output": ["aattccooddeerrbreeggiunlnaerrccoonntteesstt"], "explanation": ""}]
null
AtC
58
058C
C
C - Dubious Document
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
1 \leq n \leq 50 1 \leq |S_i| \leq 50 for every i = 1, ..., n. S_i consists of lowercase English letters (a - z) for every i = 1, ..., n.``` n S_1 ... S_n ```
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line.
[{"input": ["3\r\ncbaa\r\ndaacc\r\nacacac"], "output": ["aac"], "explanation": "The strings that can be created from each of cbaa, daacc and acacac, are aa, aac, aca, caa and so forth. Among them, aac, aca and caa are the longest, and the lexicographically smallest of these three is aac."}, {"input": ["3\r\na\r\naa\r\nb"], "output": [""], "explanation": "The answer is an empty string."}]
null
AtC
58
058D
D
D - ###
On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i. For every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7. That is, for every quadruple (i,j,k,l) satisfying 1\leq i < j\leq n and 1\leq k < l\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.
2 \leq n,m \leq 10^5 -10^9 \leq x_1 < ... < x_n \leq 10^9 -10^9 \leq y_1 < ... < y_m \leq 10^9 x_i and y_i are integers.``` n m x_1 x_2 ... x_n y_1 y_2 ... y_m ```
Print the total area of the rectangles, modulo 10^9+7.
[{"input": ["3 3\r\n1 3 4\r\n1 3 6"], "output": ["60"], "explanation": "The following figure illustrates this input:\n\nThe total area of the nine rectangles A, B, ..., I shown in the following figure, is 60.\n"}, {"input": ["6 5\r\n-790013317 -192321079 95834122 418379342 586260100 802780784\r\n-253230108 193944314 363756450 712662868 735867677"], "output": ["835067060"], "explanation": ""}]
null
AtC
59
059A
A
A - Three-letter acronym
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
s_1, s_2 and s_3 are composed of lowercase English letters. 1 ≤ |s_i| ≤ 10 (1≤i≤3)``` s_1 s_2 s_3 ```
Print the answer.
[{"input": ["atcoder beginner contest"], "output": ["ABC"], "explanation": "The initial letters of atcoder, beginner and contest are a, b and c. Uppercase and concatenate them to obtain ABC."}, {"input": ["resident register number"], "output": ["RRN"], "explanation": ""}, {"input": ["k nearest neighbor"], "output": ["KNN"], "explanation": ""}, {"input": ["async layered coding"], "output": ["ALC"], "explanation": ""}]
null
AtC
59
059B
B
B - Comparison
You are given two positive integers A and B. Compare the magnitudes of these numbers.
1 ≤ A, B ≤ 10^{100} Neither A nor B begins with a 0.``` A B ```
Print GREATER if A>B, LESS if A<B and EQUAL if A=B.
[{"input": ["36\r\n24"], "output": ["GREATER"], "explanation": "Since 36>24, print GREATER."}, {"input": ["850\r\n3777"], "output": ["LESS"], "explanation": ""}, {"input": ["9720246\r\n22516266"], "output": ["LESS"], "explanation": ""}, {"input": ["123456789012345678901234567890\r\n234567890123456789012345678901"], "output": ["LESS"], "explanation": ""}]
null
AtC
59
059C
C
C - Sequence
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero. For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.
2 ≤ n ≤ 10^5 |a_i| ≤ 10^9 Each a_i is an integer.``` n a_1 a_2 ... a_n ```
Print the minimum necessary count of operations.
[{"input": ["4\r\n1 -3 1 0"], "output": ["4"], "explanation": "For example, the given sequence can be transformed into 1, -2, 2, -2 by four operations. The sums of the first one, two, three and four terms are 1, -1, 1 and -1, respectively, which satisfy the conditions."}, {"input": ["5\r\n3 -6 4 -5 7"], "output": ["0"], "explanation": "The given sequence already satisfies the conditions."}, {"input": ["6\r\n-1 4 3 2 -5 4"], "output": ["8"], "explanation": ""}]
null
AtC
59
059D
D
D - Alice&Brown
Alice and Brown loves games. Today, they will play the following game. In this game, there are two piles initially consisting of X and Y stones, respectively. Alice and Bob alternately perform the following operation, starting from Alice: Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile. The player who becomes unable to perform the operation, loses the game. Given X and Y, determine the winner of the game, assuming that both players play optimally.
0 ≤ X, Y ≤ 10^{18}``` X Y ```
Print the winner: either Alice or Brown.
[{"input": ["2 1"], "output": ["Brown"], "explanation": "Alice can do nothing but taking two stones from the pile containing two stones. As a result, the piles consist of zero and two stones, respectively. Then, Brown will take the two stones, and the piles will consist of one and zero stones, respectively. Alice will be unable to perform the operation anymore, which means Brown's victory."}, {"input": ["5 0"], "output": ["Alice"], "explanation": ""}, {"input": ["0 0"], "output": ["Brown"], "explanation": ""}, {"input": ["4 8"], "output": ["Alice"], "explanation": ""}]
null
AtC
60
060A
A
A - Shiritori
You are given three strings A, B and C. Check whether they form a word chain. More formally, determine whether both of the following are true: The last character in A and the initial character in B are the same. The last character in B and the initial character in C are the same. If both are true, print YES. Otherwise, print NO.
A, B and C are all composed of lowercase English letters (a - z). 1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.``` A B C ```
Print YES or NO.
[{"input": ["rng gorilla apple"], "output": ["YES"], "explanation": "They form a word chain."}, {"input": ["yakiniku unagi sushi"], "output": ["NO"], "explanation": "A and B form a word chain, but B and C do not."}, {"input": ["a a a"], "output": ["YES"], "explanation": ""}, {"input": ["aaaaaaaaab aaaaaaaaaa aaaaaaaaab"], "output": ["NO"], "explanation": ""}]
null
AtC
60
060B
B
B - Choose Integers
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print YES. Otherwise, print NO.
1 ≤ A ≤ 100 1 ≤ B ≤ 100 0 ≤ C < B``` A B C ```
Print YES or NO.
[{"input": ["7 5 1"], "output": ["YES"], "explanation": "For example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5."}, {"input": ["2 2 1"], "output": ["NO"], "explanation": "The sum of even numbers, no matter how many, is never odd."}, {"input": ["1 100 97"], "output": ["YES"], "explanation": "You can select 97, since you may select multiples of 1, that is, all integers."}, {"input": ["40 98 58"], "output": ["YES"], "explanation": ""}, {"input": ["77 42 36"], "output": ["NO"], "explanation": ""}]
null
AtC
60
060C
C
C - Sentou
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
1 ≤ N ≤ 200,000 1 ≤ T ≤ 10^9 0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9 T and each t_i are integers.``` N T t_1 t_2 ... t_N ```
Assume that the shower will emit water for a total of X seconds. Print X.
[{"input": ["2 4\r\n0 3"], "output": ["7"], "explanation": "Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds."}, {"input": ["2 4\r\n0 5"], "output": ["8"], "explanation": "One second after the shower stops emission of water triggered by the first person, the switch is pushed again."}, {"input": ["4 1000000000\r\n0 1000 1000000 1000000000"], "output": ["2000000000"], "explanation": ""}, {"input": ["1 1\r\n0"], "output": ["1"], "explanation": ""}, {"input": ["9 10\r\n0 3 5 7 100 110 200 300 311"], "output": ["67"], "explanation": ""}]
null
AtC
60
060D
D
D - Simple Knapsack
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
1 ≤ N ≤ 100 1 ≤ W ≤ 10^9 1 ≤ w_i ≤ 10^9 For each i = 2,3,...,N, w_1 ≤ w_i ≤ w_1 + 3. 1 ≤ v_i ≤ 10^7 W, each w_i and v_i are integers.``` N W w_1 v_1 w_2 v_2 : w_N v_N ```
Print the maximum possible total value of the selected items.
[{"input": ["4 6\r\n2 1\r\n3 4\r\n4 10\r\n3 4"], "output": ["11"], "explanation": "The first and third items should be selected."}, {"input": ["4 6\r\n2 1\r\n3 7\r\n4 10\r\n3 6"], "output": ["13"], "explanation": "The second and fourth items should be selected."}, {"input": ["4 10\r\n1 100\r\n1 100\r\n1 100\r\n1 100"], "output": ["400"], "explanation": "You can take everything."}, {"input": ["4 1\r\n10 100\r\n10 100\r\n10 100\r\n10 100"], "output": ["0"], "explanation": "You can take nothing."}]
null
AtC
61
061A
A
A - Between Two Integers
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
-100≤A,B,C≤100 A, B and C are all integers.``` A B C ```
If the condition is satisfied, print Yes; otherwise, print No.
[{"input": ["1 3 2"], "output": ["Yes"], "explanation": "C=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes."}, {"input": ["6 5 4"], "output": ["No"], "explanation": "C=4 is less than A=6, and thus the output should be No."}, {"input": ["2 2 2"], "output": ["Yes"], "explanation": ""}]
null
AtC
61
061B
B
B - Counting Roads
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
2≤N,M≤50 1≤a_i,b_i≤N a_i ≠ b_i All input values are integers.``` N M a_1 b_1 : a_M b_M ```
Print the answer in N lines. In the i-th line (1≤i≤N), print the number of roads connected to city i.
[{"input": ["4 3\r\n1 2\r\n2 3\r\n1 4"], "output": ["2\r\n2\r\n1\r\n1"], "explanation": ""}, {"input": ["2 5\r\n1 2\r\n2 1\r\n1 2\r\n2 1\r\n1 2"], "output": ["5\r\n5"], "explanation": ""}, {"input": ["8 8\r\n1 2\r\n3 4\r\n1 5\r\n2 8\r\n3 7\r\n5 2\r\n4 1\r\n6 8"], "output": ["3\r\n3\r\n2\r\n2\r\n2\r\n1\r\n1\r\n2"], "explanation": ""}]
null
AtC
61
061C
C
C - Big Array
There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \{1,2,2,3,3,3\} is 3.
1≤N≤10^5 1≤a_i,b_i≤10^5 1≤K≤b_1…+…b_n All input values are integers.``` N K a_1 b_1 : a_N b_N ```
Print the K-th smallest integer in the array after the N operations.
[{"input": ["3 4\r\n1 1\r\n2 2\r\n3 3"], "output": ["3"], "explanation": "The resulting array is the same as the one in the problem statement."}, {"input": ["10 500000\r\n1 100000\r\n1 100000\r\n1 100000\r\n1 100000\r\n1 100000\r\n100000 100000\r\n100000 100000\r\n100000 100000\r\n100000 100000\r\n100000 100000"], "output": ["1"], "explanation": ""}]
null
AtC
61
061D
D
D - Score Attack
There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print inf.
2≤N≤1000 1≤M≤min(N(N-1),2000) 1≤a_i,b_i≤N (1≤i≤M) a_i≠b_i (1≤i≤M) a_i≠a_j or b_i≠b_j (1≤i<j≤M) -10^9≤c_i≤10^9 (1≤i≤M) c_i is an integer. In the given graph, there exists a path from vertex 1 to vertex N.``` N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M ```
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print inf.
[{"input": ["3 3\r\n1 2 4\r\n2 3 3\r\n1 3 5"], "output": ["7"], "explanation": "There are two ways to move the piece to vertex N=3:\nThus, the maximum possible score at the end of the game is 7."}, {"input": ["2 2\r\n1 2 1\r\n2 1 1"], "output": ["inf"], "explanation": "It is possible to increase the score indefinitely by alternating between vertex 1 and 2."}, {"input": ["6 5\r\n1 2 -1000000000\r\n2 3 -1000000000\r\n3 4 -1000000000\r\n4 5 -1000000000\r\n5 6 -1000000000"], "output": ["-5000000000"], "explanation": ""}]
null
AtC
62
062A
A
A - Grouping
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
x and y are integers. 1 ≤ x < y ≤ 12``` x y ```
If x and y belong to the same group, print Yes; otherwise, print No.
[{"input": ["1 3"], "output": ["Yes"], "explanation": ""}, {"input": ["2 4"], "output": ["No"], "explanation": ""}]
null
AtC
62
062B
B
B - Picture Frame
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of # and have a thickness of 1.
1 ≤ H, W ≤ 100 a_{ij} is a lowercase English letter.``` H W a_{11} ... a_{1W} : a_{H1} ... a_{HW} ```
Print the image surrounded by a box that consists of # and has a thickness of 1.
[{"input": ["2 3\r\nabc\r\narc"], "output": ["#####\r\n#abc#\r\n#arc#\r\n#####"], "explanation": ""}, {"input": ["1 1\r\nz"], "output": ["###\r\n#z#\r\n###"], "explanation": ""}]
null
AtC
62
062C
C
C - Chocolate Bar
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} - S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
2 ≤ H, W ≤ 10^5``` H W ```
Print the minimum possible value of S_{max} - S_{min}.
[{"input": ["3 5"], "output": ["0"], "explanation": "In the division below, S_{max} - S_{min} = 5 - 5 = 0."}, {"input": ["4 5"], "output": ["2"], "explanation": "In the division below, S_{max} - S_{min} = 8 - 6 = 2."}, {"input": ["5 5"], "output": ["4"], "explanation": "In the division below, S_{max} - S_{min} = 10 - 6 = 4."}, {"input": ["100000 2"], "output": ["1"], "explanation": ""}, {"input": ["100000 100000"], "output": ["50000"], "explanation": ""}]
null
AtC
62
062D
D
D - 3N Numbers
Let N be a positive integer. There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}). Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a'). Find the maximum possible score of a'.
1 ≤ N ≤ 10^5 a_i is an integer. 1 ≤ a_i ≤ 10^9``` N a_1 a_2 ... a_{3N} ```
Print the maximum possible score of a'.
[{"input": ["2\r\n3 1 4 1 5 9"], "output": ["1"], "explanation": "When a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3 + 4) - (1 + 5) = 1."}, {"input": ["1\r\n1 2 3"], "output": ["-1"], "explanation": "For example, when a_1 are removed, a' will be (2, 3), which has a score of 2 - 3 = -1."}, {"input": ["3\r\n8 2 2 7 4 6 5 3 8"], "output": ["5"], "explanation": "For example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3), which has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5."}]
null
AtC
63
063A
A
A - Restricted
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output error instead.
A and B are integers. 1 ≤ A, B ≤ 9``` A B ```
If A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.
[{"input": ["6 3"], "output": ["9"], "explanation": ""}, {"input": ["6 4"], "output": ["error"], "explanation": ""}]
null
AtC
63
063B
B
B - Varied
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
2 ≤ |S| ≤ 26, where |S| denotes the length of S. S consists of lowercase English letters.``` S ```
If all the characters in S are different, print yes (case-sensitive); otherwise, print no.
[{"input": ["uncopyrightable"], "output": ["yes"], "explanation": ""}, {"input": ["different"], "output": ["no"], "explanation": ""}, {"input": ["no"], "output": ["yes"], "explanation": ""}]
null
AtC
63
063C
C
C - Bugged
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
All input values are integers. 1 ≤ N ≤ 100 1 ≤ s_i ≤ 100``` N s_1 s_2 : s_N ```
Print the maximum value that can be displayed as your grade.
[{"input": ["3\r\n5\r\n10\r\n15"], "output": ["25"], "explanation": "Your grade will be 25 if the 10-point and 15-point questions are answered correctly and the 5-point question is not, and this grade will be displayed correctly. Your grade will become 30 if the 5-point question is also answered correctly, but this grade will be incorrectly displayed as 0."}, {"input": ["3\r\n10\r\n10\r\n15"], "output": ["35"], "explanation": "Your grade will be 35 if all the questions are answered correctly, and this grade will be displayed correctly."}, {"input": ["3\r\n10\r\n20\r\n30"], "output": ["0"], "explanation": "Regardless of whether each question is answered correctly or not, your grade will be a multiple of 10 and displayed as 0."}]
null
AtC
63
063D
D
D - Widespread
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows: Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds. At least how many explosions do you need to cause in order to vanish all the monsters?
All input values are integers. 1 ≤ N ≤ 10^5 1 ≤ B < A ≤ 10^9 1 ≤ h_i ≤ 10^9``` N A B h_1 h_2 : h_N ```
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.
[{"input": ["4 5 3\r\n8\r\n7\r\n4\r\n2"], "output": ["2"], "explanation": "You can vanish all the monsters in two explosion, as follows:"}, {"input": ["2 10 4\r\n20\r\n20"], "output": ["4"], "explanation": "You need to cause two explosions centered at each monster, for a total of four."}, {"input": ["5 2 1\r\n900000000\r\n900000000\r\n1000000000\r\n1000000000\r\n1000000000"], "output": ["800000000"], "explanation": ""}]
null
AtC
64
064A
A
A - RGB Cards
AtCoDeer has three cards, one red, one green and one blue. An 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. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
1 ≤ r, g, b ≤ 9``` r g b ```
If the three-digit integer is a multiple of 4, print YES (case-sensitive); otherwise, print NO.
[{"input": ["4 3 2"], "output": ["YES"], "explanation": "432 is a multiple of 4, and thus YES should be printed."}, {"input": ["2 3 4"], "output": ["NO"], "explanation": "234 is not a multiple of 4, and thus NO should be printed."}]
null
AtC
64
064B
B
B - Traveling AtCoDeer Problem
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.
1 ≤ N ≤ 100 0 ≤ a_i ≤ 1000 a_i is an integer.``` N a_1 a_2 ... a_N ```
Print the minimum distance to be traveled.
[{"input": ["4\r\n2 3 7 9"], "output": ["7"], "explanation": "The travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2. It is not possible to do with a travel distance of less than 7, and thus 7 is the minimum distance to be traveled."}, {"input": ["8\r\n3 1 4 1 5 9 2 6"], "output": ["8"], "explanation": "There may be more than one house at a position."}]
null
AtC
64
064C
C
C - Colorful Leaderboard
In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows: Rating 1-399 : gray Rating 400-799 : brown Rating 800-1199 : green Rating 1200-1599 : cyan Rating 1600-1999 : blue Rating 2000-2399 : yellow Rating 2400-2799 : orange Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
1 ≤ N ≤ 100 1 ≤ a_i ≤ 4800 a_i is an integer.``` N a_1 a_2 ... a_N ```
Print the minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between.
[{"input": ["4\r\n2100 2500 2700 2700"], "output": ["2 2"], "explanation": "The user with rating 2100 is \"yellow\", and the others are \"orange\". There are two different colors."}, {"input": ["5\r\n1100 1900 2800 3200 3200"], "output": ["3 5"], "explanation": "The user with rating 1100 is \"green\", the user with rating 1900 is blue and the user with rating 2800 is \"red\". If the fourth user picks \"red\", and the fifth user picks \"blue\", there are three different colors. This is one possible scenario for the minimum number of colors. If the fourth user picks \"purple\", and the fifth user picks \"black\", there are five different colors. This is one possible scenario for the maximum number of colors."}, {"input": ["20\r\n800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990"], "output": ["1 1"], "explanation": "All the users are \"green\", and thus there is one color."}]
null
AtC
64
064D
D
D - Insertion
You are given a string S of length N consisting of ( and ). Your task is to insert some number of ( and ) into S to obtain a correct bracket sequence. Here, a correct bracket sequence is defined as follows: () is a correct bracket sequence. If X is a correct bracket sequence, the concatenation of (, X and ) in this order is also a correct bracket sequence. If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
The length of S is N. 1 ≤ N ≤ 100 S consists of ( and ).``` N S ```
Print the lexicographically smallest string among the shortest correct bracket sequences that can be obtained by inserting some number of ( and ) into S.
[{"input": ["3\r\n())"], "output": ["(())"], "explanation": ""}, {"input": ["6\r\n)))())"], "output": ["(((()))())"], "explanation": ""}, {"input": ["8\r\n))))(((("], "output": ["(((())))(((())))"], "explanation": ""}]
null
AtC
65
065A
A
A - Expired?
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache.
1 ≤ X,A,B ≤ 10^9``` X A B ```
Print delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache.
[{"input": ["4 3 6"], "output": ["safe"], "explanation": "He ate the food three days after the \"best-by\" date. It was not delicious or harmful for him."}, {"input": ["6 5 1"], "output": ["delicious"], "explanation": "He ate the food by the \"best-by\" date. It was delicious for him."}, {"input": ["3 7 12"], "output": ["dangerous"], "explanation": "He ate the food five days after the \"best-by\" date. It was harmful for him."}]
null
AtC
65
065B
B
B - Trained?
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When 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. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
2 ≤ N ≤ 10^5 1 ≤ a_i ≤ N``` N a_1 a_2 : a_N ```
Print -1 if it is impossible to lighten up Button 2. Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.
[{"input": ["3\r\n3\r\n1\r\n2"], "output": ["2"], "explanation": "Press Button 1, then Button 3."}, {"input": ["4\r\n3\r\n4\r\n1\r\n2"], "output": ["-1"], "explanation": "Pressing Button 1 lightens up Button 3, and vice versa, so Button 2 will never be lighten up."}, {"input": ["5\r\n3\r\n3\r\n4\r\n2\r\n4"], "output": ["3"], "explanation": ""}]
null
AtC
65
065C
C
C - Reconciled?
Snuke has N dogs and M monkeys. He wants them to line up in a row. As 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. How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
1 ≤ N,M ≤ 10^5``` N M ```
Print the number of possible arrangements, modulo 10^9+7.
[{"input": ["2 2"], "output": ["8"], "explanation": "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."}, {"input": ["3 2"], "output": ["12"], "explanation": ""}, {"input": ["1 8"], "output": ["0"], "explanation": ""}, {"input": ["100000 100000"], "output": ["530123477"], "explanation": ""}]
null
AtC
65
065D
D
D - Built?
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads. Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?
2 ≤ N ≤ 10^5 0 ≤ x_i,y_i ≤ 10^9 All input values are integers.``` N x_1 y_1 x_2 y_2 : x_N y_N ```
Print the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads.
[{"input": ["3\r\n1 5\r\n3 9\r\n7 8"], "output": ["3"], "explanation": "Build a road between Towns 1 and 2, and another between Towns 2 and 3. The total cost is 2+1=3 yen."}, {"input": ["6\r\n8 3\r\n4 9\r\n12 19\r\n18 1\r\n13 5\r\n7 6"], "output": ["8"], "explanation": ""}]
null
AtC
66
066A
A
A - ringring
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
1 \leq a,b,c \leq 10000 a, b and c are integers.``` a b c ```
Print the minimum total price of two different bells.
[{"input": ["700 600 780"], "output": ["1300"], "explanation": "The minimum among these is 1300 yen."}, {"input": ["10000 10000 10000"], "output": ["20000"], "explanation": "Buying any two bells costs 20000 yen."}]
null
AtC
66
066B
B
B - ss
We will call a string that can be obtained by concatenating two equal strings an even string. For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
2 \leq |S| \leq 200 S is an even string consisting of lowercase English letters. There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S.``` S ```
Print the length of the longest even string that can be obtained.
[{"input": ["abaababaab"], "output": ["6"], "explanation": ""}, {"input": ["xxxx"], "output": ["2"], "explanation": ""}, {"input": ["abcabcabcabc"], "output": ["6"], "explanation": "The longest even string that can be obtained is abcabc, whose length is 6."}, {"input": ["akasakaakasakasakaakas"], "output": ["14"], "explanation": "The longest even string that can be obtained is akasakaakasaka, whose length is 14."}]
null
AtC
66
066C
C
C - pushpush
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: Find the sequence b obtained after these n operations.
1 \leq n \leq 2\times 10^5 0 \leq a_i \leq 10^9 n and a_i are integers.``` n a_1 a_2 ... a_n ```
Print n integers in a line with spaces in between. The i-th integer should be b_i.
[{"input": ["4\r\n1 2 3 4"], "output": ["4 2 1 3"], "explanation": "Thus, the answer is 4 2 1 3."}, {"input": ["3\r\n1 2 3"], "output": ["3 1 2"], "explanation": "As shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2."}, {"input": ["1\r\n1000000000"], "output": ["1000000000"], "explanation": ""}, {"input": ["6\r\n0 6 7 6 7 0"], "output": ["0 6 6 0 7 7"], "explanation": ""}]
null
AtC
66
066D
D
D - 11
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
1 \leq n \leq 10^5 1 \leq a_i \leq n Each of the integers 1,...,n appears in the sequence. n and a_i are integers.``` n a_1 a_2 ... a_{n+1} ```
Print n+1 lines. The k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 10^9+7.
[{"input": ["3\r\n1 2 1 3"], "output": ["3\r\n5\r\n4\r\n1"], "explanation": "There are three subsequences with length 1: 1 and 2 and 3.\nThere are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.\nThere are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.\nThere is one subsequence with length 4: 1,2,1,3."}, {"input": ["1\r\n1 1"], "output": ["1\r\n1"], "explanation": "There is one subsequence with length 1: 1.\nThere is one subsequence with length 2: 1,1."}, {"input": ["32\r\n29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9"], "output": ["32\r\n525\r\n5453\r\n40919\r\n237336\r\n1107568\r\n4272048\r\n13884156\r\n38567100\r\n92561040\r\n193536720\r\n354817320\r\n573166440\r\n818809200\r\n37158313\r\n166803103\r\n166803103\r\n37158313\r\n818809200\r\n573166440\r\n354817320\r\n193536720\r\n92561040\r\n38567100\r\n13884156\r\n4272048\r\n1107568\r\n237336\r\n40920\r\n5456\r\n528\r\n33\r\n1"], "explanation": "Be sure to print the numbers modulo 10^9+7."}]
null
AtC
67
067A
A
A - Sharing Cookies
Snuke is giving cookies to his three goats. He 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). Your 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.
1 \leq A,B \leq 100 Both A and B are integers.``` A B ```
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.
[{"input": ["4 5"], "output": ["Possible"], "explanation": "If Snuke gives nine cookies, each of the three goats can have three cookies."}, {"input": ["1 1"], "output": ["Impossible"], "explanation": "Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them."}]
null
AtC
67
067B
B
B - Snake Toy
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
1 \leq K \leq N \leq 50 1 \leq l_i \leq 50 l_i is an integer.``` N K l_1 l_2 l_3 ... l_{N} ```
Print the answer.
[{"input": ["5 3\r\n1 2 3 4 5"], "output": ["12"], "explanation": "You can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length."}, {"input": ["15 14\r\n50 26 27 21 41 7 42 35 7 5 5 36 39 1 45"], "output": ["386"], "explanation": ""}]
null
AtC
67
067C
C
C - Splitting Pile
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
2 \leq N \leq 2 \times 10^5 -10^{9} \leq a_i \leq 10^{9} a_i is an integer.``` N a_1 a_2 ... a_{N} ```
Print the answer.
[{"input": ["6\r\n1 2 3 4 5 6"], "output": ["1"], "explanation": "If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value."}, {"input": ["2\r\n10 -10"], "output": ["20"], "explanation": "Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
null
AtC
67
067D
D
D - Fennec VS. Snuke
Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: Fennec: selects an uncolored cell that is adjacent to a black cell, and paints it black. Snuke: selects an uncolored cell that is adjacent to a white cell, and paints it white. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
2 \leq N \leq 10^5 1 \leq a_i, b_i \leq N The given graph is a tree.``` N a_1 b_1 : a_{N-1} b_{N-1} ```
If Fennec wins, print Fennec; if Snuke wins, print Snuke.
[{"input": ["7\r\n3 6\r\n1 2\r\n3 1\r\n7 4\r\n5 7\r\n1 4"], "output": ["Fennec"], "explanation": "For example, if Fennec first paints Cell 2 black, she will win regardless of Snuke's moves."}, {"input": ["4\r\n1 4\r\n4 2\r\n2 3"], "output": ["Snuke"], "explanation": ""}]
null
AtC
68
068A
A
A - ABCxxx
This contest, AtCoder Beginner Contest, is abbreviated as ABC. When 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. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
100 ≤ N ≤ 999``` N ```
Print the abbreviation for the N-th round of ABC.
[{"input": ["100"], "output": ["ABC100"], "explanation": "The 100th round of ABC is ABC100."}, {"input": ["425"], "output": ["ABC425"], "explanation": ""}, {"input": ["999"], "output": ["ABC999"], "explanation": ""}]
null
AtC
68
068B
B
B - Break Number
Takahashi loves numbers divisible by 2. You 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. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, 6 can be divided by 2 once: 6 -> 3. 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. 3 can be divided by 2 zero times.
1 ≤ N ≤ 100``` N ```
Print the answer.
[{"input": ["7"], "output": ["4"], "explanation": "4 can be divided by 2 twice, which is the most number of times among 1, 2, ..., 7."}, {"input": ["32"], "output": ["32"], "explanation": ""}, {"input": ["1"], "output": ["1"], "explanation": ""}, {"input": ["100"], "output": ["64"], "explanation": ""}]
null
AtC
68
068C
C
C - Cat Snuke and a Voyage
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, 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. Help him.
3 ≤ N ≤ 200 000 1 ≤ M ≤ 200 000 1 ≤ a_i < b_i ≤ N (a_i, b_i) \neq (1, N) If i \neq j, (a_i, b_i) \neq (a_j, b_j).``` N M a_1 b_1 a_2 b_2 : a_M b_M ```
If it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.
[{"input": ["3 2\r\n1 2\r\n2 3"], "output": ["POSSIBLE"], "explanation": ""}, {"input": ["4 3\r\n1 2\r\n2 3\r\n3 4"], "output": ["IMPOSSIBLE"], "explanation": "You have to use three boat services to get to Island 4."}, {"input": ["100000 1\r\n1 99999"], "output": ["IMPOSSIBLE"], "explanation": ""}, {"input": ["5 5\r\n1 3\r\n4 5\r\n2 3\r\n2 4\r\n1 4"], "output": ["POSSIBLE"], "explanation": "You can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5."}]
null
AtC
68
068D
D
D - Decrease (Contestant ver.)
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1. It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given an integer K. Find an integer sequence a_i such that the number of times we will perform the above operation is exactly K. It can be shown that there is always such a sequence under the constraints on input and output in this problem.
0 ≤ K ≤ 50 \times 10^{16}``` K ```
Print a solution in the following format: ``` N a_1 a_2 ... a_N ``` Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.
[{"input": ["0"], "output": ["4\r\n3 3 3 3"], "explanation": ""}, {"input": ["1"], "output": ["3\r\n1 0 3"], "explanation": ""}, {"input": ["2"], "output": ["2\r\n2 2"], "explanation": "The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1]."}, {"input": ["3"], "output": ["7\r\n27 0 0 0 0 0 0"], "explanation": ""}, {"input": ["1234567894848"], "output": ["10\r\n1000 193 256 777 0 1 1192 1234567891011 48 425"], "explanation": ""}]
null
AtC
69
069A
A
A - K-City
In 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?
2 ≤ n, m ≤ 100``` n m ```
Print the number of blocks in K-city.
[{"input": ["3 4"], "output": ["6"], "explanation": "There are six blocks, as shown below:"}, {"input": ["2 2"], "output": ["1"], "explanation": "There are one block, as shown below:"}]
null
AtC
69
069B
B
B - i18n
The word internationalization is sometimes abbreviated to i18n. This 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. Abbreviate s in the same way.
3 ≤ |s| ≤ 100 (|s| denotes the length of s.) s consists of lowercase English letters.``` s ```
Print the abbreviation of s.
[{"input": ["internationalization"], "output": ["i18n"], "explanation": ""}, {"input": ["smiles"], "output": ["s4s"], "explanation": ""}, {"input": ["xyz"], "output": ["x1z"], "explanation": ""}]
null
AtC
69
069C
C
C - 4-adjacent
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
2 ≤ N ≤ 10^5 a_i is an integer. 1 ≤ a_i ≤ 10^9``` N a_1 a_2 ... a_N ```
If Snuke can achieve his objective, print Yes; otherwise, print No.
[{"input": ["3\r\n1 10 100"], "output": ["Yes"], "explanation": "One solution is (1, 100, 10)."}, {"input": ["4\r\n1 2 3 4"], "output": ["No"], "explanation": "It is impossible to permute a so that the condition is satisfied."}, {"input": ["3\r\n1 4 1"], "output": ["Yes"], "explanation": "The condition is already satisfied initially."}, {"input": ["2\r\n1 1"], "output": ["No"], "explanation": ""}, {"input": ["6\r\n2 7 1 8 2 8"], "output": ["Yes"], "explanation": ""}]
null
AtC
69
069D
D
D - Grid Coloring
We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 1, 2, ..., N. Here, the following conditions should be satisfied: For each i (1 ≤ i ≤ N), there are exactly a_i squares painted in Color i. Here, a_1 + a_2 + ... + a_N = H W. For each i (1 ≤ i ≤ N), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i. Find a way to paint the squares so that the conditions are satisfied. It can be shown that a solution always exists.
1 ≤ H, W ≤ 100 1 ≤ N ≤ H W a_i ≥ 1 a_1 + a_2 + ... + a_N = H W``` H W N a_1 a_2 ... a_N ```
Print one way to paint the squares that satisfies the conditions. Output in the following format: ``` c_{1 1} ... c_{1 W} : c_{H 1} ... c_{H W} ``` Here, c_{i j} is the color of the square at the i-th row from the top and j-th column from the left.
[{"input": ["2 2\r\n3\r\n2 1 1"], "output": ["1 1\r\n2 3"], "explanation": "Below is an example of an invalid solution:\nThis is because the squares painted in Color 1 are not 4-connected."}, {"input": ["3 5\r\n5\r\n1 2 3 4 5"], "output": ["1 4 4 4 3\r\n2 5 4 5 3\r\n2 5 5 5 3"], "explanation": ""}, {"input": ["1 1\r\n1\r\n1"], "output": ["1"], "explanation": ""}]
null
AtC
70
070A
A
A - Palindromic Number
You are given a three-digit positive integer N. Determine whether N is a palindromic number. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
100≤N≤999 N is an integer.``` N ```
If N is a palindromic number, print Yes; otherwise, print No.
[{"input": ["575"], "output": ["Yes"], "explanation": "N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes."}, {"input": ["123"], "output": ["No"], "explanation": "N=123 becomes 321 when read backward, so it is not a palindromic number. You should print No."}, {"input": ["812"], "output": ["No"], "explanation": ""}]
null
AtC
70
070B
B
B - Two Switches
Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons?
0≤A<B≤100 0≤C<D≤100 All input values are integers.``` A B C D ```
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.
[{"input": ["0 75 25 100"], "output": ["50"], "explanation": "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. Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up. Therefore, 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."}, {"input": ["0 33 66 99"], "output": ["0"], "explanation": "Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds."}, {"input": ["10 90 20 80"], "output": ["60"], "explanation": ""}]
null
AtC
70
070C
C
C - Multiple Clocks
We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again?
1≤N≤100 1≤T_i≤10^{18} All input values are integers. The correct answer is at most 10^{18} seconds.``` N T_1 : T_N ```
Print the number of seconds after which the hand of every clock point directly upward again.
[{"input": ["2\r\n2\r\n3"], "output": ["6"], "explanation": "We have two clocks. The time when the hand of each clock points upward is as follows:\nTherefore, it takes 6 seconds until the hands of both clocks point directly upward."}, {"input": ["5\r\n2\r\n5\r\n10\r\n1000000000000000000\r\n1000000000000000000"], "output": ["1000000000000000000"], "explanation": ""}]
null
AtC
70
070D
D
D - Transit Tree Path
You are given a tree with N vertices. Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i. You are also given Q queries and an integer K. In the j-th query (1≤j≤Q): find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
3≤N≤10^5 1≤a_i,b_i≤N (1≤i≤N-1) 1≤c_i≤10^9 (1≤i≤N-1) The given graph is a tree. 1≤Q≤10^5 1≤K≤N 1≤x_j,y_j≤N (1≤j≤Q) x_j≠y_j (1≤j≤Q) x_j≠K,y_j≠K (1≤j≤Q)``` N a_1 b_1 c_1 : a_{N-1} b_{N-1} c_{N-1} Q K x_1 y_1 : x_{Q} y_{Q} ```
Print the responses to the queries in Q lines. In the j-th line j(1≤j≤Q), print the response to the j-th query.
[{"input": ["5\r\n1 2 1\r\n1 3 1\r\n2 4 1\r\n3 5 1\r\n3 1\r\n2 4\r\n2 3\r\n4 5"], "output": ["3\r\n2\r\n4"], "explanation": "The shortest paths for the three queries are as follows:"}, {"input": ["7\r\n1 2 1\r\n1 3 3\r\n1 4 5\r\n1 5 7\r\n1 6 9\r\n1 7 11\r\n3 2\r\n1 3\r\n4 5\r\n6 7"], "output": ["5\r\n14\r\n22"], "explanation": "The path for each query must pass Vertex K=2."}, {"input": ["10\r\n1 2 1000000000\r\n2 3 1000000000\r\n3 4 1000000000\r\n4 5 1000000000\r\n5 6 1000000000\r\n6 7 1000000000\r\n7 8 1000000000\r\n8 9 1000000000\r\n9 10 1000000000\r\n1 1\r\n9 10"], "output": ["17000000000"], "explanation": ""}]
null
AtC
71
071A
A
A - Meal Delivery
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
1 \leq x \leq 1000 1 \leq a \leq 1000 1 \leq b \leq 1000 x, a and b are pairwise distinct. The distances between Snuke's residence and stores A and B are different.``` x a b ```
If store A is closer, print A; if store B is closer, print B.
[{"input": ["5 2 7"], "output": ["B"], "explanation": "The distances between Snuke's residence and stores A and B are 3 and 2, respectively. Since store B is closer, print B."}, {"input": ["1 999 1000"], "output": ["A"], "explanation": ""}]
null
AtC
71
071B
B
B - Not Found
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead.
1 \leq |S| \leq 10^5 (|S| is the length of string S.) S consists of lowercase English letters.``` S ```
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead.
[{"input": ["atcoderregularcontest"], "output": ["b"], "explanation": "The string atcoderregularcontest contains a, but does not contain b."}, {"input": ["abcdefghijklmnopqrstuvwxyz"], "output": ["None"], "explanation": "This string contains every lowercase English letter."}, {"input": ["fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg"], "output": ["d"], "explanation": ""}]
null
AtC
71
071C
C
C - Make a Rectangle
We have N sticks with negligible thickness. The length of the i-th stick is A_i. Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
4 \leq N \leq 10^5 1 \leq A_i \leq 10^9 A_i is an integer.``` N A_1 A_2 ... A_N ```
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
[{"input": ["6\r\n3 1 2 4 2 1"], "output": ["2"], "explanation": "1 \\times 2 rectangle can be formed."}, {"input": ["4\r\n1 2 3 4"], "output": ["0"], "explanation": "No rectangle can be formed."}, {"input": ["10\r\n3 3 3 3 4 4 4 5 5 5"], "output": ["20"], "explanation": ""}]
null
AtC
71
071D
D
D - Coloring Dominoes
We have a board with a 2 \times N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1 square. Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors. Find the number of such ways to paint the dominoes, modulo 1000000007. The arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner: Each domino is represented by a different English letter (lowercase or uppercase). The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.
1 \leq N \leq 52 |S_1| = |S_2| = N S_1 and S_2 consist of lowercase and uppercase English letters. S_1 and S_2 represent a valid arrangement of dominoes.``` N S_1 S_2 ```
Print the number of such ways to paint the dominoes, modulo 1000000007.
[{"input": ["3\r\naab\r\nccb"], "output": ["6"], "explanation": "There are six ways as shown below:\n"}, {"input": ["1\r\nZ\r\nZ"], "output": ["3"], "explanation": "Note that it is not always necessary to use all the colors."}, {"input": ["52\r\nRvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\r\nRLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn"], "output": ["958681902"], "explanation": ""}]
null
AtC
72
072A
A
A - Sandglass2
We 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. How many grams of sand will the upper bulb contains after t seconds?
1≤X≤10^9 1≤t≤10^9 X and t are integers.``` X t ```
Print the number of sand in the upper bulb after t second.
[{"input": ["100 17"], "output": ["83"], "explanation": "17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams."}, {"input": ["48 58"], "output": ["0"], "explanation": "All 48 grams of sand will be gone, resulting in 0 grams."}, {"input": ["1000000000 1000000000"], "output": ["0"], "explanation": ""}]
null
AtC
72
072B
B
B - OddString
You 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.
Each character in s is a lowercase English letter. 1≤|s|≤10^5``` s ```
Print the string obtained by concatenating all the characters in the odd-numbered positions.
[{"input": ["atcoder"], "output": ["acdr"], "explanation": "Extract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr."}, {"input": ["aaaa"], "output": ["aa"], "explanation": ""}, {"input": ["z"], "output": ["z"], "explanation": ""}, {"input": ["fukuokayamaguchi"], "output": ["fkoaaauh"], "explanation": ""}]
null
AtC
72
072C
C
C - Together
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
1≤N≤10^5 0≤a_i<10^5 (1≤i≤N) a_i is an integer.``` N a_1 a_2 .. a_N ```
Print the maximum possible number of i such that a_i=X.
[{"input": ["7\r\n3 1 4 1 5 9 2"], "output": ["4"], "explanation": "For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count."}, {"input": ["10\r\n0 1 2 3 4 5 6 7 8 9"], "output": ["3"], "explanation": ""}, {"input": ["1\r\n99999"], "output": ["1"], "explanation": ""}]
null
AtC
72
072D
D
D - Derangement
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two adjacent elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
2≤N≤10^5 p_1,p_2,..,p_N is a permutation of 1,2,..,N.``` N p_1 p_2 .. p_N ```
Print the minimum required number of operations
[{"input": ["5\r\n1 4 3 5 2"], "output": ["2"], "explanation": "Swap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the condition. This is the minimum possible number, so the answer is 2."}, {"input": ["2\r\n1 2"], "output": ["1"], "explanation": "Swapping 1 and 2 satisfies the condition."}, {"input": ["2\r\n2 1"], "output": ["0"], "explanation": "The condition is already satisfied initially."}, {"input": ["9\r\n1 2 4 9 5 8 7 3 6"], "output": ["3"], "explanation": ""}]
null
AtC
73
073A
A
A - September 9
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
10≤N≤99``` N ```
If 9 is contained in the decimal notation of N, print Yes; if not, print No.
[{"input": ["29"], "output": ["Yes"], "explanation": "The one's digit of 29 is 9."}, {"input": ["72"], "output": ["No"], "explanation": "72 does not contain 9."}, {"input": ["91"], "output": ["Yes"], "explanation": ""}]
null
AtC
73
073B
B
B - Theater
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now?
1≤N≤1000 1≤l_i≤r_i≤100000 No seat is occupied by more than one person. All input values are integers.``` N l_1 r_1 : l_N r_N ```
Print the number of people sitting at the theater.
[{"input": ["1\r\n24 30"], "output": ["7"], "explanation": "There are 7 people, sitting at Seat 24,25,26,27,28,29 and 30."}, {"input": ["2\r\n6 8\r\n3 3"], "output": ["4"], "explanation": ""}]
null
AtC
73
073C
C
C - Write and Erase
You are playing the following game with Joisino. Initially, you have a blank sheet of paper. Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. Then, you are asked a question: How many numbers are written on the sheet now? The 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?
1≤N≤100000 1≤A_i≤1000000000(=10^9) All input values are integers.``` N A_1 : A_N ```
Print how many numbers will be written on the sheet at the end of the game.
[{"input": ["3\r\n6\r\n2\r\n6"], "output": ["1"], "explanation": "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."}, {"input": ["4\r\n2\r\n5\r\n5\r\n2"], "output": ["0"], "explanation": "It is possible that no number is written on the sheet in the end."}, {"input": ["6\r\n12\r\n22\r\n16\r\n22\r\n18\r\n12"], "output": ["2"], "explanation": ""}]
null
AtC
73
073D
D
D - joisino's travel
There are N towns in the State of Atcoder, connected by M bidirectional roads. The i-th road connects Town A_i and B_i and has a length of C_i. Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order). She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road. If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?
2≤N≤200 1≤M≤N×(N-1)/2 2≤R≤min(8,N) (min(8,N) is the smaller of 8 and N.) r_i≠r_j (i≠j) 1≤A_i,B_i≤N, A_i≠B_i (A_i,B_i)≠(A_j,B_j),(A_i,B_i)≠(B_j,A_j) (i≠j) 1≤C_i≤100000 Every town can be reached from every town by road. All input values are integers.``` N M R r_1 ... r_R A_1 B_1 C_1 : A_M B_M C_M ```
Print the distance traveled by road if Joisino visits the towns in the order that minimizes it.
[{"input": ["3 3 3\r\n1 2 3\r\n1 2 1\r\n2 3 1\r\n3 1 4"], "output": ["2"], "explanation": "For example, if she visits the towns in the order of 1, 2, 3, the distance traveled will be 2, which is the minimum possible."}, {"input": ["3 3 2\r\n1 3\r\n2 3 2\r\n1 3 6\r\n1 2 2"], "output": ["4"], "explanation": "The shortest distance between Towns 1 and 3 is 4. Thus, whether she visits Town 1 or 3 first, the distance traveled will be 4."}, {"input": ["4 6 3\r\n2 3 4\r\n1 2 4\r\n2 3 3\r\n4 3 1\r\n1 4 1\r\n4 2 2\r\n3 1 6"], "output": ["3"], "explanation": ""}]
null
AtC
74
074A
A
A - Bichrome Cells
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
1 \leq N \leq 100 0 \leq A \leq N^2``` N A ```
Print the number of squares that will be painted black.
[{"input": ["3\r\n4"], "output": ["5"], "explanation": "There are nine squares in a 3 \\times 3 square grid. Four of them will be painted white, so the remaining five squares will be painted black."}, {"input": ["19\r\n100"], "output": ["261"], "explanation": ""}, {"input": ["10\r\n0"], "output": ["100"], "explanation": "As zero squares will be painted white, all the squares will be painted black."}]
null
AtC
74
074B
B
B - Collecting Balls (Easy Version)
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
1 \leq N \leq 100 1 \leq K \leq 100 0 < x_i < K All input values are integers.``` N K x_1 x_2 ... x_N ```
Print the minimum possible total distance covered by robots.
[{"input": ["1\r\n10\r\n2"], "output": ["4"], "explanation": "There are just one ball, one type-A robot and one type-B robot.\nIf the type-A robot is used to collect the ball, the distance from the robot to the ball is 2, and the distance from the ball to the original position of the robot is also 2, for a total distance of 4.\nSimilarly, if the type-B robot is used, the total distance covered will be 16.\nThus, the total distance covered will be minimized when the type-A robot is used. The output should be 4."}, {"input": ["2\r\n9\r\n3 6"], "output": ["12"], "explanation": "The total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot."}, {"input": ["5\r\n20\r\n11 12 9 17 12"], "output": ["74"], "explanation": ""}]
null
AtC
74
074C
C
C - Sugar Water
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. Operation 1: Pour 100A grams of water into the beaker. Operation 2: Pour 100B grams of water into the beaker. Operation 3: Put C grams of sugar into the beaker. Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
1 \leq A < B \leq 30 1 \leq C < D \leq 30 1 \leq E \leq 100 100A \leq F \leq 3 000 A, B, C, D, E and F are all integers.``` A B C D E F ```
Print two integers separated by a space. The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.
[{"input": ["1 2 10 20 15 200"], "output": ["110 10"], "explanation": "In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.\nWe can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once. It is not possible to make sugar water with higher density. For example, the following sequences of operations are infeasible:"}, {"input": ["1 2 1 2 100 1000"], "output": ["200 100"], "explanation": "There are other acceptable outputs, such as:\nHowever, the output below is not acceptable:\nThis is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible."}, {"input": ["17 19 22 26 55 2802"], "output": ["2634 934"], "explanation": ""}]
null
AtC
74
074D
D
D - Restoring Road Network
In Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads. The following are known about the road network: People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary. Different roads may have had different lengths, but all the lengths were positive integers. Snuke the archeologist found a table with N rows and N columns, A, in the ruin of Takahashi Kingdom. He thought that it represented the shortest distances between the cities along the roads in the kingdom. Determine whether there exists a road network such that for each u and v, the integer A_{u, v} at the u-th row and v-th column of A is equal to the length of the shortest path from City u to City v. If such a network exist, find the shortest possible total length of the roads.
1 \leq N \leq 300 If i ≠ j, 1 \leq A_{i, j} = A_{j, i} \leq 10^9. A_{i, i} = 0``` N A_{1, 1} A_{1, 2} ... A_{1, N} A_{2, 1} A_{2, 2} ... A_{2, N} ... A_{N, 1} A_{N, 2} ... A_{N, N} ```
If there exists no network that satisfies the condition, print -1. If it exists, print the shortest possible total length of the roads.
[{"input": ["3\r\n0 1 3\r\n1 0 2\r\n3 2 0"], "output": ["3"], "explanation": "The network below satisfies the condition:"}, {"input": ["3\r\n0 1 3\r\n1 0 1\r\n3 1 0"], "output": ["-1"], "explanation": "As there is a path of length 1 from City 1 to City 2 and City 2 to City 3, there is a path of length 2 from City 1 to City 3. However, according to the table, the shortest distance between City 1 and City 3 must be 3.\nThus, we conclude that there exists no network that satisfies the condition."}, {"input": ["5\r\n0 21 18 11 28\r\n21 0 13 10 26\r\n18 13 0 23 13\r\n11 10 23 0 17\r\n28 26 13 17 0"], "output": ["82"], "explanation": ""}, {"input": ["3\r\n0 1000000000 1000000000\r\n1000000000 0 1000000000\r\n1000000000 1000000000 0"], "output": ["3000000000"], "explanation": ""}]
null
AtC
75
075A
A
A - One out of Three
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
-100 \leq A,B,C \leq 100 A, B and C are integers. The input satisfies the condition in the statement.``` A B C ```
Among A, B and C, print the integer that is different from the rest.
[{"input": ["5 7 5"], "output": ["7"], "explanation": "This is the same case as the one in the statement."}, {"input": ["1 1 7"], "output": ["7"], "explanation": "In this case, C is the one we seek."}, {"input": ["-100 100 100"], "output": ["-100"], "explanation": ""}]
null
AtC
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
6