You are given an integer sequence 1,2,…,n1,2,…,n. You have to divide it into two sets AAand 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}A={1,2} and B={3}B={3} so the answer is 00.

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

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

题意:给你一个整数N,让你将1~N这N个整数分成两个集合,

问这两个集合的元素数值和的差最小能是多少。

思路:

先写几个样例来看下。

当N=3,

1,2,3  可以把1和2分到一个集合,3分到另一个集合。这样差为0

当N=4

1,2,3,4可以把 1和4分到一个集合,2和3在另一个集合,这样差为0

当N=5

1,2,3,4,5,可以分成这样{1,3,4},{2,5} 差为1

我们在算下这三个样例的所有元素和

N=3 ,sum=6

N=4,sum=10

N=5,sum=15

规律就可以看出来了,当1~N的和为偶数的时候,一定可以分成两个相同的sum的集合

为奇数可以分成相差为1的两个集合。

那么就根据规律来写程序了。

我的AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
int main()
{
cin>>n;
ll ans=(n*(+n))/2ll;
if(ans&)
{
cout<<<<endl;
}else
{
cout<<<<endl;
}
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

MY BLOG:
https://www.cnblogs.com/qieqiemin/

Integer Sequence Dividing CodeForces - 1102A (规律)的更多相关文章

  1. CodeForces - 1102A

    You are given an integer sequence 1,2,-,n1,2,-,n. You have to divide it into two sets AA and BB in s ...

  2. CodeForces - 1102A(思维题)

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

  3. Codeforces Round #452 (Div. 2)-899A.Splitting in Teams 899B.Months and Years 899C.Dividing the numbers(规律题)

    A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. 递推:Number Sequence(mod找规律)

    解题心得: 1.对于数据很大,很可怕,不可能用常规手段算出最后的值在进行mod的时候,可以思考找规律. 2.找规律时不必用手算(我傻,用手算了好久).直接先找前100项进行mod打一个表出来,直接看就 ...

  5. CodeForces - 810C(规律)

    C. Do you want a date? time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. Codeforces Round #531 (Div. 3) ABCDEF题解

    Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...

  7. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

  8. CodeForces - 1059C Sequence Transformation (GCD相关)

    Let's call the following process a transformation of a sequence of length nn. If the sequence is emp ...

  9. Sequence in the Pocket【思维+规律】

    Sequence in the Pocket 题目链接(点击) DreamGrid has just found an integer sequence  in his right pocket. A ...

随机推荐

  1. redis面试必问

    1.项目中缓存是如何使用的?为什么要用缓存?缓存使用不当会造成什么后果? 面试题剖析 为什么要用缓存? 用缓存,主要有两个用途:高性能.高并发. 高性能 假设这么个场景,你有个操作,一个请求过来,吭哧 ...

  2. Usaco 2019 Jan Platinum

    Usaco 2019 Jan Platinum 要不是昨天老师给我们考了这套题,我都不知道usaco还有铂金这么一级. 插播一则新闻:杨神坚持认为铂金比黄金简单,原因竟是:铜 汞 银 铂 金(金属活动 ...

  3. NOIP2018爆零退役滚粗记

    \(Day\ -1\) 非常的颓废 上午考了loli\(\ \ oi\)的最后一轮,\(mhr\)一个小时十五分钟怒切\(260\)分,吊打生爷 发现自己\(T2\)树的直径写怪了,不明觉厉 怕不是要 ...

  4. 【转】escape,encodeURI,encodeURIComponent有什么区别?

    在这个页面里面试着搜了一下 「UTF-8」 ,居然没有搜到. escape 和 encodeURI 都属于 Percent-encoding,基本功能都是把 URI 非法字符转化成合法字符,转化后形式 ...

  5. day04--流程控制之if

    编程的目的是让计算机像人脑一样工作,因此就需要让计算机具备人脑一样的逻辑思维,这里就需要用到计算机语言的流程控制: 流程控制之if......else 语法1: if 条件: 代码块 # 一组代码块的 ...

  6. java 实现serialVersionUID

    文章转自  https://www.cnblogs.com/duanxz/p/3511695.html 作用 serialVersionUID适用于Java的序列化机制.简单来说,Java的序列化机制 ...

  7. MP实战系列(六)之代码生成器讲解

    MP的代码生成器可谓用"简洁"二字,来形容. 我个人觉得jeesite的代码生成器都不一定比它好用.当然也是由于我个人的习惯. 只需一键执行main方法,就可以生成对应的项目文件, ...

  8. 贪心之oj.1797

    1797:金银岛 查看 提交 统计 提问 总时间限制: 3000ms 内存限制: 65536kB 描述 某天KID利用飞行器飞到了一个金银岛上,上面有许多珍贵的金属,KID虽然更喜欢各种宝石的艺术品, ...

  9. java 变量及数据类型、原码、反码、补码

    Java基础——变量及数据类型 变量的概念 内存中的一个存储区域 变量名+数据类型 可在同一类型范围内不断变化 为什么定义变量: 用于不断的存放同一类型的常量,并可以重复使用 使用变量注意: 变量的作 ...

  10. Intellij实用技巧

    快捷键 Tradition 快捷键 介绍 Ctrl + Z 撤销 Ctrl + Shift + Z 取消撤销 Ctrl + X 剪切 Ctrl + C 复制 Ctrl + S 保存 Tab 缩进 Sh ...