Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.

Here are some interesting facts about XXX:  XXX consists of n cities, k of whose (just imagine!) are capital cities.  All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to c_{i}.  All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 — 2 — ... — n — 1. Formally, for every 1 ≤ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.  Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 ≤ i ≤ n,  i ≠ x, there is a road between cities x and i.  There is at most one road between any two cities.  Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals c_{i}·c_{j}.

Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products c_{a}·c_{b}. Will you help her?


-----Input-----

The first line of the input contains two integers n and k (3 ≤ n ≤ 100 000, 1 ≤ k ≤ n) — the number of cities in XXX and the number of capital cities among them.

The second line of the input contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10 000) — beauty values of the cities.

The third line of the input contains k distinct integers id_1, id_2, ..., id_{k} (1 ≤ id_{i} ≤ n) — indices of capital cities. Indices are given in ascending order.


-----Output-----

Print the only integer — summary price of passing each of the roads in XXX.


-----Examples-----
Input
4 1
2 3 1 2
3

Output
17
Input
5 2
3 5 2 2 4
1 4

Output
71


-----Note-----

This image describes first sample case:

[Image]

It is easy to see that summary price is equal to 17.

This image describes second sample case:

[Image]

It is easy to see that summary price is equal to 71.

Difficulty: interview

Starter code:

Solutions:
from sys import stdin


n, k = list(map(int, input().split()))
our = list(map(int, input().split()))
cap = set(map(int, input().split()))
res = 0
sum_b = sum(our)
for elem in cap:
    sum_b -= our[elem - 1]
    res += sum_b * our[elem - 1]
for i in range(len(our)):
    if (i + 1) not in cap and (i + 1) % n + 1 not in cap:
        res += our[i] * our[(i + 1) % n]
print(res)


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

ans = 0
SUM = 0
FRE = [0] * n
for i in range(k):
    cap[i] -= 1
    SUM += c[cap[i]]
    FRE[cap[i]] = 1

tot = sum(c)

for i in range(n):
    if FRE[i] == 0:
        if FRE[(i + n - 1) % n] == 0:
            ans += c[i] * c[(i + n - 1) % n]
        if FRE[(i + n + 1) % n] == 0:
            ans += c[i] * c[(i + n + 1) % n]
        ans += c[i] * SUM
    else:
        ans += c[i] * (tot - c[i])

print(ans >> 1)
    


n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=set(map(int,input().split()))
t=0
p=0
q=0
s=0
for i, x in enumerate(a):
    if i+1 in b:
        t += x*s
        p += x - q
        q = 0
    else:
        t += x*p
        p += x - q
        q = x
    s += x
if n not in b and 1 not in b:
    t += a[-1]*a[0]
print(t)


n, k = [int(i) for i in input().split()]
s = [[int(i), 0] for i in input().split()]
c = [int(i) for i in input().split()]
for i in c:
	s[i-1][1] = 1
a = 0
for i in s:
	a+=i[0]
ans = 0
for i in range(n-1):
	if s[i][1]:
		a-=s[i][0]
		ans += s[i][0]*(a)
	else:
		if not s[i+1][1]:
			ans+=s[i][0]*s[i+1][0]
if s[n-1][1]:
	a-=s[n-1][0]
	ans += s[n-1][0]*(a)
else:
	if not s[0][1]:
		ans+=s[n-1][0]*s[0][0]
print(ans)


n, m = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
ans = 0
for i in range(n - 1):
    ans += c[i] * c[i + 1]
ans += c[0] * c[n - 1]
s = sum(c)

k = list(map(int, input().split(' ')))
v = [0] * n
for i in k:
    if v[i - 1]:
        continue
    v[i - 1] = 1
    s -= c[i - 1]
    ans += s * c[(i - 1 + n) % n]
    if not v[(i - 2 + n) % n]:
        ans -= c[i - 1] * c[(i - 2 + n) % n]
    if not v[i % n]:
        ans -= c[i - 1] * c[i % n]

print(ans)


n,k=input().split()
n,k=int(n),int(k)
beaut=[]
ans=0
sum=0
cap=[0 for i in range(n)]
beaut=[int(i) for i in input().split()]
v=[int(i) for i in input().split()]
for i in range(n):
	sum=sum+beaut[i]
