Different outputs for run as custom input and submission and even different for see expected output


Code is giving different outputs for Run with Custom Input and while submitting the code for the same input. I have checked the global variables and cleared them before using in the code. The expected output for the test case is the same as the one returned by Run with Custom Input, but the same input gives a different result when code is submitted.