There was an electronic store heist last night.

All keyboards which were in the store yesterday were numbered in ascending order from some integer number x. For example, if x=4 and there were 3 keyboards in the store, then the devices had indices 4, 5 and 6, and if x=10 and there were 7 of them then the keyboards had indices 10, 11, 12, 13, 14, 15 and 16.

After the heist, only n keyboards remain, and they have indices a1,a2,…,an. Calculate the minimum possible number of keyboards that have been stolen. The staff remember neither x nor the number of keyboards in the store before the heist.

Input

The first line contains single integer n (1≤n≤1000) — the number of keyboards in the store that remained after the heist.

The second line contains n distinct integers a1,a2,…,an (1≤ai≤109) — the indices of the remaining keyboards. The integers ai are given in arbitrary order and are pairwise distinct.

Output

Print the minimum possible number of keyboards that have been stolen if the staff remember neither x nor the number of keyboards in the store before the heist.

Examples

inputCopy

4

10 13 12 8

outputCopy

2

inputCopy

5

7 5 6 4 8

outputCopy

0

Note

In the first example, if x=8 then minimum number of stolen keyboards is equal to 2. The keyboards with indices 9 and 11 were stolen during the heist.

In the second example, if x=4 then nothing was stolen during the heist.

#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
} #define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 100050
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
long long a[N];
int main()
{
int n;
read(n);
rep(0, n, i) read(a[i]);
sort(a, a + n);
long long ans = 0;
reo(1, n, i) ans += a[i] - a[i - 1] - 1;
wl(ans),P;
return 0;
}

Codeforces Round #509 (Div. 2) A. Heist 贪心的更多相关文章

  1. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

  2. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  3. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  4. Codeforces Round #180 (Div. 2) B. Sail 贪心

    B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...

  5. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  6. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

  7. Codeforces Round #509 (Div. 2)

    咕咕咕了好多天终于有时间写篇博客了_(:з」∠)_ 打网赛打到自闭的一周,终于靠这场CF找回了一点信心... 1041A - Heist \(ans=max\left \{ a_i \right \} ...

  8. Codeforces Round #374 (Div. 2) B. Passwords 贪心

    B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...

  9. Codeforces Round #303 (Div. 2) C. Woodcutters 贪心

    C. Woodcutters Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...

随机推荐

  1. webpack中引用jquery

    1.首先需要添加项目中jquery的依赖 npm install jquery --save-dev 2.参考配置代码: var webpack = require("webpack&quo ...

  2. shell http请求&处理返回值获取其中某个字段的值

    并且第一个接口的返回值中部分参数得作为第二个接口的入参,所以做了如下shell验证 第一个接口返回的response body串: { "bizCode": "1&quo ...

  3. python3(二十三)classInstance

    """ 类和实例和访问权限 """ __author__ = 'shaozhiqi' # class后面紧接着是类名,即Student,类名 ...

  4. vueThink框架搭建与填坑(new)

    自己跟着官网搭建vueThink框架,发现github上文档有很多坑.所以总结一下(仅针对WIN端下载使用) 1.安装node.js 前端部分是基于node.js上运行的,所以必须先安装node.js ...

  5. golang 在 Mac , Linux , Windows 下交叉编译详解

    一. 前言 Golang 支持交叉编译, 在一个平台上生成然后再另外一个平台去执行. 而且编译的工具[build]这个工具是Golang 内置的,不需要你去下载第三方的包啥的,贼方便. 二. 交叉编译 ...

  6. 学习Salesforce | 带你解锁Superbadge的真正作用

    Superbadges是对专业知识和技能的一种认可,通过解决企业在实际业务场景中遇到的复杂问题,展示你的Salesforce专业技能. 要想获得Superbadge,首先需要完成Trailhead徽章 ...

  7. B - Fadi and LCM CodeForces - 1285C 质因子

    题目大意很简单,给你一个整数X,让你求a和b,使得max(a,b)尽可能的小,然后打印a,b 题解:想到了质因子分解,也考虑到了暴力,但是觉得暴力的话会TLE,所以打算用贪心做,然后就一直Wa.... ...

  8. Springboot:员工管理之登录、拦截器(十(4))

    1:构建登录javaBean com\springboot\vo\LoginUser.java package com.springboot.vo; import lombok.Data; @Data ...

  9. SringMVC入门程序

    Spring MVC是Spring Framework的一部分,是基于Java实现MVC的轻量级Web框架 1.Spring优点 轻量级,简单易学 高效 , 基于请求响应的MVC框架 与Spring兼 ...

  10. pytorch 孪生神经网络DNN

    代码内容请见: https://github.com/LiuXinyu12378/DNN-network