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: MEDIUM

Solutions:
(n, k) = map(int, str.split(input()))
cities = tuple(map(int, str.split(input())))
capitales = set(map(lambda s: int(s) - 1, 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) = map(int, input().split())
A = list(map(int, input().split()))
cap = set(map(int, input().split()))
price = res = 0
for i in range(len(A)):
	if i + 1 not in cap and (i + 1) % n + 1 not in cap:
		price = A[i] * A[(i + 1) % n]
		res += price
price = sum(A)
for i in cap:
	price -= A[i - 1]
	res += price * A[i - 1]
print(res)


input()
(l, c, t) = (list(map(int, input().split())), [int(s) - 1 for s in input().split()], 0)
s = sum(l)
for i in c:
	(x, l[i]) = (l[i], 0)
	s -= x
	t += s * x
print(t + sum((l[i] * x for (i, x) in enumerate(l, -1))))


(n, m) = 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) = 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, 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] = list(map(int, input().split()))
c = list(map(int, input().split()))
x = list(map(int, input().split()))
res = 0
for i in range(n):
	res += c[i] * c[(i + 1) % n]
tot = 0
for i in range(n):
	tot += c[i]
for i in range(k):
	j = x[i] - 1
	res += c[j] * (tot - c[j] - c[(j - 1 + n) % n] - c[(j + 1) % n])
ctot = 0
for i in range(k):
	j = x[i] - 1
	ctot += c[j]
tmp = 0
for i in range(k):
	j = x[i] - 1
	jp = x[(i - 1 + k) % k] - 1
	jn = x[(i + 1) % k] - 1
	tmp += c[j] * (ctot - c[j])
	if (jp + 1) % n == j:
		tmp -= c[j] * c[jp]
	if (jn - 1 + n) % n == j:
		tmp -= c[j] * c[jn]
tmp = tmp // 2
res -= tmp
print(res)


(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]
	elif cap[i] == 0 and cap[i + 1] == 0:
		ans += a[i] * a[i + 1]
if cap[n - 1] == 1:
	s -= a[-1]
	ans += s * a[-1]
if cap[0] == 0 and cap[n - 1] == 0:
	ans += a[0] * a[-1]
	print(ans)
else:
	print(ans)


(n, k) = map(int, input().split())
iscap = [0] * (n + 10)
ans1 = 0
ans2 = 0
ans3 = 0
s = 0
s2 = 0
c = list(map(int, input().split()))
data = list(map(int, input().split()))
for i in data:
	iscap[i - 1] = 1
for i in c:
	s += i
for i in data:
	s2 += c[i - 1]
for i in range(n):
	if iscap[i] == 1:
		temp = s - c[i]
		ans1 += temp * c[i]
		temp = 0
		if i - 1 == -1:
			if iscap[n - 1] == 0:
				temp += c[n - 1]
		elif iscap[i - 1] == 0:
			temp += c[i - 1]
		if i + 1 == n:
			if iscap[0] == 0:
				temp += c[0]
		elif iscap[i + 1] == 0:
			temp += c[i + 1]
		ans2 += temp * c[i]
	else:
		temp = 0
		if i - 1 == -1:
			temp += c[n - 1]
		else:
			temp += c[i - 1]
		if i + 1 == n:
			temp += c[0]
		else:
			temp += c[i + 1]
		ans1 += temp * c[i]
		ans2 += temp * c[i]
for i in range(k):
	ans3 += c[data[i] - 1] * (s2 - c[data[i] - 1])
ans2 //= 2
ans3 //= 2
print(ans1 - ans2 - ans3)


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


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


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
b = list(map(int, input().split()))
c = list(map(int, input().split()))
s = sum(b)
r = 0
for i in c:
	s -= b[i - 1]
	r += s * b[i - 1]
for i in c:
	b[i - 1] = 0
r += b[0] * b[-1]
for i in range(n - 1):
	r += b[i] * b[i + 1]
print(r)


import sys
(n, k) = map(int, sys.stdin.readline().split())
beauty = [int(x) for x in sys.stdin.readline().split()]
indices = [int(x) - 1 for x in sys.stdin.readline().split()]
s = sum(beauty)
price = 0
for i in indices:
	price += beauty[i] * (s - beauty[i])
	s -= beauty[i]
	beauty[i] = 0
for i in range(n - 1):
	price += beauty[i] * beauty[i + 1]
