XXI Berland Annual Fair is coming really soon! Traditionally fair consists of nn booths, arranged in a circle. The booths are numbered 11 through nn clockwise with nn being adjacent to 11 . The ii -th booths sells some candies for the price of aiai burles per item. Each booth has an unlimited supply of candies.
Polycarp has decided to spend at most TT burles at the fair. However, he has some plan in mind for his path across the booths:
- at first, he visits booth number 11 ;
- if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately;
- then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
Calculate the number of candies Polycarp will buy.
Input
The first line contains two integers nn and TT (1≤n≤2⋅1051≤n≤2⋅105 , 1≤T≤10181≤T≤1018 ) — the number of booths at the fair and the initial amount of burles Polycarp has.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109 ) — the price of the single candy at booth number ii .
Output
Print a single integer — the total number of candies Polycarp will buy.
Examples
Input
3 38 5 2 5
Output
10
Input
5 21 2 4 100 2 6
Output
6
Note
Let's consider the first example. Here are Polycarp's moves until he runs out of money:
- Booth 11 , buys candy for 55 , T=33T=33 ;
- Booth 22 , buys candy for 22 , T=31T=31 ;
- Booth 33 , buys candy for 55 , T=26T=26 ;
- Booth 11 , buys candy for 55 , T=21T=21 ;
- Booth 22 , buys candy for 22 , T=19T=19 ;
- Booth 33 , buys candy for 55 , T=14T=14 ;
- Booth 11 , buys candy for 55 , T=9T=9 ;
- Booth 22 , buys candy for 22 , T=7T=7 ;
- Booth 33 , buys candy for 55 , T=2T=2 ;
- Booth 11 , buys no candy, not enough money;
- Booth 22 , buys candy for 22 , T=0T=0 .
No candy can be bought later. The total number of candies bought is 1010 .
In the second example he has 11 burle left at the end of his path, no candy can be bought with this amount.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[200020];
ll n;ll nn;
int main(){
ll initial;ll num=0; ll minn=1e9;
cin>>n>>initial;
for(ll i=0;i<n;i++){
cin>>a[i];
minn=min(minn,a[i]);
}
ll res=0;
while(initial>=minn){
ll s=0;ll num=0;
for(ll i=0;i<n;i++) if(a[i]<=initial) s++,num+=a[i],initial-=a[i];
res+=s+(long long)initial/num*s; initial%=num;
}
cout<<res<<endl;
return 0;
}
一开始的时候不是检验最小值和剩余的钱,而是用一个遍历,虽然总的来说是影响常数阶,但是还是超时了,所以要尽量简化。
还有转换要是很麻烦的话,都用long long ,就行了,wa了一发。
我一开始只想到把一遍的减掉,但是里面的数可以相差很多,所以每一遍减去都可以是不同的数,当我意识到的时候,只认为是只会出现一次,实际上每一次都是等价的,每一次都是。审题,例子要完全明白要表达的意思。