Elma is learning chess figures.
She learned that a rook can move either horizontally or vertically. To enhance her understanding of rook movement Elma's grandmother gave Elma an 8 × 8 chess board and asked her to find a way to move the rook from a1 to h8 making exactly nn moves, so that all visited cells are different.
A visited cell is the initial cell a1 and each cell on which the rook lands after a move.
The input contains a single integer nn (2 ≤ n ≤ 63)(2≤n≤63) — the desired number of moves.
Output a space-separated list of n+1n+1 visited cells in the order they are visited by the rook. All cells must be different. The list should start with a1 and end with h8. A solution always exists.
本题答案不唯一,符合要求的答案均正确
样例输入复制
4
样例输出复制
a1 f1 c1 c8 h8
样例解释
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
You are given a positive integer nn.
Find a sequence of fractions \frac {a_i} {b_i}, i = 1...kbiai,i=1...k(where a_iai and b_ibi are positive integers) for some kk such that:
\begin{cases} b_i \text{ divides } n, 1 The input consists of a single integer n (2 ≤ n ≤ 10^9)n(2≤n≤109). In the first line print "YES" if there exists such a sequence of fractions or "NO" otherwise. If there exists such a sequence, next lines should contain a description of the sequence in the following format. The second line should contain integer k (1 ≤ k ≤ 100000)k(1≤k≤100000) — the number of elements in the sequence. It is guaranteed that if such a sequence exists, then there exists a sequence of length at most 100000. Next kk lines should contain fractions of the sequence with two integers a_iai and b_ibi on each line. 本题答案不唯一,符合要求的答案均正确 样例输入1复制 样例输出1复制 样例输入2复制 样例输出2复制 Berland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country. Berland State University works every day of the week, but classes for guest students are held on the following schedule. You know the sequence of seven integers a_1, a_2, . . . , a_7a1,a2,...,a7 (a_i = 0ai=0 or a_i = 1ai=1): The classes for guest students are held in at least one day of a week. You want to visit the capital of Berland and spend the minimum number of days in it to study kk days as a guest student in Berland State University. Write a program to find the length of the shortest continuous period of days to stay in the capital to study exactly kk days as a guest student. The first line of the input contains integer t (1 ≤ t ≤ 10 000)t(1≤t≤10000) — the number of test cases to process. For each test case independently solve the problem and print the answer. Each test case consists of two lines. The first of them contains integer k (1 ≤ k ≤ 10^8)k(1≤k≤108) — the required number of days to study as a guest student. The second line contains exactly seven integers a_1, a_2, . . . , a_7a1,a2,...,a7 (a_i = 0ai=0 or a_i = 1ai=1) where a_i = 1ai=1 if and only if classes for guest students are held on the i-th day of a week. Print tt lines, the ii-th line should contain the answer for the ii-th test case — the length of the shortest continuous period of days you need to stay to study exactly kk days as a guest student. 样例输入复制 样例输出复制 样例解释 In the first test case you must arrive to the capital of Berland on Monday, have classes on this day, spenda week until next Monday and have classes on the next Monday. In total you need to spend 8 days in thecapital of Berland. The kingdom of Lazyland is the home to nn idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland. Today kk important jobs for the kingdom (k ≤ n)(k≤n) should be performed. Every job should be done by one person and every person can do at most one job. The King allowed every idler to choose one job they wanted to do and the ii-th idler has chosen the job a_iai. Unfortunately, some jobs may not be chosen by anyone, so the King has to persuade some idlers to choose another job. The King knows that it takes b_ibi minutes to persuade the ii-th idler. He asked his minister of labour to calculate the minimum total time he needs to spend persuading the idlers to get all the jobs done. Can you help him? The first line of the input contains two integers nn and kk (1 ≤ k ≤ n ≤ 10^5)(1≤k≤n≤105) — the number of idlers and the number of jobs. The second line of the input contains nn integers a_1, a_2, . . . , a_na1,a2,...,an (1 ≤ a_i ≤ k)(1≤ai≤k) — the jobs chosen by each idler. The third line of the input contains nn integers b_1, b_2, . . . , b_nb1,b2,...,bn (1 ≤ b_i ≤ 10^9)(1≤bi≤109) — the time the King needs to spend to persuade the ii-th idler. The only line of the output should contain one number — the minimum total time the King needs to spend persuading the idlers to get all the jobs done. 样例输入1复制 样例输出1复制 样例输入2复制 样例输出2复制 Input
Output
2
NO
6
YES
2
1 2
1 3
#include
G. Guest Student
Input
Output
3
2
0 1 0 0 0 0 0
100000000
1 0 0 0 1 0 1
1
1 0 0 0 0 0 0
8
233333332
1
#include
L. Lazyland
Input
Output
8 7
1 1 3 1 5 3 7 1
5 7 4 8 1 3 5 2
10
3 3
3 1 2
5 3 4
0
#include