Help me in solving ZCO13001 problem

My issue

n = int(input())

l = list(map(int, input().split(" ")))

strength_diff = 0
for i in range(n):
for j in range(n):
if i != j:
strength_diff += abs(l[i] - l[j])

print(strength_diff//2)

What is the issue in this code…

Sample input is cleared but not other inputs.

My code

# cook your dish here
n = int(input())

l = list(map(int, input().split(" ")))

strength_diff = 0
for i in range(n):
    for j in range(n):
        if i != j:
            strength_diff += abs(l[i] - l[j])

print(strength_diff//2)
            

Problem Link: CodeChef: Practical coding for everyone

O(n^2) time complexity won’t work .
the acceptable time complexity would be O(nlogn).

in for loop line use this ,

for i in range(n):
    for j in range(i,n):
        d=abs(l[i]-l[j])
        strength_diff += d