Problem:


Score : 300 points

Problem Statement

We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.

Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.

Find the inversion number of B, modulo 10^9 + 7.

Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that  B_i > B_j.

Constraints

All values in input are integers.

1 \leq N \leq 2000

1 \leq K \leq 10^9

1 \leq A_i \leq 2000

Input

Input is given from Standard Input in the following format:

N K
A_0 A_1 ... A_{N - 1}

Output

Print the inversion number of B, modulo 10^9 + 7.

Sample Input 1

2 2
2 1

Sample Output 1

3

In this case, B~=~2,~1,~2,~1. We have:

B_0 > B_1

B_0 > B_3

B_2 > B_3

Thus, the inversion number of B is 3.

Sample Input 2

3 5
1 1 1

Sample Output 2

0

A may contain multiple occurrences of the same number.

Sample Input 3

10 998244353
10 9 8 7 5 6 3 4 2 1

Sample Output 3

185297239

Be sure to print the output modulo 10^9 + 7.



Sample input:
2 2
2 1


Sample output:
3

Submission status: Wrong Answer

Solution code:
def main():
    mod = 10**9+7
    n,k = map(int,input().split())
    k %= mod

    ls = [int(x) for x in input().split()]
    ans1 = [0 for _ in range(n)]
    ans2 = [0 for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if ls[i]>ls[j]:
                if j>i:
                    ans1[i] += 1
                else:
                    ans2[i] += 1   
    A = 0
    k1 = (k*(k+1))%mod//2
    k2 = (k*(k-1))%mod//2

    for i in range(n):
        A += (k1*ans1[i])%mod
        A %=mod
        A += (k2*ans2[i])%mod
        A %= mod
    print(A%mod)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int, input().strip().split()))
count = 0
for i in range(N):
    for j in range(i,N):
        if A[i]>A[j]:
            count += 1
        else:
            count += 0
print(count*K*(K+1)/2)

Submission status: Wrong Answer

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

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * 2001

    def sum(self, i):
        ret = 0
        while i > 0:
            ret += self.tree[i]
            i -= i & -i
        return ret

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

bit = Bit(N)

last_a = A[0]
inter = 0
for i in range(N):
    ai = A[i]
    for j in range(i + 1):
        aj = A[j]
        if ai > aj:
            inter += 1

intra = 0
for i in range(len(A)):
    a = A[i]
    bit.add(a, 1)
    s_a = bit.sum(a)
    intra += i + 1 - s_a

# print(inter, intra)

mod = 10**9 + 7

