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

import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    #     # ans=int(A*x/B)-A*int(x/B)
    #     min,_=math.modf(x/B)
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    max=0
    max_x=0
    first=0

    for x in range(N+1):
        rem = x%B
        if x == 0:
            first=rem
        elif rem == first:
            break
        if rem > max:
            max=rem
            max_x=x

    # min,_=math.modf(max_x/B)

    print(int(A*max_x/B)-A*int(max_x/B))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
   # file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    #     # ans=int(A*x/B)-A*int(x/B)
    #     min,_=math.modf(x/B)
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    # max=0
    # max_x=0
    # first=0
    #
    # for x in range(N+1):
    #     rem = x%B
    #     if x == 0:
    #         first=rem
    #     elif rem == first:
    #         break
    #     if rem > max:
    #         max=rem
    #         max_x=x

    if N<B:
        max_x=N
    else:
        max_x=B-1

    # min,_=math.modf(max_x/B)

    print(int(A*max_x/B)-A*int(max_x/B))

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

N,W = map(int,input().split())
dp = [0]*(W+1)
for _ in range(N):
    w,v = map(int,input().split())
    if w > W:
        continue
    else:
        for j in range(w,W+1)[::-1]:
            if dp[j] < dp[j-w]+v:
                dp[j] = dp[j-w]+v
print(dp[W])

### FIXED CODE ###

N,W = map(int,input().split())
import copy
dp = [0]*(W+1)
for _ in range(N):
    dpc = copy.deepcopy(dp)
    w,v = map(int,input().split())
    if w > W:
        continue
    else:
        for j in range(w,W+1):
            if dpc[j] < dpc[j-w]+v:
                dp[j] = dpc[j-w]+v
print(dp[W])
### BUGGY CODE ###

import sys
from operator import itemgetter

mod = 10**9 + 7
inf = 1<<30

def solve():
    N, M = map(int, sys.stdin.readline().split())
    sects = []

    for i in range(N):
        li, ri = map(int, sys.stdin.readline().split())

        sects.append((li - 1, ri, ri - li + 1))

    sects.sort(key=itemgetter(2))

    # print(sects)

    print(N)

    left = 0

    ft = FenwickTree([0]*(M + 1))

    for d in range(2, M + 1):
        for j in range(left, N):
            if sects[j][2] >= d:
                left = j
                break
            else:
                ft.add(sects[j][0], 1)
                ft.add(sects[j][1], -1)
        else:
            left = N

        # print('left', left)
        # print(ft.data)

        ans = N - left + sum(ft.get_sum(j) for j in range(d, M + 1, d))
        
        print(ans)

class FenwickTree:
    def __init__(self, a):
        self.n = len(a)
        self.data = [0] + a[:]

        for i in range(1, self.n + 1):
            if i + (i & (-i)) <= self.n:
                self.data[i + (i & (-i))] += self.data[i]

    def add(self, i, x):
        ''' a[i] += x '''
        i += 1 # 0-oringn -> 1-origin

        while i <= self.n:
            self.data[i] += x
            i += i & (-i)

    def get_sum(self, r):
        ''' sum[a_0 .. a_r) '''
        res = 0

        while r > 0:
            res += self.data[r]
            r -= r & (-r)

        return res


if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys
from operator import itemgetter

mod = 10**9 + 7
inf = 1<<30

def solve():
    N, M = map(int, sys.stdin.readline().split())
    sects = []

    for i in range(N):
        li, ri = map(int, sys.stdin.readline().split())

        sects.append((li - 1, ri, ri - li + 1))

    sects.sort(key=itemgetter(2))

    # print(sects)

    print(N)

    left = 0

    ft = FenwickTree([0]*(M + 1))

    for d in range(2, M + 1):
        for j in range(left, N):
            if sects[j][2] >= d:
                left = j
                break
            else:
                ft.add(sects[j][0], 1)
                ft.add(sects[j][1], -1)
        else:
            left = N

        # print('left', left)
        # print(ft.data)

        ans = N - left + sum(ft.get_sum(j) for j in range(d, M + 1, d))
        
        print(ans)

class FenwickTree:
    def __init__(self, a):
        self.n = len(a)
        self.data = [0] + a[:]

        for i in range(1, self.n + 1):
            if i + (i & (-i)) <= self.n:
                self.data[i + (i & (-i))] += self.data[i]

    def add(self, i, x):
        ''' a[i] += x '''
        i += 1 # 0-oringn -> 1-origin

        while i <= self.n:
            self.data[i] += x
            i += i & (-i)

    def get_sum(self, r):
        ''' sum[a_0 .. a_r) '''
        res = 0

        while r > 0:
            res += self.data[r]
            r -= r & (-r)

        return res


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

