Simon has a prime number x and an array of non-negative integers a_1, a_2, ..., a_{n}.

Simon loves fractions very much. Today he wrote out number $\frac{1}{x^{a} 1} + \frac{1}{x^{a_{2}}} + \ldots + \frac{1}{x^{a_{n}}}$ on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: $\frac{s}{t}$, where number t equals x^{a}_1 + a_2 + ... + a_{n}. Now Simon wants to reduce the resulting fraction. 

Help him, find the greatest common divisor of numbers s and t. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (10^9 + 7).


-----Input-----

The first line contains two positive integers n and x (1 ≤ n ≤ 10^5, 2 ≤ x ≤ 10^9) — the size of the array and the prime number.

The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_1 ≤ a_2 ≤ ... ≤ a_{n} ≤ 10^9). 


-----Output-----

Print a single number — the answer to the problem modulo 1000000007 (10^9 + 7).


-----Examples-----
Input
2 2
2 2

Output
8

Input
3 3
1 2 3

Output
27

Input
2 2
29 29

Output
73741817

Input
4 5
0 0 0 0

Output
1



-----Note-----

In the first sample $\frac{1}{4} + \frac{1}{4} = \frac{4 + 4}{16} = \frac{8}{16}$. Thus, the answer to the problem is 8.

In the second sample, $\frac{1}{3} + \frac{1}{9} + \frac{1}{27} = \frac{243 + 81 + 27}{729} = \frac{351}{729}$. The answer to the problem is 27, as 351 = 13·27, 729 = 27·27.

In the third sample the answer to the problem is 1073741824 mod 1000000007 = 73741817.

In the fourth sample $\frac{1}{1} + \frac{1}{1} + \frac{1}{1} + \frac{1}{1} = \frac{4}{1}$. Thus, the answer to the problem is 1.

Difficulty: interview

Starter code:

Solutions:
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
def solve(a, s):
  #print (a)
  a.append((-1, 0))
  a.sort()
  b = []
  for i in range(1, len(a)):
    if a[i][0] != a[i-1][0]:
      b.append(a[i])
    else:
      b[-1] = (a[i][0], b[-1][1] + a[i][1])
  for i in range(len(b)):
    t = b[i][1]
    cnt = 0
    while t%x == 0:
      t //= x
      cnt += 1
    b[i] = (b[i][0] + cnt, t)
  #print (b)
  z = min(min(b)[0], s)
  if z == 0:
    return 0
  return z + solve([(x[0]-z, x[1]) for x in b], s-z)
s = sum(a)
print(pow(x, solve([(s-x, 1) for x in a], s), 10**9+7))

3

def readln(): return tuple(map(int, input().split()))

n, x = readln()
a = readln()
m = max(a)
ans = sum(a) - m
cnt = {}
for v in a:
    cnt[m - v] = cnt.get(m - v, 0) + 1
while True:
    k = min(cnt.keys())
    v = cnt[k]
    c = 0
    while v % x == 0:
        c += 1
        v //= x
    #print(cnt, k, cnt[k], c, v)
    if c:
        cnt[k + c] = cnt.get(k + c, 0) + v
        cnt.pop(k)
    else:
        break
    #print(cnt)
print(pow(x, ans + min(min(cnt.keys()), m), 10**9 + 7))


