You are given an integer sequence 1,2,…,n1,2,…,n. You have to divide it into two sets AA and BB in such a way that each element belongs to exactly one set and |sum(A)−sum(B)||sum(A)−sum(B)| is minimum possible.

The value |x||x| is the absolute value of xx and sum(S)sum(S) is the sum of elements of the set SS.

Input
The first line of the input contains one integer nn (1≤n≤2⋅1091≤n≤2⋅109).

Output
Print one integer — the minimum possible value of |sum(A)−sum(B)||sum(A)−sum(B)| if you divide the initial sequence 1,2,…,n1,2,…,n into two sets AA and BB.

Examples
Input
3
Output
0
Input
5
Output
1
Input
6
Output
1
Note
Some (not all) possible answers to examples:

In the first example you can divide the initial sequence into sets A={1,2} and B={3} so the answer is 00.

In the second example you can divide the initial sequence into sets A={1,3,4} and B={2,5} so the answer is 11.

In the third example you can divide the initial sequence into sets A={1,4,5}and B={2,3,6} so the answer is 11.

解题思路:先求出前n项的和,如果前n项和为偶数,则总能找到两个子集的和相等;若为奇数,则总能找到两个子集和相差为1.

include<stdio.h>

int main()
{
long long n,ans;
while(~scanf("%lld",&n))
{
ans=(1+n)*n/2;
if(ans%2==1)
printf("1\n");
else if(ans%2==0)
printf("0\n");
}
}

CodeForces - 1102A的更多相关文章

  1. Integer Sequence Dividing CodeForces - 1102A (规律)

    You are given an integer sequence 1,2,…,n1,2,…,n. You have to divide it into two sets AAand BB in su ...

  2. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

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

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

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

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

  5. 【Codeforces 738C】Road to Cinema

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

  6. 【Codeforces 738A】Interview with Oleg

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

  7. CodeForces - 662A Gambling Nim

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

  8. CodeForces - 274B Zero Tree

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

  9. CodeForces - 261B Maxim and Restaurant

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

随机推荐

  1. java学习之路--I/O流

      java基础学习总结——流 一.JAVA流式输入/输出原理

  2. 十三、事务、连接池 、ThreadLocal 、BaseServlet自定义Servlet父类 、 DBUtils à commons-dbutils

    l 事务 l 连接池 l ThreadLocal l BaseServlet自定义Servlet父类(只要求会用,不要求会写) l DBUtils à commons-dbutils 事务 l 事务的 ...

  3. if-else案例–开关灯

    首先,创建一个html页面,添加一个div盒子,用css设置相应的样式,用js获取盒子的元素,通过点击事件,设置body的背景颜色,用if..else来判断当什么状态设置相应的颜色,(swith... ...

  4. Python函数中的列表

    在看21天的Python书中写出了一个陷阱,但没给出解释,以下为代码陷阱

  5. oracle 表 库实例 空间

    地址 http://blog.csdn.net/g15738290530/article/details/51859048 1:个人理解 数据库可以有多个实例,其中 orcl 为默认 一般情况下,一个 ...

  6. 《Zero MQ》

    原文链接 http://www.aosabook.org/en/zeromq.html ZeroMQ ZeroMQ 是一个消息系统,或者‘面向消息的中间件’.广泛应用于金融服务,游戏开发,嵌入式系统, ...

  7. ARE 212 - Problem Set 5

    ARE 212 - Problem Set 5Due May 1stPart I: Theory (Optional)1. Show that the parameter estimates for ...

  8. 天梯赛练习题L2-006. 树的遍历

    题目链接 已知一棵树的后序遍历顺序和中序遍历顺序,求层次遍历的顺序: 树的四种遍历: 先序遍历:先访问根节点,再访问左子树,最后访问右子树 中序遍历:先访问左子树,再访问根节点,最后访问右子树 后序遍 ...

  9. Java注解--笔记

    @Override标签的作用@Override是伪代码,所以是可写可不写的.它表示方法重写,写上会给我们带来好处. 1.可以当注释用,方便阅读. 2.告诉阅读你代码的人,这是方法的复写. 3.编译器可 ...

  10. Python3学习之路~8.4 利用socket实现文件传送+MD5校验

    利用socket实现文件传送,大约分为如下几步: 1.读取文件名2.检测文件是否存在3.打开文件(别忘了最后关闭文件)4.检测文件大小5.发送文件大小给客户端6.等客户端确认7.开始边读边发数据8.m ...