Problem p02928 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

DIV_NUM = 1000000000 + 7

INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])

A = [int(x) for x in input().split()]
AA = np.array(A)
if N==1:
    print(0)
    exit()

# https://kira000.hatenadiary.jp/entry/2019/02/23/053917
def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                cnt += 1
    return cnt

answer = bubble_sort(AA)

B = sorted(A)
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r

# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A , dtype='int64')

if N==1:
    print(0)
    exit()

tree = [0] * (N+100)

def BIT_update(x):
    while x <= N:
        tree[x] += 1
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x += z
                break
            y //= 2
            z *= 2

def BIT_sum(x):
    s = 0
    while x > 0:
        s += tree[x]
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x -= z
                break
            y //= 2
            z *= 2
    return s
 
answer = N*(N-1)//2
for i in AA:
    answer -= BIT_sum(int(i))
    BIT_update(int(i))

B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A , dtype='int64')

if N==1:
    print(0)
    exit()
 
tree = [0] * (N+1)

def BIT_update(x):
    while x <= N:
        tree[x] += 1
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x += z
                break
            y //= 2
            z *= 2

def BIT_sum(x):
    s = 0
    while x > 0:
        s += tree[x]
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x -= z
                break
            y //= 2
            z *= 2
    return s
 
answer = N*(N-1)//2
for i in AA:
    answer -= BIT_sum(int(i))
    BIT_update(int(i))

B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A , dtype='int64')

if N==1:
    print(0)
    exit()
 
tree = [0] * (N+1)

def BIT_update(x):
    while x <= N:
        tree[x] += 1
        y = x
        z = 1
        while y:
            if y % 2 == 1:
                x += z
                break
            y /= 2
            z *= 2
def BIT_sum(x):
    s = 0
    while x > 0:
        s += tree[x]
        y = x
        z = 1
        while y:
            if y % 2 == 1:
                x -= z
                break
            y /= 2
            z *= 2
    return s
 
answer = N*(N-1)//2
for i in AA:
    answer -= BIT_sum(int(i))
    BIT_update(int(i))

B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A , dtype='int64')

if N==1:
    print(0)
    exit()
 
tree = [0] * (N+1)

def BIT_update(x):
    while x <= N:
        tree[x] += 1
        y = x
        z = 1
        while y:
            if y % 2 == 1:
                x += z
                break
            y /= 2
            z *= 2
def BIT_sum(x):
    s = 0
    while x > 0:
        s += tree[x]
        y = x
        z = 1
        while y:
            if y % 2 == 1:
                x -= z
                break
            y /= 2
            z *= 2
    return s
 
answer = N*(N-1)//2
for i in AA:
    answer -= BIT_sum(int(i))
    BIT_update(int(i))

print(type(i),type(N))
print(tree)


B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A , dtype='int64')
Q=np.array([0], dtype = 'int64')
if N==1:
    print(0)
    exit()
 
tree = [0] * (N+1)
 
# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(x):
    Q[0]=x
    while Q[0] <= N:
        tree[Q[0]] += 1
        Q[0] += Q[0]&(-Q[0])
def BIT_sum(x):
    s = 0
    Q[0]=x
    while Q[0] > 0:
        s += tree[Q[0]]
        Q[0] -= Q[0]&(-Q[0])
    return s
 
answer = N*(N-1)//2
for x in AA:
    answer -= BIT_sum(int(x))
    BIT_update(int(x))

#print(type(x),type(N))
#print(tree)


B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A)
if N==1:
    print(0)
    exit()
 
tree = np.array([0] * (N+1) )
 
# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(x):
    s = 0
    while x > 0:
        s += tree[x]
        x -= x&(-x)
    return s
 
answer = N*(N-1)//2
for x in AA:
    answer -= BIT_sum(int(x))
    BIT_update(int(x))
 
B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A)
if N==1:
    print(0)
    exit()
 
