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

import bisect
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
for i in range(m):
    b, c = [int(i) for i in input().split()]
    idx = bisect.bisect_left(a, c)
    if idx <= b:
        a[:idx] = [c for _ in range(idx)]
    else:
        a[:b] = [c for _ in range(b)]
    a.sort()
print(sum(a))


### FIXED CODE ###

import bisect
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
d = []
cnt = 1
for i in range(n-1):
    if a[i+1] == a[i]:
        cnt += 1
    else:
        d.append([a[i], cnt])
        cnt = 1
d.append([a[n-1], cnt])


for i in range(m):
    b, c = [int(i) for i in input().split()]
    d.append([c, b])
d.sort(reverse=True)
ans = 0
j = 0
for i in range(n):
    if d[j][1] > 0:
        ans += d[j][0]
        d[j][1] -= 1
    if d[j][1] == 0:
        j += 1
print(ans)
### BUGGY CODE ###

n=int(input())
s=[]
for _ in range(n):
	s.append(input())
element=list(set(s))

Max=0
for i in element:
	Max=max(Max,s.count(i))

ans=[]
for i in element:
	if Max==s.count(i):
		ans.append(i)
ans.sort()
for i in ans:
	print(i)
		

### FIXED CODE ###

n=int(input())
s={}
for _ in range(n):
	_s=input()
	if _s in s:
		s[_s]=s[_s]+1
	else:
		s[_s]=1

s=sorted(s.items(),key=lambda x:(x[1],x[0]))
max=s[-1][1]
for i in s:
	if i[1]==max:
		print(i[0])
### BUGGY CODE ###

from itertools import *
n, k = map(int, input().split())
mod = 998244353
strides = []
for i in range(k):
  l, r = map(int, input().split())
  for t in range(l, r + 1):
    strides.append(t)
strides.sort()

d = [0] * (n + 1)  # マスに対応
d[0] = 1
for i in range(1, n):
  for stride in strides:
    if i >= stride:
      d[i] += d[i - stride]
  d[i] %= mod
print(d[n-1])

### FIXED CODE ###

n, k = map(int, input().split())
mod = 998244353
d = [0] * (n + 1)
d[1] = 1
LR =[list(map(int, input().split())) for _ in range(k)]

for i in range(2, n+1):
  d[i] = d[i - 1]
  for l, r in LR:
    if i - l <= 0:
      continue
    d[i] = (d[i] + (d[i-l] - d[max(0,i-r-1)])) % mod
print((d[-1] - d[-2])%mod)
### BUGGY CODE ###

n = int(raw_input())

c = 0

pn = []

for i in xrange(n):

    a = int(raw_input())

    if a==2:
        c+=1
        pn.append(a)
        continue

    for x in pn:
        if a==x:
            c+=1
            pn.append(a)
            break

    for x in xrange(2, a):
        if a%x==0:
            break

        if a-1==x and a%x!=0:
            c+=1

print c

### FIXED CODE ###

import math

n = int(raw_input())

def isPrime(a):
    if a==2 or a==3:
        return 1
    if a<2 or a%2==0:
        return 0
        
    i = int(math.sqrt(a))+1
    for x in xrange(3,i):
        if a%x==0:
            return 0
    return 1

cnt = 0
for _ in xrange(n):
    a = int(raw_input())
    cnt += isPrime(a)
print cnt
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
P = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    P[p-1] += x
ans = [-1] * N
#print(G)
#print(P)
def dfs(v, p):
    ans[v] = P[v] + p
    for vi in G[v]:
        if ans[vi] != -1:
            continue
        dfs(vi, ans[v])

dfs(0, 0)
#print(ans)
print(' '.join(map(lambda x: str(x), ans)))


### FIXED CODE ###

import sys