MOD = 10**9+7
def pow(x, n, MOD):
    if(n==0):
        return 1
    if(n%2==0):
        a = pow(x, n//2, MOD)
        return a*a % MOD
    else:
        a = pow(x, n//2, MOD)
        return (x*a*a) % MOD

n, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
s = sum(a)
d = []

for el in a:
	d.append(s-el)

d.sort()
i=0
gcd = d[0]
c=0
while i<n and d[i]==gcd:
	c+=1
	i+=1

while c%x==0:
	c=c//x
	gcd+=1
	
	while i<n and d[i]==gcd:
		c+=1
		i+=1
		
if gcd>s:
	gcd = s
	
print( pow(x, gcd, MOD) )


n, x = map(int, input().split())
t = list(map(int, input().split()))
b = max(t)
k = t.count(b)
r = sum(t)
s = r - b
while k % x == 0:
    b -= 1
    s += 1
    k = k // x + t.count(b)
print(pow(x, min(r, s), 1000000007))

input_str = input()
n, x = int(input_str.split()[0]), int(input_str.split()[1])
input_str = input()
a = input_str.split()
s = 0
for i in range(n):
    a[i] = int(a[i])
    #a.append(1000000000)
    s += a[i]

'''
a = []
for i in range(n):
    if i<65536:
        temp = 1
    else:
        temp = 0#random.randint(0, 1000000000)
    s += temp
    a.append(temp)#(557523474, 999999999))'''

sum_a = [s-a[i] for i in range(n)]
minimum = min(sum_a)
res = pow(x, minimum, 1000000007)#FastPow(x, minimum)#x**minimum
sum_xa = 0
s_new = s - minimum
for i in range(n):
    sum_xa += pow(x, s_new - a[i], 1000000007)#FastPow(x, s_new - a[i])

deg = 0
deg_zn = s-minimum
ts = sum_xa
while sum_xa%1==0 and deg_zn:
    sum_xa /= x
    deg += 1 
    deg_zn -= 1
  #  print (deg, sum_xa%1==0)
#if (n, x) == (98304, 2):
#    print (minimum, s, ts, deg)


if deg:
    res *= pow(x, deg-1 if sum_xa%1!=0 else deg)
print (res%1000000007)

n, x = list(map(int, input().split(' ')))
arr = list(map(int, input().split(' ')))
sx = sum(arr)
adds = [sx - i for i in arr]
adds.sort()
while adds.count(adds[0]) % x == 0:
    ct = adds.count(adds[0])
    addsok = ct // x
    adds = [adds[0]+1] * addsok + adds[ct:]

print(pow(x, min(min(adds), sx), (10**9+7)))


n, x = list(map(int, input().split(' ')))
arr = list(map(int, input().split(' ')))
tot = sum(arr) - max(arr)
sx = sum(arr)
adds = [sx - tot - i for i in arr]
adds.sort()

while adds.count(adds[0]) % x == 0:
    ct = adds.count(adds[0])
    addsok = ct // x
    adds = [adds[0]+1] * addsok + adds[ct:]

print(pow(x, (min(tot + min(adds), sx)), (10**9+7)))


#!/usr/bin/env python3

import sys
import heapq

n, x = list(map(int, sys.stdin.readline().split()))
a = list(map(int, sys.stdin.readline().split()))
s = sum(a)

h = []
for y in a:
    heapq.heappush(h, s - y)

p, cnt = 0, 0

while len(h) > 0:
    z = heapq.heappop(h)
    if p == z:
        cnt += 1
        if cnt == x:
            heapq.heappush(h, p + 1)
            cnt = 0
    else:
        if cnt != 0:
            print(pow(x, min(p, s), 10 ** 9 + 7))
            return
        cnt = 1
        p = z

print(pow(x, min(p, s), 10 ** 9 + 7))


#!/usr/bin/env python3

import sys
import heapq

n, x = list(map(int, sys.stdin.readline().split()))
a = list(map(int, sys.stdin.readline().split()))
s = sum(a)

h = []
for y in a:
    heapq.heappush(h, s - y)

p, cnt = 0, 0

while len(h) > 0:
    z = heapq.heappop(h)
    if p == z:
        cnt += 1
        if cnt == x:
            heapq.heappush(h, p + 1)
            cnt = 0
    else:
        if cnt != 0:
            print(pow(x, min(p, s), 10 ** 9 + 7))
            return
        cnt = 1
        p = z

print(pow(x, min(p, s), 10 ** 9 + 7))


n, x = map(int, input().split())
t = list(map(int, input().split()))
b = max(t)
k = t.count(b)
r = sum(t)
s = r - b
while k % x == 0:
    b -= 1
    s += 1
    k = k // x + t.count(b)
print(pow(x, min(r, s), 1000000007))

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

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

b = max(t)

k = t.count(b)

r = sum(t)

s = r - b

while k % x == 0:

    b -= 1

    s += 1

    k = k // x + t.count(b)

print(pow(x, min(r, s), 1000000007))



# Made By Mostafa_Khaled


modulus = 10 ** 9 + 7


def main():
    n, x = list(map(int, input().split()))
    arr = list(map(int, input().split()))

    total = sum(arr)
    powers = [total - x for x in arr]
    powers.sort(reverse=True)

    while True:

        low = powers[len(powers) - 1]

        cnt = 0

        while len(powers) > 0 and powers[len(powers) - 1] == low:
            cnt += 1
            powers.pop()

        if cnt % x == 0:
            cnt = cnt // x
            for i in range(cnt):
                powers.append(low + 1)
        else:
            low = min(low, total)
            print(pow(x, low, modulus))
            return


def __starting_point():
    main()

__starting_point()

modulus = 10 ** 9 + 7


def main():
    n, x = list(map(int, input().split()))
    arr = list(map(int, input().split()))

    total = sum(arr)
    powers = [total - x for x in arr]
    powers.sort(reverse=True)

    while True:

        low = powers[len(powers) - 1]

        cnt = 0

        while len(powers) > 0 and powers[len(powers) - 1] == low:
            cnt += 1
            powers.pop()

        if cnt % x == 0:
            cnt = cnt // x
            for i in range(cnt):
                powers.append(low + 1)
        else:
            low = min(low, total)
            print(pow(x, low, modulus))
            return


def __starting_point():
    main()

__starting_point()

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

total = sum(a)
biggest = max(a)

exp = total - biggest

hm = a.count(biggest)
while hm%x == 0:	
	biggest -= 1
	exp += 1
	hm = hm//x + a.count(biggest)

if exp > total:
	exp = total
print(pow(x, exp, 1000000007))

modulus = 10**9 +7

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

tot = sum(s)
powers=[tot-x for x in s]
powers.sort(reverse=True)

while True:

    low=powers[-1]
    cnt = 0
    while len(powers) > 0 and powers[-1]==low:
        cnt += 1
        powers.pop()
    if cnt%x==0:
        cnt=cnt // x
        for n in range(cnt):
            powers.append(low+1)
    else:
        low = min(low, tot)
        print(pow(x, low, modulus))
        return


n,x=list(map(int,input().split()))
l=list(map(int,input().split()))
from collections import Counter
l.sort()
gcd=sum(l[:n-1])
m=10**9+7
s=sum(l)
l1=[]
for i in l:
    l1.append(s-i-gcd)
c=Counter(l1)
l2=[]
for i in c:
    l2.append(i)
l2.sort()
z=True
while z:
    z=False
    for i in c.copy():
        a=c[i]
        b=0
        while a%x==0 and a!=0:
            z=True
            a//=x
            b+=1
        if z:
            c[i+b]+=a
            c[i]=0
y=l[-1]
for i in c:
    if c[i]:
        y=min(y,i)
gcd+=y
print(pow(x,min(s,gcd),m))

    
        


#########			##	##     ##    	  ####  #####  ##     #  ##     #		##
	#			   # #	# #   # #		 #	  #	#	#  # #    #  # #    #	   # #
	#			  #  #	#  ###  #	    #		#	#  #  #   #  #  #   #	  #  #
	#			 #####	#	#	#	   #    ###	#	#  #   #  #  #   #  #    #####
	#			#    #	#		#	   #    # #	#	#  #	# #  #	  # #   #    #  
######### 	   #     # 	#		#		##### #	#####  #	 ##  #	   ##  #     #

"""

PPPPPPP       RRRRRRR		    OOOO	  VV        VV    EEEEEEEEEE
PPPPPPPP      RRRRRRRR         OOOOOO     VV       VV	  EE
PPPPPPPPP     RRRRRRRRR       OOOOOOOO    VV      VV	  EE
PPPPPPPP      RRRRRRRR        OOOOOOOO    VV     VV    	  EEEEEE
PPPPPPP       RRRRRRR         OOOOOOOO    VV    VV        EEEEEEE
PP  		  RRRR			  OOOOOOOO    VV   VV         EEEEEE
PP			  RR  RR          OOOOOOOO    VV  VV          EE
PP			  RR    RR         OOOOOO     VV VV           EE
PP			  RR      RR        OOOO      VVVV            EEEEEEEEEE

"""



"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;
 
def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x
 
def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val
    
# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;
 
## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## lcm function
def lcm(a, b):
	return (a * b) // gcd(a, b)
 
## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)
 
## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0, hi = None):
    if hi == None:
        hi = len(a);
    while lo < hi:
        mid = (lo+hi)//2;
        if a[mid] < x:
            lo = mid+1;
        else:
            hi = mid;
    return lo;
 
## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes
 
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 
 
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;
 
# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];
 
# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;
 
 
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x
 
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n): 
    prime = [True for i in range(n+1)] 
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

# Euler's Toitent Function phi
def phi(n) : 
  
    result = n 
    p = 2
    while(p * p<= n) : 
        if (n % p == 0) : 
            while (n % p == 0) : 
                n = n // p 
            result = result * (1.0 - (1.0 / (float) (p))) 
        p = p + 1
    if (n > 1) : 
        result = result * (1.0 - (1.0 / (float)(n))) 
   
    return (int)(result) 

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
 
	return True
 
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array
 
################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))
 
## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));
 
def float_array():
    return list(map(float, input().strip().split()));
 
## taking string array input
def str_array():
    return input().strip().split();
 
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
 
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
 
from itertools import permutations
import math

from bisect import bisect_left



def solve():
	n, x = list(map(int, input().split()))
	powers = list(map(int, input().split()))
	summ = sum(powers)
	biggest = max(powers)
	p = summ - biggest
	number_of_powers = powers.count(biggest)
	while number_of_powers % x == 0:
		biggest -= 1
		p += 1
		number_of_powers = number_of_powers // x + powers.count(biggest)
	if p > summ:
		p = summ
	print(pow(x, p, MOD))

def __starting_point():
	for _ in range(1):
		solve()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))

