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

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

d = []
d_count = 0
loop = 0

while True:
        for b, c in bc:
                d.extend([c] * b)
                d_count += b
                loop += 1
        if d_count > n:
                break
        elif loop == m:
                break

ans = []

a.extend(d)
a.sort(reverse = True)

for i in range(n):
        ans.append(a[i])

print(sum(ans))

### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

a_count = 0
for b, c in bc:
        if c > a[a_count]:
                for i in range(b):
                        if c > a[a_count]:
                                a[a_count] = c
                                a_count += 1    
                        else:
                                break
                        if a_count == n:
                                        break

        else:
                break
        if a_count == n:
                break        

print(sum(a))
### BUGGY CODE ###

from collections import deque

def bfs(start):
    queue = deque([start])
    visited = []

    while queue:
        label = queue.pop()

        #if label == goal:
        #    visited.append(label)
        #    return tekazu[goal]

        if label not in visited:
            visited.append(label)

            for v in d[label]:
                if v not in visited:
                    tekazu[v] = tekazu[label] + 1
                    queue.appendleft(v)

    return

n = int(input())
d = {i: [] for i in range(n)}

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

tekazu = [0 for _ in range(n)] # nは頂点数
bfs(0)
tekazu_Fennec = tekazu

tekazu = [0 for _ in range(n)] # nは頂点数
bfs(n - 1)
tekazu_Snuke = tekazu


Fennec = 0
Snuke = 0

for i in range(n):
    if tekazu_Fennec[i] <= tekazu_Snuke[i]:
        Fennec += 1
    else:
        Snuke += 1

if Fennec > Snuke:
    print("Fennec")
else:
    print("Snuke")

### FIXED CODE ###

from collections import deque

def bfs(start):
    queue = deque([start])
    visited = []

    while queue:
        label = queue.pop()

        #if label not in visited:
        visited.append(label)

        for v in d[label]:
            if tekazu[v] == float("inf"):
                tekazu[v] = tekazu[label] + 1
                queue.appendleft(v)

    return

n = int(input())
d = [[] for _ in range(n)]

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

tekazu = [float("inf") for _ in range(n)] # nは頂点数
tekazu[0] = 0
bfs(0)
tekazu_Fennec = tekazu

tekazu = [float("inf") for _ in range(n)] # nは頂点数
tekazu[-1] = 0
bfs(n - 1)
tekazu_Snuke = tekazu

Fennec = 0
Snuke = 0

for i in range(n):
    if tekazu_Fennec[i] <= tekazu_Snuke[i]:
        Fennec += 1
    else:
        Snuke += 1

#print(tekazu_Fennec, tekazu_Snuke)

if Fennec > Snuke:
    print("Fennec")
else:
    print("Snuke")
### BUGGY CODE ###

N=int(input())
count1=[c for c in range(N+1)]
count2=[2*c for c in range(N+1)]
count2[1]=1

i=2
while i<=N//2+1:
    j=2
    while i*j<=N:
        count2[i*j]+=count1[i*j]
        j+=1
    i+=1

print(sum(count2))

### FIXED CODE ###

N=int(input())
ans=sum(2*i for i in range(N+1))

j=2
while j<=N:
    k=2
    while j*k<=N:
        ans+=j*k
        k+=1
    j+=1

print(ans-1)
### BUGGY CODE ###

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

scores = []

score = 1
for i in range(k-1, -1, -1):
    score *= a[i]

scores.append(score)

for j in range(k, n):
    scores.append(scores[-1] * a[j] / a[j-k])
    if scores[-1] > scores[-2]:
        print('Yes')
    else:
        print('No')



### FIXED CODE ###

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

for i in range(k, n):
    if a[i] > a[i-k]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###


import itertools

[n,k] = [int(x) for x in input().split()]
data = [int(x) for x in input().split()]

kumi = list(itertools.combinations(list(range(n)), k))
answer = sum(data)

for comb in kumi:
    total = 0
    for x in comb:
        total += data[x]
    if total < answer:
        answer = total

print(answer)



