Harryxun/stf_run huggingface dataset:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  p.sort()
  p1 = {i for i in range(p[-1])}
  p = set(p)
  p2 = p1 - p
  p2 = list(p2)
  absv = x
  for i in range(len(p2)):
    if absv > abs(x - p2[i]):
      absv = abs(x - p2[i])
      value = x - p2[i]
  print(x - value)  

### FIXED CODE ###

x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  value = x
  for i in range(-1, 102):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)
n = input().range(3)
print('Yes' if n[0]==n[2] else 'No')

### FIXED CODE ###

n = input()
print('Yes' if n[0]==n[2] else 'No')
import argparse

def prime_calc(n):
    if n < 2:
        return False
    else:
        i = 2
        while n > i:
            if n % i == 0:
                return False
            else:
                i += 1
    return True

def prime(n):
    cnt = 0
    for i in range(0, n+1):
        ans = prime_calc(i)
        if ans is True:
            cnt = cnt + 1

    return cnt

def main():
    l = []

    parser = argparse.ArgumentParser()
    parser.add_argument("filename", help="The filename to be processed")
    args = parser.parse_args()

    if args.filename:
        with open(args.filename) as f:
            for line in f:
                a = int(line.rstrip())
                l.append(a)

    for line in l:
        print(prime(line))

if __name__ == "__main__":
    main()


### FIXED CODE ###

import math
import sys

sup = 1000000

is_prime = [0] * sup

count = [0] * sup

def setup():
    is_prime[2] = 1
    for n in range(3,sup,2):
        flag = True
        for i in range(3, int(math.floor(math.sqrt(n) + 1)), 2):
            if n % i == 0:
                flag = False
                break
        if flag:
            is_prime[n] = 1

def precount():
    for n in range(2, sup):
        count[n] = count[n-1] + is_prime[n]

def main():
    setup()
    precount()

    l = []

    for line in sys.stdin:
        l.append(int(line))

    for line in l:
         print(count[line])

if __name__ == "__main__":
    main()
''' 3???????????? '''
def sample(x):
    return x * x * x 

# ??\???
n = input()

print sample(n)

### FIXED CODE ###

def sample(n):
    return n * n * n

n = input()
x = sample(n)
print x
import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w = map(int, read().split())
    s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int)
    left = s.copy()
    right = s.copy
    up = s.copy
    down = s.copy
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print((left + right + up + down).max() - 3)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

def read():
    return sys.stdin.readline().rstrip()

def main():
    h, w = map(int, read().split())
    s = [list(read()) for _ in range(h)]
    row = [[0 for _ in range(w)] for _ in range(h)]
    col = [[0 for _ in range(w)] for _ in range(h)]
    for i in range(h):
        c = 0
        for j in range(w):
            if s[i][j] == "#":
                for k in range(j - c, j):
                    row[i][k] = c
                c = 0
            else:
                c += 1
        for k in range(w - c, w):
            row[i][k] = c
    for i in range(w):
        c = 0
        for j in range(h):
            if s[j][i] == "#":
                for k in range(j - c, j):
                    col[k][i] = c
                c = 0
            else:
                c += 1
        for k in range(h - c, h):
            col[k][i] = c
    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(row[i][j] + col[i][j], ans)
    print(ans - 1)

if __name__ == '__main__':
    main()
N,M = map(int, input())
prices = list(map(int,input().split()))
prices.sort()
print(sum(sumprices[0:M - 1]))

### FIXED CODE ###

N,M = map(int, input().split())
prices = list(map(int,input().split()))
prices.sort()
print(sum(prices[0:M]))
import math
import random

