https://vjudge.net/problem/2135388/origin

Describe

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

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

Input

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

Output

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

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 0.

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

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 1.

这是一道思维题,刚拿到题的时候毛了,这是什么题,DP背包容量为1/2值的和;不难发现这个题是个防爆零的送分题。

在表格中不难看出,当数字个数为偶数个时,要平分到两个组合,如果平分后个数为奇数肯定数组中间的两个值被分开,最小差值唯一,123456 分1 / 6 分2 / 5 分3 /4,差值为1; 当个数为奇数个时便有如下方法如果去掉最大之后,按照偶数分析。

AC代码如下

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define inf 0x3f3f3f3f
#define maxn 100
#define Abs(a) ((a)>0?(a):-(a))
int main()
{
int n;
cin>>n;
if(n%2==1) {
n=n-1;
n/=2;
if(n%2==1) cout<<'0'<<endl;
else cout<<'1'<<endl;
return 0;
}
else
{
n=n/2;
if(n%2==0) cout<<'0'<<endl;
else cout<<'1'<<endl;
return 0;
}
}

CodeForces - 1102A(思维题)的更多相关文章

  1. Codeforces 424A (思维题)

    Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Statu ...

  2. Vova and Trophies CodeForces - 1082B(思维题)

    Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trop ...

  3. CodeForces - 417B (思维题)

    Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status ...

  4. CodeForces - 417A(思维题)

    Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit  ...

  5. B - Sonya and Exhibition CodeForces - 1004B (思维题)

    B. Sonya and Exhibition time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题

    http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...

  7. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  8. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

随机推荐

  1. tf.nn.sigmoid_cross_entropy_with_logits 分类

    tf.nn.sigmoid_cross_entropy_with_logits(_sentinel=None,,labels=None,logits=None,name=None) logits和la ...

  2. Node.js 的事件循环机制

    目录 微任务 事件循环机制 setImmediate.setTimeout/setInterval 和 process.nextTick 执行时机对比 实例分析 参考 1.微任务 在谈论Node的事件 ...

  3. Python趣味入门3:变量、字串输入与输出

    安装配置python环境完毕,非常有必要花十分钟对一些基本概念:变量.数学字符.输入.输出等4个概念进行理解,下面通过简单示例,深入了解python的基本语法. 本文的示例均在IDLE的命令行模式中完 ...

  4. 千亿级平台技术架构:为了支撑高并发,我把身份证存到了JS里

    @ 目录 一.用户信息安全规范 1.1 ​用户信息.敏感信息定义及判断依据 1.1.1 个人信息 1.1.2 个人敏感信息 1.2 ​用户信息存储的注意事项 二.​框架技术实现 2.1 用户敏感信息自 ...

  5. Cobalt Strike系列教程第六章:安装扩展

    Cobalt Strike系列教程分享如约而至,新关注的小伙伴可以先回顾一下前面的内容: Cobalt Strike系列教程第一章:简介与安装 Cobalt Strike系列教程第二章:Beacon详 ...

  6. Python程序设计实验报告四:循环结构程序设计(设计型实验)

    安徽工程大学 Python程序设计 实验报告 班级   物流191   姓名  姚彩琴  学号3190505129 成绩 日期     2020.4.8     指导老师       修宇 [实验名称 ...

  7. 杭电 逃离迷宫 BFS

    给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位 ...

  8. LeetCode#160-Intersection of Two Linked Lists-相交链表

    一.题目 编写一个程序,找到两个单链表相交的起始节点. 如下面的两个链表: 在节点 c1 开始相交. 示例 1: 输入:intersectVal = 8, listA = [4,1,8,4,5], l ...

  9. Windows DC域控由server08r2升级至server2016测试

    测试环境 原DC: csctest.com CSCDC01 192.168.100.1 server08r2 CSCDC02 192.168.100.2 server08r2 要求: 原两台旧主机均更 ...

  10. 使用hexo和coding建立静态博客站点

    背景 由于工作性质的原因,做技术的总想记录和分享一下自己的学习和成长历程,向这世界证明我来过.写文章,发博客,一开始使用51cto,广告太多,看起来让人很痛苦:接着试用了博客园,广告少一些,但感觉还是 ...