for i in range(k):
	cap[v[i]-1]=1

for i in range(n):
	if(cap[i]==1):
		sum=sum-beaut[i]
		ans=ans+beaut[i]*sum

for i in range(n):
	if(cap[i]==0):
		if(cap[(i+1)%n]==0):
			ans=ans+beaut[i]*beaut[(i+1)%n]
print(ans)

n, k = map(int, input().split())
prices = list(map(int, input().split()))
st = list(map(int, input().split()))
for i in range(k):
    st[i] -= 1
ans = 0
used = 0
useds = set()
s = sum(prices)
for i in range(n):
    ans += prices[i] * prices[i - 1]
for i in range(k):
    ans += s * prices[st[i]] - prices[st[i]] * used
    ans -= prices[st[i]] * (prices[st[i]] + prices[st[i] - 1] + prices[(st[i] + 1) % n])
    if (st[i] - 1) % n in useds:
        ans += prices[st[i]] * prices[st[i] - 1]
    if (st[i] + 1) % n in useds:
        ans += prices[st[i]] * prices[(st[i] + 1) % n]    
    used += prices[st[i]]
    useds.add(st[i])
print(ans)

n, m = list(map(int,input().split()))
cost = list(map(int,input().split()))
iscapi = [False]*n
capi = list([int(x)-1 for x in input().split()])
#print(capi)
for i in capi:
    iscapi[i]  = True
tot = 0
sumi = 0
for i in range(0,n):
    if not iscapi[i] and not iscapi[(i+1)%n]:
        tot += cost[i]*cost[(i+1)%n]
#print(tot)

price = [cost[i] for i in capi]
#print(price)
for i in range(m-2,-1,-1):
    price[i] += price[i+1]
#print(price)
for i in range(m-1):
    tot += cost[capi[i]]*price[i+1]
#print(tot)

for i in range(n):
    if not iscapi[i]:
        sumi += cost[i]
#print(sumi)
for i in capi:
    tot += cost[i]*sumi
print(tot)
    

    


n, k = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
capitals = set([int(x) - 1 for x in input().split()])

r = c[0] * c[-1]

for i in range(n-1):
    r += c[i] * c[i+1]

c_sum = sum(c)

for i in capitals:
    k = c_sum - c[i] - c[(i-1)%n]
    if (i+1)%n not in capitals:
        k -= c[(i+1)%n]
    r += c[i] * k
    c_sum -= c[i]

print(r)


import math

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

res = 0
sum = 0

arr = [int(x) for x in input().split()]
arrK = [int(x) - 1 for x in input().split()]

for i in range(0, N):
    res += arr[i] * arr[i - 1]
    sum += arr[i]

dictU = {}
used = 0
for i in arrK:
    cur = i
    if cur == 0:
        pre = N-1
    else:
        pre = cur - 1
    if cur == N-1:
        next = 0
    else:
        next = cur + 1
    tmp = 0
    if pre in dictU:
        tmp += arr[pre]
    if next in dictU:
        tmp += arr[next]

    test = arr[cur] * (sum - arr[cur] - arr[pre] - arr[next] - used + tmp)
    res += test
    dictU[cur] = True
    #print(res, test, cur)
    used += arr[cur]

print(res)










n,k = list(map(int,input().split()))
ci = list(map(int,input().split()))
idi = list(map(int,input().split()))
idi += [n+1]
num3 = sum(ci)
num = 0
num2 = 0
ans = 0
num4 = 0
if idi[num] == 1:
    num += 1
    num2 += ci[0]
    ans += (num3-num2)*ci[0]
    num4 = 0
else:
    ans += ci[1]*ci[0]
    num4 = 1
for i in range(2,n):
    if idi[num] == i:
        num2 += ci[i-1]
        ans += (num3-num2-ci[i-2]*num4)*ci[i-1]
        num += 1
        num4 = 0
    else:
        ans += ci[i]*ci[i-1]
        num4 = 1
if idi[k-1] == n:
        num2 += ci[n-1]
        ans += (num3-num2-ci[n-2]*num4)*ci[n-1]
        num += 1
if idi[0] != 1 and idi[k-1] != n:
    ans += ci[n-1] * ci[0]