def is_prime3(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in xrange(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True


a = int(input())
while True:
 if is_prime(a) == 1:
  break
 a = a + 1

print(a)



### FIXED CODE ###

import random

def is_prime(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False

    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)

        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False

    return True

a = int(input())

while True:
 if is_prime(a) == 1:
  break
 a = a + 1

print(a)
import math
a,b = map(int,input().split())
gcd = math.gcd(a,b)
ans = a*b//gcd
print(ans)

### FIXED CODE ###

import fractions
a,b = map(int,input().split())
gcd = fractions.gcd(a,b)
ans = a*b//gcd
print(ans)
a,b,c = map(int,input().split())
if (a==b and b==c)
	print("Yes")
else
	print("No")

### FIXED CODE ###


a,b,c = map(int,input().split())
if (a==b and b==c):
	print("Yes")
else:
	print("No")
import numpy as np
N, Q = map(int, raw_input().split())
S = raw_input()
L = np.zeros(Q)
R = np.zeros(Q)
for i in range(Q):
    L[i], R[i] = map(int, raw_input().split())
num = np.zeros(Q)
for i in range(N):
    if S[i] == "A":
        if S[i+1] == "C":
            for j in range(Q):
                if int(L[j]-1) <= i and i < int(R[j]-1):                                                            
                   num[j] += 1
for i in num:
    print int(i)


### FIXED CODE ###

import numpy as np
N, Q = map(int, raw_input().split())
S = raw_input()
L = np.zeros(Q)
R = np.zeros(Q)
for i in range(Q):
    L[i], R[i] = map(int, raw_input().split())
num = np.zeros(N)
num_tmp = 0
for i in range(1,N):
    if S[i-1:i+1] == "AC":
        num_tmp += 1
    num[i] = num_tmp
for i in range(Q):
    print int(num[int(R[i]-1)] - num[int(L[i]-1)])
N, M = map(int,input().split())
A_list = []
for i in range(M):
    A_list.append(int(input()))
if A_list[0] == 1:
    Dp_list = [1,0]
else:
    Dp_list = [1,1]
for i in range(2, N + 1):
    if i not in A_list:
        Dp_list.append(Dp_list[i-2] + Dp_list[i-1])
    elif i in A_list and i-1 in A_list:
        Dp_list = [0] * (N + 1)
        break
    else:
        Dp_list.append(0)
print(Dp_list[N]%1000000007)

### FIXED CODE ###

N, M = map(int,input().split())
A_list = set([int(input()) for _ in range(M)])
Dp_list = [0] * (N+1)
Dp_list[0] = 1

if 1 in A_list:
    Dp_list[1] = 0
else:
    Dp_list[1] = 1

if N != 1:
    for i in range(2, N + 1):
        if i in A_list:
            continue

        Dp_list[i] = Dp_list[i-2] + Dp_list[i-1]
        Dp_list[i] %= 1000000007
    print(Dp_list[N])
else:
    print(1)
def tax(p,x):
    return p*(100+x) // 100
def solve(X,Y,S):
    for a in range(1,S):
        for b in range(1,S):
            sum = tax(a,X)+tax(b,X)
            if sum == S:
                tax(a,Y)+tax(b,Y) 
            if sum > S:
                break
    return best 
while True:
    X,Y,S = map(int, input().strip().split('')) 
    if X == 0:
        break
print(solve(X,Y,S))


### FIXED CODE ###

def tax(p,x):
    return p*(100+x) // 100

def solve(X,Y,S):
    A=0
    sum=0
    NS=0
    for a in range(1,S):
        for b in range(1,S-a+1):
            sum = tax(a,X)+tax(b,X)
            if sum == S:
                NS = tax(a,Y)+tax(b,Y)
                if NS > A:
                    A = NS
            if sum > S:
                break
    return A 

while True:
    X,Y,S = map(int, input().split()) 
    if X == 0:
        break
    print(solve(X,Y,S))
N=int(input())
lis=[chr(i) for i in range(97, 97+26)]
ans=''
for i in range(100000):
    rem=N%26**(i+1)
    ans=ans+lis[rem-1-26*i]
    if 26**(i+1)>N:
        break
print(ans)

### FIXED CODE ###

N=int(input())
lis=[chr(i) for i in range(97, 97+26)]
ans=''
while N>0:
    N-=1
    ans+=lis[N%26]
    N=N//26
print(ans[::-1])
n = input()
if n%9 == 0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n = int(input())
if n%9 == 0:
  print('Yes')
else:
  print('No')
mod = 998244353
n = int(input())
A = [int(x) for x in input().split()]

if A[0] != 0:
    print(0)
else:
    L = [0]*(n+1)
    for i in range(n):
        L[A[i]] += 1

    if L[0]!=1:
        print(0)
    else:
        ans = 1
        for i in range(1,n):
            if L[i]>0:
                for k in range(L[i]):
                    ans *= L[i-1]
                    ans %= mod
            else:
                nxt = i
                break
        for j in range(nxt,n+1):
            if L[j] != 0:
                print(0)
                break
        else:
            print(ans)



### FIXED CODE ###

mod = 998244353
n = int(input())
A = [int(x) for x in input().split()]

if A[0] != 0:
    print(0)
else:
    L = [0]*(n+1)
    for i in range(n):
        L[A[i]] += 1

    if L[0]!=1:
        print(0)
    else:
        ans = 1
        for i in range(1,n+1):
            if L[i]>0:
                for k in range(L[i]):
                    ans *= L[i-1]
                    ans %= mod
            else:
                nxt = i
                break
        for j in range(nxt,n+1):
            if L[j] != 0:
                print(0)
                break
        else:
            print(ans)
n,k,q=map(int,input().split())
a=[int(input()) for _ in range(q)]
if q<k:
  print(0)
  exit()
point=[-k]*n
for i in range(q):
  point[a[i]]+=1
for i in range(n):
  if point[i]>=0:
    print('Yes')
  else:
    print('No')
    
  


### FIXED CODE ###

n,k,q=map(int,input().split())
a=[int(input()) for _ in range(q)]
point=[-k]*n
for i in range(q):
  point[a[i]-1]+=1
for i in range(n):
  if point[i]>-2*k+q:
    print('Yes')
  else:
    print('No')
a=input().split('')
n=int(a[0])
x=int(a[1])
t=int(a[2])
f=x
m=t
while x<n:
  x=x+f
  t=t+m
print(t)


### FIXED CODE ###

a=input().split(' ')
n=int(a[0])
x=int(a[1])
t=int(a[2])
f=x
m=t
while x<n:
  x=x+f
  t=t+m
print(t)
import math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
a = Counter(v[1::2]).most_common()
b = Counter(v[0::2]).most_common()
a.append(0,0)
b.append(0,0)

if a[0][0] != b[0][0]:
    print(n//2 - a[0][1] + n//2 - b[0][1])
else:
    tmp_x = n//2 - a[1][1] + n//2 - b[0][1]
    tmp_y = n//2 - a[0][1] + n//2 - b[1][1]
    print(min(tmp_x, tmp_y))


### FIXED CODE ###

import math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
a = [v[i] for i in range(n) if i%2]
b = [v[i] for i in range(n) if i%2==0]
cnt_a = Counter(a)
cnt_b = Counter(b)
max_a = cnt_a.most_common()[0][1]
max_b = cnt_b.most_common()[0][1]

str_a = cnt_a.most_common()[0][0]
str_b = cnt_b.most_common()[0][0]

max_2a = 0
max_2b = 0

for i in cnt_a:
    if str_a != i  and cnt_a[i] > max_2a:
        max_2a = cnt_a[i]

for i in cnt_b:
    if str_b != i  and cnt_b[i] > max_2b:
        max_2b = cnt_b[i]

if str_a != str_b:
    print(n//2 - max_a + n//2 - max_b)
else:
    tmp_a = n//2 - max_2a + n//2 - max_b
    tmp_b = n//2 - max_a + n//2 - max_2b
    print(min(tmp_a,tmp_b))
n,m=map(int,input().split())

limit=int(m**(1/2))+1

divisors=[]
for d in range(limit):
    if m%d==0:
        divisors.append(d)
        divisors.append(m//d)
ans=1

for d in divisors:
    if n*d<=m:
        ans=d
print(ans)


### FIXED CODE ###

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

limit=int(m**(1/2))+1

divisors=[]
for d in range(1,limit):
    if m%d==0:
        divisors.append(d)
        divisors.append(m//d)

divisors.sort()
ans=1

for d in divisors:
    if n*d<=m:
        ans=d
print(ans)
from collections import Counter


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

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

A.sort()
B.sort()
A_cnt = Counter(A)
B_cnt = Counter(B)
if len(A) > 0:
    if max(A_cnt.values()) > 1:
        print(0)
        exit()
if len(B) > 0:
    if max(B_cnt.values()) > 1:
        print(0)
        exit()

a = 0
b = 0
i = 1
C = [0] * (N * M)
while i <= N * M:
    if i == A[a] and i == B[b]:
        C[i - 1] = 1
        a += 1
        b += 1
    elif i == A[a] and i != B[b]:
        C[i - 1] = M - b
        a += 1
    elif i != A[a] and i == B[b]:
        C[i - 1] = N - a
        b += 1
    else:
        C[i - 1] = (N - a) * (M - b) - (N * M - i)
    i += 1

ans = 1
mod = 10 ** 9 + 7
for c in C:
    ans = (ans * c) % mod

print(ans)


### FIXED CODE ###

from collections import Counter


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

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

A.sort()
B.sort()
A_cnt = Counter(A)
B_cnt = Counter(B)
if len(A) > 0:
    if max(A_cnt.values()) > 1:
        print(0)
        exit()
if len(B) > 0:
    if max(B_cnt.values()) > 1:
        print(0)
        exit()
if A[N - 1] != N * M or B[M - 1] != N * M:
    print(0)
    exit()

a = 0
b = 0
i = 1
C = [0] * (N * M)
while i <= N * M:
    if i == A[a] and i == B[b]:
        C[i - 1] = 1
        a += 1
        b += 1
    elif i == A[a] and i != B[b]:
        C[i - 1] = M - b
        a += 1
    elif i != A[a] and i == B[b]:
        C[i - 1] = N - a
        b += 1
    else:
        C[i - 1] = (N - a) * (M - b) - (N * M - i)
    i += 1

ans = 1
mod = 10 ** 9 + 7
for c in C:
    ans = (ans * c) % mod

print(ans)
n,k = map(int, input().split())
res = 0
a = 0
while res == 0:
    if k**(a-1) < n and n <= k**a:
        ans = a
        res += 1
        break
    a += 1
print(ans)

### FIXED CODE ###

n, r = map(int, input().split())
print( r if n >= 10 else r + (10-n)*100)
a,b = map(str,input().split())
cnt = 0
for i in range(1,101):
    if int(a+b) == i*i:
        print("Yes")
        cnt = 1
        break
if cnt == 0:
    prnt("No")

### FIXED CODE ###

a,b = map(str,input().split())
cnt = 0
for i in range(1,400):
    if int(a+b) == i*i:
        print("Yes")
        cnt = 1
        break
if cnt == 0:
    print("No")
a,b = input().split() # read two numbeers 

A = int(a)  # Declare the number to A
B = int(b) # declare the number to B

C = int(A*B) # we use int to truncate the fractional part of C
print(C) # print C

### FIXED CODE ###

str_a, str_b = input().split()
a = int(str_a)
b_100 = int(str_b.replace('.', ''))
print(a * b_100 // 100)
# import sys
# sys.setrecursionlimit(100000)
nCr = {}
def cmb(n, r):
  if r == 0 or r == n: return 1
  if r == 1: return n
  if (n,r) in nCr: return nCr[(n,r)]
  nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
  return nCr[(n,r)]


n,k = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort()
li = []
l = [1]
num = 1
cnt = 1
for i in range(n-1):
  if lis[i] == lis[i+1]:
    cnt += 1
    l.append(num)
  else:
    num = i + 2
    l.append(num)
    for _ in range(cnt):
      li.append(i+1)
    cnt = 1
for _ in range(cnt):
  li.append(n)

ans = 0
for i in range(n):
  if n-l[i] >= k-1:
    ans -= cmb(n-l[i],k-1) * lis[i]
  if i >= k-1:
    ans += cmb(i,k-1) * lis[i]
  if ans >= 10 ** 9 +7:
    ans %= 10 ** 9 + 7
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル


n,k = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort()
ans = 0
for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(n):
    if i >= k-1:
        ans += lis[i] * cmb(i,k-1,mod)
    if n-i-1 >= k-1:
        ans -= lis[i] * cmb(n-i-1,k-1,mod)
    ans %= 10 ** 9+7
print(ans)
c = 1
while True:
    x = input()
    if x == 0 else return
    print("Case ", c, ": ", x) 
    c += 1


### FIXED CODE ###

c = 1
while True:
    x = int(input())
    if x == 0: break
    print("Case {}: {}".format(c, x))
    c += 1
import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())
dist = np.diff(list(map(int, input().split())))

L = np.cumsum(np.array([1 / x for x in range(1, n)]))
n_1 = factorial(n-1)
# L *= n_1

# print(int((np.sum(L * dist) * n_1) % MOD))

ans = 0
for l, d in zip(L, dist):
    ans += l * d % MOD

ans = (ans * n_1 % MOD)
print(int(ans))

### FIXED CODE ###

import numpy as np
from math import factorial
MOD = 10**9 + 7

n = int(input())

dist = np.diff(list(map(int, input().split())))
L = np.cumsum(np.array([1 / x for x in range(1, n)]))
n_1 = factorial(n-1) % MOD

# fac = [1] * n
# for i in range(1,n):
# 	fac[i] = fac[i-1] * i % MOD

# print(int(np.sum(L * dist * n_1)) % MOD)
# ans = 0
# for l, d in zip(L, dist):
#     print("l d ", l * d)
#     ans += l * d
#     ans %= MOD

ans = 0
tmp = 0
for i, d in enumerate(dist):
    tmp += pow(i+1, MOD-2, MOD)
    ans += tmp * d
    ans %= MOD

# print(n_1)
print(ans * n_1 % MOD)
# print(int(np.sum(dist * L * n_1) % MOD))
import sys

memo = [line.strip() for line in sys.stdin]
at = ""
for i in len(memo):
    for j in len(memo[i]):
        if not memo[i][j].isdigit():
            at += "@"
        else:
            at += str(memo[i][j])
print(sum(at.replace("@", " ").split()))

### FIXED CODE ###

import re
ans = 0
while True:
    try:
        line = input()
    except:
        print(ans)
        break
    ans += sum(map(int, re.findall("[0-9]+", line)))
import numpy as np
N,M = map(int,input().split())
A = np.array(input().split(), dtype=np.int64)
A_cum = np.mod(A.cumsum(),M)

counter = np.bincount(A_cum)
counter[0] += 1 # empty
answer = (counter * (counter-1)).sum() // 2
print(answer)


### FIXED CODE ###

import numpy as np
from collections import Counter

N,M = map(int,input().split())
A = np.array([0]+[int(x) for x in input().split()],dtype=np.int64)
A_cum = np.mod(A.cumsum(),M)

c = Counter(A_cum)

answer = 0
for x in c.values():
  answer += x*(x-1)//2
print(answer)
from collections import deque

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

l = deque(list(map(int,input().split())))
count = 0
while count < x:
    count += l.popleft()

print(n-len(l)+1)

### FIXED CODE ###

from collections import deque

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

l = deque(list(map(int,input().split())))
count = 0

if sum(l) <= x:
    print(n+1)
else:
    while count <= x:
        count += l.popleft()
        if len(l) == 0:
            break

    print(n-len(l))
N = int(input())

a = []
for i in range(1,N + 1):
  count = 0
  while True:
    if i % 2 == 0:
      i /= 2
    count += 1
    else:
      break
  a.append(count)
print(a.index(max(a)) + 1)


### FIXED CODE ###

N = int(input())

a = []
for i in range(1,N + 1):
  count = 0
  while True:
    if i % 2 == 1:
      break
    else:
      i /= 2
      count += 1
  a.append(count)
print(a.index(max(a)) + 1)
n = int(input().split())
for num in range(n+1):
  total = total + num
print(total)

### FIXED CODE ###

n = int(input())
total = 0
for num in range(n+1):
  total = total + num
print(total)
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

kyori = abs(a - b)
sokudo = v-w

if kyori=<t*sokudo:
  print('YES')
else:
  print('NO')


### FIXED CODE ###

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

kyori = abs(a - b)
sokudo = v-w

if kyori<=t*sokudo:
  print('YES')
else:
  print('NO')
n=int(input())
price_list=[int(input()) for i in range(n)]
print(sum(price_list)-max(price_list)//2)

### FIXED CODE ###

print("Christmas"+" Eve"*(25-int(input())))
n = int(input())
a= list(map(int,input().split()))
if n == 1:
  print(n)
  exit()

a.sort()
if a[0] == 1:
  print(1)
  exit()

dp = [1] * n +[0]

def div(k):
  global dp
  if dp[k] != 0:
    for i in range(k):
      if a[k]%a[i] == 0:
        dp[k] = 0
        if a[k] == a[i]:dp[i] = 0
        break
  if k < n-1:div(k+1)

div(1)
print(sum(dp))

### FIXED CODE ###

from collections import Counter
n = int(input())
a= list(map(int,input().split()))
if n == 1:
  print(1)
  exit()

a.sort()

c = Counter(a)
a = list(set(a))
dp = [0] * (10**6 +1)

for x in a:
  t = x * 2
  while t <= 10**6:
    dp[t] = 1
    t += x

ans = 0
for x in a:
  if (c[x] == 1) & (dp[x] == 0):
    ans += 1

print(ans)
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)

### FIXED 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)
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')]*N
dp[0] = 0
 
 
for i in range(1,N):
  dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i)
print(dp[N-1])

### FIXED CODE ###

def test():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [float('inf')]*N
    dp[0] = 0
 
    for i in range(1, N):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()
import sys
n = int(input())
a = list(map(int, input().split()))

a = list(set(a))

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


if n <= 2:
    print(max(a))
else:
    a.sort()
    ans = max(gcd(a[0], a[-1]), gcd(a[1], a[-1]), gcd(a[0], a[-2]))
    print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
 
 
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)
 
 
L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
    L[i+1] = gcd(L[i], A[i])
 
for i in range(N-1, -1, -1):
    R[i] = gcd(R[i+1], A[i])
 
ans = 1
for i in range(N):
    ans = max(ans, gcd(L[i], R[i+1]))
 
print(ans)
import numpy as np
a,b,c=map(int, input().split())
r=c**2-(a**2+b**2)
if r>2*np.sqrt(ab):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b,c=map(int, input().split())
r=c-a-b
if r > 0 and r**2>4*a*b:
  print("Yes")
else:
  print("No")
s = list(map(str, input()))
k = int(input())

i=0

while i <= k:
	if s[i] =='1':
		ans = 1
		i += 1
	else:
		ans = s[i]
		break

print(ans)

### FIXED CODE ###

s = list(map(int, input()))
k = int(input())

i=0

while i <= k-1:
	if s[i] == 1:
		ans = 1
		i += 1
	else:
		ans = s[i]
		break

print(ans)