def main():
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    n, q = map(int, input().split())
    #n, q = map(int, "4 3".split())
    g = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        #a, b = map(int, ["1 2", "2 3", "2 4"][i].split())
        g[a-1].append(b-1)
        g[b-1].append(a-1)


    add = [0] * n
    for i in range(q):
        p, v = map(int, input().split())
        #p, v = map(int, ["2 10", "1 100", "3 1"][i].split())
        #dfs(p-1, v)
        add[p-1] += v

    ans = [0] * n
    def dfs(v,p,value): #p: parent of v
        value += add[v]
        ans[v] = value
        for c in g[v]:
            if c == p: continue
            dfs(c,v,value)
    dfs(0, -1, 0)
    """
    def dfs(start, point):
        stack = [start]
        while stack:
            x = stack.pop()
            ans[x] += point
            stack += g[x]
    """

    print(' '.join(map(str, ans)))

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

# E
from collections import Counter

H,W,M=map(int,input().split())
h,w,bomb=[0]*M,[0]*M,[]
for i in range(M):
    h[i],w[i]=map(int,input().split())
    bomb.append((h[i],w[i]))

most_h,most_w=Counter(h).most_common(),Counter(w).most_common()

def max_values(lis):
    max_num=lis[0][1]
    for i in range(len(lis)):
        if lis[i][1]<max_num:
            res=lis[:i]
            break
    else:
        res=lis
    return res

most_h=max_values(most_h)
most_w=max_values(most_w)

res=-1
k=0
for i,i_n in most_h:
    for j,j_n in most_w:
        if not (i,j) in bomb or k>M:
            res=i_n+j_n
            break
        k+=1
    if res>-1:
        break
else:
    res=i_n+j_n-1
print(res)


### FIXED CODE ###

H,W,M=map(int,input().split())
h,w,bomb=[0]*H,[0]*W,[]
for i in range(M):
    a,b=map(int,input().split())
    bomb.append((a-1,b-1))
    h[a-1]+=1
    w[b-1]+=1
    
max_h=max(h)
max_w=max(w)

bomb_and_max=0
for i,j in bomb:
    if h[i]==max_h and w[j]==max_w:
        bomb_and_max+=1
    
if bomb_and_max==h.count(max_h)*w.count(max_w):
    print(max_h+max_w-1)
else:
    print(max_h+max_w)
### BUGGY CODE ###

import sys
import array

from operator import itemgetter

def upd(ft,i):
	i+=1
	while(i<len(ft)):
		ft[i]+=1
		i+=i&-i

def get(ft,i):
	i+=1
	ret=0
	while(i!=0):
	    ret+=ft[i]
	    i-=i&-i
	return ret


def comb(cnt,x):
	return cnt[x]-1;

def main():

	input = sys.stdin.readline
	tl=200100

	ft=[0]*tl


	md = 998244353
	n = int(input())
	xy = [[0]*2 for _ in range(n)]
	yxi = [[0]*3 for _ in range(n)]
	ys = []
	hp = []
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))

	for i in range(n):
		yxi[i]=[xy[i][1],xy[i][0],i]
	yxi.sort(key=itemgetter(0))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def calc(ft,get,upd,cnt):
		for aa in yxi:
			ix=aa[2]
			a=get(ft,ix)
			b=get(ft,n)-a
			upd(ft,ix)
			c=ix-a
			d=n-ix-1-b
		#	exc=(comb(a+b)+comb(a+c)+comb(b+d)+comb(c+d)-comb(a)-comb(b)-comb(c)-comb(d))%md
		#	cur=(comb(n)-exc)%md
		#	ans=(ans+cur)%md
		#	ans=(ans+comb(cnt,n)-comb(cnt,a+b)-comb(cnt,a+c)-comb(cnt,b+d)-comb(cnt,c+d)+comb(cnt,a)+comb(cnt,b)+comb(cnt,c)+comb(cnt,d))%md
			yield(comb(cnt,n)-comb(cnt,a+b)-comb(cnt,a+c)-comb(cnt,b+d)-comb(cnt,c+d)+comb(cnt,a)+comb(cnt,b)+comb(cnt,c)+comb(cnt,d))%md

	print((sum(calc(ft,get,upd,cnt)))%md)

main()


### FIXED CODE ###

import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()
### BUGGY CODE ###

from bisect import *
while 1:
    n, lmt = map(int, raw_input().split())
    if n == 0: break
    p = [input() for i in range(n)]
    p = sorted(set(i + j for i in p for j in p))
    s = bisect(p, lmt)
    ans = 0
    for i in p[:s]:
        t = bisect(p[:s], lmt - i)
        ans = max(ans, i + p[t-1])
    print ans