print(ans)


t = input
p = print
r = range
n, k = map(int, t().split())
cities_beauty = list(map(int, t().split()))
capital = set(map(int, t().split()))
cities = set([i for i in r(1, n + 1)])
cities = cities ^ capital

ans = 0
city_sum = 0
for city in cities:
    if city == 1 and n in cities:
        ans += (cities_beauty[0] * cities_beauty[-1])
    if (city + 1) in cities and city != n:
        ans += (cities_beauty[city - 1] * cities_beauty[city])
    city_sum += cities_beauty[city - 1]

cap_sum = 0
for cap in capital:
    ans += cities_beauty[cap - 1] * city_sum
    cap_sum += cities_beauty[cap - 1]

for cap in capital:
    cap_sum -= cities_beauty[cap - 1]
    ans += cities_beauty[cap - 1] * cap_sum

p(ans)


n,m = map(int,input().split())
a = list(map(int,input().split()))
c = list(map(int,input().split()))
cap = [0]*(n+1)
for i in c:
    cap[i-1] = 1
ans = 0
s = sum(a)
for i in range(len(a)-1):
    if cap[i]==1:
        s -= a[i]
        ans += s*a[i]
        #print("s :", s)
        #print("a[i] :", a[i])
    elif cap[i] ==0 and cap[i+1] == 0:
        #print("a[i] :",a[i])
        #print("a[i+1] :",a[i+1])
        ans += a[i] * a[i+1]

#print(cap)
if cap[n-1] == 1:
    s -= a[-1]
    ans += s*a[-1]
    #print("s :",s)
    #print("a[i] :",a[-1])
if cap[0] == 0 and cap[n-1]==0:
    ans += a[0] * a[-1]
    print(ans)
else:
    print(ans)

n, k = list(map(int, str.split(input())))
cities = tuple(map(int, str.split(input())))
capitales = set([int(s) - 1 for s in str.split(input())])

total_weight = sum(cities)
capitales_weight = sum(map(cities.__getitem__, capitales))
weight = 0
for i in range(n):

    if i in capitales:

        sub_weight = total_weight - capitales_weight
        next_city = (i + 1) % n
        if next_city not in capitales:

            sub_weight -= cities[next_city]

    else:

        sub_weight = cities[(i - 1) % n]

    weight += sub_weight * cities[i]

past_sub_weight = 0
for i in sorted(capitales):

    weight += past_sub_weight * cities[i]
    past_sub_weight += cities[i]

print(weight)


n, k = list(map(int, input().split()))
c = list(map(int, input().split()))
d = set(map(int, input().split()))

s = 0
s0 = sum(c)

for i in d:
    s0 -= c[i - 1]
    s += s0 * c[i - 1]

for i in range(n):
    if i + 1 not in d and (i + 1) % n + 1 not in d:
        s += c[i] * c[(i + 1) % n]

print(s)


n, k = list(map(int, input().split()))
c = list(map(int, input().split()))
d = set(map(int, input().split()))

s = 0
s0 = sum(c)

for i in d:
    s0 -= c[i - 1]
    s += c[i - 1] * s0

for i in range(n):
    if i + 1 not in d and (i + 1) % n + 1 not in d:
        s += c[i] * c[(i + 1) % n]

print(s)


n, k = map(int, input().split())
C = [0] + list(map(int, input().split()))
K = set(map(int, input().split()))

F = [0] * (n + 1)
G = [0] * (n + 2)

for i in range(1, n + 1):
   F[i] = F[i-1] + C[i]
   if i in K:
      G[i] = G[i - 1]
   else:
      G[i] = G[i-1] + C[i]

#print(F)
#print(G)

summa = 0
for i in range(1, n + 1):
   if i in K:
      summa += G[i-2] * C[i]
      summa += (F[n] - F[i ]) * C[i]
      #print(i, G[i-2] * C[i], (F[n] - F[i ]) * C[i])

   elif i < n:
      summa += C[i] * C[i + 1] 

   elif i == n and 1 not in K:
      summa += C[1] * C[i]

 
   
print(summa)

