A positive integer X is a cool number if it satisfies the following conditions:
For example:
The first line contains an integer T (1 ≤ T ≤ 10) denoting the number of tests. Then T tests follow, each test case consists of only one number k.
For each test case, print out all the cool numbers in one line in increasing order, separated by a single space. If there is no cool number, output -1
2
1
5
-1
21200
Given an array A of N integers A1, A2, A3, ..., AN. This array is generated by the following formula:
A1 = S
Ai = (C1 * Ai - 1 + C2) mod M, for i = 2..N
Your task is very simple. Find out K smallest integers among the N generated integers.
First line of input consist number of test case T (T ≤ 20). Each of the next T lines describe a test case. Each test case consists of six numbers: N, K, S, C1, C2, M where:
For the ith test case, you should print K smallest numbers in ascending order on the ith line of output. The numbers should be seperated by a single space.
2
10000 9 71 197 5 91723
2014 4 27 279 64 97264
3 4 4 24 40 40 41 49 71
27 77 221 251
Alpha is a modern and very well-planned city. The city is arranged in a grid shape with all the streets are one-way and parallel to the North-South axis or East-West axis. There are V vertical streets (parallel to North-South axis) and H horizontal streets (parallel to East-West axis). V vertical streets are numbered 1 to V from West to East. H horizontal streets are numbered 1 to H from South to North.
If we represent this city in a 2D plane, the first vertical street is on the line x = 0, the first horizontal street is on the line y = 0. The ith vertical street is VGi meters from the (i + 1)th vertical street. The jth horizontal street is HGj meters from the (j + 1)th horizontal street.
Vertical streets are either Northbound (go from South to North) or Southbound (go from North to South). The directions of these vertical streets are given in a string VD where VDi is either ‘N’ or ‘S’. Horizontal streets are either Westbound (go from East to West) or Eastbound (go from West to East). The directions of these horizontal streets are given in a string HD where HDj is either ‘W’ or ‘E’.
Given K queries x1, y1, x2, y2, you are to calculate the shortest path from (x1, y1) to (x2, y2).
The first line is the number T (T ≤ 20) denotes the number of test cases. Then T test cases follow:
For each query, print the shortest distance. If it is not possible to go from (x1, y1) to (x2, y2), print -1 instead.
1
6 6 4
1 1 2 1 1
1 1 2 1 1
NNNSSS
WWWEEE
5 4 5 4
2 2 4 4
3 2 3 0
6 6 5 5
0
4
10
14
The city map with directions: 
Two positive numbers are called coprime (or relatively prime) if their greatest common divisor is 1. A set of integers is said to be pairwise coprime if for every pair of different element (a, b), a and b are co-prime.
Given set S of N first positive integers, your task is to find the largest subset S' of S such that S' is pairwise coprime.
The first line of input is the number T - the number of tests (T ≤ 1000). Then T tests follow. Each test will be printed in one line with the number N. (1 ≤ N ≤ 106)
For each test, print Case#i: p where i is the 1-based index of the test and p is the size of the largest subset.
1
5
Case #1: 4
{1, 2, 3, 5} and {1, 3, 4, 5} are the largest pairwise coprime subset.
A binary tree is a tree data structure where each node has at most two children which are referred to as left child and right child. A binary search tree is a binary tree where each node has a comparable key and must satisfy the following conditions:
Given a binary tree, your task is to choose a maximal set S of connected nodes in the given tree so that these nodes and the relations (left child, right child, or ancestor) among them form a binary search tree.
The first line of input is the number T (T ≤ 20).
Then T tests follow:
For each test, print the maximal size of S.
2
8
2 3 10
4 5 5
6 7 15
0 0 3
0 0 7
0 0 17
0 8 13
0 0 14
3
0 2 5
0 3 6
0 0 7
5
3
The example test case correspond to the following figure: 
You are given a directed rooted tree T with N vertices (N ≤ 105). The vertices are numbered from 1 to N, with vertex 1 being the root. You must perform Q queries of two types on the tree (Q ≤ 105):
The pre-order tree traversal can be explained by this pseudo-code and figure. 
The first line of input contains the only integer T - number of test cases (T ≤ 10). Then T tests follow. For each test case:
For each query of type , print one line containing the only integer - the answer of the query.
1
7
1 3
1 2
3 5
3 4
2 6
2 7
15
2 1
2 2
2 3
2 4
2 5
2 6
2 7
1 3 2
2 1
2 2
2 3
2 4
2 5
2 6
2 7
1
3
5
4
2
6
7
1
2
6
7
3
5
4
The query type 2 in example can be explained by the following figure: 

