ZhenlongDai/ACPR huggingface dataset:
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K =map(int,input().split())
a = list(map(int,input().split()))

count = 0
dis = 0
for i in a:
    for k in a:
        if k < i:
            count +=1
        count %= (10 ** 9 + 7)
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
        dis %= (10**9+7)
a = dis * K % (10**9+7)
b = count*K% (10**9+7)*(K-1)% (10**9+7)
ans = (a+b)% (10**9+7)
print(ans)


Failing test case input:
3 10
0 6 -1

Expected output:
155


Actual output:
290


Fixed submission (verdict: Accepted):
N,K =map(int,input().split())
a = list(map(int,input().split()))

count = 0
dis = 0
mod = (10**9+7)
for i in a:
    for k in a:
        if k < i:
            count +=1
        count %= mod
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
        dis %= mod
print(int((K * dis + K * (K - 1) * count

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m = map(int, input().split())
A = list(map(int, input().split()))
c1 = 0
c2 = 0
for i in range(n-1):
  for k in range(n-1-i):
    if A[i] > A[k+1+i]:
      c1 += 1
for i in range(n):
  for k in range(n):
    if A[i] > A[k]:
      c2 += 1
c3 = (m * (m - 1) / 2)%(10**9+7)
print(int((c3*c2+c1*m)%(10**9+7)))

Failing test case input:
10 1051516890
10 9 10 7 5 5 0 4 4 0

Expected output:
818429624


Actual output:
818430731


Fixed submission (verdict: Accepted):
n,m = map(int, input().split())
A = list(map(int, input().split()))
c1 = 0
c2 = 0
for i in range(n-1):
  for k in range(n-1-i):
    if A[i] > A[k+1+i]:
      c1 += 1
for i in range(n):
  for k in range(n):
    if A[i] > A[k]:
      c2 += 1
c3 = (m * (m - 1) 
c4 = (c3*c2)%(10**9+7)
c5 = (c1*m)%(10**9+7)
print(int((c4+c5)%(10**9+7)))

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

numc = 0
numf = 0

for i in range(0, N):
    for j in range(0,i):
        if A[j] > A[i]:
            numc += 1
        if A[i] > A[j]:
            numf += 1
numbers = numc*K*(K+1)+ numf*K*(K-1)
 
ans = numbers % (10**9 + 7) / 2
print(ans)

Failing test case input:
10 918571889
10 9 10 7 7 3 0 11 4 0

Expected output:
551061978


Actual output:
51061974.5


Fixed submission (verdict: Accepted):
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
numc = 0
numf = 0

for i in range(0, N):
    for j in range(0,i):
        if A[j] > A[i]:
            numc += 1
        if A[i] > A[j]:
            numf += 1
numbers = numc*K*(K+1) + numf*K*(K-1)
 
ans = int(numbers
print(ans)
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(map(int, input().split()))
sum1 = 0
sum2 = 0
for i in range(n-1):
    for j in range(i+1, n):
        if a[i]>a[j]:
            sum1+=1
        elif a[i]<a[j]:
            sum2+=1
ans = sum1*k*k+(sum2-sum1)*k*(k-1)/2
print(ans%1e9+7)

Failing test case input:
10 727991293
-1 9 20 7 7 3 0 6 4 1

Expected output:
524216575


Actual output:
139800583.0


Fixed submission (verdict: Accepted):
INF = 1000000007

n, k = map(int, input().split())
a = list(map(int, input().split()))
sum1 = 0
sum2 = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue    
        if a[i]>a[j]:
            if i <j:
                sum1+=1
            else:
                sum2 +=1
ans = sum1+sum2
x = sum1*k
y = ans *((k*(k-1))
print(int((x+y)%INF))

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int,input().split())
a = list(map(int,input().split()))
inner = int(0)
outer = int(0)
for i in range(0,n):
    for j in range(0,n):
        if a[i] > a[j]:
            outer += 1
            if i < j:
                inner += 1

b = (int(inner * int(k)) + int(outer * int(k) * int(k-1) / 2))
print(int(b%int(1000000007)))

Failing test case input:
10 727991293
10 9 10 7 5 3 0 4 4 0

Expected output:
102125547


Actual output:
102126319


Fixed submission (verdict: Accepted):
from decimal import *
n, k = map(int,input().split())
a = list(map(int,input().split()))
inner = 0
outer = 0
for i in range(0,n):
    for j in range(0,n):
        if a[i] > a[j]:
            outer += 1
            if i < j:
                inner += 1

print((Decimal(((inner) * (k)) + Decimal((outer) * Decimal((k) * (k-1)) / 2))%(1000000007)))

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

prime = 10**9+7

def sowa(num):
  return int((1+num)*num/2)

n,k = map(int, input().split())
a = list(map(int, input().split()))

tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i+1,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = (sum(tento1) *k %prime) + (sum(tento2) *(sowa(k-1) %prime) %prime)
print(int(ret%prime))


Failing test case input:
10 727991293
10 9 10 7 5 3 0 4 4 1

Expected output:
225136212


Actual output:
225135954


Fixed submission (verdict: Accepted):

prime = 10**9+7

def sowa(num):
  return int((1+num)*num

n,k = map(int, input().split())
a = list(map(int, input().split()))

tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i+1,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = (sum(tento1) *k %prime) + (sum(tento2) *(sowa(k-1) %prime) %prime)
print(int(ret%prime))
Problem: p02928
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,K=map(int,input().split())
A=list(map(int,input().split()))
s=0
for i in range(1,n):
    k=i
    while A[k]<A[k-1]:
        A[k],A[k-1]=A[k-1],A[k]
        k-=1
        s+=1
        if k==0:
            break
j=0
l=1
S=0
while j<n-1:
    if A[j]==A[j+1]:
        l+=1
        j+=1
    else:
        S=S+l*(n-1-j)
        l=1
        j+=1
B=s*K+(S*K*(K-1))/2
print(int(B)%1000000007)

Failing test case input:
10 727991293
0 9 10 7 5 3 0 4 4 0

Expected output:
155184580


Actual output:
155182885


Fixed submission (verdict: Accepted):
n,K=map(int,input().split())
A=list(map(int,input().split()))
s=0
for i in range(1,n):
    k=i
    while A[k]<A[k-1]:
        A[k],A[k-1]=A[k-1],A[k]
        k-=1
        s+=1
        if k==0:
            break
j=0
l=1
S=0
while j<n-1:
    if A[j]==A[j+1]:
        l+=1
        j+=1
    else:
        S=S+l*(n-1-j)
        l=1
        j+=1
B=int(s*K+(S*K*(K-1))
C=int(s*K)%1000000007
D=(K*(K-1)
print((C+S*D)%1000000007)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(map(int, input().split()))

const = pow(10, 9) + 7

c = 0

for i in range(n):
    for j in range(n - i - 1):
        
        if a[i] > a[n - j - 1]:
            c += 1

print("c", c)

p = len(set(a))

q = p * (p - 1) / 2

print("q", q)

ans = 0 + c * k + q * k * (k - 1) / 2

print(int(ans) % const)


Failing test case input:
10 1652783124
20 9 1 7 2 4 0 4 0 2

Expected output:
185071863


Actual output:
c 32
q 21.0
37064172


Fixed submission (verdict: Accepted):
import copy

n, k = map(int, input().split())
a = list(map(int, input().split()))

const = 1000000007
c = 0
d = 0

for i in range(n):
    for j in range(n - i - 1):
        if a[i] > a[n - j - 1]:
            c += 1

b = copy.deepcopy(a)

for i in range(n):
    for j in range(n):
        if b[i] > a[j]:
            d += 1





ans = c * k + d * (k * (k - 1) 

print(int(ans) % const)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
A=list(map(int,input().split()))

cnt=0
a=0

if n==1:print(0)
else:
  for i in range(n-1):
    for j in range(i+1,n):
      if A[i]>A[j]:
        cnt+=1

  for i in range(n):
    for j in range(n):
      if A[i]>A[j]:
        a+=1

      
print((cnt*k+a*k*(k-1)/2)%(10**9+7))


Failing test case input:
10 1468376359
13 5 8 7 3 6 3 4 4 1

Expected output:
232731606


Actual output:
232734090.0


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
A=list(map(int,input().split()))

cnt=0
a=0

if n==1:print(0)
else:
  for i in range(n-1):
    for j in range(i+1,n):
      if A[i]>A[j]:
        cnt+=1

  for i in range(n):
    for j in range(n):
      if A[i]>A[j]:
        a+=1

      
  print(int(cnt*k+a*(k*(k-1)
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K =map(int,input().split())
a = list(map(int,input().split()))

count = 0
dis = 0
for i in a:
    for k in a:
        if k < i:
            count +=1
    count %= (10 ** 9 + 7)
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
a = dis * K % (10**9+7)
b = round(count*K/2% (10**9+7)*(K-1))
ans = (a+b)% (10**9+7)
print(ans)

Failing test case input:
10 1051516890
10 15 10 1 5 4 0 8 8 0

Expected output:
39781881


Actual output:
39781873


Fixed submission (verdict: Accepted):
N,K =map(int,input().split())
a = list(map(int,input().split()))

count = 0
dis = 0
mod = (10**9+7)
for i in a:
    for k in a:
        if k < i:
            count +=1
        count %= mod
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
        dis %= mod
print(int((K * dis + K * (K - 1) * count

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
A = list(map(int, input().split()))

tentosu_f = 0
tentosu_l = 0
mod = 10**9 + 7
ans = 0

for i in range(n):
    for j in range(i, n):
        if A[i] > A[j]:
            tentosu_f += 1
          
for i in range(n):
    for j in range(n):
        if A[i] > A[j]:
            tentosu_l += 1
            
ans = (tentosu_f * k) % mod + (tentosu_l * k *(k-1) / 2) % mod
print(int(ans % mod))

Failing test case input:
10 1652783124
20 9 8 7 5 5 0 4 1 2

Expected output:
611908778


Actual output:
611912706


Fixed submission (verdict: Accepted):
mod = (10 ** 9) + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))

ten_f = 0
ten_l = 0

for i in range(N):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            ten_f += 1

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            ten_l += 1

ans = (ten_f * (K)) + ((K * ((K - 1)) 
print(ans % mod)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())

a = list(map(int,input().split()))

MOD = pow(10,9) + 7

p = 0

c = 0
d = 0
for i in range(n):
  for j in range(i+1,n):
    if(a[i] > a[j]):
      c += 1
      d += 1
    elif(a[i] < a[j]):
      d += 1


ans = int(c * k % MOD) + int( int((k *(k-1)/2) % MOD) * d)
ans = int(ans%MOD)

print(ans)

Failing test case input:
10 918571889
19 9 10 7 5 6 0 6 4 0

Expected output:
280511408


Actual output:
280511752


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**9)

n,k = map(int,input().split())

a = list(map(int,input().split()))

MOD = pow(10,9) + 7

p = 0

c = 0
d = 0
for i in range(n):
  for j in range(i+1,n):
    if(a[i] > a[j]):
      c += 1
      d += 1
    elif(a[i] < a[j]):
      d += 1


ans = int(c * k % MOD) + int( (k *(k-1)
ans = int(ans%MOD)

print(ans)
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
a = list(map(int,input().split()))
counta = 0
countb = 0
for i in range(n):
    for j in range(n-i-1):
        if a[i]>a[j+i+1]:
            counta += 1
b = sorted(a)[::-1]
for i in range(n):
    for j in range(n-i-1):
        if b[i]>b[j+i+1]:
            countb += 1
print(int((counta*k+countb*int((k*(k-1))/2))%(10**9+7)))


Failing test case input:
10 918571889
10 9 10 7 5 3 0 6 4 0

Expected output:
361939526


Actual output:
361939870


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
a = list(map(int,input().split()))
counta = 0
countb = 0
for i in range(n):
    for j in range(n-i-1):
        if a[i]>a[j+i+1]:
            counta += 1
b = sorted(a)[::-1]
for i in range(n):
    for j in range(n-i-1):
        if b[i]>b[j+i+1]:
            countb += 1
print((counta*k+countb*((k*(k-1))

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = list(map(int, input().split()))

x = 0
for l in range(N - 1):
  for r in range(l + 1, N):
    if A[l] > A[r]:
      x += 1

      
AA = A + A
y = 0
for l in range(2 * N - 1):
  for r in range(l + 1, 2 * N):
    if AA[l] > AA[r]:
      y += 1
y -= 2 * x



print(int((K * x  % (10 ** 9 + 7) + K * (K - 1) * y / 2  % (10 ** 9 + 7)) % (10 ** 9 + 7)))

Failing test case input:
10 1468376359
13 9 8 7 6 6 3 4 4 1

Expected output:
42989697


Actual output:
42989194


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = list(map(int, input().split()))

x = 0
for l in range(N - 1):
  for r in range(l + 1, N):
    if A[l] > A[r]:
      x += 1

      
AA = A + A
y = 0
for l in range(2 * N - 1):
  for r in range(l + 1, 2 * N):
    if AA[l] > AA[r]:
      y += 1
y -= 2 * x

  
print(int((K * x + K * (K - 1) * y

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i):
            if a[i] > a[j + i]:
                t2 += 1

    
    
    count = (t1*k*(k-1)/2%mod + t2*k)%mod
    print(int(count))


if __name__ == '__main__':
    n, k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)


Failing test case input:
10 1087786498
13 2 8 7 6 6 3 4 4 1

Expected output:
982508952


Actual output:
982507117


Fixed submission (verdict: Accepted):
import numpy as np
import random
import sys
from functools import lru_cache

def main(n,k,a):

    mod = 10**9 + 7
    c1,c2 = 0,0
    for i in range(len(a)):
        for j in range(len(a)):
            
            if a[i] > a[j]:
                
                if i < j:
                    c1 += 1

                elif i > j:
                    c2 += 1
        
        count = (c1*k*(k+1)

    print(count)


if __name__ == '__main__':
    n,k = map(int,input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

prime = 10**9+7

def sowa(num):
  return int((1+num)*num/2)

n,k = map(int, input().split())
a = list(map(int, input().split()))


tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i+1,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = ((sum(tento1)%prime) *(k%prime) %prime) + ((sum(tento2)%prime) *(sowa(k-1) %prime)%prime)
print(ret%prime)


Failing test case input:
10 918571889
10 9 10 7 5 3 0 6 4 0

Expected output:
361939526


Actual output:
361939870


Fixed submission (verdict: Accepted):

prime = 10**9+7

def sowa(num):
  return int((1+num)*num

n,k = map(int, input().split())
a = list(map(int, input().split()))

tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i+1,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = (sum(tento1) *k %prime) + (sum(tento2) *(sowa(k-1) %prime) %prime)
print(int(ret%prime))

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split(' '))
a_list = list(map(int, input().split(' ')))

bl = 0
cl = 0
for i in range(n):
  bl += len([j for j in a_list if j > a_list[i]])
  cl += len([k for k in a_list[i:] if k < a_list[i]])
  
cnt = ((bl * k * (k - 1) / 2) % 1000000007) + ((cl * k) % 1000000007)
print(int(cnt % 1000000007))
  

Failing test case input:
10 727991293
0 9 10 7 5 3 0 4 4 1

Expected output:
401205910


Actual output:
401206164


Fixed submission (verdict: Accepted):
n, k = map(int, input().split(' '))
a_list = list(map(int, input().split(' ')))
MOD = 10 ** 9 + 7

cnt = 0
cnt_ = 0
for i in range(n):
  cnt_ += len(list(k for k in a_list if k > a_list[i]))
  for j in range(i+1,n):
    if a_list[i] > a_list[j]:
      cnt += 1

ans = (cnt_) * (k * (k-1) 

print(ans % MOD)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K =map(int,input().split())
a = list(map(int,input().split()))

count = 0
dis = 0
for i in a:
    for k in a:
        if k < i:
            count +=1
    count %= (10 ** 9 + 7)
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
a = dis * K % (10**9+7)
b = round(count*K*(K-1)/2 % (10**9+7))
ans = (a+b)% (10**9+7)
print(ans)

Failing test case input:
10 1468376359
13 9 8 7 6 6 3 4 4 1

Expected output:
42989697


Actual output:
42989194


Fixed submission (verdict: Accepted):
N,K =map(int,input().split())
a = list(map(int,input().split()))

count = 0
dis = 0
mod = (10**9+7)
for i in a:
    for k in a:
        if k < i:
            count +=1
        count %= mod
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
        dis %= mod
print(int((K * dis + K * (K - 1) * count
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())

A = list(map(int, input().split()))

x = 0
for i in range(N):
    for j in range(N-1, i, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            x += 1
M = 10**9 + 7
if x != 0:
    ans = ( ((K*x)%M) + ( ((1/4)*N*(N-1) % M) * (K*(K-1)%M) ) % M ) % (M)
    print(int(ans))
else:
    print(0)

Failing test case input:
10 1468376359
10 1 8 7 9 0 3 4 4 2

Expected output:
976881877


Actual output:
31290228


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())

A = list(map(int, input().split()))
AA = []
for i in range(2):
    AA.extend(A)

x = 0
for i in range(N):
    for j in range(i+1, N):
        if A[j] < A[i]:
            x += 1
M = 10**9 + 7

y = 0
NN = N*2
for i in range(NN):
    for j in range(i+1, NN):
        if AA[j] < AA[i]:
            y += 1

a = (K*x)
b = (y - 2*x) * (K*(K-1)
ans = ((a+b)  % M)
print(int(ans))

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K =map(int,input().split())
a = list(map(int,input().split()))

count = 0
dis = 0
mod = (10**9+7)
for i in a:
    for k in a:
        if k < i:
            count +=1
        count %= mod
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
        dis %= mod
a = dis * K % mod
b = count*K*(K-1) % mod 
ans = (a+b)% mod
while ans>=10**9+7:
    ans%=10**9+7
print(ans)

Failing test case input:
3 9
0 6 0

Expected output:
81


Actual output:
153


Fixed submission (verdict: Accepted):
N,K =map(int,input().split())
a = list(map(int,input().split()))

count = 0
dis = 0
mod = (10**9+7)
for i in a:
    for k in a:
        if k < i:
            count +=1
        count %= mod
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
        dis %= mod
print(int((K * dis + K * (K - 1) * count

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = input().split()
N = int(n)
K = int(k)
A = [int(a) for a in input().split()]
countAList = []
countBList = []
for j in range(N):
    countA = 0
    countB = 0
    for i in range(N):
        if A[i] < A[j]:
            countB += 1
            if i > j:
                countA += 1
    countAList.append(countA)
    countBList.append(countB)
result = 0

for a, b in zip(countAList, countBList):
    result += K * a + int(b * K * (K - 1) / 2)
    result %= 10 ** 9 + 7
print(result % (10 ** 9 + 7))


Failing test case input:
10 1051516890
10 9 10 7 5 5 0 8 4 0

Expected output:
297366296


Actual output:
297366918


Fixed submission (verdict: Accepted):
n, k = input().split()
N = int(n)
K = int(k)
A = [int(a) for a in input().split()]
countAList = []
countBList = []
for j in range(N):
    countA = 0
    countB = 0
    for i in range(N):
        if A[i] < A[j]:
            countB += 1
            if i > j:
                countA += 1
    countAList.append(countA)
    countBList.append(countB)
result = 0

for a, b in zip(countAList, countBList):
    result += int(K * a) + int(b * K * (K - 1) 
    result %= 10 ** 9 + 7
print(result)
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 1000000007
ans = 0
fflag = 0
bflag = 0

for i in range(n):
    for j in range(n):
        if i > j:
            if a[i] > a[j]:
                fflag += 1
        if i < j:
            if a[i] > a[j]:
                bflag += 1

ans = (int((fflag+bflag)*k*(k+1)/2) - fflag)%mod
print(ans)

Failing test case input:
10 872422839
13 9 8 7 3 5 3 4 4 1

Expected output:
35803540


Actual output:
397918618


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
fflag = 0
bflag = 0

for i in range(n):
    for j in range(n):
        if i > j:
            if a[i] > a[j]:
                fflag += 1
        elif i < j:
            if a[i] > a[j]:
                bflag += 1

ans = ((fflag+bflag)*k*(k+1)
print(ans)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())

a = list(map(int,input().split()))

Q = pow(10,9) + 7

p = 0

c = 0
d = 0
for i in range(n):
    for j in range(i+1,n):
      if(a[i] > a[j]):
         c += 1
         d += 1
      elif(a[i] < a[j]):
         d += 1


ans = int(c * k % Q) + ( int(k *(k-1)/2) % Q) * d
ans = int(ans%Q)

print(ans)

Failing test case input:
10 727991293
0 9 10 7 5 3 0 4 4 1

Expected output:
401205910


Actual output:
401205652


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**9)

n,k = map(int,input().split())

a = list(map(int,input().split()))

MOD = pow(10,9) + 7

p = 0

c = 0
d = 0
for i in range(n):
  for j in range(i+1,n):
    if(a[i] > a[j]):
      c += 1
      d += 1
    elif(a[i] < a[j]):
      d += 1


ans = int(c * k % MOD) + int( (k *(k-1)
ans = int(ans%MOD)

print(ans)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

prime = 10**9+7

def sowa(num):
  return int((1+num)*num/2)

n,k = map(int, input().split())
a = list(map(int, input().split()))


tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = ((sum(tento1)%prime) *(k%prime) %prime) + ((sum(tento2)%prime) *(sowa(k-1) %prime)%prime)
print(ret%prime)


Failing test case input:
10 727991293
0 9 10 7 5 3 0 4 4 0

Expected output:
155184580


Actual output:
155184334


Fixed submission (verdict: Accepted):

prime = 10**9+7

def sowa(num):
  return int((1+num)*num

n,k = map(int, input().split())
a = list(map(int, input().split()))

tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i+1,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = (sum(tento1) *k %prime) + (sum(tento2) *(sowa(k-1) %prime) %prime)
print(int(ret%prime))
Problem: p02928
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
a_array = [int(i) for i in input().split()]

countR=0
countA=0

for i in range(N):
    for j in range(i+1, N):
        if a_array[i] > a_array[j]:
            countR += 1

    for j in range(N):
        if a_array[i] > a_array[j]:
            countA += 1

print(int(countR * K + countA * K * (K-1) / 2)%(10**9+7))

Failing test case input:
10 918571889
10 9 10 7 7 3 0 11 4 0

Expected output:
551061978


Actual output:
551063178


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
a_array = [int(i) for i in input().split()]

countR=0
countA=0

for i in range(N):
    for j in range(i+1, N):
        if a_array[i] > a_array[j]:
            countR += 1

    for j in range(N):
        if a_array[i] > a_array[j]:
            countA += 1

print(int((countR * K + countA * K * (K-1)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


list1 = input().split()
list2 = input().split()
N = int(list1[0])
K = int(list1[1])
a = [int(i) for i in list2]

cnt_l = 0
cnt_r = 0
for j in range(len(a)):
    for i in range(j):
        if a[i] > a[j]:
            cnt_l = cnt_l + 1
    for i in range(j, len(a)):
        if a[i] > a[j]:
            cnt_r = cnt_r + 1

res = ((cnt_l * K * (K+1) / 2) + (cnt_r * (K-1) * K /2)) % (10**9 + 7)

print(int(res))

Failing test case input:
10 1468376359
13 2 8 7 6 6 3 4 4 1

Expected output:
764355261


Actual output:
764359064


Fixed submission (verdict: Accepted):


list1 = input().split()
list2 = input().split()
N = int(list1[0])
K = int(list1[1])
a = [int(i) for i in list2]

cnt_l = 0
cnt_r = 0
for j in range(len(a)):
    for i in range(j):
        if a[i] > a[j]:
            cnt_l = cnt_l + 1
    for i in range(j, len(a)):
        if a[i] > a[j]:
            cnt_r = cnt_r + 1

res = ((cnt_l * K * (K+1) 

print(int(res))

Problem: p02928
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

ans = 0

for n in range(N):
    for i in range(N):
        if A[n] > A[i]:
            if n<i:ans += K*(K+1)/2
            else:ans+=K*(K-1)/2
            
print(int(ans%(10**9+7)))


Failing test case input:
10 998244353
20 9 8 7 8 5 0 4 0 2

Expected output:
869618066


Actual output:
869618027


Fixed submission (verdict: Accepted):
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

ans = 0
mod = 10**9+7

for n in range(N):
    for i in range(N):
        if A[n] > A[i]:
            if n<i:ans += (K*(K+1)
            else:ans+=(K*(K-1)

print(ans%mod)
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K =map(int,input().split())
a = list(map(int,input().split()))

count = 0
dis = 0
for i in a:
    for k in a:
        if k < i:
            count +=1
        count %= (10 ** 9 + 7)
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
        dis %= (10**9+7)
a = dis * K % (10**9+7)
b = count*K% (10**9+7)
b = b *(K-1)% (10**9+7)
ans = (a+b)% (10**9+7)
print(ans)


Failing test case input:
10 727991293
10 9 10 7 5 3 0 4 4 0

Expected output:
102125547


Actual output:
268573442


Fixed submission (verdict: Accepted):
N,K =map(int,input().split())
a = list(map(int,input().split()))

count = 0
dis = 0
mod = (10**9+7)
for i in a:
    for k in a:
        if k < i:
            count +=1
        count %= mod
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
        dis %= mod
print(int((K * dis + K * (K - 1) * count

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 1000000007
ans = 0
fflag = 0
bflag = 0

for i in range(n):
    for j in range(n):
        if i > j:
            if a[i] > a[j]:
                fflag += 1
        if i < j:
            if a[i] > a[j]:
                bflag += 1

ans = int(((fflag+bflag)*(k*(k+1))%mod)/2) - fflag
print(ans)

Failing test case input:
10 918571889
19 9 10 12 5 6 0 6 4 0

Expected output:
443367644


Actual output:
373370814


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
fflag = 0
bflag = 0

for i in range(n):
    for j in range(n):
        if i > j:
            if a[i] > a[j]:
                fflag += 1
        elif i < j:
            if a[i] > a[j]:
                bflag += 1

ans = ((fflag+bflag)*k*(k+1)
print(ans)

Problem: p02928
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

import math
from fractions import Fraction
import itertools

input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
p=[0]*n
q=[0]*n
ans=0
mod=10**9+7
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            if i>j:
                p[i]+=1
            elif i<j:
                q[i]+=1
                
for i in range(n):
    ans+=(k*q[i]+((p[i]+q[i])*k*(k-1)/2)%mod)%mod
    ans=ans%mod
print(int(ans%mod))

Failing test case input:
10 1468376359
10 9 8 7 5 6 3 4 4 1

Expected output:
597398059


Actual output:
597398607


Fixed submission (verdict: Accepted):
import sys

import math
from fractions import Fraction
import itertools

input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
p=[0]*n
q=[0]*n
ans=0
mod=10**9+7
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            if i>j:
                p[i]+=1
            elif i<j:
                q[i]+=1
                
for i in range(n):
    ans+=(k*q[i]+((p[i]+q[i])*k*(k-1)
    ans=ans%mod
print(int(ans%mod))
Problem: p02928
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K = map(int,input().split())
S = list(map(int,input().split()))
divisor = 10**9 + 7

m = []
for i in range(N-1):
  cnt = sum([1 for j in range(i,N) if S[i] > S[j]])
  m.append(cnt)


f = sum(m)
import decimal as d
f = d.Decimal(f)
ans = f*K*(K+1)/2 % divisor
print(ans)
  

Failing test case input:
3 6
0 3 1

Expected output:
51


Actual output:
21


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
S = list(map(int,input().split()))
divisor = 10**9 + 7

m = []
for i in range(N-1):
  cnt = sum([1 for j in range(i,N) if S[i] > S[j]])
  m.append(cnt)

f = sum(m) 

m = []
for i in range(N):
  cnt = sum([1 for j in range(0,N) if S[i] > S[j]])
  m.append(cnt)

g = sum(m) 
  

import decimal as d
f = d.Decimal(f)
g = d.Decimal(g)
ans = (f*K + g*K*(K-1)/2) % divisor
print(ans)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

cnt_1 = 0
for i in range(len(A)):
  for j in range(i+1, len(A)):
    if A[i] > A[j]:
      cnt_1 += 1

cnt_2 = 0
for i in range(len(A)):
  for j in range(len(A)):
    if A[i] > A[j]:
      cnt_2 += 1

cnt = cnt_1 * K + cnt_2 * int((K-1)*K/2)

print(cnt % 1000000007)


Failing test case input:
10 1087786498
13 2 8 7 6 12 3 2 4 0

Expected output:
824903118


Actual output:
824903074


Fixed submission (verdict: Accepted):
import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

cnt_1 = 0
for i in range(len(A)):
  for j in range(i+1, len(A)):
    if A[i] > A[j]:
      cnt_1 += 1

cnt_2 = 0
for i in range(len(A)):
  for j in range(len(A)):
    if A[i] > A[j]:
      cnt_2 += 1

cnt = cnt_1 * K + cnt_2 * int((K-1)*K

print(cnt % (10**9 + 7))

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N,K=map(int,input().split())

A=list(map(int,input().split()))

A=A+A

count=[0]*2*N

for i in range(N):
    for j in range(i,2*N):
        if A[i]>A[j]:
            count[j]+=1
a=(sum(count[0:N]))
b=(sum(count[N:2*N]))
c=(int((a*K+b*K*(K-1)/2)))
print(c%(10**9+7))


Failing test case input:
10 998244353
20 9 8 7 1 5 0 4 1 2

Expected output:
34480265


Actual output:
34480228


Fixed submission (verdict: Accepted):


N,K=map(int,input().split())

A=list(map(int,input().split()))

A=A+A

count=[0]*2*N

for i in range(N):
    for j in range(i,2*N):
        if A[i]>A[j]:
            count[j]+=1
a=(sum(count[0:N]))
b=(sum(count[N:2*N]))
c=(int((a*K+b*K*(K-1)
print(c%(10**9+7))
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]
mod = int(10**9 + 7)
n, k = na()
a = na()


ans = 0


for i, ai in enumerate(a):
    cr = sum(x <ai for x in a[i+1:])
    cl = sum(x <ai for x in a[:i])
    ans += int(-cl +(cl+cr)*(k+1)*k/2) % mod
    ans = ans % mod
print(ans)


Failing test case input:
3 9
0 6 0

Expected output:
81


Actual output:
89


Fixed submission (verdict: Accepted):
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, k = na()
a = na()
cl = 0
cr = 0
for i in range(n-1):
    for j in range(i+1,n):
        if a[i] < a[j]:
            cl += 1
        if a[i] > a[j]:
            cr += 1
ans = (cr*k %mod + (cl+cr) * k*(k-1)
print(ans)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    def c(x,y):
        if x > y:
            return 1
        else:
            return 0
    n,k = map(int,input().split())
    x = 1000000007
    kk = int(k*(k-1)/2)%x
    a = list(map(int,input().split()))
    c1 = []
    c2 = []
    for i in range(n):
        l = [c(a[i],p) for p in a]
        c1.append(sum(l))
        c2.append(sum(l[i:]))
    ans = ((sum(c1)%x)*kk)%x+((sum(c2)%x)*k)%x
    print(ans%x)
    
if __name__ == '__main__':
    main()

Failing test case input:
10 1051516890
10 9 10 7 5 5 0 4 4 0

Expected output:
818429624


Actual output:
818430731


Fixed submission (verdict: Accepted):
def main():
    def c(x,y):
        if x > y:
            return 1
        else:
            return 0
    n,k = map(int,input().split())
    x = 1000000007
    kk = int(k*(k-1)
    a = list(map(int,input().split()))
    c1 = []
    c2 = []
    for i in range(n):
        l = [c(a[i],p) for p in a]
        c1.append(sum(l))
        c2.append(sum(l[i:]))
    ans = ((sum(c1)%x)*kk)%x+((sum(c2)%x)*k)%x
    print(ans%x)
    
if __name__ == '__main__':
    main()
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * len(A)
C = [0] * len(A)
mod = 10 ** 9 + 7
counter = 0
for i in range(N):
    B[i] = sum([A[i] > A[j] for j in range(0, N)])  
    C[i] = sum([A[i] > A[j] for j in range(i, N)])  

for i in range(N):
    c = (C[i] * K)%mod + ((K - 1) * K * B[i] / 2)%mod

    counter = (counter + c) % mod
print(counter)


Failing test case input:
10 872422839
9 9 8 7 3 5 3 4 4 0

Expected output:
259107781


Actual output:
259107235.0


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * len(A)
C = [0] * len(A)
mod = 10 ** 9 + 7
counter = 0
for i in range(N):
    B[i] = sum([A[i] > A[j] for j in range(0, N)])  
    C[i] = sum([A[i] > A[j] for j in range(i, N)])  

for i in range(N):
    c = (C[i] * K)%mod + ((K - 1) * K * B[i] 

    counter = (counter + c) % mod
print(int(counter))

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i):
            if a[i] > a[j + i]:
                t2 += 1
                
    count = t1 * k * (k - 1) / 2 % mod
    count += t2 * k % mod
    print(int(count % mod))


if __name__ == '__main__':
    n,k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)


Failing test case input:
10 727991293
10 9 10 7 5 3 0 4 4 0

Expected output:
102125547


Actual output:
102126319


Fixed submission (verdict: Accepted):
import numpy as np
import random
import sys
from functools import lru_cache

def main(n,k,a):

    mod = 10**9 + 7
    c1,c2 = 0,0
    for i in range(len(a)):
        for j in range(len(a)):
            
            if a[i] > a[j]:
                
                if i < j:
                    c1 += 1

                elif i > j:
                    c2 += 1
        
        count = (c1*k*(k+1)

    print(count)


if __name__ == '__main__':
    n,k = map(int,input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
a = list(map(int,input().split()))
counta = 0
countb = 0
for i in range(n):
    for j in range(n-i-1):
        if a[i]>a[j+i+1]:
            counta += 1
b = sorted(a)[::-1]
for i in range(n):
    for j in range(n-i-1):
        if b[i]>b[j+i+1]:
            countb += 1
print((counta*k+countb*int((k*(k-1))/2))%(10**9+7))


Failing test case input:
10 1468376359
13 2 8 7 6 6 3 4 4 1

Expected output:
764355261


Actual output:
764356422


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
a = list(map(int,input().split()))
counta = 0
countb = 0
for i in range(n):
    for j in range(n-i-1):
        if a[i]>a[j+i+1]:
            counta += 1
b = sorted(a)[::-1]
for i in range(n):
    for j in range(n-i-1):
        if b[i]>b[j+i+1]:
            countb += 1
print((counta*k+countb*((k*(k-1))
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
li = list(map(int,input().split()))
mod = 10**9 +7

ans_1 = 0
ans_2 = 0
for i in range(n-1):
  for j in range(i+1,n):
    if li[i] > li[j]:
      ans_1+= 1
for i in range(n):
  for j in range(n):
    if li[i] < li[j]:
      ans_2 += 1
ans = k*ans_1 + 0.5*k*(k-1)%mod*ans_2%mod
print(int(ans%mod))

Failing test case input:
10 1051516890
10 9 10 7 5 5 0 4 4 0

Expected output:
818429624


Actual output:
818430731


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
li = list(map(int,input().split()))
mod = 10**9 +7
 
ans_1 = 0
ans_2 = 0
for i in range(n):
  for j in range(i+1,n):
    if li[i] > li[j]:
      ans_1+= 1
for i in range(n):
  for j in range(n):
    if li[i] > li[j]:
      ans_2 += 1
ans = k*ans_1%mod + (k*(k-1)
print(int(ans%mod))

Problem: p02928
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
P = (10**9)+7
N,K = map(int,input().split())
A = list(map(int,input().split()))
res_p = 0
res_n = 0

for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            res_p += 1
        if A[-i-1]>A[-j-1]:
            res_n += 1
res = (K * res_p)
res += (res_p + res_n) * ((K * (K-1)) / 2) 


print(res % P)


Failing test case input:
10 872422839
13 9 8 7 3 5 5 4 4 1

Expected output:
908226379


Actual output:
908227003.0


Fixed submission (verdict: Accepted):
P = (10**9)+7
N,K = map(int,input().split())
A = list(map(int,input().split()))
res_p = 0
res_n = 0

for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            res_p += 1
        if A[-i-1]>A[-j-1]:
            res_n += 1
res = (K * res_p)
res += (res_p + res_n) * (K * (K-1) 
print(int(res % P) )

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = list(map(int, input().split()))

tota = 0
totd = 0

for i in range(N): 
    for j in range(i+1, N): 
        if A[i] > A[j]:
            tota += 1
    for k in range(N): 
        if A[i] > A[k]:
            totd += 1

print(int((((K%1000000007)/2)*(2*tota + ((K-1))*totd)%1000000007)%1000000007))

Failing test case input:
10 998244353
20 11 8 2 5 2 3 4 1 2

Expected output:
715289784


Actual output:
715289749


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10**9 + 7
tota = 0
totd = 0

for i in range(N): 
    for j in range(i+1, N): 
        if A[i] > A[j]:
            tota += 1
    for k in range(N): 
        if A[i] > A[k]:
            totd += 1

ans = (tota * K + K*(K-1)
print(int(ans))
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
la = list(map(int, input().split()))

count = 0
for i in range(n):
    for j in range(n-i-1):
        jj = j+1+i
        if la[i] > la[jj]:
            count += 1

count2 = 0
laa = sorted(la)
for i in range(n):
    for j in range(n-i-1):
        jj = j+1+i
      
        if laa[i] < laa[jj]:
            count2 += 1
result = (count*k + (count2)*((1/2)*(k-1)*(k)))
print(int(result)%(pow(10,9)+7))


Failing test case input:
10 872422839
9 9 8 7 5 5 3 4 4 0

Expected output:
876376284


Actual output:
876376866


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
la = list(map(int, input().split()))
mod = pow(10,9)+7

c = 0
for i in range(n):
    for j in range(n-i-1):
        jj = j+1+i
        if la[i] > la[jj]:
            c += 1

c2 = 0
for i in range(n):
    for j in range(n):
        if la[i] > la[j]:
            c2 += 1

a = c*k
b = c2*((k*(k-1))


print((a+b)%mod)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = list(map(int,input().split()))

count = 0
for i in range(N-1):
    for j in range(i, N):
        if A[i] > A[j]:
            count += 1
first = (count * K) % 1000000007

count2 = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            count2 += 1
second = (count2 * (K*(K-1)/2)) % 1000000007

print(int((first+second)%1000000007))

Failing test case input:
10 727991293
-1 9 20 7 7 3 0 6 4 1

Expected output:
524216575


Actual output:
524216311


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = list(map(int,input().split()))
MOD = 1000000007
count = 0
for i in range(N-1):
    for j in range(i+1, N):
        if A[i] > A[j]:
            count += 1
first = (count * K) % 1000000007

count2 = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            count2 += 1

ans = ((count * K) + (count2 * K * (K-1) 



print(ans)

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

input = sys.stdin.readline

MOD = 10 ** 9 + 7

n, k = map(int, input().split())
a = list(map(int, input().split()))

a_single = 0
a_multi = 0

for i, ai in enumerate(a):
    for j, aj in enumerate(a):
        if ai > aj:
            a_multi += 1
            if j > i:
                a_single += 1

ans = a_single * k % MOD
ans += k * (k - 1) % MOD 
ans %= MOD

print(ans)


Failing test case input:
10 559937258
10 9 10 7 9 3 0 11 4 0

Expected output:
338231974


Actual output:
499968075


Fixed submission (verdict: Accepted):
import sys

input = sys.stdin.readline

MOD = 10 ** 9 + 7

n, k = map(int, input().split())
a = list(map(int, input().split()))

a_single = 0
a_multi = 0

for i, ai in enumerate(a):
    for j, aj in enumerate(a):
        if ai > aj:
            a_multi += 1
            if j > i:
                a_single += 1

ans = 0
ans = (a_single * k % MOD + ans) % MOD
ans = (k * (k - 1) 

print(ans)
Problem: p02928
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def getlist():
	return list(map(int, input().split()))

N, K = getlist()
A = getlist()

x = 0
for i in range(N):
	for j in range(i + 1, N):
		if A[i] > A[j]:
			x += 1

B = sorted(A)
s = 0
v = 0
c = 0
for i in range(N):
	if B[i] > v:
		c = i
	s += c
	v = B[i]


ans = int(((K - 1) * K) / 2) * s + K * x
print(ans % 1000000007)

Failing test case input:
10 918571889
10 9 10 7 5 3 0 6 4 0

Expected output:
361939526


Actual output:
361939870


Fixed submission (verdict: Accepted):
def getlist():
	return list(map(int, input().split()))

N, K = getlist()
A = getlist()

x = 0
for i in range(N):
	for j in range(i + 1, N):
		if A[i] > A[j]:
			x += 1

s = 0
for i in range(N):
	for j in range(N):
		if i != j:
			if A[i] > A[j]:
				s += 1

ans1x = int(((K - 1) * K) 
ans1 = ans1x * s % 1000000007
ans2 = K * x % 1000000007
print((ans1 + ans2) % 1000000007)

Problem: p02928
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
M = 10**9+7
N,K = map(int, input().split())
A = list(map(int, input().split()))
A_ = sorted(A, reverse = True)

ans = 0
ans_ = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        if A[i] > A[j]:
            ans += 1
        if A_[i] > A_[j]:
            ans_ += 1
print(int((K*(K-1)/2%M)*ans_+ans*K)%M)

Failing test case input:
10 1652783124
20 9 8 7 5 5 0 4 1 2

Expected output:
611908778


Actual output:
611911682


Fixed submission (verdict: Accepted):
M = 10**9+7
import sys
input = sys.stdin.readline
def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    A_ = sorted(A, reverse = True)
    ans = 0
    ans_ = 0
    for i in range(0,N-1):
        for j in range(i+1,N):
            if A[i] > A[j]:
                ans += 1
            if A_[i] > A_[j]:
                ans_ += 1

    print(int((((K*(K-1)

if __name__ == '__main__':
    main()

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = input().split()
N = int(N)
K = int(K)
ans =0

A =[int(i) for i in input().split()]

firstcnt = 0
seccnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        if A[i]> A[j]:
            firstcnt += 1
for i in range(N):
    for j in range(N):
        if A[i]> A[j]:
            seccnt += 1

firstcnt %= 1000000007

ans = firstcnt * K + seccnt * (K-1)*K/2
ans %= 1000000007

print(int(ans))


Failing test case input:
10 1652783124
20 9 8 7 5 8 0 4 1 2

Expected output:
306342551


Actual output:
306349815


Fixed submission (verdict: Accepted):
N,K = input().split()
N = int(N)
K = int(K)
mod = 1000000007
ans =0

A =[int(i) for i in input().split()]

firstcnt = 0
seccnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        if A[i]> A[j]:
            firstcnt += 1
for i in range(N):
    for j in range(N):
        if A[i]> A[j]:
            seccnt += 1


firstcnt =  firstcnt % mod
seccnt = seccnt % mod

a = (firstcnt*K)%mod
c = ((K-1)*K
b = (seccnt * c)%mod

ans = a + b
ans = ans % mod

print(int(ans))
Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
A = list(map(int, input().split()))

tota = 0
totd = 0

for i in range(N):
    for j in range(i+1, N):
        if A[i] > A[j]:
            tota += 1
    for k in range(N):
        if A[i] > A[k]:
            totd += 1

print(int((((K%1000000007)/2)*(2*tota + ((K-1)%1000000007)*totd))%1000000007))

Failing test case input:
10 998244353
10 9 8 7 5 6 3 4 2 1

Expected output:
185297239

Actual output:
185297196


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10**9 + 7
tota = 0
totd = 0

for i in range(N): 
    for j in range(i+1, N): 
        if A[i] > A[j]:
            tota += 1
    for k in range(N): 
        if A[i] > A[k]:
            totd += 1

ans = (tota * K + K*(K-1)
print(int(ans))

Problem: p02928
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())

A = list(map(int, input().split()))

mod = 1000000007


B = A * 2
syokiti_A = 0
syokiti_B = 0
for i in range(N):
    for j in range(i, N):
        if A[i] > A[j]:
            syokiti_A += 1

for i in range(N*2):
    for j in range(i, N*2):
        if B[i] > B[j]:
            syokiti_B += 1

ans = int((syokiti_A + syokiti_B*K*(K-1)/2)) % mod

print(int(ans))



Failing test case input:
10 998244353
10 9 8 7 5 6 3 4 2 1

Expected output:
185297239

Actual output:
136967491


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())

A = list(map(int, input().split()))

mod = 1000000007


B = A * 2
syokiti_A = 0
syokiti_B = 0
for i in range(N):
    for j in range(i, N):
        if A[i] > A[j]:
            syokiti_A += 1

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if A[i] > A[j]:
            syokiti_B += 1

ans = (syokiti_A * K) % mod + (syokiti_B * K * (K-1) 
print(int(ans) % mod)