I tried Solving D-Query

I tried Solving D-Query , but getting WA .
Please Give any hint . I tried everything but still not working .

@shivampandey9599,
This is how I implemented it, you can compare your code with this.
Also, please check if the initial values of beg and End are correct, I think I took different initial values than yours.
P.S I have updated the link.