n=int(input())
from collections import Counter
s=[]
for i in range(n):
  read=list(input())
  s.append(Counter(read))

ans=0
for i in range(n-1):
  for j in range(i+1,n):
    if s[i]==s[j]:
      ans=ans+1
    

print(ans)


### FIXED CODE ###

n=int(input())
from collections import Counter
s=[]
for i in range(n):
  read=list(input())
  read.sort()
  s.append("".join(read))

ans=0
dic=Counter(s)
for i in dic:
  ans=ans+dic[i]*(dic[i]-1)//2
print(ans)
### BUGGY CODE ###

N = int(input())
entry = list(map(int, input().split()))

result = []
for i in range(1, len(entry)+1):
    result.append(entry.index(i)+1)
for j in range(len(result)):
    print(result[j], " ", end="")

### FIXED CODE ###

from operator import itemgetter

N = int(input())
entry = list(map(int, input().split()))

result =[]
for i in range(len(entry)):
    result.append([i+1, entry[i]])
result2 = sorted(result, key=itemgetter(1))
    
for i in range(len(result)):
    print(result2[i][0], " ", end="")
### BUGGY CODE ###

if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
    if n <= k+1:
        print(abs(hs[0]-hs[-1]))
        exit()
    ans_list = [0]*n
    for i in range(1,k+1):
        ans_list[-i] = abs(hs[-1] - hs[-i])
    for i in range(k+1,n+1):
        hs_i = hs[-i]
        ans_list[-i] = min([abs(hs_i-hs[-i+x])+ans_list[-i+x] for x in range(1,k+1)])
    print(ans_list[0])


### FIXED CODE ###

if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
    if n <= k+1:
        print(abs(hs[0]-hs[-1]))
        exit()
    ans_list = [0]*n
    last_hs = hs[-1]
    for i in range(1,k+2):
        ans_list[-i] = abs(last_hs - hs[-i])
    for i in range(k+2,n+1):
        hs_i = hs[-i]
        ans_list[-i] = min([abs(hs_i-x)+y for x,y in zip(hs[1-i:k+1-i],ans_list[1-i:k+1-i])])
    print(ans_list[0])
### BUGGY CODE ###

K, S = map(int, input().split())

c = 0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if (x + y + z) == S:c+=1
print(c)

### FIXED CODE ###

K, S = map(int, input().split())

c = 0

for x in range(K+1):
    for y in range(K+1):
        if 0 <= S - (x + y) <= K:c+=1
print(c)
### BUGGY CODE ###

'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    q = int(ipt())
    for _ in range(q):
        a,b = map(int,ipt().split())
        if a > b:
            a,b = b,a
        ans = a-1
        tgt = a*b
        pi = b
        for i in range(a+1,10**9+1):
            xi = (tgt-1)//i
            if i**2 > tgt:
                ans += (tgt-1)//i
                if xi == pi:
                    ans -= 1
                break
            ans += 1
            pi = xi
        print(ans)

    return None

if __name__ == '__main__':
    main()


### FIXED CODE ###

'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    q = int(ipt())
    for _ in range(q):
        a,b = map(int,ipt().split())
        if a > b:
            a,b = b,a
        tgt = a*b
        rt = int(tgt**0.5+0.0000000000001)
        ans = rt*2-1
        if a == b:
            ans -= 1
        elif rt**2 == tgt:
            ans -= 2
        elif rt*(rt+1) < tgt:
            pass
        elif rt**2-1 < tgt:
            ans -= 1
        print(ans)

    return None

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

n = int(input())
pros = [ int(input()) for i in range(n)]
k = set()
k.add(0)
for i in range(1 << len(pros)):
    output = []
    for j in range(len(pros)):
        if ((i >> j) & 1) == 1:
            output.append(pros[j])
    if sum(output) % 10 != 0:
        k.add(sum(output))
print(max(k))

### FIXED CODE ###

n = int(input())
s = [int(input()) for i in range(n)]
s.sort()
j = sum([ i % 10 for i in s ])
if j == 0:
    ans = 0
else:
    if sum(s) % 10 != 0:
        ans = sum(s)
    else:
        for i in range(n):
            tmp = sum(s)-s[i]
            if tmp % 10 != 0:
                ans = tmp
                break
print(ans)
### BUGGY CODE ###

import copy

N=int(input())

A=list(map(int,input().split()))

#print(A)

mama=dict()
papa=dict()
parent=dict()

An=set(A)

for i in An:
    parent[i]=A.count(i)
