Given n balls . All of them are initially  uncolored . You have to color the balls with two colors RED and BLUE such that there can be atmost 2 positions where a RED ball is touching BLUE ball or vice versa. You have to color all the balls.Find the number of ways in which balls can be colored.
Example 1:
Input: n = 1
Output: 2
Explanation: Possible ways to color are {{R},{B}}. 
So the answer is 2 .
Example 2:
Input: n = 2
Output: 4
Explanation: Possible ways to color are 
{{RB},{BR},{RR},{BB}}.So the answer is 4.
Your Task:  
You dont need to read input or print anything. Complete the function noOfWays() which takes n as input parameter and returns  the number of ways in which balls can be colored.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
1<= n <=10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:

    def noOfWays (self, n):

        # code here 

Solutions:
class Solution:

	def noOfWays(self, n):
		return n ** 2 - n + 2


class Solution:

	def noOfWays(self, n):
		if n == 1:
			return 2
		else:
			return n * n - (n - 2)


class Solution:

	def noOfWays(self, n):
		a = n * (n - 1)
		return a + 2


class Solution:

	def noOfWays(self, n):
		ans = n * (n - 1)
		return ans + 2


class Solution:

	def noOfWays(self, n):
		if n <= 3:
			return 2 ** n
		p = n - 2
		return p * p + 3 * p + 4


class Solution:

	def noOfWays(self, n):
		if n == 1:
			return 2
		if n == 2:
			return 4
		return (n - 1) * (n - 2) + (n - 1) * 2 + 2


import math

class Solution:

	def noOfWays(self, n):
		if n == 1:
			return 2
		return 2 * n + (n - 1) * (n - 2)


class Solution:

	def noOfWays(self, n):
		r = 0
		if n >= 1:
			r += 1
		if n >= 2:
			r += n - 1
		if n >= 3:
			for ml in range(1, n - 1):
				r += ml
		return r * 2


class Solution:

	def noOfWays(self, n):
		if n <= 3:
			return pow(2, n)
		else:
			return pow(n, 2) - (n - 2)


class Solution:

	def noOfWays(self, n):
		total_ways = 2 + 2 * (n - 1) + (n - 1) * (n - 2)
		if 0 == n:
			return 0
		return total_ways