### FIXED CODE ###

[n,k] = [int(x) for x in input().split()]
data = [int(x) for x in input().split()]
data.sort()

print(sum(data[:k]))
### BUGGY CODE ###

def resolve():
    import sys
    from collections import Counter
    n = int(input())
    s = [sys.stdin.readline().rstrip() for i in range(n)]
    d = Counter(s).most_common()
    e = d[0][1]
    f = ([i for i in set(s) if s.count(i) == e])
    f = sorted(f)
    for i in f:
        print(i)
resolve()

### FIXED CODE ###

def resolve():
    import sys
    from collections import Counter
    n = int(input())
    s = [sys.stdin.readline().rstrip() for i in range(n)]
    d = Counter(s).most_common()
    e = d[0][1]
    ans = []
    for i in range(len(d)):
        if d[i][1] != e:
            break
        else:
            ans.append(d[i][0])
    for j in sorted(ans):
        print(j)
resolve()
### BUGGY CODE ###

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

import queue

# input
h, w = map(int, input().split())
a = [ list(input()) for _ in range(h) ]

# direction vector
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]

# 黒マスを列挙 O(H*W)
black_grid = []
for x in range(w):
    for y in range(h):
        if a[y][x] == "#":
            black_grid += [ (x, y, 0) ]

# 訪れたかどうかの情報を持つ bool 値
is_visited = [ [False for _ in range(w)] for __ in range(h) ]

q = queue.Queue()

# 各黒マスを queue に入れる
for point in black_grid:
    q.put(point)

ans = 0
while not q.empty():
    # queue の先頭を取り出す
    x, y, cnt = q.get()
    ans = max(ans, cnt)
    # 4方向にループ
    for i in range(4):
        nx, ny = x + dx[i], y + dy[i]
        if nx < 0 or w <= nx or ny < 0 or h <= ny:
            continue

        if is_visited[ny][nx] == False:
            if a[ny][nx] == ".":
                a[ny][nx] = "#"
                q.put( (ny, nx, cnt+1) )

            is_visited[ny][nx] = True

print(ans)



### FIXED CODE ###

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

from collections import deque

# input
h, w = map(int, input().split())
a = [ list(input()) for _ in range(h) ]

# direction vector
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]

# 訪れたかどうかの情報を持つ bool 値
is_visited = [ [False for _ in range(w)] for __ in range(h) ]

q = deque()

for x in range(w):
    for y in range(h):
        if a[y][x] == "#":
            q.append( (x, y, 0) )
            is_visited[y][x] = True

while q:
    # queue の先頭を取り出す
    x, y, cnt = q.popleft()
    # 4方向にループ
    for i in range(4):
        nx, ny = x + dx[i], y + dy[i]

        if nx < 0 or w <= nx or ny < 0 or h <= ny or is_visited[ny][nx]:
            continue

        q.append( (nx, ny, cnt+1) )
        is_visited[ny][nx] = True

print(cnt)
### BUGGY CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 29
val = 0
from bisect import bisect_left as bl, bisect_right as br
    
