diff --git "a/query.jsonl" "b/query.jsonl" new file mode 100644--- /dev/null +++ "b/query.jsonl" @@ -0,0 +1,348 @@ +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

We have a 2 \\times N grid. We will denote the square at the i-th row and j-th column (1 \\leq i \\leq 2, 1 \\leq j \\leq N) as (i, j).

\n

You are initially in the top-left square, (1, 1).\nYou will travel to the bottom-right square, (2, N), by repeatedly moving right or down.

\n

The square (i, j) contains A_{i, j} candies.\nYou will collect all the candies you visit during the travel.\nThe top-left and bottom-right squares also contain candies, and you will also collect them.

\n

At most how many candies can you collect when you choose the best way to travel?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
  • 1 \\leq A_{i, j} \\leq 100 (1 \\leq i \\leq 2, 1 \\leq j \\leq N)
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_{1, 1} A_{1, 2} ... A_{1, N}\nA_{2, 1} A_{2, 2} ... A_{2, N}\n
\n
\n
\n
\n
\n

Output

Print the maximum number of candies that can be collected.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n3 2 2 4 1\n1 2 2 2 1\n
\n
\n
\n
\n
\n

Sample Output 1

14\n
\n

The number of collected candies will be maximized when you:

\n
    \n
  • move right three times, then move down once, then move right once.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

4\n1 1 1 1\n1 1 1 1\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n

You will always collect the same number of candies, regardless of how you travel.

\n
\n
\n
\n
\n
\n

Sample Input 3

7\n3 3 4 5 4 5 3\n5 3 4 4 2 3 2\n
\n
\n
\n
\n
\n

Sample Output 3

29\n
\n
\n
\n
\n
\n
\n

Sample Input 4

1\n2\n3\n
\n
\n
\n
\n
\n

Sample Output 4

5\n
\n
\n
", "id": "codenet-bug-p03449", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Takahashi is distributing N balls to K persons.

\n

If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq K \\leq N \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\n
\n
\n
\n
\n
\n

Output

Print the maximum possible difference in the number of balls received.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 2\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

The only way to distribute three balls to two persons so that each of them receives at least one ball is to give one ball to one person and give two balls to the other person.

\n

Thus, the maximum possible difference in the number of balls received is 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 1\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

We have no choice but to give three balls to the only person, in which case the difference in the number of balls received is 0.

\n
\n
\n
\n
\n
\n

Sample Input 3

8 5\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n

For example, if we give 1, 4, 1, 1, 1 balls to the five persons, the number of balls received between the person with the most balls and the person with the fewest balls would be 3, which is the maximum result.

\n
\n
", "id": "codenet-bug-p03005", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

\n

We have A balls with the string S written on each of them and B balls with the string T written on each of them.
\nFrom these balls, Takahashi chooses one with the string U written on it and throws it away.
\nFind the number of balls with the string S and balls with the string T that we have now.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • S, T, and U are strings consisting of lowercase English letters.
  • \n
  • The lengths of S and T are each between 1 and 10 (inclusive).
  • \n
  • S \\not= T
  • \n
  • S=U or T=U.
  • \n
  • 1 \\leq A,B \\leq 10
  • \n
  • A and B are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
S T\nA B\nU\n
\n
\n
\n
\n
\n

Output

\n

Print the answer, with space in between.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

red blue\n3 4\nred\n
\n
\n
\n
\n
\n

Sample Output 1

2 4\n
\n

Takahashi chose a ball with red written on it and threw it away.\nNow we have two balls with the string S and four balls with the string T.

\n
\n
\n
\n
\n
\n

Sample Input 2

red blue\n5 5\nblue\n
\n
\n
\n
\n
\n

Sample Output 2

5 4\n
\n

Takahashi chose a ball with blue written on it and threw it away.\nNow we have five balls with the string S and four balls with the string T.

\n
\n
", "id": "codenet-bug-p02777", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 300 points

\n
\n
\n

Problem Statement

\n

We have a 3 \\times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.
\nAccording to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.
\nDetermine if he is correct.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • c_{i, j} \\ (1 \\leq i \\leq 3, 1 \\leq j \\leq 3) is an integer between 0 and 100 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
c_{1,1} c_{1,2} c_{1,3}\nc_{2,1} c_{2,2} c_{2,3}\nc_{3,1} c_{3,2} c_{3,3}\n
\n
\n
\n
\n
\n

Output

\n

If Takahashi's statement is correct, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 0 1\n2 1 2\n1 0 1\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

Takahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 2 2\n2 1 2\n2 2 2\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

Takahashi is incorrect in this case.

\n
\n
\n
\n
\n
\n

Sample Input 3

0 8 8\n0 8 8\n0 8 8\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 4

1 8 6\n2 9 7\n0 7 7\n
\n
\n
\n
\n
\n

Sample Output 4

No\n
\n
\n
", "id": "codenet-bug-p03435", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd format. For example, January 23, 2018 should be written as 2018/01/23.

\n

After finishing the document, she noticed that she had mistakenly wrote 2017 at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to 2018 and prints it.

\n
\n
\n
\n
\n

Constraints

    \n
  • S is a string of length 10.
  • \n
  • The first eight characters in S are 2017/01/.
  • \n
  • The last two characters in S are digits and represent an integer between 1 and 31 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Replace the first four characters in S with 2018 and print it.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2017/01/07\n
\n
\n
\n
\n
\n

Sample Output 1

2018/01/07\n
\n
\n
\n
\n
\n
\n

Sample Input 2

2017/01/31\n
\n
\n
\n
\n
\n

Sample Output 2

2018/01/31\n
\n
\n
", "id": "codenet-bug-p03469", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi has N days of summer vacation.

\n

His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.

\n

He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.

\n

What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?

\n

If Takahashi cannot finish all the assignments during the vacation, print -1 instead.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^6
  • \n
  • 1 \\leq M \\leq 10^4
  • \n
  • 1 \\leq A_i \\leq 10^4
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\nA_1 ... A_M\n
\n
\n
\n
\n
\n

Output

Print the maximum number of days Takahashi can hang out during the vacation, or -1.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

41 2\n5 6\n
\n
\n
\n
\n
\n

Sample Output 1

30\n
\n

For example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.

\n
\n
\n
\n
\n
\n

Sample Input 2

10 2\n5 6\n
\n
\n
\n
\n
\n

Sample Output 2

-1\n
\n

He cannot finish his assignments.

\n
\n
\n
\n
\n
\n

Sample Input 3

11 2\n5 6\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

He can finish his assignments, but he will have no time to hang out.

\n
\n
\n
\n
\n
\n

Sample Input 4

314 15\n9 26 5 35 8 9 79 3 23 8 46 2 6 43 3\n
\n
\n
\n
\n
\n

Sample Output 4

9\n
\n
\n
", "id": "codenet-bug-p02706", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Given is a positive integer N.\nHow many tuples (A,B,C) of positive integers satisfy A \\times B + C = N?

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 10^6
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

There are 3 tuples of integers that satisfy A \\times B + C = 3: (A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 1).

\n
\n
\n
\n
\n
\n

Sample Input 2

100\n
\n
\n
\n
\n
\n

Sample Output 2

473\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1000000\n
\n
\n
\n
\n
\n

Sample Output 3

13969985\n
\n
\n
", "id": "codenet-bug-p02548", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

For an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.

\n

Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.

\n

Find the maximum possible value of M_1 + M_2 + \\cdots + M_N.

\n
\n
\n
\n
\n

Constraints

    \n
  • N is an integer satisfying 1 \\leq N \\leq 10^9.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the maximum possible value of M_1 + M_2 + \\cdots + M_N.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

When the permutation \\{P_1, P_2\\} = \\{2, 1\\} is chosen, M_1 + M_2 = 1 + 0 = 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

13\n
\n
\n
\n
\n
\n

Sample Output 2

78\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p02924", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Katsusando loves omelette rice.

\n

Besides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.

\n

To prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like these foods or not.

\n

The i-th person answered that he/she only likes the A_{i1}-th, A_{i2}-th, ..., A_{iK_i}-th food.

\n

Find the number of the foods liked by all the N people.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N, M \\leq 30
  • \n
  • 1 \\leq K_i \\leq M
  • \n
  • 1 \\leq A_{ij} \\leq M
  • \n
  • For each i (1 \\leq i \\leq N), A_{i1}, A_{i2}, ..., A_{iK_i} are distinct.
  • \n
\n
\n
\n
\n
\n

Constraints

Input is given from Standard Input in the following format:

\n
N M\nK_1 A_{11} A_{12} ... A_{1K_1}\nK_2 A_{21} A_{22} ... A_{2K_2}\n:\nK_N A_{N1} A_{N2} ... A_{NK_N}\n
\n
\n
\n
\n
\n

Output

Print the number of the foods liked by all the N people.

\n
\n
\n
\n
\n
\n

Sample Input 1

3 4\n2 1 3\n3 1 2 3\n2 3 2\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

As only the third food is liked by all the three people, 1 should be printed.

\n
\n
\n
\n
\n
\n

Sample Input 2

5 5\n4 2 3 4 5\n4 1 3 4 5\n4 1 2 4 5\n4 1 2 3 5\n4 1 2 3 4\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

Katsusando's hypothesis turned out to be wrong.

\n
\n
\n
\n
\n
\n

Sample Input 3

1 30\n3 5 10 30\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n
\n
", "id": "codenet-bug-p03126", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

N persons are standing in a row. The height of the i-th person from the front is A_i.

\n

We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:

\n

Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.

\n

Find the minimum total height of the stools needed to meet this goal.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 2\\times 10^5
  • \n
  • 1 \\leq A_i \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 \\ldots A_N\n
\n
\n
\n
\n
\n

Output

Print the minimum total height of the stools needed to meet the goal.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n2 1 5 4 3\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

If the persons stand on stools of heights 0, 1, 0, 1, and 2, respectively, their heights will be 2, 2, 5, 5, and 5, satisfying the condition.

\n

We cannot meet the goal with a smaller total height of the stools.

\n
\n
\n
\n
\n
\n

Sample Input 2

5\n3 3 3 3 3\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

Giving a stool of height 0 to everyone will work.

\n
\n
", "id": "codenet-bug-p02578", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N squares arranged in a row from left to right.

\n

The height of the i-th square from the left is H_i.

\n

You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.

\n

Find the maximum number of times you can move.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 1 \\leq H_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nH_1 H_2 ... H_N\n
\n
\n
\n
\n
\n

Output

Print the maximum number of times you can move.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n10 4 8 7 3\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

By landing on the third square from the left, you can move to the right twice.

\n
\n
\n
\n
\n
\n

Sample Input 2

7\n4 4 5 6 6 5 5\n
\n
\n
\n
\n
\n

Sample Output 2

3\n
\n

By landing on the fourth square from the left, you can move to the right three times.

\n
\n
\n
\n
\n
\n

Sample Input 3

4\n1 2 3 4\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p02923", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.

\n

You can use the following theorem:

\n

Theorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 3 \\leq N \\leq 10
  • \n
  • 1 \\leq L_i \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nL_1 L_2 ... L_N\n
\n
\n
\n
\n
\n

Output

If an N-sided polygon satisfying the condition can be drawn, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n3 8 5 1\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

Since 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can be drawn on a plane.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n3 8 4 1\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

Since 8 \\geq 8 = 3 + 4 + 1, it follows from the theorem that such a polygon cannot be drawn on a plane.

\n
\n
\n
\n
\n
\n

Sample Input 3

10\n1 8 10 5 8 12 34 100 11 3\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
", "id": "codenet-bug-p03136", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You have decided to write a book introducing good restaurants.\nThere are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.\nNo two restaurants have the same score.

\n

You want to introduce the restaurants in the following order:

\n
    \n
  • The restaurants are arranged in lexicographical order of the names of their cities.
  • \n
  • If there are multiple restaurants in the same city, they are arranged in descending order of score.
  • \n
\n

Print the identification numbers of the restaurants in the order they are introduced in the book.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ N ≤ 100
  • \n
  • S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
  • \n
  • 0 ≤ P_i ≤ 100
  • \n
  • P_i is an integer.
  • \n
  • P_i ≠ P_j (1 ≤ i < j ≤ N)
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS_1 P_1\n:\nS_N P_N\n
\n
\n
\n
\n
\n

Output

Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n
\n
\n
\n
\n
\n

Sample Output 1

3\n4\n6\n1\n5\n2\n
\n

The lexicographical order of the names of the three cities is kazan < khabarovsk < moscow. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2.

\n
\n
\n
\n
\n
\n

Sample Input 2

10\nyakutsk 10\nyakutsk 20\nyakutsk 30\nyakutsk 40\nyakutsk 50\nyakutsk 60\nyakutsk 70\nyakutsk 80\nyakutsk 90\nyakutsk 100\n
\n
\n
\n
\n
\n

Sample Output 2

10\n9\n8\n7\n6\n5\n4\n3\n2\n1\n
\n
\n
", "id": "codenet-bug-p03030", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N candles placed on a number line.\nThe i-th candle from the left is placed on coordinate x_i.\nHere, x_1 < x_2 < ... < x_N holds.

\n

Initially, no candles are burning.\nSnuke decides to light K of the N candles.

\n

Now, he is at coordinate 0.\nHe can move left and right along the line with speed 1.\nHe can also light a candle when he is at the same position as the candle, in negligible time.

\n

Find the minimum time required to light K candles.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 1 \\leq K \\leq N
  • \n
  • x_i is an integer.
  • \n
  • |x_i| \\leq 10^8
  • \n
  • x_1 < x_2 < ... < x_N
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\nx_1 x_2 ... x_N\n
\n
\n
\n
\n
\n

Output

Print the minimum time required to light K candles.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 3\n-30 -10 10 20 50\n
\n
\n
\n
\n
\n

Sample Output 1

40\n
\n

He should move and light candles as follows:

\n
    \n
  • Move from coordinate 0 to -10.
  • \n
  • Light the second candle from the left.
  • \n
  • Move from coordinate -10 to 10.
  • \n
  • Light the third candle from the left.
  • \n
  • Move from coordinate 10 to 20.
  • \n
  • Light the fourth candle from the left.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

3 2\n10 20 30\n
\n
\n
\n
\n
\n

Sample Output 2

20\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1 1\n0\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
    \n
  • There may be a candle placed at coordinate 0.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 4

8 5\n-9 -7 -4 -3 1 2 3 4\n
\n
\n
\n
\n
\n

Sample Output 4

10\n
\n
\n
", "id": "codenet-bug-p03274", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.\nThere are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.

\n

Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.\nNote that Obs. i is also good when no observatory can be reached from Obs. i using just one road.

\n

How many good observatories are there?

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 10^5
  • \n
  • 1 \\leq M \\leq 10^5
  • \n
  • 1 \\leq H_i \\leq 10^9
  • \n
  • 1 \\leq A_i,B_i \\leq N
  • \n
  • A_i \\neq B_i
  • \n
  • Multiple roads may connect the same pair of observatories.
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\nH_1 H_2 ... H_N\nA_1 B_1\nA_2 B_2\n:\nA_M B_M\n
\n
\n
\n
\n
\n

Output

Print the number of good observatories.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 3\n1 2 3 4\n1 3\n2 3\n2 4\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n
    \n
  • \n

    From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.

    \n
  • \n
  • \n

    From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.

    \n
  • \n
  • \n

    From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.

    \n
  • \n
  • \n

    From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.

    \n
  • \n
\n

Thus, the good observatories are Obs. 3 and 4, so there are two good observatories.

\n
\n
\n
\n
\n
\n

Sample Input 2

6 5\n8 6 9 1 2 1\n1 3\n4 2\n4 3\n4 6\n4 6\n
\n
\n
\n
\n
\n

Sample Output 2

3\n
\n
\n
", "id": "codenet-bug-p02689", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N monsters, numbered 1, 2, ..., N.

\n

Initially, the health of Monster i is A_i.

\n

Below, a monster with at least 1 health is called alive.

\n

Until there is only one alive monster, the following is repeated:

\n
    \n
  • A random alive monster attacks another random alive monster.
  • \n
  • As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.
  • \n
\n

Find the minimum possible final health of the last monster alive.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 10^5
  • \n
  • 1 \\leq A_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 ... A_N\n
\n
\n
\n
\n
\n

Output

Print the minimum possible final health of the last monster alive.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n2 10 8 40\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n5 13 8 1000000000\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

3\n1000000000 1000000000 1000000000\n
\n
\n
\n
\n
\n

Sample Output 3

1000000000\n
\n
\n
", "id": "codenet-bug-p03127", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.)\nThe state of each piece is represented by a string S of length N.\nIf S_i=B, the i-th piece from the left is showing black;\nIf S_i=W, the i-th piece from the left is showing white.

\n

Consider performing the following operation:

\n
    \n
  • Choose i (1 \\leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.
  • \n
\n

Find the maximum possible number of times this operation can be performed.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq |S| \\leq 2\\times 10^5
  • \n
  • S_i=B or W
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the maximum possible number of times the operation can be performed.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

BBW\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

The operation can be performed twice, as follows:

\n
    \n
  • Flip the second and third pieces from the left.
  • \n
  • Flip the first and second pieces from the left.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

BWBWBW\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n
\n
", "id": "codenet-bug-p03200", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).

\n

Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?

\n

We remind you that the distance between the origin and the point (p, q) can be represented as \\sqrt{p^2+q^2}.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 2\\times 10^5
  • \n
  • 0 \\leq D \\leq 2\\times 10^5
  • \n
  • |X_i|,|Y_i| \\leq 2\\times 10^5
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N D\nX_1 Y_1\n\\vdots\nX_N Y_N\n
\n
\n
\n
\n
\n

Output

Print an integer representing the number of points such that the distance from the origin is at most D.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 5\n0 5\n-2 4\n3 4\n4 -4\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

The distance between the origin and each of the given points is as follows:

\n
    \n
  • \\sqrt{0^2+5^2}=5
  • \n
  • \\sqrt{(-2)^2+4^2}=4.472\\ldots
  • \n
  • \\sqrt{3^2+4^2}=5
  • \n
  • \\sqrt{4^2+(-4)^2}=5.656\\ldots
  • \n
\n

Thus, we have three points such that the distance from the origin is at most 5.

\n
\n
\n
\n
\n
\n

Sample Input 2

12 3\n1 1\n1 1\n1 1\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n
\n
\n
\n
\n
\n

Sample Output 2

7\n
\n

Multiple points may exist at the same coordinates.

\n
\n
\n
\n
\n
\n

Sample Input 3

20 100000\n14309 -32939\n-56855 100340\n151364 25430\n103789 -113141\n147404 -136977\n-37006 -30929\n188810 -49557\n13419 70401\n-88280 165170\n-196399 137941\n-176527 -61904\n46659 115261\n-153551 114185\n98784 -6820\n94111 -86268\n-30401 61477\n-55056 7872\n5901 -163796\n138819 -185986\n-69848 -96669\n
\n
\n
\n
\n
\n

Sample Output 3

6\n
\n
\n
", "id": "codenet-bug-p02595", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

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.

\n
\n
\n
\n
\n

Constraints

    \n
  • Each character in s is a lowercase English letter.
  • \n
  • 1≤|s|≤10^5
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
s\n
\n
\n
\n
\n
\n

Output

Print the string obtained by concatenating all the characters in the odd-numbered positions.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

atcoder\n
\n
\n
\n
\n
\n

Sample Output 1

acdr\n
\n

Extract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.

\n
\n
\n
\n
\n
\n

Sample Input 2

aaaa\n
\n
\n
\n
\n
\n

Sample Output 2

aa\n
\n
\n
\n
\n
\n
\n

Sample Input 3

z\n
\n
\n
\n
\n
\n

Sample Output 3

z\n
\n
\n
\n
\n
\n
\n

Sample Input 4

fukuokayamaguchi\n
\n
\n
\n
\n
\n

Sample Output 4

fkoaaauh\n
\n
\n
", "id": "codenet-bug-p03610", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

Given are integers A, B, and N.

\n

Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.

\n

Here floor(t) denotes the greatest integer not greater than the real number t.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ A ≤ 10^{6}
  • \n
  • 1 ≤ B ≤ 10^{12}
  • \n
  • 1 ≤ N ≤ 10^{12}
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B N\n
\n
\n
\n
\n
\n

Output

Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 7 4\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

When x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.

\n
\n
\n
\n
\n
\n

Sample Input 2

11 10 9\n
\n
\n
\n
\n
\n

Sample Output 2

9\n
\n
\n
", "id": "codenet-bug-p02696", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There is an N-car train.

\n

You are given an integer i. Find the value of j such that the following statement is true: \"the i-th car from the front of the train is the j-th car from the back.\"

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
  • 1 \\leq i \\leq N
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N i\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 2\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

The second car from the front of a 4-car train is the third car from the back.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 1\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

15 11\n
\n
\n
\n
\n
\n

Sample Output 3

5\n
\n
\n
", "id": "codenet-bug-p03272", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi has many red balls and blue balls. Now, he will place them in a row.

\n

Initially, there is no ball placed.

\n

Takahashi, who is very patient, will do the following operation 10^{100} times:

\n
    \n
  • Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.
  • \n
\n

How many blue balls will be there among the first N balls in the row of balls made this way?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^{18}
  • \n
  • A, B \\geq 0
  • \n
  • 0 < A + B \\leq 10^{18}
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N A B\n
\n
\n
\n
\n
\n

Output

Print the number of blue balls that will be there among the first N balls in the row of balls.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

8 3 4\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

Let b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.

\n
\n
\n
\n
\n
\n

Sample Input 2

8 0 4\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

He placed only red balls from the beginning.

\n
\n
\n
\n
\n
\n

Sample Input 3

6 2 4\n
\n
\n
\n
\n
\n

Sample Output 3

2\n
\n

Among bbrrrr, there are two blue balls.

\n
\n
", "id": "codenet-bug-p02754", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 200 points

\n
\n
\n

Problem Statement

\n

The restaurant AtCoder serves the following five dishes:

\n
    \n
  • ABC Don (rice bowl): takes A minutes to serve.
  • \n
  • ARC Curry: takes B minutes to serve.
  • \n
  • AGC Pasta: takes C minutes to serve.
  • \n
  • APC Ramen: takes D minutes to serve.
  • \n
  • ATC Hanbagu (hamburger patty): takes E minutes to serve.
  • \n
\n

Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered.

\n

This restaurant has the following rules on orders:

\n
    \n
  • An order can only be placed at a time that is a multiple of 10 (time 0, 10, 20, ...).
  • \n
  • Only one dish can be ordered at a time.
  • \n
  • No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered.
  • \n
\n

E869120 arrives at this restaurant at time 0. He will order all five dishes. Find the earliest possible time for the last dish to be delivered.
\nHere, he can order the dishes in any order he likes, and he can place an order already at time 0.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • A, B, C, D and E are integers between 1 and 123 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
A\nB\nC\nD\nE\n
\n
\n
\n
\n
\n

Output

\n

Print the earliest possible time for the last dish to be delivered, as an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

29\n20\n7\n35\n120\n
\n
\n
\n
\n
\n

Sample Output 1

215\n
\n

If we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta, ATC Hanbagu, APC Ramen, the earliest possible time for each order is as follows:

\n
    \n
  • Order ABC Don at time 0, which will be delivered at time 29.
  • \n
  • Order ARC Curry at time 30, which will be delivered at time 50.
  • \n
  • Order AGC Pasta at time 50, which will be delivered at time 57.
  • \n
  • Order ATC Hanbagu at time 60, which will be delivered at time 180.
  • \n
  • Order APC Ramen at time 180, which will be delivered at time 215.
  • \n
\n

There is no way to order the dishes in which the last dish will be delivered earlier than this.

\n
\n
\n
\n
\n
\n

Sample Input 2

101\n86\n119\n108\n57\n
\n
\n
\n
\n
\n

Sample Output 2

481\n
\n

If we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC Hanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as follows:

\n
    \n
  • Order AGC Pasta at time 0, which will be delivered at time 119.
  • \n
  • Order ARC Curry at time 120, which will be delivered at time 206.
  • \n
  • Order ATC Hanbagu at time 210, which will be delivered at time 267.
  • \n
  • Order APC Ramen at time 270, which will be delivered at time 378.
  • \n
  • Order ABC Don at time 380, which will be delivered at time 481.
  • \n
\n

There is no way to order the dishes in which the last dish will be delivered earlier than this.

\n
\n
\n
\n
\n
\n

Sample Input 3

123\n123\n123\n123\n123\n
\n
\n
\n
\n
\n

Sample Output 3

643\n
\n

This is the largest valid case.

\n
\n
", "id": "codenet-bug-p03076", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible.\nWhen all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N,K \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\n
\n
\n
\n
\n
\n

Output

Print the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

7 3\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

When the users receive two, two and three crackers, respectively, the (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

100 10\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

The crackers can be distributed evenly.

\n
\n
\n
\n
\n
\n

Sample Input 3

1 1\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03284", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are N items, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), Item i has a weight of w_i and a value of v_i.

\n

Taro has decided to choose some of the N items and carry them home in a knapsack.\nThe capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.

\n

Find the maximum possible sum of the values of items that Taro takes home.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 100
  • \n
  • 1 \\leq W \\leq 10^9
  • \n
  • 1 \\leq w_i \\leq W
  • \n
  • 1 \\leq v_i \\leq 10^3
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N W\nw_1 v_1\nw_2 v_2\n:\nw_N v_N\n
\n
\n
\n
\n
\n

Output

Print the maximum possible sum of the values of items that Taro takes home.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 8\n3 30\n4 50\n5 60\n
\n
\n
\n
\n
\n

Sample Output 1

90\n
\n

Items 1 and 3 should be taken.\nThen, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 1000000000\n1000000000 10\n
\n
\n
\n
\n
\n

Sample Output 2

10\n
\n
\n
\n
\n
\n
\n

Sample Input 3

6 15\n6 5\n5 6\n6 4\n6 6\n3 5\n7 2\n
\n
\n
\n
\n
\n

Sample Output 3

17\n
\n

Items 2, 4 and 5 should be taken.\nThen, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.

\n
\n
", "id": "codenet-bug-p03164", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given a string S as input. This represents a valid date in the year 2019 in the yyyy/mm/dd format. (For example, April 30, 2019 is represented as 2019/04/30.)

\n

Write a program that prints Heisei if the date represented by S is not later than April 30, 2019, and prints TBD otherwise.

\n
\n
\n
\n
\n

Constraints

    \n
  • S is a string that represents a valid date in the year 2019 in the yyyy/mm/dd format.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print Heisei if the date represented by S is not later than April 30, 2019, and print TBD otherwise.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2019/04/30\n
\n
\n
\n
\n
\n

Sample Output 1

Heisei\n
\n
\n
\n
\n
\n
\n

Sample Input 2

2019/11/01\n
\n
\n
\n
\n
\n

Sample Output 2

TBD\n
\n
\n
", "id": "codenet-bug-p03109", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

Give a pair of integers (A, B) such that A^5-B^5 = X.\nIt is guaranteed that there exists such a pair for the given integer X.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq X \\leq 10^9
  • \n
  • X is an integer.
  • \n
  • There exists a pair of integers (A, B) satisfying the condition in Problem Statement.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
X\n
\n
\n
\n
\n
\n

Output

Print A and B, with space in between.\nIf there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.

\n
A B\n
\n
\n
\n
\n
\n
\n
\n

Sample Input 1

33\n
\n
\n
\n
\n
\n

Sample Output 1

2 -1\n
\n

For A=2 and B=-1, A^5-B^5 = 33.

\n
\n
\n
\n
\n
\n

Sample Input 2

1\n
\n
\n
\n
\n
\n

Sample Output 2

0 -1\n
\n
\n
", "id": "codenet-bug-p02690", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Given are N integers A_1,\\ldots,A_N.

\n

Find the sum of A_i \\times A_j over all pairs (i,j) such that 1\\leq i < j \\leq N, modulo (10^9+7).

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 2\\times 10^5
  • \n
  • 0 \\leq A_i \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 \\ldots A_N\n
\n
\n
\n
\n
\n

Output

Print \\sum_{i=1}^{N-1}\\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7).

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n1 2 3\n
\n
\n
\n
\n
\n

Sample Output 1

11\n
\n

We have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n141421356 17320508 22360679 244949\n
\n
\n
\n
\n
\n

Sample Output 2

437235829\n
\n
\n
", "id": "codenet-bug-p02572", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Alice and Bob are controlling a robot. They each have one switch that controls the robot.
\nAlice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.
\nBob started holding down his button C second after the start-up, and released his button D second after the start-up.
\nFor how many seconds both Alice and Bob were holding down their buttons?

\n
\n
\n
\n
\n

Constraints

    \n
  • 0≤A<B≤100
  • \n
  • 0≤C<D≤100
  • \n
  • All input values are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C D\n
\n
\n
\n
\n
\n

Output

Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

0 75 25 100\n
\n
\n
\n
\n
\n

Sample Output 1

50\n
\n

Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.
\nBob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.
\nTherefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.

\n
\n
\n
\n
\n
\n

Sample Input 2

0 33 66 99\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.

\n
\n
\n
\n
\n
\n

Sample Input 3

10 90 20 80\n
\n
\n
\n
\n
\n

Sample Output 3

60\n
\n
\n
", "id": "codenet-bug-p03632", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Given any integer x, Aoki can do the operation below.

\n

Operation: Replace x with the absolute difference of x and K.

\n

You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 ≤ N ≤ 10^{18}
  • \n
  • 1 ≤ K ≤ 10^{18}
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\n
\n
\n
\n
\n
\n

Output

Print the minimum possible value taken by N after Aoki does the operation zero or more times.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

7 4\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

Initially, N=7.

\n

After one operation, N becomes |7-4| = 3.

\n

After two operations, N becomes |3-4| = 1, which is the minimum value taken by N.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 6\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n

N=2 after zero operations is the minimum.

\n
\n
\n
\n
\n
\n

Sample Input 3

1000000000000000000 1\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p02719", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

\n

Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.

\n

Given is a string S. Find the minimum number of hugs needed to make S palindromic.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • S is a string consisting of lowercase English letters.
  • \n
  • The length of S is between 1 and 100 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

\n

Print the minimum number of hugs needed to make S palindromic.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

redcoder\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

For example, we can change the fourth character to o and get a palindrome redooder.

\n
\n
\n
\n
\n
\n

Sample Input 2

vvvvvv\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

We might need no hugs at all.

\n
\n
\n
\n
\n
\n

Sample Input 3

abcdabc\n
\n
\n
\n
\n
\n

Sample Output 3

2\n
\n
\n
", "id": "codenet-bug-p02836", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Given are strings s and t of length N each, both consisting of lowercase English letters.

\n

Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
  • |S| = |T| = N
  • \n
  • S and T are strings consisting of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS T\n
\n
\n
\n
\n
\n

Output

Print the string formed.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\nip cc\n
\n
\n
\n
\n
\n

Sample Output 1

icpc\n
\n
\n
\n
\n
\n
\n

Sample Input 2

8\nhmhmnknk uuuuuuuu\n
\n
\n
\n
\n
\n

Sample Output 2

humuhumunukunuku\n
\n
\n
\n
\n
\n
\n

Sample Input 3

5\naaaaa aaaaa\n
\n
\n
\n
\n
\n

Sample Output 3

aaaaaaaaaa\n
\n
\n
", "id": "codenet-bug-p02830", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

We have a board with H horizontal rows and W vertical columns of squares.\nThere is a bishop at the top-left square on this board.\nHow many squares can this bishop reach by zero or more movements?

\n

Here the bishop can only move diagonally.\nMore formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds:

\n
    \n
  • r_1 + c_1 = r_2 + c_2
  • \n
  • r_1 - c_1 = r_2 - c_2
  • \n
\n

For example, in the following figure, the bishop can move to any of the red squares in one move:

\n

\"\"

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq H, W \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
H \\ W\n
\n
\n
\n
\n
\n

Output

Print the number of squares the bishop can reach.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 5\n
\n
\n
\n
\n
\n

Sample Output 1

10\n
\n

The bishop can reach the cyan squares in the following figure:

\n

\"\"

\n
\n
\n
\n
\n
\n

Sample Input 2

7 3\n
\n
\n
\n
\n
\n

Sample Output 2

11\n
\n

The bishop can reach the cyan squares in the following figure:

\n

\"\"

\n
\n
\n
\n
\n
\n

Sample Input 3

1000000000 1000000000\n
\n
\n
\n
\n
\n

Sample Output 3

500000000000000000\n
\n
\n
", "id": "codenet-bug-p02742", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.

\n

Given are two integers A and B.

\n

If Takahashi can calculate A \\times B, print the result; if he cannot, print -1 instead.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A \\leq 20
  • \n
  • 1 \\leq B \\leq 20
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

If Takahashi can calculate A \\times B, print the result; if he cannot, print -1.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 5\n
\n
\n
\n
\n
\n

Sample Output 1

10\n
\n

2 \\times 5 = 10.

\n
\n
\n
\n
\n
\n

Sample Input 2

5 10\n
\n
\n
\n
\n
\n

Sample Output 2

-1\n
\n

5\\times 10 = 50, but Takahashi cannot do this calculation, so print -1 instead.

\n
\n
\n
\n
\n
\n

Sample Input 3

9 9\n
\n
\n
\n
\n
\n

Sample Output 3

81\n
\n
\n
", "id": "codenet-bug-p02879", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.

\n

Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.

\n

Ultimately, how many slimes will be there?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^5
  • \n
  • |S| = N
  • \n
  • S consists of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS\n
\n
\n
\n
\n
\n

Output

Print the final number of slimes.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10\naabbbbaaca\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

Ultimately, these slimes will fuse into abaca.

\n
\n
\n
\n
\n
\n

Sample Input 2

5\naaaaa\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

All the slimes will fuse into one.

\n
\n
\n
\n
\n
\n

Sample Input 3

20\nxxzaffeeeeddfkkkkllq\n
\n
\n
\n
\n
\n

Sample Output 3

10\n
\n
\n
", "id": "codenet-bug-p02887", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.\n(Assume that the positive x-axis points right, and the positive y-axis points up.)

\n

Takahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).

\n

Given x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.

\n
\n
\n
\n
\n

Constraints

    \n
  • |x_1|,|y_1|,|x_2|,|y_2| \\leq 100
  • \n
  • (x_1,y_1)(x_2,y_2)
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
x_1 y_1 x_2 y_2\n
\n
\n
\n
\n
\n

Output

Print x_3,y_3,x_4 and y_4 as integers, in this order.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

0 0 0 1\n
\n
\n
\n
\n
\n

Sample Output 1

-1 1 -1 0\n
\n

(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.\nNote that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 3 6 6\n
\n
\n
\n
\n
\n

Sample Output 2

3 10 -1 7\n
\n
\n
\n
\n
\n
\n

Sample Input 3

31 -41 -59 26\n
\n
\n
\n
\n
\n

Sample Output 3

-126 -64 -36 -131\n
\n
\n
", "id": "codenet-bug-p03265", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

In some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.

\n

It had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.

\n

Assuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.

\n

Assume also that the depth of the snow cover is always at least 1 meter.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq a < b < 499500(=1+2+3+...+999)
  • \n
  • All values in input are integers.
  • \n
  • There is no input that contradicts the assumption.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
a b\n
\n
\n
\n
\n
\n

Output

If the depth of the snow cover is x meters, print x as an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

8 13\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

The heights of the two towers are 10 meters and 15 meters, respectively.\nThus, we can see that the depth of the snow cover is 2 meters.

\n
\n
\n
\n
\n
\n

Sample Input 2

54 65\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n
\n
", "id": "codenet-bug-p03328", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^9
  • \n
  • N is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the largest square number not exceeding N.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n

10 is not square, but 9 = 3 × 3 is. Thus, we print 9.

\n
\n
\n
\n
\n
\n

Sample Input 2

81\n
\n
\n
\n
\n
\n

Sample Output 2

81\n
\n
\n
\n
\n
\n
\n

Sample Input 3

271828182\n
\n
\n
\n
\n
\n

Sample Output 3

271821169\n
\n
\n
", "id": "codenet-bug-p03556", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.

\n
\n\n

An example of a trapezoid

\n
\n

Find the area of this trapezoid.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≦a≦100
  • \n
  • 1≦b≦100
  • \n
  • 1≦h≦100
  • \n
  • All input values are integers.
  • \n
  • h is even.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
a\nb\nh\n
\n
\n
\n
\n
\n

Output

Print the area of the given trapezoid. It is guaranteed that the area is an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n4\n2\n
\n
\n
\n
\n
\n

Sample Output 1

7\n
\n

When the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n4\n4\n
\n
\n
\n
\n
\n

Sample Output 2

16\n
\n

In this case, a parallelogram is given, which is also a trapezoid.

\n
\n
", "id": "codenet-bug-p03997", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

There are N people standing in a queue from west to east.

\n

Given is a string S of length N representing the directions of the people.\nThe i-th person from the west is facing west if the i-th character of S is L, and east if that character of S is R.

\n

A person is happy if the person in front of him/her is facing the same direction.\nIf no person is standing in front of a person, however, he/she is not happy.

\n

You can perform the following operation any number of times between 0 and K (inclusive):

\n

Operation: Choose integers l and r such that 1 \\leq l \\leq r \\leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.

\n

What is the maximum possible number of happy people you can have?

\n
\n
\n
\n
\n

Constraints

    \n
  • N is an integer satisfying 1 \\leq N \\leq 10^5.
  • \n
  • K is an integer satisfying 1 \\leq K \\leq 10^5.
  • \n
  • |S| = N
  • \n
  • Each character of S is L or R.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\nS\n
\n
\n
\n
\n
\n

Output

Print the maximum possible number of happy people after at most K operations.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6 1\nLRLRRL\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

If we choose (l, r) = (2, 5), we have LLLRLL, where the 2-nd, 3-rd, and 6-th persons from the west are happy.

\n
\n
\n
\n
\n
\n

Sample Input 2

13 3\nLRRLRLRRLRLLR\n
\n
\n
\n
\n
\n

Sample Output 2

9\n
\n
\n
\n
\n
\n
\n

Sample Input 3

10 1\nLLLLLRRRRR\n
\n
\n
\n
\n
\n

Sample Output 3

9\n
\n
\n
\n
\n
\n
\n

Sample Input 4

9 2\nRRRLRLRLL\n
\n
\n
\n
\n
\n

Sample Output 4

7\n
\n
\n
", "id": "codenet-bug-p02918", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You have three tasks, all of which need to be completed.

\n

First, you can complete any one task at cost 0.

\n

Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.

\n

Here, |x| denotes the absolute value of x.

\n

Find the minimum total cost required to complete all the task.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq A_1, A_2, A_3 \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A_1 A_2 A_3\n
\n
\n
\n
\n
\n

Output

Print the minimum total cost required to complete all the task.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 6 3\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

When the tasks are completed in the following order, the total cost will be 5, which is the minimum:

\n
    \n
  • Complete the first task at cost 0.
  • \n
  • Complete the third task at cost 2.
  • \n
  • Complete the second task at cost 3.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

11 5 5\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n
\n
\n
\n
\n
\n

Sample Input 3

100 100 100\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03292", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 500 points

\n
\n
\n

Problem Statement

We have N bulbs arranged on a number line, numbered 1 to N from left to right.\nBulb i is at coordinate i.

\n

Each bulb has a non-negative integer parameter called intensity.\nWhen there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.\nInitially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:

\n
    \n
  • For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.
  • \n
\n

Find the intensity of each bulb after the K operations.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 2 \\times 10^5
  • \n
  • 1 \\leq K \\leq 2 \\times 10^5
  • \n
  • 0 \\leq A_i \\leq N
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\nA_1 A_2 \\ldots A_N\n
\n
\n
\n
\n
\n

Output

Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:

\n
A{'}_1 A{'}_2 \\ldots A{'}_N\n
\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 1\n1 0 0 1 0\n
\n
\n
\n
\n
\n

Sample Output 1

1 2 2 1 2 \n
\n

Initially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.\nSimilarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

5 2\n1 0 0 1 0\n
\n
\n
\n
\n
\n

Sample Output 2

3 3 4 4 3 \n
\n
\n
", "id": "codenet-bug-p02647", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given nonnegative integers a and b (a ≤ b), and a positive integer x.\nAmong the integers between a and b, inclusive, how many are divisible by x?

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 ≤ a ≤ b ≤ 10^{18}
  • \n
  • 1 ≤ x ≤ 10^{18}
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
a b x\n
\n
\n
\n
\n
\n

Output

Print the number of the integers between a and b, inclusive, that are divisible by x.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 8 2\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

There are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.

\n
\n
\n
\n
\n
\n

Sample Input 2

0 5 1\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n

There are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.

\n
\n
\n
\n
\n
\n

Sample Input 3

9 9 2\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

There are no integer between 9 and 9, inclusive, that is divisible by 2.

\n
\n
\n
\n
\n
\n

Sample Input 4

1 1000000000000000000 3\n
\n
\n
\n
\n
\n

Sample Output 4

333333333333333333\n
\n

Watch out for integer overflows.

\n
\n
", "id": "codenet-bug-p03861", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There is an integer sequence A of length N whose values are unknown.

\n

Given is an integer sequence B of length N-1 which is known to satisfy the following:

\n

B_i \\geq \\max(A_i, A_{i+1})

\n

Find the maximum possible sum of the elements of A.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 100
  • \n
  • 0 \\leq B_i \\leq 10^5
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nB_1 B_2 ... B_{N-1}\n
\n
\n
\n
\n
\n

Output

Print the maximum possible sum of the elements of A.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n2 5\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n

A can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n3\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n
\n
\n
\n
\n
\n

Sample Input 3

6\n0 153 10 10 23\n
\n
\n
\n
\n
\n

Sample Output 3

53\n
\n
\n
", "id": "codenet-bug-p02917", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively.\nPrint Yes if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print No otherwise.

\n
\n
\n
\n
\n

Constraints

    \n
  • 0\\leq A,B,C\\leq 100
  • \n
  • A, B and C are distinct integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

Print Yes if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print No otherwise.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 8 5\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

We pass the coordinate 5 on the straight way from the house at coordinate 3 to the house at coordinate 8.

\n
\n
\n
\n
\n
\n

Sample Input 2

7 3 1\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n
\n
\n
\n
\n
\n

Sample Input 3

10 2 4\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 4

31 41 59\n
\n
\n
\n
\n
\n

Sample Output 4

No\n
\n
\n
", "id": "codenet-bug-p03067", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given an integer K.\nPrint the string obtained by repeating the string ACL K times and concatenating them.

\n

For example, if K = 3, print ACLACLACL.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq K \\leq 5
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
K\n
\n
\n
\n
\n
\n

Output

Print the string obtained by repeating the string ACL K times and concatenating them.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n
\n
\n
\n
\n
\n

Sample Output 1

ACLACLACL\n
\n
\n
", "id": "codenet-bug-p02534", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Print the K-th element of the following sequence of length 32:

\n
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51\n
\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq K \\leq 32
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
K\n
\n
\n
\n
\n
\n

Output

Print the K-th element.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

The 6-th element is 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

27\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n

The 27-th element is 5.

\n
\n
", "id": "codenet-bug-p02741", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given a grid with 2 rows and 3 columns of squares.\nThe color of the square at the i-th row and j-th column is represented by the character C_{ij}.

\n

Write a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise.

\n
\n
\n
\n
\n

Constraints

    \n
  • C_{i,j}(1 \\leq i \\leq 2, 1 \\leq j \\leq 3) is a lowercase English letter.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
C_{11}C_{12}C_{13}\nC_{21}C_{22}C_{23}\n
\n
\n
\n
\n
\n

Output

Print YES if this grid remains the same when rotated 180 degrees; print NO otherwise.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

pot\ntop\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

This grid remains the same when rotated 180 degrees.

\n
\n
\n
\n
\n
\n

Sample Input 2

tab\nbet\n
\n
\n
\n
\n
\n

Sample Output 2

NO\n
\n

This grid does not remain the same when rotated 180 degrees.

\n
\n
\n
\n
\n
\n

Sample Input 3

eye\neel\n
\n
\n
\n
\n
\n

Sample Output 3

NO\n
\n
\n
", "id": "codenet-bug-p03555", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You have decided to give an allowance to your child depending on the outcome of the game that he will play now.

\n

The game is played as follows:

\n
    \n
  • There are three \"integer panels\", each with a digit between 1 and 9 (inclusive) printed on it, and one \"operator panel\" with a + printed on it.
  • \n
  • The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
  • \n
  • Then, the amount of the allowance will be equal to the resulting value of the formula.
  • \n
\n

Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq A, B, C \\leq 9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

Print the maximum possible amount of the allowance.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 5 2\n
\n
\n
\n
\n
\n

Sample Output 1

53\n
\n

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.

\n
\n
\n
\n
\n
\n

Sample Input 2

9 9 9\n
\n
\n
\n
\n
\n

Sample Output 2

108\n
\n
\n
\n
\n
\n
\n

Sample Input 3

6 6 7\n
\n
\n
\n
\n
\n

Sample Output 3

82\n
\n
\n
", "id": "codenet-bug-p03250", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.

\n

For each square, you will perform either of the following operations once:

\n
    \n
  • Decrease the height of the square by 1.
  • \n
  • Do nothing.
  • \n
\n

Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 1 \\leq H_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nH_1 H_2 ... H_N\n
\n
\n
\n
\n
\n

Output

If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n1 2 1 1 3\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

You can achieve the objective by decreasing the height of only the second square from the left by 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n1 3 2 1\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n
\n
\n
\n
\n
\n

Sample Input 3

5\n1 2 3 4 5\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 4

1\n1000000000\n
\n
\n
\n
\n
\n

Sample Output 4

Yes\n
\n
\n
", "id": "codenet-bug-p02953", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.

\n

The problem has N test cases.

\n

For each test case i (1\\leq i \\leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively.

\n

See the Output section for the output format.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^5
  • \n
  • S_i is AC, WA, TLE, or RE.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS_1\n\\vdots\nS_N\n
\n
\n
\n
\n
\n

Output

Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively. Print the following:

\n
AC x C_0\nWA x C_1\nTLE x C_2\nRE x C_3\n
\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6\nAC\nTLE\nAC\nAC\nWA\nTLE\n
\n
\n
\n
\n
\n

Sample Output 1

AC x 3\nWA x 1\nTLE x 2\nRE x 0\n
\n

We have 3, 1, 2, and 0 test case(s) for which the verdict is AC, WA, TLE, and RE, respectively.

\n
\n
\n
\n
\n
\n

Sample Input 2

10\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\n
\n
\n
\n
\n
\n

Sample Output 2

AC x 10\nWA x 0\nTLE x 0\nRE x 0\n
\n
\n
", "id": "codenet-bug-p02613", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

\n

Your objective is to visit all these cities at least once.

\n

In order to do so, you will first set a positive integer D.

\n

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

\n
    \n
  • Move 1: travel from coordinate y to coordinate y + D.
  • \n
  • Move 2: travel from coordinate y to coordinate y - D.
  • \n
\n

Find the maximum value of D that enables you to visit all the cities.

\n

Here, to visit a city is to travel to the coordinate where that city is located.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 1 \\leq X \\leq 10^9
  • \n
  • 1 \\leq x_i \\leq 10^9
  • \n
  • x_i are all different.
  • \n
  • x_1, x_2, ..., x_N \\neq X
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N X\nx_1 x_2 ... x_N\n
\n
\n
\n
\n
\n

Output

Print the maximum value of D that enables you to visit all the cities.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 3\n1 7 11\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

\n
    \n
  • Perform Move 2 to travel to coordinate 1.
  • \n
  • Perform Move 1 to travel to coordinate 3.
  • \n
  • Perform Move 1 to travel to coordinate 5.
  • \n
  • Perform Move 1 to travel to coordinate 7.
  • \n
  • Perform Move 1 to travel to coordinate 9.
  • \n
  • Perform Move 1 to travel to coordinate 11.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

3 81\n33 105 57\n
\n
\n
\n
\n
\n

Sample Output 2

24\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1 1\n1000000000\n
\n
\n
\n
\n
\n

Sample Output 3

999999999\n
\n
\n
", "id": "codenet-bug-p03262", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word \"bill\" refers to only these.

\n

According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ N ≤ 2000
  • \n
  • 1000 ≤ Y ≤ 2 × 10^7
  • \n
  • N is an integer.
  • \n
  • Y is a multiple of 1000.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N Y\n
\n
\n
\n
\n
\n

Output

If the total value of N bills cannot be Y yen, print -1 -1 -1.

\n

If the total value of N bills can be Y yen, let one such set of bills be \"x 10000-yen bills, y 5000-yen bills and z 1000-yen bills\", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

9 45000\n
\n
\n
\n
\n
\n

Sample Output 1

4 0 5\n
\n

If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0 is also correct.

\n
\n
\n
\n
\n
\n

Sample Input 2

20 196000\n
\n
\n
\n
\n
\n

Sample Output 2

-1 -1 -1\n
\n

When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.

\n
\n
\n
\n
\n
\n

Sample Input 3

1000 1234000\n
\n
\n
\n
\n
\n

Sample Output 3

14 27 959\n
\n

There are also many other possibilities.

\n
\n
\n
\n
\n
\n

Sample Input 4

2000 20000000\n
\n
\n
\n
\n
\n

Sample Output 4

2000 0 0\n
\n
\n
", "id": "codenet-bug-p03471", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 100 points

\n
\n
\n

Problem Statement

\n

Takahashi is solving quizzes. He has easily solved all but the last one.

\n

The last quiz has three choices: 1, 2, and 3.

\n

With his supernatural power, Takahashi has found out that the choices A and B are both wrong.

\n

Print the correct choice for this problem.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • Each of the numbers A and B is 1, 2, or 3.
  • \n
  • A and B are different.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
A\nB\n
\n
\n
\n
\n
\n

Output

\n

Print the correct choice.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n1\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

When we know 3 and 1 are both wrong, the correct choice is 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

1\n2\n
\n
\n
\n
\n
\n

Sample Output 2

3\n
\n
\n
", "id": "codenet-bug-p02829", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

A string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.
\nGiven a string S, determine whether it is coffee-like.

\n
\n
\n
\n
\n

Constraints

    \n
  • S is a string of length 6 consisting of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

If S is coffee-like, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

sippuu\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

In sippuu, the 3-rd and 4-th characters are equal, and the 5-th and 6-th characters are also equal.

\n
\n
\n
\n
\n
\n

Sample Input 2

iphone\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n
\n
\n
\n
\n
\n

Sample Input 3

coffee\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p02723", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 400 points

\n
\n
\n

Problem Statement

\n

There is a cave.

\n

The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.

\n

It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.

\n

Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.

\n
    \n
  • If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
  • \n
\n

Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 10^5
  • \n
  • 1 \\leq M \\leq 2 \\times 10^5
  • \n
  • 1 \\leq A_i, B_i \\leq N\\ (1 \\leq i \\leq M)
  • \n
  • A_i \\neq B_i\\ (1 \\leq i \\leq M)
  • \n
  • One can travel between any two rooms by traversing passages.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N M\nA_1 B_1\n:\nA_M B_M\n
\n
\n
\n
\n
\n

Output

\n

If there is no way to place signposts satisfying the objective, print No.

\n

Otherwise, print N lines. The first line should contain Yes, and the i-th line (2 \\leq i \\leq N) should contain the integer representing the room indicated by the signpost in Room i.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 4\n1 2\n2 3\n3 4\n4 2\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n1\n2\n2\n
\n

If we place the signposts as described in the sample output, the following happens:

\n
    \n
  • Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.
  • \n
  • Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.
  • \n
  • Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.
  • \n
\n

Thus, the objective is satisfied.

\n
\n
\n
\n
\n
\n

Sample Input 2

6 9\n3 4\n6 1\n2 4\n5 3\n4 6\n1 5\n6 2\n4 5\n5 6\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n6\n5\n5\n1\n1\n
\n

If there are multiple solutions, any of them will be accepted.

\n
\n
", "id": "codenet-bug-p02678", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

Takahashi has a string S consisting of lowercase English letters.

\n

Starting with this string, he will produce a new one in the procedure given as follows.

\n

The procedure consists of Q operations. In Operation i (1 \\leq i \\leq Q), an integer T_i is provided, which means the following:

\n
    \n
  • \n

    If T_i = 1: reverse the string S.

    \n
  • \n
  • \n

    If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.

    \n
      \n
    • If F_i = 1 : Add C_i to the beginning of the string S.
    • \n
    • If F_i = 2 : Add C_i to the end of the string S.
    • \n
    \n
  • \n
\n

Help Takahashi by finding the final string that results from the procedure.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq |S| \\leq 10^5
  • \n
  • S consists of lowercase English letters.
  • \n
  • 1 \\leq Q \\leq 2 \\times 10^5
  • \n
  • T_i = 1 or 2.
  • \n
  • F_i = 1 or 2, if provided.
  • \n
  • C_i is a lowercase English letter, if provided.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\nQ\nQuery_1\n:\nQuery_Q\n
\n

In the 3-rd through the (Q+2)-th lines, Query_i is one of the following:

\n
1\n
\n

which means T_i = 1, and:

\n
2 F_i C_i\n
\n

which means T_i = 2.

\n
\n
\n
\n
\n

Output

Print the resulting string.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

a\n4\n2 1 p\n1\n2 2 c\n1\n
\n
\n
\n
\n
\n

Sample Output 1

cpa\n
\n

There will be Q = 4 operations. Initially, S is a.

\n
    \n
  • \n

    Operation 1: Add p at the beginning of S. S becomes pa.

    \n
  • \n
  • \n

    Operation 2: Reverse S. S becomes ap.

    \n
  • \n
  • \n

    Operation 3: Add c at the end of S. S becomes apc.

    \n
  • \n
  • \n

    Operation 4: Reverse S. S becomes cpa.

    \n
  • \n
\n

Thus, the resulting string is cpa.

\n
\n
\n
\n
\n
\n

Sample Input 2

a\n6\n2 2 a\n2 1 b\n1\n2 2 c\n1\n1\n
\n
\n
\n
\n
\n

Sample Output 2

aabc\n
\n

There will be Q = 6 operations. Initially, S is a.

\n
    \n
  • \n

    Operation 1: S becomes aa.

    \n
  • \n
  • \n

    Operation 2: S becomes baa.

    \n
  • \n
  • \n

    Operation 3: S becomes aab.

    \n
  • \n
  • \n

    Operation 4: S becomes aabc.

    \n
  • \n
  • \n

    Operation 5: S becomes cbaa.

    \n
  • \n
  • \n

    Operation 6: S becomes aabc.

    \n
  • \n
\n

Thus, the resulting string is aabc.

\n
\n
\n
\n
\n
\n

Sample Input 3

y\n1\n2 1 x\n
\n
\n
\n
\n
\n

Sample Output 3

xy\n
\n
\n
", "id": "codenet-bug-p02756", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 100 points

\n
\n
\n

Problem Statement

\n

The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.

\n

When counting pencils in Japanese, the counter word \"本\" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of \"本\" in the phrase \"N 本\" for a positive integer N not exceeding 999 is as follows:

\n
    \n
  • hon when the digit in the one's place of N is 2, 4, 5, 7, or 9;
  • \n
  • pon when the digit in the one's place of N is 0, 1, 6 or 8;
  • \n
  • bon when the digit in the one's place of N is 3.
  • \n
\n

Given N, print the pronunciation of \"本\" in the phrase \"N 本\".

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • N is a positive integer not exceeding 999.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

\n

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

16\n
\n
\n
\n
\n
\n

Sample Output 1

pon\n
\n

The digit in the one's place of 16 is 6, so the \"本\" in \"16 本\" is pronounced pon.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n
\n
\n
\n
\n
\n

Sample Output 2

hon\n
\n
\n
\n
\n
\n
\n

Sample Input 3

183\n
\n
\n
\n
\n
\n

Sample Output 3

bon\n
\n
\n
", "id": "codenet-bug-p02675", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N people living on a number line.

\n

The i-th person lives at coordinate X_i.

\n

You are going to hold a meeting that all N people have to attend.

\n

The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.

\n

Find the minimum total points of stamina the N people have to spend.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 100
  • \n
  • 1 \\leq X_i \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nX_1 X_2 ... X_N\n
\n
\n
\n
\n
\n

Output

Print the minimum total stamina the N people have to spend.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n1 4\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.

\n

Note that you can hold the meeting only at an integer coordinate.

\n
\n
\n
\n
\n
\n

Sample Input 2

7\n14 14 2 13 56 2 37\n
\n
\n
\n
\n
\n

Sample Output 2

2354\n
\n
\n
", "id": "codenet-bug-p02767", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.\nHe can climb up one or two steps at a time.

\n

However, the treads of the a_1-th, a_2-th, a_3-th, \\ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.

\n

How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps?\nFind the count modulo 1\\ 000\\ 000\\ 007.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 0 \\leq M \\leq N-1
  • \n
  • 1 \\leq a_1 < a_2 < ... < a_M \\leq N-1
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\na_1\na_2\n .\n .\n .\na_M\n
\n
\n
\n
\n
\n

Output

Print the number of ways to climb up the stairs under the condition, modulo 1\\ 000\\ 000\\ 007.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6 1\n3\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

There are four ways to climb up the stairs, as follows:

\n
    \n
  • 0 \\to 1 \\to 2 \\to 4 \\to 5 \\to 6
  • \n
  • 0 \\to 1 \\to 2 \\to 4 \\to 6
  • \n
  • 0 \\to 2 \\to 4 \\to 5 \\to 6
  • \n
  • 0 \\to 2 \\to 4 \\to 6
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

10 2\n4\n5\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

There may be no way to climb up the stairs without setting foot on the broken steps.

\n
\n
\n
\n
\n
\n

Sample Input 3

100 5\n1\n23\n45\n67\n89\n
\n
\n
\n
\n
\n

Sample Output 3

608200469\n
\n

Be sure to print the count modulo 1\\ 000\\ 000\\ 007.

\n
\n
", "id": "codenet-bug-p03013", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

\n

Takahashi is organizing a party.

\n

At the party, each guest will receive one or more snack pieces.

\n

Takahashi predicts that the number of guests at this party will be A or B.

\n

Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.

\n

We assume that a piece cannot be divided and distributed to multiple guests.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 1 \\leq A, B \\leq 10^5
  • \n
  • A \\neq B
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

\n

Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 3\n
\n
\n
\n
\n
\n

Sample Output 1

6\n
\n

When we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.

\n
\n
\n
\n
\n
\n

Sample Input 2

123 456\n
\n
\n
\n
\n
\n

Sample Output 2

18696\n
\n
\n
\n
\n
\n
\n

Sample Input 3

100000 99999\n
\n
\n
\n
\n
\n

Sample Output 3

9999900000\n
\n
\n
", "id": "codenet-bug-p02831", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.

\n

The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?

\n
\n
\n
\n
\n

Constraints

    \n
  • -40 \\leq X \\leq 40
  • \n
  • X is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
X\n
\n
\n
\n
\n
\n

Output

Print Yes if you will turn on the air conditioner; print No otherwise.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

25\n
\n
\n
\n
\n
\n

Sample Output 1

No\n
\n
\n
\n
\n
\n
\n

Sample Input 2

30\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n
\n
\n
", "id": "codenet-bug-p02594", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are N stones, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), the height of Stone i is h_i.

\n

There is a frog who is initially on Stone 1.\nHe will repeat the following action some number of times to reach Stone N:

\n
    \n
  • If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \\ldots, i + K. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
  • \n
\n

Find the minimum possible total cost incurred before the frog reaches Stone N.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 10^5
  • \n
  • 1 \\leq K \\leq 100
  • \n
  • 1 \\leq h_i \\leq 10^4
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\nh_1 h_2 \\ldots h_N\n
\n
\n
\n
\n
\n

Output

Print the minimum possible total cost incurred.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 3\n10 30 40 50 20\n
\n
\n
\n
\n
\n

Sample Output 1

30\n
\n

If we follow the path 125, the total cost incurred would be |10 - 30| + |30 - 20| = 30.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 1\n10 20 10\n
\n
\n
\n
\n
\n

Sample Output 2

20\n
\n

If we follow the path 123, the total cost incurred would be |10 - 20| + |20 - 10| = 20.

\n
\n
\n
\n
\n
\n

Sample Input 3

2 100\n10 10\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

If we follow the path 12, the total cost incurred would be |10 - 10| = 0.

\n
\n
\n
\n
\n
\n

Sample Input 4

10 4\n40 10 20 70 80 10 20 70 80 60\n
\n
\n
\n
\n
\n

Sample Output 4

40\n
\n

If we follow the path 14810, the total cost incurred would be |40 - 70| + |70 - 70| + |70 - 60| = 40.

\n
\n
", "id": "codenet-bug-p03161", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

N of us are going on a trip, by train or taxi.

\n

The train will cost each of us A yen (the currency of Japan).

\n

The taxi will cost us a total of B yen.

\n

How much is our minimum total travel expense?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 20
  • \n
  • 1 \\leq A \\leq 50
  • \n
  • 1 \\leq B \\leq 50
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N A B\n
\n
\n
\n
\n
\n

Output

Print an integer representing the minimum total travel expense.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 2 9\n
\n
\n
\n
\n
\n

Sample Output 1

8\n
\n

The train will cost us 4 \\times 2 = 8 yen, and the taxi will cost us 9 yen, so the minimum total travel expense is 8 yen.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 2 7\n
\n
\n
\n
\n
\n

Sample Output 2

7\n
\n
\n
\n
\n
\n
\n

Sample Input 3

4 2 8\n
\n
\n
\n
\n
\n

Sample Output 3

8\n
\n
\n
", "id": "codenet-bug-p02981", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Snuke is going to open a contest named \"AtCoder s Contest\".\nHere, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.

\n

Snuke has decided to abbreviate the name of the contest as \"AxC\".\nHere, x is the uppercase English letter at the beginning of s.

\n

Given the name of the contest, print the abbreviation of the name.

\n
\n
\n
\n
\n

Constraints

    \n
  • The length of s is between 1 and 100, inclusive.
  • \n
  • The first character in s is an uppercase English letter.
  • \n
  • The second and subsequent characters in s are lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
AtCoder s Contest\n
\n
\n
\n
\n
\n

Output

Print the abbreviation of the name of the contest.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

AtCoder Beginner Contest\n
\n
\n
\n
\n
\n

Sample Output 1

ABC\n
\n

The contest in which you are participating now.

\n
\n
\n
\n
\n
\n

Sample Input 2

AtCoder Snuke Contest\n
\n
\n
\n
\n
\n

Sample Output 2

ASC\n
\n

This contest does not actually exist.

\n
\n
\n
\n
\n
\n

Sample Input 3

AtCoder X Contest\n
\n
\n
\n
\n
\n

Sample Output 3

AXC\n
\n
\n
", "id": "codenet-bug-p03860", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

You are given an integer N.
\nFor two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B.
\nFor example, F(3,11) = 2 since 3 has one digit and 11 has two digits.
\nFind the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \\times B.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^{10}
  • \n
  • N is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \\times B.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10000\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

F(A,B) has a minimum value of 3 at (A,B)=(100,100).

\n
\n
\n
\n
\n
\n

Sample Input 2

1000003\n
\n
\n
\n
\n
\n

Sample Output 2

7\n
\n

There are two pairs (A,B) that satisfy the condition: (1,1000003) and (1000003,1). For these pairs, F(1,1000003)=F(1000003,1)=7.

\n
\n
\n
\n
\n
\n

Sample Input 3

9876543210\n
\n
\n
\n
\n
\n

Sample Output 3

6\n
\n
\n
", "id": "codenet-bug-p03775", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.

\n

He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.

\n

Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq K \\leq N \\leq 200000
  • \n
  • 1 \\leq A_i \\leq N
  • \n
  • All input values are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\nA_1 A_2 ... A_N\n
\n
\n
\n
\n
\n

Output

Print the minimum number of balls that Takahashi needs to rewrite the integers on them.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 2\n1 1 2 2 5\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.\nOn the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 4\n1 1 2 2\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.

\n
\n
\n
\n
\n
\n

Sample Input 3

10 3\n5 1 3 2 4 1 1 2 3 4\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n
\n
", "id": "codenet-bug-p03497", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 500 points

\n
\n
\n

Problem Statement

There are N Snuke Cats numbered 1, 2, \\ldots, N, where N is even.

\n

Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.

\n

Recently, they learned the operation called xor (exclusive OR).

\n
\nWhat is xor?\n

\nFor n non-negative integers x_1, x_2, \\ldots, x_n, their xor, x_1~\\textrm{xor}~x_2~\\textrm{xor}~\\ldots~\\textrm{xor}~x_n is defined as follows:\n

    \n
  • When x_1~\\textrm{xor}~x_2~\\textrm{xor}~\\ldots~\\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \\geq 0) is 1 if the number of integers among x_1, x_2, \\ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.
  • \n
\nFor example, 3~\\textrm{xor}~5 = 6.\n

\n
\n

They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.

\n

We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i.\nUsing this information, restore the integer written on the scarf of each Snuke Cat.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 200000
  • \n
  • N is even.
  • \n
  • 0 \\leq a_i \\leq 10^9
  • \n
  • There exists a combination of integers on the scarfs that is consistent with the given information.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\na_1 a_2 \\ldots a_N\n
\n
\n
\n
\n
\n

Output

Print a line containing N integers separated with space.

\n

The i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.

\n

If there are multiple possible solutions, you may print any of them.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n20 11 9 24\n
\n
\n
\n
\n
\n

Sample Output 1

26 5 7 22\n
\n
    \n
  • 5~\\textrm{xor}~7~\\textrm{xor}~22 = 20
  • \n
  • 26~\\textrm{xor}~7~\\textrm{xor}~22 = 11
  • \n
  • 26~\\textrm{xor}~5~\\textrm{xor}~22 = 9
  • \n
  • 26~\\textrm{xor}~5~\\textrm{xor}~7 = 24
  • \n
\n

Thus, this output is consistent with the given information.

\n
\n
", "id": "codenet-bug-p02631", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≦N≦100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the necessary number of candies in total.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n
\n
\n
\n
\n
\n

Sample Output 1

6\n
\n

The answer is 1+2+3=6.

\n
\n
\n
\n
\n
\n

Sample Input 2

10\n
\n
\n
\n
\n
\n

Sample Output 2

55\n
\n

The sum of the integers from 1 to 10 is 55.

\n
\n
\n
\n
\n
\n

Sample Input 3

1\n
\n
\n
\n
\n
\n

Sample Output 3

1\n
\n

Only one child. The answer is 1 in this case.

\n
\n
", "id": "codenet-bug-p04029", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

We have N weights indexed 1 to N. The \bmass of the weight indexed i is W_i.

\n

We will divide these weights into two groups: the weights with indices not greater than T, and those with indices greater than T, for some integer 1 \\leq T < N. Let S_1 be the sum of the masses of the weights in the former group, and S_2 be the sum of the masses of the weights in the latter group.

\n

Consider all possible such divisions and find the minimum possible absolute difference of S_1 and S_2.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 100
  • \n
  • 1 \\leq W_i \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nW_1 W_2 ... W_{N-1} W_N\n
\n
\n
\n
\n
\n

Output

Print the minimum possible absolute difference of S_1 and S_2.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n1 2 3\n
\n
\n
\n
\n
\n

Sample Output 1

0\n
\n

If T = 2, S_1 = 1 + 2 = 3 and S_2 = 3, with the absolute difference of 0.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n1 3 1 1\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n

If T = 2, S_1 = 1 + 3 = 4 and S_2 = 1 + 1 = 2, with the absolute difference of 2. We cannot have a smaller absolute difference.

\n
\n
\n
\n
\n
\n

Sample Input 3

8\n27 23 76 2 3 5 62 52\n
\n
\n
\n
\n
\n

Sample Output 3

2\n
\n
\n
", "id": "codenet-bug-p03012", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given string S and T consisting of lowercase English letters.

\n

Determine if S equals T after rotation.

\n

That is, determine if S equals T after the following operation is performed some number of times:

\n

Operation: Let S = S_1 S_2 ... S_{|S|}. Change S to S_{|S|} S_1 S_2 ... S_{|S|-1}.

\n

Here, |X| denotes the length of the string X.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq |S| \\leq 100
  • \n
  • |S| = |T|
  • \n
  • S and T consist of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\nT\n
\n
\n
\n
\n
\n

Output

If S equals T after rotation, print Yes; if it does not, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

kyoto\ntokyo\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n
    \n
  • In the first operation, kyoto becomes okyot.
  • \n
  • In the second operation, okyot becomes tokyo.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

abc\narc\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

abc does not equal arc after any number of operations.

\n
\n
\n
\n
\n
\n

Sample Input 3

aaaaaaaaaaaaaaab\naaaaaaaaaaaaaaab\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p03293", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^4
  • \n
  • 1 \\leq A \\leq B \\leq 36
  • \n
  • All input values are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N A B\n
\n
\n
\n
\n
\n

Output

Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

20 2 5\n
\n
\n
\n
\n
\n

Sample Output 1

84\n
\n

Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.

\n
\n
\n
\n
\n
\n

Sample Input 2

10 1 2\n
\n
\n
\n
\n
\n

Sample Output 2

13\n
\n
\n
\n
\n
\n
\n

Sample Input 3

100 4 16\n
\n
\n
\n
\n
\n

Sample Output 3

4554\n
\n
\n
", "id": "codenet-bug-p03478", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are N items, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), Item i has a weight of w_i and a value of v_i.

\n

Taro has decided to choose some of the N items and carry them home in a knapsack.\nThe capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.

\n

Find the maximum possible sum of the values of items that Taro takes home.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 100
  • \n
  • 1 \\leq W \\leq 10^5
  • \n
  • 1 \\leq w_i \\leq W
  • \n
  • 1 \\leq v_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N W\nw_1 v_1\nw_2 v_2\n:\nw_N v_N\n
\n
\n
\n
\n
\n

Output

Print the maximum possible sum of the values of items that Taro takes home.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 8\n3 30\n4 50\n5 60\n
\n
\n
\n
\n
\n

Sample Output 1

90\n
\n

Items 1 and 3 should be taken.\nThen, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.

\n
\n
\n
\n
\n
\n

Sample Input 2

5 5\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n
\n
\n
\n
\n
\n

Sample Output 2

5000000000\n
\n

The answer may not fit into a 32-bit integer type.

\n
\n
\n
\n
\n
\n

Sample Input 3

6 15\n6 5\n5 6\n6 4\n6 6\n3 5\n7 2\n
\n
\n
\n
\n
\n

Sample Output 3

17\n
\n

Items 2, 4 and 5 should be taken.\nThen, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.

\n
\n
", "id": "codenet-bug-p03163", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \\ldots, Dish N) once.

\n

The i-th dish (1 \\leq i \\leq N) he ate was Dish A_i.

\n

When he eats Dish i (1 \\leq i \\leq N), he gains B_i satisfaction points.

\n

Additionally, when he eats Dish i+1 just after eating Dish i (1 \\leq i \\leq N - 1), he gains C_i more satisfaction points.

\n

Find the sum of the satisfaction points he gained.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 20
  • \n
  • 1 \\leq A_i \\leq N
  • \n
  • A_1, A_2, ..., A_N are all different.
  • \n
  • 1 \\leq B_i \\leq 50
  • \n
  • 1 \\leq C_i \\leq 50
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 ... A_N\nB_1 B_2 ... B_N\nC_1 C_2 ... C_{N-1}\n
\n
\n
\n
\n
\n

Output

Print the sum of the satisfaction points Takahashi gained, as an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n3 1 2\n2 5 4\n3 6\n
\n
\n
\n
\n
\n

Sample Output 1

14\n
\n

Takahashi gained 14 satisfaction points in total, as follows:

\n
    \n
  • First, he ate Dish 3 and gained 4 satisfaction points.
  • \n
  • Next, he ate Dish 1 and gained 2 satisfaction points.
  • \n
  • Lastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

4\n2 3 4 1\n13 5 8 24\n45 9 15\n
\n
\n
\n
\n
\n

Sample Output 2

74\n
\n
\n
\n
\n
\n
\n

Sample Input 3

2\n1 2\n50 50\n50\n
\n
\n
\n
\n
\n

Sample Output 3

150\n
\n
\n
", "id": "codenet-bug-p02916", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.

\n

The i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1.

\n

You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.

\n

At least how many tiles need to be repainted to satisfy the condition?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq |S| \\leq 10^5
  • \n
  • S_i is 0 or 1.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the minimum number of tiles that need to be repainted to satisfy the condition.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

000\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

The condition can be satisfied by repainting the middle tile white.

\n
\n
\n
\n
\n
\n

Sample Input 2

10010010\n
\n
\n
\n
\n
\n

Sample Output 2

3\n
\n
\n
\n
\n
\n
\n

Sample Input 3

0\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03073", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

Given is a string S consisting of digits from 1 through 9.

\n

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

\n

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ |S| ≤ 200000
  • \n
  • S is a string consisting of digits from 1 through 9.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1817181712114\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

\n
\n
\n
\n
\n
\n

Sample Input 2

14282668646\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n
\n
\n
\n
\n
\n

Sample Input 3

2119\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

No pairs satisfy the condition.

\n
\n
", "id": "codenet-bug-p02702", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.)

\n

Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer.

\n

If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print -1.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A \\leq B \\leq 100
  • \n
  • A and B are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print -1.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 2\n
\n
\n
\n
\n
\n

Sample Output 1

25\n
\n

If the price of a product before tax is 25 yen, the amount of consumption tax levied on it is:

\n
    \n
  • When the consumption tax rate is 8 percent: \\lfloor 25 \\times 0.08 \\rfloor = \\lfloor 2 \\rfloor = 2 yen.
  • \n
  • When the consumption tax rate is 10 percent: \\lfloor 25 \\times 0.1 \\rfloor = \\lfloor 2.5 \\rfloor = 2 yen.
  • \n
\n

Thus, the price of 25 yen satisfies the condition. There are other possible prices, such as 26 yen, but print the minimum such price, 25.

\n
\n
\n
\n
\n
\n

Sample Input 2

8 10\n
\n
\n
\n
\n
\n

Sample Output 2

100\n
\n

If the price of a product before tax is 100 yen, the amount of consumption tax levied on it is:

\n
    \n
  • When the consumption tax rate is 8 percent: \\lfloor 100 \\times 0.08 \\rfloor = 8 yen.
  • \n
  • When the consumption tax rate is 10 percent: \\lfloor 100 \\times 0.1 \\rfloor = 10 yen.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 3

19 99\n
\n
\n
\n
\n
\n

Sample Output 3

-1\n
\n

There is no price before tax satisfying this condition, so print -1.

\n
\n
", "id": "codenet-bug-p02755", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There are N mountains ranging from east to west, and an ocean to the west.

\n

At the top of each mountain, there is an inn. You have decided to choose where to stay from these inns.

\n

The height of the i-th mountain from the west is H_i.

\n

You can certainly see the ocean from the inn at the top of the westmost mountain.

\n

For the inn at the top of the i-th mountain from the west (i = 2, 3, ..., N), you can see the ocean if and only if H_1 \\leq H_i, H_2 \\leq H_i, ..., and H_{i-1} \\leq H_i.

\n

From how many of these N inns can you see the ocean?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 20
  • \n
  • 1 \\leq H_i \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nH_1 H_2 ... H_N\n
\n
\n
\n
\n
\n

Output

Print the number of inns from which you can see the ocean.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n6 5 6 8\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

You can see the ocean from the first, third and fourth inns from the west.

\n
\n
\n
\n
\n
\n

Sample Input 2

5\n4 5 3 5 4\n
\n
\n
\n
\n
\n

Sample Output 2

3\n
\n
\n
\n
\n
\n
\n

Sample Input 3

5\n9 5 6 8 4\n
\n
\n
\n
\n
\n

Sample Output 3

1\n
\n
\n
", "id": "codenet-bug-p03072", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

We have a string S of length N consisting of R, G, and B.

\n

Find the number of triples (i,~j,~k)~(1 \\leq i < j < k \\leq N) that satisfy both of the following conditions:

\n
    \n
  • S_i \\neq S_j, S_i \\neq S_k, and S_j \\neq S_k.
  • \n
  • j - i \\neq k - j.
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 4000
  • \n
  • S is a string of length N consisting of R, G, and B.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS\n
\n
\n
\n
\n
\n

Output

Print the number of triplets in question.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\nRRGB\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

\n
\n
\n
\n
\n
\n

Sample Input 2

39\nRBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB\n
\n
\n
\n
\n
\n

Sample Output 2

1800\n
\n
\n
", "id": "codenet-bug-p02714", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given positive integers A and B.

\n

Find the K-th largest positive integer that divides both A and B.

\n

The input guarantees that there exists such a number.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq A, B \\leq 100
  • \n
  • The K-th largest positive integer that divides both A and B exists.
  • \n
  • K \\geq 1
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B K\n
\n
\n
\n
\n
\n

Output

Print the K-th largest positive integer that divides both A and B.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

8 12 2\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

Three positive integers divides both 8 and 12: 1, 2 and 4.\nAmong them, the second largest is 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

100 50 4\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1 1 1\n
\n
\n
\n
\n
\n

Sample Output 3

1\n
\n
\n
", "id": "codenet-bug-p03106", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.\nGiven two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.

\n
\n\"b4ab979900ed647703389d4349eb84ee.png\"\n
\n
\n
\n
\n
\n

Constraints

    \n
  • x and y are integers.
  • \n
  • 1 ≤ x < y ≤ 12
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
x y\n
\n
\n
\n
\n
\n

Output

If x and y belong to the same group, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 3\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 2

2 4\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n
\n
", "id": "codenet-bug-p03711", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N people standing in a row from west to east.\nEach person is facing east or west.\nThe directions of the people is given as a string S of length N.\nThe i-th person from the west is facing east if S_i = E, and west if S_i = W.

\n

You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader.\nHere, we do not care which direction the leader is facing.

\n

The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized.\nFind the minimum number of people who have to change their directions.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 3 \\times 10^5
  • \n
  • |S| = N
  • \n
  • S_i is E or W.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS\n
\n
\n
\n
\n
\n

Output

Print the minimum number of people who have to change their directions.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\nWEEWW\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

Assume that we appoint the third person from the west as the leader.\nThen, the first person from the west needs to face east and has to turn around.\nThe other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case.\nIt is not possible to have 0 people who have to change their directions, so the answer is 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

12\nWEWEWEEEWWWE\n
\n
\n
\n
\n
\n

Sample Output 2

4\n
\n
\n
\n
\n
\n
\n

Sample Input 3

8\nWWWWWEEE\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n
\n
", "id": "codenet-bug-p03339", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:

\n
    \n
  • the dogs numbered 1,2,\\cdots,26 were respectively given the names a, b, ..., z;
  • \n
  • the dogs numbered 27,28,29,\\cdots,701,702 were respectively given the names aa, ab, ac, ..., zy, zz;
  • \n
  • the dogs numbered 703,704,705,\\cdots,18277,18278 were respectively given the names aaa, aab, aac, ..., zzy, zzz;
  • \n
  • the dogs numbered 18279,18280,18281,\\cdots,475253,475254 were respectively given the names aaaa, aaab, aaac, ..., zzzy, zzzz;
  • \n
  • the dogs numbered 475255,475256,\\cdots were respectively given the names aaaaa, aaaab, ...;
  • \n
  • and so on.
  • \n
\n

To sum it up, the dogs numbered 1, 2, \\cdots were respectively given the following names:

\n

a, b, ..., z, aa, ab, ..., az, ba, bb, ..., bz, ..., za, zb, ..., zz, aaa, aab, ..., aaz, aba, abb, ..., abz, ..., zzz, aaaa, ...

\n

Now, Roger asks you:

\n

\"What is the name for the dog numbered N?\"

\n
\n
\n
\n
\n

Constraints

    \n
  • N is an integer.
  • \n
  • 1 \\leq N \\leq 1000000000000001
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the answer to Roger's question as a string consisting of lowercase English letters.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n
\n
\n
\n
\n
\n

Sample Output 1

b\n
\n
\n
\n
\n
\n
\n

Sample Input 2

27\n
\n
\n
\n
\n
\n

Sample Output 2

aa\n
\n
\n
\n
\n
\n
\n

Sample Input 3

123456789\n
\n
\n
\n
\n
\n

Sample Output 3

jjddja\n
\n
\n
", "id": "codenet-bug-p02629", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9.

\n

Determine whether N is a multiple of 9.

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 \\leq N < 10^{200000}
  • \n
  • N is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

If N is a multiple of 9, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

123456789\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

The sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so 123456789 is a multiple of 9.

\n
\n
\n
\n
\n
\n

Sample Input 2

0\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 3

31415926535897932384626433832795028841971693993751058209749445923078164062862089986280\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
", "id": "codenet-bug-p02577", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Shichi-Go-San (literally \"Seven-Five-Three\") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.

\n

Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ X ≤ 9
  • \n
  • X is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
X\n
\n
\n
\n
\n
\n

Output

If Takahashi's growth will be celebrated, print YES; if it will not, print NO.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

The growth of a five-year-old child will be celebrated.

\n
\n
\n
\n
\n
\n

Sample Input 2

6\n
\n
\n
\n
\n
\n

Sample Output 2

NO\n
\n

See you next year.

\n
\n
", "id": "codenet-bug-p03210", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Joisino wants to evaluate the formula \"A op B\".\nHere, A and B are integers, and the binary operator op is either + or -.\nYour task is to evaluate the formula instead of her.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≦A,B≦10^9
  • \n
  • op is either + or -.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
A op B\n
\n
\n
\n
\n
\n

Output

Evaluate the formula and print the result.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 + 2\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

Since 1 + 2 = 3, the output should be 3.

\n
\n
\n
\n
\n
\n

Sample Input 2

5 - 7\n
\n
\n
\n
\n
\n

Sample Output 2

-2\n
\n
\n
", "id": "codenet-bug-p03844", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Compute A \\times B.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A \\leq 100
  • \n
  • 1 \\leq B \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

Print the value A \\times B as an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 5\n
\n
\n
\n
\n
\n

Sample Output 1

10\n
\n

We have 2 \\times 5 = 10.

\n
\n
\n
\n
\n
\n

Sample Input 2

100 100\n
\n
\n
\n
\n
\n

Sample Output 2

10000\n
\n
\n
", "id": "codenet-bug-p02657", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest.\nIn this game, an honest player always tells the truth, and an dishonest player always tell lies.\nYou are given two characters a and b as the input. Each of them is either H or D, and carries the following information:

\n

If a=H, AtCoDeer is honest; if a=D, AtCoDeer is dishonest.\nIf b=H, AtCoDeer is saying that TopCoDeer is honest; if b=D, AtCoDeer is saying that TopCoDeer is dishonest.

\n

Given this information, determine whether TopCoDeer is honest.

\n
\n
\n
\n
\n

Constraints

    \n
  • a=H or a=D.
  • \n
  • b=H or b=D.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
a b\n
\n
\n
\n
\n
\n

Output

If TopCoDeer is honest, print H. If he is dishonest, print D.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

H H\n
\n
\n
\n
\n
\n

Sample Output 1

H\n
\n

In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.

\n
\n
\n
\n
\n
\n

Sample Input 2

D H\n
\n
\n
\n
\n
\n

Sample Output 2

D\n
\n

In this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest.

\n
\n
\n
\n
\n
\n

Sample Input 3

D D\n
\n
\n
\n
\n
\n

Sample Output 3

H\n
\n
\n
", "id": "codenet-bug-p03777", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Given are two strings S and T.

\n

Let us change some of the characters in S so that T will be a substring of S.

\n

At least how many characters do we need to change?

\n

Here, a substring is a consecutive subsequence. For example, xxx is a substring of yxxxy, but not a substring of xxyxx.

\n
\n
\n
\n
\n

Constraints

    \n
  • The lengths of S and T are each at least 1 and at most 1000.
  • \n
  • The length of T is at most that of S.
  • \n
  • S and T consist of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\nT\n
\n
\n
\n
\n
\n

Output

Print the minimum number of characters in S that need to be changed.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

cabacc\nabc\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

For example, changing the fourth character a in S to c will match the second through fourth characters in S to T.

\n

Since S itself does not have T as its substring, this number of changes - one - is the minimum needed.

\n
\n
\n
\n
\n
\n

Sample Input 2

codeforces\natcoder\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n
\n
", "id": "codenet-bug-p02571", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:

\n
    \n
  • Query i (1 \\leq i \\leq Q): You will be given integers l_i and r_i (1 \\leq l_i < r_i \\leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?
  • \n
\n
\n
\n
\n
\n

Notes

A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.

\n

For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and (the empty string), but not AC.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 10^5
  • \n
  • 1 \\leq Q \\leq 10^5
  • \n
  • S is a string of length N.
  • \n
  • Each character in S is A, C, G or T.
  • \n
  • 1 \\leq l_i < r_i \\leq N
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N Q\nS\nl_1 r_1\n:\nl_Q r_Q\n
\n
\n
\n
\n
\n

Output

Print Q lines. The i-th line should contain the answer to the i-th query.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

8 3\nACACTACG\n3 7\n2 3\n1 8\n
\n
\n
\n
\n
\n

Sample Output 1

2\n0\n3\n
\n
    \n
  • Query 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.
  • \n
  • Query 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.
  • \n
  • Query 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.
  • \n
\n
\n
", "id": "codenet-bug-p03087", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:

\n
    \n
  • 1 \\leq x,y,z
  • \n
  • x^2 + y^2 + z^2 + xy + yz + zx = n
  • \n
\n

Given an integer N, find each of f(1),f(2),f(3),\\ldots,f(N).

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^4
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print N lines. The i-th line should contain the value f(i).

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

20\n
\n
\n
\n
\n
\n

Sample Output 1

0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n3\n0\n0\n0\n0\n0\n3\n3\n0\n0\n
\n
    \n
  • For n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.
  • \n
  • For n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.
  • \n
  • For n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.
  • \n
  • For n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.
  • \n
\n
\n
", "id": "codenet-bug-p02608", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You have a digit sequence S of length 4. You are wondering which of the following formats S is in:

\n
    \n
  • YYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order
  • \n
  • MMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order
  • \n
\n

If S is valid in only YYMM format, print YYMM; if S is valid in only MMYY format, print MMYY; if S is valid in both formats, print AMBIGUOUS; if S is valid in neither format, print NA.

\n
\n
\n
\n
\n

Constraints

    \n
  • S is a digit sequence of length 4.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the specified string: YYMM, MMYY, AMBIGUOUS or NA.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1905\n
\n
\n
\n
\n
\n

Sample Output 1

YYMM\n
\n

May XX19 is a valid date, but 19 is not valid as a month. Thus, this string is only valid in YYMM format.

\n
\n
\n
\n
\n
\n

Sample Input 2

0112\n
\n
\n
\n
\n
\n

Sample Output 2

AMBIGUOUS\n
\n

Both December XX01 and January XX12 are valid dates. Thus, this string is valid in both formats.

\n
\n
\n
\n
\n
\n

Sample Input 3

1700\n
\n
\n
\n
\n
\n

Sample Output 3

NA\n
\n

Neither 0 nor 17 is valid as a month. Thus, this string is valid in neither format.

\n
\n
", "id": "codenet-bug-p03042", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Some number of chocolate pieces were prepared for a training camp.\nThe camp had N participants and lasted for D days.\nThe i-th participant (1 \\leq i \\leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on.\nAs a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.

\n

Find the number of chocolate pieces prepared at the beginning of the camp.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
  • 1 \\leq D \\leq 100
  • \n
  • 1 \\leq X \\leq 100
  • \n
  • 1 \\leq A_i \\leq 100 (1 \\leq i \\leq N)
  • \n
  • All input values are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nD X\nA_1\nA_2\n:\nA_N\n
\n
\n
\n
\n
\n

Output

Find the number of chocolate pieces prepared at the beginning of the camp.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n7 1\n2\n5\n10\n
\n
\n
\n
\n
\n

Sample Output 1

8\n
\n

The camp has 3 participants and lasts for 7 days.\nEach participant eats chocolate pieces as follows:

\n
    \n
  • The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.
  • \n
  • The second participant eats one chocolate piece on Day 1 and 6, for a total of two.
  • \n
  • The third participant eats one chocolate piece only on Day 1, for a total of one.
  • \n
\n

Since the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n8 20\n1\n10\n
\n
\n
\n
\n
\n

Sample Output 2

29\n
\n
\n
\n
\n
\n
\n

Sample Input 3

5\n30 44\n26\n18\n81\n18\n6\n
\n
\n
\n
\n
\n

Sample Output 3

56\n
\n
\n
", "id": "codenet-bug-p03400", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N cubes stacked vertically on a desk.

\n

You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0, and blue if that character is 1.

\n

You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.

\n

At most how many cubes can be removed?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^5
  • \n
  • |S| = N
  • \n
  • Each character in S is 0 or 1.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the maximum number of cubes that can be removed.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

0011\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

All four cubes can be removed, by performing the operation as follows:

\n
    \n
  • Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.
  • \n
  • Remove the first and second cubes from the bottom.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

11011010001011\n
\n
\n
\n
\n
\n

Sample Output 2

12\n
\n
\n
\n
\n
\n
\n

Sample Input 3

0\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03107", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

In order to pass the entrance examination tomorrow, Taro has to study for T more hours.

\n

Fortunately, he can leap to World B where time passes X times as fast as it does in our world (World A).

\n

While (X \\times t) hours pass in World B, t hours pass in World A.

\n

How many hours will pass in World A while Taro studies for T hours in World B?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq T \\leq 100
  • \n
  • 1 \\leq X \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
T X\n
\n
\n
\n
\n
\n

Output

Print the number of hours that will pass in World A.

\n

The output will be regarded as correct when its absolute or relative error from the judge's output is at most 10^{-3}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

8 3\n
\n
\n
\n
\n
\n

Sample Output 1

2.6666666667\n
\n

While Taro studies for eight hours in World B where time passes three times as fast, 2.6666... hours will pass in World A.

\n

Note that an absolute or relative error of at most 10^{-3} is allowed.

\n
\n
\n
\n
\n
\n

Sample Input 2

99 1\n
\n
\n
\n
\n
\n

Sample Output 2

99.0000000000\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1 100\n
\n
\n
\n
\n
\n

Sample Output 3

0.0100000000\n
\n
\n
", "id": "codenet-bug-p03135", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

You are given two non-negative integers L and R.\nWe will choose two integers i and j such that L \\leq i < j \\leq R.\nFind the minimum possible value of (i \\times j) \\mbox{ mod } 2019.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 0 \\leq L < R \\leq 2 \\times 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
L R\n
\n
\n
\n
\n
\n

Output

Print the minimum possible value of (i \\times j) \\mbox{ mod } 2019 when i and j are chosen under the given condition.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2020 2040\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

When (i, j) = (2020, 2021), (i \\times j) \\mbox{ mod } 2019 = 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 5\n
\n
\n
\n
\n
\n

Sample Output 2

20\n
\n

We have only one choice: (i, j) = (4, 5).

\n
\n
", "id": "codenet-bug-p02983", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N stones arranged in a row. Every stone is painted white or black.\nA string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is ., and the stone is black if the character is #.

\n

Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.\nFind the minimum number of stones that needs to be recolored.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 2\\times 10^5
  • \n
  • S is a string of length N consisting of . and #.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS\n
\n
\n
\n
\n
\n

Output

Print the minimum number of stones that needs to be recolored.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n#.#\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

It is enough to change the color of the first stone to white.

\n
\n
\n
\n
\n
\n

Sample Input 2

5\n#.##.\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n
\n
\n
\n
\n
\n

Sample Input 3

9\n.........\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03069", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Serval is fighting with a monster.

\n

The health of the monster is H.

\n

In one attack, Serval can decrease the monster's health by A.\nThere is no other way to decrease the monster's health.

\n

Serval wins when the monster's health becomes 0 or below.

\n

Find the number of attacks Serval needs to make before winning.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq H \\leq 10^4
  • \n
  • 1 \\leq A \\leq 10^4
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
H A\n
\n
\n
\n
\n
\n

Output

Print the number of attacks Serval needs to make before winning.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10 4\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n
    \n
  • After one attack, the monster's health will be 6.
  • \n
  • After two attacks, the monster's health will be 2.
  • \n
  • After three attacks, the monster's health will be -2.
  • \n
\n

Thus, Serval needs to make three attacks to win.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 10000\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

10000 1\n
\n
\n
\n
\n
\n

Sample Output 3

10000\n
\n
\n
", "id": "codenet-bug-p02783", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Given is a sequence of integers A_1, A_2, ..., A_N.\nIf its elements are pairwise distinct, print YES; otherwise, print NO.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 ≤ N ≤ 200000
  • \n
  • 1 ≤ A_i ≤ 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 ... A_N\n
\n
\n
\n
\n
\n

Output

If the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n2 6 1 4 5\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

The elements are pairwise distinct.

\n
\n
\n
\n
\n
\n

Sample Input 2

6\n4 1 3 1 6 2\n
\n
\n
\n
\n
\n

Sample Output 2

NO\n
\n

The second and fourth elements are identical.

\n
\n
\n
\n
\n
\n

Sample Input 3

2\n10000000 10000000\n
\n
\n
\n
\n
\n

Sample Output 3

NO\n
\n
\n
", "id": "codenet-bug-p02779", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There is a string S consisting of digits 1, 2, ..., 9.\nLunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)

\n

The master's favorite number is 753. The closer to this number, the better.\nWhat is the minimum possible (absolute) difference between X and 753?

\n
\n
\n
\n
\n

Constraints

    \n
  • S is a string of length between 4 and 10 (inclusive).
  • \n
  • Each character in S is 1, 2, ..., or 9.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the minimum possible difference between X and 753.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1234567876\n
\n
\n
\n
\n
\n

Sample Output 1

34\n
\n

Taking out the seventh to ninth characters results in X = 787, and the difference between this and 753 is 787 - 753 = 34. The difference cannot be made smaller, no matter where X is taken from.

\n

Note that the digits cannot be rearranged. For example, taking out 567 and rearranging it to 765 is not allowed.

\n

We cannot take out three digits that are not consecutive from S, either. For example, taking out the seventh digit 7, the ninth digit 7 and the tenth digit 6 to obtain 776 is not allowed.

\n
\n
\n
\n
\n
\n

Sample Input 2

35753\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

If 753 itself can be taken out, the answer is 0.

\n
\n
\n
\n
\n
\n

Sample Input 3

1111111111\n
\n
\n
\n
\n
\n

Sample Output 3

642\n
\n

No matter where X is taken from, X = 111, with the difference 753 - 111 = 642.

\n
\n
", "id": "codenet-bug-p03211", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^5
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the number of positive integers less than or equal to N that have an odd number of digits.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

11\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n

Among the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \\ldots, 9.

\n
\n
\n
\n
\n
\n

Sample Input 2

136\n
\n
\n
\n
\n
\n

Sample Output 2

46\n
\n

In addition to 1, 2, \\ldots, 9, another 37 integers also have an odd number of digits: 100, 101, \\ldots, 136.

\n
\n
\n
\n
\n
\n

Sample Input 3

100000\n
\n
\n
\n
\n
\n

Sample Output 3

90909\n
\n
\n
", "id": "codenet-bug-p02952", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

\n

Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.

\n

The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)

\n

Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 101 \\le X \\le 10^{18}
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
X\n
\n
\n
\n
\n
\n

Output

\n

Print the number of years it takes for Takahashi's balance to reach X yen or above for the first time.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

103\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n
    \n
  • The balance after one year is 101 yen.
  • \n
  • The balance after two years is 102 yen.
  • \n
  • The balance after three years is 103 yen.
  • \n
\n

Thus, it takes three years for the balance to reach 103 yen or above.

\n
\n
\n
\n
\n
\n

Sample Input 2

1000000000000000000\n
\n
\n
\n
\n
\n

Sample Output 2

3760\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1333333333\n
\n
\n
\n
\n
\n

Sample Output 3

1706\n
\n
\n
", "id": "codenet-bug-p02694", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Takahashi loves takoyaki - a ball-shaped snack.

\n

With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.

\n

How long does it take to make N takoyaki?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N,X,T \\leq 1000
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N X T\n
\n
\n
\n
\n
\n

Output

Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

20 12 6\n
\n
\n
\n
\n
\n

Sample Output 1

12\n
\n

He can make 12 pieces of takoyaki in the first 6 minutes and 8 more in the next 6 minutes, so he can make 20 in a total of 12 minutes.

\n

Note that being able to make 12 in 6 minutes does not mean he can make 2 in 1 minute.

\n
\n
\n
\n
\n
\n

Sample Input 2

1000 1 1000\n
\n
\n
\n
\n
\n

Sample Output 2

1000000\n
\n

It seems to take a long time to make this kind of takoyaki.

\n
\n
", "id": "codenet-bug-p02576", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\\/\\/\\/ when the following conditions are satisfied:

\n
    \n
  • For each i = 1,2,..., n-2, a_i = a_{i+2}.
  • \n
  • Exactly two different numbers appear in the sequence.
  • \n
\n

You are given a sequence v_1,v_2,...,v_n whose length is even.\nWe would like to make this sequence /\\/\\/\\/ by replacing some of its elements.\nFind the minimum number of elements that needs to be replaced.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq n \\leq 10^5
  • \n
  • n is even.
  • \n
  • 1 \\leq v_i \\leq 10^5
  • \n
  • v_i is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
n\nv_1 v_2 ... v_n\n
\n
\n
\n
\n
\n

Output

Print the minimum number of elements that needs to be replaced.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n3 1 3 2\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

The sequence 3,1,3,2 is not /\\/\\/\\/, but we can make it /\\/\\/\\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

\n
\n
\n
\n
\n
\n

Sample Input 2

6\n105 119 105 119 105 119\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

The sequence 105,119,105,119,105,119 is /\\/\\/\\/.

\n
\n
\n
\n
\n
\n

Sample Input 3

4\n1 1 1 1\n
\n
\n
\n
\n
\n

Sample Output 3

2\n
\n

The elements of the sequence 1,1,1,1 are all the same, so it is not /\\/\\/\\/.

\n
\n
", "id": "codenet-bug-p03244", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There are N apple trees in a row. People say that one of them will bear golden apples.

\n

We want to deploy some number of inspectors so that each of these trees will be inspected.

\n

Each inspector will be deployed under one of the trees. For convenience, we will assign numbers from 1 through N to the trees. An inspector deployed under the i-th tree (1 \\leq i \\leq N) will inspect the trees with numbers between i-D and i+D (inclusive).

\n

Find the minimum number of inspectors that we need to deploy to achieve the objective.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 20
  • \n
  • 1 \\leq D \\leq 20
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N D\n
\n
\n
\n
\n
\n

Output

Print the minimum number of inspectors that we need to deploy to achieve the objective.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6 2\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

We can achieve the objective by, for example, placing an inspector under Tree 3 and Tree 4.

\n
\n
\n
\n
\n
\n

Sample Input 2

14 3\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n
\n
\n
\n
\n
\n

Sample Input 3

20 4\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n
\n
", "id": "codenet-bug-p02970", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi and Aoki will have a battle using their monsters.

\n

The health and strength of Takahashi's monster are A and B, respectively, and those of Aoki's monster are C and D, respectively.

\n

The two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, Aoki's, ...\nHere, an attack decreases the opponent's health by the value equal to the attacker's strength.\nThe monsters keep attacking until the health of one monster becomes 0 or below. The person with the monster whose health becomes 0 or below loses, and the other person wins.

\n

If Takahashi will win, print Yes; if he will lose, print No.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A,B,C,D \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C D\n
\n
\n
\n
\n
\n

Output

If Takahashi will win, print Yes; if he will lose, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10 9 10 10\n
\n
\n
\n
\n
\n

Sample Output 1

No\n
\n

First, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.

\n

Next, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.

\n

Takahashi's monster is the first to have 0 or less health, so Takahashi loses.

\n
\n
\n
\n
\n
\n

Sample Input 2

46 4 40 5\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n
\n
\n
", "id": "codenet-bug-p02700", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi's house has only one socket.

\n

Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.

\n

One power strip with A sockets can extend one empty socket into A empty sockets.

\n

Find the minimum number of power strips required.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq A \\leq 20
  • \n
  • 1 \\leq B \\leq 20
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

Print the minimum number of power strips required.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 10\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.

\n
\n
\n
\n
\n
\n

Sample Input 2

8 9\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n

2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.

\n
\n
\n
\n
\n
\n

Sample Input 3

8 8\n
\n
\n
\n
\n
\n

Sample Output 3

1\n
\n
\n
", "id": "codenet-bug-p02922", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.

\n

You are given an integer N. Find the N-th Lucas number.

\n

Here, the i-th Lucas number L_i is defined as follows:

\n
    \n
  • L_0=2
  • \n
  • L_1=1
  • \n
  • L_i=L_{i-1}+L_{i-2} (i≥2)
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • 1≤N≤86
  • \n
  • It is guaranteed that the answer is less than 10^{18}.
  • \n
  • N is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the N-th Lucas number.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n
\n
\n
\n
\n
\n

Sample Output 1

11\n
\n
    \n
  • L_0=2
  • \n
  • L_1=1
  • \n
  • L_2=L_0+L_1=3
  • \n
  • L_3=L_1+L_2=4
  • \n
  • L_4=L_2+L_3=7
  • \n
  • L_5=L_3+L_4=11
  • \n
\n

Thus, the 5-th Lucas number is 11.

\n
\n
\n
\n
\n
\n

Sample Input 2

86\n
\n
\n
\n
\n
\n

Sample Output 2

939587134549734843\n
\n
\n
", "id": "codenet-bug-p03544", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There is a grid of squares with H horizontal rows and W vertical columns.\nThe square at the i-th row from the top and the j-th column from the left is represented as (i, j).\nEach square is black or white.\nThe color of the square is given as an H-by-W matrix (a_{i, j}).\nIf a_{i, j} is ., the square (i, j) is white; if a_{i, j} is #, the square (i, j) is black.

\n

Snuke is compressing this grid.\nHe will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:

\n
    \n
  • Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.
  • \n
\n

It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.\nFind the final state of the grid.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq H, W \\leq 100
  • \n
  • a_{i, j} is . or #.
  • \n
  • There is at least one black square in the whole grid.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
H W\na_{1, 1}...a_{1, W}\n:\na_{H, 1}...a_{H, W}\n
\n
\n
\n
\n
\n

Output

Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 4\n##.#\n....\n##.#\n.#.#\n
\n
\n
\n
\n
\n

Sample Output 1

###\n###\n.##\n
\n

The second row and the third column in the original grid will be removed.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 3\n#..\n.#.\n..#\n
\n
\n
\n
\n
\n

Sample Output 2

#..\n.#.\n..#\n
\n

As there is no row or column that consists only of white squares, no operation will be performed.

\n
\n
\n
\n
\n
\n

Sample Input 3

4 5\n.....\n.....\n..#..\n.....\n
\n
\n
\n
\n
\n

Sample Output 3

#\n
\n
\n
\n
\n
\n
\n

Sample Input 4

7 6\n......\n....#.\n.#....\n..#...\n..#...\n......\n.#..#.\n
\n
\n
\n
\n
\n

Sample Output 4

..#\n#..\n.#.\n.#.\n#.#\n
\n
\n
", "id": "codenet-bug-p03273", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 100 points

\n
\n
\n

Problem Statement

\n

Takahashi the Jumbo will practice golf.

\n

His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).

\n

If he can achieve the objective, print OK; if he cannot, print NG.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • All values in input are integers.
  • \n
  • 1 \\leq A \\leq B \\leq 1000
  • \n
  • 1 \\leq K \\leq 1000
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
K\nA B\n
\n
\n
\n
\n
\n

Output

\n

If he can achieve the objective, print OK; if he cannot, print NG.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

7\n500 600\n
\n
\n
\n
\n
\n

Sample Output 1

OK\n
\n

Among the multiples of 7, for example, 567 lies between 500 and 600.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n5 7\n
\n
\n
\n
\n
\n

Sample Output 2

NG\n
\n

No multiple of 4 lies between 5 and 7.

\n
\n
\n
\n
\n
\n

Sample Input 3

1\n11 11\n
\n
\n
\n
\n
\n

Sample Output 3

OK\n
\n
\n
", "id": "codenet-bug-p02693", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given two integers A and B as the input. Output the value of A + B.

\n

However, if A + B is 10 or greater, output error instead.

\n
\n
\n
\n
\n

Constraints

    \n
  • A and B are integers.
  • \n
  • 1 ≤ A, B ≤ 9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

If A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6 3\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n
\n
\n
\n
\n
\n

Sample Input 2

6 4\n
\n
\n
\n
\n
\n

Sample Output 2

error\n
\n
\n
", "id": "codenet-bug-p03697", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively.\nAfter repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get:

\n
    \n
  • Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result.
  • \n
\n

However, if the absolute value of the answer exceeds 10^{18}, print Unfair instead.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A,B,C \\leq 10^9
  • \n
  • 0 \\leq K \\leq 10^{18}
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C K\n
\n
\n
\n
\n
\n

Output

Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times.\nIf the absolute value of the answer exceeds 10^{18}, print Unfair instead.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 2 3 1\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

After one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3, respectively. We should print 5-4=1.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 3 2 0\n
\n
\n
\n
\n
\n

Sample Output 2

-1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1000000000 1000000000 1000000000 1000000000000000000\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03345", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

We have held a popularity poll for N items on sale. Item i received A_i votes.

\n

From these N items, we will select M as popular items. However, we cannot select an item with less than \\dfrac{1}{4M} of the total number of votes.

\n

If M popular items can be selected, print Yes; otherwise, print No.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq M \\leq N \\leq 100
  • \n
  • 1 \\leq A_i \\leq 1000
  • \n
  • A_i are distinct.
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\nA_1 ... A_N\n
\n
\n
\n
\n
\n

Output

If M popular items can be selected, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 1\n5 4 2 1\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

There were 12 votes in total. The most popular item received 5 votes, and we can select it.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 2\n380 19 1\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

There were 400 votes in total. The second and third most popular items received less than \\dfrac{1}{4\\times 2} of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.

\n
\n
\n
\n
\n
\n

Sample Input 3

12 3\n4 56 78 901 2 345 67 890 123 45 6 789\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p02718", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi is practicing shiritori alone again today.

\n

Shiritori is a game as follows:

\n
    \n
  • In the first turn, a player announces any one word.
  • \n
  • In the subsequent turns, a player announces a word that satisfies the following conditions:
      \n
    • That word is not announced before.
    • \n
    • The first character of that word is the same as the last character of the last word announced.
    • \n
    \n
  • \n
\n

In this game, he is practicing to announce as many words as possible in ten seconds.

\n

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

\n
\n
\n
\n
\n

Constraints

    \n
  • N is an integer satisfying 2 \\leq N \\leq 100.
  • \n
  • W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nW_1\nW_2\n:\nW_N\n
\n
\n
\n
\n
\n

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\nhoge\nenglish\nhoge\nenigma\n
\n
\n
\n
\n
\n

Sample Output 1

No\n
\n

As hoge is announced multiple times, the rules of shiritori was not observed.

\n
\n
\n
\n
\n
\n

Sample Input 2

9\nbasic\nc\ncpp\nphp\npython\nnadesico\nocaml\nlua\nassembly\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 3

8\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaa\naaaaaaa\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
\n
\n
\n
\n

Sample Input 4

3\nabc\narc\nagc\n
\n
\n
\n
\n
\n

Sample Output 4

No\n
\n
\n
", "id": "codenet-bug-p03261", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 100 points

\n
\n
\n

Problem Statement

\n

In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the \"year-month-day\" order, or the \"month-day\" order without the year.
\nFor example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.

\n

In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.
\nHow many days from 2018-1-1 through 2018-a-b are Takahashi?

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • a is an integer between 1 and 12 (inclusive).
  • \n
  • b is an integer between 1 and 31 (inclusive).
  • \n
  • 2018-a-b is a valid date in Gregorian calendar.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
a b\n
\n
\n
\n
\n
\n

Output

\n

Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 5\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

There are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 1\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

There is only one day that is Takahashi: 1-1.

\n
\n
\n
\n
\n
\n

Sample Input 3

11 30\n
\n
\n
\n
\n
\n

Sample Output 3

11\n
\n

There are eleven days that are Takahashi: 1-1, 2-2, 3-3, 4-4, 5-5, 6-6, 7-7, 8-8, 9-9, 10-10 and 11-11.

\n
\n
", "id": "codenet-bug-p03359", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H).\nYou are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq W,H \\leq 10^9
  • \n
  • 0\\leq x\\leq W
  • \n
  • 0\\leq y\\leq H
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
W H x y\n
\n
\n
\n
\n
\n

Output

Print the maximum possible area of the part whose area is not larger than that of the other, followed by 1 if there are multiple ways to cut the rectangle and achieve that maximum, and 0 otherwise.

\n

The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 3 1 2\n
\n
\n
\n
\n
\n

Sample Output 1

3.000000 0\n
\n

The line x=1 gives the optimal cut, and no other line does.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 2 1 1\n
\n
\n
\n
\n
\n

Sample Output 2

2.000000 1\n
\n
\n
", "id": "codenet-bug-p03001", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:

\n
    \n
  • Choose two among A, B and C, then increase both by 1.
  • \n
  • Choose one among A, B and C, then increase it by 2.
  • \n
\n

It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 \\leq A,B,C \\leq 50
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

Print the minimum number of operations required to make A, B and C all equal.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 5 4\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

We can make A, B and C all equal by the following operations:

\n
    \n
  • Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.
  • \n
  • Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

2 6 3\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n
\n
\n
\n
\n
\n

Sample Input 3

31 41 5\n
\n
\n
\n
\n
\n

Sample Output 3

23\n
\n
\n
", "id": "codenet-bug-p03387", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Given is an integer x that is greater than or equal to 0, and less than or equal to 1.\nOutput 1 if x is equal to 0, or 0 if x is equal to 1.

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 \\leq x \\leq 1
  • \n
  • x is an integer
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
x\n
\n
\n
\n
\n
\n

Output

Print 1 if x is equal to 0, or 0 if x is equal to 1.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1\n
\n
\n
\n
\n
\n

Sample Output 1

0\n
\n
\n
\n
\n
\n
\n

Sample Input 2

0\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n
\n
", "id": "codenet-bug-p02552", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

We have a permutation p = {p_1,\\ p_2,\\ ...,\\ p_n} of {1,\\ 2,\\ ...,\\ n}.

\n

Print the number of elements p_i (1 < i < n) that satisfy the following condition:

\n
    \n
  • p_i is the second smallest number among the three numbers p_{i - 1}, p_i, and p_{i + 1}.
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 3 \\leq n \\leq 20
  • \n
  • p is a permutation of {1,\\ 2,\\ ...,\\ n}.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
n\np_1 p_2 ... p_n\n
\n
\n
\n
\n
\n

Output

Print the number of elements p_i (1 < i < n) that satisfy the condition.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n1 3 5 4 2\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

p_2 = 3 is the second smallest number among p_1 = 1, p_2 = 3, and p_3 = 5. Also, p_4 = 4 is the second smallest number among p_3 = 5, p_4 = 4, and p_5 = 2. These two elements satisfy the condition.

\n
\n
\n
\n
\n
\n

Sample Input 2

9\n9 6 3 2 5 8 7 4 1\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n
\n
", "id": "codenet-bug-p02988", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.

\n

Takahashi says: \"there are X animals in total in the garden, and they have Y legs in total.\" Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq X \\leq 100
  • \n
  • 1 \\leq Y \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
X Y\n
\n
\n
\n
\n
\n

Output

If there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 8\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

The statement \"there are 3 animals in total in the garden, and they have 8 legs in total\" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 100\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

There is no combination of numbers of cranes and turtles in which this statement is correct.

\n
\n
\n
\n
\n
\n

Sample Input 3

1 2\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n

We also consider the case in which there are only cranes or only turtles.

\n
\n
", "id": "codenet-bug-p02640", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

\n

Given is a string S. Replace every character in S with x and print the result.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • S is a string consisting of lowercase English letters.
  • \n
  • The length of S is between 1 and 100 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

\n

Replace every character in S with x and print the result.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

sardine\n
\n
\n
\n
\n
\n

Sample Output 1

xxxxxxx\n
\n

Replacing every character in S with x results in xxxxxxx.

\n
\n
\n
\n
\n
\n

Sample Input 2

xxxx\n
\n
\n
\n
\n
\n

Sample Output 2

xxxx\n
\n
\n
\n
\n
\n
\n

Sample Input 3

gone\n
\n
\n
\n
\n
\n

Sample Output 3

xxxx\n
\n
\n
", "id": "codenet-bug-p02778", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

How many integer sequences A_1,A_2,\\ldots,A_N of length N satisfy all of the following conditions?

\n
    \n
  • 0 \\leq A_i \\leq 9
  • \n
  • There exists some i such that A_i=0 holds.
  • \n
  • There exists some i such that A_i=9 holds.
  • \n
\n

The answer can be very large, so output it modulo 10^9 + 7.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^6
  • \n
  • N is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the answer modulo 10^9 + 7.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

Two sequences \\{0,9\\} and \\{9,0\\} satisfy all conditions.

\n
\n
\n
\n
\n
\n

Sample Input 2

1\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n
\n
\n
\n
\n
\n

Sample Input 3

869121\n
\n
\n
\n
\n
\n

Sample Output 3

2511445\n
\n
\n
", "id": "codenet-bug-p02554", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are a total of A + B cats and dogs.\nAmong them, A are known to be cats, but the remaining B are not known to be either cats or dogs.

\n

Determine if it is possible that there are exactly X cats among these A + B animals.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A \\leq 100
  • \n
  • 1 \\leq B \\leq 100
  • \n
  • 1 \\leq X \\leq 200
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B X\n
\n
\n
\n
\n
\n

Output

If it is possible that there are exactly X cats, print YES; if it is impossible, print NO.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 5 4\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

If there are one cat and four dogs among the B = 5 animals, there are X = 4 cats in total.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 2 6\n
\n
\n
\n
\n
\n

Sample Output 2

NO\n
\n

Even if all of the B = 2 animals are cats, there are less than X = 6 cats in total.

\n
\n
\n
\n
\n
\n

Sample Input 3

5 3 2\n
\n
\n
\n
\n
\n

Sample Output 3

NO\n
\n

Even if all of the B = 3 animals are dogs, there are more than X = 2 cats in total.

\n
\n
", "id": "codenet-bug-p03377", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Given is an integer N.

\n

Takahashi chooses an integer a from the positive integers not greater than N with equal probability.

\n

Find the probability that a is odd.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the probability that a is odd.\nYour output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-6}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n
\n
\n
\n
\n
\n

Sample Output 1

0.5000000000\n
\n

There are four positive integers not greater than 4: 1, 2, 3, and 4. Among them, we have two odd numbers: 1 and 3. Thus, the answer is \\frac{2}{4} = 0.5.

\n
\n
\n
\n
\n
\n

Sample Input 2

5\n
\n
\n
\n
\n
\n

Sample Output 2

0.6000000000\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1\n
\n
\n
\n
\n
\n

Sample Output 3

1.0000000000\n
\n
\n
", "id": "codenet-bug-p02897", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

Takahashi is going to buy N items one by one.

\n

The price of the i-th item he buys is A_i yen (the currency of Japan).

\n

He has M discount tickets, and he can use any number of them when buying an item.

\n

If Y tickets are used when buying an item priced X yen, he can get the item for \\frac{X}{2^Y} (rounded down to the nearest integer) yen.

\n

What is the minimum amount of money required to buy all the items?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N, M \\leq 10^5
  • \n
  • 1 \\leq A_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\nA_1 A_2 ... A_N\n
\n
\n
\n
\n
\n

Output

Print the minimum amount of money required to buy all the items.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 3\n2 13 8\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n

We can buy all the items for 9 yen, as follows:

\n
    \n
  • Buy the 1-st item for 2 yen without tickets.
  • \n
  • Buy the 2-nd item for 3 yen with 2 tickets.
  • \n
  • Buy the 3-rd item for 4 yen with 1 ticket.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

4 4\n1 9 3 5\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1 100000\n1000000000\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

We can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.

\n
\n
\n
\n
\n
\n

Sample Input 4

10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n
\n
\n
\n
\n
\n

Sample Output 4

9500000000\n
\n
\n
", "id": "codenet-bug-p02912", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.

\n

You are given N numbers X_1, X_2, ..., X_N, where N is an even number.\nFor each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.

\n

Find B_i for each i = 1, 2, ..., N.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 200000
  • \n
  • N is even.
  • \n
  • 1 \\leq X_i \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nX_1 X_2 ... X_N\n
\n
\n
\n
\n
\n

Output

Print N lines.\nThe i-th line should contain B_i.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n2 4 4 3\n
\n
\n
\n
\n
\n

Sample Output 1

4\n3\n3\n4\n
\n
    \n
  • Since the median of X_2, X_3, X_4 is 4, B_1 = 4.
  • \n
  • Since the median of X_1, X_3, X_4 is 3, B_2 = 3.
  • \n
  • Since the median of X_1, X_2, X_4 is 3, B_3 = 3.
  • \n
  • Since the median of X_1, X_2, X_3 is 4, B_4 = 4.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

2\n1 2\n
\n
\n
\n
\n
\n

Sample Output 2

2\n1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

6\n5 5 4 4 3 3\n
\n
\n
\n
\n
\n

Sample Output 3

4\n4\n4\n4\n4\n4\n
\n
\n
", "id": "codenet-bug-p03379", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.

\n

Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.

\n
    \n
  • A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B.
  • \n
  • An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students.
  • \n
\n

A string S is assigned indicating attributes of all participants. If the i-th character of string S is a, this means the participant ranked i-th in the Qualification contests is a Japanese student; b means the participant ranked i-th is an overseas student; and c means the participant ranked i-th is neither of these.

\n

Write a program that outputs for all the participants in descending rank either Yes if they passed the Qualification contests or No if they did not pass.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≦N,A,B≦100000
  • \n
  • A+B≦N
  • \n
  • S is N characters long.
  • \n
  • S consists only of the letters a, b and c.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Inputs are provided from Standard Input in the following form.

\n
N A B\nS\n
\n
\n
\n
\n
\n

Output

Output N lines. On the i-th line, output Yes if the i-th participant passed the Qualification contests or No if that participant did not pass.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10 2 3\nabccabaabb\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nNo\n
\n

The first, second, fifth, sixth, and seventh participants pass the Qualification contests.

\n
\n
\n
\n
\n
\n

Sample Input 2

12 5 2\ncabbabaacaba\n
\n
\n
\n
\n
\n

Sample Output 2

No\nYes\nYes\nYes\nYes\nNo\nYes\nYes\nNo\nYes\nNo\nNo\n
\n

The sixth participant is third among overseas students and thus does not pass the Qualification contests.

\n
\n
\n
\n
\n
\n

Sample Input 3

5 2 2\nccccc\n
\n
\n
\n
\n
\n

Sample Output 3

No\nNo\nNo\nNo\nNo\n
\n
\n
", "id": "codenet-bug-p03971", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n
\n
\n

Problem Statement

You are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, , b is positive, negative or zero.

\n
\n
\n
\n
\n

Constraints

    \n
  • a and b are integers.
  • \n
  • -10^9≤a≤b≤10^9
  • \n
\n
\n
\n
\n
\n

Partial Score

    \n
  • In test cases worth 100 points, -10≤a≤b≤10.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
a b\n
\n
\n
\n
\n
\n

Output

If the product is positive, print Positive. If it is negative, print Negative. If it is zero, print Zero.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 3\n
\n
\n
\n
\n
\n

Sample Output 1

Positive\n
\n

1×2×3=6 is positive.

\n
\n
\n
\n
\n
\n

Sample Input 2

-3 -1\n
\n
\n
\n
\n
\n

Sample Output 2

Negative\n
\n

(-3)×(-2)×(-1)=-6 is negative.

\n
\n
\n
\n
\n
\n

Sample Input 3

-1 1\n
\n
\n
\n
\n
\n

Sample Output 3

Zero\n
\n

(-1)×0×1=0.

\n
\n
", "id": "codenet-bug-p04033", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

AtCoDeer the deer is going on a trip in a two-dimensional plane.\nIn his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.

\n

If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1).\nNote that he cannot stay at his place.\nDetermine whether he can carry out his plan.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 N 10^5
  • \n
  • 0 x_i 10^5
  • \n
  • 0 y_i 10^5
  • \n
  • 1 t_i 10^5
  • \n
  • t_i < t_{i+1} (1 i N-1)
  • \n
  • All input values are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nt_1 x_1 y_1\nt_2 x_2 y_2\n:\nt_N x_N y_N\n
\n
\n
\n
\n
\n

Output

If AtCoDeer can carry out his plan, print Yes; if he cannot, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n3 1 2\n6 1 1\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

For example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1), (1,0), then (1,1).

\n
\n
\n
\n
\n
\n

Sample Input 2

1\n2 100 100\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

It is impossible to be at (100,100) two seconds after being at (0,0).

\n
\n
\n
\n
\n
\n

Sample Input 3

2\n5 1 1\n100 1 1\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
", "id": "codenet-bug-p03457", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 200 points

\n
\n
\n

Problem Statement

\n

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.
\nAs the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

\n

Find the N-th smallest integer that would make Ringo happy.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • D is 0, 1 or 2.
  • \n
  • N is an integer between 1 and 100 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
D N\n
\n
\n
\n
\n
\n

Output

\n

Print the N-th smallest integer that can be divided by 100 exactly D times.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

0 5\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...
\nThus, the 5-th smallest integer that would make Ringo happy is 5.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 11\n
\n
\n
\n
\n
\n

Sample Output 2

1100\n
\n

The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \\ 000, 1 \\ 100, ...
\nThus, the integer we are seeking is 1 \\ 100.

\n
\n
\n
\n
\n
\n

Sample Input 3

2 85\n
\n
\n
\n
\n
\n

Sample Output 3

850000\n
\n

The integers that can be divided by 100 exactly twice are as follows: 10 \\ 000, 20 \\ 000, 30 \\ 000, ...
\nThus, the integer we are seeking is 850 \\ 000.

\n
\n
", "id": "codenet-bug-p03324", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

We have two bottles for holding water.

\n

Bottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water.

\n

Bottle 2 contains C milliliters of water.

\n

We will transfer water from Bottle 2 to Bottle 1 as much as possible.

\n

How much amount of water will remain in Bottle 2?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq B \\leq A \\leq 20
  • \n
  • 1 \\leq C \\leq 20
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

Print the integer representing the amount of water, in milliliters, that will remain in Bottle 2.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6 4 3\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

We will transfer two milliliters of water from Bottle 2 to Bottle 1, and one milliliter of water will remain in Bottle 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

8 3 9\n
\n
\n
\n
\n
\n

Sample Output 2

4\n
\n
\n
\n
\n
\n
\n

Sample Input 3

12 3 7\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p02951", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 300 points

\n
\n
\n

Problem Statement

\n

Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:

\n
    \n
  • Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, 7 becomes 7777777, 8 becomes 88888888 and 9 becomes 999999999. 1 remains as 1.
  • \n
\n

For example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next.\nYou are interested in what the string looks like after 5 \\times 10^{15} days. What is the K-th character from the left in the string after 5 \\times 10^{15} days?

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • S is a string of length between 1 and 100 (inclusive).
  • \n
  • K is an integer between 1 and 10^{18} (inclusive).
  • \n
  • The length of the string after 5 \\times 10^{15} days is at least K.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
S\nK\n
\n
\n
\n
\n
\n

Output

\n

Print the K-th character from the left in Mr. Infinity's string after 5 \\times 10^{15} days.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1214\n4\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

The string S changes as follows:

\n
    \n
  • Now: 1214
  • \n
  • After one day: 12214444
  • \n
  • After two days: 1222214444444444444444
  • \n
  • After three days: 12222222214444444444444444444444444444444444444444444444444444444444444444
  • \n
\n

The first five characters in the string after 5 \\times 10^{15} days is 12222. As K=4, we should print the fourth character, 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\n157\n
\n
\n
\n
\n
\n

Sample Output 2

3\n
\n

The initial string is 3. The string after 5 \\times 10^{15} days consists only of 3.

\n
\n
\n
\n
\n
\n

Sample Input 3

299792458\n9460730472580800\n
\n
\n
\n
\n
\n

Sample Output 3

2\n
\n
\n
", "id": "codenet-bug-p03282", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

This contest, AtCoder Beginner Contest, is abbreviated as ABC.

\n

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.

\n

What is the abbreviation for the N-th round of ABC? Write a program to output the answer.

\n
\n
\n
\n
\n

Constraints

    \n
  • 100 ≤ N ≤ 999
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the abbreviation for the N-th round of ABC.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

100\n
\n
\n
\n
\n
\n

Sample Output 1

ABC100\n
\n

The 100th round of ABC is ABC100.

\n
\n
\n
\n
\n
\n

Sample Input 2

425\n
\n
\n
\n
\n
\n

Sample Output 2

ABC425\n
\n
\n
\n
\n
\n
\n

Sample Input 3

999\n
\n
\n
\n
\n
\n

Sample Output 3

ABC999\n
\n
\n
", "id": "codenet-bug-p03643", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

We have sticks numbered 1, \\cdots, N. The length of Stick i (1 \\leq i \\leq N) is L_i.

\n

In how many ways can we choose three of the sticks with different lengths that can form a triangle?

\n

That is, find the number of triples of integers (i, j, k) (1 \\leq i < j < k \\leq N) that satisfy both of the following conditions:

\n
    \n
  • L_i, L_j, and L_k are all different.
  • \n
  • There exists a triangle whose sides have lengths L_i, L_j, and L_k.
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
  • 1 \\leq L_i \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nL_1 L_2 \\cdots L_N\n
\n
\n
\n
\n
\n

Output

Print the number of ways to choose three of the sticks with different lengths that can form a triangle.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n4 4 9 7 5\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

The following five triples (i, j, k) satisfy the conditions: (1, 3, 4), (1, 4, 5), (2, 3, 4), (2, 4, 5), and (3, 4, 5).

\n
\n
\n
\n
\n
\n

Sample Input 2

6\n4 5 4 3 3 5\n
\n
\n
\n
\n
\n

Sample Output 2

8\n
\n

We have two sticks for each of the lengths 3, 4, and 5. To satisfy the first condition, we have to choose one from each length.

\n

There is a triangle whose sides have lengths 3, 4, and 5, so we have 2 ^ 3 = 8 triples (i, j, k) that satisfy the conditions.

\n
\n
\n
\n
\n
\n

Sample Input 3

10\n9 4 6 1 9 6 10 6 6 8\n
\n
\n
\n
\n
\n

Sample Output 3

39\n
\n
\n
\n
\n
\n
\n

Sample Input 4

2\n1 1\n
\n
\n
\n
\n
\n

Sample Output 4

0\n
\n

No triple (i, j, k) satisfies 1 \\leq i < j < k \\leq N, so we should print 0.

\n
\n
", "id": "codenet-bug-p02583", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

\n

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \\leq i \\leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \\leq i \\leq M).

\n

Consider the following action:

\n
    \n
  • Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.
  • \n
\n

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N, M \\leq 200000
  • \n
  • 1 \\leq K \\leq 10^9
  • \n
  • 1 \\leq A_i, B_i \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M K\nA_1 A_2 \\ldots A_N\nB_1 B_2 \\ldots B_M\n
\n
\n
\n
\n
\n

Output

Print an integer representing the maximum number of books that can be read.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 4 240\n60 90 120\n80 150 80 150\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

\n

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

\n
    \n
  • Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.
  • \n
  • Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.
  • \n
  • Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

3 4 730\n60 90 120\n80 150 80 150\n
\n
\n
\n
\n
\n

Sample Output 2

7\n
\n
\n
\n
\n
\n
\n

Sample Input 3

5 4 1\n1000000000 1000000000 1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

Watch out for integer overflows.

\n
\n
", "id": "codenet-bug-p02623", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1\\leq A\\leq B\\leq 10^{18}
  • \n
  • 1\\leq C,D\\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C D\n
\n
\n
\n
\n
\n

Output

Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 9 2 3\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

5 and 7 satisfy the condition.

\n
\n
\n
\n
\n
\n

Sample Input 2

10 40 6 8\n
\n
\n
\n
\n
\n

Sample Output 2

23\n
\n
\n
\n
\n
\n
\n

Sample Input 3

314159265358979323 846264338327950288 419716939 937510582\n
\n
\n
\n
\n
\n

Sample Output 3

532105071133627368\n
\n
\n
", "id": "codenet-bug-p02995", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi has N blue cards and M red cards.\nA string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.

\n

Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.

\n

Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)

\n

At most how much can he earn on balance?

\n

Note that the same string may be written on multiple cards.

\n
\n
\n
\n
\n

Constraints

    \n
  • N and M are integers.
  • \n
  • 1 \\leq N, M \\leq 100
  • \n
  • s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\ns_1\ns_2\n:\ns_N\nM\nt_1\nt_2\n:\nt_M\n
\n
\n
\n
\n
\n

Output

If Takahashi can earn at most X yen on balance, print X.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\napple\norange\napple\n1\ngrape\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

He can earn 2 yen by announcing apple.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\napple\norange\napple\n5\napple\napple\napple\napple\napple\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

If he announces apple, he will lose 3 yen. If he announces orange, he can earn 1 yen.

\n
\n
\n
\n
\n
\n

Sample Input 3

1\nvoldemort\n10\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

If he announces voldemort, he will lose 9 yen. If he announces orange, for example, he can avoid losing a yen.

\n
\n
\n
\n
\n
\n

Sample Input 4

6\nred\nred\nblue\nyellow\nyellow\nred\n5\nred\nred\nyellow\ngreen\nblue\n
\n
\n
\n
\n
\n

Sample Output 4

1\n
\n
\n
", "id": "codenet-bug-p03408", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given two integers A and B.\nFind the largest value among A+B, A-B and A \\times B.

\n
\n
\n
\n
\n

Constraints

    \n
  • -1000 \\leq A,B \\leq 1000
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

Print the largest value among A+B, A-B and A \\times B.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 1\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

3+1=4, 3-1=2 and 3 \\times 1=3. The largest among them is 4.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 -2\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n

The largest is 4 - (-2) = 6.

\n
\n
\n
\n
\n
\n

Sample Input 3

0 0\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03337", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Takahashi has K 500-yen coins. (Yen is the currency of Japan.)\nIf these coins add up to X yen or more, print Yes; otherwise, print No.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq K \\leq 100
  • \n
  • 1 \\leq X \\leq 10^5
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
K X\n
\n
\n
\n
\n
\n

Output

If the coins add up to X yen or more, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 900\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

Two 500-yen coins add up to 1000 yen, which is not less than X = 900 yen.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 501\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

One 500-yen coin is worth 500 yen, which is less than X = 501 yen.

\n
\n
\n
\n
\n
\n

Sample Input 3

4 2000\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n

Four 500-yen coins add up to 2000 yen, which is not less than X = 2000 yen.

\n
\n
", "id": "codenet-bug-p02811", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Snuke lives at position x on a number line.\nOn this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.

\n

Snuke decided to get food delivery from the closer of stores A and B.\nFind out which store is closer to Snuke's residence.

\n

Here, the distance between two points s and t on a number line is represented by |s-t|.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq x \\leq 1000
  • \n
  • 1 \\leq a \\leq 1000
  • \n
  • 1 \\leq b \\leq 1000
  • \n
  • x, a and b are pairwise distinct.
  • \n
  • The distances between Snuke's residence and stores A and B are different.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
x a b\n
\n
\n
\n
\n
\n

Output

If store A is closer, print A; if store B is closer, print B.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 2 7\n
\n
\n
\n
\n
\n

Sample Output 1

B\n
\n

The distances between Snuke's residence and stores A and B are 3 and 2, respectively.\nSince store B is closer, print B.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 999 1000\n
\n
\n
\n
\n
\n

Sample Output 2

A\n
\n
\n
", "id": "codenet-bug-p03623", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.

\n

You can take and complete at most one of these jobs in a day.

\n

However, you cannot retake a job that you have already done.

\n

Find the maximum total reward that you can earn no later than M days from today.

\n

You can already start working today.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 1 \\leq M \\leq 10^5
  • \n
  • 1 \\leq A_i \\leq 10^5
  • \n
  • 1 \\leq B_i \\leq 10^4
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\nA_1 B_1\nA_2 B_2\n\\vdots\nA_N B_N\n
\n
\n
\n
\n
\n

Output

Print the maximum total reward that you can earn no later than M days from today.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 4\n4 3\n4 1\n2 2\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

You can earn the total reward of 5 by taking the jobs as follows:

\n
    \n
  • Take and complete the first job today. You will earn the reward of 3 after four days from today.
  • \n
  • Take and complete the third job tomorrow. You will earn the reward of 2 after two days from tomorrow, that is, after three days from today.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

5 3\n1 2\n1 3\n1 4\n2 1\n2 3\n
\n
\n
\n
\n
\n

Sample Output 2

10\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1 1\n2 1\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p02948", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 200 points

\n
\n
\n

Problem Statement

A country decides to build a palace.

\n

In this country, the average temperature of a point at an elevation of x meters is T-x \\times 0.006 degrees Celsius.

\n

There are N places proposed for the place. The elevation of Place i is H_i meters.

\n

Among them, Princess Joisino orders you to select the place whose average temperature is the closest to A degrees Celsius, and build the palace there.

\n

Print the index of the place where the palace should be built.

\n

It is guaranteed that the solution is unique.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 1000
  • \n
  • 0 \\leq T \\leq 50
  • \n
  • -60 \\leq A \\leq T
  • \n
  • 0 \\leq H_i \\leq 10^5
  • \n
  • All values in input are integers.
  • \n
  • The solution is unique.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nT A\nH_1 H_2 ... H_N\n
\n
\n
\n
\n
\n

Output

Print the index of the place where the palace should be built.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n12 5\n1000 2000\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n
    \n
  • The average temperature of Place 1 is 12-1000 \\times 0.006=6 degrees Celsius.
  • \n
  • The average temperature of Place 2 is 12-2000 \\times 0.006=0 degrees Celsius.
  • \n
\n

Thus, the palace should be built at Place 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\n21 -11\n81234 94124 52141\n
\n
\n
\n
\n
\n

Sample Output 2

3\n
\n
\n
", "id": "codenet-bug-p03220", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Given is a positive integer L.\nFind the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ L ≤ 1000
  • \n
  • L is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
L\n
\n
\n
\n
\n
\n

Output

Print the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.\nYour output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n
\n
\n
\n
\n
\n

Sample Output 1

1.000000000000\n
\n

For example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.

\n

On the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.

\n
\n
\n
\n
\n
\n

Sample Input 2

999\n
\n
\n
\n
\n
\n

Sample Output 2

36926037.000000000000\n
\n
\n
", "id": "codenet-bug-p02731", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

\n

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

\n

Given are N strings s_1, s_2, \\ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \\leq i < j \\leq N) such that s_i is an anagram of s_j.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 10^5
  • \n
  • s_i is a string of length 10.
  • \n
  • Each character in s_i is a lowercase English letter.
  • \n
  • s_1, s_2, \\ldots, s_N are all distinct.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\ns_1\ns_2\n:\ns_N\n
\n
\n
\n
\n
\n

Output

Print the number of pairs of integers i, j (1 \\leq i < j \\leq N) such that s_i is an anagram of s_j.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\nacornistnt\npeanutbomb\nconstraint\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\noneplustwo\nninemodsix\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

\n
\n
\n
\n
\n
\n

Sample Input 3

5\nabaaaaaaaa\noneplustwo\naaaaaaaaba\ntwoplusone\naaaabaaaaa\n
\n
\n
\n
\n
\n

Sample Output 3

4\n
\n

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.

\n
\n
", "id": "codenet-bug-p02947", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Takahashi, who is A years old, is riding a Ferris wheel.

\n

It costs B yen (B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who are 5 years old or younger are free of charge. (Yen is the currency of Japan.)

\n

Find the cost of the Ferris wheel for Takahashi.

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 ≤ A ≤ 100
  • \n
  • 2 ≤ B ≤ 1000
  • \n
  • B is an even number.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

Print the cost of the Ferris wheel for Takahashi.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

30 100\n
\n
\n
\n
\n
\n

Sample Output 1

100\n
\n

Takahashi is 30 years old now, and the cost of the Ferris wheel is 100 yen.

\n
\n
\n
\n
\n
\n

Sample Input 2

12 100\n
\n
\n
\n
\n
\n

Sample Output 2

50\n
\n

Takahashi is 12 years old, and the cost of the Ferris wheel is the half of 100 yen, that is, 50 yen.

\n
\n
\n
\n
\n
\n

Sample Input 3

0 100\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

Takahashi is 0 years old, and he can ride the Ferris wheel for free.

\n
\n
", "id": "codenet-bug-p03035", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

\n

Given is a positive integer N. Consider repeatedly applying the operation below on N:

\n
    \n
  • First, choose a positive integer z satisfying all of the conditions below:
      \n
    • z can be represented as z=p^e, where p is a prime number and e is a positive integer;
    • \n
    • z divides N;
    • \n
    • z is different from all integers chosen in previous operations.
    • \n
    \n
  • \n
  • Then, replace N with N/z.
  • \n
\n

Find the maximum number of times the operation can be applied.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^{12}
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

\n

Print the maximum number of times the operation can be applied.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

24\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

We can apply the operation three times by, for example, making the following choices:

\n
    \n
  • Choose z=2 (=2^1). (Now we have N=12.)
  • \n
  • Choose z=3 (=3^1). (Now we have N=4.)
  • \n
  • Choose z=4 (=2^2). (Now we have N=1.)
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

1\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

We cannot apply the operation at all.

\n
\n
\n
\n
\n
\n

Sample Input 3

64\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n

We can apply the operation three times by, for example, making the following choices:

\n
    \n
  • Choose z=2 (=2^1). (Now we have N=32.)
  • \n
  • Choose z=4 (=2^2). (Now we have N=8.)
  • \n
  • Choose z=8 (=2^3). (Now we have N=1.)
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 4

1000000007\n
\n
\n
\n
\n
\n

Sample Output 4

1\n
\n

We can apply the operation once by, for example, making the following choice:

\n
    \n
  • z=1000000007 (=1000000007^1). (Now we have N=1.)
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 5

997764507000\n
\n
\n
\n
\n
\n

Sample Output 5

7\n
\n
\n
", "id": "codenet-bug-p02660", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

\n

She is shopping, and now paying at the cashier.\nHer total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

\n

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

\n

Find the amount of money that she will hand to the cashier.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≦ N < 10000
  • \n
  • 1 ≦ K < 10
  • \n
  • 0 ≦ D_1 < D_2 < … < D_K≦9
  • \n
  • \\{D_1,D_2,...,D_K\\} ≠ \\{1,2,3,4,5,6,7,8,9\\}
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
N K\nD_1 D_2D_K\n
\n
\n
\n
\n
\n

Output

Print the amount of money that Iroha will hand to the cashier.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1000 8\n1 3 4 5 6 7 8 9\n
\n
\n
\n
\n
\n

Sample Output 1

2000\n
\n

She dislikes all digits except 0 and 2.

\n

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

\n
\n
\n
\n
\n
\n

Sample Input 2

9999 1\n0\n
\n
\n
\n
\n
\n

Sample Output 2

9999\n
\n
\n
", "id": "codenet-bug-p04045", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Find \\displaystyle{\\sum_{a=1}^{K}\\sum_{b=1}^{K}\\sum_{c=1}^{K} \\gcd(a,b,c)}.

\n

Here \\gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq K \\leq 200
  • \n
  • K is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
K\n
\n
\n
\n
\n
\n

Output

Print the value of \\displaystyle{\\sum_{a=1}^{K}\\sum_{b=1}^{K}\\sum_{c=1}^{K} \\gcd(a,b,c)}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n

\\gcd(1,1,1)+\\gcd(1,1,2)+\\gcd(1,2,1)+\\gcd(1,2,2)\n+\\gcd(2,1,1)+\\gcd(2,1,2)+\\gcd(2,2,1)+\\gcd(2,2,2)\n=1+1+1+1+1+1+1+2=9

\n

Thus, the answer is 9.

\n
\n
\n
\n
\n
\n

Sample Input 2

200\n
\n
\n
\n
\n
\n

Sample Output 2

10813692\n
\n
\n
", "id": "codenet-bug-p02713", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

A company has N members, who are assigned ID numbers 1, ..., N.

\n

Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.

\n

When a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.

\n

You are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 2 \\times 10^5
  • \n
  • 1 \\leq A_i < i
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_2 ... A_N\n
\n
\n
\n
\n
\n

Output

For each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n1 1 2 2\n
\n
\n
\n
\n
\n

Sample Output 1

2\n2\n0\n0\n0\n
\n

The member numbered 1 has two immediate subordinates: the members numbered 2 and 3.

\n

The member numbered 2 has two immediate subordinates: the members numbered 4 and 5.

\n

The members numbered 3, 4, and 5 do not have immediate subordinates.

\n
\n
\n
\n
\n
\n

Sample Input 2

10\n1 1 1 1 1 1 1 1 1\n
\n
\n
\n
\n
\n

Sample Output 2

9\n0\n0\n0\n0\n0\n0\n0\n0\n0\n
\n
\n
\n
\n
\n
\n

Sample Input 3

7\n1 2 3 4 5 6\n
\n
\n
\n
\n
\n

Sample Output 3

1\n1\n1\n1\n1\n1\n0\n
\n
\n
", "id": "codenet-bug-p02707", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

In some other world, today is December D-th.

\n

Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.

\n
\n
\n
\n
\n

Constraints

    \n
  • 22 \\leq D \\leq 25
  • \n
  • D is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
D\n
\n
\n
\n
\n
\n

Output

Print the specified string (case-sensitive).

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

25\n
\n
\n
\n
\n
\n

Sample Output 1

Christmas\n
\n
\n
\n
\n
\n
\n

Sample Input 2

22\n
\n
\n
\n
\n
\n

Sample Output 2

Christmas Eve Eve Eve\n
\n

Be sure to print spaces between the words.

\n
\n
", "id": "codenet-bug-p03206", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given three integers A, B and C.\nDetermine whether C is not less than A and not greater than B.

\n
\n
\n
\n
\n

Constraints

    \n
  • -100≤A,B,C≤100
  • \n
  • A, B and C are all integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

If the condition is satisfied, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 3 2\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

C=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.

\n
\n
\n
\n
\n
\n

Sample Input 2

6 5 4\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

C=4 is less than A=6, and thus the output should be No.

\n
\n
\n
\n
\n
\n

Sample Input 3

2 2 2\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p03719", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

\n

We have N+M balls, each of which has an integer written on it.
\nIt is known that:

\n
    \n
  • The numbers written on N of the balls are even.
  • \n
  • The numbers written on M of the balls are odd.
  • \n
\n

Find the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.
\nIt can be shown that this count does not depend on the actual values written on the balls.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 0 \\leq N,M \\leq 100
  • \n
  • 2 \\leq N+M
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N M\n
\n
\n
\n
\n
\n

Output

\n

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 1\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

For example, let us assume that the numbers written on the three balls are 1,2,4.

\n
    \n
  • If we choose the two balls with 1 and 2, the sum is odd;
  • \n
  • If we choose the two balls with 1 and 4, the sum is odd;
  • \n
  • If we choose the two balls with 2 and 4, the sum is even.
  • \n
\n

Thus, the answer is 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 3\n
\n
\n
\n
\n
\n

Sample Output 2

9\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1 1\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
\n
\n
\n
\n

Sample Input 4

13 3\n
\n
\n
\n
\n
\n

Sample Output 4

81\n
\n
\n
\n
\n
\n
\n

Sample Input 5

0 3\n
\n
\n
\n
\n
\n

Sample Output 5

3\n
\n
\n
", "id": "codenet-bug-p02729", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 300 points

\n
\n
\n

Problem Statement

\n

In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)!

\n

There are five means of transport in this empire:

\n
    \n
  • Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.
  • \n
  • Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.
  • \n
  • Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.
  • \n
  • Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.
  • \n
  • Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.
  • \n
\n

For each of them, one vehicle leaves the city at each integer time (time 0, 1, 2, ...).

\n

There is a group of N people at City 1, and they all want to go to City 6.
\nAt least how long does it take for all of them to reach there? \nYou can ignore the time needed to transfer.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 1 \\leq N, A, B, C, D, E \\leq 10^{15}
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\nA\nB\nC\nD\nE\n
\n
\n
\n
\n
\n

Output

\n

Print the minimum time required for all of the people to reach City 6, in minutes.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n3\n2\n4\n3\n5\n
\n
\n
\n
\n
\n

Sample Output 1

7\n
\n

One possible way to travel is as follows.\nFirst, there are N = 5 people at City 1, as shown in the following image:

\n

\"

\n

In the first minute, three people travels from City 1 to City 2 by train. Note that a train can only occupy at most three people.

\n

\"

\n

In the second minute, the remaining two people travels from City 1 to City 2 by train, and two of the three people who were already at City 2 travels to City 3 by bus. Note that a bus can only occupy at most two people.

\n

\"

\n

In the third minute, two people travels from City 2 to City 3 by train, and another two people travels from City 3 to City 4 by taxi.

\n

\"

\n

From then on, if they continue traveling without stopping until they reach City 6, all of them can reach there in seven minutes.
\nThere is no way for them to reach City 6 in 6 minutes or less.

\n
\n
\n
\n
\n
\n

Sample Input 2

10\n123\n123\n123\n123\n123\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n

All kinds of vehicles can occupy N = 10 people at a time.\nThus, if they continue traveling without stopping until they reach City 6, all of them can reach there in five minutes.

\n
\n
\n
\n
\n
\n

Sample Input 3

10000000007\n2\n3\n5\n7\n11\n
\n
\n
\n
\n
\n

Sample Output 3

5000000008\n
\n

Note that the input or output may not fit into a 32-bit integer type.

\n
\n
", "id": "codenet-bug-p03077", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

We have a tree with N vertices numbered 1 to N.\nThe i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i.\nYour objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:

\n
    \n
  • For any two vertices painted in the same color, the distance between them is an even number.
  • \n
\n

Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 1 \\leq u_i < v_i \\leq N
  • \n
  • 1 \\leq w_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nu_1 v_1 w_1\nu_2 v_2 w_2\n.\n.\n.\nu_{N - 1} v_{N - 1} w_{N - 1}\n
\n
\n
\n
\n
\n

Output

Print a coloring of the vertices that satisfies the condition, in N lines.\nThe i-th line should contain 0 if Vertex i is painted white and 1 if it is painted black.

\n

If there are multiple colorings that satisfy the condition, any of them will be accepted.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n1 2 2\n2 3 1\n
\n
\n
\n
\n
\n

Sample Output 1

0\n0\n1\n
\n
\n
\n
\n
\n
\n

Sample Input 2

5\n2 5 2\n2 3 10\n1 3 8\n3 4 2\n
\n
\n
\n
\n
\n

Sample Output 2

1\n0\n1\n0\n1\n
\n
\n
", "id": "codenet-bug-p03044", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 300 points

\n
\n
\n

Problem Statement

\n

Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.

\n

A game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.

\n

When a player correctly answers a question, each of the other N-1 players receives minus one (-1) point. There is no other factor that affects the players' scores.

\n

At the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive.

\n

In the last game, the players gave a total of Q correct answers, the i-th of which was given by Player A_i.\nFor Kizahashi, write a program that determines whether each of the N players survived this game.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 10^5
  • \n
  • 1 \\leq K \\leq 10^9
  • \n
  • 1 \\leq Q \\leq 10^5
  • \n
  • 1 \\leq A_i \\leq N\\ (1 \\leq i \\leq Q)
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N K Q\nA_1\nA_2\n.\n.\n.\nA_Q\n
\n
\n
\n
\n
\n

Output

\n

Print N lines. The i-th line should contain Yes if Player i survived the game, and No otherwise.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6 3 4\n3\n1\n3\n2\n
\n
\n
\n
\n
\n

Sample Output 1

No\nNo\nYes\nNo\nNo\nNo\n
\n

In the beginning, the players' scores are (3, 3, 3, 3, 3, 3).

\n
    \n
  • Player 3 correctly answers a question. The players' scores are now (2, 2, 3, 2, 2, 2).
  • \n
  • Player 1 correctly answers a question. The players' scores are now (2, 1, 2, 1, 1, 1).
  • \n
  • Player 3 correctly answers a question. The players' scores are now (1, 0, 2, 0, 0, 0).
  • \n
  • Player 2 correctly answers a question. The players' scores are now (0, 0, 1, -1, -1, -1).
  • \n
\n

Players 1, 2, 4, 5 and 6, who have 0 points or lower, are eliminated, and Player 3 survives this game.

\n
\n
\n
\n
\n
\n

Sample Input 2

6 5 4\n3\n1\n3\n2\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\nYes\nYes\nYes\nYes\nYes\n
\n
\n
\n
\n
\n
\n

Sample Input 3

10 13 15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9\n
\n
\n
\n
\n
\n

Sample Output 3

No\nNo\nNo\nNo\nYes\nNo\nNo\nNo\nYes\nNo\n
\n
\n
", "id": "codenet-bug-p02911", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

The window of Takahashi's room has a width of A. There are two curtains hung over the window, each of which has a horizontal length of B. (Vertically, the curtains are long enough to cover the whole window.)

\n

We will close the window so as to minimize the total horizontal length of the uncovered part of the window.\nFind the total horizontal length of the uncovered parts of the window then.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A \\leq 100
  • \n
  • 1 \\leq B \\leq 100
  • \n
  • A and B are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

Print the total horizontal length of the uncovered parts of the window.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

12 4\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

We have a window with a horizontal length of 12, and two curtains, each of length 4, that cover both ends of the window, for example. The uncovered part has a horizontal length of 4.

\n
\n
\n
\n
\n
\n

Sample Input 2

20 15\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

If the window is completely covered, print 0.

\n
\n
\n
\n
\n
\n

Sample Input 3

20 30\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

Each curtain may be longer than the window.

\n
\n
", "id": "codenet-bug-p02885", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given three integers, A, B and C.
\nAmong them, two are the same, but the remaining one is different from the rest.
\nFor example, when A=5,B=7,C=5, A and C are the same, but B is different.
\nFind the one that is different from the rest among the given three integers.

\n
\n
\n
\n
\n

Constraints

    \n
  • -100 \\leq A,B,C \\leq 100
  • \n
  • A, B and C are integers.
  • \n
  • The input satisfies the condition in the statement.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

Among A, B and C, print the integer that is different from the rest.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 7 5\n
\n
\n
\n
\n
\n

Sample Output 1

7\n
\n

This is the same case as the one in the statement.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 1 7\n
\n
\n
\n
\n
\n

Sample Output 2

7\n
\n

In this case, C is the one we seek.

\n
\n
\n
\n
\n
\n

Sample Input 3

-100 100 100\n
\n
\n
\n
\n
\n

Sample Output 3

-100\n
\n
\n
", "id": "codenet-bug-p03573", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes:

\n
    \n
  • Red boxes, each containing R red balls
  • \n
  • Green boxes, each containing G green balls
  • \n
  • Blue boxes, each containing B blue balls
  • \n
\n

Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes.\nHow many triples of non-negative integers (r,g,b) achieve this?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq R,G,B,N \\leq 3000
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
R G B N\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 2 3 4\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

Four triples achieve the objective, as follows:

\n
    \n
  • (4,0,0)
  • \n
  • (2,1,0)
  • \n
  • (1,0,1)
  • \n
  • (0,2,0)
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

13 1 4 3000\n
\n
\n
\n
\n
\n

Sample Output 2

87058\n
\n
\n
", "id": "codenet-bug-p03048", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

How many multiples of d are there among the integers between L and R (inclusive)?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq L \\leq R \\leq 100
  • \n
  • 1 \\leq d \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
L R d\n
\n
\n
\n
\n
\n

Output

Print the number of multiples of d among the integers between L and R (inclusive).

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 10 2\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n
    \n
  • Among the integers between 5 and 10, there are three multiples of 2: 6, 8, and 10.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

6 20 7\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n
    \n
  • Among the integers between 6 and 20, there are two multiples of 7: 7 and 14.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 3

1 100 1\n
\n
\n
\n
\n
\n

Sample Output 3

100\n
\n
\n
", "id": "codenet-bug-p02606", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

It is known that the area of a regular dodecagon inscribed in a circle of radius a is 3a^2.

\n

Given an integer r, find the area of a regular dodecagon inscribed in a circle of radius r.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq r \\leq 100
  • \n
  • r is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
r\n
\n
\n
\n
\n
\n

Output

Print an integer representing the area of the regular dodecagon.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n
\n
\n
\n
\n
\n

Sample Output 1

48\n
\n

The area of the regular dodecagon is 3 \\times 4^2 = 48.

\n
\n
\n
\n
\n
\n

Sample Input 2

15\n
\n
\n
\n
\n
\n

Sample Output 2

675\n
\n
\n
\n
\n
\n
\n

Sample Input 3

80\n
\n
\n
\n
\n
\n

Sample Output 3

19200\n
\n
\n
", "id": "codenet-bug-p02969", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).

\n

We will collect all of these balls, by choosing two integers p and q such that p \\neq 0 or q \\neq 0 and then repeating the following operation:

\n
    \n
  • Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
  • \n
\n

Find the minimum total cost required to collect all the balls when we optimally choose p and q.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 50
  • \n
  • |x_i|, |y_i| \\leq 10^9
  • \n
  • If i \\neq j, x_i \\neq x_j or y_i \\neq y_j.
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nx_1 y_1\n:\nx_N y_N\n
\n
\n
\n
\n
\n

Output

Print the minimum total cost required to collect all the balls.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n1 1\n2 2\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

If we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by collecting them in the order (1, 1), (2, 2).

\n
\n
\n
\n
\n
\n

Sample Input 2

3\n1 4\n4 6\n7 8\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

If we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by collecting them in the order (7, 8), (4, 6), (1, 4).

\n
\n
\n
\n
\n
\n

Sample Input 3

4\n1 1\n1 2\n2 1\n2 2\n
\n
\n
\n
\n
\n

Sample Output 3

2\n
\n
\n
", "id": "codenet-bug-p03006", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Given are integers a,b,c and d.\nIf x and y are integers and a \\leq x \\leq b and c\\leq y \\leq d hold, what is the maximum possible value of x \\times y?

\n
\n
\n
\n
\n

Constraints

    \n
  • -10^9 \\leq a \\leq b \\leq 10^9
  • \n
  • -10^9 \\leq c \\leq d \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
a b c d\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 2 1 1\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

If x = 1 and y = 1 then x \\times y = 1.\nIf x = 2 and y = 1 then x \\times y = 2.\nTherefore, the answer is 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 5 -4 -2\n
\n
\n
\n
\n
\n

Sample Output 2

-6\n
\n

The answer can be negative.

\n
\n
\n
\n
\n
\n

Sample Input 3

-1000000000 0 -1000000000 0\n
\n
\n
\n
\n
\n

Sample Output 3

1000000000000000000\n
\n
\n
", "id": "codenet-bug-p02553", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 400 points

\n
\n
\n

Problem Statement

\n

Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.

\n

Let the current time be time 0. Kizahashi has N jobs numbered 1 to N.

\n

It takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.

\n

Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.

\n

Can Kizahashi complete all the jobs in time? If he can, print Yes; if he cannot, print No.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 2 \\times 10^5
  • \n
  • 1 \\leq A_i, B_i \\leq 10^9 (1 \\leq i \\leq N)
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\nA_1 B_1\n.\n.\n.\nA_N B_N\n
\n
\n
\n
\n
\n

Output

\n

If Kizahashi can complete all the jobs in time, print Yes; if he cannot, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n2 4\n1 9\n1 8\n4 9\n3 12\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

He can complete all the jobs in time by, for example, doing them in the following order:

\n
    \n
  • Do Job 2 from time 0 to 1.
  • \n
  • Do Job 1 from time 1 to 3.
  • \n
  • Do Job 4 from time 3 to 7.
  • \n
  • Do Job 3 from time 7 to 8.
  • \n
  • Do Job 5 from time 8 to 11.
  • \n
\n

Note that it is fine to complete Job 3 exactly at the deadline, time 8.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\n334 1000\n334 1000\n334 1000\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

He cannot complete all the jobs in time, no matter what order he does them in.

\n
\n
\n
\n
\n
\n

Sample Input 3

30\n384 8895\n1725 9791\n170 1024\n4 11105\n2 6\n578 1815\n702 3352\n143 5141\n1420 6980\n24 1602\n849 999\n76 7586\n85 5570\n444 4991\n719 11090\n470 10708\n1137 4547\n455 9003\n110 9901\n15 8578\n368 3692\n104 1286\n3 4\n366 12143\n7 6649\n610 2374\n152 7324\n4 7042\n292 11386\n334 5720\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p02996", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between.\nPrint the acronym formed from the uppercased initial letters of the words.

\n
\n
\n
\n
\n

Constraints

    \n
  • s_1, s_2 and s_3 are composed of lowercase English letters.
  • \n
  • 1 ≤ |s_i| ≤ 10 (1≤i≤3)
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
s_1 s_2 s_3\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

atcoder beginner contest\n
\n
\n
\n
\n
\n

Sample Output 1

ABC\n
\n

The initial letters of atcoder, beginner and contest are a, b and c. Uppercase and concatenate them to obtain ABC.

\n
\n
\n
\n
\n
\n

Sample Input 2

resident register number\n
\n
\n
\n
\n
\n

Sample Output 2

RRN\n
\n
\n
\n
\n
\n
\n

Sample Input 3

k nearest neighbor\n
\n
\n
\n
\n
\n

Sample Output 3

KNN\n
\n
\n
\n
\n
\n
\n

Sample Input 4

async layered coding\n
\n
\n
\n
\n
\n

Sample Output 4

ALC\n
\n
\n
", "id": "codenet-bug-p03737", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

We will buy a product for N yen (the currency of Japan) at a shop.

\n

If we use only 1000-yen bills to pay the price, how much change will we receive?

\n

Assume we use the minimum number of bills required.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10000
  • \n
  • N is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the amount of change as an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1900\n
\n
\n
\n
\n
\n

Sample Output 1

100\n
\n

We will use two 1000-yen bills to pay the price and receive 100 yen in change.

\n
\n
\n
\n
\n
\n

Sample Input 2

3000\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

We can pay the exact price.

\n
\n
", "id": "codenet-bug-p02612", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

AtCoDeer has three cards, one red, one green and one blue.
\nAn integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.
\nWe will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.
\nIs this integer a multiple of 4?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ r, g, b ≤ 9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
r g b\n
\n
\n
\n
\n
\n

Output

If the three-digit integer is a multiple of 4, print YES (case-sensitive); otherwise, print NO.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 3 2\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

432 is a multiple of 4, and thus YES should be printed.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 3 4\n
\n
\n
\n
\n
\n

Sample Output 2

NO\n
\n

234 is not a multiple of 4, and thus NO should be printed.

\n
\n
", "id": "codenet-bug-p03693", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

In \"Takahashi-ya\", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions).

\n

A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is o, it means the ramen should be topped with boiled egg; if that character is x, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen.

\n

Write a program that, when S is given, prints the price of the corresponding bowl of ramen.

\n
\n
\n
\n
\n

Constraints

    \n
  • S is a string of length 3.
  • \n
  • Each character in S is o or x.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the price of the bowl of ramen corresponding to S.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

oxo\n
\n
\n
\n
\n
\n

Sample Output 1

900\n
\n

The price of a ramen topped with two kinds of toppings, boiled egg and green onions, is 700 + 100 \\times 2 = 900 yen.

\n
\n
\n
\n
\n
\n

Sample Input 2

ooo\n
\n
\n
\n
\n
\n

Sample Output 2

1000\n
\n

The price of a ramen topped with all three kinds of toppings is 700 + 100 \\times 3 = 1000 yen.

\n
\n
\n
\n
\n
\n

Sample Input 3

xxx\n
\n
\n
\n
\n
\n

Sample Output 3

700\n
\n

The price of a ramen without any toppings is 700 yen.

\n
\n
", "id": "codenet-bug-p03369", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Given an integer a as input, print the value a + a^2 + a^3.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq a \\leq 10
  • \n
  • a is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
a\n
\n
\n
\n
\n
\n

Output

Print the value a + a^2 + a^3 as an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n
\n
\n
\n
\n
\n

Sample Output 1

14\n
\n

When a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.

\n

Print the answer as an input. Outputs such as 14.0 will be judged as incorrect.

\n
\n
\n
\n
\n
\n

Sample Input 2

10\n
\n
\n
\n
\n
\n

Sample Output 2

1110\n
\n
\n
", "id": "codenet-bug-p02621", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

A programming competition site AtCode regularly holds programming contests.

\n

The next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.

\n

The contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.

\n

The contest after the ARC is called AGC, which is rated for all contestants.

\n

Takahashi's rating on AtCode is R. What is the next contest rated for him?

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 ≤ R ≤ 4208
  • \n
  • R is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
R\n
\n
\n
\n
\n
\n

Output

Print the name of the next contest rated for Takahashi (ABC, ARC or AGC).

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1199\n
\n
\n
\n
\n
\n

Sample Output 1

ABC\n
\n

1199 is less than 1200, so ABC will be rated.

\n
\n
\n
\n
\n
\n

Sample Input 2

1200\n
\n
\n
\n
\n
\n

Sample Output 2

ARC\n
\n

1200 is not less than 1200 and ABC will be unrated, but it is less than 2800 and ARC will be rated.

\n
\n
\n
\n
\n
\n

Sample Input 3

4208\n
\n
\n
\n
\n
\n

Sample Output 3

AGC\n
\n
\n
", "id": "codenet-bug-p03288", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.

\n

More specifically, in one move, he can go from coordinate x to x + D or x - D.

\n

He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.

\n

Find the minimum possible absolute value of the coordinate of the destination.

\n
\n
\n
\n
\n

Constraints

    \n
  • -10^{15} \\leq X \\leq 10^{15}
  • \n
  • 1 \\leq K \\leq 10^{15}
  • \n
  • 1 \\leq D \\leq 10^{15}
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
X K D\n
\n
\n
\n
\n
\n

Output

Print the minimum possible absolute value of the coordinate of the destination.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6 2 4\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

Takahashi is now at coordinate 6. It is optimal to make the following moves:

\n
    \n
  • Move from coordinate 6 to (6 - 4 =) 2.
  • \n
  • Move from coordinate 2 to (2 - 4 =) -2.
  • \n
\n

Here, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.

\n
\n
\n
\n
\n
\n

Sample Input 2

7 4 3\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

Takahashi is now at coordinate 7. It is optimal to make, for example, the following moves:

\n
    \n
  • Move from coordinate 7 to 4.
  • \n
  • Move from coordinate 4 to 7.
  • \n
  • Move from coordinate 7 to 4.
  • \n
  • Move from coordinate 4 to 1.
  • \n
\n

Here, the absolute value of the coordinate of the destination is 1, and we cannot make it smaller.

\n
\n
\n
\n
\n
\n

Sample Input 3

10 1 2\n
\n
\n
\n
\n
\n

Sample Output 3

8\n
\n
\n
\n
\n
\n
\n

Sample Input 4

1000000000000000 1000000000000000 1000000000000000\n
\n
\n
\n
\n
\n

Sample Output 4

1000000000000000\n
\n

The answer can be enormous.

\n
\n
", "id": "codenet-bug-p02584", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given an integer sequence A of length N.\nFind the maximum absolute difference of two elements (with different indices) in A.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 100
  • \n
  • 1 \\leq A_i \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 ... A_N\n
\n
\n
\n
\n
\n

Output

Print the maximum absolute difference of two elements (with different indices) in A.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n1 4 6 3\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

The maximum absolute difference of two elements is A_3-A_1=6-1=5.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n1000000000 1\n
\n
\n
\n
\n
\n

Sample Output 2

999999999\n
\n
\n
\n
\n
\n
\n

Sample Input 3

5\n1 1 1 1 1\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03308", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains 5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)

\n

Takahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?

\n

(We assume that there are six kinds of coins available: 500-yen, 100-yen, 50-yen, 10-yen, 5-yen, and 1-yen coins.)

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 \\leq X \\leq 10^9
  • \n
  • X is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
X\n
\n
\n
\n
\n
\n

Output

Print the maximum number of happiness points that can be earned.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1024\n
\n
\n
\n
\n
\n

Sample Output 1

2020\n
\n

By exchanging his money so that he gets two 500-yen coins and four 5-yen coins, he gains 2020 happiness points, which is the maximum number of happiness points that can be earned.

\n
\n
\n
\n
\n
\n

Sample Input 2

0\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

He is penniless - or yenless.

\n
\n
\n
\n
\n
\n

Sample Input 3

1000000000\n
\n
\n
\n
\n
\n

Sample Output 3

2000000000\n
\n

He is a billionaire - in yen.

\n
\n
", "id": "codenet-bug-p02724", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

An elementary school student Takahashi has come to a variety store.

\n

He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?

\n

Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.

\n
\n
\n
\n
\n

Constraints

    \n
  • All input values are integers.
  • \n
  • 1 \\leq A, B \\leq 500
  • \n
  • 1 \\leq C \\leq 1000
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

If Takahashi can buy the toy, print Yes; if he cannot, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

50 100 120\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

He has 50 + 100 = 150 yen, so he can buy the 120-yen toy.

\n
\n
\n
\n
\n
\n

Sample Input 2

500 100 1000\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

He has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.

\n
\n
\n
\n
\n
\n

Sample Input 3

19 123 143\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n

There are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard to use.

\n
\n
\n
\n
\n
\n

Sample Input 4

19 123 142\n
\n
\n
\n
\n
\n

Sample Output 4

Yes\n
\n
\n
", "id": "codenet-bug-p03407", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

When Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.

\n

You, the smartwatch, has found N routes to his home.

\n

If Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.

\n

Find the smallest cost of a route that takes not longer than time T.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 100
  • \n
  • 1 \\leq T \\leq 1000
  • \n
  • 1 \\leq c_i \\leq 1000
  • \n
  • 1 \\leq t_i \\leq 1000
  • \n
  • The pairs (c_i, t_i) are distinct.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N T\nc_1 t_1\nc_2 t_2\n:\nc_N t_N\n
\n
\n
\n
\n
\n

Output

Print the smallest cost of a route that takes not longer than time T.

\n

If there is no route that takes not longer than time T, print TLE instead.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 70\n7 60\n1 80\n4 50\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n
    \n
  • The first route gets him home at cost 7.
  • \n
  • The second route takes longer than time T = 70.
  • \n
  • The third route gets him home at cost 4.
  • \n
\n

Thus, the cost 4 of the third route is the minimum.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 3\n1 1000\n2 4\n3 1000\n4 500\n
\n
\n
\n
\n
\n

Sample Output 2

TLE\n
\n

There is no route that takes not longer than time T = 3.

\n
\n
\n
\n
\n
\n

Sample Input 3

5 9\n25 8\n5 9\n4 10\n1000 1000\n6 1\n
\n
\n
\n
\n
\n

Sample Output 3

5\n
\n
\n
", "id": "codenet-bug-p03239", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You will be given a string S of length 3 representing the weather forecast for three days in the past.

\n

The i-th character (1 \\leq i \\leq 3) of S represents the forecast for the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.

\n

You will also be given a string T of length 3 representing the actual weather on those three days.

\n

The i-th character (1 \\leq i \\leq 3) of S represents the actual weather on the i-th day. S, C, and R stand for sunny, cloudy, and rainy, respectively.

\n

Print the number of days for which the forecast was correct.

\n
\n
\n
\n
\n

Constraints

    \n
  • S and T are strings of length 3 each.
  • \n
  • S and T consist of S, C, and R.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\nT\n
\n
\n
\n
\n
\n

Output

Print the number of days for which the forecast was correct.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

CSS\nCSR\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n
    \n
  • For the first day, it was forecast to be cloudy, and it was indeed cloudy.
  • \n
  • For the second day, it was forecast to be sunny, and it was indeed sunny.
  • \n
  • For the third day, it was forecast to be sunny, but it was rainy.
  • \n
\n

Thus, the forecast was correct for two days in this case.

\n
\n
\n
\n
\n
\n

Sample Input 2

SSR\nSSR\n
\n
\n
\n
\n
\n

Sample Output 2

3\n
\n
\n
\n
\n
\n
\n

Sample Input 3

RRR\nSSS\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p02921", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Given are three integers A_1, A_2, and A_3.

\n

If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A_i \\leq 13 \\ \\ (i=1,2,3)
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A_1 A_2 A_3\n
\n
\n
\n
\n
\n

Output

If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 7 9\n
\n
\n
\n
\n
\n

Sample Output 1

win\n
\n

5+7+9=21, so print win.

\n
\n
\n
\n
\n
\n

Sample Input 2

13 7 2\n
\n
\n
\n
\n
\n

Sample Output 2

bust\n
\n

13+7+2=22, so print bust.

\n
\n
", "id": "codenet-bug-p02835", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

\n

We have N balls. The i-th ball has an integer A_i written on it.
\nFor each k=1, 2, ..., N, solve the following problem and print the answer.

\n
    \n
  • Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.
  • \n
\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 3 \\leq N \\leq 2 \\times 10^5
  • \n
  • 1 \\leq A_i \\leq N
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 ... A_N\n
\n
\n
\n
\n
\n

Output

\n

For each k=1,2,...,N, print a line containing the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n1 1 2 1 2\n
\n
\n
\n
\n
\n

Sample Output 1

2\n2\n3\n2\n3\n
\n

Consider the case k=1 for example. The numbers written on the remaining balls are 1,2,1,2.
\nFrom these balls, there are two ways to choose two distinct balls so that the integers written on them are equal.
\nThus, the answer for k=1 is 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n1 2 3 4\n
\n
\n
\n
\n
\n

Sample Output 2

0\n0\n0\n0\n
\n

No two balls have equal numbers written on them.

\n
\n
\n
\n
\n
\n

Sample Input 3

5\n3 3 3 3 3\n
\n
\n
\n
\n
\n

Sample Output 3

6\n6\n6\n6\n6\n
\n

Any two balls have equal numbers written on them.

\n
\n
\n
\n
\n
\n

Sample Input 4

8\n1 2 1 4 2 1 4 1\n
\n
\n
\n
\n
\n

Sample Output 4

5\n7\n5\n7\n7\n5\n7\n5\n
\n
\n
", "id": "codenet-bug-p02732", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

We have a sequence p = {p_1,\\ p_2,\\ ...,\\ p_N} which is a permutation of {1,\\ 2,\\ ...,\\ N}.

\n

You can perform the following operation at most once: choose integers i and j (1 \\leq i < j \\leq N), and swap p_i and p_j. Note that you can also choose not to perform it.

\n

Print YES if you can sort p in ascending order in this way, and NO otherwise.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 50
  • \n
  • p is a permutation of {1,\\ 2,\\ ...,\\ N}.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\np_1 p_2 ... p_N\n
\n
\n
\n
\n
\n

Output

Print YES if you can sort p in ascending order in the way stated in the problem statement, and NO otherwise.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n5 2 3 4 1\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

You can sort p in ascending order by swapping p_1 and p_5.

\n
\n
\n
\n
\n
\n

Sample Input 2

5\n2 4 3 5 1\n
\n
\n
\n
\n
\n

Sample Output 2

NO\n
\n

In this case, swapping any two elements does not sort p in ascending order.

\n
\n
\n
\n
\n
\n

Sample Input 3

7\n1 2 3 4 5 6 7\n
\n
\n
\n
\n
\n

Sample Output 3

YES\n
\n

p is already sorted in ascending order, so no operation is needed.

\n
\n
", "id": "codenet-bug-p02958", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There are N children, numbered 1, 2, ..., N.

\n

Snuke has decided to distribute x sweets among them.\nHe needs to give out all the x sweets, but some of the children may get zero sweets.

\n

For each i (1 \\leq i \\leq N), Child i will be happy if he/she gets exactly a_i sweets.\nSnuke is trying to maximize the number of happy children by optimally distributing the sweets.\nFind the maximum possible number of happy children.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 100
  • \n
  • 1 \\leq x \\leq 10^9
  • \n
  • 1 \\leq a_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N x\na_1 a_2 ... a_N\n
\n
\n
\n
\n
\n

Output

Print the maximum possible number of happy children.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 70\n20 30 10\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

One optimal way to distribute sweets is (20, 30, 20).

\n
\n
\n
\n
\n
\n

Sample Input 2

3 10\n20 30 10\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

The optimal way to distribute sweets is (0, 0, 10).

\n
\n
\n
\n
\n
\n

Sample Input 3

4 1111\n1 10 100 1000\n
\n
\n
\n
\n
\n

Sample Output 3

4\n
\n

The optimal way to distribute sweets is (1, 10, 100, 1000).

\n
\n
\n
\n
\n
\n

Sample Input 4

2 10\n20 20\n
\n
\n
\n
\n
\n

Sample Output 4

0\n
\n

No children will be happy, no matter how the sweets are distributed.

\n
\n
", "id": "codenet-bug-p03254", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There is a circular pond with a perimeter of K meters, and N houses around them.

\n

The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.

\n

When traveling between these houses, you can only go around the pond.

\n

Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq K \\leq 10^6
  • \n
  • 2 \\leq N \\leq 2 \\times 10^5
  • \n
  • 0 \\leq A_1 < ... < A_N < K
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
K N\nA_1 A_2 ... A_N\n
\n
\n
\n
\n
\n

Output

Print the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

20 3\n5 10 15\n
\n
\n
\n
\n
\n

Sample Output 1

10\n
\n

If you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.

\n
\n
\n
\n
\n
\n

Sample Input 2

20 3\n0 5 15\n
\n
\n
\n
\n
\n

Sample Output 2

10\n
\n

If you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.

\n
\n
", "id": "codenet-bug-p02725", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You have an integer variable x.\nInitially, x=0.

\n

Some person gave you a string S of length N, and using the string you performed the following operation N times.\nIn the i-th operation, you incremented the value of x by 1 if S_i=I, and decremented the value of x by 1 if S_i=D.

\n

Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≤N≤100
  • \n
  • |S|=N
  • \n
  • No characters except I and D occur in S.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
N\nS\n
\n
\n
\n
\n
\n

Output

Print the maximum value taken by x during the operations.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\nIIDID\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

After each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively. Thus, the output should be 2, the maximum value.

\n
\n
\n
\n
\n
\n

Sample Input 2

7\nDDIDDII\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

The initial value x=0 is the maximum value taken by x, thus the output should be 0.

\n
\n
", "id": "codenet-bug-p03827", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given a string S of length N consisting of lowercase English letters.\nWe will cut this string at one position into two strings X and Y.\nHere, we would like to maximize the number of different letters contained in both X and Y.\nFind the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 100
  • \n
  • |S| = N
  • \n
  • S consists of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS\n
\n
\n
\n
\n
\n

Output

Print the largest possible number of different letters contained in both X and Y.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6\naabbca\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

If we cut the string between the third and fourth letters into X = aab and Y = bca, the letters contained in both X and Y are a and b.\nThere will never be three or more different letters contained in both X and Y, so the answer is 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

10\naaaaaaaaaa\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

However we divide S, only a will be contained in both X and Y.

\n
\n
\n
\n
\n
\n

Sample Input 3

45\ntgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir\n
\n
\n
\n
\n
\n

Sample Output 3

9\n
\n
\n
", "id": "codenet-bug-p03338", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

A shop sells N kinds of fruits, Fruit 1, \\ldots, N, at prices of p_1, \\ldots, p_N yen per item, respectively. (Yen is the currency of Japan.)

\n

Here, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq K \\leq N \\leq 1000
  • \n
  • 1 \\leq p_i \\leq 1000
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\np_1 p_2 \\ldots p_N\n
\n
\n
\n
\n
\n

Output

Print an integer representing the minimum possible total price of fruits.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 3\n50 100 80 120 80\n
\n
\n
\n
\n
\n

Sample Output 1

210\n
\n

This shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen, and 80 yen, respectively.

\n

The minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen when choosing Fruit 1, 3, and 5.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 1\n1000\n
\n
\n
\n
\n
\n

Sample Output 2

1000\n
\n
\n
", "id": "codenet-bug-p02628", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are S sheep and W wolves.

\n

If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.

\n

If the wolves will attack the sheep, print unsafe; otherwise, print safe.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq S \\leq 100
  • \n
  • 1 \\leq W \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S W\n
\n
\n
\n
\n
\n

Output

If the wolves will attack the sheep, print unsafe; otherwise, print safe.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 5\n
\n
\n
\n
\n
\n

Sample Output 1

unsafe\n
\n

There are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.

\n
\n
\n
\n
\n
\n

Sample Input 2

100 2\n
\n
\n
\n
\n
\n

Sample Output 2

safe\n
\n

Many a sheep drive away two wolves.

\n
\n
\n
\n
\n
\n

Sample Input 3

10 10\n
\n
\n
\n
\n
\n

Sample Output 3

unsafe\n
\n
\n
", "id": "codenet-bug-p02699", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

\n

A Hitachi string is a concatenation of one or more copies of the string hi.

\n

For example, hi and hihi are Hitachi strings, while ha and hii are not.

\n

Given a string S, determine whether S is a Hitachi string.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • The length of S is between 1 and 10 (inclusive).
  • \n
  • S is a string consisting of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

\n

If S is a Hitachi string, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

hihi\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

hihi is the concatenation of two copies of hi, so it is a Hitachi string.

\n
\n
\n
\n
\n
\n

Sample Input 2

hi\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 3

ha\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
", "id": "codenet-bug-p02747", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.

\n

Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.

\n

Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1\\leq A,B,C,D \\leq 10
  • \n
  • All input values are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C D\n
\n
\n
\n
\n
\n

Output

Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 8 7 1\n
\n
\n
\n
\n
\n

Sample Output 1

Left\n
\n

The total weight of the masses on the left pan is 11, and the total weight of the masses on the right pan is 8. Since 11>8, we should print Left.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 4 5 2\n
\n
\n
\n
\n
\n

Sample Output 2

Balanced\n
\n

The total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print Balanced.

\n
\n
\n
\n
\n
\n

Sample Input 3

1 7 6 4\n
\n
\n
\n
\n
\n

Sample Output 3

Right\n
\n

The total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print Right.

\n
\n
", "id": "codenet-bug-p03477", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.

\n

You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.

\n

You planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.

\n

You want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples.

\n

Find the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above.

\n

We can prove that this value is uniquely determined.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 200
  • \n
  • -100 \\leq L \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N L\n
\n
\n
\n
\n
\n

Output

Find the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 2\n
\n
\n
\n
\n
\n

Sample Output 1

18\n
\n

The flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively. The optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 -1\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

The flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal choice is to eat Apple 2, so the answer is (-1)+1=0.

\n
\n
\n
\n
\n
\n

Sample Input 3

30 -50\n
\n
\n
\n
\n
\n

Sample Output 3

-1044\n
\n
\n
", "id": "codenet-bug-p02994", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

The development of algae in a pond is as follows.

\n

Let the total weight of the algae at the beginning of the year i be x_i gram. For i≥2000, the following formula holds:

\n
    \n
  • x_{i+1} = rx_i - D
  • \n
\n

You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print them in order.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 ≤ r ≤ 5
  • \n
  • 1 ≤ D ≤ 100
  • \n
  • D < x_{2000} ≤ 200
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
r D x_{2000}\n
\n
\n
\n
\n
\n

Output

Print 10 lines. The i-th line (1 ≤ i ≤ 10) should contain x_{2000+i} as an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 10 20\n
\n
\n
\n
\n
\n

Sample Output 1

30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n
\n

For example, x_{2001} = rx_{2000} - D = 2 \\times 20 - 10 = 30 and x_{2002} = rx_{2001} - D = 2 \\times 30 - 10 = 50.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 40 60\n
\n
\n
\n
\n
\n

Sample Output 2

200\n760\n3000\n11960\n47800\n191160\n764600\n3058360\n12233400\n48933560\n
\n
\n
", "id": "codenet-bug-p03036", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

\n

The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.

\n

One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.

\n

If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

\n
    \n
  • X < Z \\leq Y
  • \n
  • x_1, x_2, ..., x_N < Z
  • \n
  • y_1, y_2, ..., y_M \\geq Z
  • \n
\n

Determine if war will break out.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N, M \\leq 100
  • \n
  • -100 \\leq X < Y \\leq 100
  • \n
  • -100 \\leq x_i, y_i \\leq 100
  • \n
  • x_1, x_2, ..., x_N \\neq X
  • \n
  • x_i are all different.
  • \n
  • y_1, y_2, ..., y_M \\neq Y
  • \n
  • y_i are all different.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M X Y\nx_1 x_2 ... x_N\ny_1 y_2 ... y_M\n
\n
\n
\n
\n
\n

Output

If war will break out, print War; otherwise, print No War.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 2 10 20\n8 15 13\n16 22\n
\n
\n
\n
\n
\n

Sample Output 1

No War\n
\n

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.

\n
    \n
  • X = 10 < 16 \\leq 20 = Y
  • \n
  • 8, 15, 13 < 16
  • \n
  • 16, 22 \\geq 16
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

4 2 -48 -1\n-20 -35 -91 -23\n-22 66\n
\n
\n
\n
\n
\n

Sample Output 2

War\n
\n
\n
\n
\n
\n
\n

Sample Input 3

5 3 6 8\n-10 3 1 5 -100\n100 6 14\n
\n
\n
\n
\n
\n

Sample Output 3

War\n
\n
\n
", "id": "codenet-bug-p03251", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \\leq i \\leq H, 1 \\leq j \\leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is ., and black if c_{i,j} is #.

\n

Consider doing the following operation:

\n
    \n
  • Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.
  • \n
\n

You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq H, W \\leq 6
  • \n
  • 1 \\leq K \\leq HW
  • \n
  • c_{i,j} is . or #.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
H W K\nc_{1,1}c_{1,2}...c_{1,W}\nc_{2,1}c_{2,2}...c_{2,W}\n:\nc_{H,1}c_{H,2}...c_{H,W}\n
\n
\n
\n
\n
\n

Output

Print an integer representing the number of choices of rows and columns satisfying the condition.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 3 2\n..#\n###\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

Five choices below satisfy the condition.

\n
    \n
  • The 1-st row and 1-st column
  • \n
  • The 1-st row and 2-nd column
  • \n
  • The 1-st row and 3-rd column
  • \n
  • The 1-st and 2-nd column
  • \n
  • The 3-rd column
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

2 3 4\n..#\n###\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

One choice, which is choosing nothing, satisfies the condition.

\n
\n
\n
\n
\n
\n

Sample Input 3

2 2 3\n##\n##\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
\n
\n
\n
\n

Sample Input 4

6 6 8\n..##..\n.#..#.\n#....#\n######\n#....#\n#....#\n
\n
\n
\n
\n
\n

Sample Output 4

208\n
\n
\n
", "id": "codenet-bug-p02614", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

You are given a string S consisting of lowercase English letters.\nAnother string T is initially empty.\nDetermine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

\n
    \n
  • Append one of the following at the end of T: dream, dreamer, erase and eraser.
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • 1≦|S|≦10^5
  • \n
  • S consists of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

erasedream\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

Append erase and dream at the end of T in this order, to obtain S = T.

\n
\n
\n
\n
\n
\n

Sample Input 2

dreameraser\n
\n
\n
\n
\n
\n

Sample Output 2

YES\n
\n

Append dream and eraser at the end of T in this order, to obtain S = T.

\n
\n
\n
\n
\n
\n

Sample Input 3

dreamerer\n
\n
\n
\n
\n
\n

Sample Output 3

NO\n
\n
\n
", "id": "codenet-bug-p03854", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Takahashi is meeting up with Aoki.

\n

They have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.

\n

Takahashi will leave his house now and go straight to the place at a speed of S meters per minute.

\n

Will he arrive in time?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq D \\leq 10000
  • \n
  • 1 \\leq T \\leq 10000
  • \n
  • 1 \\leq S \\leq 10000
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
D T S\n
\n
\n
\n
\n
\n

Output

If Takahashi will reach the place in time, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1000 15 80\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

It takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters per minute. They have planned to meet in 15 minutes so he will arrive in time.

\n
\n
\n
\n
\n
\n

Sample Input 2

2000 20 100\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n
\n

It takes 20 minutes to go 2000 meters to the place at a speed of 100 meters per minute. They have planned to meet in 20 minutes so he will arrive just on time.

\n
\n
\n
\n
\n
\n

Sample Input 3

10000 1 1\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n

He will be late.

\n
\n
", "id": "codenet-bug-p02570", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc.

\n
\n
\n
\n
\n

Constraints

    \n
  • |S|=3
  • \n
  • S consists of a, b and c.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

If S can be obtained by permuting abc, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

bac\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

Swapping the first and second characters in bac results in abc.

\n
\n
\n
\n
\n
\n

Sample Input 2

bab\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n
\n
\n
\n
\n
\n

Sample Input 3

abc\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 4

aaa\n
\n
\n
\n
\n
\n

Sample Output 4

No\n
\n
\n
", "id": "codenet-bug-p03385", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You went shopping to buy cakes and donuts with X yen (the currency of Japan).

\n

First, you bought one cake for A yen at a cake shop.\nThen, you bought as many donuts as possible for B yen each, at a donut shop.

\n

How much do you have left after shopping?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A, B \\leq 1 000
  • \n
  • A + B \\leq X \\leq 10 000
  • \n
  • X, A and B are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
X\nA\nB\n
\n
\n
\n
\n
\n

Output

Print the amount you have left after shopping.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1234\n150\n100\n
\n
\n
\n
\n
\n

Sample Output 1

84\n
\n

You have 1234 - 150 = 1084 yen left after buying a cake.\nWith this amount, you can buy 10 donuts, after which you have 84 yen left.

\n
\n
\n
\n
\n
\n

Sample Input 2

1000\n108\n108\n
\n
\n
\n
\n
\n

Sample Output 2

28\n
\n
\n
\n
\n
\n
\n

Sample Input 3

579\n123\n456\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
\n
\n
\n
\n

Sample Input 4

7477\n549\n593\n
\n
\n
\n
\n
\n

Sample Output 4

405\n
\n
\n
", "id": "codenet-bug-p03447", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given a positive integer X.\nFind the largest perfect power that is at most X.\nHere, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 X 1000
  • \n
  • X is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
X\n
\n
\n
\n
\n
\n

Output

Print the largest perfect power that is at most X.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n

There are four perfect powers that are at most 10: 1, 4, 8 and 9.\nWe should print the largest among them, 9.

\n
\n
\n
\n
\n
\n

Sample Input 2

1\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

999\n
\n
\n
\n
\n
\n

Sample Output 3

961\n
\n
\n
", "id": "codenet-bug-p03352", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given a string S of length N consisting of lowercase English letters, and an integer K.\nPrint the string obtained by replacing every character in S that differs from the K-th character of S, with *.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq K \\leq N\\leq 10
  • \n
  • S is a string of length N consisting of lowercase English letters.
  • \n
  • N and K are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS\nK\n
\n
\n
\n
\n
\n

Output

Print the string obtained by replacing every character in S that differs from the K-th character of S, with *.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\nerror\n2\n
\n
\n
\n
\n
\n

Sample Output 1

*rr*r\n
\n

The second character of S is r. When we replace every character in error that differs from r with *, we get the string *rr*r.

\n
\n
\n
\n
\n
\n

Sample Input 2

6\neleven\n5\n
\n
\n
\n
\n
\n

Sample Output 2

e*e*e*\n
\n
\n
\n
\n
\n
\n

Sample Input 3

9\neducation\n7\n
\n
\n
\n
\n
\n

Sample Output 3

******i**\n
\n
\n
", "id": "codenet-bug-p03068", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are N students in a school.

\n

We will divide these students into some groups, and in each group they will discuss some themes.

\n

You think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.

\n

Divide the students so that the number of groups consisting of three or more students is maximized.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 1000
  • \n
  • All input values are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

If you can form at most x groups consisting of three or more students, print x.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

8\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

For example, you can form a group of three students and another of five students.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

Sometimes you cannot form any group consisting of three or more students, regardless of how you divide the students.

\n
\n
\n
\n
\n
\n

Sample Input 3

9\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n
\n
", "id": "codenet-bug-p03423", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1\\leq N,K\\leq 100
  • \n
  • N and K are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\n
\n
\n
\n
\n
\n

Output

If we can choose K integers as above, print YES; otherwise, print NO.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 2\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

We can choose 1 and 3.

\n
\n
\n
\n
\n
\n

Sample Input 2

5 5\n
\n
\n
\n
\n
\n

Sample Output 2

NO\n
\n
\n
\n
\n
\n
\n

Sample Input 3

31 10\n
\n
\n
\n
\n
\n

Sample Output 3

YES\n
\n
\n
\n
\n
\n
\n

Sample Input 4

10 90\n
\n
\n
\n
\n
\n

Sample Output 4

NO\n
\n
\n
", "id": "codenet-bug-p03129", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Takahashi wants to be a member of some web service.

\n

He tried to register himself with the ID S, which turned out to be already used by another user.

\n

Thus, he decides to register using a string obtained by appending one character at the end of S as his ID.

\n

He is now trying to register with the ID T. Determine whether this string satisfies the property above.

\n
\n
\n
\n
\n

Constraints

    \n
  • S and T are strings consisting of lowercase English letters.
  • \n
  • 1 \\leq |S| \\leq 10
  • \n
  • |T| = |S| + 1
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\nT\n
\n
\n
\n
\n
\n

Output

If T satisfies the property in Problem Statement, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

chokudai\nchokudaiz\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

chokudaiz can be obtained by appending z at the end of chokudai.

\n
\n
\n
\n
\n
\n

Sample Input 2

snuke\nsnekee\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

snekee cannot be obtained by appending one character at the end of snuke.

\n
\n
\n
\n
\n
\n

Sample Input 3

a\naa\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p02681", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

We will play a one-player game using a number line and N pieces.

\n

First, we place each of these pieces at some integer coordinate.

\n

Here, multiple pieces can be placed at the same coordinate.

\n

Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move:

\n

Move: Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1.

\n

Note that the coordinates where we initially place the pieces are already regarded as visited.

\n

Find the minimum number of moves required to achieve the objective.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 1 \\leq M \\leq 10^5
  • \n
  • -10^5 \\leq X_i \\leq 10^5
  • \n
  • X_1, X_2, ..., X_M are all different.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\nX_1 X_2 ... X_M\n
\n
\n
\n
\n
\n

Output

Find the minimum number of moves required to achieve the objective.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 5\n10 12 1 2 14\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

The objective can be achieved in five moves as follows, and this is the minimum number of moves required.

\n
    \n
  • Initially, put the two pieces at coordinates 1 and 10.
  • \n
  • Move the piece at coordinate 1 to 2.
  • \n
  • Move the piece at coordinate 10 to 11.
  • \n
  • Move the piece at coordinate 11 to 12.
  • \n
  • Move the piece at coordinate 12 to 13.
  • \n
  • Move the piece at coordinate 13 to 14.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

3 7\n-10 -3 0 9 -100 2 17\n
\n
\n
\n
\n
\n

Sample Output 2

19\n
\n
\n
\n
\n
\n
\n

Sample Input 3

100 1\n-100000\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03137", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

We have a 3×3 square grid, where each square contains a lowercase English letters.\nThe letter in the square at the i-th row from the top and j-th column from the left is c_{ij}.

\n

Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.

\n
\n
\n
\n
\n

Constraints

    \n
  • Input consists of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
c_{11}c_{12}c_{13}\nc_{21}c_{22}c_{23}\nc_{31}c_{32}c_{33}\n
\n
\n
\n
\n
\n

Output

Print the string of length 3 that can be obtained by concatenating the letters on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

ant\nobe\nrec\n
\n
\n
\n
\n
\n

Sample Output 1

abc\n
\n

The letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid are a, b and c from top-right to bottom-left. Concatenate these letters and print abc.

\n
\n
\n
\n
\n
\n

Sample Input 2

edu\ncat\nion\n
\n
\n
\n
\n
\n

Sample Output 2

ean\n
\n
\n
", "id": "codenet-bug-p03415", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given a three-digit positive integer N.
\nDetermine whether N is a palindromic number.
\nHere, a palindromic number is an integer that reads the same backward as forward in decimal notation.

\n
\n
\n
\n
\n

Constraints

    \n
  • 100≤N≤999
  • \n
  • N is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

If N is a palindromic number, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

575\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.

\n
\n
\n
\n
\n
\n

Sample Input 2

123\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

N=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.

\n
\n
\n
\n
\n
\n

Sample Input 3

812\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
", "id": "codenet-bug-p03631", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Given is a three-digit integer N. Does N contain the digit 7?

\n

If so, print Yes; otherwise, print No.

\n
\n
\n
\n
\n

Constraints

    \n
  • 100 \\leq N \\leq 999
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

If N contains the digit 7, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

117\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

117 contains 7 as its last digit.

\n
\n
\n
\n
\n
\n

Sample Input 2

123\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

123 does not contain the digit 7.

\n
\n
\n
\n
\n
\n

Sample Input 3

777\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p02711", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are two rectangles.\nThe lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B.\nThe lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.

\n

Print the area of the rectangle with the larger area.\nIf the two rectangles have equal areas, print that area.

\n
\n
\n
\n
\n

Constraints

    \n
  • All input values are integers.
  • \n
  • 1≤A≤10^4
  • \n
  • 1≤B≤10^4
  • \n
  • 1≤C≤10^4
  • \n
  • 1≤D≤10^4
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
A B C D\n
\n
\n
\n
\n
\n

Output

Print the area of the rectangle with the larger area.\nIf the two rectangles have equal areas, print that area.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 5 2 7\n
\n
\n
\n
\n
\n

Sample Output 1

15\n
\n

The first rectangle has an area of 3×5=15, and the second rectangle has an area of 2×7=14.\nThus, the output should be 15, the larger area.

\n
\n
\n
\n
\n
\n

Sample Input 2

100 600 200 300\n
\n
\n
\n
\n
\n

Sample Output 2

60000\n
\n
\n
", "id": "codenet-bug-p03826", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Let us define the FizzBuzz sequence a_1,a_2,... as follows:

\n
    \n
  • If both 3 and 5 divides i, a_i=\\mbox{FizzBuzz}.
  • \n
  • If the above does not hold but 3 divides i, a_i=\\mbox{Fizz}.
  • \n
  • If none of the above holds but 5 divides i, a_i=\\mbox{Buzz}.
  • \n
  • If none of the above holds, a_i=i.
  • \n
\n

Find the sum of all numbers among the first N terms of the FizzBuzz sequence.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^6
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the sum of all numbers among the first N terms of the FizzBuzz sequence.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

15\n
\n
\n
\n
\n
\n

Sample Output 1

60\n
\n

The first 15 terms of the FizzBuzz sequence are:

\n

1,2,\\mbox{Fizz},4,\\mbox{Buzz},\\mbox{Fizz},7,8,\\mbox{Fizz},\\mbox{Buzz},11,\\mbox{Fizz},13,14,\\mbox{FizzBuzz}

\n

Among them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.

\n
\n
\n
\n
\n
\n

Sample Input 2

1000000\n
\n
\n
\n
\n
\n

Sample Output 2

266666333332\n
\n

Watch out for overflow.

\n
\n
", "id": "codenet-bug-p02712", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

AtCoDeer the deer found two positive integers, a and b.\nDetermine whether the product of a and b is even or odd.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 a,b 10000
  • \n
  • a and b are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
a b\n
\n
\n
\n
\n
\n

Output

If the product is odd, print Odd; if it is even, print Even.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 4\n
\n
\n
\n
\n
\n

Sample Output 1

Even\n
\n

As 3 × 4 = 12 is even, print Even.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 21\n
\n
\n
\n
\n
\n

Sample Output 2

Odd\n
\n

As 1 × 21 = 21 is odd, print Odd.

\n
\n
", "id": "codenet-bug-p03455", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Compute A \\times B, truncate its fractional part, and print the result as an integer.

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 \\leq A \\leq 10^{15}
  • \n
  • 0 \\leq B < 10
  • \n
  • A is an integer.
  • \n
  • B is a number with two digits after the decimal point.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

Print the answer as an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

198 1.10\n
\n
\n
\n
\n
\n

Sample Output 1

217\n
\n

We have 198 \\times 1.10 = 217.8. After truncating the fractional part, we have the answer: 217.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 0.01\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1000000000000000 9.99\n
\n
\n
\n
\n
\n

Sample Output 3

9990000000000000\n
\n
\n
", "id": "codenet-bug-p02659", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

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.
\nA pixel is the smallest element of an image, and in this problem it is a square of size 1×1.
\nAlso, the given images are binary images, and the color of each pixel is either white or black.

\n

In the input, every pixel is represented by a character: . corresponds to a white pixel, and # corresponds to a black pixel.
\nThe image A is given as N strings A_1,...,A_N.
\nThe j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).
\nSimilarly, the template image B is given as M strings B_1,...,B_M.
\nThe j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).

\n

Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≦M≦N≦50
  • \n
  • A_i is a string of length N consisting of # and ..
  • \n
  • B_i is a string of length M consisting of # and ..
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
N M\nA_1\nA_2\n:  \nA_N\nB_1\nB_2\n:  \nB_M\n
\n
\n
\n
\n
\n

Output

Print Yes if the template image B is contained in the image A. Print No otherwise.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 2\n#.#\n.#.\n#.#\n#.\n.#\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

The template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 1\n....\n....\n....\n....\n#\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

The template image B, composed of a black pixel, is not contained in the image A composed of white pixels.

\n
\n
", "id": "codenet-bug-p03804", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi loves numbers divisible by 2.

\n

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.

\n

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.

\n

For example,

\n
    \n
  • 6 can be divided by 2 once: 6 -> 3.
  • \n
  • 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
  • \n
  • 3 can be divided by 2 zero times.
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ N ≤ 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

7\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

4 can be divided by 2 twice, which is the most number of times among 1, 2, ..., 7.

\n
\n
\n
\n
\n
\n

Sample Input 2

32\n
\n
\n
\n
\n
\n

Sample Output 2

32\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1\n
\n
\n
\n
\n
\n

Sample Output 3

1\n
\n
\n
\n
\n
\n
\n

Sample Input 4

100\n
\n
\n
\n
\n
\n

Sample Output 4

64\n
\n
\n
", "id": "codenet-bug-p03644", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 500 points

\n
\n
\n

Problem Statement

You are given a sequence with N integers: A = \\{ A_1, A_2, \\cdots, A_N \\}.\nFor each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:

\n
    \n
  • If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
  • \n
\n

Find the minimum number of colors required to satisfy the condition.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 0 \\leq A_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1\n:\nA_N\n
\n
\n
\n
\n
\n

Output

Print the minimum number of colors required to satisfy the condition.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n2\n1\n4\n5\n3\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

We can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1, 4, and 5 blue.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n0\n0\n0\n0\n
\n
\n
\n
\n
\n

Sample Output 2

4\n
\n

We have to paint all the integers with distinct colors.

\n
\n
", "id": "codenet-bug-p02973", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.
\nCurrently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.
\nHere, both the x- and y-coordinates before and after each movement must be integers.
\nHe will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).
\nHere, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).
\nUnder this condition, find a shortest path for him.

\n
\n
\n
\n
\n

Constraints

    \n
  • -1000 ≤ sx < tx ≤ 1000
  • \n
  • -1000 ≤ sy < ty ≤ 1000
  • \n
  • sx,sy,tx and ty are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
sx sy tx ty\n
\n
\n
\n
\n
\n

Output

Print a string S that represents a shortest path for Dolphin.
\nThe i-th character in S should correspond to his i-th movement.
\nThe directions of the movements should be indicated by the following characters:

\n
    \n
  • U: Up
  • \n
  • D: Down
  • \n
  • L: Left
  • \n
  • R: Right
  • \n
\n

If there exist multiple shortest paths under the condition, print any of them.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

0 0 1 2\n
\n
\n
\n
\n
\n

Sample Output 1

UURDDLLUUURRDRDDDLLU\n
\n

One possible shortest path is:

\n
    \n
  • Going from (sx,sy) to (tx,ty) for the first time: (0,0)(0,1)(0,2)(1,2)
  • \n
  • Going from (tx,ty) to (sx,sy) for the first time: (1,2)(1,1)(1,0)(0,0)
  • \n
  • Going from (sx,sy) to (tx,ty) for the second time: (0,0)(-1,0)(-1,1)(-1,2)(-1,3)(0,3)(1,3)(1,2)
  • \n
  • Going from (tx,ty) to (sx,sy) for the second time: (1,2)(2,2)(2,1)(2,0)(2,-1)(1,-1)(0,-1)(0,0)
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

-2 -2 1 1\n
\n
\n
\n
\n
\n

Sample Output 2

UURRURRDDDLLDLLULUUURRURRDDDLLDL\n
\n
\n
", "id": "codenet-bug-p03836", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

You have N cards. On the i-th card, an integer A_i is written.

\n

For each j = 1, 2, ..., M in this order, you will perform the following operation once:

\n

Operation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.

\n

Find the maximum possible sum of the integers written on the N cards after the M operations.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 1 \\leq M \\leq 10^5
  • \n
  • 1 \\leq A_i, C_i \\leq 10^9
  • \n
  • 1 \\leq B_i \\leq N
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\nA_1 A_2 ... A_N\nB_1 C_1\nB_2 C_2\n\\vdots\nB_M C_M\n
\n
\n
\n
\n
\n

Output

Print the maximum possible sum of the integers written on the N cards after the M operations.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 2\n5 1 4\n2 3\n1 5\n
\n
\n
\n
\n
\n

Sample Output 1

14\n
\n

By replacing the integer on the second card with 5, the sum of the integers written on the three cards becomes 5 + 5 + 4 = 14, which is the maximum result.

\n
\n
\n
\n
\n
\n

Sample Input 2

10 3\n1 8 5 7 100 4 52 33 13 5\n3 10\n4 30\n1 4\n
\n
\n
\n
\n
\n

Sample Output 2

338\n
\n
\n
\n
\n
\n
\n

Sample Input 3

3 2\n100 100 100\n3 99\n3 99\n
\n
\n
\n
\n
\n

Sample Output 3

300\n
\n
\n
\n
\n
\n
\n

Sample Input 4

11 3\n1 1 1 1 1 1 1 1 1 1 1\n3 1000000000\n4 1000000000\n3 1000000000\n
\n
\n
\n
\n
\n

Sample Output 4

10000000001\n
\n

The output may not fit into a 32-bit integer type.

\n
\n
", "id": "codenet-bug-p03038", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 400 points

\n
\n
\n

Problem Statement

\n

Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.

\n

The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.

\n

When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.

\n

What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 2 \\times 10^5
  • \n
  • 1 \\leq A_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 \\dots A_N\n
\n
\n
\n
\n
\n

Output

\n

Print the maximum total comfort the N players can get.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n2 2 1 3\n
\n
\n
\n
\n
\n

Sample Output 1

7\n
\n

By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.

\n

\"Figure\"

\n

They cannot get the total comfort greater than 7, so the answer is 7.

\n
\n
\n
\n
\n
\n

Sample Input 2

7\n1 1 1 1 1 1 1\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n
\n
", "id": "codenet-bug-p02615", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 200 points

\n
\n
\n

Problem Statement

\n

Takahashi will do a tap dance. The dance is described by a string S where each character is L, R, U, or D. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character.

\n

S is said to be easily playable if and only if it satisfies both of the following conditions:

\n
    \n
  • Every character in an odd position (1-st, 3-rd, 5-th, \\ldots) is R, U, or D.
  • \n
  • Every character in an even position (2-nd, 4-th, 6-th, \\ldots) is L, U, or D.
  • \n
\n

Your task is to print Yes if S is easily playable, and No otherwise.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • S is a string of length between 1 and 100 (inclusive).
  • \n
  • Each character of S is L, R, U, or D.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

\n

Print Yes if S is easily playable, and No otherwise.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

RUDLUDR\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

Every character in an odd position (1-st, 3-rd, 5-th, 7-th) is R, U, or D.

\n

Every character in an even position (2-nd, 4-th, 6-th) is L, U, or D.

\n

Thus, S is easily playable.

\n
\n
\n
\n
\n
\n

Sample Input 2

DULL\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

The 3-rd character is not R, U, nor D, so S is not easily playable.

\n
\n
\n
\n
\n
\n

Sample Input 3

UUUUUUUUUUUUUUU\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 4

ULURU\n
\n
\n
\n
\n
\n

Sample Output 4

No\n
\n
\n
\n
\n
\n
\n

Sample Input 5

RDULULDURURLRDULRLR\n
\n
\n
\n
\n
\n

Sample Output 5

Yes\n
\n
\n
", "id": "codenet-bug-p02910", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 300 points

\n
\n
\n

Problem Statement

\n

Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively.

\n

An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.

\n

At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • All values in input are integers.
  • \n
  • 1 \\leq A, B \\leq 1000
  • \n
  • 0 \\leq H \\leq 11
  • \n
  • 0 \\leq M \\leq 59
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
A B H M\n
\n
\n
\n
\n
\n

Output

\n

Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 4 9 0\n
\n
\n
\n
\n
\n

Sample Output 1

5.00000000000000000000\n
\n

The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.

\n

\"The

\n
\n
\n
\n
\n
\n

Sample Input 2

3 4 10 40\n
\n
\n
\n
\n
\n

Sample Output 2

4.56425719433005567605\n
\n

The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.

\n

\"The

\n
\n
", "id": "codenet-bug-p02677", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.

\n

You are given a 4-digit integer N. Answer the question: Is N good?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1000 ≤ N ≤ 9999
  • \n
  • N is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

If N is good, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1118\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

N is good, since it contains three consecutive 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

7777\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n
\n

An integer is also good when all the digits are the same.

\n
\n
\n
\n
\n
\n

Sample Input 3

1234\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
", "id": "codenet-bug-p03543", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0.\nYou are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \\leq k \\leq N), by repeating the following \"watering\" operation:

\n
    \n
  • Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \\leq x \\leq r.
  • \n
\n

Find the minimum number of watering operations required to satisfy the condition.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
  • 0 \\leq h_i \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nh_1 h_2 h_3 ...... h_N\n
\n
\n
\n
\n
\n

Output

Print the minimum number of watering operations required to satisfy the condition.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n1 2 2 1\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

The minimum number of watering operations required is 2.\nOne way to achieve it is:

\n
    \n
  • Perform the operation with (l,r)=(1,3).
  • \n
  • Perform the operation with (l,r)=(2,4).
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

5\n3 1 2 3 1\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n
\n
\n
\n
\n
\n

Sample Input 3

8\n4 23 75 0 23 96 50 100\n
\n
\n
\n
\n
\n

Sample Output 3

221\n
\n
\n
", "id": "codenet-bug-p03147", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Fennec is fighting with N monsters.

\n

The health of the i-th monster is H_i.

\n

Fennec can do the following two actions:

\n
    \n
  • Attack: Fennec chooses one monster. That monster's health will decrease by 1.
  • \n
  • Special Move: Fennec chooses one monster. That monster's health will become 0.
  • \n
\n

There is no way other than Attack and Special Move to decrease the monsters' health.

\n

Fennec wins when all the monsters' healths become 0 or below.

\n

Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 2 \\times 10^5
  • \n
  • 0 \\leq K \\leq 2 \\times 10^5
  • \n
  • 1 \\leq H_i \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\nH_1 ... H_N\n
\n
\n
\n
\n
\n

Output

Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 1\n4 1 5\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.

\n
\n
\n
\n
\n
\n

Sample Input 2

8 9\n7 9 3 2 3 8 4 6\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

She can use Special Move on all the monsters.

\n
\n
\n
\n
\n
\n

Sample Input 3

3 0\n1000000000 1000000000 1000000000\n
\n
\n
\n
\n
\n

Sample Output 3

3000000000\n
\n

Watch out for overflow.

\n
\n
", "id": "codenet-bug-p02785", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

\n

N friends of Takahashi has come to a theme park.

\n

To ride the most popular roller coaster in the park, you must be at least K centimeters tall.

\n

The i-th friend is h_i centimeters tall.

\n

How many of the Takahashi's friends can ride the roller coaster?

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 1 \\le N \\le 10^5
  • \n
  • 1 \\le K \\le 500
  • \n
  • 1 \\le h_i \\le 500
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N K\nh_1 h_2 \\ldots h_N\n
\n
\n
\n
\n
\n

Output

\n

Print the number of people among the Takahashi's friends who can ride the roller coaster.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 150\n150 140 100 200\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

Two of them can ride the roller coaster: the first and fourth friends.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 500\n499\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n
\n
\n
\n
\n
\n

Sample Input 3

5 1\n100 200 300 400 500\n
\n
\n
\n
\n
\n

Sample Output 3

5\n
\n
\n
", "id": "codenet-bug-p02898", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

You are playing the following game with Joisino.

\n
    \n
  • Initially, you have a blank sheet of paper.
  • \n
  • 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.
  • \n
  • Then, you are asked a question: How many numbers are written on the sheet now?
  • \n
\n

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?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≤N≤100000
  • \n
  • 1≤A_i≤1000000000(=10^9)
  • \n
  • All input values are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1\n:\nA_N\n
\n
\n
\n
\n
\n

Output

Print how many numbers will be written on the sheet at the end of the game.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n6\n2\n6\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

The game proceeds as follows:

\n
    \n
  • \n

    6 is not written on the sheet, so write 6.

    \n
  • \n
  • \n

    2 is not written on the sheet, so write 2.

    \n
  • \n
  • \n

    6 is written on the sheet, so erase 6.

    \n
  • \n
\n

Thus, the sheet contains only 2 in the end. The answer is 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n2\n5\n5\n2\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

It is possible that no number is written on the sheet in the end.

\n
\n
\n
\n
\n
\n

Sample Input 3

6\n12\n22\n16\n22\n18\n12\n
\n
\n
\n
\n
\n

Sample Output 3

2\n
\n
\n
", "id": "codenet-bug-p03607", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 500 points

\n
\n
\n

Problem Statement

\n

We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.

\n

We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.

\n

The i-th and j-th sardines (i \\neq j) are on bad terms if and only if A_i \\cdot A_j + B_i \\cdot B_j = 0.

\n

In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 2 \\times 10^5
  • \n
  • -10^{18} \\leq A_i, B_i \\leq 10^{18}
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\nA_1 B_1\n:\nA_N B_N\n
\n
\n
\n
\n
\n

Output

\n

Print the count modulo 1000000007.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n1 2\n-1 1\n2 -1\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

There are five ways to choose the set of sardines, as follows:

\n
    \n
  • The 1-st
  • \n
  • The 1-st and 2-nd
  • \n
  • The 2-nd
  • \n
  • The 2-nd and 3-rd
  • \n
  • The 3-rd
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

10\n3 2\n3 2\n-1 1\n2 -1\n-3 -9\n-8 12\n7 7\n8 1\n8 2\n8 4\n
\n
\n
\n
\n
\n

Sample Output 2

479\n
\n
\n
", "id": "codenet-bug-p02679", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits \"1974\".

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 \\leq N_1, N_2, N_3, N_4 \\leq 9
  • \n
  • N_1, N_2, N_3 and N_4 are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N_1 N_2 N_3 N_4\n
\n
\n
\n
\n
\n

Output

If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits \"1974\", print YES; if they cannot, print NO.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 7 9 4\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

We can get 1974 by swapping N_2 and N_3.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 9 7 4\n
\n
\n
\n
\n
\n

Sample Output 2

YES\n
\n

We already have 1974 before doing anything.

\n
\n
\n
\n
\n
\n

Sample Input 3

1 2 9 1\n
\n
\n
\n
\n
\n

Sample Output 3

NO\n
\n
\n
\n
\n
\n
\n

Sample Input 4

4 9 0 8\n
\n
\n
\n
\n
\n

Sample Output 4

NO\n
\n
\n
", "id": "codenet-bug-p03149", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

\n

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

\n

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 10^5
  • \n
  • 1 \\leq A_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n

Output

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 ... A_N\n
\n
\n
\n
\n
\n

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

\n
\n
\n
\n
\n
\n

Sample Input 1

3\n7 6 8\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\n12 15 18\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n
\n
\n
\n
\n
\n

Sample Input 3

2\n1000000000 1000000000\n
\n
\n
\n
\n
\n

Sample Output 3

1000000000\n
\n

We can replace an integer with itself.

\n
\n
", "id": "codenet-bug-p03061", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

A biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation.

\n

Find the total number of biscuits produced within T + 0.5 seconds after activation.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq A, B, T \\leq 20
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B T\n
\n
\n
\n
\n
\n

Output

Print the total number of biscuits produced within T + 0.5 seconds after activation.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 5 7\n
\n
\n
\n
\n
\n

Sample Output 1

10\n
\n
    \n
  • Five biscuits will be produced three seconds after activation.
  • \n
  • Another five biscuits will be produced six seconds after activation.
  • \n
  • Thus, a total of ten biscuits will be produced within 7.5 seconds after activation.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

3 2 9\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n
\n
\n
\n
\n
\n

Sample Input 3

20 20 19\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03059", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Takahashi loves the number 7 and multiples of K.

\n

Where is the first occurrence of a multiple of K in the sequence 7,77,777,\\ldots? (Also see Output and Sample Input/Output below.)

\n

If the sequence contains no multiples of K, print -1 instead.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq K \\leq 10^6
  • \n
  • K is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
K\n
\n
\n
\n
\n
\n

Output

Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

101\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

None of 7, 77, and 777 is a multiple of 101, but 7777 is.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n
\n
\n
\n
\n
\n

Sample Output 2

-1\n
\n

All elements in the sequence are odd numbers; there are no multiples of 2.

\n
\n
\n
\n
\n
\n

Sample Input 3

999983\n
\n
\n
\n
\n
\n

Sample Output 3

999982\n
\n
\n
", "id": "codenet-bug-p02596", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

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.

\n

You are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, and print ARC otherwise.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≦ x ≦ 3{,}000
  • \n
  • x is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
x\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1000\n
\n
\n
\n
\n
\n

Sample Output 1

ABC\n
\n

Smeke's current rating is less than 1200, thus the output should be ABC.

\n
\n
\n
\n
\n
\n

Sample Input 2

2000\n
\n
\n
\n
\n
\n

Sample Output 2

ARC\n
\n

Smeke's current rating is not less than 1200, thus the output should be ARC.

\n
\n
", "id": "codenet-bug-p03813", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Print the circumference of a circle of radius R.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq R \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
R\n
\n
\n
\n
\n
\n

Output

Print the circumference of the circle.\nYour output is considered correct if and only if its absolute or relative error from our answer is at most 10^{-2}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1\n
\n
\n
\n
\n
\n

Sample Output 1

6.28318530717958623200\n
\n

Since we accept an absolute or relative error of at most 10^{-2}, 6.28 is also an acceptable output, but 6 is not.

\n
\n
\n
\n
\n
\n

Sample Input 2

73\n
\n
\n
\n
\n
\n

Sample Output 2

458.67252742410977361942\n
\n
\n
", "id": "codenet-bug-p02705", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.

\n

To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≦A,B,C≦10
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

If it is possible to construct a Haiku by using each of the phrases once, print YES (case-sensitive). Otherwise, print NO.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 5 7\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

Using three phrases of length 5, 5 and 7, it is possible to construct a Haiku.

\n
\n
\n
\n
\n
\n

Sample Input 2

7 7 5\n
\n
\n
\n
\n
\n

Sample Output 2

NO\n
\n
\n
", "id": "codenet-bug-p04043", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are two buttons, one of size A and one of size B.

\n

When you press a button of size X, you get X coins and the size of that button decreases by 1.

\n

You will press a button twice. Here, you can press the same button twice, or press both buttons once.

\n

At most how many coins can you get?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 3 \\leq A, B \\leq 20
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

Print the maximum number of coins you can get.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 3\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n

You can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this is the maximum result.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 4\n
\n
\n
\n
\n
\n

Sample Output 2

7\n
\n
\n
\n
\n
\n
\n

Sample Input 3

6 6\n
\n
\n
\n
\n
\n

Sample Output 3

12\n
\n
\n
", "id": "codenet-bug-p03071", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

This contest is CODE FESTIVAL.\nHowever, Mr. Takahashi always writes it CODEFESTIVAL, omitting the single space between CODE and FESTIVAL.

\n

So he has decided to make a program that puts the single space he omitted.

\n

You are given a string s with 12 letters.\nOutput the string putting a single space between the first 4 letters and last 8 letters in the string s.

\n
\n
\n
\n
\n

Constraints

    \n
  • s contains exactly 12 letters.
  • \n
  • All letters in s are uppercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
s\n
\n
\n
\n
\n
\n

Output

Print the string putting a single space between the first 4 letters and last 8 letters in the string s.\nPut a line break at the end.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

CODEFESTIVAL\n
\n
\n
\n
\n
\n

Sample Output 1

CODE FESTIVAL\n
\n

Putting a single space between the first 4 letters and last 8 letters in CODEFESTIVAL makes it CODE FESTIVAL.

\n
\n
\n
\n
\n
\n

Sample Input 2

POSTGRADUATE\n
\n
\n
\n
\n
\n

Sample Output 2

POST GRADUATE\n
\n
\n
\n
\n
\n
\n

Sample Input 3

ABCDEFGHIJKL\n
\n
\n
\n
\n
\n

Sample Output 3

ABCD EFGHIJKL\n
\n
\n
", "id": "codenet-bug-p03992", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

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?

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 ≤ n, m ≤ 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
n m\n
\n
\n
\n
\n
\n

Output

Print the number of blocks in K-city.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 4\n
\n
\n
\n
\n
\n

Sample Output 1

6\n
\n

There are six blocks, as shown below:

\n
\n\"9179be829dc9810539213537d4c7398c.png\"\n
\n
\n
\n
\n
\n
\n

Sample Input 2

2 2\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

There are one block, as shown below:

\n
\n\"997bfafa99be630b54d037225a5c68ea.png\"\n
\n
\n
", "id": "codenet-bug-p03635", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Alice and Bob are playing One Card Poker.
\nOne Card Poker is a two-player game using playing cards.

\n

Each card in this game shows an integer between 1 and 13, inclusive.
\nThe strength of a card is determined by the number written on it, as follows:

\n

Weak 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < 1 Strong

\n

One Card Poker is played as follows:

\n
    \n
  1. Each player picks one card from the deck. The chosen card becomes the player's hand.
  2. \n
  3. The players reveal their hands to each other. The player with the stronger card wins the game.
    \nIf their cards are equally strong, the game is drawn.
  4. \n
\n

You are watching Alice and Bob playing the game, and can see their hands.
\nThe number written on Alice's card is A, and the number written on Bob's card is B.
\nWrite a program to determine the outcome of the game.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≦A≦13
  • \n
  • 1≦B≦13
  • \n
  • A and B are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

Print Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

8 6\n
\n
\n
\n
\n
\n

Sample Output 1

Alice\n
\n

8 is written on Alice's card, and 6 is written on Bob's card.\nAlice has the stronger card, and thus the output should be Alice.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 1\n
\n
\n
\n
\n
\n

Sample Output 2

Draw\n
\n

Since their cards have the same number, the game will be drawn.

\n
\n
\n
\n
\n
\n

Sample Input 3

13 1\n
\n
\n
\n
\n
\n

Sample Output 3

Bob\n
\n
\n
", "id": "codenet-bug-p03803", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.\nFor convenience, we will call them Island 1, Island 2, ..., Island N.

\n

There are M kinds of regular boat services between these islands.\nEach service connects two islands. The i-th service connects Island a_i and Island b_i.

\n

Cat Snuke is on Island 1 now, and wants to go to Island N.\nHowever, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.

\n

Help him.

\n
\n
\n
\n
\n

Constraints

    \n
  • 3 ≤ N ≤ 200 000
  • \n
  • 1 ≤ M ≤ 200 000
  • \n
  • 1 ≤ a_i < b_i ≤ N
  • \n
  • (a_i, b_i) \\neq (1, N)
  • \n
  • If i \\neq j, (a_i, b_i) \\neq (a_j, b_j).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\na_1 b_1\na_2 b_2\n:\na_M b_M\n
\n
\n
\n
\n
\n

Output

If it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 2\n1 2\n2 3\n
\n
\n
\n
\n
\n

Sample Output 1

POSSIBLE\n
\n
\n
\n
\n
\n
\n

Sample Input 2

4 3\n1 2\n2 3\n3 4\n
\n
\n
\n
\n
\n

Sample Output 2

IMPOSSIBLE\n
\n

You have to use three boat services to get to Island 4.

\n
\n
\n
\n
\n
\n

Sample Input 3

100000 1\n1 99999\n
\n
\n
\n
\n
\n

Sample Output 3

IMPOSSIBLE\n
\n
\n
\n
\n
\n
\n

Sample Input 4

5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n
\n
\n
\n
\n
\n

Sample Output 4

POSSIBLE\n
\n

You can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.

\n
\n
", "id": "codenet-bug-p03645", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

Given is a number sequence A of length N.

\n

Find the number of integers i \\left(1 \\leq i \\leq N\\right) with the following property:

\n
    \n
  • For every integer j \\left(1 \\leq j \\leq N\\right) such that i \\neq j , A_j does not divide A_i.
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 2 \\times 10^5
  • \n
  • 1 \\leq A_i \\leq 10^6
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 \\cdots A_N\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n24 11 8 3 16\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

The integers with the property are 2, 3, and 4.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n5 5 5 5\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

Note that there can be multiple equal numbers.

\n
\n
\n
\n
\n
\n

Sample Input 3

10\n33 18 45 28 8 19 89 86 2 4\n
\n
\n
\n
\n
\n

Sample Output 3

5\n
\n
\n
", "id": "codenet-bug-p02642", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.

\n

At least how many sheets of paper does he need?

\n
\n
\n
\n
\n

Constraints

    \n
  • N is an integer.
  • \n
  • 1 \\leq N \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

By printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the 2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3 sheets of paper.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

100\n
\n
\n
\n
\n
\n

Sample Output 3

50\n
\n
\n
", "id": "codenet-bug-p02759", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W.\nIf we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W], as shown in the following figure:

\n

\"\"

\n

AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle.\nFind the minimum distance it needs to be moved.

\n
\n
\n
\n
\n

Constraints

    \n
  • All input values are integers.
  • \n
  • 1≤W≤10^5
  • \n
  • 1≤a,b≤10^5
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
W a b\n
\n
\n
\n
\n
\n

Output

Print the minimum distance the second rectangle needs to be moved.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 2 6\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

This input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 1 3\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

The rectangles are already connected, and thus no move is needed.

\n
\n
\n
\n
\n
\n

Sample Input 3

5 10 1\n
\n
\n
\n
\n
\n

Sample Output 3

4\n
\n
\n
", "id": "codenet-bug-p03778", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

You have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \\leq i \\leq N) is v_i.

\n

When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.

\n

After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 50
  • \n
  • 1 \\leq v_i \\leq 1000
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nv_1 v_2 \\ldots v_N\n
\n
\n
\n
\n
\n

Output

Print a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.

\n

Your output will be judged correct when its absolute or relative error from the judge's output is at most 10^{-5}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n3 4\n
\n
\n
\n
\n
\n

Sample Output 1

3.5\n
\n

If you start with two ingredients, the only choice is to put both of them in the pot. The value of the ingredient resulting from the ingredients of values 3 and 4 is (3 + 4) / 2 = 3.5.

\n

Printing 3.50001, 3.49999, and so on will also be accepted.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\n500 300 200\n
\n
\n
\n
\n
\n

Sample Output 2

375\n
\n

You start with three ingredients this time, and you can choose what to use in the first composition. There are three possible choices:

\n
    \n
  • Use the ingredients of values 500 and 300 to produce an ingredient of value (500 + 300) / 2 = 400. The next composition will use this ingredient and the ingredient of value 200, resulting in an ingredient of value (400 + 200) / 2 = 300.
  • \n
  • Use the ingredients of values 500 and 200 to produce an ingredient of value (500 + 200) / 2 = 350. The next composition will use this ingredient and the ingredient of value 300, resulting in an ingredient of value (350 + 300) / 2 = 325.
  • \n
  • Use the ingredients of values 300 and 200 to produce an ingredient of value (300 + 200) / 2 = 250. The next composition will use this ingredient and the ingredient of value 500, resulting in an ingredient of value (250 + 500) / 2 = 375.
  • \n
\n

Thus, the maximum possible value of the last ingredient remaining is 375.

\n

Printing 375.0 and so on will also be accepted.

\n
\n
\n
\n
\n
\n

Sample Input 3

5\n138 138 138 138 138\n
\n
\n
\n
\n
\n

Sample Output 3

138\n
\n
\n
", "id": "codenet-bug-p02935", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi has A cookies, and Aoki has B cookies.\nTakahashi will do the following action K times:

\n
    \n
  • If Takahashi has one or more cookies, eat one of his cookies.
  • \n
  • Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.
  • \n
  • If they both have no cookies, do nothing.
  • \n
\n

In the end, how many cookies will Takahashi and Aoki have, respectively?

\n
\n
\n
\n
\n

Constraints

    \n
  • 0 \\leq A \\leq 10^{12}
  • \n
  • 0 \\leq B \\leq 10^{12}
  • \n
  • 0 \\leq K \\leq 10^{12}
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B K\n
\n
\n
\n
\n
\n

Output

Print the numbers of Takahashi's and Aoki's cookies after K actions.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 3 3\n
\n
\n
\n
\n
\n

Sample Output 1

0 2\n
\n

Takahashi will do the following:

\n
    \n
  • He has two cookies, so he eats one of them.
  • \n
  • Now he has one cookie left, and he eats it.
  • \n
  • Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.
  • \n
\n

Thus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

500000000000 500000000000 1000000000000\n
\n
\n
\n
\n
\n

Sample Output 2

0 0\n
\n

Watch out for overflows.

\n
\n
", "id": "codenet-bug-p02818", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given a string S consisting of lowercase English letters.\nFind the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S.\nIf every lowercase English letter occurs in S, print None instead.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq |S| \\leq 10^5 (|S| is the length of string S.)
  • \n
  • S consists of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the lexicographically smallest lowercase English letter that does not occur in S.\nIf every lowercase English letter occurs in S, print None instead.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

atcoderregularcontest\n
\n
\n
\n
\n
\n

Sample Output 1

b\n
\n

The string atcoderregularcontest contains a, but does not contain b.

\n
\n
\n
\n
\n
\n

Sample Input 2

abcdefghijklmnopqrstuvwxyz\n
\n
\n
\n
\n
\n

Sample Output 2

None\n
\n

This string contains every lowercase English letter.

\n
\n
\n
\n
\n
\n

Sample Input 3

fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg\n
\n
\n
\n
\n
\n

Sample Output 3

d\n
\n
\n
", "id": "codenet-bug-p03624", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \\times ... \\times A_N.

\n

However, if the result exceeds 10^{18}, print -1 instead.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 10^5
  • \n
  • 0 \\leq A_i \\leq 10^{18}
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 ... A_N\n
\n
\n
\n
\n
\n

Output

Print the value A_1 \\times ... \\times A_N as an integer, or -1 if the value exceeds 10^{18}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n1000000000 1000000000\n
\n
\n
\n
\n
\n

Sample Output 1

1000000000000000000\n
\n

We have 1000000000 \\times 1000000000 = 1000000000000000000.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\n101 9901 999999000001\n
\n
\n
\n
\n
\n

Sample Output 2

-1\n
\n

We have 101 \\times 9901 \\times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

\n
\n
\n
\n
\n
\n

Sample Input 3

31\n4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p02658", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

The word internationalization is sometimes abbreviated to i18n.\nThis comes from the fact that there are 18 letters between the first i and the last n.

\n

You are given a string s of length at least 3 consisting of lowercase English letters.\nAbbreviate s in the same way.

\n
\n
\n
\n
\n

Constraints

    \n
  • 3 ≤ |s| ≤ 100 (|s| denotes the length of s.)
  • \n
  • s consists of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
s\n
\n
\n
\n
\n
\n

Output

Print the abbreviation of s.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

internationalization\n
\n
\n
\n
\n
\n

Sample Output 1

i18n\n
\n
\n
\n
\n
\n
\n

Sample Input 2

smiles\n
\n
\n
\n
\n
\n

Sample Output 2

s4s\n
\n
\n
\n
\n
\n
\n

Sample Input 3

xyz\n
\n
\n
\n
\n
\n

Sample Output 3

x1z\n
\n
\n
", "id": "codenet-bug-p03636", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are N stones, numbered 1, 2, \\ldots, N.\nFor each i (1 \\leq i \\leq N), the height of Stone i is h_i.

\n

There is a frog who is initially on Stone 1.\nHe will repeat the following action some number of times to reach Stone N:

\n
    \n
  • If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
  • \n
\n

Find the minimum possible total cost incurred before the frog reaches Stone N.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 10^5
  • \n
  • 1 \\leq h_i \\leq 10^4
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nh_1 h_2 \\ldots h_N\n
\n
\n
\n
\n
\n

Output

Print the minimum possible total cost incurred.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n10 30 40 20\n
\n
\n
\n
\n
\n

Sample Output 1

30\n
\n

If we follow the path 124, the total cost incurred would be |10 - 30| + |30 - 20| = 30.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n10 10\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

If we follow the path 12, the total cost incurred would be |10 - 10| = 0.

\n
\n
\n
\n
\n
\n

Sample Input 3

6\n30 10 60 10 60 50\n
\n
\n
\n
\n
\n

Sample Output 3

40\n
\n

If we follow the path 1356, the total cost incurred would be |30 - 60| + |60 - 60| + |60 - 50| = 40.

\n
\n
", "id": "codenet-bug-p03160", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

There are N persons called Person 1 through Person N.

\n

You are given M facts that \"Person A_i and Person B_i are friends.\" The same fact may be given multiple times.

\n

If X and Y are friends, and Y and Z are friends, then X and Z are also friends. There is no friendship that cannot be derived from the M given facts.

\n

Takahashi the evil wants to divide the N persons into some number of groups so that every person has no friend in his/her group.

\n

At least how many groups does he need to make?

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 2\\times 10^5
  • \n
  • 0 \\leq M \\leq 2\\times 10^5
  • \n
  • 1\\leq A_i,B_i\\leq N
  • \n
  • A_i \\neq B_i
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\nA_1 B_1\n\\vdots\nA_M B_M\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 3\n1 2\n3 4\n5 1\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

Dividing them into three groups such as \\{1,3\\}, \\{2,4\\}, and \\{5\\} achieves the goal.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 10\n1 2\n2 1\n1 2\n2 1\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n
\n
\n
\n
\n
\n

Sample Output 2

4\n
\n
\n
\n
\n
\n
\n

Sample Input 3

10 4\n3 1\n4 1\n5 9\n2 6\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n
\n
", "id": "codenet-bug-p02573", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

\n

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ K ≤ N ≤ 200000
  • \n
  • 1 ≤ p_i ≤ 1000
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\np_1 ... p_N\n
\n
\n
\n
\n
\n

Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

\n

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 3\n1 2 2 4 5\n
\n
\n
\n
\n
\n

Sample Output 1

7.000000000000\n
\n

When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 1\n6 6 6 6\n
\n
\n
\n
\n
\n

Sample Output 2

3.500000000000\n
\n

Regardless of which die we choose, the expected value of the number shown is 3.5.

\n
\n
\n
\n
\n
\n

Sample Input 3

10 4\n17 13 13 12 15 20 10 13 17 11\n
\n
\n
\n
\n
\n

Sample Output 3

32.000000000000\n
\n
\n
", "id": "codenet-bug-p02780", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S, it means it was sunny on the i-th day; if that character is R, it means it was rainy on that day.

\n

Find the maximum number of consecutive rainy days in this period.

\n
\n
\n
\n
\n

Constraints

    \n
  • |S| = 3
  • \n
  • Each character of S is S or R.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the maximum number of consecutive rainy days in the period.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

RRS\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

We had rain on the 1-st and 2-nd days in the period. Here, the maximum number of consecutive rainy days is 2, so we should print 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

SSS\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

It was sunny throughout the period. We had no rainy days, so we should print 0.

\n
\n
\n
\n
\n
\n

Sample Input 3

RSR\n
\n
\n
\n
\n
\n

Sample Output 3

1\n
\n

We had rain on the 1-st and 3-rd days - two \"streaks\" of one rainy day, so we should print 1.

\n
\n
", "id": "codenet-bug-p02582", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You will be given an integer a and a string s consisting of lowercase English letters as input.

\n

Write a program that prints s if a is not less than 3200 and prints red if a is less than 3200.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2800 \\leq a < 5000
  • \n
  • s is a string of length between 1 and 10 (inclusive).
  • \n
  • Each character of s is a lowercase English letter.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
a\ns\n
\n
\n
\n
\n
\n

Output

If a is not less than 3200, print s; if a is less than 3200, print red.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3200\npink\n
\n
\n
\n
\n
\n

Sample Output 1

pink\n
\n

a = 3200 is not less than 3200, so we print s = pink.

\n
\n
\n
\n
\n
\n

Sample Input 2

3199\npink\n
\n
\n
\n
\n
\n

Sample Output 2

red\n
\n

a = 3199 is less than 3200, so we print red.

\n
\n
\n
\n
\n
\n

Sample Input 3

4049\nred\n
\n
\n
\n
\n
\n

Sample Output 3

red\n
\n

a = 4049 is not less than 3200, so we print s = red.

\n
\n
", "id": "codenet-bug-p02933", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given two positive integers a and b.\nLet x be the average of a and b.\nPrint x rounded up to the nearest integer.

\n
\n
\n
\n
\n

Constraints

    \n
  • a and b are integers.
  • \n
  • 1 \\leq a, b \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
a b\n
\n
\n
\n
\n
\n

Output

Print x rounded up to the nearest integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 3\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

The average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

7 4\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n

The average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.

\n
\n
\n
\n
\n
\n

Sample Input 3

5 5\n
\n
\n
\n
\n
\n

Sample Output 3

5\n
\n
\n
", "id": "codenet-bug-p03485", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

\n

We have three boxes A, B, and C, each of which contains an integer.
\nCurrently, the boxes A, B, and C contain the integers X, Y, and Z, respectively.
\nWe will now do the operations below in order. Find the content of each box afterward.

\n
    \n
  • Swap the contents of the boxes A and B
  • \n
  • Swap the contents of the boxes A and C
  • \n
\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 1 \\leq X,Y,Z \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
X Y Z\n
\n
\n
\n
\n
\n

Output

\n

Print the integers contained in the boxes A, B, and C, in this order, with space in between.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 2 3\n
\n
\n
\n
\n
\n

Sample Output 1

3 1 2\n
\n

After the contents of the boxes A and B are swapped, A, B, and C contain 2, 1, and 3, respectively.
\nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and 2, respectively.

\n
\n
\n
\n
\n
\n

Sample Input 2

100 100 100\n
\n
\n
\n
\n
\n

Sample Output 2

100 100 100\n
\n
\n
\n
\n
\n
\n

Sample Input 3

41 59 31\n
\n
\n
\n
\n
\n

Sample Output 3

31 41 59\n
\n
\n
", "id": "codenet-bug-p02717", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

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).

\n

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.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≦ |s| ≦ 200{,}000
  • \n
  • s consists of uppercase English letters.
  • \n
  • There exists a substring of s that starts with A and ends with Z.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
s\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

QWERTYASDFZXCV\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

\n
\n
\n
\n
\n
\n

Sample Input 2

ZABCZ\n
\n
\n
\n
\n
\n

Sample Output 2

4\n
\n
\n
\n
\n
\n
\n

Sample Input 3

HASFJGHOGAKZZFEGA\n
\n
\n
\n
\n
\n

Sample Output 3

12\n
\n
\n
", "id": "codenet-bug-p03814", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 100 points

\n
\n
\n

Problem Statement

\n

M-kun is a competitor in AtCoder, whose highest rating is X.
\nIn this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:

\n
    \n
  • From 400 through 599: 8-kyu
  • \n
  • From 600 through 799: 7-kyu
  • \n
  • From 800 through 999: 6-kyu
  • \n
  • From 1000 through 1199: 5-kyu
  • \n
  • From 1200 through 1399: 4-kyu
  • \n
  • From 1400 through 1599: 3-kyu
  • \n
  • From 1600 through 1799: 2-kyu
  • \n
  • From 1800 through 1999: 1-kyu
  • \n
\n

What kyu does M-kun have?

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 400 \\leq X \\leq 1999
  • \n
  • X is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
X\n
\n
\n
\n
\n
\n

Output

\n

Print the kyu M-kun has, as an integer.\nFor example, if he has 8-kyu, print 8.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

725\n
\n
\n
\n
\n
\n

Sample Output 1

7\n
\n

M-kun's highest rating is 725, which corresponds to 7-kyu.
\nThus, 7 is the correct output.

\n
\n
\n
\n
\n
\n

Sample Input 2

1600\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n

M-kun's highest rating is 1600, which corresponds to 2-kyu.
\nThus, 2 is the correct output.

\n
\n
", "id": "codenet-bug-p02600", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Given is an integer r.

\n

How many times is the area of a circle of radius r larger than the area of a circle of radius 1?

\n

It can be proved that the answer is always an integer under the constraints given.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq r \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
r\n
\n
\n
\n
\n
\n

Output

Print the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

The area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.

\n

Note that output must be an integer - for example, 4.0 will not be accepted.

\n
\n
\n
\n
\n
\n

Sample Input 2

100\n
\n
\n
\n
\n
\n

Sample Output 2

10000\n
\n
\n
", "id": "codenet-bug-p02859", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

\n

Takahashi is a teacher responsible for a class of N students.

\n

The students are given distinct student numbers from 1 to N.

\n

Today, all the students entered the classroom at different times.

\n

According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).

\n

From these records, reconstruct the order in which the students entered the classroom.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 1 \\le N \\le 10^5
  • \n
  • 1 \\le A_i \\le N
  • \n
  • A_i \\neq A_j (i \\neq j)
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 \\ldots A_N\n
\n
\n
\n
\n
\n

Output

\n

Print the student numbers of the students in the order the students entered the classroom.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n2 3 1\n
\n
\n
\n
\n
\n

Sample Output 1

3 1 2\n
\n

First, student number 3 entered the classroom.

\n

Then, student number 1 entered the classroom.

\n

Finally, student number 2 entered the classroom.

\n
\n
\n
\n
\n
\n

Sample Input 2

5\n1 2 3 4 5\n
\n
\n
\n
\n
\n

Sample Output 2

1 2 3 4 5\n
\n
\n
\n
\n
\n
\n

Sample Input 3

8\n8 2 7 3 4 5 6 1\n
\n
\n
\n
\n
\n

Sample Output 3

8 2 4 5 6 7 3 1\n
\n
\n
", "id": "codenet-bug-p02899", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There are N positive integers written on a blackboard: A_1, ..., A_N.

\n

Snuke can perform the following operation when all integers on the blackboard are even:

\n
    \n
  • Replace each integer X on the blackboard by X divided by 2.
  • \n
\n

Find the maximum possible number of operations that Snuke can perform.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 200
  • \n
  • 1 \\leq A_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 ... A_N\n
\n
\n
\n
\n
\n

Output

Print the maximum possible number of operations that Snuke can perform.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n8 12 40\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

Initially, [8, 12, 40] are written on the blackboard.\nSince all those integers are even, Snuke can perform the operation.

\n

After the operation is performed once, [4, 6, 20] are written on the blackboard.\nSince all those integers are again even, he can perform the operation.

\n

After the operation is performed twice, [2, 3, 10] are written on the blackboard.\nNow, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.

\n

Thus, Snuke can perform the operation at most twice.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n5 6 8 10\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

Since there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all.

\n
\n
\n
\n
\n
\n

Sample Input 3

6\n382253568 723152896 37802240 379425024 404894720 471526144\n
\n
\n
\n
\n
\n

Sample Output 3

8\n
\n
\n
", "id": "codenet-bug-p03494", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Takahashi is standing on a multiplication table with infinitely many rows and columns.

\n

The square (i,j) contains the integer i \\times j. Initially, Takahashi is standing at (1,1).

\n

In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).

\n

Given an integer N, find the minimum number of moves needed to reach a square that contains N.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 10^{12}
  • \n
  • N is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the minimum number of moves needed to reach a square that contains the integer N.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.

\n
\n
\n
\n
\n
\n

Sample Input 2

50\n
\n
\n
\n
\n
\n

Sample Output 2

13\n
\n

(5, 10) can be reached in 13 moves.

\n
\n
\n
\n
\n
\n

Sample Input 3

10000000019\n
\n
\n
\n
\n
\n

Sample Output 3

10000000018\n
\n

Both input and output may be enormous.

\n
\n
", "id": "codenet-bug-p02881", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given a positive integer N.\nFind the minimum positive integer divisible by both 2 and N.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

Print the minimum positive integer divisible by both 2 and N.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n
\n
\n
\n
\n
\n

Sample Output 1

6\n
\n

6 is divisible by both 2 and 3.\nAlso, there is no positive integer less than 6 that is divisible by both 2 and 3.\nThus, the answer is 6.

\n
\n
\n
\n
\n
\n

Sample Input 2

10\n
\n
\n
\n
\n
\n

Sample Output 2

10\n
\n
\n
\n
\n
\n
\n

Sample Input 3

999999999\n
\n
\n
\n
\n
\n

Sample Output 3

1999999998\n
\n
\n
", "id": "codenet-bug-p03307", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

\n

You are visiting a large electronics store to buy a refrigerator and a microwave.

\n

The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \\le i \\le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \\le j \\le B ) is sold at b_j yen.

\n

You have M discount tickets. With the i-th ticket ( 1 \\le i \\le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.

\n

You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • All values in input are integers.
  • \n
  • 1 \\le A \\le 10^5
  • \n
  • 1 \\le B \\le 10^5
  • \n
  • 1 \\le M \\le 10^5
  • \n
  • 1 \\le a_i , b_i , c_i \\le 10^5
  • \n
  • 1 \\le x_i \\le A
  • \n
  • 1 \\le y_i \\le B
  • \n
  • c_i \\le a_{x_i} + b_{y_i}
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
A B M\na_1 a_2 ... a_A\nb_1 b_2 ... b_B\nx_1 y_1 c_1\n\\vdots\nx_M y_M c_M\n
\n
\n
\n
\n
\n

Output

\n

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 3 1\n3 3\n3 3 3\n1 2 1\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

With the ticket, you can get the 1-st refrigerator and the 2-nd microwave for 3+3-1=5 yen.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 1 2\n10\n10\n1 1 5\n1 1 10\n
\n
\n
\n
\n
\n

Sample Output 2

10\n
\n

Note that you cannot use more than one ticket at a time.

\n
\n
\n
\n
\n
\n

Sample Input 3

2 2 1\n3 5\n3 5\n2 2 2\n
\n
\n
\n
\n
\n

Sample Output 3

6\n
\n

You can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is the minimum amount to pay in this case.\nNote that using a ticket is optional.

\n
\n
", "id": "codenet-bug-p02748", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

A ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \\leq i \\leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.

\n

How many times will the ball make a bounce where the coordinate is at most X?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
  • 1 \\leq L_i \\leq 100
  • \n
  • 1 \\leq X \\leq 10000
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N X\nL_1 L_2 ... L_{N-1} L_N\n
\n
\n
\n
\n
\n

Output

Print the number of times the ball will make a bounce where the coordinate is at most X.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 6\n3 4 5\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

The ball will make a bounce at the coordinates 0, 3, 7 and 12, among which two are less than or equal to 6.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 9\n3 3 3 3\n
\n
\n
\n
\n
\n

Sample Output 2

4\n
\n

The ball will make a bounce at the coordinates 0, 3, 6, 9 and 12, among which four are less than or equal to 9.

\n
\n
", "id": "codenet-bug-p03000", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

In AtCoder City, there are three stations numbered 1, 2, and 3.

\n

Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A, Company A operates Station i; if S_i is B, Company B operates Station i.

\n

To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.

\n

Determine if there is a pair of stations that will be connected by a bus service.

\n
\n
\n
\n
\n

Constraints

    \n
  • Each character of S is A or B.
  • \n
  • |S| = 3
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

If there is a pair of stations that will be connected by a bus service, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

ABA\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

Company A operates Station 1 and 3, while Company B operates Station 2.

\n

There will be a bus service between Station 1 and 2, and between Station 2 and 3, so print Yes.

\n
\n
\n
\n
\n
\n

Sample Input 2

BBA\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n
\n

Company B operates Station 1 and 2, while Company A operates Station 3.

\n

There will be a bus service between Station 1 and 3, and between Station 2 and 3, so print Yes.

\n
\n
\n
\n
\n
\n

Sample Input 3

BBB\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n

Company B operates all the stations. Thus, there will be no bus service, so print No.

\n
\n
", "id": "codenet-bug-p02753", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Given is a string S. Let T be the concatenation of K copies of S.\nWe can repeatedly perform the following operation: choose a character in T and replace it with a different character.\nFind the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq |S| \\leq 100
  • \n
  • S consists of lowercase English letters.
  • \n
  • 1 \\leq K \\leq 10^9
  • \n
  • K is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\nK\n
\n
\n
\n
\n
\n

Output

Print the minimum number of operations required.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

issii\n2\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

T is issiiissii. For example, we can rewrite it into ispiqisyhi, and now any two adjacent characters are different.

\n
\n
\n
\n
\n
\n

Sample Input 2

qq\n81\n
\n
\n
\n
\n
\n

Sample Output 2

81\n
\n
\n
\n
\n
\n
\n

Sample Input 3

cooooooooonteeeeeeeeeest\n999993333\n
\n
\n
\n
\n
\n

Sample Output 3

8999939997\n
\n
\n
", "id": "codenet-bug-p02891", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 300 points

\n
\n
\n

Problem Statement

\n

Find the minimum prime number greater than or equal to X.

\n
\n
\n
\n
\n

Notes

\n

A prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself.

\n

For example, 2, 3, and 5 are prime numbers, while 4 and 6 are not.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 2 \\le X \\le 10^5
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
X\n
\n
\n
\n
\n
\n

Output

\n

Print the minimum prime number greater than or equal to X.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

20\n
\n
\n
\n
\n
\n

Sample Output 1

23\n
\n

The minimum prime number greater than or equal to 20 is 23.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n

X itself can be a prime number.

\n
\n
\n
\n
\n
\n

Sample Input 3

99992\n
\n
\n
\n
\n
\n

Sample Output 3

100003\n
\n
\n
", "id": "codenet-bug-p02819", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N+1 towns. The i-th town is being attacked by A_i monsters.

\n

We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters.

\n

What is the maximum total number of monsters the heroes can cooperate to defeat?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 1 \\leq A_i \\leq 10^9
  • \n
  • 1 \\leq B_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 ... A_{N+1}\nB_1 B_2 ... B_N\n
\n
\n
\n
\n
\n

Output

Print the maximum total number of monsters the heroes can defeat.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n3 5 2\n4 5\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n

If the heroes choose the monsters to defeat as follows, they can defeat nine monsters in total, which is the maximum result.

\n
    \n
  • The first hero defeats two monsters attacking the first town and two monsters attacking the second town.
  • \n
  • The second hero defeats three monsters attacking the second town and two monsters attacking the third town.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

3\n5 6 3 8\n5 100 8\n
\n
\n
\n
\n
\n

Sample Output 2

22\n
\n
\n
\n
\n
\n
\n

Sample Input 3

2\n100 1 1\n1 100\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n
\n
", "id": "codenet-bug-p02959", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.

\n

Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).

\n

Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:

\n
    \n
  • If a_i = 1, he painted the region satisfying x < x_i within the rectangle.
  • \n
  • If a_i = 2, he painted the region satisfying x > x_i within the rectangle.
  • \n
  • If a_i = 3, he painted the region satisfying y < y_i within the rectangle.
  • \n
  • If a_i = 4, he painted the region satisfying y > y_i within the rectangle.
  • \n
\n

Find the area of the white region within the rectangle after he finished painting.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≦ W, H ≦ 100
  • \n
  • 1 ≦ N ≦ 100
  • \n
  • 0 ≦ x_i ≦ W (1 ≦ i ≦ N)
  • \n
  • 0 ≦ y_i ≦ H (1 ≦ i ≦ N)
  • \n
  • W, H (21:32, added), x_i and y_i are integers.
  • \n
  • a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
W H N\nx_1 y_1 a_1\nx_2 y_2 a_2\n:\nx_N y_N a_N\n
\n
\n
\n
\n
\n

Output

Print the area of the white region within the rectangle after Snuke finished painting.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 4 2\n2 1 1\n3 3 4\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n

The figure below shows the rectangle before Snuke starts painting.

\n
\n\"e19e673abcd0882783f635cce9d2f94d.png\"\n
\n

First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:

\n
\n\"f25cd04bbac23c4e5426d70511a9762f.png\"\n
\n

Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:

\n
\n\"46b0c06fd9eee4f148e1f441f7abca53.png\"\n
\n

Now, the area of the white region within the rectangle is 9.

\n
\n
\n
\n
\n
\n

Sample Input 2

5 4 3\n2 1 1\n3 3 4\n1 4 2\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

It is possible that the whole region within the rectangle is painted black.

\n
\n
\n
\n
\n
\n

Sample Input 3

10 10 5\n1 6 1\n4 1 3\n6 9 4\n9 4 2\n3 1 3\n
\n
\n
\n
\n
\n

Sample Output 3

64\n
\n
\n
", "id": "codenet-bug-p03944", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given a 4-character string S consisting of uppercase English letters.\nDetermine if S consists of exactly two kinds of characters which both appear twice in S.

\n
\n
\n
\n
\n

Constraints

    \n
  • The length of S is 4.
  • \n
  • S consists of uppercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

If S consists of exactly two kinds of characters which both appear twice in S, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

ASSA\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

S consists of A and S which both appear twice in S.

\n
\n
\n
\n
\n
\n

Sample Input 2

STOP\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n
\n
\n
\n
\n
\n

Sample Input 3

FFEE\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 4

FREE\n
\n
\n
\n
\n
\n

Sample Output 4

No\n
\n
\n
", "id": "codenet-bug-p02987", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

You drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.

\n

How many kinds of items did you get?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 2\\times 10^5
  • \n
  • S_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS_1\n:\nS_N\n
\n
\n
\n
\n
\n

Output

Print the number of kinds of items you got.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\napple\norange\napple\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

You got two kinds of items: apple and orange.

\n
\n
\n
\n
\n
\n

Sample Input 2

5\ngrape\ngrape\ngrape\ngrape\ngrape\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

4\naaaa\na\naaa\naa\n
\n
\n
\n
\n
\n

Sample Output 3

4\n
\n
\n
", "id": "codenet-bug-p02701", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There are three airports A, B and C, and flights between each pair of airports in both directions.

\n

A one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.

\n

Consider a route where we start at one of the airports, fly to another airport and then fly to the other airport.

\n

What is the minimum possible sum of the flight times?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq P,Q,R \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
P Q R\n
\n
\n
\n
\n
\n

Output

Print the minimum possible sum of the flight times.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 3 4\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n
    \n
  • The sum of the flight times in the route A \\rightarrow B \\rightarrow C: 1 + 3 = 4 hours
  • \n
  • The sum of the flight times in the route A \\rightarrow C \\rightarrow C: 4 + 3 = 7 hours
  • \n
  • The sum of the flight times in the route B \\rightarrow A \\rightarrow C: 1 + 4 = 5 hours
  • \n
  • The sum of the flight times in the route B \\rightarrow C \\rightarrow A: 3 + 4 = 7 hours
  • \n
  • The sum of the flight times in the route C \\rightarrow A \\rightarrow B: 4 + 1 = 5 hours
  • \n
  • The sum of the flight times in the route C \\rightarrow B \\rightarrow A: 3 + 1 = 4 hours
  • \n
\n

The minimum of these is 4 hours.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 2 3\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n
\n
", "id": "codenet-bug-p03011", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

You have a sequence A composed of N positive integers: A_{1}, A_{2}, \\cdots, A_{N}.

\n

You will now successively do the following Q operations:

\n
    \n
  • In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
  • \n
\n

For each i (1 \\leq i \\leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N, Q, A_{i}, B_{i}, C_{i} \\leq 10^{5}
  • \n
  • B_{i} \\neq C_{i}
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_{1} A_{2} \\cdots A_{N}\nQ\nB_{1} C_{1}\nB_{2} C_{2}\n\\vdots\nB_{Q} C_{Q}\n
\n
\n
\n
\n
\n

Output

Print Q integers S_{i} to Standard Output in the following format:

\n
S_{1}\nS_{2}\n\\vdots\nS_{Q}\n
\n

Note that S_{i} may not fit into a 32-bit integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n1 2 3 4\n3\n1 2\n3 4\n2 4\n
\n
\n
\n
\n
\n

Sample Output 1

11\n12\n16\n
\n

Initially, the sequence A is 1,2,3,4.

\n

After each operation, it becomes the following:

\n
    \n
  • 2, 2, 3, 4
  • \n
  • 2, 2, 4, 4
  • \n
  • 4, 4, 4, 4
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

4\n1 1 1 1\n3\n1 2\n2 1\n3 5\n
\n
\n
\n
\n
\n

Sample Output 2

8\n4\n4\n
\n

Note that the sequence A may not contain an element whose value is B_{i}.

\n
\n
\n
\n
\n
\n

Sample Input 3

2\n1 2\n3\n1 100\n2 100\n100 1000\n
\n
\n
\n
\n
\n

Sample Output 3

102\n200\n2000\n
\n
\n
", "id": "codenet-bug-p02630", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Snuke is buying a bicycle.\nThe bicycle of his choice does not come with a bell, so he has to buy one separately.

\n

He has very high awareness of safety, and decides to buy two bells, one for each hand.

\n

The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively.\nFind the minimum total price of two different bells.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq a,b,c \\leq 10000
  • \n
  • a, b and c are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
a b c\n
\n
\n
\n
\n
\n

Output

Print the minimum total price of two different bells.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

700 600 780\n
\n
\n
\n
\n
\n

Sample Output 1

1300\n
\n
    \n
  • Buying a 700-yen bell and a 600-yen bell costs 1300 yen.
  • \n
  • Buying a 700-yen bell and a 780-yen bell costs 1480 yen.
  • \n
  • Buying a 600-yen bell and a 780-yen bell costs 1380 yen.
  • \n
\n

The minimum among these is 1300 yen.

\n
\n
\n
\n
\n
\n

Sample Input 2

10000 10000 10000\n
\n
\n
\n
\n
\n

Sample Output 2

20000\n
\n

Buying any two bells costs 20000 yen.

\n
\n
", "id": "codenet-bug-p03671", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

We have a bingo card with a 3\\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.

\n

The MC will choose N numbers, b_1, b_2, \\cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.

\n

Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq A_{i, j} \\leq 100
  • \n
  • A_{i_1, j_1} \\neq A_{i_2, j_2} ((i_1, j_1) \\neq (i_2, j_2))
  • \n
  • 1 \\leq N \\leq 10
  • \n
  • 1 \\leq b_i \\leq 100
  • \n
  • b_i \\neq b_j (i \\neq j)
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A_{1, 1} A_{1, 2} A_{1, 3}\nA_{2, 1} A_{2, 2} A_{2, 3}\nA_{3, 1} A_{3, 2} A_{3, 3}\nN\nb_1\n\\vdots\nb_N\n
\n
\n
\n
\n
\n

Output

If we will have a bingo, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

84 97 66\n79 89 11\n61 59 7\n7\n89\n7\n87\n79\n24\n84\n30\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.

\n
\n
\n
\n
\n
\n

Sample Input 2

41 7 46\n26 89 2\n78 92 8\n5\n6\n45\n16\n57\n17\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

We will mark nothing.

\n
\n
\n
\n
\n
\n

Sample Input 3

60 88 34\n92 41 43\n65 73 48\n10\n60\n43\n88\n11\n48\n73\n65\n41\n92\n34\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n

We will mark all the squares.

\n
\n
", "id": "codenet-bug-p02760", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

\n

Given is a permutation P_1, \\ldots, P_N of 1, \\ldots, N.\nFind the number of integers i (1 \\leq i \\leq N) that satisfy the following condition:

\n
    \n
  • For any integer j (1 \\leq j \\leq i), P_i \\leq P_j.
  • \n
\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 1 \\leq N \\leq 2 \\times 10^5
  • \n
  • P_1, \\ldots, P_N is a permutation of 1, \\ldots, N.
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\nP_1 ... P_N\n
\n
\n
\n
\n
\n

Output

\n

Print the number of integers i that satisfy the condition.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n4 2 5 1 3\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

i=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.
\nSimilarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n4 3 2 1\n
\n
\n
\n
\n
\n

Sample Output 2

4\n
\n

All integers i (1 \\leq i \\leq N) satisfy the condition.

\n
\n
\n
\n
\n
\n

Sample Input 3

6\n1 2 3 4 5 6\n
\n
\n
\n
\n
\n

Sample Output 3

1\n
\n

Only i=1 satisfies the condition.

\n
\n
\n
\n
\n
\n

Sample Input 4

8\n5 7 4 2 6 8 1 3\n
\n
\n
\n
\n
\n

Sample Output 4

4\n
\n
\n
\n
\n
\n
\n

Sample Input 5

1\n1\n
\n
\n
\n
\n
\n

Sample Output 5

1\n
\n
\n
", "id": "codenet-bug-p02791", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1.

\n
    \n
  • The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
  • \n
  • The s_i-th digit from the left is c_i. \\left(i = 1, 2, \\cdots, M\\right)
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 3
  • \n
  • 0 \\leq M \\leq 5
  • \n
  • 1 \\leq s_i \\leq N
  • \n
  • 0 \\leq c_i \\leq 9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\ns_1 c_1\n\\vdots\ns_M c_M\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 3\n1 7\n3 2\n1 7\n
\n
\n
\n
\n
\n

Sample Output 1

702\n
\n

702 satisfies the conditions - its 1-st and 3-rd digits are 7 and 2, respectively - while no non-negative integer less than 702 satisfies them.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 2\n2 1\n2 3\n
\n
\n
\n
\n
\n

Sample Output 2

-1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

3 1\n1 0\n
\n
\n
\n
\n
\n

Sample Output 3

-1\n
\n
\n
", "id": "codenet-bug-p02761", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There are N gems. The value of the i-th gem is V_i.

\n

You will choose some of these gems, possibly all or none, and get them.

\n

However, you need to pay a cost of C_i to get the i-th gem.

\n

Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.

\n

Find the maximum possible value of X-Y.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 20
  • \n
  • 1 \\leq C_i, V_i \\leq 50
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nV_1 V_2 ... V_N\nC_1 C_2 ... C_N\n
\n
\n
\n
\n
\n

Output

Print the maximum possible value of X-Y.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n10 2 5\n6 3 4\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

If we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10.\nWe have X-Y = 5 here, which is the maximum possible value.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n13 21 6 19\n11 30 6 15\n
\n
\n
\n
\n
\n

Sample Output 2

6\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1\n1\n50\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03060", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

AtCoder Inc. holds a contest every Saturday.

\n

There are two types of contests called ABC and ARC, and just one of them is held at a time.

\n

The company holds these two types of contests alternately: an ARC follows an ABC and vice versa.

\n

Given a string S representing the type of the contest held last week, print the string representing the type of the contest held this week.

\n
\n
\n
\n
\n

Constraints

    \n
  • S is ABC or ARC.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the string representing the type of the contest held this week.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

ABC\n
\n
\n
\n
\n
\n

Sample Output 1

ARC\n
\n

They held an ABC last week, so they will hold an ARC this week.

\n
\n
", "id": "codenet-bug-p02687", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given a string S. Each character of S is uppercase or lowercase English letter.\nDetermine if S satisfies all of the following conditions:

\n
    \n
  • The initial character of S is an uppercase A.
  • \n
  • There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).
  • \n
  • All letters except the A and C mentioned above are lowercase.
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • 4 ≤ |S| ≤ 10 (|S| is the length of the string S.)
  • \n
  • Each character of S is uppercase or lowercase English letter.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

If S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

AtCoder\n
\n
\n
\n
\n
\n

Sample Output 1

AC\n
\n

The first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.

\n
\n
\n
\n
\n
\n

Sample Input 2

ACoder\n
\n
\n
\n
\n
\n

Sample Output 2

WA\n
\n

The second letter should not be C.

\n
\n
\n
\n
\n
\n

Sample Input 3

AcycliC\n
\n
\n
\n
\n
\n

Sample Output 3

WA\n
\n

The last letter should not be C, either.

\n
\n
\n
\n
\n
\n

Sample Input 4

AtCoCo\n
\n
\n
\n
\n
\n

Sample Output 4

WA\n
\n

There should not be two or more occurrences of C.

\n
\n
\n
\n
\n
\n

Sample Input 5

Atcoder\n
\n
\n
\n
\n
\n

Sample Output 5

WA\n
\n

The number of C should not be zero, either.

\n
\n
", "id": "codenet-bug-p03289", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

You are given a sequence of length N: A_1, A_2, ..., A_N.\nFor each integer i between 1 and N (inclusive), answer the following question:

\n
    \n
  • Find the maximum value among the N-1 elements other than A_i in the sequence.
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 200000
  • \n
  • 1 \\leq A_i \\leq 200000
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1\n:\nA_N\n
\n
\n
\n
\n
\n

Output

Print N lines. The i-th line (1 \\leq i \\leq N) should contain the maximum value among the N-1 elements other than A_i in the sequence.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n1\n4\n3\n
\n
\n
\n
\n
\n

Sample Output 1

4\n3\n4\n
\n
    \n
  • The maximum value among the two elements other than A_1, that is, A_2 = 4 and A_3 = 3, is 4.
  • \n
  • The maximum value among the two elements other than A_2, that is, A_1 = 1 and A_3 = 3, is 3.
  • \n
  • The maximum value among the two elements other than A_3, that is, A_1 = 1 and A_2 = 4, is 4.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

2\n5\n5\n
\n
\n
\n
\n
\n

Sample Output 2

5\n5\n
\n
\n
", "id": "codenet-bug-p02971", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

We have five variables x_1, x_2, x_3, x_4, and x_5.

\n

The variable x_i was initially assigned a value of i.

\n

Snuke chose one of these variables and assigned it 0.

\n

You are given the values of the five variables after this assignment.

\n

Find out which variable Snuke assigned 0.

\n
\n
\n
\n
\n

Constraints

    \n
  • The values of x_1, x_2, x_3, x_4, and x_5 given as input are a possible outcome of the assignment by Snuke.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
x_1 x_2 x_3 x_4 x_5\n
\n
\n
\n
\n
\n

Output

If the variable Snuke assigned 0 was x_i, print the integer i.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

0 2 3 4 5\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

In this case, Snuke assigned 0 to x_1, so we should print 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 2 0 4 5\n
\n
\n
\n
\n
\n

Sample Output 2

3\n
\n
\n
", "id": "codenet-bug-p02639", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

Given is a string S consisting of L and R.

\n

Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left.

\n

The character written on the leftmost square is always R, and the character written on the rightmost square is always L.

\n

Initially, one child is standing on each square.

\n

Each child will perform the move below 10^{100} times:

\n
    \n
  • Move one square in the direction specified by the character written in the square on which the child is standing. L denotes left, and R denotes right.
  • \n
\n

Find the number of children standing on each square after the children performed the moves.

\n
\n
\n
\n
\n

Constraints

    \n
  • S is a string of length between 2 and 10^5 (inclusive).
  • \n
  • Each character of S is L or R.
  • \n
  • The first and last characters of S are R and L, respectively.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the number of children standing on each square after the children performed the moves, in order from left to right.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

RRLRL\n
\n
\n
\n
\n
\n

Sample Output 1

0 1 2 1 1\n
\n
    \n
  • After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.
  • \n
  • After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.
  • \n
  • After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

RRLLLLRLRRLL\n
\n
\n
\n
\n
\n

Sample Output 2

0 3 3 0 0 0 1 1 0 2 2 0\n
\n
\n
\n
\n
\n
\n

Sample Input 3

RRRLLRLLRRRLLLLL\n
\n
\n
\n
\n
\n

Sample Output 3

0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0\n
\n
\n
", "id": "codenet-bug-p02954", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given an H × W grid.
\nThe squares in the grid are described by H strings, S_1,...,S_H.
\nThe j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \\leq i \\leq H,1 \\leq j \\leq W).
\n. stands for an empty square, and # stands for a square containing a bomb.

\n

Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.
\n(Below, we will simply say \"adjacent\" for this meaning. For each square, there are at most eight adjacent squares.)
\nHe decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.

\n

Print the strings after the process.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq H,W \\leq 50
  • \n
  • S_i is a string of length W consisting of # and ..
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
H W\nS_1\n:\nS_H\n
\n
\n
\n
\n
\n

Output

Print the H strings after the process.
\nThe i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \\leq i \\leq H, 1 \\leq j \\leq W).

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 5\n.....\n.#.#.\n.....\n
\n
\n
\n
\n
\n

Sample Output 1

11211\n1#2#1\n11211\n
\n

For example, let us observe the empty square at the first row from the top and first column from the left.
\nThere is one bomb square adjacent to this empty square: the square at the second row and second column.
\nThus, the . corresponding to this empty square is replaced with 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 5\n#####\n#####\n#####\n
\n
\n
\n
\n
\n

Sample Output 2

#####\n#####\n#####\n
\n

It is possible that there is no empty square.

\n
\n
\n
\n
\n
\n

Sample Input 3

6 6\n#####.\n#.#.##\n####.#\n.#..#.\n#.##..\n#.#...\n
\n
\n
\n
\n
\n

Sample Output 3

#####3\n#8#7##\n####5#\n4#65#2\n#5##21\n#4#310\n
\n
\n
", "id": "codenet-bug-p03574", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 500 points

\n
\n
\n

Problem Statement

We have a two-dimensional grid with H \\times W squares. There are M targets to destroy in this grid - the position of the i-th target is \\left(h_i, w_i \\right).

\n

Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.

\n

Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq H, W \\leq 3 \\times 10^5
  • \n
  • 1 \\leq M \\leq \\min\\left(H\\times W, 3 \\times 10^5\\right)
  • \n
  • 1 \\leq h_i \\leq H
  • \n
  • 1 \\leq w_i \\leq W
  • \n
  • \\left(h_i, w_i\\right) \\neq \\left(h_j, w_j\\right) \\left(i \\neq j\\right)
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
H W M\nh_1 w_1\n\\vdots\nh_M w_M\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 3 3\n2 2\n1 1\n1 3\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

We can destroy all the targets by placing the bomb at \\left(1, 2\\right).

\n
\n
\n
\n
\n
\n

Sample Input 2

3 3 4\n3 3\n3 1\n1 1\n1 2\n
\n
\n
\n
\n
\n

Sample Output 2

3\n
\n
\n
\n
\n
\n
\n

Sample Input 3

5 5 10\n2 5\n4 3\n2 3\n5 5\n2 2\n5 4\n5 3\n5 1\n3 5\n1 4\n
\n
\n
\n
\n
\n

Sample Output 3

6\n
\n
\n
", "id": "codenet-bug-p02580", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

N Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town.

\n

There are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \\cdots, A_{i, {d_i}}.

\n

Takahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 100
  • \n
  • 1 \\leq K \\leq 100
  • \n
  • 1 \\leq d_i \\leq N
  • \n
  • 1 \\leq A_{i, 1} < \\cdots < A_{i, d_i} \\leq N
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\nd_1\nA_{1, 1} \\cdots A_{1, d_1}\n\\vdots\nd_K\nA_{K, 1} \\cdots A_{K, d_K}\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 2\n2\n1 3\n1\n3\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n
    \n
  • Snuke 1 has Snack 1.
  • \n
  • Snuke 2 has no snacks.
  • \n
  • Snuke 3 has Snack 1 and 2.
  • \n
\n

Thus, there will be one victim: Snuke 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 3\n1\n3\n1\n3\n1\n3\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n
\n
", "id": "codenet-bug-p02688", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.

\n

You can perform the following operation on this integer sequence any number of times:

\n

Operation: Choose an integer i satisfying 1 \\leq i \\leq N-1. Multiply both A_i and A_{i+1} by -1.

\n

Let B_1, B_2, ..., B_N be the integer sequence after your operations.

\n

Find the maximum possible value of B_1 + B_2 + ... + B_N.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 10^5
  • \n
  • -10^9 \\leq A_i \\leq 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 ... A_N\n
\n
\n
\n
\n
\n

Output

Print the maximum possible value of B_1 + B_2 + ... + B_N.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n-10 5 -4\n
\n
\n
\n
\n
\n

Sample Output 1

19\n
\n

If we perform the operation as follows:

\n
    \n
  • Choose 1 as i, which changes the sequence to 10, -5, -4.
  • \n
  • Choose 2 as i, which changes the sequence to 10, 5, 4.
  • \n
\n

we have B_1 = 10, B_2 = 5, B_3 = 4. The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4 = 19, is the maximum possible result.

\n
\n
\n
\n
\n
\n

Sample Input 2

5\n10 -4 -8 -11 3\n
\n
\n
\n
\n
\n

Sample Output 2

30\n
\n
\n
\n
\n
\n
\n

Sample Input 3

11\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000\n
\n
\n
\n
\n
\n

Sample Output 3

10000000000\n
\n

The output may not fit into a 32-bit integer type.

\n
\n
", "id": "codenet-bug-p03062", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.

\n

Operation: Choose one character of S and replace it with a different character.

\n
\n
\n
\n
\n

Constraints

    \n
  • S and T have lengths between 1 and 2\\times 10^5 (inclusive).
  • \n
  • S and T consists of lowercase English letters.
  • \n
  • S and T have equal lengths.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\nT\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

cupofcoffee\ncupofhottea\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

We can achieve the objective in four operations, such as the following:

\n
    \n
  • First, replace the sixth character c with h.
  • \n
  • Second, replace the eighth character f with t.
  • \n
  • Third, replace the ninth character f with t.
  • \n
  • Fourth, replace the eleventh character e with a.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

abcde\nbcdea\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n
\n
\n
\n
\n
\n

Sample Input 3

apple\napple\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

No operations may be needed to achieve the objective.

\n
\n
", "id": "codenet-bug-p02622", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.

\n

Given an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
  • N is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

If N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

10 can be represented as, for example, 2 \\times 5.

\n
\n
\n
\n
\n
\n

Sample Input 2

50\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

50 cannot be represented as the product of two integers between 1 and 9.

\n
\n
\n
\n
\n
\n

Sample Input 3

81\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p02880", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

\n

A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:

\n
    \n
  • In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.
  • \n
\n

For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.

\n

You are given a positive integer K. Find the K-th smallest lunlun number.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 1 \\leq K \\leq 10^5
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
K\n
\n
\n
\n
\n
\n

Output

\n

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

15\n
\n
\n
\n
\n
\n

Sample Output 1

23\n
\n

We will list the 15 smallest lunlun numbers in ascending order:
\n1,\n2,\n3,\n4,\n5,\n6,\n7,\n8,\n9,\n10,\n11,\n12,\n21,\n22,\n23.
\nThus, the answer is 23.

\n
\n
\n
\n
\n
\n

Sample Input 2

1\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

13\n
\n
\n
\n
\n
\n

Sample Output 3

21\n
\n
\n
\n
\n
\n
\n

Sample Input 4

100000\n
\n
\n
\n
\n
\n

Sample Output 4

3234566667\n
\n

Note that the answer may not fit into the 32-bit signed integer type.

\n
\n
", "id": "codenet-bug-p02720", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

A string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:

\n
    \n
  • S is a palindrome.
  • \n
  • Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.
  • \n
  • The string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.
  • \n
\n

Determine whether S is a strong palindrome.

\n
\n
\n
\n
\n

Constraints

    \n
  • S consists of lowercase English letters.
  • \n
  • The length of S is an odd number between 3 and 99 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

If S is a strong palindrome, print Yes;\notherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

akasaka\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n
    \n
  • S is akasaka.
  • \n
  • The string formed by the 1-st through the 3-rd characters is aka.
  • \n
  • The string formed by the 5-th through the 7-th characters is aka.\nAll of these are palindromes, so S is a strong palindrome.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

level\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n
\n
\n
\n
\n
\n

Sample Input 3

atcoder\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
", "id": "codenet-bug-p02730", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 100 points

\n
\n
\n

Problem Statement

\n

In AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectively.
\nTwo antennas can communicate directly if the distance between them is k or less, and they cannot if the distance is greater than k.
\nDetermine if there exists a pair of antennas that cannot communicate directly.
\nHere, assume that the distance between two antennas at coordinates p and q (p < q) is q - p.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • a, b, c, d, e and k are integers between 0 and 123 (inclusive).
  • \n
  • a < b < c < d < e
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
a\nb\nc\nd\ne\nk\n
\n
\n
\n
\n
\n

Output

\n

Print :( if there exists a pair of antennas that cannot communicate directly, and print Yay! if there is no such pair.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1\n2\n4\n8\n9\n15\n
\n
\n
\n
\n
\n

Sample Output 1

Yay!\n
\n

In this case, there is no pair of antennas that cannot communicate directly, because:

\n
    \n
  • the distance between A and B is 2 - 1 = 1
  • \n
  • the distance between A and C is 4 - 1 = 3
  • \n
  • the distance between A and D is 8 - 1 = 7
  • \n
  • the distance between A and E is 9 - 1 = 8
  • \n
  • the distance between B and C is 4 - 2 = 2
  • \n
  • the distance between B and D is 8 - 2 = 6
  • \n
  • the distance between B and E is 9 - 2 = 7
  • \n
  • the distance between C and D is 8 - 4 = 4
  • \n
  • the distance between C and E is 9 - 4 = 5
  • \n
  • the distance between D and E is 9 - 8 = 1
  • \n
\n

and none of them is greater than 15. Thus, the correct output is Yay!.

\n
\n
\n
\n
\n
\n

Sample Input 2

15\n18\n26\n35\n36\n18\n
\n
\n
\n
\n
\n

Sample Output 2

:(\n
\n

In this case, the distance between antennas A and D is 35 - 15 = 20 and exceeds 18, so they cannot communicate directly.\nThus, the correct output is :(.

\n
\n
", "id": "codenet-bug-p03075", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

We have two integers: A and B.

\n

Print the largest number among A + B, A - B, and A \\times B.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • -100 \\leq A,\\ B \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

Print the largest number among A + B, A - B, and A \\times B.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

-13 3\n
\n
\n
\n
\n
\n

Sample Output 1

-10\n
\n

The largest number among A + B = -10, A - B = -16, and A \\times B = -39 is -10.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 -33\n
\n
\n
\n
\n
\n

Sample Output 2

34\n
\n

The largest number among A + B = -32, A - B = 34, and A \\times B = -33 is 34.

\n
\n
\n
\n
\n
\n

Sample Input 3

13 3\n
\n
\n
\n
\n
\n

Sample Output 3

39\n
\n

The largest number among A + B = 16, A - B = 10, and A \\times B = 39 is 39.

\n
\n
", "id": "codenet-bug-p02945", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

Given is an integer S.\nFind how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S.\nThe answer can be very large, so output it modulo 10^9 + 7.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq S \\leq 2000
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

7\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

3 sequences satisfy the condition: \\{3,4\\}, \\{4,3\\} and \\{7\\}.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

There are no sequences that satisfy the condition.

\n
\n
\n
\n
\n
\n

Sample Input 3

1729\n
\n
\n
\n
\n
\n

Sample Output 3

294867501\n
\n
\n
", "id": "codenet-bug-p02555", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Alice, Bob and Charlie are playing Card Game for Three, as below:

\n
    \n
  • At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.
  • \n
  • The players take turns. Alice goes first.
  • \n
  • If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)
  • \n
  • If the current player's deck is empty, the game ends and the current player wins the game.
  • \n
\n

You are given the initial decks of the players.\nMore specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way.

\n

Determine the winner of the game.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≦|S_A|≦100
  • \n
  • 1≦|S_B|≦100
  • \n
  • 1≦|S_C|≦100
  • \n
  • Each letter in S_A, S_B, S_C is a, b or c.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
S_A\nS_B\nS_C\n
\n
\n
\n
\n
\n

Output

If Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

aca\naccc\nca\n
\n
\n
\n
\n
\n

Sample Output 1

A\n
\n

The game will progress as below:

\n
    \n
  • Alice discards the top card in her deck, a. Alice takes the next turn.
  • \n
  • Alice discards the top card in her deck, c. Charlie takes the next turn.
  • \n
  • Charlie discards the top card in his deck, c. Charlie takes the next turn.
  • \n
  • Charlie discards the top card in his deck, a. Alice takes the next turn.
  • \n
  • Alice discards the top card in her deck, a. Alice takes the next turn.
  • \n
  • Alice's deck is empty. The game ends and Alice wins the game.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

abcb\naacb\nbccc\n
\n
\n
\n
\n
\n

Sample Output 2

C\n
\n
\n
", "id": "codenet-bug-p03998", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each.\nDetermine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes.

\n
\n
\n
\n
\n

Constraints

    \n
  • N is an integer between 1 and 100, inclusive.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

If there is a way to buy some cakes and some doughnuts for exactly N dollars, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

11\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

If you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.

\n
\n
\n
\n
\n
\n

Sample Input 2

40\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n
\n

If you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.

\n
\n
\n
\n
\n
\n

Sample Input 3

3\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n

The prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than 3 dollars, so there is no such way.

\n
\n
", "id": "codenet-bug-p03285", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Takahashi is a member of a programming competition site, ButCoder.

\n

Each member of ButCoder is assigned two values: Inner Rating and Displayed Rating.

\n

The Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests. Otherwise, the Displayed Rating will be their Inner Rating minus 100 \\times (10 - K) when the member has participated in K contests.

\n

Takahashi has participated in N contests, and his Displayed Rating is R. Find his Inner Rating.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 100
  • \n
  • 0 \\leq R \\leq 4111
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N R\n
\n
\n
\n
\n
\n

Output

Print his Inner Rating.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 2919\n
\n
\n
\n
\n
\n

Sample Output 1

3719\n
\n

Takahashi has participated in 2 contests, which is less than 10, so his Displayed Rating is his Inner Rating minus 100 \\times (10 - 2) = 800.

\n

Thus, Takahashi's Inner Rating is 2919 + 800 = 3719.

\n
\n
\n
\n
\n
\n

Sample Input 2

22 3051\n
\n
\n
\n
\n
\n

Sample Output 2

3051\n
\n
\n
", "id": "codenet-bug-p02765", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Given is a string S representing the day of the week today.

\n

S is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.

\n

After how many days is the next Sunday (tomorrow or later)?

\n
\n
\n
\n
\n

Constraints

    \n
  • S is SUN, MON, TUE, WED, THU, FRI, or SAT.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the number of days before the next Sunday.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

SAT\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

It is Saturday today, and tomorrow will be Sunday.

\n
\n
\n
\n
\n
\n

Sample Input 2

SUN\n
\n
\n
\n
\n
\n

Sample Output 2

7\n
\n

It is Sunday today, and seven days later, it will be Sunday again.

\n
\n
", "id": "codenet-bug-p02847", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Snuke is giving cookies to his three goats.

\n

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).

\n

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.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A,B \\leq 100
  • \n
  • Both A and B are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

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.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 5\n
\n
\n
\n
\n
\n

Sample Output 1

Possible\n
\n

If Snuke gives nine cookies, each of the three goats can have three cookies.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 1\n
\n
\n
\n
\n
\n

Sample Output 2

Impossible\n
\n

Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.

\n
\n
", "id": "codenet-bug-p03657", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

As a New Year's gift, Dolphin received a string s of length 19.
\nThe string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters].
\nDolphin wants to convert the comma-separated string s into a space-separated string.
\nWrite a program to perform the conversion for him.

\n
\n
\n
\n
\n

Constraints

    \n
  • The length of s is 19.
  • \n
  • The sixth and fourteenth characters in s are ,.
  • \n
  • The other characters in s are lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
s\n
\n
\n
\n
\n
\n

Output

Print the string after the conversion.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

happy,newyear,enjoy\n
\n
\n
\n
\n
\n

Sample Output 1

happy newyear enjoy\n
\n

Replace all the commas in happy,newyear,enjoy with spaces to obtain happy newyear enjoy.

\n
\n
\n
\n
\n
\n

Sample Input 2

haiku,atcoder,tasks\n
\n
\n
\n
\n
\n

Sample Output 2

haiku atcoder tasks\n
\n
\n
\n
\n
\n
\n

Sample Input 3

abcde,fghihgf,edcba\n
\n
\n
\n
\n
\n

Sample Output 3

abcde fghihgf edcba\n
\n
\n
", "id": "codenet-bug-p03834", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Two students of AtCoder Kindergarten are fighting over candy packs.

\n

There are three candy packs, each of which contains a, b, and c candies, respectively.

\n

Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.

\n

Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≦ a, b, c ≦ 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
a b c\n
\n
\n
\n
\n
\n

Output

If it is possible to distribute the packs so that each student gets the same number of candies, print Yes. Otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10 30 20\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

Give the pack with 30 candies to one student, and give the two packs with 10 and 20 candies to the other. Then, each gets 30 candies.

\n
\n
\n
\n
\n
\n

Sample Input 2

30 30 100\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

In this case, the student who gets the pack with 100 candies always has more candies than the other.

\n

Note that every pack must be given to one of them.

\n
\n
\n
\n
\n
\n

Sample Input 3

56 25 31\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p03943", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L.

\n

She will concatenate all of the strings in some order, to produce a long string.

\n

Among all strings that she can produce in this way, find the lexicographically smallest one.

\n

Here, a string s=s_1s_2s_3...s_n is lexicographically smaller than another string t=t_1t_2t_3...t_m if and only if one of the following holds:\n

    \n
  • There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i.
  • \n
  • s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
  • \n

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≦ N, L ≦ 100
  • \n
  • For each i, the length of S_i equals L.
  • \n
  • For each i, S_i consists of lowercase letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
N L\nS_1\nS_2\n:\nS_N\n
\n
\n
\n
\n
\n

Output

Print the lexicographically smallest string that Iroha can produce.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 3\ndxx\naxx\ncxx\n
\n
\n
\n
\n
\n

Sample Output 1

axxcxxdxx\n
\n

The following order should be used: axx, cxx, dxx.

\n
\n
", "id": "codenet-bug-p04044", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 500 points

\n
\n
\n

Problem Statement

We have N logs of lengths A_1,A_2,\\cdots A_N.

\n

We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.

\n

Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 2 \\times 10^5
  • \n
  • 0 \\leq K \\leq 10^9
  • \n
  • 1 \\leq A_i \\leq 10^9
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\nA_1 A_2 \\cdots A_N\n
\n
\n
\n
\n
\n

Output

Print an integer representing the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 3\n7 9\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n
    \n
  • First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5, resulting in two logs of length 3.5 each.
  • \n
  • Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3, resulting in two logs of length 3 and 6.
  • \n
  • Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3, resulting in two logs of length 3.3 and 2.7.
  • \n
\n

In this case, the longest length of a log will be 3.5, which is the shortest possible result. After rounding up to an integer, the output should be 4.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 0\n3 4 5\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n
\n
\n
\n
\n
\n

Sample Input 3

10 10\n158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202\n
\n
\n
\n
\n
\n

Sample Output 3

292638192\n
\n
\n
", "id": "codenet-bug-p02598", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \\ldots, p_N.

\n

Among the integers not contained in the sequence p_1, \\ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq X \\leq 100
  • \n
  • 0 \\leq N \\leq 100
  • \n
  • 1 \\leq p_i \\leq 100
  • \n
  • p_1, \\ldots, p_N are all distinct.
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
X N\np_1 ... p_N\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6 5\n4 7 10 6 5\n
\n
\n
\n
\n
\n

Sample Output 1

8\n
\n

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

\n
\n
\n
\n
\n
\n

Sample Input 2

10 5\n4 7 10 6 5\n
\n
\n
\n
\n
\n

Sample Output 2

9\n
\n

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

\n
\n
\n
\n
\n
\n

Sample Input 3

100 0\n\n
\n
\n
\n
\n
\n

Sample Output 3

100\n
\n

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.

\n
\n
", "id": "codenet-bug-p02641", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given three strings A, B and C. Check whether they form a word chain.

\n

More formally, determine whether both of the following are true:

\n
    \n
  • The last character in A and the initial character in B are the same.
  • \n
  • The last character in B and the initial character in C are the same.
  • \n
\n

If both are true, print YES. Otherwise, print NO.

\n
\n
\n
\n
\n

Constraints

    \n
  • A, B and C are all composed of lowercase English letters (a - z).
  • \n
  • 1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

Print YES or NO.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

rng gorilla apple\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

They form a word chain.

\n
\n
\n
\n
\n
\n

Sample Input 2

yakiniku unagi sushi\n
\n
\n
\n
\n
\n

Sample Output 2

NO\n
\n

A and B form a word chain, but B and C do not.

\n
\n
\n
\n
\n
\n

Sample Input 3

a a a\n
\n
\n
\n
\n
\n

Sample Output 3

YES\n
\n
\n
\n
\n
\n
\n

Sample Input 4

aaaaaaaaab aaaaaaaaaa aaaaaaaaab\n
\n
\n
\n
\n
\n

Sample Output 4

NO\n
\n
\n
", "id": "codenet-bug-p03729", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

We have N ID cards, and there are M gates.

\n

We can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards.

\n

How many of the ID cards allow us to pass all the gates alone?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 1 \\leq M \\leq 10^5
  • \n
  • 1 \\leq L_i \\leq R_i \\leq N
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\nL_1 R_1\nL_2 R_2\n\\vdots\nL_M R_M\n
\n
\n
\n
\n
\n

Output

Print the number of ID cards that allow us to pass all the gates alone.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 2\n1 3\n2 4\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

Two ID cards allow us to pass all the gates alone, as follows:

\n
    \n
  • The first ID card does not allow us to pass the second gate.
  • \n
  • The second ID card allows us to pass all the gates.
  • \n
  • The third ID card allows us to pass all the gates.
  • \n
  • The fourth ID card does not allow us to pass the first gate.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

10 3\n3 6\n5 7\n6 9\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n
\n
\n
\n
\n
\n

Sample Input 3

100000 1\n1 100000\n
\n
\n
\n
\n
\n

Sample Output 3

100000\n
\n
\n
", "id": "codenet-bug-p03037", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.

\n
\n
\n
\n
\n

Constraints

    \n
  • S and T are strings consisting of lowercase English letters.
  • \n
  • The lengths of S and T are between 1 and 100 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S T\n
\n
\n
\n
\n
\n

Output

Print the resulting string.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

oder atc\n
\n
\n
\n
\n
\n

Sample Output 1

atcoder\n
\n

When S = oder and T = atc, concatenating T and S in this order results in atcoder.

\n
\n
\n
\n
\n
\n

Sample Input 2

humu humu\n
\n
\n
\n
\n
\n

Sample Output 2

humuhumu\n
\n
\n
", "id": "codenet-bug-p02817", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 200 points

\n
\n
\n

Problem Statement

\n

We have N cards. A number a_i is written on the i-th card.
\nAlice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
\nThe game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • N is an integer between 1 and 100 (inclusive).
  • \n
  • a_i \\ (1 \\leq i \\leq N) is an integer between 1 and 100 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\na_1 a_2 a_3 ... a_N\n
\n
\n
\n
\n
\n

Output

\n

Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2\n3 1\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

First, Alice will take the card with 3. Then, Bob will take the card with 1.\nThe difference of their scores will be 3 - 1 = 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\n2 7 4\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n

First, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.

\n
\n
\n
\n
\n
\n

Sample Input 3

4\n20 18 2 18\n
\n
\n
\n
\n
\n

Sample Output 3

18\n
\n
\n
", "id": "codenet-bug-p03434", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.

\n

The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.\nThese buttons are numbered 1 through N.\nWhen Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i.\nWhen Button i is not lighten up, nothing will happen by pressing it.

\n

Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.

\n

Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 ≤ N ≤ 10^5
  • \n
  • 1 ≤ a_i ≤ N
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\na_1\na_2\n:\na_N\n
\n
\n
\n
\n
\n

Output

Print -1 if it is impossible to lighten up Button 2.\nOtherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n3\n1\n2\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

Press Button 1, then Button 3.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\n3\n4\n1\n2\n
\n
\n
\n
\n
\n

Sample Output 2

-1\n
\n

Pressing Button 1 lightens up Button 3, and vice versa, so Button 2 will never be lighten up.

\n
\n
\n
\n
\n
\n

Sample Input 3

5\n3\n3\n4\n2\n4\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n
\n
", "id": "codenet-bug-p03680", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

We have a grid with N rows and M columns of squares. Initially, all the squares are white.

\n

There is a button attached to each row and each column.\nWhen a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa.\nWhen a button attached to a column is pressed, the colors of all the squares in that column are inverted.

\n

Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N,M \\leq 1000
  • \n
  • 0 \\leq K \\leq NM
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M K\n
\n
\n
\n
\n
\n

Output

If Takahashi can have exactly K black squares in the grid, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 2 2\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

Press the buttons in the order of the first row, the first column.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 2 1\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n
\n
\n
\n
\n
\n

Sample Input 3

3 5 8\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n

Press the buttons in the order of the first column, third column, second row, fifth column.

\n
\n
\n
\n
\n
\n

Sample Input 4

7 9 20\n
\n
\n
\n
\n
\n

Sample Output 4

No\n
\n
\n
", "id": "codenet-bug-p03592", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.

\n

Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ N ≤ 100
  • \n
  • 1 ≤ d_i ≤ 100
  • \n
  • All input values are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nd_1\n:\nd_N\n
\n
\n
\n
\n
\n

Output

Print the maximum number of layers in a kagami mochi that can be made.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\n10\n8\n8\n6\n
\n
\n
\n
\n
\n

Sample Output 1

3\n
\n

If we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\n15\n15\n15\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

When all the mochi have the same diameter, we can only have a 1-layered kagami mochi.

\n
\n
\n
\n
\n
\n

Sample Input 3

7\n50\n30\n50\n100\n50\n80\n30\n
\n
\n
\n
\n
\n

Sample Output 3

4\n
\n
\n
", "id": "codenet-bug-p03470", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 200 points

\n
\n
\n

Problem Statement

\n

M-kun has the following three cards:

\n
    \n
  • A red card with the integer A.
  • \n
  • A green card with the integer B.
  • \n
  • A blue card with the integer C.
  • \n
\n

He is a genius magician who can do the following operation at most K times:

\n
    \n
  • Choose one of the three cards and multiply the written integer by 2.
  • \n
\n

His magic is successful if both of the following conditions are satisfied after the operations:

\n
    \n
  • The integer on the green card is strictly greater than the integer on the red card.
  • \n
  • The integer on the blue card is strictly greater than the integer on the green card.
  • \n
\n

Determine whether the magic can be successful.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 1 \\leq A, B, C \\leq 7
  • \n
  • 1 \\leq K \\leq 7
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
A B C\nK\n
\n
\n
\n
\n
\n

Output

\n

If the magic can be successful, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

7 2 5\n3\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

The magic will be successful if, for example, he does the following operations:

\n
    \n
  • First, choose the blue card. The integers on the red, green, and blue cards are now 7, 2, and 10, respectively.
  • \n
  • Second, choose the green card. The integers on the red, green, and blue cards are now 7, 4, and 10, respectively.
  • \n
  • Third, choose the green card. The integers on the red, green, and blue cards are now 7, 8, and 10, respectively.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

7 4 2\n3\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

He has no way to succeed in the magic with at most three operations.

\n
\n
", "id": "codenet-bug-p02601", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

There are N points in a D-dimensional space.

\n

The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}).

\n

The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \\sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}.

\n

How many pairs (i, j) (i < j) are there such that the distance between the i-th point and the j-th point is an integer?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 2 \\leq N \\leq 10
  • \n
  • 1 \\leq D \\leq 10
  • \n
  • -20 \\leq X_{ij} \\leq 20
  • \n
  • No two given points have the same coordinates. That is, if i \\neq j, there exists k such that X_{ik} \\neq X_{jk}.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N D\nX_{11} X_{12} ... X_{1D}\nX_{21} X_{22} ... X_{2D}\n\\vdots\nX_{N1} X_{N2} ... X_{ND}\n
\n
\n
\n
\n
\n

Output

Print the number of pairs (i, j) (i < j) such that the distance between the i-th point and the j-th point is an integer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 2\n1 2\n5 5\n-2 8\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

The number of pairs with an integer distance is one, as follows:

\n
    \n
  • The distance between the first point and the second point is \\sqrt{|1-5|^2 + |2-5|^2} = 5, which is an integer.
  • \n
  • The distance between the second point and the third point is \\sqrt{|5-(-2)|^2 + |5-8|^2} = \\sqrt{58}, which is not an integer.
  • \n
  • The distance between the third point and the first point is \\sqrt{|-2-1|^2+|8-2|^2} = 3\\sqrt{5}, which is not an integer.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

3 4\n-3 7 8 2\n-12 1 10 2\n-2 8 9 3\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n
\n
\n
\n
\n
\n

Sample Input 3

5 1\n1\n2\n3\n4\n5\n
\n
\n
\n
\n
\n

Sample Output 3

10\n
\n
\n
", "id": "codenet-bug-p02982", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

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.

\n

How many grams of sand will the upper bulb contains after t seconds?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1≤X≤10^9
  • \n
  • 1≤t≤10^9
  • \n
  • X and t are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
X t\n
\n
\n
\n
\n
\n

Output

Print the number of sand in the upper bulb after t second.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

100 17\n
\n
\n
\n
\n
\n

Sample Output 1

83\n
\n

17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams.

\n
\n
\n
\n
\n
\n

Sample Input 2

48 58\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

All 48 grams of sand will be gone, resulting in 0 grams.

\n
\n
\n
\n
\n
\n

Sample Input 3

1000000000 1000000000\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
", "id": "codenet-bug-p03609", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

We conducted a survey on newspaper subscriptions.\nMore specifically, we asked each of the N respondents the following two questions:

\n
    \n
  • Question 1: Are you subscribing to Newspaper X?
  • \n
  • Question 2: Are you subscribing to Newspaper Y?
  • \n
\n

As the result, A respondents answered \"yes\" to Question 1, and B respondents answered \"yes\" to Question 2.

\n

What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?

\n

Write a program to answer this question.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
  • 0 \\leq A \\leq N
  • \n
  • 0 \\leq B \\leq N
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N A B\n
\n
\n
\n
\n
\n

Output

Print the maximum possible number and the minimum possible number of respondents subscribing to both newspapers, in this order, with a space in between.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

10 3 5\n
\n
\n
\n
\n
\n

Sample Output 1

3 0\n
\n

In this sample, out of the 10 respondents, 3 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.

\n

Here, the number of respondents subscribing to both newspapers is at most 3 and at least 0.

\n
\n
\n
\n
\n
\n

Sample Input 2

10 7 5\n
\n
\n
\n
\n
\n

Sample Output 2

5 2\n
\n

In this sample, out of the 10 respondents, 7 answered they are subscribing to Newspaper X, and 5 answered they are subscribing to Newspaper Y.

\n

Here, the number of respondents subscribing to both newspapers is at most 5 and at least 2.

\n
\n
\n
\n
\n
\n

Sample Input 3

100 100 100\n
\n
\n
\n
\n
\n

Sample Output 3

100 100\n
\n
\n
", "id": "codenet-bug-p03139", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

There are N people. The name of the i-th person is S_i.

\n

We would like to choose three people so that the following conditions are met:

\n
    \n
  • The name of every chosen person begins with M, A, R, C or H.
  • \n
  • There are no multiple people whose names begin with the same letter.
  • \n
\n

How many such ways are there to choose three people, disregarding order?

\n

Note that the answer may not fit into a 32-bit integer type.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^5
  • \n
  • S_i consists of uppercase English letters.
  • \n
  • 1 \\leq |S_i| \\leq 10
  • \n
  • S_i \\neq S_j (i \\neq j)
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS_1\n:\nS_N\n
\n
\n
\n
\n
\n

Output

If there are x ways to choose three people so that the given conditions are met, print x.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

We can choose three people with the following names:

\n
    \n
  • \n

    MASHIKE, RUMOI, HABORO

    \n
  • \n
  • \n

    MASHIKE, RUMOI, HOROKANAI

    \n
  • \n
\n

Thus, we have two ways.

\n
\n
\n
\n
\n
\n

Sample Input 2

4\nZZ\nZZZ\nZ\nZZZZZZZZZZ\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

Note that there may be no ways to choose three people so that the given conditions are met.

\n
\n
\n
\n
\n
\n

Sample Input 3

5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO\n
\n
\n
\n
\n
\n

Sample Output 3

7\n
\n
\n
", "id": "codenet-bug-p03425", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.

\n

We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 0 \\leq A, B, C
  • \n
  • 1 \\leq K \\leq A + B + C \\leq 2 \\times 10^9
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C K\n
\n
\n
\n
\n
\n

Output

Print the maximum possible sum of the numbers written on the cards chosen.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 1 1 3\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

Consider picking up two cards with 1s and one card with a 0.\nIn this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.

\n
\n
\n
\n
\n
\n

Sample Input 2

1 2 3 4\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n
\n
\n
\n
\n
\n

Sample Input 3

2000000000 0 0 2000000000\n
\n
\n
\n
\n
\n

Sample Output 3

2000000000\n
\n
\n
", "id": "codenet-bug-p02682", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 300 points

\n
\n
\n

Problem Statement

\n

We have N voting papers. The i-th vote (1 \\leq i \\leq N) has the string S_i written on it.

\n

Print all strings that are written on the most number of votes, in lexicographical order.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 1 \\leq N \\leq 2 \\times 10^5
  • \n
  • S_i (1 \\leq i \\leq N) are strings consisting of lowercase English letters.
  • \n
  • The length of S_i (1 \\leq i \\leq N) is between 1 and 10 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\nS_1\n:\nS_N\n
\n
\n
\n
\n
\n

Output

\n

Print all strings in question in lexicographical order.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n
\n
\n
\n
\n
\n

Sample Output 1

beet\nvet\n
\n

beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.

\n
\n
\n
\n
\n
\n

Sample Input 2

8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n
\n
\n
\n
\n
\n

Sample Output 2

buffalo\n
\n
\n
\n
\n
\n
\n

Sample Input 3

7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n
\n
\n
\n
\n
\n

Sample Output 3

kick\n
\n
\n
\n
\n
\n
\n

Sample Input 4

4\nushi\ntapu\nnichia\nkun\n
\n
\n
\n
\n
\n

Sample Output 4

kun\nnichia\ntapu\nushi\n
\n
\n
", "id": "codenet-bug-p02773", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

A maze is composed of a grid of H \\times W squares - H vertical, W horizontal.

\n

The square at the i-th row from the top and the j-th column from the left - (i,j) - is a wall if S_{ij} is # and a road if S_{ij} is ..

\n

There is a magician in (C_h,C_w). He can do the following two kinds of moves:

\n
    \n
  • Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.
  • \n
  • Move B: Use magic to warp himself to a road square in the 5\\times 5 area centered at the square he is currently in.
  • \n
\n

In either case, he cannot go out of the maze.

\n

At least how many times does he need to use the magic to reach (D_h, D_w)?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq H,W \\leq 10^3
  • \n
  • 1 \\leq C_h,D_h \\leq H
  • \n
  • 1 \\leq C_w,D_w \\leq W
  • \n
  • S_{ij} is # or ..
  • \n
  • S_{C_h C_w} and S_{D_h D_w} are ..
  • \n
  • (C_h,C_w) \\neq (D_h,D_w)
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
H W\nC_h C_w\nD_h D_w\nS_{11}\\ldots S_{1W}\n\\vdots\nS_{H1}\\ldots S_{HW}\n
\n
\n
\n
\n
\n

Output

Print the minimum number of times the magician needs to use the magic. If he cannot reach (D_h,D_w), print -1 instead.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 4\n1 1\n4 4\n..#.\n..#.\n.#..\n.#..\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

For example, by walking to (2,2) and then using the magic to travel to (4,4), just one use of magic is enough.

\n

Note that he cannot walk diagonally.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 4\n1 4\n4 1\n.##.\n####\n####\n.##.\n
\n
\n
\n
\n
\n

Sample Output 2

-1\n
\n

He cannot move from there.

\n
\n
\n
\n
\n
\n

Sample Input 3

4 4\n2 2\n3 3\n....\n....\n....\n....\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n

No use of magic is needed.

\n
\n
\n
\n
\n
\n

Sample Input 4

4 5\n1 2\n2 5\n#.###\n####.\n#..##\n#..##\n
\n
\n
\n
\n
\n

Sample Output 4

2\n
\n
\n
", "id": "codenet-bug-p02579", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There is always an integer in Takahashi's mind.

\n

Initially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by 1; when he eats -, the integer in his mind decreases by 1.

\n

The symbols Takahashi is going to eat are given to you as a string S. The i-th character in S is the i-th symbol for him to eat.

\n

Find the integer in Takahashi's mind after he eats all the symbols.

\n
\n
\n
\n
\n

Constraints

    \n
  • The length of S is 4.
  • \n
  • Each character in S is + or -.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

Print the integer in Takahashi's mind after he eats all the symbols.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

+-++\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n
    \n
  • Initially, the integer in Takahashi's mind is 0.
  • \n
  • The first integer for him to eat is +. After eating it, the integer in his mind becomes 1.
  • \n
  • The second integer to eat is -. After eating it, the integer in his mind becomes 0.
  • \n
  • The third integer to eat is +. After eating it, the integer in his mind becomes 1.
  • \n
  • The fourth integer to eat is +. After eating it, the integer in his mind becomes 2.
  • \n
\n

Thus, the integer in Takahashi's mind after he eats all the symbols is 2.

\n
\n
\n
\n
\n
\n

Sample Input 2

-+--\n
\n
\n
\n
\n
\n

Sample Output 2

-2\n
\n
\n
\n
\n
\n
\n

Sample Input 3

----\n
\n
\n
\n
\n
\n

Sample Output 3

-4\n
\n
\n
", "id": "codenet-bug-p03315", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given strings s and t, consisting of lowercase English letters.\nYou will create a string s' by freely rearranging the characters in s.\nYou will also create a string t' by freely rearranging the characters in t.\nDetermine whether it is possible to satisfy s' < t' for the lexicographic order.

\n
\n
\n
\n
\n

Notes

For a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:

\n
    \n
  • N < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.
  • \n
  • There exists i (1 \\leq i \\leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.
  • \n
\n

For example, xy < xya and atcoder < atlas.

\n
\n
\n
\n
\n

Constraints

    \n
  • The lengths of s and t are between 1 and 100 (inclusive).
  • \n
  • s and t consists of lowercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
s\nt\n
\n
\n
\n
\n
\n

Output

If it is possible to satisfy s' < t', print Yes; if it is not, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

yx\naxy\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

We can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.

\n
\n
\n
\n
\n
\n

Sample Input 2

ratcode\natlas\n
\n
\n
\n
\n
\n

Sample Output 2

Yes\n
\n

We can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort < tslaa.

\n
\n
\n
\n
\n
\n

Sample Input 3

cd\nabc\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n

No matter how we rearrange cd and abc, we cannot achieve our objective.

\n
\n
\n
\n
\n
\n

Sample Input 4

w\nww\n
\n
\n
\n
\n
\n

Sample Output 4

Yes\n
\n
\n
\n
\n
\n
\n

Sample Input 5

zzz\nzzz\n
\n
\n
\n
\n
\n

Sample Output 5

No\n
\n
\n
", "id": "codenet-bug-p03486", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

Snuke has N strings. The i-th string is s_i.

\n

Let us concatenate these strings into one string after arranging them in some order.\nFind the maximum possible number of occurrences of AB in the resulting string.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 10^{4}
  • \n
  • 2 \\leq |s_i| \\leq 10
  • \n
  • s_i consists of uppercase English letters.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\ns_1\n\\vdots\ns_N\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\nABCA\nXBAZ\nBAD\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

For example, if we concatenate ABCA, BAD and XBAZ in this order, the resulting string ABCABADXBAZ has two occurrences of AB.

\n
\n
\n
\n
\n
\n

Sample Input 2

9\nBEWPVCRWH\nZZNQYIJX\nBAVREA\nPA\nHJMYITEOX\nBCJHMRMNK\nBP\nQVFABZ\nPRGKSPUNA\n
\n
\n
\n
\n
\n

Sample Output 2

4\n
\n
\n
\n
\n
\n
\n

Sample Input 3

7\nRABYBBE\nJOZ\nBMHQUVA\nBPA\nISU\nMCMABAOBHZ\nSZMEHMA\n
\n
\n
\n
\n
\n

Sample Output 3

4\n
\n
\n
", "id": "codenet-bug-p03049", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows:

\n
    \n
  • \n

    The first term s is given as input.

    \n
  • \n
  • \n

    Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.

    \n
  • \n
  • \n

    a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.

    \n
  • \n
\n

Find the minimum integer m that satisfies the following condition:

\n
    \n
  • There exists an integer n such that a_m = a_n (m > n).
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq s \\leq 100
  • \n
  • All values in input are integers.
  • \n
  • It is guaranteed that all elements in a and the minimum m that satisfies the condition are at most 1000000.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
s\n
\n
\n
\n
\n
\n

Output

Print the minimum integer m that satisfies the condition.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

8\n
\n
\n
\n
\n
\n

Sample Output 1

5\n
\n

a=\\{8,4,2,1,4,2,1,4,2,1,......\\}. As a_5=a_2, the answer is 5.

\n
\n
\n
\n
\n
\n

Sample Input 2

7\n
\n
\n
\n
\n
\n

Sample Output 2

18\n
\n

a=\\{7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,......\\}.

\n
\n
\n
\n
\n
\n

Sample Input 3

54\n
\n
\n
\n
\n
\n

Sample Output 3

114\n
\n
\n
", "id": "codenet-bug-p03146", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 100 points

\n
\n
\n

Problem Statement

We have two distinct integers A and B.

\n

Print the integer K such that |A - K| = |B - K|.

\n

If such an integer does not exist, print IMPOSSIBLE instead.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 0 \\leq A,\\ B \\leq 10^9
  • \n
  • A and B are distinct.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

Print the integer K satisfying the condition.

\n

If such an integer does not exist, print IMPOSSIBLE instead.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 16\n
\n
\n
\n
\n
\n

Sample Output 1

9\n
\n

|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.

\n
\n
\n
\n
\n
\n

Sample Input 2

0 3\n
\n
\n
\n
\n
\n

Sample Output 2

IMPOSSIBLE\n
\n

No integer satisfies the condition.

\n
\n
\n
\n
\n
\n

Sample Input 3

998244353 99824435\n
\n
\n
\n
\n
\n

Sample Output 3

549034394\n
\n
\n
", "id": "codenet-bug-p02957", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 500 points

\n
\n
\n

Problem Statement

We have N integers. The i-th number is A_i.

\n

\\{A_i\\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\\leq i < j \\leq N.

\n

\\{A_i\\} is said to be setwise coprime when \\{A_i\\} is not pairwise coprime but GCD(A_1,\\ldots,A_N)=1.

\n

Determine if \\{A_i\\} is pairwise coprime, setwise coprime, or neither.

\n

Here, GCD(\\ldots) denotes greatest common divisor.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 10^6
  • \n
  • 1 \\leq A_i\\leq 10^6
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 \\ldots A_N\n
\n
\n
\n
\n
\n

Output

If \\{A_i\\} is pairwise coprime, print pairwise coprime; if \\{A_i\\} is setwise coprime, print setwise coprime; if neither, print not coprime.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n3 4 5\n
\n
\n
\n
\n
\n

Sample Output 1

pairwise coprime\n
\n

GCD(3,4)=GCD(3,5)=GCD(4,5)=1, so they are pairwise coprime.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\n6 10 15\n
\n
\n
\n
\n
\n

Sample Output 2

setwise coprime\n
\n

Since GCD(6,10)=2, they are not pairwise coprime. However, since GCD(6,10,15)=1, they are setwise coprime.

\n
\n
\n
\n
\n
\n

Sample Input 3

3\n6 10 16\n
\n
\n
\n
\n
\n

Sample Output 3

not coprime\n
\n

GCD(6,10,16)=2, so they are neither pairwise coprime nor setwise coprime.

\n
\n
", "id": "codenet-bug-p02574", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

An uppercase or lowercase English letter \\alpha will be given as input.\nIf \\alpha is uppercase, print A; if it is lowercase, print a.

\n
\n
\n
\n
\n

Constraints

    \n
  • \\alpha is an uppercase (A - Z) or lowercase (a - z) English letter.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
α\n
\n
\n
\n
\n
\n

Output

If \\alpha is uppercase, print A; if it is lowercase, print a.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

B\n
\n
\n
\n
\n
\n

Sample Output 1

A\n
\n

B is uppercase, so we should print A.

\n
\n
\n
\n
\n
\n

Sample Input 2

a\n
\n
\n
\n
\n
\n

Sample Output 2

a\n
\n

a is lowercase, so we should print a.

\n
\n
", "id": "codenet-bug-p02627", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Given are a positive integer N and a string S of length N consisting of lowercase English letters.

\n

Determine whether the string is a concatenation of two copies of some string.\nThat is, determine whether there is a string T such that S = T + T.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100
  • \n
  • S consists of lowercase English letters.
  • \n
  • |S| = N
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS\n
\n
\n
\n
\n
\n

Output

If S is a concatenation of two copies of some string, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

6\nabcabc\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

Let T = abc, and S = T + T.

\n
\n
\n
\n
\n
\n

Sample Input 2

6\nabcadc\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1\nz\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
", "id": "codenet-bug-p02860", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

There is a hotel with the following accommodation fee:

\n
    \n
  • X yen (the currency of Japan) per night, for the first K nights
  • \n
  • Y yen per night, for the (K+1)-th and subsequent nights
  • \n
\n

Tak is staying at this hotel for N consecutive nights.\nFind his total accommodation fee.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N, K \\leq 10000
  • \n
  • 1 \\leq Y < X \\leq 10000
  • \n
  • N,\\,K,\\,X,\\,Y are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
N\nK\nX\nY\n
\n
\n
\n
\n
\n

Output

Print Tak's total accommodation fee.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5\n3\n10000\n9000\n
\n
\n
\n
\n
\n

Sample Output 1

48000\n
\n

The accommodation fee is as follows:

\n
    \n
  • 10000 yen for the 1-st night
  • \n
  • 10000 yen for the 2-nd night
  • \n
  • 10000 yen for the 3-rd night
  • \n
  • 9000 yen for the 4-th night
  • \n
  • 9000 yen for the 5-th night
  • \n
\n

Thus, the total is 48000 yen.

\n
\n
\n
\n
\n
\n

Sample Input 2

2\n3\n10000\n9000\n
\n
\n
\n
\n
\n

Sample Output 2

20000\n
\n
\n
", "id": "codenet-bug-p04011", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 200 points

\n
\n
\n

Problem Statement

\n

There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:

\n
    \n
  • Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
  • \n
\n

What is the largest possible sum of the integers written on the blackboard after K operations?

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • A, B and C are integers between 1 and 50 (inclusive).
  • \n
  • K is an integer between 1 and 10 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
A B C\nK\n
\n
\n
\n
\n
\n

Output

\n

Print the largest possible sum of the integers written on the blackboard after K operations by E869220.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 3 11\n1\n
\n
\n
\n
\n
\n

Sample Output 1

30\n
\n

In this sample, 5, 3, 11 are initially written on the blackboard, and E869120 can perform the operation once.
\nThere are three choices:

\n
    \n
  1. Double 5: The integers written on the board after the operation are 10, 3, 11.
  2. \n
  3. Double 3: The integers written on the board after the operation are 5, 6, 11.
  4. \n
  5. Double 11: The integers written on the board after the operation are 5, 3, 22.
  6. \n
\n

If he chooses 3., the sum of the integers written on the board afterwards is 5 + 3 + 22 = 30, which is the largest among 1. through 3.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 3 4\n2\n
\n
\n
\n
\n
\n

Sample Output 2

22\n
\n

E869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows:

\n
    \n
  • First, double 4. The integers written on the board are now 3, 3, 8.
  • \n
  • Next, double 8. The integers written on the board are now 3, 3, 16.
  • \n
\n

Then, the sum of the integers eventually written on the blackboard is 3 + 3 + 16 = 22.

\n
\n
", "id": "codenet-bug-p03360", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 200 points

\n
\n
\n

Problem Statement

\n

The number 105 is quite special - it is odd but still it has eight divisors.\nNow, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • N is an integer between 1 and 200 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

\n

Print the count.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

105\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

Among the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.

\n
\n
\n
\n
\n
\n

Sample Input 2

7\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.

\n
\n
", "id": "codenet-bug-p03281", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given two integers K and S.
\nThree variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.
\nHow many different assignments of values to X, Y and Z are there such that X + Y + Z = S?

\n
\n
\n
\n
\n

Constraints

    \n
  • 2≤K≤2500
  • \n
  • 0≤S≤3K
  • \n
  • K and S are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

The input is given from Standard Input in the following format:

\n
K S\n
\n
\n
\n
\n
\n

Output

Print the number of the triples of X, Y and Z that satisfy the condition.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 2\n
\n
\n
\n
\n
\n

Sample Output 1

6\n
\n

There are six triples of X, Y and Z that satisfy the condition:

\n
    \n
  • X = 0, Y = 0, Z = 2
  • \n
  • X = 0, Y = 2, Z = 0
  • \n
  • X = 2, Y = 0, Z = 0
  • \n
  • X = 0, Y = 1, Z = 1
  • \n
  • X = 1, Y = 0, Z = 1
  • \n
  • X = 1, Y = 1, Z = 0
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

5 15\n
\n
\n
\n
\n
\n

Sample Output 2

1\n
\n

The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z.

\n
\n
", "id": "codenet-bug-p03835", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

We have N switches with \"on\" and \"off\" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.

\n

Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are \"on\" among these switches is congruent to p_i modulo 2.

\n

How many combinations of \"on\" and \"off\" states of the switches light all the bulbs?

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N, M \\leq 10
  • \n
  • 1 \\leq k_i \\leq N
  • \n
  • 1 \\leq s_{ij} \\leq N
  • \n
  • s_{ia} \\neq s_{ib} (a \\neq b)
  • \n
  • p_i is 0 or 1.
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\nk_1 s_{11} s_{12} ... s_{1k_1}\n:\nk_M s_{M1} s_{M2} ... s_{Mk_M}\np_1 p_2 ... p_M\n
\n
\n
\n
\n
\n

Output

Print the number of combinations of \"on\" and \"off\" states of the switches that light all the bulbs.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 2\n2 1 2\n1 2\n0 1\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n
    \n
  • Bulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.
  • \n
  • Bulb 2 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.
  • \n
\n

There are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 3\n2 1 2\n1 1\n1 2\n0 0 1\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n
    \n
  • Bulb 1 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1 and 2.
  • \n
  • Bulb 2 is lighted when there is an even number of switches that are \"on\" among the following: Switch 1.
  • \n
  • Bulb 3 is lighted when there is an odd number of switches that are \"on\" among the following: Switch 2.
  • \n
\n

Switch 1 has to be \"off\" to light Bulb 2 and Switch 2 has to be \"on\" to light Bulb 3, but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0.

\n
\n
\n
\n
\n
\n

Sample Input 3

5 2\n3 1 2 5\n2 2 3\n1 0\n
\n
\n
\n
\n
\n

Sample Output 3

8\n
\n
\n
", "id": "codenet-bug-p03031", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

In programming, hexadecimal notation is often used.

\n

In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters A, B, C, D, E and F are used to represent the values 10, 11, 12, 13, 14 and 15, respectively.

\n

In this problem, you are given two letters X and Y. Each X and Y is A, B, C, D, E or F.

\n

When X and Y are seen as hexadecimal numbers, which is larger?

\n
\n
\n
\n
\n

Constraints

    \n
  • Each X and Y is A, B, C, D, E or F.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
X Y\n
\n
\n
\n
\n
\n

Output

If X is smaller, print <; if Y is smaller, print >; if they are equal, print =.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

A B\n
\n
\n
\n
\n
\n

Sample Output 1

<\n
\n

10 < 11.

\n
\n
\n
\n
\n
\n

Sample Input 2

E C\n
\n
\n
\n
\n
\n

Sample Output 2

>\n
\n

14 > 12.

\n
\n
\n
\n
\n
\n

Sample Input 3

F F\n
\n
\n
\n
\n
\n

Sample Output 3

=\n
\n

15 = 15.

\n
\n
", "id": "codenet-bug-p03547", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Snuke has a grid consisting of three squares numbered 1, 2 and 3.\nIn each square, either 0 or 1 is written. The number written in Square i is s_i.

\n

Snuke will place a marble on each square that says 1.\nFind the number of squares on which Snuke will place a marble.

\n
\n
\n
\n
\n

Constraints

    \n
  • Each of s_1, s_2 and s_3 is either 1 or 0.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
s_{1}s_{2}s_{3}\n
\n
\n
\n
\n
\n

Output

Print the answer.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

101\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n
    \n
  • A marble will be placed on Square 1 and 3.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

000\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n
    \n
  • No marble will be placed on any square.
  • \n
\n
\n
", "id": "codenet-bug-p03493", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

AtCoDeer the deer has found two positive integers, a and b.\nDetermine whether the concatenation of a and b in this order is a square number.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 a,b 100
  • \n
  • a and b are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
a b\n
\n
\n
\n
\n
\n

Output

If the concatenation of a and b in this order is a square number, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

1 21\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

As 121 = 11 × 11, it is a square number.

\n
\n
\n
\n
\n
\n

Sample Input 2

100 100\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

100100 is not a square number.

\n
\n
\n
\n
\n
\n

Sample Input 3

12 10\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
", "id": "codenet-bug-p03456", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

It is September 9 in Japan now.

\n

You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?

\n
\n
\n
\n
\n

Constraints

    \n
  • 10≤N≤99
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\n
\n
\n
\n
\n
\n

Output

If 9 is contained in the decimal notation of N, print Yes; if not, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

29\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

The one's digit of 29 is 9.

\n
\n
\n
\n
\n
\n

Sample Input 2

72\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

72 does not contain 9.

\n
\n
\n
\n
\n
\n

Sample Input 3

91\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p03605", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

Print all the integers that satisfies the following in ascending order:

\n
    \n
  • Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
  • \n
\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq A \\leq B \\leq 10^9
  • \n
  • 1 \\leq K \\leq 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B K\n
\n
\n
\n
\n
\n

Output

Print all the integers that satisfies the condition above in ascending order.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 8 2\n
\n
\n
\n
\n
\n

Sample Output 1

3\n4\n7\n8\n
\n
    \n
  • 3 is the first smallest integer among the integers between 3 and 8.
  • \n
  • 4 is the second smallest integer among the integers between 3 and 8.
  • \n
  • 7 is the second largest integer among the integers between 3 and 8.
  • \n
  • 8 is the first largest integer among the integers between 3 and 8.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

4 8 3\n
\n
\n
\n
\n
\n

Sample Output 2

4\n5\n6\n7\n8\n
\n
\n
\n
\n
\n
\n

Sample Input 3

2 9 100\n
\n
\n
\n
\n
\n

Sample Output 3

2\n3\n4\n5\n6\n7\n8\n9\n
\n
\n
", "id": "codenet-bug-p03386", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

\n

The door of Snuke's laboratory is locked with a security code.

\n

The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same.

\n

You are given the current security code S. If S is hard to enter, print Bad; otherwise, print Good.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • S is a 4-character string consisting of digits.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

\n

If S is hard to enter, print Bad; otherwise, print Good.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3776\n
\n
\n
\n
\n
\n

Sample Output 1

Bad\n
\n

The second and third digits are the same, so 3776 is hard to enter.

\n
\n
\n
\n
\n
\n

Sample Input 2

8080\n
\n
\n
\n
\n
\n

Sample Output 2

Good\n
\n

There are no two consecutive digits that are the same, so 8080 is not hard to enter.

\n
\n
\n
\n
\n
\n

Sample Input 3

1333\n
\n
\n
\n
\n
\n

Sample Output 3

Bad\n
\n
\n
\n
\n
\n
\n

Sample Input 4

0024\n
\n
\n
\n
\n
\n

Sample Output 4

Bad\n
\n
\n
", "id": "codenet-bug-p02993", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \\leq i \\leq N) is given to you as a character c_i; R stands for red and W stands for white.

\n

You can do the following two kinds of operations any number of times in any order:

\n
    \n
  • Choose two stones (not necessarily adjacent) and swap them.
  • \n
  • Choose one stone and change its color (from red to white and vice versa).
  • \n
\n

According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

\n
\n
\n
\n
\n

Constraints

    \n
  • 2 \\leq N \\leq 200000
  • \n
  • c_i is R or W.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nc_{1}c_{2}...c_{N}\n
\n
\n
\n
\n
\n

Output

Print an integer representing the minimum number of operations needed.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\nWWRR\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

For example, the two operations below will achieve the objective.

\n
    \n
  • Swap the 1-st and 3-rd stones from the left, resulting in RWWR.
  • \n
  • Change the color of the 4-th stone from the left, resulting in RWWW.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

2\nRR\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

It can be the case that no operation is needed.

\n
\n
\n
\n
\n
\n

Sample Input 3

8\nWRWWRWRR\n
\n
\n
\n
\n
\n

Sample Output 3

3\n
\n
\n
", "id": "codenet-bug-p02597", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 400 points

\n
\n
\n

Problem Statement

\n

The Kingdom of Takahashi has N towns, numbered 1 through N.

\n

There is one teleporter in each town. The teleporter in Town i (1 \\leq i \\leq N) sends you to Town A_i.

\n

Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

\n

Help the king by writing a program that answers this question.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 2 \\leq N \\leq 2 \\times 10^5
  • \n
  • 1 \\leq A_i \\leq N
  • \n
  • 1 \\leq K \\leq 10^{18}
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N K\nA_1 A_2 \\dots A_N\n
\n
\n
\n
\n
\n

Output

\n

Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 5\n3 2 4 1\n
\n
\n
\n
\n
\n

Sample Output 1

4\n
\n

If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.

\n
\n
\n
\n
\n
\n

Sample Input 2

6 727202214173249351\n6 5 2 5 3 2\n
\n
\n
\n
\n
\n

Sample Output 2

2\n
\n
\n
", "id": "codenet-bug-p02684", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Snuke has N dogs and M monkeys. He wants them to line up in a row.

\n

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.

\n

How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).\nHere, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ N,M ≤ 10^5
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\n
\n
\n
\n
\n
\n

Output

Print the number of possible arrangements, modulo 10^9+7.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 2\n
\n
\n
\n
\n
\n

Sample Output 1

8\n
\n

We will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.

\n
\n
\n
\n
\n
\n

Sample Input 2

3 2\n
\n
\n
\n
\n
\n

Sample Output 2

12\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1 8\n
\n
\n
\n
\n
\n

Sample Output 3

0\n
\n
\n
\n
\n
\n
\n

Sample Input 4

100000 100000\n
\n
\n
\n
\n
\n

Sample Output 4

530123477\n
\n
\n
", "id": "codenet-bug-p03681", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 100 points

\n
\n
\n

Problem Statement

\n

The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...

\n

Given is a string S representing the weather in the town today. Predict the weather tomorrow.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • S is Sunny, Cloudy, or Rainy.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
S\n
\n
\n
\n
\n
\n

Output

\n

Print a string representing the expected weather tomorrow, in the same format in which input is given.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

Sunny\n
\n
\n
\n
\n
\n

Sample Output 1

Cloudy\n
\n

In Takahashi's town, a sunny day is followed by a cloudy day.

\n
\n
\n
\n
\n
\n

Sample Input 2

Rainy\n
\n
\n
\n
\n
\n

Sample Output 2

Sunny\n
\n
\n
", "id": "codenet-bug-p02909", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 100 points

\n
\n
\n

Problem Statement

\n

A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.

\n

You will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • A, B, and C are all integers between 1 and 9 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

\n

If the given triple is poor, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

5 7 5\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

A and C are equal, but B is different from those two numbers, so this triple is poor.

\n
\n
\n
\n
\n
\n

Sample Input 2

4 4 4\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

A, B, and C are all equal, so this triple is not poor.

\n
\n
\n
\n
\n
\n

Sample Input 3

4 9 6\n
\n
\n
\n
\n
\n

Sample Output 3

No\n
\n
\n
\n
\n
\n
\n

Sample Input 4

3 3 4\n
\n
\n
\n
\n
\n

Sample Output 4

Yes\n
\n
\n
", "id": "codenet-bug-p02771", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 300 points

\n
\n
\n

Problem Statement

\n

AtCoder Mart sells 1000000 of each of the six items below:

\n
    \n
  • Riceballs, priced at 100 yen (the currency of Japan) each
  • \n
  • Sandwiches, priced at 101 yen each
  • \n
  • Cookies, priced at 102 yen each
  • \n
  • Cakes, priced at 103 yen each
  • \n
  • Candies, priced at 104 yen each
  • \n
  • Computers, priced at 105 yen each
  • \n
\n

Takahashi wants to buy some of them that cost exactly X yen in total.\nDetermine whether this is possible.
\n(Ignore consumption tax.)

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • 1 \\leq X \\leq 100000
  • \n
  • X is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
X\n
\n
\n
\n
\n
\n

Output

\n

If it is possible to buy some set of items that cost exactly X yen in total, print 1; otherwise, print 0.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

615\n
\n
\n
\n
\n
\n

Sample Output 1

1\n
\n

For example, we can buy one of each kind of item, which will cost 100+101+102+103+104+105=615 yen in total.

\n
\n
\n
\n
\n
\n

Sample Input 2

217\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

No set of items costs 217 yen in total.

\n
\n
", "id": "codenet-bug-p02843", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Find the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.

\n
\n
\n
\n
\n

Constraints

    \n
  • 2\\leq K\\leq 100
  • \n
  • K is an integer.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
K\n
\n
\n
\n
\n
\n

Output

Print the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n
\n
\n
\n
\n
\n

Sample Output 1

2\n
\n

Two pairs can be chosen: (2,1) and (2,3).

\n
\n
\n
\n
\n
\n

Sample Input 2

6\n
\n
\n
\n
\n
\n

Sample Output 2

9\n
\n
\n
\n
\n
\n
\n

Sample Input 3

11\n
\n
\n
\n
\n
\n

Sample Output 3

30\n
\n
\n
\n
\n
\n
\n

Sample Input 4

50\n
\n
\n
\n
\n
\n

Sample Output 4

625\n
\n
\n
", "id": "codenet-bug-p03264", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score: 100 points

\n
\n
\n

Problem Statement

\n

E869120 has A 1-yen coins and infinitely many 500-yen coins.
\nDetermine if he can pay exactly N yen using only these coins.

\n
\n
\n
\n
\n

Constraints

\n
    \n
  • N is an integer between 1 and 10000 (inclusive).
  • \n
  • A is an integer between 0 and 1000 (inclusive).
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

\n

Input is given from Standard Input in the following format:

\n
N\nA\n
\n
\n
\n
\n
\n

Output

\n

If E869120 can pay exactly N yen using only his 1-yen and 500-yen coins, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2018\n218\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

We can pay 2018 yen with four 500-yen coins and 18 1-yen coins, so the answer is Yes.

\n
\n
\n
\n
\n
\n

Sample Input 2

2763\n0\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

When we have no 1-yen coins, we can only pay a multiple of 500 yen using only 500-yen coins. Since 2763 is not a multiple of 500, we cannot pay this amount.

\n
\n
\n
\n
\n
\n

Sample Input 3

37\n514\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n
\n
", "id": "codenet-bug-p03433", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

There are N empty boxes arranged in a row from left to right.\nThe integer i is written on the i-th box from the left (1 \\leq i \\leq N).

\n

For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.

\n

We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:

\n
    \n
  • For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.
  • \n
\n

Does there exist a good set of choices? If the answer is yes, find one good set of choices.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq N \\leq 2 \\times 10^5
  • \n
  • a_i is 0 or 1.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\na_1 a_2 ... a_N\n
\n
\n
\n
\n
\n

Output

If a good set of choices does not exist, print -1.

\n

If a good set of choices exists, print one such set of choices in the following format:

\n
M\nb_1 b_2 ... b_M\n
\n

where M denotes the number of boxes that will contain a ball, and b_1,\\ b_2,\\ ...,\\ b_M are the integers written on these boxes, in any order.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n1 0 0\n
\n
\n
\n
\n
\n

Sample Output 1

1\n1\n
\n

Consider putting a ball only in the box with 1 written on it.

\n
    \n
  • There are three boxes with multiples of 1 written on them: the boxes with 1, 2, and 3. The total number of balls contained in these boxes is 1.
  • \n
  • There is only one box with a multiple of 2 written on it: the box with 2. The total number of balls contained in these boxes is 0.
  • \n
  • There is only one box with a multiple of 3 written on it: the box with 3. The total number of balls contained in these boxes is 0.
  • \n
\n

Thus, the condition is satisfied, so this set of choices is good.

\n
\n
\n
\n
\n
\n

Sample Input 2

5\n0 0 0 0 0\n
\n
\n
\n
\n
\n

Sample Output 2

0\n
\n

Putting nothing in the boxes can be a good set of choices.

\n
\n
", "id": "codenet-bug-p02972", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.\nWe will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.

\n

Determine whether the arrangement of the poles is beautiful.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq a,b,c \\leq 100
  • \n
  • a, b and c are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
a b c\n
\n
\n
\n
\n
\n

Output

Print YES if the arrangement of the poles is beautiful; print NO otherwise.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 4 6\n
\n
\n
\n
\n
\n

Sample Output 1

YES\n
\n

Since 4-2 = 6-4, this arrangement of poles is beautiful.

\n
\n
\n
\n
\n
\n

Sample Input 2

2 5 6\n
\n
\n
\n
\n
\n

Sample Output 2

NO\n
\n

Since 5-2 \\neq 6-5, this arrangement of poles is not beautiful.

\n
\n
\n
\n
\n
\n

Sample Input 3

3 2 1\n
\n
\n
\n
\n
\n

Sample Output 3

YES\n
\n

Since 1-2 = 2-3, this arrangement of poles is beautiful.

\n
\n
", "id": "codenet-bug-p03759", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

\n

You are given three integers A, B and C.

\n

Determine if there exists an equilateral triangle whose sides have lengths A, B and C.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq A,B,C \\leq 100
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B C\n
\n
\n
\n
\n
\n

Output

If there exists an equilateral triangle whose sides have lengths A, B and C, print Yes; otherwise, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 2 2\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n
    \n
  • There exists an equilateral triangle whose sides have lengths 2, 2 and 2.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

3 4 5\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n
    \n
  • There is no equilateral triangle whose sides have lengths 3, 4 and 5.
  • \n
\n
\n
", "id": "codenet-bug-p03079", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Takahashi participated in a contest on AtCoder.

\n

The contest had N problems.

\n

Takahashi made M submissions during the contest.

\n

The i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).

\n

The number of Takahashi's correct answers is the number of problems on which he received an AC once or more.

\n

The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.

\n

Find the numbers of Takahashi's correct answers and penalties.

\n
\n
\n
\n
\n

Constraints

    \n
  • N, M, and p_i are integers.
  • \n
  • 1 \\leq N \\leq 10^5
  • \n
  • 0 \\leq M \\leq 10^5
  • \n
  • 1 \\leq p_i \\leq N
  • \n
  • S_i is AC or WA.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N M\np_1 S_1\n:\np_M S_M\n
\n
\n
\n
\n
\n

Output

Print the number of Takahashi's correct answers and the number of Takahashi's penalties.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA\n
\n
\n
\n
\n
\n

Sample Output 1

2 2\n
\n

In his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.

\n

In his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.

\n

Thus, he has two correct answers and two penalties.

\n
\n
\n
\n
\n
\n

Sample Input 2

100000 3\n7777 AC\n7777 AC\n7777 AC\n
\n
\n
\n
\n
\n

Sample Output 2

1 0\n
\n

Note that it is pointless to get an AC more than once on the same problem.

\n
\n
\n
\n
\n
\n

Sample Input 3

6 0\n
\n
\n
\n
\n
\n

Sample Output 3

0 0\n
\n
\n
", "id": "codenet-bug-p02802", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

You are given positive integers A and B.

\n

If A is a divisor of B, print A + B; otherwise, print B - A.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 1 \\leq A \\leq B \\leq 20
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
A B\n
\n
\n
\n
\n
\n

Output

If A is a divisor of B, print A + B; otherwise, print B - A.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 12\n
\n
\n
\n
\n
\n

Sample Output 1

16\n
\n

As 4 is a divisor of 12, 4 + 12 = 16 should be printed.

\n
\n
\n
\n
\n
\n

Sample Input 2

8 20\n
\n
\n
\n
\n
\n

Sample Output 2

12\n
\n
\n
\n
\n
\n
\n

Sample Input 3

1 1\n
\n
\n
\n
\n
\n

Sample Output 3

2\n
\n

1 is a divisor of 1.

\n
\n
", "id": "codenet-bug-p03125", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 400 points

\n
\n
\n

Problem Statement

There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.

\n

Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \\leq i \\leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1).

\n

When Mountain i (1 \\leq i \\leq N) receives 2x liters of rain, Dam i-1 and Dam i each accumulates x liters of water (Dam 0 is Dam N).

\n

One day, each of the mountains received a non-negative even number of liters of rain.

\n

As a result, Dam i (1 \\leq i \\leq N) accumulated a total of A_i liters of water.

\n

Find the amount of rain each of the mountains received. We can prove that the solution is unique under the constraints of this problem.

\n
\n
\n
\n
\n

Constraints

    \n
  • All values in input are integers.
  • \n
  • 3 \\leq N \\leq 10^5-1
  • \n
  • N is an odd number.
  • \n
  • 0 \\leq A_i \\leq 10^9
  • \n
  • The situation represented by input can occur when each of the mountains receives a non-negative even number of liters of rain.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nA_1 A_2 ... A_N\n
\n
\n
\n
\n
\n

Output

Print N integers representing the number of liters of rain Mountain 1, Mountain 2, ..., Mountain N received, in this order.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3\n2 2 4\n
\n
\n
\n
\n
\n

Sample Output 1

4 0 4\n
\n

If we assume Mountain 1, 2, and 3 received 4, 0, and 4 liters of rain, respectively, it is consistent with this input, as follows:

\n
    \n
  • Dam 1 should have accumulated \\frac{4}{2} + \\frac{0}{2} = 2 liters of water.
  • \n
  • Dam 2 should have accumulated \\frac{0}{2} + \\frac{4}{2} = 2 liters of water.
  • \n
  • Dam 3 should have accumulated \\frac{4}{2} + \\frac{4}{2} = 4 liters of water.
  • \n
\n
\n
\n
\n
\n
\n

Sample Input 2

5\n3 8 7 5 5\n
\n
\n
\n
\n
\n

Sample Output 2

2 4 12 2 8\n
\n
\n
\n
\n
\n
\n

Sample Input 3

3\n1000000000 1000000000 0\n
\n
\n
\n
\n
\n

Sample Output 3

0 2000000000 0\n
\n
\n
", "id": "codenet-bug-p02984", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 200 points

\n
\n
\n

Problem Statement

You are given a string S of length N.\nAmong its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings.

\n

Here, a subsequence of a string is a concatenation of one or more characters from the string without changing the order.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 \\leq N \\leq 100000
  • \n
  • S consists of lowercase English letters.
  • \n
  • |S|=N
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N\nS\n
\n
\n
\n
\n
\n

Output

Print the number of the subsequences such that all characters are different, modulo 10^9+7.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4\nabcd\n
\n
\n
\n
\n
\n

Sample Output 1

15\n
\n

Since all characters in S itself are different, all its subsequences satisfy the condition.

\n
\n
\n
\n
\n
\n

Sample Input 2

3\nbaa\n
\n
\n
\n
\n
\n

Sample Output 2

5\n
\n

The answer is five: b, two occurrences of a, two occurrences of ba. Note that we do not count baa, since it contains two as.

\n
\n
\n
\n
\n
\n

Sample Input 3

5\nabcab\n
\n
\n
\n
\n
\n

Sample Output 3

17\n
\n
\n
", "id": "codenet-bug-p03095", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 100 points

\n
\n
\n

Problem Statement

Three people, A, B and C, are trying to communicate using transceivers.\nThey are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively.\nTwo people can directly communicate when the distance between them is at most d meters.\nDetermine if A and C can communicate, either directly or indirectly.\nHere, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 a,b,c 100
  • \n
  • 1 d 100
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
a b c d\n
\n
\n
\n
\n
\n

Output

If A and C can communicate, print Yes; if they cannot, print No.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

4 7 9 3\n
\n
\n
\n
\n
\n

Sample Output 1

Yes\n
\n

A and B can directly communicate, and also B and C can directly communicate, so we should print Yes.

\n
\n
\n
\n
\n
\n

Sample Input 2

100 10 1 2\n
\n
\n
\n
\n
\n

Sample Output 2

No\n
\n

They cannot communicate in this case.

\n
\n
\n
\n
\n
\n

Sample Input 3

10 10 10 1\n
\n
\n
\n
\n
\n

Sample Output 3

Yes\n
\n

There can be multiple people at the same position.

\n
\n
\n
\n
\n
\n

Sample Input 4

1 100 2 10\n
\n
\n
\n
\n
\n

Sample Output 4

Yes\n
\n
\n
", "id": "codenet-bug-p03351", "lang": "", "meta": ""} +{"src": "codenet", "title": "", "text": "\n

Score : 300 points

\n
\n
\n

Problem Statement

Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:

\n
    \n
  1. Throw the die. The current score is the result of the die.
  2. \n
  3. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.
  4. \n
  5. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.
  6. \n
\n

You are given N and K. Find the probability that Snuke wins the game.

\n
\n
\n
\n
\n

Constraints

    \n
  • 1 ≤ N ≤ 10^5
  • \n
  • 1 ≤ K ≤ 10^5
  • \n
  • All values in input are integers.
  • \n
\n
\n
\n
\n
\n
\n
\n

Input

Input is given from Standard Input in the following format:

\n
N K\n
\n
\n
\n
\n
\n

Output

Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.

\n
\n
\n
\n
\n
\n
\n

Sample Input 1

3 10\n
\n
\n
\n
\n
\n

Sample Output 1

0.145833333333\n
\n
    \n
  • If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^4 = \\frac{1}{48}.
  • \n
  • If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^3 = \\frac{1}{24}.
  • \n
  • If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^2 = \\frac{1}{12}.
  • \n
\n

Thus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} + \\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.

\n
\n
\n
\n
\n
\n

Sample Input 2

100000 5\n
\n
\n
\n
\n
\n

Sample Output 2

0.999973749998\n
\n
\n
", "id": "codenet-bug-p03043", "lang": "", "meta": ""}