Minimum and maximum differences

2.8

32 votes
Basic Programming, , Basics of Implementation, Greedy Algorithms
Problem

You are given a number . Your task is to determine two arrays of permutation of size  so that  for each and the sum of  for each is minimum and maximum possible.

Example 

If , then for the minimum difference is and the corresponding array permutation is  and the maximum difference is also  and the corresponding array permutation is .

Input format

The first line contains an integer .

Output format

  • In the first line, print one integer for the minimum difference.
  • In the second line, print permutation corresponding to the minimum difference.
  • In the third line, print one integer for the maximum difference.
  • In the fourth line, print permutation  corresponding to the maximum difference

If there is no permutation for minimum, then print    instead of the first and second lines.
If there is no permutation for maximum, then print   instead of the third and fourth lines.

Sample Input
3
Sample Output
4
3 1 2
4
2 3 1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

given so if we take  as our permuatation for minimum we will get   as sum of absolute diffrence with index. you can't get absolute difference less than this without  violatiiong condintion

for maximum differance we can use as permutation for maximum. we will get  as sum of absolute diffrence with index. you  can't get absolute difference more than this without violatiiong condintion

In this case () minimum and maximum differance is same

Editor Image

?