ans = (intra * K * (K + 1) // 2) % mod
ans += inter * (K - 1) * K // 2 % mod
ans %= mod
print(ans)

Submission status: Wrong Answer

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

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * 2001

    def sum(self, i):
        ret = 0
        while i > 0:
            ret += self.tree[i]
            i -= i & -i
        return ret

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

bit = Bit(N)

last_a = A[0]
inter = 0
for i in range(1, N):
    a = A[i]
    if last_a < a:
        inter += 1
    else:
        last_a = a

intra = 0
for i in range(len(A)):
    a = A[i]
    bit.add(a, 1)
    s_a = bit.sum(a)
    intra += i + 1 - s_a

# print(inter, intra)

mod = 10**9 + 7

ans = (intra * K * (K + 1) // 2) % mod
ans += inter * (K - 1) * K // 2 % mod
ans %= mod
print(ans)

Submission status: Wrong Answer

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

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * 2001

    def sum(self, i):
        ret = 0
        while i > 0:
            ret += self.tree[i]
            i -= i & -i
        return ret

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

bit = Bit(N)

last_a = A[0]
inter = 0
for i in range(1, N):
    a = A[i]
    if last_a < a:
        inter += 1
    last_a = a

intra = 0
for i in range(len(A)):
    a = A[i]
    bit.add(a, 1)
    s_a = bit.sum(a)
    intra += i + 1 - s_a

# print(inter, intra)

mod = 10**9 + 7

ans = (intra * K * (K + 1) // 2) % mod
ans += inter * (K - 1) * K // 2 % mod
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * 2001

    def sum(self, i):
        ret = 0
        while i > 0:
            ret += self.tree[i]
            i -= i & -i
        return ret

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

bit = Bit(N)

inter = 0
intra = 0
for i in range(len(A)):
    a = A[i]
    bit.add(a, 1)
    s_a = bit.sum(a)
    intra += i + 1 - s_a
    if a == 1:
        continue
    inter += bit.sum(a - 1)

mod = 10**9 + 7

ans = (intra * K * (K + 1) // 2) % mod
ans += inter * (K - 1) * K // 2 % mod
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))

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

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 = int((tentosu_f * k) % mod + (k*(k-1) / 2 * tentosu_l) % mod)
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import collections

N,K = map(int, input().split())
arr = list(map(int, input().split()))
c = collections.Counter(arr)

counts = list(c.values())[::-1]

if len(counts)==1:
  print(0)
else:
  value = 0
  for i,num in enumerate(arr):
    value += len([1 for x in arr if x<num])
  out_arr = value*K*(K-1)//2
  print(out_arr)
  
  in_arr = 0
  for j,num in enumerate(arr):
    in_arr += len([1 for x in arr[j+1:] if x<num])
  in_arr = in_arr*K
  print((out_arr+in_arr)%1000000007)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))

    MOD = int(1e9) + 7

    count = np.zeros((N, 2001), dtype=int)

    count[0][a[0]] += 1
    for i in range(1, N):
        count[i] = count[i-1]
        count[i][a[i]] += 1
    
    for i in range(1, 2001):
        count[:, i] += count[:, i-1]
    # print(count)
    ans = 0
    for i in range(N-1):
        left = count[i][a[i]-1]
        right = count[-1][a[i]-1] - left
        if left + right == 0:
            continue
        start = (left + right) * (K - 1) + right
        end = right
        num = (start - end) // (left + right) + 1
        # print(left, right, start, end, num)
        ans += (num * (start + end)) // 2
        ans %= MOD
        # print((num * (start + end)) // 2)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections

N,K = map(int, input().split())
arr = list(map(int, input().split()))
c = collections.Counter(arr)

counts = list(c.values())

if len(counts)==1:
  print(0)
else:
  value = 0
  for i,cnt in enumerate(counts[::-1][1:]):
    value += cnt*sum(counts[i+1:])
  out_arr = value*K*(K-1)//2
  
  in_arr = 0
  for j,num in enumerate(arr):
    in_arr += len([1 for x in arr[j+1:] if x<num])
  in_arr = in_arr*K
  print((out_arr+in_arr)%1000000007)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))

tentosu_f = 0
tentosu_l = 0

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

Submission status: Wrong Answer

Solution code:
import collections

N,K = map(int, input().split())
arr = list(map(int, input().split()))
c = collections.Counter(arr)

counts = list(c.values())[::-1]

if len(counts)==1:
  print(0)
else:
  value = 0
  for i,cnt in enumerate(counts[1:]):
    value += cnt*(i+1)
  out_arr = value*K*(K-1)//2
  in_arr = 0
  for j,num in enumerate(arr):
    in_arr += len([1 for x in arr[j+1:] if x<num])
  in_arr = in_arr*K
  print((out_arr+in_arr)%1000000007)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))

tentosu_f = 0
tentosu_l = 0

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))

tentosu_f = 0
tentosu_l = 0

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

Submission status: Wrong Answer

Solution code:
n,k = list(map(int,input().split()))
num_list = list(map(int,input().split()))
up_list = [0 for i in range(n)]
up_listk = []
ans = 0
for i in range(n):
    for j in num_list:
        if num_list[0] > j:
            up_list[i] += 1
    up_listk.append(up_list[i])
    up_list[i]
    del num_list[0]
ans = sum(up_list)*k*(k+1)/2
mod = 10**9+7
print(int(ans%mod))

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7

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

C = [0] * (max(A)+1)
a1 = 0
a2 = 0

for i in range(n):
    C[A[i]] += 1
    a2 += sum(C[A[i]+1:])