for k in range(l):
    # i桁目を求める
    tmp = pow(2, k+1)
    bb = [item%(tmp) for item in b]
    bb.sort()
    ans = 0
    for item in a:
        aa = item%(tmp)
        if aa<=tmp//2:
            num = br(bb, tmp-1-aa) - bl(bb, tmp//2-aa)
        else:
            num = br(bb, tmp-1-aa) + (n - bl(bb, tmp//2*3-aa))
        ans += num
        ans %= 2
    if ans:
        val += pow(2, k)
print(val)

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = 29
val = 0

def lcount(a,b,x):
    """ソート済a,bに対して, a[i]+b[j]<=xなるi,jの個数
    """
    la = len(a)
    lb = len(b)
    j = -1
    ans = 0
    for i in range(la-1, -1, -1):
        while j+1<lb and a[i]+b[j+1]<=x:
            j += 1
        ans += (j+1)
    return ans
for k in range(l):
    # i桁目を求める
    tmp = pow(2, k+1)
    bb = [item%(tmp) for item in b]
    aa = [item%(tmp) for item in a]
    aa.sort()
    bb.sort()
    ans = n**2 - lcount(aa,bb,tmp//2*3-1) + lcount(aa,bb,tmp-1) - lcount(aa,bb,tmp//2-1)
    if ans%2:
        val += pow(2, k)
print(val)
### BUGGY CODE ###

n=int(input())

def m_div(n):
    ans=0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ans+=1
            if i != n // i:
                ans+=1

    return ans


ans=0
for i in range(1,n+1):
    ans+=(i*m_div(i))

print(ans)

### FIXED CODE ###

n=int(input())

x=[-1]*(10**7+5)
x[0]=0
x[1]=1
i=2
prime=[]
while i<=10**7+1:

    if x[i]==-1:
        x[i]=i
        prime.append(i)

    for j in prime:
        if i*j>10**7+1 or j>x[i]:break
        x[j*i]=j
    i+=1



def f(k):
    if k==1:
        return 1

    z=[]
    p=x[k]
    m=1
    ans=1
    while k>=2:
        k=k//p
        if p==x[k]:
            m+=1
        else:
            z.append(m)
            m=1
            p=x[k]

    for i in range(len(z)):
        ans*=z[i]+1
    return ans
ans=0
for i in range(1,n+1):
    #print(i,f(i))
    ans += i*f(i)

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

import numpy as np
import math
import collections

T = int(input())
for i in range(T):
    x = 0
    L0 = [0]
    ans = True
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    for i, s in enumerate(reversed(S)):
        #print(L0, A[N - i - 1])
        if s == "0":
            tmp = set(np.array(L0) ^ A[N - i - 1])
            L0 = list(set(L0).union(tmp))
        if s == "1":
            if A[N - i - 1] not in L0:
                ans = False
                break

    print(int(not ans))


### FIXED CODE ###

import numpy as np
import math
import collections

T = int(input())
for i in range(T):
    x = 0
    L0 = [0]
    ans = 0
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    for i, s in enumerate(reversed(S)):
        tmp = A[N - 1 - i]
        for l0 in L0:
            if tmp ^ l0 < tmp:
                tmp = tmp ^ l0
        if tmp > 0:
            if s == "1":
                ans = 1
                break
            L0.append(tmp)
    print(ans)
### BUGGY CODE ###

if __name__ == "__main__":
    from itertools import permutations
    N, M, R = map(int, input().split())
    rs = map(lambda x: int(x) - 1, input().split())
    dist, ans = [[10000000 for _ in range(N)] for _ in range(N)], 10000000
    for _ in range(M):
        v1, v2, d = map(int, input().split())
        dist[v1-1][v2-1] = dist[v2-1][v1-1] = d
    for i in range(N):
        dist[i][i] = 0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    for r in permutations(rs):
        t = 0
        for i in range(R-1):
            t += dist[r[i]][r[i+1]]
        ans = min(t, ans)
    print(ans)


### FIXED CODE ###

from itertools import permutations
N, M, R = map(int, input().split())
rs = map(lambda x: int(x) - 1, input().split())
dist = [[10**9 for _ in range(N)] for _ in range(N)]
for _ in range(M):
    v1, v2, d = map(int, input().split())
    dist[v1-1][v2-1] = dist[v2-1][v1-1] = d
for i in range(N):
    dist[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
ans = 10**9
for r in permutations(rs):
    t = 0
    for i in range(R-1):
        t += dist[r[i]][r[i+1]]
        if t > 10**9:
            break
    ans = min(t, ans)
print(ans)
### BUGGY CODE ###

s=input()
m=len(s)
from collections import Counter
c=Counter()
tmp=""
c[0]+=1
for i in s[::-1]:
    tmp=i+tmp
    c[int(tmp)%2019]+=1

ll=c.most_common()
ans=0
for i,j in ll:
    if j>=2:
        ans+=j*(j-1)//2
    else:
        break
print(ans)


### FIXED CODE ###

s=[int(j) for j in input()][::-1]
c=[0]*2019
tmp=0
c[0]+=1
t=1
import numpy as np
for i in s:
    tmp+=t*i
    c[tmp%2019]+=1
    t=t*10%2019
c=np.array(c)
ans=c*(c-1)//2
print(ans.sum())
### BUGGY CODE ###

import sys

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

is_reverse = False
for _ in range(q):
  tf = sys.stdin.readline().split()
  if tf[0] == '1':
    is_reverse = False if is_reverse else True
  else:
    if tf[1] == '1':
      if is_reverse:
        s += tf[2]
      else:
        s = tf[2] + s
    else:
      if is_reverse:
        s = tf[2] + s
      else:
        s += tf[2]
if is_reverse:
  print(s[::-1])
else:
  print(s)

### FIXED CODE ###

import sys
from collections import deque

s = input()
q = int(input())
is_reverse = False
ds = deque(s)

for _ in range(q):
  tf = sys.stdin.readline().split()
  if len(tf) == 1:
    is_reverse = False if is_reverse else True
  else:
    if tf[1] == '1':
      if is_reverse:
        ds.append(tf[2])
      else:
        ds.appendleft(tf[2])
    else:
      if is_reverse:
        ds.appendleft(tf[2])
      else:
        ds.append(tf[2])
if is_reverse:
  ds.reverse()
ans = ''.join(list(ds))
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
strings_set = set(strings)
count = 0
for string in strings_set:
    tmp = strings.count(string)
    if tmp > 1:
        count += tmp * (tmp - 1) // 2

print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
string_set = set()
counts = {}
count = 0
for string in strings:
    if string in string_set:
        count += counts[string]
        counts[string] += 1
    else:
        string_set.add(string)
        counts[string] = 1

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

def main():
    from itertools import accumulate

    n, k = map(int, input().split())
    *a, = map(int, input().split())

    acc = (0,) + tuple(accumulate(a))

    bs = tuple(set() for _ in range(40))

    pow2 = [1 << j for j in range(40)]

    m = 0
    for l in range(n):
        for r in range(l + 1, n + 1):
            beauty = acc[r] - acc[l]
            for j in range(40):
                if beauty & pow2[j] > 0:
                    bs[j].add(m)
            m += 1

    ret = 0
    t = set(range(m))
    for j in range(39, -1, -1):
        s = t & bs[j]
        if len(s) >= k:
            ret += pow2[j]
            t = s
    print(ret)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from math import log, ceil

n, k = map(int, input().split())
a = tuple(map(int, input().split()))

A_MAX = 10 ** 9
MAX_BIT_LENGTH = ceil(log(A_MAX * n, 2))

cs = [0]
t = 0
for aa in a:
    t += aa
    cs.append(t)

ps = []
for r in range(1, n + 1):
    for l in range(r):
        ps.append(cs[r] - cs[l])

ans = 0
for b in range(MAX_BIT_LENGTH)[::-1]:
    cnt = 0
    t = ans + (1 << b)
    for p in ps:
        if p & t == t:
            cnt += 1
            if cnt == k:
                ans = t
                break

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

#非再帰minセグ木

class MinSegmentTree:
    def __init__(self, n): #a1, a2, ..., an
        n_ = 1
        while n_ < n:
            n_ *= 2

        self.n = n_
        self.arr = [float("inf")] * (2*self.n-1)

    def update(self, k, a): #0_indexed
        k += self.n - 1
        self.arr[k] = a

        while k:
            k = (k-1) // 2
            x = self.arr[2*k+1]; y = self.arr[2*k+2]
            self.arr[k] = x if x<y else y

    def query(self, l, r):#[l,r)の値を返す
        L, R = l+self.n, r+self.n
        res = float ("inf")

        while L < R:
            if R & 1:
                R -= 1
                y = self.arr[R-1]
                if res > y:
                    res = y

            if L & 1:
                y = self.arr[L-1]
                if res > y:
                    res = y
                L += 1

            L >>= 1
            R >>= 1

        return res

import sys
input=sys.stdin.readline
n,m=map(int,input().split())

sg=MinSegmentTree(n+1)
sg.update(1,0)
lrc=[tuple(map(int,input().split())) for _ in range(m)]
lrc.sort(key=lambda x:x[0])
for i in range(m):
    l,r,c=lrc[i]
    x=sg.query(l,l+1)
    if x!=float("inf"):
        x+=c
        for j in range(l,r+1):
            sg.update(j,min(x,sg.query(j,j+1)))
ans=sg.query(n,n+1)
print(ans if ans!=float("inf") else -1)


### FIXED CODE ###


from collections import defaultdict
from heapq import heappop, heappush


class Graph():

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra():

    def __init__(self, graph, start):
        self.g = graph.graph

        self.dist = defaultdict(lambda: float("inf"))
        self.dist[start] = 0

        self.prev = defaultdict(lambda: None)

        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            dist_u, u = heappop(self.Q)

            if self.dist[u] < dist_u:
                continue

            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):

        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal

        while node is not None:
            path.append(node)
            node = self.prev[node]

        return path[::-1]


import sys
input=sys.stdin.readline
n,m=map(int,input().split())
g=Graph()

for _ in range(m):
    l,r,c=map(int,input().split())
    g.add_edge(l,r,c)
for i in range(2,n+1):
    g.add_edge(i,i-1,0)


d = Dijkstra(g,1)
ans=d.shortest_distance(n)
print(ans if ans!=float("inf") else -1)
### BUGGY CODE ###

def resolve():
    import math
    from collections import defaultdict
    def factorization(n):
        # 参考: https://qiita.com/snow67675476/items/e87ddb9285e27ea555f8
        dic = defaultdict(int)
        temp = n
        for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
            if temp % i == 0:
                cnt = 0
                while temp % i == 0:
                    cnt += 1
                    temp //= i
                dic[i] = cnt

        if temp != 1:
            dic[temp] = 1
        if not dic:
            dic[n] = 1

        return set(dic.keys())

    n = int(input())
    a = list(set(map(int, input().split())))
    pair = False
    divisors = factorization(a[0])
    ggcd = a[0]
    for i in range(1, len(a)):
        divs = factorization(a[i])
        nxt = divisors | divs
        if len(nxt) != len(divs) + len(divisors):
            pair = True
            break
        else:
            divisors = nxt
    for i in range(1, len(a)):
        ggcd = math.gcd(ggcd, a[i])
        if ggcd == 1:
            break
    if ggcd != 1:
        print("not coprime")
    else:
        if pair:
            print("setwise coprime")
        else:
            print("pairwise coprime")
resolve()

### FIXED CODE ###

def resolve():
    import math
    n = int(input())
    a = list(set(map(int, input().split())))
    maxa = max(a)

    ggcd = a[0]
    for i in range(1, len(a)):
        ggcd = math.gcd(ggcd, a[i])
        if ggcd == 1:
            break

    pair = False

    c = [0] * (10**6+ 1)
    for i in a:
        c[i] += 1

    for i in range(2, maxa+1):
        cnt = 0
        for j in range(i, maxa+1, i):

            cnt += c[j]
        if cnt > 1:
            pair = True

    if ggcd != 1:
        print("not coprime")
    else:
        if pair:
            print("setwise coprime")
        else:
            print("pairwise coprime")
resolve()
### BUGGY CODE ###

import sys
import math
import numpy as np


MOD=998244353
N=int(input())
a=[int(input()) for i in range(N)]
a.sort(reverse=True)

A=sum(a)
M=math.ceil(A/2)  
x =[ [0 for j in range(M+1)] for i in range(N)]
x[0][0]=2
x[0][min(a[0],M)]=1

p=M-A+a[0]
q=a[0]
for i in range(1,N):
    p+=a[i]
    q+=a[i]
    for j in range(max(p,0),min(q,M)+1):
        if j==M:
            x[i][j]=sum(x[i-1][ max(M-a[i],0): M ])+x[i-1][M]*3

        elif j-a[i]<0: x[i][j]=x[i-1][j]*2
        else: x[i][j]=x[i-1][j]*2+x[i-1][j-a[i]]

        x[i][j]%=MOD

if sum(a)%2==0:
    y =[ [0 for j in range(M+1)] for i in range(N)]
    y[0][0]=1
    p=M-A+a[0]
    q=a[0]
    for i in range(1,N):
        p+=a[i]
        q+=a[i]
        for j in range(max(p,0),min(q,M)+1):
            if j-a[i]<0: y[i][j]=y[i-1][j]
            else: y[i][j]=y[i-1][j]+y[i-1][j-a[i]]

            y[i][j]%=MOD

    ans=3**N-x[N-1][M]*3+y[N-1][M]*6



else: ans=3**N-x[N-1][M]*3
print(ans%MOD)

### FIXED CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]
mod=998244353
s=sum(a)

dp=[[0]*(s+1) for _ in range(n)]
dp[0][0],dp[0][a[0]]=2,1
for i in range(n-1):
    for j in range(s+1):
        dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2)%mod
        if j+a[i+1]<=s: dp[i+1][j+a[i+1]]=(dp[i+1][j+a[i+1]]+dp[i][j])%mod

dp2=[[0]*(s+1) for _ in range(n)]
dp2[0][0]=1;dp2[0][a[0]]=1
for i in range(n-1):
    for j in range(s+1):
        dp2[i+1][j]=(dp2[i+1][j]+dp2[i][j])%mod
        if j+a[i+1]<=s: dp2[i+1][j+a[i+1]]=(dp2[i+1][j+a[i+1]]+dp2[i][j])%mod

if s%2==0:
    inable=( sum(dp[n-1][s//2:]) - dp2[n-1][s//2] )*3%mod
else:
    inable=( sum(dp[n-1][s//2+1:]) )*3 %mod

ans=1
for _ in range(n):
    ans=ans*3%mod
ans=(ans-inable)%mod
print(ans)
### BUGGY CODE ###

K=int(input())
if K%2==0:
    print(-1)
else:
    if K%7==0:
        L=9*K//7
    else:
        L=9*K
    i=1
    rest=(10**i)%L
    while True:
        if rest==1:
            print(i)
            exit()
        else:
            rest=(rest*10)%L
            i+=1


### FIXED CODE ###

K=int(input())
if K%2==0:
    print(-1)
else:
    if K%7==0:
        L=9*K//7
    else:
        L=9*K
    rest=10%L
    for i in range(1,L+1):
        if rest==1:
            print(i)
            exit()
        else:
            rest=(rest*10)%L
        if i==L and rest!=1:
            print(-1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N, K = readnums()
    x = list(readnums())
    ans = 0
    for i in range(K, N + 1):
        l = x[i - K:i]
        if l[0] > 0:
            val = abs(max(l))
        elif l[-1] < 0:
            val = abs(min(l))
        else:
            val = abs(min(l)) + abs(max(l))
            val += min(abs(min(l)), abs(max(l)))
        if not ans:
            ans = val
        else:
            ans = min(ans, val)

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N, K = readnums()
    x = list(readnums())
    ans = 0
    for i in range(K - 1, N):
        ls = i - K + 1
        le = i
        if x[ls] > 0:
            val = abs(x[le])
        elif x[le] < 0:
            val = abs(x[ls])
        else:
            val = abs(x[ls]) + abs(x[le])
            val += min(abs(x[ls]), abs(x[le]))
        if not ans:
            ans = val
        else:
            ans = min(ans, val)

    print(ans)


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

n,m=map(int,input().split())
a=list(map(int,input().split()))
import numpy as np

for i in range(m):
  np_a = np.array(a)
  x=np_a.argmax()
  a[x]//=2
print(sum(a))

### FIXED CODE ###

import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x: x*(-1), a))
heapq.heapify(a)
for _ in range(m):
  x=heapq.heappop(a)
  x=((x*(-1))//2)*(-1)
  heapq.heappush(a,x)










print(sum(a)*(-1))