Limits 1s, 512 MB

Research (or thesis) is a time-consuming task. One can not define research as a straight line from where he/she begins to where he/she finishes. Research is a continuous process of with ups and downs. Amee, a fourth-year and a hard-working student have been facing the reality of research as he starts his fourth-year thesis. He finds the work is tedious which requires an in-depth concentration and plenty of patience.

To become more productive and focused, Amee has started drinking a cup of coffee every day. Coffee has caffeine which acts as a mild stimulant to the central nervous system. Caffeine with a healthy level improves alertness, attention, and concentration. After drinking coffee every day, Amee has gained more focused on his work. He usually makes coffee by himself. He also likes to drink coffee from a nearby coffee-shop of his Varsity. He drinks coffee with different flavor and ingredients. He tracks each type of coffee that he ordered from the coffee-shop or he made by himself. Since he has been drinking coffee for a long time, he wants to find a pattern of his taste. Can you help him?

Objective:
You are given data about the type of coffee that Amee ordered for the last N days. Your task is to calculate how many days (average) later Amee returns back to a certain coffee type.

Input

Your program should handle T test cases. Each test case starts with two integers NN (2<N<10002< N< 1000) and PP (1P201\le P\le 20) where NN denotes the number of days and PP denotes the number of coffee type. In the next line, there will be NN number of integers II (1IP1\le I \le P) in chronological order which defines the coffee type.

Output

For each test case, you will generate outputs which depend on your finding.

The first line prints the following line: “Test Case: t” (without the quotation) where t is the test case number. If you do not find a case where Amee returns back to previously ordered coffee, you print “No Pattern” (without the quotation). If you find a pattern for a coffee type, you will print two values separated by space: (1) first value shows the coffee type and (2) second value shows the average number of days (2 decimal points) after which Amee returns back to drink the coffee type. If you find multiple coffee types, show the result in each line sorted by the coffee type.

Samples

InputOutput
2
10 2
1 1 1 2 1 1 1 1 1 2
5 5
1 2 3 4 5
Test Case: 1
1 1.00
2 5.00
Test Case: 2
No Pattern

Explanation: For the first sample input,

The number of days when he starts using type 1 again is 1 day. The number of days when he starts again using type 2 is 5 days. So the average is 1.00 and 5.00 for these two types. In the next case, there is no repetition. Hence, there is no pattern.

InputOutput
2
10 3
2 1 1 1 1 2 3 1 2 3
3 1
1 1 1
Test Case: 1
1 2.00
2 3.00
3 2.00
Test Case: 2
No Pattern

Submit

Login to submit.

Statistics

88% Solution Ratio
kzvd4729Earliest, Apr '19
nusuBotFastest, 0.0s
IamHotLightest, 131 kB
ovis96Shortest, 715B
Toph uses cookies. By continuing you agree to our Cookie Policy.