明若清溪天下绝歌 缱绻成说,不知该在哪处着墨;一生情深怎奈何世事 徒留斑驳,只一念痴恋成奢。

You went to the store, selling nn types of chocolates. There are aiai chocolates of type ii in stock.

You have unlimited amount of cash (so you are not restricted by any prices) and want to buy as many chocolates as possible. However if you buy xixi chocolates of type ii (clearly, 0≤xi≤ai0≤xi≤ai), then for all 1≤j<i1≤j<i at least one of the following must hold:

  • xj=0xj=0 (you bought zero chocolates of type jj)
  • xj<xixj<xi (you bought less chocolates of type jj than of type ii)

For example, the array x=[0,0,1,2,10]x=[0,0,1,2,10] satisfies the requirement above (assuming that all ai≥xiai≥xi), while arrays x=[0,1,0]x=[0,1,0], x=[5,5]x=[5,5] and x=[3,2]x=[3,2] don't.

Calculate the maximum number of chocolates you can buy.

Input

The first line contains an integer nn (1≤n≤2⋅1051≤n≤2⋅105), denoting the number of types of chocolate.

The next line contains nn integers aiai (1≤ai≤1091≤ai≤109), denoting the number of chocolates of each type.

Output

Print the maximum number of chocolates you can buy.

Examples

input

Copy

5
1 2 1 3 6

output

Copy

10

input

Copy

5
3 2 5 4 10

output

Copy

20

input

Copy

4
1 1 1 1

output

Copy

1

Note

In the first example, it is optimal to buy: 0+0+1+3+60+0+1+3+6 chocolates.

In the second example, it is optimal to buy: 1+2+3+4+101+2+3+4+10 chocolates.

In the third example, it is optimal to buy: 0+0+0+10+0+0+1 chocolates.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
ll a[200020];
int n;
int main()
{scanf ("%d",&n);for (int i=1; i<=n; i++)scanf ("%lld",&a[i]);ll ans=a[n];for (int i=n-1; i>=1; i--){if (a[i]>=a[i+1]){if (!a[i+1])break;ans+=a[i+1]-1;a[i]=a[i+1]-1;}elseans+=a[i];}printf ("%lld\n",ans);return 0;
}

It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, the poor boy will use the first bus he sees no matter where it goes. If several buses come at the same time, he will choose one randomly.

Serval will go to the bus station at time tt, and there are nn bus routes which stop at this station. For the ii-th bus route, the first bus arrives at time sisi minutes, and each bus of this route comes didi minutes later than the previous one.

As Serval's best friend, you wonder which bus route will he get on. If several buses arrive at the same time, you can print any of them.

Input

The first line contains two space-separated integers nn and tt (1≤n≤1001≤n≤100, 1≤t≤1051≤t≤105) — the number of bus routes and the time Serval goes to the station.

Each of the next nn lines contains two space-separated integers sisi and didi (1≤si,di≤1051≤si,di≤105) — the time when the first bus of this route arrives and the interval between two buses of this route.

Output

Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.

Examples

input

Copy

2 2
6 4
9 5

output

Copy

1

input

Copy

5 5
3 3
2 5
5 6
4 9
6 1

output

Copy

3

input

Copy

3 7
2 2
2 3
2 4

output

Copy

1

Note

In the first example, the first bus of the first route arrives at time 66, and the first bus of the second route arrives at time 99, so the first route is the answer.

In the second example, a bus of the third route arrives at time 55, so it is the answer.

In the third example, buses of the first route come at times 22, 44, 66, 88, and so fourth, buses of the second route come at times 22, 55, 88, and so fourth and buses of the third route come at times 22, 66, 1010, and so on, so 11 and 22 are both acceptable answers while 33 is not.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int main()
{int n, m,a,d, mi = inf, jg, ls;scanf("%d%d", &n, &m);for (int i = 1; i <= n; i++){scanf("%d%d", &a, &d);if (a >= m)ls = a - m;else{ls = d - (m - a) % d;if (ls >= d)ls -= d;}if (ls < mi){mi = ls;jg = i;}}printf("%d\n", jg);return 0;
}

An array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each number from 11 to nn exactly once. For example, the following arrays are permutations: [3,1,2][3,1,2], [1][1], [1,2,3,4,5][1,2,3,4,5] and [4,3,1,2][4,3,1,2]. The following arrays are not permutations: [2][2], [1,1][1,1], [2,3,4][2,3,4].

Polycarp invented a really cool permutation p1,p2,…,pnp1,p2,…,pn of length nn. It is very disappointing, but he forgot this permutation. He only remembers the array q1,q2,…,qn−1q1,q2,…,qn−1 of length n−1n−1, where qi=pi+1−piqi=pi+1−pi.

Given nn and q=q1,q2,…,qn−1q=q1,q2,…,qn−1, help Polycarp restore the invented permutation.

Input

The first line contains the integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of the permutation to restore. The second line contains n−1n−1 integers q1,q2,…,qn−1q1,q2,…,qn−1 (−n<qi<n−n<qi<n).

Output

Print the integer -1 if there is no such permutation of length nn which corresponds to the given array qq. Otherwise, if it exists, print p1,p2,…,pnp1,p2,…,pn. Print any such permutation if there are many of them.

Examples

input

Copy

3
-2 1

output

Copy

3 1 2 

input

Copy

5
1 1 1 1

output

Copy

1 2 3 4 5 

input

Copy

4
-1 2 2

output

Copy

