Edit the given code to optimize its performance.
for i in range(N):
    for j in range(N-1):
        sum += A[i][j]
sum = 0
for j in range(N-1):
    for i in range(N):
        sum += A[i][j]
<s>[INST] Edit the given code to optimize its performance. [/INST] Input:
for i in range(N):
    for j in range(N-1):
        sum += A[i][j] </s>