There are N students in a class, each in possession of a different funny story. 
They want to share funny stories with each other by sending electronic messages. Assume that a sender includes all the funny stories he or she knows at the time the message is sent and that a message may only have one addressee. What is the minimum number of messages they need to send to guarantee that every one of them gets all the funny stories?
 
Example 1:
Input:
2
Output:
2
Explanation:
Person 1 sends a message to 
Person 2, Person 2 sends
message to Person 1.
A total of 2 messages are sent.
 
 
Example 2:
Input:
1
Output:
0
Explanation:
No messages are sent.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function minimumMessages() which takes an integer N and returns the minimum number of messages they need to send to guarantee that every one of them gets all the funny stories.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
 
Constraints:
1<=N<=10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Greedy algorithms

Starter code: #User function Template for python3
class Solution:
    def minimumMessages (ob,N):
        # code here 

Solutions:
class Solution:

	def minimumMessages(ob, N):
		if N == 1:
			return 0
		if N == 2:
			return 2
		if N > 2:
			i = 0
			a = 2
			while a <= N:
				a = a + 1
				i = i + 2
			return i


class Solution:

	def minimumMessages(ob, N):
		return N * 2 - 2


import math

class Solution:

	def minimumMessages(ob, N):
		return (N - 1) * 2


class Solution:

	def minimumMessages(ob, N):
		return N - 1 + N - 1


class Solution:

	def minimumMessages(ob, N):
		if N == 1:
			return 0
		else:
			return 2 * (N - 1)


class Solution:

	def minimumMessages(ob, n):
		return 2 * n - 2


class Solution:

	def minimumMessages(ob, N):
		return 2 * N - 2
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.minimumMessages(N))


class Solution:

	def minimumMessages(ob, N):
		if N <= 1:
			return 0
		elif N % 2 == 0:
			return N * 2 - 2
		else:
			return N * 2 - 2
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.minimumMessages(N))


class Solution:

	def minimumMessages(ob, N):
		a = (N - 1) * 2
		return a


class Solution:

	def minimumMessages(ob, n):
		if n == 1:
			return 0
		return (n - 1) * 2


class Solution:

	def minimumMessages(self, N):
		return (N - 1) * 2