**Problem:** [Problem Link][1]

**Prerequisites:** Basics of Modular Arithmetic

We will solve the problem by breaking into three parts:

Let **MOD = 10 ^{9}+7**

**Part 1: Finding the MOD of large number**

Let the given number be **A**, where **|A|** denotes the number of digits in **A**. Let **A _{i}** represents the

**i**digit and

^{th}**l = |A|**then

**A%MOD** = **Σ A _{i}×10^{l-i} % MOD**

= **Σ (A _{i}×(10^{l-i} % MOD))%MOD**

For example

**12345%MOD = (1×10 ^{4})%MOD + (2×10^{3})%MOD + (3×10^{2})%MOD +(4×10^{1})%MOD + (5×10^{0})%MOD**

One important point here is **10 ^{i}** is used many times, hence we can calculate and store them.

Here is my code example:

```
vector<int> arr(100005);
vector<ll> dig = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; // for converting char to digits
arr[0] = 1;
for(int i=1, i < 100005; i++)
arr[i] = ((arr[i-1]×10)%MOD);
// let s contains the number in string format ( since number is very large) and l contains the length
int mi = 0;
for(int i = s.size()-1; i>=0; i--){
mi += ((dig[s[i]-'0']×arr[l-i-1])%MOD);
}
mi = mi%MOD;
```

**Part 2: Generating next shift from previous**

For generating the next shift from previous shift

**A ^{next} = A^{prev} ×10 - 10^{l }× A^{prev}_{1} + A^{prev}_{1}**

For Example :

**23451 = 12345*10 - 10 ^{5}×1+1**

**= 123450 - 100000 + 1**

Yeah, sure you should perform subtraction first and then multiplication to prevent overflow, but I used long long.

Here is my Code example

```
int l = s.size();
// for having the ith shift where mi contains the i-1th shift
mi = (((mi×10)%MOD + dig[s[i]-'0'])%MOD - (dig[s[i]-'0']×arr[l])%MOD)%MOD;
```

**Part 3: Combining the result**

If you are with me till now, this part is the most simplest among the all. The idea is how you can generate the number using the digit. For example

**12345 = (1×10 ^{4}) + (2×10^{3}) + (3×10^{2}) +(4×10^{1}) + (5×10^{0})**

**= ((((( 1 ) × 10 + 2 ) × 10 + 3 ) × 10 + 4 ) × 10 + 5 )**

For input **123**, we can get the combine result as follows :

**total = ((( 123 ) × 10 ^{3} + 231 ) × 10^{3} + 312 )**

Working on the similar lines, you can combine the next shift with the previous result. Let **total** represent the total score till now, then combining process involves

```
total = ((total×arr[l])%MOD + mi)%MOD;
```

**Time complexity:** ◯(n), where n = |N|

**Code:** [Solution Link][2]

[1]: https://www.codechef.com/COOK101A/problems/YVNUM

[2]: https://www.codechef.com/viewsolution/22071480