At the annual meeting of Board of Directors of Acme Inc.  If everyone attending shakes hands exactly one time with every other attendee, how many handshakes are there?

Example 

$n=3$  

There are $3$ attendees, ${p1}$, $p2$ and $p3$.  ${p1}$ shakes hands with $p2$ and $p3$, and $p2$ shakes hands with $p3$.  Now they have all shaken hands after $3$ handshakes.  

Function Description  

Complete the handshakes function in the editor below.  

handshakes has the following parameter:  

int n:  the number of attendees  

Returns  

int:  the number of handshakes  

Input Format 

The first line contains the number of test cases ${t}}$. 

Each of the following ${t}}$ lines contains an integer, $n$.   

Constraints  

$1\leq t\leq1000$ 

$0<n<10^6$  

Sample Input

2
1
2

Sample Output  

0
1

Explanation

Case 1 : The lonely board member shakes no hands, hence 0. 

Case 2 : There are 2 board members, so 1 handshake takes place.

Source: hackerrank | Difficulty: EASY
Tags: Mathematics


Solutions:
t = int(input())
for i in range(t):
	n = int(input())
	print(int(n * (n - 1) / 2))


n = int(input())
for i in range(n):
	people = int(input())
	handshakes = people * (people - 1) // 2
	print(handshakes)


n = int(input())
for i in range(n):
	k = int(input())
	print(int(k * (k - 1) / 2))


import math
testcase = int(input())
for x in range(testcase):
	x = int(input())
	print(int(x * (x - 1) / 2))


cases = int(input())
i = 0
result = []
while i < cases:
	people = int(input())
	bunch = people
	j = 0
	ans = 0
	while j < people - 1:
		bunch = bunch - 1
		ans += bunch
		j += 1
	result.append(ans)
	i += 1
i = 0
while i < cases:
	print(result[i])
	i += 1


