Sum_equals_input:
def getPairsCount(arr, n, sum):
count = 0 # Initialize result
# Consider all possible pairs
# and check their sums
for i in range(0, n):
for j in range(i + 1, n):
if arr[i] + arr[j] == sum:
count += 1
return count
# Driver function
n=int(input())
arr=[int(i) for i in input().split()][:n]
n = len(arr)
sum = int(input())
print(getPairsCount(arr, n, sum))
Array Challenge 4
n=int(input())
l=sorted(map(int,input().split()))
for i in range(n//3):
if not l[i]<l[i+n//3]<l[i+2*(n//3)] or l[i+n//3]%l[i]!=0 or l[i+2*(n//3)]%l[i+(n//3)]:
print(-1)
exit(0)
for i in range(n//3):
print(*l[i::n//3])
Post a Comment