price += beauty[0] * beauty[-1]
sys.stdout.write(str(price))


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


(n, k) = 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) = map(int, input().split())
a = list(map(int, input().split()))
cap = [0 for i in range(n)]
c = list(map(int, input().split()))
for i in c:
	cap[i - 1] = 1
s = sum(a)
ans = 0
for i in range(n):
	if cap[i] == 1:
		ans += a[i] * (s - a[i])
		s -= a[i]
	elif cap[i - 1] != 1:
		ans += a[i] * a[i - 1]
print(ans)


[n, k] = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
ids = [int(x) for x in input().split()]
s = [0 for x in range(n + 1)]
s[0] = 0
for i in range(1, n + 1):
	s[i] = s[i - 1] + c[i - 1]
q = c[0] * c[n - 1]
for i in range(n - 1):
	q += c[i] * c[i + 1]
prev = -1
prevSum = 0
first = 1
for i in ids:
	if i > 1:
		q += c[i - 1] * (s[i - 2] - prevSum)
		if prev == i - 1:
			q += c[i - 1] * c[i - 2]
		if i == n and first:
			q -= c[n - 1] * c[0]
	if i < n:
		q += c[i - 1] * (s[n] - s[i + 1])
		if i == 1:
			first = 0
			q -= c[0] * c[n - 1]
	prev = i
	prevSum += c[i - 1]
print(q)


(n, m) = map(int, input().split())
an = 0
l = list(map(int, input().split()))
x = sum(l)
v = [0] * (10 ** 5 + 5)
k = list(map(int, input().split()))
for i in range(m):
	v[k[i] - 1] = 1
	an += (x - l[k[i] - 1]) * l[k[i] - 1]
	x -= l[k[i] - 1]
for i in range(n):
	if v[i] == 0 and v[(i + 1) % n] == 0:
		an += l[i] * l[(i + 1) % n]
print(an)


read = lambda : map(int, input().split())
(n, k) = read()
c = list(read())
id = list(read())
f = [0] * n
for i in id:
	f[i - 1] = 1
s1 = sum(c)
s2 = sum((c[i - 1] for i in id))
ans = 0
for i in range(n):
	if f[i]:
		ans += c[i] * (s1 - c[i])
	else:
		cur = s2
		if not f[(i - 1) % n]:
			cur += c[(i - 1) % n]
		if not f[(i + 1) % n]:
			cur += c[(i + 1) % n]
		ans += c[i] * cur
ans //= 2
print(ans)


import sys
(n, k) = map(int, sys.stdin.readline().strip().split())
l = list(map(int, sys.stdin.readline().strip().split()))
c = [int(i) - 1 for i in sys.stdin.readline().strip().split()]
ans = 0
h = [0] * n
sl = sum(l)
sc = 0
for i in c:
	h[i] = 1
	sc += l[i]
for i in range(n):
	if h[i]:
		ans += l[i] * (sl - l[i])
	else:
		ans += l[i] * sc
		if not h[(i + 1) % n]:
			ans += l[i] * l[(i + 1) % n]
		if not h[(i + n - 1) % n]:
			ans += l[i] * l[(i + n - 1) % n]