def main():
    n,k = map(int, input().split())
    beauty= list(map(int, input().split()))
    capitals= set(map(int, input().split()))
    result = balans = 0
    for i in range(n):      
        if ((i+1) not in capitals) and ( (i + 1) % n) + 1 not in capitals:
            balans = beauty[i]*beauty[(i+1)%n]
            result+= balans
    balans= sum(beauty)
    for i in capitals:
        balans-=beauty[i-1]
        result+=balans*beauty[i-1]
    print (result)
        
main()

n,k=list(map(int,input().split()))
c=list(map(int,input().split()))
s=set(map(int,input().split()))
sust=sum(c)
su=0
for i in s:
    sust-=c[i-1]
    su+=c[i-1]*sust
for i in range(n):
    if (i+1 not in s) and ((i+1)%n+1 not in s):
        su+=c[i]*c[(i+1)%n]
print(su)


n, k = map(int, input().split())
cost = [0] + list(map(int, input().split()))
capitals = set(map(int, input().split()))

town_sum = [0] * (n + 1)
no_cap_sum = [0] * (n + 2)

for i in range(1, n + 1):
    town_sum[i] = town_sum[i - 1] + cost[i]
    if i in capitals:
        no_cap_sum[i] = no_cap_sum[i - 1]
    else:
        no_cap_sum[i] = no_cap_sum[i - 1] + cost[i]
      
ans = 0

for i in range(1, n + 1):
    if i in capitals:
        ans += (town_sum[n] - town_sum[i]) * cost[i]
        ans += no_cap_sum[i - 2] * cost[i]
        
    elif i < n:
        ans += cost[i] * cost[i + 1]
        
    elif i == n and 1 not in capitals:
        ans += cost[1] * cost[i]
        
print(ans)



n, k = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
capitals = set([int(x) - 1 for x in input().split()])

r = c[0] * c[-1]

for i in range(n-1):
    r += c[i] * c[i+1]

c_sum = sum(c)

for i in capitals:
    k = c_sum - c[i] - c[(i-1)%n]
    if (i+1)%n not in capitals:
        k -= c[(i+1)%n]
    r += c[i] * k
    c_sum -= c[i]

print(r)



n, k = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
capitals = set([int(x) - 1 for x in input().split()])

r = c[0] * c[-1]

for i in range(n-1):
    r += c[i] * c[i+1]

c_sum = sum(c)

for i in capitals:
    k = c_sum - c[i] - c[(i-1)%n]
    if (i+1)%n not in capitals:
        k -= c[(i+1)%n]
    r += c[i] * k
    c_sum -= c[i]

print(r)

n, k = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
capitals = set([int(x) - 1 for x in input().split()])

r = c[0] * c[-1]

for i in range(n-1):
    r += c[i] * c[i+1]

c_sum = sum(c)

for i in capitals:
    k = c_sum - c[i] - c[(i-1)%n]
    if (i+1)%n not in capitals:
        k -= c[(i+1)%n]
    r += c[i] * k
    c_sum -= c[i]

print(r)

n, k = map(int, input().split())
c = list(map(int, input().split()))
v = c[0] * c[n - 1] + sum(c[i] * c[i + 1] for i in range(n - 1))
s, ss, cs = set(), 0, sum(c)
for k in map(int, input().split()):
    a, b, x = n if k == 1 else k - 1, 1 if k == n else k + 1, 0
    if a not in s:
        x += c[a - 1]
    if b not in s:
        x += c[b - 1]
    v += c[k - 1] * (cs - c[k - 1] - ss - x)
    s.add(k)
    ss += c[k - 1]
print(v)

n, k = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
ids = [(int(x)-1) for x in input().split()]

s = sum(c)
ans = 0
for i in range(n):
  ans += (c[i] * c[(i+1)%n])
for i in range(k):
  if (abs(ids[i] - ids[(i+1)%k]) == 1) or (ids[i] == n-1 and ids[0] == 0):
    ans += c[ids[i]]*c[ids[(i+1)%k]]
temp = 0
for i in range(k):
  ans += c[ids[i]] * (s - c[(ids[i]-1)%n] - c[(ids[i]+1)%n] - c[ids[i]])
  ans -= c[ids[i]]*temp
  temp += c[ids[i]]
  

print(repr(ans))