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
Tags: Mathematics

Implementation

Starter code:

Solutions:
(n, k) = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
s = sum(c)
m = 0
for i in range(k):
	d[i] -= 1
	s -= c[d[i]]
	m += c[d[i]] * s
	c[d[i]] = 0
for i in range(n):
	m += c[i] * c[(i + 1) % n]
print(m)


(n, m) = map(int, input().split())
cost = list(map(int, input().split()))
iscapi = [False] * n
capi = list(map(lambda x: int(x) - 1, input().split()))
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]
price = [cost[i] for i in capi]
for i in range(m - 2, -1, -1):
	price[i] += price[i + 1]
for i in range(m - 1):
	tot += cost[capi[i]] * price[i + 1]
for i in range(n):
	if not iscapi[i]:
		sumi += cost[i]
for i in capi:
	tot += cost[i] * sumi
print(tot)


(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]
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]
	elif i < n:
		summa += C[i] * C[i + 1]
	elif i == n and 1 not in K:
		summa += C[1] * C[i]
print(summa)


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) = map(int, input().split())
cities = input().split()
cap = input().split()
capitals = [False] * len(cities)
j = 0
sumBeauties = 0
sumRoads = 0
for i in range(len(cities)):
	cities[i] = int(cities[i])
	sumBeauties += cities[i]
	if j >= len(cap):
		continue
	if int(cap[j]) == i + 1:
		capitals[i] = True
		j += 1
for i in range(len(cities)):
	if capitals[i]:
		sumBeauties -= cities[i]
		sumRoads += cities[i] * sumBeauties
	elif not capitals[i - 1]:
		sumRoads += cities[i] * cities[i - 1]
print(sumRoads)


(n, k) = map(int, input().split())
cost = list(map(int, input().split()))
capital = set(map(int, input().split()))
ans = 0
for i in range(1, n):
	g = set()
	if i not in capital:
		if i == 1:
			g = set([i + 1, n]) - capital
			temp = [cost[i - 1] for i in g]
			ans += cost[i - 1] * sum(temp)
		else:
			g = set([i + 1]) - capital
			temp = [cost[i - 1] for i in g]
			ans += cost[i - 1] * sum(temp)
b = sum(cost)
for i in capital:
	b -= cost[i - 1]
	ans += cost[i - 1] * b
print(ans)


(n, k) = map(int, input().split())
bs = list(map(int, input().split()))
cptls = list(map(lambda c: int(c) - 1, input().split()))
set_cpt = set(cptls)
tc = 0 if 0 in set_cpt or n - 1 in set_cpt else bs[n - 1] * bs[0]
bs_sum = sum(bs)
for i in range(0, n - 1):
	if i in set_cpt:
		tc += (bs_sum - bs[i]) * bs[i]
	elif i + 1 in set_cpt:
		continue
	else:
		tc += bs[i] * bs[i + 1]
tc = tc + (bs_sum - bs[n - 1]) * bs[n - 1] if n - 1 in set_cpt else tc
s = 0
for c in cptls:
	tc -= s * bs[c]
	s += bs[c]
print(tc)


(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
karr = list(map(int, input().strip().split()))
s = sum(arr)
ans = 0
mp = {}
for i in range(k):
	mp[karr[i] - 1] = 1
	s -= arr[karr[i] - 1]
	ans += s * arr[karr[i] - 1]
for i in range(n - 1):
	if i not in mp:
		if i + 1 not in mp:
			ans += arr[i] * arr[i + 1]
if 0 not in mp:
	if n - 1 not in mp:
		ans += arr[0] * arr[n - 1]
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)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
c = list(map(int, input().split()))
s1 = sum(c)
ids = list(map(int, input().split()))
ids = list(map(lambda x: x - 1, ids))
s2 = sum((c[i] for i in ids))
se = set(ids)
ans = 0
for i in range(n):
	if i in se:
		ans += c[i] * (s1 - c[i])
	else:
		t = s2
		if (i - 1) % n not in se:
			t += c[(i - 1) % n]
		if (i + 1) % n not in se:
			t += c[(i + 1) % n]
		ans += c[i] * t
