A. candy bags

Source: Internet
Author: User
Time limit per test

1 second

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Gerald hasNYounger brothers and their number happens to be even. One day he boughtN2 candy
Bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integerKFrom 1N2 he
Has exactly one bagKCandies.

Help him giveNBags of candies to each brother so that all brothers got the same number of candies.

Input

The single line contains a single integerN(NIs
Even, 2 bytes ≤ averageNLimit ≤ limit 100)-the number of Gerald's brothers.

Output

Let's assume that Gerald indexes his brothers with numbers from 1N.
You need to printNLines, onI-Th
Line printNIntegers-the numbers of candies in the bags forI-Th
Brother. Naturally, all these numbers shoshould be distinct and be within limits from 1N2.
You can print the numbers in the lines in any order.

It is guaranteed that the solution exists at the given limits.

Sample test (s) Input
2
Output
1 42 3
Note

The sample shows Gerald's actions if he has two brothers. in this case, his bags contain 1, 2, 3 and 4 candies. he can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.

Description: This question is to select n pairs of numbers from 1 to n ^ 2 so that the sum of each pair of numbers is equal. The simplest thing is to pair the head and tail, and then move them in turn.

#include <cstdio>#include<iostream>using namespace std;int main(){int n,i;scanf("%d",&n);for(i=1;i<=(n*n)/2;i++){printf("%d %d\n",i,(n*n)-i+1);}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.