Regarding Yalalovichik Numbers (Dec Cookoff)

Hello ,
I solved the question in O(|N|.log(|N|) time , still i am getting tle .
About my approach :For example if N=123 then Y(N) = 123231312 => Y(N) = (123000000 + 231000 + 312)
MOD=1000000007 .
Now Y(N) %MOD = [(123%MOD) * pow(10,6)%MOD + …] I calculated modulo of all rotated strings in O(N + NlogN) time [N=length of string <=1e5].

Similarly , Modulo of powers of 10 can also be calculated in log(N) using efficient power function .
So , with this complexity the solution should pass the test cases .

Here is my submission :
Please help me as I am bewildered and confused as to where did I go wrong.

int d = n.size();
arr[0] = n;
string t1 = n.substr(0,i) , t2 = n.substr(i,(d-i));
substr function takes linear time complexity, so the complexity goes to \mathcal{O}(\mid{N}\mid^2)

Take a look here for understanding how you can do it without the substr function