forked from 0xNilesh/Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bargain.cpp
59 lines (58 loc) · 1.12 KB
/
bargain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<bits/stdc++.h>
# define mp make_pair
# define pb push_back
# define pp pair<int,int>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define M 1000000007
using namespace std;
ll cal(ll n,ll power)
{
ll res=1;
while(power)
{
if(power%2)
{
res = (res*n)%M;
}
n = (n*n)%M;
power/=2;
}
return res;
}
int main()
{
fast
string s;
cin>>s;
ll ans=0;
vector<ll>A;
vector<ll>B(s.size(),0);
ll q=0;
for(int i=0;i<s.size();i++)
{
q=q*10+(s[i]-'0');
q=q%M;
A.pb(q);
}
q=s[s.size()-1]-'0';
B[s.size()-1]=q;
for(int i=s.size()-2;i>=0;i--)
{
q=(q%M+((A[i]-'0')*10)%M)%M;
B[i]=q;;
}
for(int i=0;i<s.size();i++)
{
for(int j=i;j<s.size();j++)
{
ll temp=0;
if(i-1>=0)
temp=A[i]*(cal(10,s.size()-j-1))%M;
temp+=A[i] + A[j+1]%M;
ans+=temp;
}
}
cout<<ans<<"\n";
return 0;
}