### FIXED CODE ###

from bisect import *
while 1:
    n, lmt = map(int, raw_input().split())
    if n == 0: break
    p = [input() for i in range(n)] + [0]
    p = sorted(set(i + j for i in p for j in p))
    s = bisect(p, lmt)
    print max(i + p[bisect(p, lmt - i) - 1] for i in p[:s])
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
keep=1
count=0
lis=[]
while keep!=2:
  count+=1
  if keep in lis:
    print(-1)
    break
  lis.append(keep)
  keep=a[keep-1]
  if keep==2:
    print(count)
    break

### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
keep=1
count=0
ababa=0
for i in range(n):
  count+=1
  keep=a[keep-1]
  if keep==2:
    ababa=1
    print(count)
    break
if ababa==0:
  print(-1)
### BUGGY CODE ###

from collections import deque
def permutation(n, x, mod=10**9+7):
    # nPx
    # 順列
    # ex) permutaion(5, 2) = 20
    tmp = 1
    for i in range(n, n-x, -1):
        tmp = (tmp * i) % mod
    return tmp

def power_func(a,b,p=10**9+7):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

n,v=map(int,input().split())
m=10**9+7
perm1=deque([1])
perm2=deque([permutation(v,n)])
comb=deque([1])
ones=deque([1])
acc=((comb[-1]*perm1[-1]%m)*perm2[-1]**2)%m
for k in range(n):
  #nCk+1=nCk*(n-k/k+1)
  comb.append((comb.pop()*(n-k)*power_func(k+1,m-2))%m)
  #vPk+1=vPk*(v-k)
  perm1.append((perm1.pop()*(v-k))%m)
  #v-(k+1)Pn-(k+1)=v-kPn-k/(v-k)
  perm2.append((perm2.pop()*power_func(v-k,m-2))%m)
  #(-1)^k+1=(-1)^k*(-1)
  ones.append(ones.pop()*(-1))
  acc+=ones[-1]*((comb[-1]*perm1[-1]%m)*perm2[-1]**2)%m
print(acc%m)


### FIXED CODE ###

from collections import deque
#from functools import lru_cache

def permutation(n, x, mod=10**9+7):
    # nPx
    # 順列
    # ex) permutaion(5, 2) = 20
    tmp = 1
    for i in range(n, n-x, -1):
        tmp = (tmp * i) % mod
    return tmp

def power_func(a,n,p=10**9+7):
    bi = str(format(n,"b"))#2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res*res) %p
        if bi[i] == "1":
            res = (res*a) %p
    return res


n,v=map(int,input().split())
m=10**9+7
perm1=deque([1])
perm2=deque([permutation(v,n)])
comb=deque([1])
ones=deque([1])
acc=((comb[-1]*perm1[-1]%m)*perm2[-1]**2)%m
for k in range(n):
  #nCk+1=nCk*(n-k/k+1)
  comb.append((comb.pop()*(n-k)*power_func(k+1,m-2))%m)
  #vPk+1=vPk*(v-k)
  perm1.append((perm1.pop()*(v-k))%m)
  #v-(k+1)Pn-(k+1)=v-kPn-k/(v-k)
  perm2.append((perm2.pop()*power_func(v-k,m-2))%m)
  #(-1)^k+1=(-1)^k*(-1)
  ones.append(ones.pop()*(-1))
  acc+=ones[-1]*((comb[-1]*perm1[-1]%m)*perm2[-1]**2)%m
print(acc%m)
### BUGGY CODE ###

import  math
K = int(input())

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for l in range(1, K + 1):
            ans  += math.gcd(i, math.gcd(j, l))
            
            
print(ans)


### FIXED CODE ###

from math import gcd
 
k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            ans += gcd(i, gcd(j,m))
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
a = []
b = []
for _ in range(n):
    a1,b1 = map(int,input().split())
    a.append(a1)
    b.append(b1)
ans = 0
cnt = 0
flag = 1
while flag:
    flag = 0
    for i in range(n-1,0,-1):
        if a[i] < a[i-1]:
            a[i],a[i-1] = a[i-1],a[i]
            b[i],b[i-1] = b[i-1],b[i]
            flag = 1
