What should be the upper limit of z

in my code what sholud be the upper limit of z so that every test case work
one more thing iam getting 2 run time error & 1 no output
in which case it will not give any output

@pankajsingh hey pankaj this question have some constraints associate with it the size of this array can be 10^9 so try to fix it.

now i set z=100005 then i am getting no output for 2 cases rest are running correct