Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys


def Sieve(N, AList):
    AList.sort()

    N_NotDivisible = 0
    while( len(AList)>0 ):
        if(len(AList)> 1):
            if(AList[0]!=AList[1]):
                N_NotDivisible+= 1
            value = AList[0]
            AList = [i for i in AList if(i%value!=0) ]
        else:
            N_NotDivisible+= 1
            break
    #print(Mins)
    return N_NotDivisible

if(__name__ == "__main__"):

    N = int( input().strip() )
    AList_str = input().strip().split()

    AList = [0] * N
    for i in range(N):
        AList[i] = int(AList_str[i])
    N_NotDivisible= Sieve(N, AList)
    print(N_NotDivisible)


### FIXED CODE ###

import sys

def Sieve2(N, AList, Bools, Max_A):
    N_NotDivisible = 0
    value = 0
    for i in range(N):
        if(AList[i]>value):
            value = AList[i]
            if(Bools[value]==True):
                N_NotDivisible += 1

            for j in range(2, Max_A//value+1, 1 ):
                Bools[j*value] = False
    #print(Mins)
    return N_NotDivisible


if(__name__ == "__main__"):

    N = int( input().strip() )
    AList_str = input().strip().split()
    Max = 0
    AList = [0] * N
    for i in range(N):
        AList[i] = int(AList_str[i])
        Max = max(AList[i], Max)
    Bools = [False] * (Max+1)
    AList.sort()
    Dups = []
    for Num in range(N):
        value = AList[Num]
        Bools[value] = True
        if(Num < N-1 and AList[Num] == AList[Num+1]):
            Dups.append(value)
    for Num in range(len(Dups)):
        value = Dups[Num]
        Bools[value] = False


    N_NotDivisible= Sieve2(N, AList, Bools, Max)
    print(N_NotDivisible)
### BUGGY CODE ###

def resolve():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(m):
        m = max(a)
        a[a.index(m)] //= 2
    print(sum(a))


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

import heapq


def resolve():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    query = []
    for i in range(n):
        heapq.heappush(query, -a[i])
    for i in range(m):
        nexta = -1 * heapq.heappop(query) // 2
        heapq.heappush(query, -nexta)
    print(-sum(query))


if __name__ == "__main__":
    resolve()
### BUGGY CODE ###

import numpy as np
n=int(input())
ds=list(map(int,input().split()))
sds=sorted(set(ds))
nds=np.array(ds)
ans=0
for i,d in enumerate(sds[1:]):
    l=sum(np.where(nds>=d,1,-1))
    if l==0:
        ans+=(d-sds[i])
print(ans)


### FIXED CODE ###

n=int(input())
ds=list(map(int,input().split()))
ds.sort()
print(ds[n//2]-ds[n//2-1])
### BUGGY CODE ###

import math

MOD = 10**9+7


def modinv(x):
    ret = 1
    m = MOD - 2
    for i in range(0, 32):
        if m & (1 << i):
            ret *= x
            ret %= MOD
        x *= x
        x %= MOD
    return ret


fact = [1] * 200100
for i in range(1, 200100):
    fact[i] = fact[i-1] * i % MOD


def calc(h, w):
    h -= 1
    w -= 1
    return (fact[h+w]*modinv(fact[h]) % MOD)*modinv(fact[w]) % MOD


h, w, a, b = map(int, input().split())
ans = 0
for i in range(1, h - a + 1):
    ans += calc(i, b) * calc(h + 1 - i, w - b) % MOD
    if ans >= MOD:
        ans -= MOD
print(ans)


### FIXED CODE ###

import math

MOD = 10**9+7


def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0


def modinv(a):
    g, x, y = xgcd(a, MOD)
    return x % MOD


fact = [1] * 200100
for i in range(1, 200100):
    fact[i] = fact[i-1] * i % MOD


def calc(h, w):
    h -= 1
    w -= 1
    return (fact[h+w]*modinv(fact[h]) % MOD)*modinv(fact[w]) % MOD


h, w, a, b = map(int, input().split())
if a >= h // 2:
    ans = 0
    for i in range(1, h - a + 1):
        ans += calc(i, b) * calc(h + 1 - i, w - b) % MOD
        if ans >= MOD:
            ans -= MOD
    print(ans)

else:
    ans = calc(h, w)
    for i in range(h-a+1, h + 1):
        ans -= calc(i, b) * calc(h + 1 - i, w - b) % MOD
        if ans < 0:
            ans += MOD
    print(ans)
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

isprime = None

def sieve(n):
    global isprime

    if n < 2:
        isprime = [False] * (n + 1)
        return

    isprime = [True if i % 2 != 0 else False for i in range(n + 1)]
    isprime[0] = isprime[1] = False
    isprime[2] = True

    from math import sqrt, ceil

    for i in range(3, int(sqrt(n)) + 1):
        if isprime[i] == True:
            for j in range(2, ceil(n / i)):
                isprime[i * j] = False

def main():
    global isprime

    sieve(100000)

    _ = sys.stdin.readline()

    accsums = [0] * 100001
    k = 2
    for l, r in (map(int, line.split()) for line in sys.stdin.readlines()):
        if r > k:
            for i in range(k, r + 1):
                accsums[i] = accsums[i - 1]
                if isprime[i] == isprime[(i + 1) // 2] == True:
                     accsums[i] += 1
        print(accsums[r] - accsums[l - 1])

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

isprime = None

def sieve(n):
    global isprime

    if n < 2:
        isprime = [False] * (n + 1)
        return

    isprime = [True if i % 2 != 0 else False for i in range(n + 1)]
    isprime[0] = isprime[1] = False
    isprime[2] = True

    from math import sqrt, ceil

    for i in range(3, int(sqrt(n)) + 1):
        if isprime[i] == True:
            for j in range(i + i, n + 1, i):
                isprime[j] = False

def main():
    global isprime

    sieve(100000)

    _ = sys.stdin.readline()

    csums = [0] * 100001
    for i in range(3, 100001):
        csums[i] += csums[i - 1]
        if isprime[i] == True and isprime[(i + 1) // 2] == True:
            csums[i] += 1

    for l, r in (map(int, line.split()) for line in sys.stdin.readlines()):
        print(csums[r] - csums[l - 1])

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
from heapq import heappop, heappush, heapify
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float("inf")

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(lambda x: int(x)-1, input().split())
    g[u].append(v)
s, t = map(lambda x: int(x)-1, input().split())

g2 = [[] for _ in range(n)]
visited = [False] * n

def dfs(v):
    if visited[v]: return
    visited[v] = True
    for nv1 in g[v]:
        for nv2 in g[nv1]:
            for nv3 in g[nv2]:
                g2[v].append((nv3, 1))
                dfs(nv3)

for i in range(n): dfs(i)

def dijkstra(graph, n, s):
    d = [INF] * n
    d[s], q = 0, []
    heappush(q, (0, s))
    while q:
        dist, v = heappop(q)
        if d[v] < dist: continue
        for nv, cost in graph[v]:
            if d[nv] > d[v] + cost:
                d[nv] = d[v] + cost
                heappush(q, (d[nv], nv))
    return d

ans = dijkstra(g2, n, s)[t]
print(-1 if ans == INF else ans)


### FIXED CODE ###

from heapq import heappop, heappush, heapify

INF = float("inf")
n, m = map(int, input().split())
idx = [[i*3 + j for j in range(3)] for i in range(n)]
g = [[] for _ in range(n*3)]
for _ in range(m):
    u, v = map(lambda x: int(x)-1, input().split())
    for i in range(3):
        g[idx[u][i]].append((idx[v][(i+1) % 3], 1))
s, t = map(lambda x: int(x)-1, input().split())

def dijkstra(graph, n, s):
    d = [INF] * n
    d[s], q = 0, []
    heappush(q, (0, s))
    while q:
        dist, v = heappop(q)
        if d[v] < dist: continue
        for nv, cost in graph[v]:
            if d[nv] > d[v] + cost:
                d[nv] = d[v] + cost
                heappush(q, (d[nv], nv))
    return d

res = dijkstra(g, n*3, idx[s][0])[idx[t][0]]
print(-1 if res == INF else res // 3)
### BUGGY CODE ###

import numpy as np

MOD = 10**9 + 7
s = input()
count = np.zeros(13, dtype = int)
count[0] = 1
for i in range(len(s)):
    new = np.zeros(13, dtype = int)
    for m in range(13):
        new[(m * 10) % 13] = count[m]
    count = new
    if s[i] != "?":
        div = int(s[i])
        count = np.concatenate([count[-div:], count[:-div]], 0)
    else:
        new = np.copy(count)
        for div in range(1, 10):
            new += np.concatenate([count[-div:], count[:-div]], 0)
        count = new
    count %= MOD
print(count[5])

### FIXED CODE ###

from copy import copy

MOD = 10**9 + 7
s = input()
count = [0 for _ in range(13)]
count[0] = 1
for i in range(len(s)):
    new = [0 for _ in range(13)]
    for m in range(13):
        new[(m * 10) % 13] = count[m]
    count = new
    if s[i] != "?":
        div = int(s[i])
        count = count[-div:] +  count[:-div]
    else:
        new = [0 for _ in range(13)]
        pre = sum(count[:3])
        SUM = sum(count) % MOD
        for j in range(13):
            pre += count[(j+3) % 13]
            pre -= count[j % 13]
            new[j] = (SUM - pre) % MOD
        count = new
print(count[5])
### BUGGY CODE ###

if __name__ == '__main__':
    k, s = map(int, input().split())
    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            if i + j > s:
                break
            for l in range(k+1):
                if i+j+l == s:
                    ans += 1
                elif i+j+l > s:
                    break
    print(ans)

### FIXED CODE ###

if __name__ == '__main__':
    k, s = map(int, input().split())
    ans = 0
    for i in range(k+1):
        if i > s:
            break
        for j in range(k+1):
            z = s - i - j
            if i + j > s:
                break
            elif 0 <= z and z <= k:
                ans += 1
    print(ans)
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()
lr = [input().split() for _ in range(Q)]

A = []
for i in range(N-1):
	if S[i] == "A" and S[i+1] == "C":
		A.append(1)
	else:
		A.append(0)

A.append(0)
print

for i in range(Q):
	l = int(lr[i][0])
	r = int(lr[i][1])
	if A[r-1] == 1:
		r -= 1
	print(A[l-1 :r].count(1))

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()
lr = [LIST() for _ in range(Q)]

T = [0]*N
cnt = 0
for i in range(1, N):
	if S[i] == "C" and S[i-1] == "A":
		cnt += 1
		T[i] = cnt
	else:
		T[i] = cnt

for i in range(Q):
	print(T[lr[i][1]-1]-T[lr[i][0]-1])
### BUGGY CODE ###

MOD = 10**9 + 7


def main():
    from fractions import Fraction as F
    from collections import Counter

    N = int(input())
    A = []
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    for _ in range(N):
        a, b = (int(i) for i in input().split())
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            A.append((F(a, b), F(b, a)))
            cA[F(a, b)] += 1

    used = set()
    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in A:
        if a in used or -b in used:
            continue
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[-b], MOD) - 1 + 1
        ans %= MOD
        used.add(a)
        used.add(-b)
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()


### FIXED CODE ###

MOD = 10**9 + 7
P = 7 ** 21 + 52


def F(a, b):
    return (a * pow(b, P-2, P)) % P


def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    B = []
    used = set()
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            x = F(a, b)
            y = -F(b, a) % P
            cA[x] += 1
            if x not in used and y not in used:
                B.append((x, y))
                used.add(x)
                used.add(y)

    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in B:
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[b], MOD) - 1 + 1
        ans %= MOD
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(raw_input())

li = []
for i in range(n):
    cmd = raw_input().split()
    if cmd[0] == 'insert':
        li.append(int(cmd[1]))
    elif cmd[0] == 'delete':
        try:
            p = li[::-1].index(int(cmd[1]))
            li.pop(-p-1)
        except:
            pass
    elif cmd[0] == 'deleteFirst':
        li.pop()
    elif cmd[0] == 'deleteLast':
        li.pop(0)
for e in li[::-1]:
    print e,

### FIXED CODE ###

import sys,gc
    
A=[]
fp =0
bp =0

n=int(raw_input())
while n:
    s = raw_input()
    if s[0] == 'i':
        A.append(int(s[7:]))
        fp += 1
    elif s[6] == ' ':
        try:
            i = A[::-1].index(int(s[7:]))
            if i!=-1:
                del A[-i-1]
                fp -=1
        except:
            pass
    elif s[6] == 'F':
        A.pop()
        fp -=1
    elif s[6] == 'L':
        bp +=1
    n -=1

for e in A[bp:fp+1][::-1]:
    print int(e),
### BUGGY CODE ###

N = int(input())
A_list = list(map(int, input().split()))
A_list.sort()

is_prime = [True] * N
for i in range(N):
    if is_prime[i] == False:
        continue
    for j in range(i+1, N):
        if A_list[j] % A_list[i] == 0:
            is_prime[j] = False
    if i != N-1:
        if A_list[i] == A_list[i+1]:
            is_prime[i] = False

print(is_prime.count(True))


### FIXED CODE ###

N = int(input())
A_list = list(map(int, input().split()))
A_list.sort()
A_max = A_list[N-1]

is_prime = [False] * (A_max+1)


for i in A_list:
    is_prime[i] = True

x = -1
for i in A_list:
    if not is_prime[i]:
        continue
    elif x == i:
        is_prime[i] = False
        continue
    for j in range(i*2, A_max+1, i):
        is_prime[j] = False
    x = i

count = 0
for i in A_list:
    if is_prime[i]:
        count += 1


print(count)
### BUGGY CODE ###


n = int(input())
S = [list(input()) for i in range(n)]

M = [[] for i in range(n)]
for i in range(n):
    for j in range(n):
        if S[i][j] == "1":
            M[i].append(j)
ans = -1
owa = 0
for i in range(n):
    a0 = -1
    Q = [[i, 0]]
    st = 0
    D = [-1] * n
    while st < len(Q):
        a = Q[st][0]
        d = Q[st][1]
        D[a] = d
        for x in M[a]:
            if D[x] == -1:
                Q.append([x, d+1])
            elif D[x] == d-1 or D[x] == d+1:
                continue
            else:
                owa = 1
                break
        if owa == 1:
            break
        st += 1
    if owa == 0:
        a0 = max(D)+1
    ans = max(ans, a0)

print(ans)


### FIXED CODE ###


n = int(input())
S = [list(input()) for i in range(n)]

M = [[] for i in range(n)]
for i in range(n):
    for j in range(n):
        if S[i][j] == "1":
            M[i].append(j)
ans = -1
owa = 0
for i in range(n):
    a0 = -1
    Q = [[i, 0]]
    st = 0
    D = [-1] * n
    while st < len(Q):
        a = Q[st][0]
        d = Q[st][1]
        D[a] = d
        for x in M[a]:
            if D[x] == -1:
                Q.append([x, d+1])
                D[x] = d+1
            elif D[x] != d-1 and D[x] != d+1:
                owa = 1
                break
        if owa == 1:
            break
        st += 1
    if owa == 0:
        a0 = max(D)+1
    ans = max(ans, a0)

print(ans)
### BUGGY CODE ###

import sys
from collections import deque

V = list(input())
S = deque()
S.extend(V)
Q = int(input())

for i in range(Q):
    c = sys.stdin.readline().split()
    #print('s:', S)
    #print('c:', c)

    if c[0] == '1':
        S.reverse()
    else:
        if c[1] == '1':
            S.appendleft(c[2])
        else:
            S.append(c[2])

print(''.join(S))

### FIXED CODE ###

import sys
from collections import deque

V = list(input())
S = deque()
S.extend(V)
Q = int(input())

memo = []
r = 0
for i in range(Q):
    c = sys.stdin.readline().split()
    #print(c)
    if c[0] == '1':
        r += 1
        continue
    else:
        if c[1] == '1':
            memo.append((r, c[2]))
        else:
            memo.append((r+1, c[2]))
        
#print(memo)        
if r % 2 == 1:
    S.reverse()

for m in memo:
    s, l = m
    s = r - s
    if s % 2 == 0:
        S.appendleft(l)
    else:
        S.append(l)    

print(''.join(S))
### BUGGY CODE ###

import bisect
import sys
input=sys.stdin.readline
n,d,a=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()

LV=(n-1).bit_length()
N0=2**LV
data=[0]*(2*N0)
lazy=[0]*(2*N0)

def gindex(l,r):
  L=l+N0;R=r+N0
  lm=(L//(L&-L))>>1
  rm=(R//(R&-R))>>1
  while L<R:
    if R<=rm:
      yield R
    if L<=lm:
      yield L
    L>>=1;R>>=1
  while L:
    yield L
    L>>=1

def propagates(*ids):
  for i in reversed(ids):
    v=lazy[i-1]
    if not v:
      continue
    lazy[2*i-1]+=v;lazy[2*i]+=v
    data[2*i-1]+=v;data[2*i]+=v
    lazy[i-1]=0

def update(l,r,x):
  L=N0+l;R=N0+r
  while L<R:
    if R&1:
      R-=1
      lazy[R-1]+=x;data[R-1]+=x
    if L&1:
      lazy[L-1]+=x; data[L-1]+=x
      L+=1
    L>>=1;R>>=1
  for i in gindex(l,r):
    data[i-1]=min(data[2*i-1],data[2*i])+lazy[i-1]

def query(l,r):
  propagates(*gindex(l,r))
  L=N0+l;R=N0+r

  s=10**9+1
  while L<R:
    if R&1:
      R-=1
      s=min(s,data[R-1])
    if L&1:
      s=min(s,data[L-1])
      L+=1
    L>>=1; R>>=1
  return s

def main():
  x=[]
  for i in range(n):
    x.append(l[i][0])
    update(i,i+1,l[i][1])

  Right=[]
  for i in range(n):
    Right.append(bisect.bisect_right(x,x[i]+2*d))

  p=0
  ans=0
  while p<n:
    x=query(p,p+1)
    update(p,Right[p],-((x+a-1)//a)*a)
    ans+=(x+a-1)//a
    while query(p,p+1)<=0:
      p+=1
      if p==n:
        break
  print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import bisect
import sys
input=sys.stdin.readline
n,d,a=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()

data0=[0]*(n+1)
data1=[0]*(n+1)

def _add(data,k,x):
  while k<=n:
    data[k]+=x
    k+=k&-k

def add(l,r,x):
  _add(data0,l,-x*(l-1))
  _add(data0,r,x*(r-1))
  _add(data1,l,x)
  _add(data1,r,-x)

def _get(data,k):
  s=0
  while k:
    s+=data[k]
    k-=k&-k
  return s

def query(l,r):
  return _get(data1,r-1)*(r-1)+_get(data0,r-1)-_get(data1,l-1)*(l-1)-_get(data0,l-1)

x=[]
for i in range(n):
  x.append(l[i][0])
  add(i+1,i+2,l[i][1])

Right=[]
for i in range(n):
  Right.append(bisect.bisect_right(x,x[i]+2*d))

p=0
ans=0
while p<n:
  Q=query(p+1,p+2)
  add(p+1,Right[p]+1,-((Q+a-1)//a)*a)
  ans+=(Q+a-1)//a
  p=min(p+1,n-1)
  while query(p+1,p+2)<=0:
    p+=1
    if p==n:
      break
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
lis=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    lis[a].append(b)
    lis[b].append(a)
ans=[0 for i in range(n+1)]
i=1
ii=lis[i]
for oo in ii:
  ans[oo]=1
  lis[oo].clear()
while i<=n:
    for k in ii:
        for j in lis:
            if ii!=j:
                if k in j:
                    ans[lis.index(j)]=k
                    j.clear()
    i+=1
print("Yes")
for i in range(2,len(ans)):
  print(ans[i])

### FIXED CODE ###

n,m=map(int,input().split())
lis=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    lis[a-1].append(b-1)
    lis[b-1].append(a-1)

ans=[-1]*n
ans[0] = 0
from collections import deque
q = deque([0])
while q:
    a=q.popleft()
    for i in lis[a]:
        if ans[i]==-1:
            ans[i]=a
            q.append(i)
print("Yes")
for i in range(1,len(ans)):
    print(ans[i]+1)
### BUGGY CODE ###

s=input()
q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x=='1':
    cnt+=1
    
  elif x[0]=='2':
    if (x[2]=='1' and cnt%2==0) or (x[2]=='2' and cnt%2==1):
      s=x[4]+s
      
    else:
      s=s+x[4]
      
if cnt%2==1:
  s=s[::-1]
  

print(s)
    

### FIXED CODE ###

from collections import deque


Q=deque(list(input()))

q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))
### BUGGY CODE ###

from collections import defaultdict
import heapq as hq
from itertools import permutations
def dijkstra(E, D, start):
    q = []
    V = [-1]*N
    V[start] = 0
    for e in E[start]:
        hq.heappush(q, (D[start, e],e))
    while q:
        d, v = hq.heappop(q)
        if V[v] >= 0:
            continue
        V[v] = d
        for e in E[v]:
            if V[e] == -1:
                hq.heappush(q, (D[v,e]+d, e))
    return V
N, M, r = map( int, input().split())
R = list( map( int, input().split()))
d = defaultdict( int)
E = [ [] for _ in range(N)]
for _ in range(M):
    a, b, c = map( int, input().split())
    a, b = a-1, b-1
    d[(a,b)] = d[(b,a)] = c
    E[a].append(b)
    E[b].append(a)
W = [ dijkstra(E,d,i) for i in range(N)]
ans = 10**9
for P in permutations( range(r)):
    now = R[P[0]]-1
    cans = 0
    for i in range(1,r):
        cans += W[now][R[P[i]]-1]
        now = R[P[i]]-1
    if cans < ans:
        ans = cans
print( ans)


### FIXED CODE ###

from collections import defaultdict
import heapq as hq
from itertools import permutations
def dijkstra(E, D, start,W):
    q = []
    V = [-1]*N
    V[start] = 0
    # for i in range(start):
    #     V[i] = W[i][start]
    #     for e in E[i]:
    #         if e > start:
    #             hq.heappush(q, (V[i] + D[(i,e)], e))
    for e in E[start]:
        if V[e] == -1:
            hq.heappush(q, (D[start, e],e))
    # print(V, q)
    while q:
        d, v = hq.heappop(q)
        if V[v] >= 0:
            continue
        V[v] = d
        for e in E[v]:
            if V[e] == -1:
                hq.heappush(q, (D[v,e]+d, e))
    return V
N, M, r = map( int, input().split())
R = list( map( int, input().split()))
d = defaultdict( int)
E = [ [] for _ in range(N)]
for _ in range(M):
    a, b, c = map( int, input().split())
    a, b = a-1, b-1
    d[(a,b)] = d[(b,a)] = c
    E[a].append(b)
    E[b].append(a)
W = [ [-1]*N for i in range(N)]
# for i in range(N):
#     W[i] = dijkstra(E,d,i,W)
    # print(W)
for i in range(r):
    W[R[i]-1] = dijkstra(E,d,R[i]-1,W)

ans = 10**9
for P in permutations( range(r)):
    now = R[P[0]]-1
    cans = 0
    for i in range(1,r):
        cans += W[now][R[P[i]]-1]
        now = R[P[i]]-1
    if cans < ans:
        ans = cans
print( ans)