__starting_point()

#########			##	##     ##    	  ####  #####  ##     #  ##     #		##
	#			   # #	# #   # #		 #	  #	#	#  # #    #  # #    #	   # #
	#			  #  #	#  ###  #	    #		#	#  #  #   #  #  #   #	  #  #
	#			 #####	#	#	#	   #    ###	#	#  #   #  #  #   #  #    #####
	#			#    #	#		#	   #    # #	#	#  #	# #  #	  # #   #    #  
######### 	   #     # 	#		#		##### #	#####  #	 ##  #	   ##  #     #

"""

PPPPPPP       RRRRRRR		    OOOO	  VV        VV    EEEEEEEEEE
PPPPPPPP      RRRRRRRR         OOOOOO     VV       VV	  EE
PPPPPPPPP     RRRRRRRRR       OOOOOOOO    VV      VV	  EE
PPPPPPPP      RRRRRRRR        OOOOOOOO    VV     VV    	  EEEEEE
PPPPPPP       RRRRRRR         OOOOOOOO    VV    VV        EEEEEEE
PP  		  RRRR			  OOOOOOOO    VV   VV         EEEEEE
PP			  RR  RR          OOOOOOOO    VV  VV          EE
PP			  RR    RR         OOOOOO     VV VV           EE
PP			  RR      RR        OOOO      VVVV            EEEEEEEEEE

"""