for i in range(n):
    a1 += sum(C[A[i]+1:])

a1 %= mod
a2 %= mod
#print(a1*0.5*n*(n-1))
k %= mod

ans = 0
ans += a2*k % mod
ans2 = a1*k % mod
ans2 *= 0.5*(k-1) % mod
ans += ans2 % mod

print(int(ans % mod))

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
a=list(map(int, input().split()))
count=0

for i in range(len(a)):
  for j in range(i, len(a)):
    if a[j] < a[i]:
      count+=1

s=k+1
s=s*s
s=s/2
total=count*s
mod=total%1000000007

print(mod)

Submission status: Wrong Answer

Solution code:
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)/2) % MOD * d)
ans = int(ans%MOD)

print(ans)

Submission status: Wrong Answer

Solution code:
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( int((k *(k-1)/2) % MOD) * d)
ans = int(ans%MOD)

print(ans)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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 = c * k % Q +d* (k *(k-1)/2) % Q
ans = int(ans%Q)

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
tmp=10**9+7

cna=0
for i,a in enumerate(A):
    for at in A[i+1:]:    
        if a>at:
            cna+=1

cna2=0
for a in A:
    for at in A:    
        if a>at:
            cna2+=1


kt=int((K-1)*(K)/2)

print((K*cna+kt*cna2)%tmp)

Submission status: Wrong Answer

Solution code:

def kleene_inversion(n: int, k: int, a) -> int:
    res = 0
    for i, aa in enumerate(a, 1):
        s = sum(aa > aaa for aaa in a[i:])
        res += s * k
        res += s * (k - 1)
    return int(res % (10e9 + 7))




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

Submission status: Wrong Answer

Solution code:
s=list(map(int,input().split()))
t=list(map(int,input().split()))
if s[0]==1:
  print(0)
else:
  p=s[1]-1
  q=s[1]
  r=(p*q)/2
  b=0
  for i in range(s[0]):
    a=0
    for j in range(s[0]):
      if t[i]>t[j]:
        a=a+1
    b=b+a*r
  for v in range(s[0]-1):
    a=0
    for w in range(v+1,s[0]):
      if t[v]>t[w]:
        a=a+1
    b=b+a*s[1]
  b=b%1000000007
  print(int(b))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

R = lambda: map(int, input().split())
n, k = R()
a = list(R())
w = [0] * n

def merge(b, e):
    m = b + (e - b) // 2
    i, j = b, m
    r = k = 0
    while i < m and j < e:
        if a[i] <= a[j]:
            w[k] = a[i]
            i += 1
        else:
            r += m - i
            w[k] = a[j]
            j += 1
        k += 1
    a[e - m + i: e] = a[i: m]
    a[b: b + k] = w[:k]
    return r        
    
def mergesort(b, e):
    if e - b < 2:
        return 0
    m = b + (e - b) // 2
    return mergesort(b, m) + mergesort(m, e) + merge(b, e)


r = k * mergesort(0, n)
print(a)
c = n * (n - 1) // 2
for _, g in groupby(a):
    x = sum(1 for _ in g)
    c -= x * (x - 1) // 2
