E - E

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] is not.

A permutation triple of permutations of length n(a, b, c) is called a Lucky Permutation Triple if and only if . The sign ai denotes the i-th element of permutation a. The modular equality described above denotes that the remainders after dividing ai + bi by n and dividing ci by n are equal.

Now, he has an integer n and wants to find a Lucky Permutation Triple. Could you please help him?

Input

The first line contains a single integer n(1 ≤ n ≤ 105).

Output

If no Lucky Permutation Triple of length n exists print -1.

Otherwise, you need to print three lines. Each line contains n space-seperated integers. The first line must contain permutation a, the second line — permutation b, the third — permutation c.

If there are multiple solutions, print any of them.

Sample Input

Input
5
Output
1 4 3 2 0
1 0 2 4 3
2 4 0 1 3
Input
2
Output
-1

Hint

In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds:

  • ;
  • ;
  • ;
  • ;
  • .

In Sample 2, you can easily notice that no lucky permutation triple exists.

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
if(n==)
{
printf("%d\n%d\n%d\n",,,);
return ;
}
if(!(n&))
{
printf("-1\n");
return ;
}
for(int i=;i<n;i++)
{
printf("%d ",i);
}
printf("\n");
for(int i=;i<n;i++)
{
printf("%d ",i);
}
printf("0\n");
for(int i=;i<n;i++)
printf("%d ",(i+i+)%n);
return ;
}

http://www.voidcn.com/blog/theArcticOcean/article/p-4944592.html

这个大神讲解的挺好的。

CodeForces 304C的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. C语言代码优化(转)

    .选择合适的算法和数据结构 选择一种合适的数据结构很重要,如果在一堆随机存放的数中使用了大量的插入和删除指令,那使用链表要快得多.数组与指针语句具有十分密切的关系,一般来说,指针比较灵活简洁,而数组则 ...

  2. [转载]Using ngOptions In AngularJS

    http://odetocode.com/blogs/scott/archive/2013/06/19/using-ngoptions-in-angularjs.aspx?utm_source=tui ...

  3. 自定义 array_map() 对应的递归函数 array_map_recursive()

    array_walk 有个原生递归函数 array_walk_recursive($arr, 'function', 'words'),但是 array_map 却没有对应的递归函数 array_ma ...

  4. ROS2.9.27架设网吧软路由实战篇之端口映射与回流

    转载:http://blog.csdn.net/zm2714/article/details/7924280 上一篇:ROS2.9.27架设网吧软路由实战篇之连通网络,主要讲述了网吧架设软路由ROS2 ...

  5. MySQL关闭过程详解和安全关闭MySQL的方法

    MySQL关闭过程详解和安全关闭MySQL的方法 www.hongkevip.com 时间: -- : 阅读: 整理: 红客VIP 分享到: 红客VIP(http://www.hongkevip.co ...

  6. pip 直接安装tar.gz zip文件包 (windows linux mac 可用)

    在不能连接外网的机器上安装python的各种包,解压安装要人工输入多条命令: tar -zxvf Flask-WTF-0.10.0.tar.gz cd Flask-WTF-0.10.0 python ...

  7. 【Hibernate】Hibernate系列3之配置文件详解

    配置文件详解 3.1.配置文件 连接池性能优化:http://www.cnblogs.com/xdp-gacl/p/4002804.html

  8. MySQL报错:Packets larger than max_allowed_packet are not allowed 的解决方案

    在导大容量数据特别是CLOB数据时,可能会出现异常:“Packets larger than max_allowed_packet are not allowed”. 这是由于MySQL数据库有一个系 ...

  9. Segment Tree Modify

    For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...

  10. 转MYSQL学习(二) 运算符

    MYSQL中的运算符很多,这一节主要讲MYSQL中有的,而SQLSERVER没有的运算符 安全等于运算符(<=>) 这个操作符和=操作符执行相同的比较操作,不过<=>可以用来判 ...