print(ans // 2)


class City:

	def __init__(self, beauty):
		self.beautyValue = beauty
		self.capital = False
(n, k) = map(int, input().split())
cities = input().split()
cap = input().split()
j = 0
sumBeauties = 0
sumRoads = 0
for i in range(len(cities)):
	cities[i] = City(int(cities[i]))
	sumBeauties += cities[i].beautyValue
	if j >= len(cap):
		continue
	if int(cap[j]) == i + 1:
		cities[i].capital = True
		j += 1
for i in range(len(cities)):
	if cities[i].capital:
		sumBeauties -= cities[i].beautyValue
		sumRoads += cities[i].beautyValue * sumBeauties
	elif not cities[i - 1].capital:
		sumRoads += cities[i].beautyValue * cities[i - 1].beautyValue
print(sumRoads)


(n, k) = map(int, input().split())
c = [*map(int, input().split())]
summa = sum(c)
d = {int(x): 1 for (i, x) in enumerate(input().split())}
(res, result, last) = (0, 0, 0)
x = c[0]
res += x * (c[-1] + c[1])
if d.get(1) != None:
	s = c[1] + c[-1]
	result += x * (summa - x - s)
	last += x
for (i, x) in enumerate(c[1:n - 1]):
	i = i + 1
	s = c[i - 1] + c[i + 1]
	res += x * s
	if d.get(i + 1) != None:
		if d.get(i) != None:
			s -= c[i - 1]
		result += x * (summa - x - s - last)
		last += x
x = c[-1]
s = c[-2] + c[0]
res += x * s
if d.get(n) != None:
	if d.get(1) != None:
		s -= c[0]
	if d.get(n - 1) != None:
		s -= c[-2]
	result += x * (summa - last - x - s)
print(res // 2 + result)


(n, k) = map(int, input().split())
c = list(map(int, input().split()))
capitals = set(map(lambda x: int(x) - 1, input().split()))
total_beauty = sum(c)
capital_beauty = sum((c[x] for x in capitals))
ans = 0
for i in range(n):
	if i in capitals:
		ans += c[i] * (total_beauty - c[i])
	else:
		before = n - 1 if i == 0 else i - 1
		after = 0 if i == n - 1 else i + 1
		if before not in capitals:
			ans += c[before] * c[i]
		if after not in capitals:
			ans += c[after] * c[i]
		ans += capital_beauty * c[i]
print(ans // 2)


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


def read():
	return [int(x) for x in input().split()]

def main():
	(n, k) = read()
	c = read()
	capitals = read()
	total_beauty = sum(c)
	capitals_indicator = [False] * (n + 1)
	total_capitals_beauty = 0
	total_capitals_beauty_squared = 0
	for i in capitals:
		capitals_indicator[i] = True
		total_capitals_beauty += c[i - 1]
		total_capitals_beauty_squared += c[i - 1] ** 2
	res = 0
	for i in range(1, n):
		if not capitals_indicator[i] and (not capitals_indicator[i + 1]):
			res += c[i - 1] * c[i]
	if not capitals_indicator[1] and (not capitals_indicator[n]):
		res += c[0] * c[n - 1]
	for i in capitals:
		res += c[i - 1] * (total_beauty - c[i - 1])
	res -= (total_capitals_beauty ** 2 - total_capitals_beauty_squared) // 2
	print(res)
main()


(n, k) = map(int, input().split())
W = tuple(map(int, input().split()))
F = n * [True]
s = 0
k = sum(W)
for c in map(int, input().split()):
	F[c - 1] = False
	w = W[c - 1]
	k -= w
	s += w * k
for i in range(n):
	j = (1 + i) % n
	if F[i] and F[j]:
		s += W[i] * W[j]
print(s)


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)


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
	used += arr[cur]
print(res)


(n, k) = map(int, input().split())
C = list(map(int, input().split()))
S = list(map(int, input().split()))
G = set(S)
ans = 0
sus = sum(C)
stos = 0
for x in G:
	stos += C[x - 1]
for j in S:
	ans += C[j - 1] * (sus - C[j - 1])
for i in range(n):
	if i + 1 not in G and (i + 1) % n + 1 not in G:
		ans += C[i] * C[(i + 1) % n]
s2 = 0
for v in G:
	s2 += C[v - 1] * C[v - 1]
print(ans - (stos * stos - s2) // 2)


(n, k) = map(int, input().split())
v = list(map(int, input().split()))
c = set((i - 1 for i in map(int, input().split())))
prefix_all = [0] * n
prefix_cap = [0] * n
for i in range(n):
	if i > 0:
		prefix_all[i] += prefix_all[i - 1]
		prefix_cap[i] += prefix_cap[i - 1]
	prefix_all[i] += v[i]
	if i in c:
		prefix_cap[i] += v[i]
res = 0
for i in range(n):
	if i in c:
		res += v[i] * (prefix_all[n - 1] - prefix_all[i])
	else:
		res += v[i] * (prefix_cap[n - 1] - prefix_cap[i])
		if i + 1 < n and i + 1 not in c:
			res += v[i] * v[i + 1]
		if i == 0 and n - 1 not in c:
			res += v[0] * v[n - 1]
print(res)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, k) = I()
c = I()
p = set([i - 1 for i in I()])
ans = 0
for i in range(n):
	if i not in p and (i + 1) % n not in p:
		ans += c[i] * c[(i + 1) % n]
s = sum(c)
cur = 0
for i in p:
	ans += c[i] * (s - cur - c[i])
	cur += c[i]
print(ans)