print((r + c * k * (k - 1) // 2) % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
s=list(map(int,input().split()))
t=list(map(int,input().split()))
if s[0]==1:
  print(0)
else:
  x=s[1]%1000000007
  y=(s[1]+1)%1000000007
  z=((x*y)/2)%1000000007
  p=(s[1]-1)%1000000007
  q=s[1]%1000000007
  r=((p*q)/2)%1000000007
  b=0
  for i in range(s[0]):
    a=0
    for j in range(s[0]):
      if t[i]>t[j]:
        a=a+1
    b=b+a*r
    b=b%1000000007
  b=b%1000000007
  for v in range(s[0]-1):
    a=0
    for w in range(v+1,s[0]):
      if t[v]>t[w]:
        a=a+1
    b=b+a*s[1]
    b=b%1000000007
  b=b%1000000007
  print(int(b))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
box=list(map(int,input().split()))

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

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

ans=(count*k)%10**9+7 + (count_2*k*(k-1)//2)%10**9+7
print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
box=list(map(int,input().split()))

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

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

point=int(0.5*(k*(k-1)))
ans=((count_2*point)%(10**9+7))+((count*k)%(10**9+7))
print(ans%(10**9+7))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
box=list(map(int,input().split()))

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

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

point=int(0.5*(k*(k-1)))
print(((count_2*point)+(count*k))%(10**9+7))

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]

# バイナリインデックス木(BIT)
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):
        s = 0
        while 0 < i:
            s += self.tree[i]
            s %= MOD
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

# エントリーポイント
def main():
    N, K = input(int, int)
    A = input([int, N])

    ppp = A
    bit = Bit(2010)
    ans = []
    for i, p in enumerate(ppp):
        bit.add(p, 1)
        ans.append(i + 1 - bit.sum(p))
    ans2 = 0
    kp = (K + 1) * K // 2
    for a in ans:
        ans2 += a * kp
        ans2 %= MOD
    print(ans2)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
box=list(map(int,input().split()))

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

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

point=0.5*(k*(k-1))
print(int((count_2*point+count*k)%(10**9+7)))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
box=list(map(int,input().split()))

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

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

point=int(0.5*(k*(k-1)))
print((count_2*point+count*k)%(10**9+7))

Submission status: Wrong Answer

Solution code:
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))/2
 
ans = int(numbers % (10**9 + 7))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]

# バイナリインデックス木(BIT)
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):
        s = 0
        while 0 < i:
            s += self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

# エントリーポイント
def main():
    N, K = input(int, int)
    A = input([int, N])

    ppp = A
    bit = Bit(2010)
    ans = 0
    
    for k in range(1, K + 1):
        for i, p in enumerate(ppp):
            bit.add(p, 1)
            ans += (K * i + 1) - bit.sum(p)
            ans %= MOD
    print(ans)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())

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

mod = 1000000007

# K = 2のときの初期値が必要
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) / 2) % mod
print(int(ans) % mod)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())

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

mod = 1000000007

# K = 2のときの初期値が必要
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) + (syokiti_B * K * (K-1) / 2)
print(int(ans) % mod)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def main():
    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,i):
            if A[i] > A[j]:
                outer += 1
        for j in range(i+1,N):
            if A[i] > A[j]:
                inner += 1
                outer += 1
    count = (inner * K + outer * int(K * (K-1) / 2))
    count = count % (1000000000 +7)
    print(count)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def main():
    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,i):
            if A[i] > A[j]:
                outer += 1
        for j in range(i+1,N):
            if A[i] > A[j]:
                inner += 1
                outer += 1
    count = (inner * K + outer * int(K * (K-1) / 2))
    count = count % (1000000000 +7)
    print(A)
    print(inner)
    print(outer)
    print(count)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = int((f-g)%mod)
k = int(k%mod)

#ans = g*k + t*k*(k-1)//2
#ans = g*k + t*k*(k-1)//2
print(int(( (k%mod*g%mod)%mod + t*((k-1)*k*0.5)%mod)%mod))
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = int((f-g)%mod)
k = int(k%mod)

