QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 256 MB مجموع النقاط: 100

#15676. The Clever Student

الإحصائيات

A logic professor has three students, A, B, and C, who are excellent at reasoning and mental arithmetic. One day, the professor gives them a problem: the professor places a slip of paper on each person's forehead and tells them that each slip has a positive integer written on it, and the sum of two of these numbers equals the third. Thus, each student can see the integers on the other two students' foreheads but cannot see their own number.

At this point, the professor first asks student A: "Can you guess your own number?" A replies: "No." The professor then turns to student B: "Can you guess your own number?" B thinks for a moment and also replies: "No." The professor then asks student C the same question. C thinks for a moment, then shakes his head: "No." Next, the professor asks A the same question again, then B and C, and so on. After several rounds of questioning, when the professor asks someone again, this person suddenly reveals a triumphant smile and correctly reports the number on their own forehead.

Now, if you are told that at the $N$-th question by the professor, the person whose turn it is to answer guesses that the number on their forehead is $M$, can you deduce what numbers are on the other two students' foreheads?

Note

Before anyone guesses the number on their own forehead, everyone's answer to the professor's questions is always "No." Furthermore, there is no exchange of information between A, B, and C. That is to say, each person's deduction is based solely on the numbers on the other two people's foreheads and the negative answers given by everyone to the professor's questions.

The professor always starts by asking student A.

You may assume that these three sufficiently intelligent students can guess their own numbers in the earliest possible round based on the known conditions and will never guess incorrectly.

After a little analysis and reasoning, you will arrive at the following conclusion: the person with the largest number on their forehead is always the first to guess the number on their own forehead.

Input

The input consists of several test cases. Each line represents a test case and consists of two integers $N$ and $M$ (meaning that at the $N$-th question by the professor, the person whose turn it is to answer guesses that the number on their forehead is $M$). The two numbers are separated by a space. Finally, a line consisting of -1 -1 marks the end of the input data.

$0 < N < 500$; $0 < M < 30000$

Output

For each test case, output the results in the order they appear in the input.

The first line of the output for each test case is an integer $p$, which is the total number of possible scenarios. The following $p$ lines each contain three numbers, representing the three numbers on the foreheads of A, B, and C, respectively. When outputting, all solutions should be sorted in ascending order of the number on A's forehead; if the numbers on A's forehead are the same, they should be sorted in ascending order of the number on B's forehead.

Examples

Input 1

5 8
3 2
2 3
-1 -1

Output 1

3
2 8 6
5 8 3
6 8 2
1
1 1 2
1
2 3 1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.