parecou=0
#print(parent)
for i in parent:
    f=parent[i]
    parecou+=int((f*(f-1)/2))

#print(parecou)
for i in range(N):
    anko=parent[A[i]]
    print(parecou-int((anko*(anko-1)/2))+int(((anko-2)*(anko-1)/2)))
    """
    if(A[i] in mama):
        print(mama[A[i]])
        continue
    
    AA=copy.deepcopy(A)
    ai=A[i]
    del AA[i]
    #print(AA)
    Aset=set(AA)
    count=0
    
    for i in Aset:
        aa=AA.count(i)
        if(aa in papa):
            count+=papa[aa]
            continue
        #print(i,aa)
        aiu=int((aa*(aa-1))/2)
        count+=aiu
        papa[aa]=aiu
    print(count)
    mama[ai]=count
    """


### FIXED CODE ###

from collections import Counter
N=int(input())
A=list(map(int,input().split()))

parent=dict()
An=set(A)
parecou=0
aaa=Counter(A)
for i in aaa.values():
    parecou+=int((i*(i-1)/2))
"""
for i in An:
    f=A.count(i)
    parent[i]=f
    parecou+=int((f*(f-1)/2))
"""


#print(parecou)
for i in range(N):
    anko=aaa[A[i]]
    print(parecou-int((anko*(anko-1)/2))+int(((anko-2)*(anko-1)/2)))
    #print(parecou-anko+1)
### BUGGY CODE ###

mod=1000000007
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))
f=0
for i in range(len(a)):
    if a[i]+1 in a:
        f=1
        break
        
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
    dp[1]=0
else:
    dp[1]=1
    
for i in range(2,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=(dp[i-1]+dp[i-2])%mod

if f==1:
    print(0)
else:
    print(dp[n]%mod)
  

### FIXED CODE ###

import sys
input = sys.stdin.readline

mod=1000000007
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))
al=len(a)


f=0
for i in range(al-1):
    if a[i+1]==a[i]+1:
        f=1
        break
if f==1:
    print(0)
else:
    dp=[0]*(n+1)
    dp[0]=1
    if 1 in a:
        dp[1]=0
        a.pop(0)
        al-=1
    else:
        dp[1]=1
    
    for i in range(2,n+1):
        if al>0 and i==a[0]:
            dp[i]=0
            a.pop(0)
            al-=1
        else:
            dp[i]=(dp[i-1]+dp[i-2])%mod
    print(dp[n]%mod)
### BUGGY CODE ###

k, s = map(int, input().split())
count = 0

for i in range(0, k+1):
    for j in range(0, k+1):
        for k in range(0, k+1):
            if s == i+j+k:
                count += 1

print(count)


### FIXED CODE ###

K, S = map(int, input().split())
count = 0

for i in range(0, K+1):
    for j in range(0, K+1):
        k = S-j-i
        if k >= 0 and k <= K:
            count += 1

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

"""
"""
from math import factorial
from collections import defaultdict


def int_as_array(num): return list(map(int, [y for y in str(num)]))


def array_as_int(arr): return int(''.join(map(str, arr)))


def read_int(): return int(input())


def read_array(): return list(map(int, input().split(' ')))


def array_to_string(arr, sep=' '): return sep.join(map(str, arr))


def matrix_to_string(arr, sep=' '): return '[\n' + '\n'.join(
    [sep.join(map(str, row)) for row in arr]) + '\n]'


cache = {}


def fac(x):
    if cache.get(x) is not None:
        return cache[x]
    ans = factorial(x)
    cache[x] = ans
    return ans


def choose_combination(n, r):
    if cache.get((n, r)) is None:
        if r > n:
            return 0
        cache[(n, r)] = int((fac(n) / fac((n - r))) * (1 / fac(r)))
    return cache.get((n, r))


def solve(n, array):
    counts = defaultdict(int)
    for x in array:
        counts[x] += 1
    ways_cache = {}
    for k in array:
        if ways_cache.get(k) is not None:
            print(ways_cache[k])
            continue
        ways = 0
        for x, count in counts.items():
            adjusted_count = counts[x]
            if x == k:
                adjusted_count -= 1
            ways += choose_combination(adjusted_count, 2)
        ways_cache[k] = ways
        print(ways)


N = read_int()
array = read_array()
solve(N, array)


### FIXED CODE ###

"""
"""
from math import factorial
from collections import defaultdict


def int_as_array(num): return list(map(int, [y for y in str(num)]))


def array_as_int(arr): return int(''.join(map(str, arr)))


def read_int(): return int(input())


def read_array(): return list(map(int, input().split(' ')))


def array_to_string(arr, sep=' '): return sep.join(map(str, arr))