for i in range(n):
    flag = 1
    while b[i] > 0 and cnt < m:
        ans += a[i]
        cnt += 1
        b[i] -= 1
        flag = 0
    if flag:
        break
print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
a = []
b = []
for _ in range(n):
    a1,b1 = map(int,input().split())
    a.append(a1)
    b.append(b1)
c = sorted(zip(a,b))
ans = 0
for i in range(n):
    if m > c[i][1]:
        ans += c[i][0]*c[i][1]
        m -= c[i][1]
    else:
        ans += c[i][0]*m
        break
print(ans)
### BUGGY CODE ###

N = int(input())
l = []

for _ in range(N):
    a = int(input())
    if a not in l:
        l.append(a)
    else:
        del l[l.index(a)]
        
print(len(l))

### FIXED CODE ###

from collections import Counter

N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))
    
a = Counter(a)
ans = 0
for value in a.values():
    if value % 2 == 1:
        ans += 1
print(ans)
### BUGGY CODE ###

n = int(raw_input())
m = [int(x) for x in raw_input().split()]
a = 0
possible = True
while possible:
    dividiu = False
    for i in range(n):
        if not dividiu and m[i] % 2 == 0:
            m[i] /= 2
            dividiu = True
        else:
            m[i] *= 3
    if not dividiu:
        possible = False
    else:
        a += 1

print a

### FIXED CODE ###

n = int(input())
a = map(int, input().split())
 
cont = 0
 
for e in a:
    x = e
    while x % 2 == 0:
        x /= 2
        cont += 1
 
print(cont)
### BUGGY CODE ###

import numpy as np
H, W = map(int, input().split())

grid = [[] for h in range(H)]

for h in range(H):
    grid[h] = list(input())

L = np.array([[0] * W for h in range(H)])
U = np.array([[0] * W for h in range(H)])
R = np.array([[0] * W for h in range(H)])
D = np.array([[0] * W for h in range(H)])

for h in range(H):
    for w in range(W):

        if grid[h][w] != '#':
            if w == 0:
                L[h][w] = 1
            else:
                L[h][w] = L[h][w - 1] + 1
            if h == 0:
                U[h][w] = 1
            else:
                U[h][w] = U[h - 1][w] + 1

        if grid[H - h - 1][W - w - 1] != '#':
            if w == 0:
                R[H - h - 1][W - w - 1] = 1
            else:
                R[H - h - 1][W - w - 1] = R[H - h - 1][W - w] + 1
            if h == 0:
                D[H - h - 1][W - w - 1] = 1
            else:
                D[H - h - 1][W - w - 1] = D[H - h][W - w - 1] + 1

print(max((L + R + U + D - 3).ravel()))

### FIXED CODE ###

import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'

D = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)

for h in range(H):
    U[h] = (U[h - 1] + 1) * S[h]
    D[-h - 1] = (D[-h] + 1) * S[-h - 1]
for w in range(W):
    L[:, w] = (L[:, w - 1] + 1) * S[:, w]
    R[:, -w - 1] = (R[:, -w] + 1) * S[:, -w - 1]
print(np.max(U + D + L + R) - 3)
### BUGGY CODE ###

import sys

def main():
    N, M = map(int, input().split())
    a = [int(sys.stdin.readline().strip()) for _ in range(M)]

    dp=[0] * (N+1)
    for i in range(0, N+1):
        if i in a:
            dp[i] = 0
            continue

        if i == 0 or i == 1:
            dp[i] = 1
            continue

        if dp[i-1] == 0 and dp[i-2] == 0:
            break


        dp[i] = dp[i-1] + dp[i-2]

    print(dp[N] % 1000000007)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from collections import deque

def main():
    N, M = map(int, input().split())
    a = deque([int(sys.stdin.readline().strip()) for _ in range(M)])

    atmp = -1
    if len(a) != 0:
        atmp = a.popleft()

    dp=[0] * (N+1)
    for i in range(0, N+1):
        if i == atmp:
            if len(a) != 0:
                atmp = a.popleft()
            continue

        if i == 0 or i == 1:
            dp[i] = 1
            continue

        if dp[i-1] == 0 and dp[i-2] == 0:
            break


        dp[i] = dp[i-1] + dp[i-2]

    print(dp[N] % 1000000007)

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