-1
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,ans;
int a[200010];
int b[200010];
int p[200010];
int main()
{scanf("%d",&n);for(int i=1; i<n; i++){scanf("%d",&a[i]);p[i]=p[i-1]+a[i];}int mi=p[0];for(int i=1; i<n; i++)mi=min(mi,p[i]);for(int i=0; i<n; i++){if(p[i]-mi+1>n||b[p[i]-mi+1]){printf("-1\n");return 0;}b[p[i]-mi+1]=1;}for(int i=0; i<n; i++)printf("%d ",p[i]-mi+1);return 0;
}

cf----2019-09-22(Chocolates,Serval and Bus, Polycarp Restores Permutation)相关推荐

  1. 一周前端文章推荐(2019/09/22)

    给 「前端开发博客」 加星标,每天打卡学习 长按二维码即可识别"进入网页"查看哟~ 1.用 JS 写游戏自动脚本是什么体验? 我是从写游戏脚本入的编程这行 今天翻看老照片,翻到了下 ...

  2. 《惢客创业日记》2019.02.22(周五) 先僵化,后优化,再固化

    今天的主要工作还是设计首页主菜单中的动态图标.按照我的想法,这个动态图标是一个种子进阶的故事.注册完用户后,看到的是一棵沉睡的种子,当完成实名认证后,这个种子就开始发芽,并睁了眼睛.随着用户参与惢客的 ...

  3. 面试问题记录 2019.3.22(中国铁道科学研究院)

    问题:http的七层协议 握手几次 问题:es6 问题:浏览器是怎么渲染的 问题:mvvm 以及vue的了解 vue的双向绑定 问题:ajax 的请求头怎么知道是传输的是图片,ajax的优缺点 问题: ...

  4. 《惢客创业日记》2019.06.22(周六)规范产品设计的五字诀(二)

    今天,继续分享自己这段时间学习产品和工作的体会,也就是产品设计的五字诀中"简.素.快.用.惯"中的后四个字. 我们先来看看"素",大慨三个月前,是凉粉儿看到我们 ...

  5. 《惢客创业日记》2019.09.02(周一) 把习惯变成闹钟

    今天,在学习健康知识的时候,看到了一个关于乔吉拉德起床的故事,这个故事在很多年前就看过,不过,今天看到这个故事却联想到了惢客.说到乔迪拉德,很多懂销售的人都知道,在销售界还被冠以"销售之神& ...

  6. 《惢客创业日记》2019.09.24(周二)高龄创业者的健康博弈(十四)

    昨天,分享了我的精力汤配制方案中的第一类,根茎蔬菜类,今天,继续分享其他的四种类型的食材. 第二类是坚果类. 我一般会放入一个核桃.三个腰果.十粒枸杞和一小勺黑芝麻,如果没有腰果,也可以放入几粒生花生 ...

  7. 《惢客创业日记》2019.07.22(周一)医生如何证明诚信?

    今天上午,又拿着检查报告拐了一趟医院,医生看完检查又给开了不少药,而喝药的理由不是对症下药,而是喝药排除法.前段时间喝了两个星期的中药,又是治脾虚,又是治疗肾虚的药,都没有改善头晕.头沉的毛病.而前几 ...

  8. 《惢客创业日记》2019.09.06(周五) 产品经理该不该反人性?

    今天中午,收到了一个还款的提醒通知,我查询了一下最近的生活消费账单,发现自己在上个月的消费总额后,大吃了一惊,没想到自己在上个月花了这么多钱.等我查询明细以后,才发现,很多消费都是在不经意间就花出去了 ...

  9. 《惢客创业日记》2019.09.26(周四) 高龄创业者的健康博弈(十六)

    今天,继续接着昨天关于胃的主题分享,昨天说了,通过五招养胃生活习惯的改变,让我的胃不再反酸,身体的整体状况也有了很大的改进.不过,却出现了肠胃的毛病,就是胀气.嗳气且大便不成形.而且,过了一个月,不但 ...

最新文章

  1. NYOJ 762 第k个互质数(二分 + 容斥)
  2. java 文本 从列开始_如何从sql java中检索文本列?
  3. FPGA学习之路—接口(1)—URAT Verilog程序设计
  4. 智能硬件的时代,嵌入式是否已经日薄西山
  5. 斗地主AI算法——第六章の牌型判断
  6. 路由总结之静态、RIP、OSPF、IS-IS、BGP和策略路由
  7. 虹软人脸识别SDK - Java服务端的那些事
  8. (转)web app 禁用手机浏览器缓存方法
  9. shell_study
  10. 什么?你的私钥泄漏了?
  11. Matlab自适应均线_基于MATLAB的自回归移动平均模型(ARMA)在股票预测中的应用
  12. 苹果锁定计算机的快捷键,苹果电脑快捷键使用 Mac快捷键大全详细介绍
  13. 网络安全——社会工程学02
  14. 会考计算机基本知识点总结,高中计算机会考基本知识点
  15. 质量功能配置(QFD)矩阵
  16. 算法提高 素数环 java 题解 977
  17. 【jQuery】基础知识梳理笔记
  18. 怎么画计算机系统时空图,计算机系统结构中流水线的时空图怎么画
  19. (五)IEEE802.1Q与ISL
  20. Latex之给字符上加横线、波浪等

热门文章

  1. 游戏中常说的“周目”是什么意思呢?
  2. 后端自学——使用WinSCP远程连接阿里云轻量应用服务器
  3. 如何重装电脑自带的正版office2016家庭学生版
  4. ChatGPT的焦虑蔓延,暴露了企业转型的关键要素
  5. python3编程入门解压码_Python编程入门(第3版) PDF|百度网盘下载内附提取码
  6. html转义字符 叹号,特殊符号感叹号
  7. GitHub 访问加速方法 超好用
  8. inno setup基础使用教程
  9. Android手机令牌,WEB安全之硬件绑定变向思路
  10. 神武跑环遇到服务器维护,神武跑环不再痛苦:任务链重点难点详解攻略