tree = np.array([0] * (N+1) )
 
# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(x):
    while x <= N:
        tree[x] += 1
        y = int(x)
        x += y&(-y)
def BIT_sum(x):
    s = 0
    while x:
        s += tree[x]
        y = int(x)
        x -= y&(-y)
    return s
 
answer = N*(N-1)//2
for x in AA:
    answer -= BIT_sum(int(x))
    BIT_update(int(x))
 
B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A)
if N==1:
    print(0)
    exit()
 
tree = np.array([0] * (N+1) )
 
# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        y = int(x)
        x += y&(-y)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        y = int(x)
        x -= y&(-y)
    return s
 
answer = N*(N-1)//2
for x in AA:
    answer -= BIT_sum(tree,int(x))
    BIT_update(tree,int(x))
 
B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
 
DIV_NUM = 1000000000 + 7
 
INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])
 
A = [int(x) for x in input().split()]
AA = np.array(A)
if N==1:
    print(0)
    exit()
 
tree = np.array([0] * (N+1) )
 
# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s
 
answer = N*(N-1)//2
for x in AA:
    answer -= BIT_sum(tree,int(x))
    BIT_update(tree,int(x))
 
B = sorted(A)
 
q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
 
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

DIV_NUM = 1000000000 + 7

INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])

A = [int(x) for x in input().split()]
AA = np.array(A)
if N==1:
    print(0)
    exit()

tree = np.array([0] * (N+1) )

# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
for x in AA:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)

B = sorted(A)

q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r

# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

DIV_NUM = 1000000000 + 7

INPUT_NUMS = list(map(int, input().split()))
N=int(INPUT_NUMS[0])
K=int(INPUT_NUMS[1])

A = [int(x) for x in input().split()]
AA = np.array(A)
if N==1:
    print(0)
    exit()

tree = np.array([0] * (N+1) )

# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
for x in AA:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)

B = sorted(A)

q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r

# print(answer,K)
answer = answer % DIV_NUM
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
DIV_NUM = 1000000007


N,K = map(int, input().split())
A = [int(x) for x in input().split()]

if N==1:
    print(0)
    exit()

tree = [0] * (N+1)

# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)

B = sorted(A)

q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
# print(answer)
answer = answer % DIV_NUM
answer = (K * answer) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
DIV_NUM = 1000000007


N,K = map(int, input().split())
A = [int(x) for x in input().split()]

if N==1:
    print(0)
    exit()

tree = [0] * (N+1)

# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)

B = sorted(A)

q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r

answer = (K * answer) + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
DIV_NUM = 1000000007


N,K = map(int, input().split())
A = [int(x) for x in input().split()]

tree = [0] * (N+1)

# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)

B = sorted(A)

q=0
p=B[0]
r=0
if N==1:
    print(0)
    exit()
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r

answer = (K * answer) + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools

DIV_NUM = 1000000007


N,K = map(int, input().split())
A = [int(x) for x in input().split()]

# https://atcoder.jp/contests/chokudai_S001/submissions/5684678
data = [0]*(N+1)
def add(i, x):
    while i <= N:
        data[i] += x
        i += i & -i
def get(i):
    s = 0
    while i:
        s += data[i]
        i -= i & -i
    return s
def su(i,j):
    return get(j)-get(i)
ans = 0
for i,a in enumerate(A):
    add(a, 1)
 
    ans += a-get(a)
answer = ans

B = sorted(A)

q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r

answer = (K * answer) + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools

DIV_NUM = 1000000007


N,K = map(int, input().split())
A = [int(x) for x in input().split()]

tree = [0] * (N+1)

# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)

B = sorted(A)

q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r

answer = (K * answer) + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
DIV_NUM = 1000000007


N,K = map(int, input().split())
A = [int(x) for x in input().split()]

tree = [0] * (N+1)

# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)

B = sorted(A)

q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r

answer = (K * answer) + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)