# D - Knapsack Queries on a tree

def main():
    from sys import stdin
    import bisect

    readline = stdin.readline

    n = int(readline())

    v = [0] * n
    w = [0] * n
    for i in range(n):
        v[i], w[i] = map(int, readline().split())

    max_l = 10 ** 5

    # dp table (for some amount)
    dp = [None] * min(n, 2 ** 14)

    # dp[vertex] = list of (weight, value)
    dp[0] = [(0, 0), (w[0], v[0])]

    for u in range(1, len(dp)):
        parent = (u - 1) // 2

        dp[u] = dp[parent].copy()
        for ww, vv in dp[parent]:
            dp[u].append((ww + w[u], vv + v[u]))
        dp[u].sort()

        # remove unnecessary entries
        tail = 0
        for i in range(1, len(dp[u])):
            if dp[u][i][0] > max_l:
                break
            if dp[u][tail][0] == dp[u][i][0]:
                dp[u][tail] = dp[u][i]
            elif dp[u][tail][1] < dp[u][i][1]:
                tail += 1
                dp[u][tail] = dp[u][i]
        del dp[u][tail + 1:]

    dpw = [None] * len(dp)

    def solve(u, l):
        if u < len(dp):
            if not dpw[u]:
                dpw[u] = [w for w, v in dp[u]]
            x = bisect.bisect_right(dpw[u], l) - 1
            return dp[u][x][1]

        parent = (u - 1) // 2
        s = solve(parent, l)
        if l >= w[u]:
            t = v[u] + solve(parent, l - w[u])
            if s < t:
                s = t
        return s

    q = int(readline())
    for i in range(q):
        u, l = map(int, readline().split())
        print(solve(u - 1, l))

main()


### FIXED CODE ###

# D - Knapsack Queries on a tree

from sys import stdin
import bisect

readline = stdin.readline
bisect_right = bisect.bisect_right

n = int(readline())

v = [0] * n
w = [0] * n
for i in range(n):
    v[i], w[i] = map(int, readline().split())

max_l = 10 ** 5
vshift = 21
mask = (1 << vshift) - 1

# dp table (for some amount)
dp = [None] * min(n, 2 ** 12)

# dp[vertex] = list of (weight, value)
dp[0] = [(0 << vshift) + 0, (w[0] << vshift) + v[0]]

for u in range(1, len(dp)):
    parent = (u - 1) // 2

    ls = dp[parent][:]
    ls.extend(x + (w[u] << vshift) + v[u] for x in dp[parent]
              if (x >> vshift) + w[u] <= max_l)
    ls.sort()

    # remove unnecessary entries
    tail = 0
    for i in range(1, len(ls)):
        if (ls[tail] >> vshift) == (ls[i] >> vshift):
            ls[tail] = ls[i]
        elif (ls[tail] & mask) < (ls[i] & mask):
            tail += 1
            ls[tail] = ls[i]
    del ls[tail + 1:]
    dp[u] = ls

def solve(u, l):
    if u < len(dp):
        x = bisect_right(dp[u], (l << vshift) + mask) - 1
        return dp[u][x] & mask

    parent = (u - 1) // 2
    s = solve(parent, l)
    if l >= w[u]:
        s = max(s, v[u] + solve(parent, l - w[u]))
    return s

q = int(readline())
for i in range(q):
    u, l = map(int, readline().split())
    print(solve(u - 1, l))
### BUGGY CODE ###

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

cnt = 0
for i in range(1,N+1):
  M  = min(P_list[:i])
  if M == P_list[i-1]:
    cnt += 1

print(cnt)

### FIXED CODE ###

N = int(input())
P_list = list(map(int,input().split()))
M = P_list[0]
cnt = 1

for i in range(N):
  if M > P_list[i]:
    cnt += 1
    M = P_list[i]

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

import sys 
import random
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
D = int(readline())
C = list(map(int,readline().split()))
score = []
t = []
for i in range(D):
    s = list(map(int,readline().split()))
    max_ind = s.index(max(s)) + 1
    t.append(max_ind)
    score.append(s)

