# Tojo hates probabilities Codechef Solution|Problem Code: ANUTHM

## Problem

Consider anÂ NÂ byÂ MÂ grid. Rows are numberedÂ 1Â toÂ N, from top to bottom. Columns are numberedÂ 1Â toÂ M, from left to right. You are initially at cell (1, 1) and want to go to cell (N, M). From any cell you can move to the cell below it or to the cell right to it. You should never go out of the grid. At any point you should consider all the possibilities of movement with equal probability

Let P[i][j] be the probability of visiting cell (i, j). You need to calculate the sum of P[i][j] forÂ 1Â â‰¤Â iÂ â‰¤Â N,Â 1Â â‰¤Â iÂ â‰¤Â M.

As we all know, Tojo really hates probability-related problems. He wants you to solve this task

### Input

The first line of the input contains an integerÂ TÂ denoting the number of test cases. The description ofÂ TÂ test cases follows.Only line of each test case has two integerÂ NÂ andÂ M.

### Output

For each test case, output a single line containing the required answer. Answers within an absolute or relative error of 10-6Â will be accepted.

### Constraints

• 1Â â‰¤Â TÂ â‰¤Â 1000
• 1Â â‰¤Â NÂ â‰¤Â 1000
• 1Â â‰¤Â MÂ â‰¤Â 1000

### Sample Input 1

``````2
2 2
1 6``````

### Sample Output 1

``````3.000000
6.000000``````

## Tojo hates probabilities â€“ CodeChef Solution in JAVA

```import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int tc = 0; tc < T; tc++) {
int N = sc.nextInt();
int M = sc.nextInt();
System.out.println(solve(N, M));
}
sc.close();
}
static int solve(int N, int M) {
return N + M - 1;
}
}```

Disclaimer:Â The above Problem (Tojo hates probabilitiesÂ ) is generated byÂ CodeChef but the solution is provided byÂ Chase2learn.This tutorial is only forÂ EducationalÂ andÂ LearningÂ purpose.

Sharing Is Caring