# Make A, B and C equal by adding total value N to them

Given 3 integers **A, B, and C**, and an integer **N**, the task is to distribute **N** among all the other 3 numbers such that at the end **A = B = C**. If the distribution is possible then print “Yes” otherwise output “No”.

**Examples:**

Input:A = 5, B = 3, C = 2, N = 8

Output:Yes

Explanation:

We can distribute N = 8 by adding 1 to A, 3 to B and 4 to C to get all of them as 6. Hence the distribution is possible.

Input:A = 10, B = 20, C = 15, N = 14

Output:No

Explanation:

Distribution of N among all three integers to make them equal is not possible.

**Approach:**

To solve the problem mentioned above we have to follow the steps given below:

- Find
**maximum**out of all the three integers A, B and C. Let that be integer*K* - Multiply the integer K by 3 and then subtract it by the sum of the three integers.
- Check if the difference of that number and N is
**divisible by 3**or not. - If it is, then the output is “Yes”, otherwise it is not possible to distribute the number.

Below is the implementation of the above approach:

## C++

`// C++ program to distribute integer N ` `// among A, B, C such that they become equal ` `#include<bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `void` `distributeN(` `int` `A, ` `int` `B, ` `int` `C, ` `int` `n) ` `{ ` ` ` `// Find maximum among the three elements ` ` ` `int` `max1 = max(A, B); ` ` ` `int` `max2 = max(B, C); ` ` ` `int` `maximum = max(max1, max2); ` ` ` ` ` `// Summation of three elements ` ` ` `int` `sum = A + B + C; ` ` ` `int` `p = (3 * maximum) - sum; ` ` ` `int` `diff = n - p; ` ` ` ` ` `// Check if difference is divisible by 3 ` ` ` `if` `(diff < 0 || diff % 3) ` ` ` `cout << ` `"No"` `; ` ` ` `else` ` ` `cout << ` `"Yes"` `; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `A = 10, B = 20; ` ` ` `int` `C = 15, n = 14; ` ` ` ` ` `distributeN(A, B, C, n); ` ` ` `return` `0; ` `} ` ` ` `// This code is contributed by PratikBasu ` |

*chevron_right*

*filter_none*

## Python3

`# Python Program to Distribute integer N ` `# among A, B, C such that they become equal ` ` ` `def` `distributeN(A, B, C, n): ` ` ` ` ` `# find maximum among the three elements ` ` ` `maximum ` `=` `max` `(A, B, C) ` ` ` ` ` `# summation of three elements ` ` ` `sum` `=` `A ` `+` `B` `+` `C ` ` ` ` ` ` ` `p ` `=` `(` `3` `*` `maximum)` `-` `sum` ` ` ` ` `diff ` `=` `n` `-` `p ` ` ` ` ` `# check if difference is divisible by 3 ` ` ` `if` `diff < ` `0` `or` `diff ` `%` `3` `: ` ` ` `print` `"No"` ` ` `else` `: ` ` ` `print` `"Yes"` ` ` ` ` `# Driver code ` `A ` `=` `10` `B ` `=` `20` `C ` `=` `15` `n ` `=` `14` `distributeN(A, B, C, n) ` |

*chevron_right*

*filter_none*

**Output:**

No

**Time Complexity:** O(1)

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

## Recommended Posts:

- Minimum number of letters needed to make a total of n
- Make all numbers of an array equal
- Remove two consecutive integers from 1 to N to make sum equal to S
- Minimum operations to make two numbers equal
- Make all elements of an array equal with the given operation
- Minimum multiplications with {2, 3, 7} to make two numbers equal
- Minimum operations required to make two numbers equal
- Minimum insertions to make XOR of an Array equal to half of its sum
- Number of character corrections in the given strings to make them equal
- Minimum steps to make the product of the array equal to 1
- Minimum cost to make all array elements equal
- Minimum deletions required to make GCD of the array equal to 1
- Minimum operations to make all elements equal using the second array
- Minimum changes required to make all element in an array equal
- Make array elements equal with minimum cost

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.