M = 10000

d = [random.randint(1, D) for i in range(M)]
q = [random.randint(1, 26) for i in range(M)]
max_S = -float('inf')
for i in range(M):
    t[d[i]-1] = q[i]
    S = 0
    last = [0] * 26
    for day in range(D):
        select = t[day]-1
        S += score[day][select]
        last[select] = day+1
        for i in range(26):
            S -= C[i] * (day+1-last[i]) 
    if S > max_S:
        ans = t
        max_S = S
print('\n'.join(str(n) for n in ans))

### FIXED CODE ###

import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
D = int(readline())
C = list(map(int,readline().split()))
score = []
t = []
for i in range(D):
    s = list(map(int,readline().split()))
    max_ind = s.index(max(s)) + 1
    t.append(max_ind)
    score.append(s)
last = [0] * 26
S = 0
for d in range(D):
    select = t[d]-1
    S += score[d][select]
    last[select] = d+1
    for i in range(26):
        S -= C[i] * (d+1-last[i]) 
for i in range(D):
    print(t[i])
### BUGGY CODE ###

n, m = map(int, input().split())
p, y = [0]*m, [0]*m
dict_p = {}
for i in range(m):
    p[i], y[i] = map(int, input().split())
    if p[i] not in dict_p.keys():
        dict_p[p[i]] = list()

    dict_p[p[i]].append(y[i])
#print(dict_p)
ans = [0]*m
for i in range(m):
    dict_p[p[i]].sort()
    l = 0
    r = len(dict_p[p[i]])
    while r-l > 1:
        mid = (l+r)//2
        if dict_p[p[i]][mid] <= y[i]:
            l = mid
        elif dict_p[p[i]][mid] > y[i]:
            r = mid

    i0 = l + 1
    p0 = p[i]
    ans = str("{:0=6}".format(p0)) + str("{:0=6}".format(i0))
    print(ans)

### FIXED CODE ###

from bisect import bisect_left
from collections import defaultdict
n, m = map(int, input().split())
py = []
dict_p = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    py.append((p, y))
    dict_p[p].append(y)
#print(dict_p)
for values in dict_p.values():
    values.sort()

for p, y in py:
    x = bisect_left(dict_p[p], y)
    ans = "{:006}".format(p) + "{:006}".format(x+1)
    print(ans)
### BUGGY CODE ###

import sys
from collections import deque
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = rl()
grid = [list(rs()) for _ in range(H)]
INF = 1000

def bfs(sx, sy, gx, gy):
    d = [[INF] * W for _ in range(H)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque()
    que.append((sx, sy))
    d[sy][sx] = 0
    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]                
            if 0 <= ny and ny <= H-1 and 0 <= nx and nx <= W-1 and \
                    grid[ny][nx] != '#' and d[ny][nx] == INF:
                d[ny][nx] = d[p[1]][p[0]] + 1
                que.append((nx, ny))
    return d[gy][gx]

answer = 0
for s in range(H):
    for t in range(W):
        for u in range(s, H):
            for v in range(W):
                if grid[s][t] == '#' or grid[u][v] == '#':
                    continue
                if s == u and t == v:
                    continue
                dis = bfs(t, s, v, u)
                if dis < 400 and dis > answer:
                    answer = dis

print(answer)


### FIXED CODE ###

import sys
from collections import deque
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = rl()
grid = [list(rs()) for _ in range(H)]
INF = 1000

def bfs(sx, sy):
    d = [[INF] * W for _ in range(H)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque()
    que.append((sx, sy))
    d[sy][sx] = 0
    while que:
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]                
            if 0 <= ny and ny <= H-1 and 0 <= nx and nx <= W-1 and \
                    grid[ny][nx] != '#' and d[ny][nx] == INF:
                d[ny][nx] = d[p[1]][p[0]] + 1
                que.append((nx, ny))
    dis = [[0 if x == INF else x for x in row] for row in d]
    return max([max(y) for y in dis])

answer = 0

for s in range(H):
    for t in range(W):
        if grid[s][t] == '#':
            continue
        distance = bfs(t, s)
        if distance > answer:
            answer = distance

print(answer)