Look closely at this picture! You may think there is curve toward the center because of visual illusion but actually not. It is just a square table with black and white cells in special pattern. This is called visual illusion.
A visual illusion is characterized by visually perceived images that differ from objective reality. The information gathered by the eye is processed in the brain to give a perception that does not tally with a physical measurement of the stimulus source.
This is just a (2n + 1) * (2n + 1) table with black and white square cells. It starts with an almost white table and one black cell in the center. Then we start coloring cells in steps. In each step, we color some cells so that these cells make a minimal diamond shape and they do not share an edge with each other. The diamond shape in one step should also contain all cells colored in previous steps and do not touch them (sharing a point with them). We continue this process even when part of the diamond shape is out of the table.
Conan found this so interesting; and wants to know if a bigger table would make a stronger illusion. He needs you to write a program to print a whole table of this pattern.
The input starts with T - number of tests (T ≤ 10). Then T tests follow. Each test is printed in a line consist of a positive integer n (1 ≤ n ≤ 100).
For each test, print the (2n + 1) * (2n + 1) table using ‘b’ or ‘w’ (denotes a black or white cell).
2
1
2
www
wbw
www
wbwbw
bwwwb
wwbww
bwwwb
wbwbw
Closed-circuit television (CCTV), also known as video surveillance, is the use of video cameras to transmit a signal to a specific place, on a limited set of monitors. They are widely used for security purposes.
Next week, there will be an exhibition of famous Renaissance artwork. The exhibition room has a rectangular form with the lower left corner at (0, 0) and the upper right corner at (X, Y). In 4 corners of the room, CCTVs are used to surveillance every moves of every visitors. Inside this room, N impressive artworks are placed in glass cases. These glass cases are all rectangular shape with edges parallel to the walls; the lower left corner is at (X1i, Y1i) and the upper right corner is at (X2i, Y2i). A CCTV can track any point if the direct line from the point to the CCTV is not blocked by some case.
Given the shape of the exhibition room, the position and shape of all the cases, your task is to calculate the track-able area of 4 CCTV.
The input starts with T (T ≤ 20) - the number of tests. Then T tests follow. Each test is formatted as:
For each test, you should print 2 lines:
1
4 4
2
1 1 2 2
1 3 3 4
4.666667 6.833333
8.250000 9.666667
The layout of the exhibition room in the example:

The track-able area of CCTVs: 
A repeating decimal, also called a recurring decimal, is a number whose decimal representation eventually becomes periodic (i.e., the same sequence of digits repeats indefinitely). The repeating portion of a decimal expansion is conventionally denoted within a pair of brackets so, for example
1 / 6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66)
Both 0.1(6) or 0.1666(6) or 0.166(66) are correct representation of 1 / 6. Given a recurring decimal representation, your task is to find an irreducible fraction that has that representation.
The first line of input contains the number of tests – T (T ≤ 100). Then T tests follow. Each test is printed in a line as a string whose length does not exceed 15. It is guaranteed to be a meaningful representation of a positive fraction.
For each test, print the result in one line in the format Case #x: a/b
4
0.125
0.(142857)
0.1(6)
.2
Case #1: 1/8
Case #2: 1/7
Case #3: 1/6
Case #4: 1/5
Over the last few months, Conan has trained very intensively for competing in the ACM/ICPC contest. What he did are just eating, sleeping and coding; as a result, he has put on quite a few kilos. Since the training period are about to finish, he is planning to come back to a healthier life style: going to the gym and eating more properly.
There are N delicious dishes, dish i has Ai calories. A recipe for a meal is the combination of dishes where each dish appears no more than 1. A perfect, healthy recipe should have the total calories of M calories.
Conan is planning his meals to details and he wonders will there be enough K different perfect recipes for the next K days. 2 recipes are considered different if there is at least a dish appears in one recipe but not the other.
The input starts with the number T (T ≤ 500)- the number of tests. Then T tests follow.
For each test, if there are at least K different perfect recipes, print “ENOUGH”; otherwise you should print the number of perfect recipes.
2
10 1000 7
100 200 300 400 500 600 700 800 900 1000
10 1000 30
100 200 300 400 500 600 700 800 900 1000
ENOUGH
10
All the dishes in 2 samples are similar. There are 10 different perfect recipes:
1000 = 100 + 200 + 300 + 400
1000 = 100 + 200 + 700
1000 = 100 + 300 + 600
1000 = 100 + 400 + 500
1000 = 100 + 900
1000 = 200 + 300 + 500
1000 = 200 + 800
1000 = 300 + 700
1000 = 400 + 600
1000 = 1000