"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;
 
def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x
 
def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val
    
# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;
 
## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## lcm function
def lcm(a, b):
	return (a * b) // gcd(a, b)
 
## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)
 
## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0, hi = None):
    if hi == None:
        hi = len(a);
    while lo < hi:
        mid = (lo+hi)//2;
        if a[mid] < x:
            lo = mid+1;
        else:
            hi = mid;
    return lo;
 
## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes
 
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 
 
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;
 
# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];
 
# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;
 
 
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x
 
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n): 
    prime = [True for i in range(n+1)] 
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

# Euler's Toitent Function phi
def phi(n) : 
  
    result = n 
    p = 2
    while(p * p<= n) : 
        if (n % p == 0) : 
            while (n % p == 0) : 
                n = n // p 
            result = result * (1.0 - (1.0 / (float) (p))) 
        p = p + 1
    if (n > 1) : 
        result = result * (1.0 - (1.0 / (float)(n))) 
   
    return (int)(result) 

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
 
	return True
 
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array
 
################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))
 
## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));
 
def float_array():
    return list(map(float, input().strip().split()));
 
## taking string array input
def str_array():
    return input().strip().split();
 
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
 
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
 
from itertools import permutations
import math

from bisect import bisect_left



def solve():
	n, x = list(map(int, input().split()))
	powers = list(map(int, input().split()))
	summ = sum(powers)
	biggest = max(powers)
	p = summ - biggest
	number_of_powers = powers.count(biggest)
	while number_of_powers % x == 0:
		biggest -= 1
		p += 1
		number_of_powers = number_of_powers // x + powers.count(biggest)
	if p > summ:
		p = summ
	print(pow(x, p, MOD))

def __starting_point():
	for _ in range(1):
		solve()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))

__starting_point()