def matrix_to_string(arr, sep=' '): return '[\n' + '\n'.join(
    [sep.join(map(str, row)) for row in arr]) + '\n]'


cache = {}


def fac(x):
    return factorial(x)


def choose_combination(n, r):
    if r > n:
        return 0
    # return int((fac(n) / fac((n - r))) * (1 / fac(r)))
    # return (fac(n) // fac((n - 2)) * (1 / 2))
    # return fac((n // n - 2)) * (1 / 2))
    return (n * (n-1)) // 2


def solve(n, array):
    counts = defaultdict(int)
    for x in array:
        counts[x] += 1
    total_ways = 0
    for x, count in counts.items():
        total_ways += choose_combination(counts[x], 2)
    for k in array:
        ways = choose_combination(counts[k] - 1, 2)
        print(total_ways + ways - choose_combination(counts[k], 2))


N = read_int()
array = read_array()
solve(N, array)
### BUGGY CODE ###

import bisect

N, Q = map(int, input().rstrip().split(' '))

construction = [list(map(int, input().rstrip().split(' '))) for _ in range(N)]
D = [int(input()) for _ in range(Q)]
construction = sorted(construction, key=lambda x: x[2])

d2i = dict([(d, i) for i, d in enumerate(D)])
dist = [-1] * Q
indices = list(range(Q))
for c in construction:
    i1 = bisect.bisect_left(D, c[0] - c[2])
    i2 = bisect.bisect_left(D, c[1] - c[2])
    for i in range(i1, i2):
        dist[d2i[D[i]]] = c[2]
    del D[i1:i2]
    
for d in dist:
    print(d)
    

### FIXED CODE ###

import sys
import bisect
input=sys.stdin.readline

N, Q = map(int, input().split(' '))

construction = [list(map(int, input().split(' '))) for _ in range(N)]
D = [int(input()) for _ in range(Q)]
construction = sorted(construction, key=lambda x: x[2])

dist = [-1] * Q
jump = [-1] * Q
indices = list(range(Q))
for s, t, x in construction:
    i1 = bisect.bisect_left(D, s-x)
    i2 = bisect.bisect_left(D, t-x)
    i = i1
    while i < i2:
        k = jump[i]
        if k != -1:
            i = k
        else:
            jump[i] = i2
            dist[i] = x
            i += 1
    
for d in dist:
    print(d)
### BUGGY CODE ###

a, b, q = map(int, input().split())
inf = 10 ** 18
s = [-inf] + [int(input()) for _ in range(a)] + [inf]
t = [-inf] + [int(input()) for _ in range(b)] + [inf]

def doit(st, x):
    lo, hi = 0, len(st) - 1
    while hi - lo > 1:
        mid = (lo + hi) // 2
        if st[mid] < x:
            lo = mid
        else:
            hi = mid
    mid = (lo + hi) // 2
    return st[mid], st[mid + 1]

for _ in range(q):
    x = int(input())
    s1, s2 = doit(s, x)
    t1, t2 = doit(t, x)
    print(min(abs(s1 - x) + min(abs(t1 - s1), abs(t2 - s1)),
              abs(s2 - x) + min(abs(t1 - s2), abs(t2 - s2)),
              abs(t1 - x) + min(abs(s1 - t1), abs(s2 - t1)),
              abs(t2 - x) + min(abs(s1 - t2), abs(s2 - t2))))


### FIXED CODE ###

a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]

s = sorted(s)
t = sorted(t)
st = []
(i, j) = (0, 0)
while i < len(s) or j < len(t):
    if j == len(t) or (i < len(s) and s[i] < t[j]):
        st.append((s[i], min(abs(s[i] - t[max(j - 1, 0)]),
                             abs(s[i] - t[min(j, len(t) - 1)]))))
        i += 1
    else:
        st.append((t[j], min(abs(t[j] - s[max(i - 1, 0)]),
                             abs(t[j] - s[min(i, len(s) - 1)]))))
        j += 1

def doit(x):
    lo, hi = 0, len(st) - 1
    while hi - lo > 1:
        mid = (lo + hi) // 2
        if st[mid][0] < x:
            lo = mid
        else:
            hi = mid
    mid = (lo + hi) // 2
    return min(abs(st[mid][0] - x) + st[mid][1], abs(st[mid + 1][0] - x) + st[mid + 1][1])

for _ in range(q):
    print(doit(int(input())))
### BUGGY CODE ###

h,n = list(map(int, input().split()))
st = str(input())
a = [list(map(int, input().split())) for _ in range(n)]

for a1,b1 in a:
    print(st[a1-1:b1].count("AC"))

