ABDTOLL weird test cases

Try this test cases for both the solutions first one gives 8 and the other 0, funny part is both of them got accepted
Test case
1
1 1 5
9
Solutions
https://www.codechef.com/viewsolution/24440530
https://www.codechef.com/viewsolution/24415630