ans //= 2
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) = map(int, input().split())
c = list(map(int, input().split()))
c = {i: c[i] for i in range(n)}
caps = list(map(lambda s: int(s) - 1, input().split()))
sumCities = sum(c.values())
dist = 0
for capitalIndex in caps:
	dist += c[capitalIndex] * (sumCities - c[capitalIndex])
	sumCities -= c[capitalIndex]
	c.pop(capitalIndex)
m = len(c)
if m > 0:
	if list(c.keys())[0] == 0 and list(c.keys())[m - 1] == n - 1:
		dist += c[0] * c[n - 1]
	lastIndex = list(c.keys())[0]
	for index in list(c.keys())[1:]:
		if index - lastIndex == 1:
			dist += c[index] * c[lastIndex]
		lastIndex = index
print(dist)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
(F, res, k) = ([1] * n, 0, sum(arr))
for i in map(int, input().split()):
	F[i - 1] = 0
	k -= arr[i - 1]
	res += arr[i - 1] * k
for i in range(n):
	j = (i + 1) % n
	if F[i] and F[j]:
		res += arr[i] * arr[j]
print(res)


(n, k) = 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(x) for x in input().split()]
c = [int(x) for x in input().split()]
ind = [int(x) - 1 for x in input().split()]
s = 0
sl = 0
sq = 0
for i in range(n):
	sl += c[i]
for i in ind:
	sl -= c[i]
	s += c[i] * sl
inInd = [False for x in range(n)]
for i in ind:
	inInd[i] = True
for i in range(n - 1):
	if not inInd[i] and (not inInd[i + 1]):
		s += c[i] * c[i + 1]
if not inInd[0] and (not inInd[n - 1]):
	s += c[n - 1] * c[0]
print(s)


import sys
from decimal import *

def main():
	x = list(map(int, sys.stdin.readline().split()))
	(n, k) = (x[0], x[1])
	c = list(map(int, sys.stdin.readline().split()))
	ks = list(map(int, sys.stdin.readline().split()))
	sks = 0
	dictks = dict()
	for i in range(k):
		sks += c[ks[i] - 1]
		dictks[ks[i] - 1] = True
	ans = Decimal(0)
	for i in range(n):
		if i not in dictks:
			ans += c[i] * sks
			if (i + 1) % n not in dictks:
				ans += c[i] * c[(i + 1) % n]
	cks = Decimal(0)
	for i in range(k):
		ck = c[ks[i] - 1]
		cks += ck * (sks - ck)
	ans += int(cks / 2)
	print(ans)
main()


(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) = map(int, input().split())
arr_c = list(map(int, input().split()))
arr_id = [x - 1 for x in map(int, input().split())]
sum_c = sum(arr_c)
result = 0
for i in arr_id:
	result += arr_c[i] * (sum_c - arr_c[i])
sum_id = sum((arr_c[i] for i in arr_id))
sum_remove = 0
for i in arr_id:
	sum_remove += arr_c[i] * (sum_id - arr_c[i])
result -= sum_remove // 2
for i in arr_id:
	arr_c[i] = 0
for i in range(1, n):
	result += arr_c[i - 1] * arr_c[i]
result += arr_c[0] * arr_c[n - 1]
print(result)


from collections import *
import os, sys
from io import BytesIO, IOBase