### FIXED CODE ###

h,n = list(map(int, input().split()))
st = str(input())
a = [list(map(int, input().split())) for _ in range(n)]

o = "B"
b = []
c = 0
for i in range(len(st)):
    sti = st[i]
    if sti == "A":
        o = "A"
        b.append(c)
    elif sti == "C" and o == "A":
        o = "C"
        c += 1
        b.append(c)
    else:
        o = "B"
        b.append(c)

for a1,b1 in a:
    print(b[b1-1] - b[a1-1])
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
#グループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 #xのグループとyのグループを結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
#親を全部表示
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_groupmembers(self):
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M ,K = map(int, input().split())
uf = UnionFind(N)
friend_count=[0]*N
for m in range(M):
    p,q = map(int, input().split())
    friend_count[p-1]+=1
    friend_count[q-1]+=1
    uf.union(p-1, q-1)
bgraph = {}
for k in range(K):
    p,q = map(int, input().split())
    if p-1 in bgraph.keys():
        bgraph[p-1].append(q-1)
    else:
        bgraph[p-1] = [q-1]
    if q-1 in bgraph.keys():
        bgraph[q-1].append(p-1)
    else:
        bgraph[q-1] = [p-1]
allg =  uf.all_groupmembers()
last_list=[]
for n in range(N):
    for a in allg.values():
        if n in a:
            leng = len(a)
            if n in bgraph.keys():
                ng = len(set(bgraph[n])&set(a))
            else:
                ng = 0
            print(str(leng-ng-1-friend_count[n]), end=" ")

### FIXED CODE ###

class UnionFind():
    def __init__(self,n):
        # リンク情報　子→親の番号　親(根)→負のサイズ
        self.d=[-1 for i in range(n)]
    
    def find(self,x):
        if(self.d[x]<0):return x
        self.d[x]=self.find(self.d[x])
        return self.d[x]
 
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if(x==y):return False
        if(self.d[x]>self.d[y]):x,y=y,x
        self.d[x]+=self.d[y]
        self.d[y]=x
        return True
 
    def same(self,x,y):return self.find(x)==self.find(y)
    def size(self,x):return -1*self.d[self.find(x)]
n,m,k=map(int,input().split())
uf=UnionFind(n)
deg=[0 for i in range(n)]
to=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    uf.unite(a,b)
    deg[a]+=1
    deg[b]+=1
for i in range(k):
    a,b=map(int,input().split())
    a-=1
    b-=1
    to[a].append(b)
    to[b].append(a)
for i in range(n):
    ans=uf.size(i)-1-deg[i]
    for j in to[i]:
        if(uf.same(i,j)):ans-=1
    print(ans,end=" ")
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque

n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
  p, q, c = map(int, input().split())
  p -= 1
  q -= 1
  G[p].append((q, c))
  G[q].append((p, c))
que = deque()
que.append((0, -1, 0))
seen = set()
ans = float("inf")
while que:
  v, com, cnt = que.popleft()
  if (v, com) in seen:
    continue
  if v == n-1:
    ans = min(ans, cnt)
    continue
  seen.add((v, com))
  for nv, ncom in G[v]:
    if ncom == com:
      que.appendleft((nv, ncom, cnt))
    else:
      que.append((nv, ncom, cnt+1))
if ans == float("inf"):
  print(-1)
else:
  print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict, deque

n, m = map(int, input().split())
G = defaultdict(set)
U = 10**6
seen = set()
for _ in range(m):
  p, q, c = map(int, input().split())
  G[p+U*c].add((q+U*c, 0))
  G[q+U*c].add((p+U*c, 0))
  G[p+U*c].add((p-U, 0))
  G[q+U*c].add((q-U, 0))
  G[p-U].add((p+U*c, 1))
  G[q-U].add((q+U*c, 1))
que = deque()
que.append((1-U, 0))
while que:
  v, cnt = que.popleft()
  if v in seen:
    continue
  if v == n-U:
    print(cnt)
    exit()
  seen.add(v)
  for nv, cost in G[v]:
    if cost == 0:
      que.appendleft((nv, cnt+cost))
    else:
      que.append((nv, cnt+cost))
print(-1)
### BUGGY CODE ###

N, M = map(int, input().split())

a = list(map(int, input().split()))
for i in range(M):
    k = a.index(max(a))
    a[k] //= 2

print(sum(a))

### FIXED CODE ###

import heapq
N, M = map(int, input().split())

a = list(map(lambda x: -int(x), input().split()))
heapq.heapify(a)

for i in range(M):
    heapq.heappush(a, int(heapq.heappop(a)/2))

print(-sum(a))