import sys
T = int(sys.stdin.readline())
for t in range(T):
	N = int(sys.stdin.readline())
	print(N * (N - 1) // 2)


for test in range(int(input())):
	n = int(input())
	print(n * (n - 1) // 2)


T = int(input())
while T > 0:
	T -= 1
	N = int(input())
	print(int(N * (N - 1) / 2))


def handshake(x):
	if x == 1:
		print(0)
	else:
		y = x / 2 * (x - 1)
		print(int(y))
x = int(input())
for i in range(0, x):
	y = int(input())
	handshake(y)


for _ in range(0, int(input())):
	n = int(input())
	count = n * (n - 1) // 2 if n > 0 else 0
	print(count)


T = int(input())
for i in range(T):
	n = int(input())
	print(n * (n - 1) // 2)


import sys
factorials = {0: 1}

def factorial(n):
	if n not in factorials:
		max_n = max((x for x in factorials.keys()))
		for i in range(max_n + 1, n + 1):
			factorials[i] = factorials[i - 1] * i
	return factorials[n]

def read_input(fd):
	line_count = int(fd.readline())
	values = []
	for i in range(line_count):
		values.append(int(fd.readline()))
	return values

def combinations(n, k):
	return factorial(n) / factorial(n - k) / 2
values = read_input(sys.stdin)
for value in values:
	if value < 2:
		print(0)
	else:
		print(int(combinations(value, 2)))


T = int(input().strip())
for _ in range(T):
	N = int(input().strip())
	print(int((N - 1) * N / 2))


from sys import stdin
num_ops = int(stdin.readline().rstrip())
for i in range(num_ops):
	j = int(stdin.readline().rstrip())
	print(int(j * (j - 1) / 2))


num_testcases = int(input())
num_members = []
for i_testcase in range(num_testcases):
	num_members.append(int(input()))
for i_testcase in range(num_testcases):
	print(int((num_members[i_testcase] - 1) * num_members[i_testcase] / 2))


T = int(input())
for i in range(T):
	N = int(input())
	print(sum([x for x in range(N)]))


t = input()
for i in range(int(t)):
	a = int(input())
	print(a * (a - 1) // 2)


print('\n'.join([str(n * (n - 1) // 2) for n in map(int, [input() for i in range(int(input()))])]))


import fileinput

def calculateHandshakes(people):
	peopleCounter = people
	handshakeCounter = 0
	while True:
		if peopleCounter == 0:
			break
		handshakeCounter += peopleCounter - 1
		peopleCounter -= 1
	return handshakeCounter
isFirstLine = True
for line in fileinput.input():
	if isFirstLine:
		isFirstLine = False
		continue
	else:
		peopleCount = int(line.rstrip())
		print(calculateHandshakes(peopleCount))


t = int(input())
for i in range(t):
	n = int(input())
	rs = n
	akh = 0
	for j in range(n - 1):
		rs = rs - 1
		akh = akh + rs
	print(akh)


T = int(input())
for i in range(T):
	N = int(input())
	print(N * (N - 1) // 2)


def ans(inp):
	return int(inp * (inp - 1) / 2)
T = int(input())
for i in range(1, T + 1):
	print(ans(int(input())))


T = int(input())
for i in range(T):
	N = int(input())
	print(N * (N - 1) // 2)


T = int(input())
for t in range(0, T):
	N = int(input())
	print(N * (N - 1) // 2)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	print(N * (N - 1) // 2)


T = int(input())
for i in range(T):
	n = int(input())
	print(int(n * (n - 1) / 2))


for i in range(int(input())):
	n = int(input())
	print(n * (n - 1) // 2)


for i in range(int(input())):
	z = int(input())
	if z == 0 or z == 1:
		print(0)
		continue
	print(z * (z - 1) // 2)


def handshake(num):
	if num == 1:
		print(0)
		return
	print(num * (num - 1) // 2)

def main():
	list_nums = []
	for n in range(int(input().strip())):
		list_nums.append(int(input()))
	for num in list_nums:
		handshake(num)
main()


def handshakes(c):
	answer = []
	for x in c:
		if x == 0:
			answer.append(0)
		else:
			answer.append(int(x * (x - 1) / 2))
	return answer
N = input().strip()
N = list(map(int, N.split(' ')))
_n = N[0]
c = []
for i in range(_n):
	b = input().strip()
	b = int(b)
	c.append(b)
d = handshakes(c)
for ans in d:
	print(ans)


for i in range(int(input())):
	n = int(input())
	print(n * (n - 1) // 2)


for n in range(int(input())):
	p = int(input())
	print(int(p * (p - 1) / 2))


import math
T = int(input())
for i in range(T):
	N = int(input())
	print(int((N - 1) * N / 2))


x = int(input())
for i in range(x):
	n = int(input())
	sum = 0
	for j in range(n):
		sum = j + sum
	print(sum)


def chooseTwo(x):
	return x * (x - 1) // 2
import sys
next(sys.stdin)
for line in sys.stdin:
	print(chooseTwo(int(line.strip())))


t = int(input())
for i in range(t):
	n = int(input())
	print(n * (n - 1) // 2)


numtests = int(input())
people = []
for i in range(numtests):
	people.append(int(input()))
for i in range(numtests):
	print(people[i] * (people[i] - 1) // 2)


import math
i = 0
t = input()
t = int(t)
while i < t:
	n = input()
	n = int(n)
	if n == 1:
		print(n - 1)
	else:
		a = math.factorial(n)
		b = math.factorial(n - 2)
		b = b * 2
		c = int(a / b)
		print(c)
	i = i + 1


import sys

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		people = int(sys.stdin.readline())
		print(sum(range(people)))
main()


T = int(input())
for t in range(T):
	n = int(input())
	print(n * (n - 1) // 2)


for i in range(int(input())):
	x = int(input())
	print(int(x * (x - 1) / 2))


lines = int(input())
while lines > 0:
	num = int(input())
	total = 0
	while num > 0:
		total += num - 1
		num -= 1
	print(total)
	lines -= 1


t = int(input())
for num in range(t):
	n = int(input())
	x = n * (n - 1) / 2
	print(int(x))


T = int(input())
for i in range(T):
	n = int(input())
	print(int(n * (n - 1) / 2))


T = int(input())
for _ in range(T):
	N = int(input())
	print(N * (N - 1) // 2)


t = int(input())
for i in range(t):
	n = int(input())
	print(n * (n - 1) // 2)


tests = int(input())
for i in range(tests):
	curr = int(input())
	print(int(curr * (curr - 1) / 2))


t = int(input())
for _ in range(t):
	n = int(input())
	print(n * (n - 1) // 2)


for t in range(int(input())):
	n = int(input())
	if n < 2:
		print(0)
	else:
		print(sum(range(n)))


N = int(input())
for i in range(0, N):
	T = int(input())
	A = 0
	for c in range(0, T):
		A = A + c
	print(A)


T = int(input())
for _ in range(T):
	N = int(input())
	print(int(N * (N - 1) / 2))


import sys

def ntake2(n):
	if n == 0:
		return 0
	return n * (n - 1) // 2
for _ in range(int(sys.stdin.readline())):
	print(ntake2(int(sys.stdin.readline())))


T = int(input())
for i in range(T):
	N = int(input())
	print(N * (N - 1) // 2)


n = int(input())
assert n >= 1
assert n <= 1000
boardMem = []
for i in range(0, n):
	boardMem += [int(input())]
for i in range(0, len(boardMem)):
	key = boardMem[i]
	assert key > 0
	assert key < 1000000
	shakeMem = []
	for j in range(0, key):
		if key == 1:
			print(sum(shakeMem))
			break
		elif key > 0:
			key -= 1
			shakeMem += [key]


t = int(input())
for every_case in range(0, t):
	n = int(input())
	print(int(n * (n - 1) / 2))


def prog():
	for i in range(int(input())):
		number = int(input())
		print(number * (number - 1) // 2)
prog()


for i in range(int(input())):
	n = int(input())
	n = n - 1
	ans = 0
	while n != 0:
		ans += n
		n = n - 1
	print(ans)


def handshake(n):
	total = 0
	for i in range(1, n):
		total += i
	return total
for n in range(int(input())):
	print(handshake(int(input())))


T = int(input())

def calc(n):
	return n * (n - 1) // 2
for i in range(T):
	print(calc(int(input())))


T = int(input())
for i in range(T):
	N = int(input()) - 1
	sum = 0
	while N > 0:
		sum += N
		N -= 1
	print(sum)


import math
numLines = int(input())
INPUT_LINES = numLines
linesIn = []
for line in range(INPUT_LINES):
	linesIn.append(int(input()))
splitInput = linesIn
for num in splitInput:
	if num >= 2:
		print(int(math.factorial(num) / (2 * math.factorial(num - 2))))
	else:
		print(0)


import math
T = int(input())
for i in range(T):
	N = int(input())
	print(int(N * (N - 1) / 2))


from sys import stdin as cin
from math import factorial as f
t = int(cin.readline())
for i in range(t):
	n = int(cin.readline())
	if n == 1:
		print(0)
	else:
		print(int(f(n) / (f(2) * f(n - 2))))


for i in range(int(input())):
	people = int(input())
	shakes = 0
	if people > 1:
		for k in range(people):
			shakes += k
	print(shakes)


T = int(input())
for i in range(T):
	n = int(input())
	x = n - 1
	print(int((x + 1) * x / 2))


for i in range(int(input())):
	total = 0
	for j in range(int(input())):
		total += j
	print(total)


T = int(input())
for i in range(T):
	N = int(input())
	print(N * (N - 1) // 2)


cases = int(input())
data = []
for i in range(cases):
	data.append(int(input()))
for num in data:
	print(int(num * (num - 1) / 2))


def handshakes(count):
	total = 0
	for i in range(count):
		total += i
	return total
t = int(input())
for i in range(t):
	c = int(input())
	print(handshakes(c))


test_cases = int(input(''))
for i in range(0, test_cases):
	number = int(input(''))
	handshakes = int(number * (number - 1) / 2)
	print('{0}'.format(handshakes))


for i in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
	else:
		print(int(n * (n - 1) / 2))


def handshakes(n):
	ans = n * (n - 1) >> 1
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	print(handshakes(n))


numTest = int(input())
numHandshake = 0
for i in range(numTest):
	numPeople = int(input())
	if numPeople == 1:
		print(0)
	elif numPeople == 2:
		print(1)
	else:
		numHandshake = numPeople * (numPeople - 1) // 2
		print(numHandshake)


for case in range(int(input())):
	people = int(input())
	print(people * (people - 1) // 2)


for t in range(int(input())):
	n = int(input())
	print(n * (n - 1) // 2)


from math import factorial
t = int(input())
for i in range(t):
	n = int(input())
	if n < 2:
		print(0)
	else:
		print(int(factorial(n) / (2 * factorial(n - 2))))


for _ in range(int(input())):
	n = int(input())
	print(n * (n - 1) // 2)


cases = int(input())
for i in range(cases):
	j = int(input()) - 1
	print((j ** 2 + j) // 2)


x = int(input())
for y in range(0, x):
	k = int(input())
	m = int(k * (k - 1) / 2)
	print(m)


def tc(n):
	return n * (n - 1) // 2
t = int(input())
for c in range(t):
	print(tc(int(input())))


t = int(input())
for i in range(t):
	n = int(input())
	print(int(n * (n - 1) / 2))


T = int(input())

def getcases(N):
	testcases = []
	for x in range(N):
		temp_test = input()
		testcases.append(temp_test)
	return testcases
testcases = getcases(T)
testcases = map(lambda x: int(x), testcases)
for test in testcases:
	if test > 1:
		print(int(test * (test - 1) / 2))
	else:
		print(0)


for t in range(int(input())):
	n = int(input())
	ans = n * (n - 1) // 2
	print(ans)


testCases = int(input())
while testCases > 0:
	number = int(input()) - 1
	result = 0
	while number > 0:
		result += number
		number -= 1
	print(result)
	testCases -= 1


amount = int(input())
for x in range(amount):
	n = int(input())
	print(int(n * (n - 1) / 2))


import sys

def solve(n):
	return n * (n - 1) / 2
T = int(sys.stdin.readline().strip())
for t in range(T):
	print(int(solve(int(sys.stdin.readline().strip()))))


test = int(input())
for i in range(test):
	n = int(input())
	print(n * (n - 1) // 2)


n = int(input())
for i in range(n):
	p = int(input())
	print(int(p * (p - 1) / 2))


def handshake(nop):
	return nop * (nop - 1) // 2
for t in range(int(input())):
	nop = int(input())
	assert nop > 0 and nop <= 1000000
	print(handshake(nop))


T = int(input())
for i in range(T):
	N = int(input())
	answer = int(N * (N - 1) / 2)
	print(answer)


T = int(input())
for _ in range(T):
	N = int(input())
	print(N * (N - 1) // 2)


n = int(input())
x = []
for i in range(n):
	inp = int(input())
	x.append(inp)
for j in range(len(x)):
	print(int((x[j] - 1) * x[j] / 2))


testCase = eval(input())
for i in range(testCase):
	num = eval(input())
	print(num * (num - 1) // 2)


T = int(input())
while T:
	N = int(input())
	print(int(N * (N - 1) / 2))
	T -= 1


T = int(input())
for _ in range(T):
	n = int(input())
	print(n * (n - 1) // 2)


for i in range(int(input())):
	n = int(input())
	res = n * (n - 1) / 2
	print(int(res))


T = int(input())
for test in range(T):
	members = int(input())
	print(members * (members - 1) // 2)


t = int(input())
for i in range(t):
	n = int(input())
	print(int(n * (n - 1) / 2))