def main():
	(n, k) = rints()
	(a, b) = (rints(), set(rints()))
	(su, ans, su2) = (sum(a), 0, 0)
	for i in b:
		ans += a[i - 1] * (su - a[i - 1])
		su2 += a[i - 1]
	for i in range(n):
		if i + 1 not in b:
			(x, y) = ((i - 1) % n, (i + 1) % n)
			ans += a[i] * (su2 + a[x] * (x + 1 not in b) + a[y] * (y + 1 not in b))
	print(ans >> 1)

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')
BUFSIZE = 8192
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
rstr = lambda : input().strip()
rstrs = lambda : [str(x) for x in input().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda : int(input())
rints = lambda : [int(x) for x in input().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
main()


(n, k) = map(int, input().split())
c = list(map(int, input().split()))
v = set(map(int, input().split()))
sum_beuty = sum(c)
ans = 0
for i in v:
	sum_beuty -= c[i - 1]
	ans += c[i - 1] * sum_beuty
	c[i - 1] = 0
for i in range(n):
	ans += c[i] * c[(i + 1) % n]
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
cit = list(map(int, input().split()))
ans = 0
sum_ = sum(l)
for i in range(k):
	sum_ -= l[cit[i] - 1]
	ans += sum_ * l[cit[i] - 1]
cit = set(cit)
for i in range(n - 1):
	if i + 1 not in cit and i + 2 not in cit:
		ans += l[i] * l[i + 1]
if 1 not in cit and n not in cit:
	ans += l[0] * l[-1]
print(ans)


(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())
cit = list(map(int, input().split()))
cap = set((int(x) - 1 for x in map(int, input().split())))
ans = 0
for i in range(n):
	j = (i + 1) % n
	if i not in cap and j not in cap:
		ans += cit[i] * cit[j]
tot = sum(cit)
scap = sum((cit[c] for c in cap))
ans += sum((cit[c] * (tot - scap) for c in cap))
ans += sum((cit[c] * (scap - cit[c]) for c in cap)) // 2
print(ans)


(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) = [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
	elif 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
elif not s[0][1]:
	ans += s[n - 1][0] * s[0][0]
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()


(n, k) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ks = [int(i) - 1 for i in input().split()]
totalBeauty = sum(c)
totalCost = 0
for capital in ks:
	totalBeauty -= c[capital]
	totalCost += c[capital] * totalBeauty
	c[capital] = 0
for i in range(n - 1):
	totalCost += c[i] * c[i + 1]
totalCost += c[0] * c[n - 1]
print(totalCost)


(n, k) = map(int, input().split())
c = [int(x) for x in input().split()]
id = [int(x) - 1 for x in input().split()]
cap = [False for i in range(0, n)]
sum_c = 0
for i in range(0, n):
	sum_c += c[i]
sum_id = 0
sump_id = []
for i in range(0, k):
	cap[id[i]] = True
	sum_id += c[id[i]]
	sump_id.append(sum_id)
cost = sum_id * sum_c
for i in range(0, k):
	cost -= c[id[i]] * sump_id[i]
for i in range(0, n):
	(st, en) = (i, (i + 1) % n)
	if not cap[st] and (not cap[en]):
		cost += c[st] * c[en]
print(cost)


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


(n, k) = map(int, input().split(' '))
cost = list(map(int, input().split(' ')))
capitals = set(map(int, input().split(' ')))
sum_cost = sum((c for c in cost))
ans = 0
for capital in capitals:
	ans += cost[capital - 1] * sum_cost
ans -= (sum((cost[capital - 1] for capital in capitals)) ** 2 - sum((cost[capital - 1] ** 2 for capital in capitals))) // 2
ans -= sum((cost[capital - 1] ** 2 for capital in capitals))
if 1 not in capitals and n not in capitals:
	ans += cost[0] * cost[n - 1]
for i in range(n - 1):
	if i + 1 not in capitals and i + 2 not in capitals:
		ans += cost[i] * cost[i + 1]
print(ans)


(n, k) = map(int, input().split())
c = list(map(int, input().split()))
v = set(map(int, input().split()))
s = sum(c)
r = 0
for x in v:
	s -= c[x - 1]
	r += s * c[x - 1]
	c[x - 1] = 0
for i in range(n):
	r += c[i] * c[(i + 1) % n]
print(r)


def s():
	[n, k] = list(map(int, input().split()))
	c = list(map(int, input().split()))
	su = c[0] * c[-1]
	cap = [False] * n
	p = sum(c)
	for i in range(1, n):
		su += c[i] * c[i - 1]
	for i in list(map(int, input().split())):
		i -= 1
		p -= c[i]
		cap[i] = True
		fi = i + 1 if i < n - 1 else 0
		se = i - 1 if i > 0 else -1
		su += c[i] * (p - (0 if cap[fi] else c[fi]) - (0 if cap[se] else c[se]))
	return su
print(s())


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ls = list(map(int, input().split()))
ans = 0
su = sum(l)
for x in ls:
	su -= l[x - 1]
	ans += l[x - 1] * su
	l[x - 1] = 0
for i in range(n):
	if i == n - 1:
		ans += l[i] * l[0]
	else:
		ans += l[i] * l[i + 1]
print(ans)


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)