I hadn’t solved this question before so to better understand it I gave it a shot in Python got AC. From that point since I know I was generating the correct answers I modified my code a little bit to loop over all possible values of n (1<=n<=16384) and kept a variable to keep track of the maximum output value.

So to answer your question I found that the maximum output value for any valid case in this range is: **16513**

Obviously this tells you that your problem lies in incorrect logic and is not related to a data type issue.

**Edit**: If anyone wants to give this problem a shot the link is here

I will leave it to your correctly modify your code but to give you an idea of where to start see the cases below:

Your responses to n = 1 through n = 5

```
Case #1
first meets river 1 at 1
Case #2
first meets river 1 at 2
Case #3
first meets river 3 at 3
Case #4
first meets river 1 at 4
Case #5
first meets river 1 at 620
```

Correct responses to n = 1 through n = 5

```
Case #1
first meets river 1 at 1
2
Case #2
first meets river 3 at 23
3
Case #3
first meets river 3 at 3
4
Case #4
first meets river 3 at 23
5
Case #5
first meets river 1 at 11
```