You are provided an unlimited collection of red, green and blue balls. Now your task is to arrange N balls taken from this collection in a line in such a way that red balls appear first, followed by green balls and then blue balls. Given a value of N you have to find the number of ways to do that.
Note:  In a particular arrangement a certain color of balls may be missing but the order must be strictly maintained with the available balls.
 
 
Example 1:
Input:
N = 1
Output:
3
Explanation:
You are allowed to take 1 
ball only. So that one ball 
can be red, green, or blue. 
So the number of ways, in 
this case is 3.
 
Example 2:
Input:
N = 2
Output:
6
Explanation:
You are allowed to take 2 
balls. So you have six 
alternative arrangements ie. 
RG,GB,RB,RR,GG,BB.
 
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function numberOfWays() which takes an integer N and returns the number of ways to do that.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints 
1<=N<=10^9

Source: geeksforgeeks | Difficulty: EASY
Tags: Combinatorics

Starter code: #User function Template for python3

class Solution:

    def numberOfWays (self,N):

        # code here 

Solutions:
class Solution:

	def numberOfWays(self, N):
		a = (N + 1) * (N + 2)
		a = a // 2
		return a


class Solution:

	def numberOfWays(self, N):
		n = N + 1
		return n * (n + 1) // 2


class Solution:

	def numberOfWays(self, N):
		if N == 1:
			return 3
		temp = N * 3
		return temp + (N - 2) * (N - 1) // 2


class Solution:

	def numberOfWays(self, n):
		temp = n * (n - 1) // 2
		temp += 3 + 2 * (n - 1)
		return temp


class Solution:

	def numberOfWays(self, N):
		n = N + 2
		r = 2
		ans = 1
		for i in range(r):
			ans *= n - i
		return ans // 2


class Solution:

	def numberOfWays(self, n):
		count = (n + 1) * (n + 2)
		count = count // 2
		return count


class Solution:

	def numberOfWays(self, n):
		return int((n + 2) * (n + 1) // 2)


class Solution:

	def numberOfWays(self, N):
		ans = (N + 2) * (N + 1) // 2
		return ans