Task: Program Execution
Input (English): V, g, 6487, n, 3353, 2505, 1257, 5055, P
Output (English): 18657