#ans = g*k + t*k*(k-1)//2
#ans = g*k + t*k*(k-1)//2
print(int(( (k%mod*g%mod)%mod + t*((k-1)*k%mod//2)%mod)%mod))
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = int((f-g)%mod)
k = int(k%mod)

#ans = g*k + t*k*(k-1)//2
#ans = g*k + t*k*(k-1)//2
print(int(( (k%mod*g%mod)%mod + t*((k-1)*k%mod*0.5)%mod)%mod))
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
An = list(map(int,input().split()))
f_count = 0
r_count = 0

for i in range(N):
    for j in range(N):
        if i < j:
            if An[i] < An[j]:
                f_count += 1
            elif An[i] > An[j]:
                r_count += 1

Ans = (f_count * K*(K-1)/2 + r_count * K*(K+1)/2) % (10**9+7)

print(int(Ans))

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
An = list(map(int,input().split()))
f_count = 0
r_count = 0

for i in range(N):
    for j in range(N):
        if i < j:
            if An[i] < An[j]:
                f_count += 1
            elif An[i] > An[j]:
                r_count += 1

Ans = f_count + (f_count * K*(K-1)/2 + r_count * K*(K+1)/2) % (10**9+7)

print(int(Ans))

Submission status: Wrong Answer

Solution code:
N,K= list(map(int, input().split()))
A= list(map(int, input().split()))
AA=sorted(A)
num=0
before=0
for i in A:
    num+=AA.index(i)
num2=0
for i in range(N-1):
    for j in range(i+1,N):
        if A[i]>A[j]:
            num2+=1
hoge=int((K-1)*K/2%1000000007)
hoge=hoge*num%1000000007
hoge2=num2*K%1000000007
hoge=(hoge+hoge2)%1000000007
print(hoge)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
INF = (10 ** 9) + 7

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

tmp1 = 0
tmp2 = 0

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

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

ans = (tmp1 * (K)) + ((K * ((K - 1) // 2)) * tmp2)
print(ans % INF)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
INF = (10 ** 9) + 7

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

tmp1 = 0
tmp2 = 0

for i in range(N - 1):
    for j in range(1, N):
        if aLst[i] > aLst[j]:
            tmp1 += 1

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

ans = (tmp1 * K) + int((K * ((K - 1) / 2)) * tmp2)
print(ans % INF)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
A = [int(i) for i in input().split()]
mod = 10**9 +7

tmp1 = 0
tmp2 = 0

for i in range(n):
  for j in range(n):
    if A[i] > A[j]:
      if i < j:
        #print(i,j,A[i],A[j])
        tmp1 += 1
      if i > j:
        #print(i,j,A[i],A[j])
        tmp2 += 1
#print(tmp1,tmp2)
#print(tmp1,tmp2)
print(int(((tmp1 * (k+1) + tmp2 * (k-1)) * k / 2 )% mod))

Submission status: Wrong Answer

Solution code:
a,b=input().split()
c=input().split()
d=0
for i in range(len(c)):
    for j in range(i+1,len(c)):
        if(int(c[i])>int(c[j])):
            d=(d+1)%((10**9)+7)
if(d!=0):
    print((d*int(b)+1)%((10**9)+7))
else:
    print(d)

Submission status: Wrong Answer

Solution code:
cnt=0
mod=1e9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
#a単体での店頭数
for i in range(n):
    for j in range(i+1,n):
        if a[i]>a[j]:
            cnt+=1
ans=cnt*k%mod
cnt=0
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            cnt+=1
temp=((k-1)*k//2)%mod
ans+=cnt*temp%mod
ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
cnt=0
mod=1e9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
#a単体での店頭数
for i in range(n):
    for j in range(i+1,n):
        if a[i]>a[j]:
            cnt+=1
ans=cnt*k%mod
cnt=0
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            cnt+=1
temp=((k-1)*k//2)%mod
ans+=cnt*temp%mod
ans%=mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
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)])  # Aの中でAi>Ajとなる個数
    C[i] = sum([A[i] > A[j] for j in range(i, N)])  # Aの中でAi 以降で　Ai>Ajとなる個数

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

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

Submission status: Wrong Answer

Solution code:
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)])  # Aの中でAi>Ajとなる個数
    C[i] = sum([A[i] > A[j] for j in range(i, N)])  # Aの中でAi 以降で　Ai>Ajとなる個数

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

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

Submission status: Wrong Answer

Solution code:
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)])  # Aの中でAi>Ajとなる個数
    C[i] = sum([A[i] > A[j] for j in range(i, N)])  # Aの中でAi 以降で　Ai>Ajとなる個数
    B[i] = int(B[i]) if B[i] > 0 else 0

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

Submission status: Wrong Answer

Solution code:
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 - 1):
            if a[i] > a[j + i + 1]:
                t2 += 1

    count = (t1 * int(((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)

Submission status: Wrong Answer

Solution code:
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 - 1):
            if a[i] > a[j + i + 1]:
                t2 += 1

    count = (t1 * int((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)