Harryxun/stf_run huggingface dataset:
import sys
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
h.sort()
a = N - K
i = 0
h_left = h[:a]
h_right = h[K:]
h_middle = h[a:K]
if a != N//2:
    ans = min(h_middle[-1] - h_left[0], h_right[-1] - h_middle[0]) 
    for i in range(len(h_right)-1):
        j = a - i - 1
        ans_ = h_right[i] - h_left[j]
        ans = min(ans, ans_)
    print(ans)
else:
    ans = min(h_middle[-1] - h_left[0], h_right[-1] - h_right[0]) 
    for i in range(len(h_right)-1):
        j = a - i - 1
        ans_ = h_right[i] - h_left[j]
        ans = min(ans, ans_)
    print(ans)
    

### FIXED CODE ###

N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))
N = int(input())
a = list(map(int, input().split()))
res = [0] + a[:]
 
for i in range(n, 0, -1):
    ans[i] = sum(ans[i : : i]) % 2 
print(sum(res))
print(*[i + 1 for i in range(n) if res[i]])


### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
res = [0] + a[:]
for i in range(N, 0, -1):
  res[i] = sum(res[i : : i]) % 2 
print(sum(res))
print(*[i for i in range(N + 1) if res[i]])
#!/usr/bin/env python

def func():
    n,m = [int(i) for i in input().split(" ")]
    dic = {}
    same = 0
    for i in range(m):
        tmp = [int(i) for i in input().split(" ")]

        if tmp[0] not in dic.keys():
            dic[tmp[0]] = tmp[1]
        else:
            if dic[tmp[0]] != tmp[1]:
                print("No")
                return
            else:
                same += 1
    a = [0] * (m-same)
    for key in dic.keys():
        print(key)
        a[key-1] = dic[key]

    if a[0] == 0:
        print("No")
        return

    for i in a:
        print(i, end = "")

    print("")

if __name__ == "__main__":
    func()

### FIXED CODE ###

#!/usr/bin/env python

n, m = input().split(" ")
n = int(n)
m = int(m)
s_len = []
c_len = []
dig = 10**(n-1)

for i in range(m):
    tmp = input().split(" ")
    s_len.append(int(tmp[0]))
    c_len.append(int(tmp[1]))

for i in range(0, dig*10):
    flag = False
    if len(str(i)) < n:
        continue
    for j,s in enumerate(s_len):
        if str(i)[s-1] != str(c_len[j]) and flag == False:
            flag = True
            break
    if flag==False:
        print(i)
        exit()

print("-1")
# coding: utf-8

import math

N, K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
A.sort()

print(A)

fact = [0 for i in range(N+1)]
for i in range(N+1):
	fact[i] = math.factorial(i)

sum_max_s = 0
for i in range(K, N+1):
	sum_max_s += A[i-1] * (fact[i-1] / (fact[K-1] * fact[i-K]))

sum_min_s = 0
for i in range(1, N-K+2):
	sum_min_s += A[i-1] * (fact[N-i] / (fact[K-1] * fact[N-i-K+1]))

print(str(int(sum_max_s - sum_min_s) % (10**9 + 7)))

### FIXED CODE ###

# coding: utf-8

import math

N, K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
A.sort()

p = 10**9 + 7
facts = [1, 1]
for i in range(2, N+1):
	facts.append((facts[i-1] * i) % p)

invs = [1 for i in range(N+1)]
invs[N] = pow(facts[N], p-2, p)
for i in range(N, 1, -1):
	invs[i-1] = invs[i] * i % p

sum_max_s = 0
for i in range(K, N+1):
	sum_max_s += A[i-1] * (facts[i-1] * invs[K-1] * invs[i-K] % p) % p

sum_min_s = 0
for i in range(1, N-K+2):
	sum_min_s += A[i-1] * (facts[N-i] * invs[K-1] * invs[N-i-K+1] % p) % p

print(str(int(sum_max_s - sum_min_s) % p))
n, m = map(int, input().split())
a = list(map(int, input().split()))
d = n-sum(a)
if(a<0):
  d = -1
pritn(d)

### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
d = n-sum(a)
if(d<0):
  d = -1
print(d)
from math import ceil

a,b=map(int,input().split())

print(math.ceil(a//(2*b+1)))


### FIXED CODE ###

a,b=map(int,input().split())

ans = a//(2*b+1)

if a%(2*b+1) == 0: pass
else: ans += 1
print(ans)
import sys
sys.setrecursionlimit(10**6)

n, k = map(int, input().split())
A = list(map(int, input().split()))
L = [1]
S = {1}
def f(L, S):
    last = L[-1]-1
    if A[last] not in S:
        L.append(A[last])
        S |= {last}
        return f(L, S)
    else:
        return L
P = f(L, S)
a = A[P[-1]-1]
j = P.index(a)
r = len(P)
l = r - j

if k+1 <= j:
    print(P[k])
else:
    print(P[j+(k-j)%l])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n, k = map(int, input().split())
A = list(map(int, input().split()))
L = [1]
S = {1}

def f(L, S):
    last = L[-1]-1
    if A[last] not in S:
        L.append(A[last])
        S |= {A[last]}
        return f(L, S)
    else:
        return L
P = f(L, S)
a = A[P[-1]-1]
j = P.index(a)
r = len(P)
l = r - j

if k+1 <= j:
    print(P[k])
else:
    print(P[j+(k-j)%l])
from functools import reduce
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


N = int(input())
A = set(map(int, input().split()))
A = sorted(list(A))

ans = max(reduce(gcd, A[2:], A[0]), reduce(gcd, A[1:]))
print(ans)


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


N = int(input())
A = list(map(int, input().split()))
L = [0]*(N+1)
R = [0]*(N+1)

for i in range(N):
    L[i+1] = gcd(L[i], A[i])

for i in reversed(range(N)):
    R[i] = gcd(R[i+1], A[i])

ans = max([gcd(x, y) for x, y in zip(L, R[1:])])
print(ans)
L, R = map(int, input().split())

MIN = 2018
if R-L > 4039:
    MIN = 0


MOD = 2019
L = L%MOD
R = R%MOD
if L > R:
    L, R = R, L
else if L == R:
    MIN = 0


for i in range(L, R):
    for j in range(i+1, R+1):
        buf = (i*j) % MOD
        #print(i, j)
        MIN = min(buf, MIN)

print(MIN)

### FIXED CODE ###

L, R = map(int, input().split())

MIN = 2018
if R-L > 4039:
    MIN = 0


MOD = 2019
L = L%MOD
R = R%MOD
if L > R:
    L, R = R, L
elif L == R:
    MIN = 0


for i in range(L, R):
    for j in range(i+1, R+1):
        buf = (i*j) % MOD
        #print(i, j)
        MIN = min(buf, MIN)

print(MIN)
S = input()
T = input()

d = [[] for _ in range(26)]
alpha2num = lambda c: ord(c) - ord("a") + 1
ans = 0

for i, s in enumerate(S):
    d[alpha2num(s)].append(i)

idx = -1
for t in T:
    dl = d[alpha2num(t)]
    if not(dl):
        ans = -1
        break
    for i in dl:
        if i > idx:
            ans += i - idx
            idx = i
            break
    else:
        ans += (len(S) - idx + dl[0])
        idx = dl[0]

print(ans)

### FIXED CODE ###

import bisect

S = input()
T = input()

d = [[] for _ in range(27)]
alpha2num = lambda c: ord(c) - ord("a") + 1

for i, s in enumerate(S):
    d[alpha2num(s)].append(i)

idx = -1
l = 0
ans = 0
for t in T:
    dl = d[alpha2num(t)]
    if not dl:
        ans = -1
        break
    insert_idx = bisect.bisect_right(dl, idx)
    if insert_idx == len(dl):
        l += 1
        idx = dl[0]
    else:
        idx = dl[insert_idx]
    ans = l * len(S) + idx + 1

print(ans)
a = input()
s = input()
if a >= 3200
    print(s)
else 
    print("red")
  

### FIXED CODE ###

a  = int(input())
s = str(input())
if a >= 3200 :
    print(s)
else :
    print("red")
A,B=map(int,input())
c=0
if B%A!=0:
  c=1
print(B+c)

### FIXED CODE ###

A,B=map(int,input().split())
s=1
cut=0
while B>s:
    cut+=1
    s=s+A-1
print(cut)
N=list(input())

n=reversed(N)

if n[0]=="2" or n[0]=="4" or n[0]=="5" or n[0]=="7" or n[0]=="9":
    print(hon)
if n[0]=="0" or n[0]=="1" or n[0]=="6" or n[0]=="8":
    print(pon)
if n[0]=="3":
    print(bon)


### FIXED CODE ###

n=list(input())

n==n.reverse()

if (n[0]=="2" or n[0]=="4" or n[0]=="5" or n[0]=="7" or n[0]=="9"):
    print("hon")
elif (n[0]=="0" or n[0]=="1" or n[0]=="6" or n[0]=="8"):
    print("pon")
elif (n[0]=="3"):
    print("bon")
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

h,w,k = inpl()
s = [list(input()) for _ in range(h)]
res = INF
for yoko in itertools.product([0,1], repeat=(h-1)):
    # 0:uncut 1:cut
    ln = sum(yoko)
    gr = [[] for _ in range(ln+1)] 
    gr[0].append(0)
    ind = 0
    for i in range(1,h):
        if yoko[i-1]: ind += 1
        gr[ind].append(i)
    possible = True
    for x in range(w):
        for ind in range(ln+1):
            cnt = 0
            for y in gr[ind]:
                if s[y][x] == '1':
                    cnt += 1
            if cnt > k:
                possible = False
                break
        if not possible:
            break
    else:
        cutcnt = 0
        now = [0] * (ln+1)
        for x in range(w):
            for ind in range(ln+1):
                for y in gr[ind]:
                    if s[y][x] == '1':
                        now[ind] += 1
            if max(now) > k:
                now = [0] * (ln+1)
                cutcnt += 1
                for ind in range(ln+1):
                    for y in gr[ind]:
                        if s[y][x] == '1':
                            now[ind] += 1
    res = min(res, cutcnt + ln)
print(res)

### FIXED CODE ###

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,K = inpl()
s = [input() for _ in range(n)]
res = INF
for pat in itertools.product([0,1], repeat=n-1):
    pat = list(pat) + [0]
    group = []
    tmp = []
    for i,j in enumerate(pat):
        tmp += [i]
        if j or i == n-1:
            group += [tmp]
            tmp = []
    
    ln = len(group)
    white = [[0]*ln for _ in range(m)]
    ccc = set()
    cnt = pat.count(1) 
    ok = True
    for i in range(m):
        for j,z in enumerate(group):
            for k in z:
                if s[k][i] == '1':
                    white[i][j] += 1
            if max(white[i]) > K:
                ok = False
                break
    if not ok: continue
    
    now = [0] * ln
    for i in range(m):
        ok = True
        for j in range(ln):
            if now[j] + white[i][j] > K:
                ok = False
                break
        if ok:
            for j in range(ln):
                now[j] += white[i][j]
        else:
            cnt += 1
            for j in range(ln):
                now[j] = white[i][j]
    res = min(res, cnt)
print(res)
#!usr/bin/env python3

import sys


def string_to_list_spliter():
    lst = [int(i) for i in sys.stdin.readline().split()]
    return lst


def main():
    lst = string_to_list_spliter()
    print(min(lst), max(lst), sum())


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!usr/bin/env python3

import sys


def string_to_list_spliter():
    lst = [int(i) for i in sys.stdin.readline().split()]
    return lst


def main():
    # XXX: N????????´??°??????????????????????????????AOJ?????£???????????????
    n = sys.stdin.readline()
    lst = string_to_list_spliter()
    print(min(lst), max(lst), sum(lst))


if __name__ == '__main__':
    main()
n=int(input())
x=input()
X=0
for i in range(n):
    X+=int(x[n-1-i])*(2**i)

lis=[0,1]

for i in range(2,n+1):
    ni=i
    cnti=0
    while ni!=0:
        if ni%2==1:
            cnti+=1
        ni=ni//2
    lis.append(lis[i%cnti]+1)

cnt=0
for i in range(len(x)):
    if x[i]=="1":
        cnt+=1

for i in range(n):
    Xi=X
    ci=cnt
    if x[i]=="0":
        Xi+=2**(n-1-i)
        ci+=1
    else:
        Xi-=2**(n-1-i)
        ci-=1
    print(lis[Xi%ci]+1)

### FIXED CODE ###

import sys

n=int(input())
x=input()

if n==1:
    if x=="0":
        print(1)
    else:
        print(0)
    sys.exit()


lis=[0,1]

for i in range(2,n+1):
    ni=i
    cnti=0
    while ni!=0:
        if ni%2==1:
            cnti+=1
        ni=ni//2
    lis.append(lis[i%cnti]+1)

cnt=0
for i in range(len(x)):
    if x[i]=="1":
        cnt+=1

cpls=cnt+1
cmns=cnt-1

cplis=[1]
if cpls!=0:
    for i in range(n):
        cplis.append((cplis[i]*2)%cpls)
cmlis=[1]
if cmns!=0:
    for i in range(n):
        cmlis.append((cmlis[i]*2)%cmns)

cpsum=0
cmsum=0
for i in range(n):
    if x[i]=="1":
        cpsum=(cpsum+cplis[n-1-i])%cpls
        if cmns!=0:
            cmsum=(cmsum+cmlis[n-1-i])%cmns

for i in range(n):
    if x[i]=="0":
        Xi=(cpsum+cplis[n-1-i])%cpls
        print(lis[Xi]+1)
    else:
        if cmns==0:
            print(0)
        else:
            Xi=(cmsum-cmlis[n-1-i])%cmns
            print(lis[Xi]+1)
import math
a, b = map(int, input().split())
def lcm(a, b):
    return (a * b) // math.gcd(a, b)
print(lcm(a, b))

### FIXED CODE ###

a, b = map(int, input().split())
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
print(lcm(a,b))
N = input()
a = map(int, input().split())

def f(x):
  cnt = 0
  cur = 0
  for ai in a:
    cur += ai
    cur *= x
    if cur < 0:
      cnt += 1 - ai
    x *= -1
  print(cnt)

print(min(f(1), f(-1))

### FIXED CODE ###

N = input()
a = list(map(int, input().split()))
 
def f(x):
  cnt = 0
  cur = 0
  for ai in a:
    cur += ai
    cur *= x
    if cur <= 0:
      cnt += 1 - cur
      cur = 1
    cur *= x
    x *= -1
  return cnt
 
print(min(f(1), f(-1)))
a,b=map(int,input().split())
b=input()
if b%a==0:
  print(a+b)
else:
  print(b-a)

### FIXED CODE ###

a,b=map(int,input().split())
if b%a==0:
  print(a+b)
else:
  print(b-a)
from __future__ import division, print_function
from sys import stdin, maxint
 
 
def main():
    num = int(stdin.readline())
 
    y = []
    for _ in xrange(num):
        it = iter(int(s) for s in stdin.readline().split()[1:])
        y.append([(next(it), next(it)) for _ in xrange(next(it))])
    weight = [maxint] * num
    weight[0] = 0
    t = set(xrange(1, num))
    index = 0
 
    while t:
        for v, cost in y[index]:
            if v not in t:
                continue
            weight[v] = min(weight[v], cost + weight[index])
        index = min(t, key=lambda i: weight[i])
        t.remove(index)
    for i, d in enumerate(weight):
        print(i, d)
 
 
main()

### FIXED CODE ###

from __future__ import division, print_function
from sys import stdin, maxint
 
 
def main():
    x = int(stdin.readline())
 
    y = []
    for _ in xrange(x):
        y.append([int(s) for s in stdin.readline().split()])
 
    g = set(xrange(1, x+1))
    index = g.pop()
    h = {index}
    leng = 0
 
    while g:
        minimum = maxint

        for j in h:
            mj = y[j-1]
            for i in g:
                if 0 <= mj[i-1] < minimum:
                    index = i
                    minimum = mj[i-1]

        h.add(index)
        g.remove(index)
        leng += minimum
 
    print(leng)
 
 
main()
n = int(input())
p = list(map(int, input().split()))


for i in range(n):
    for j in range(n):
        temp = list(copy(p))
        temp[i], temp[j] = temp[j], temp[i]
        sorted_temp = sorted(temp)

        if sorted_temp  == temp:
            print("YES")
            exit()

print("NO")

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))

for i in range(n):
    for j in range(n):
        temp = p.copy()
        temp[i], temp[j] = temp[j], temp[i]
        sorted_temp = sorted(temp)

        if sorted_temp  == temp:
            print("YES")
            exit()

print("NO")
N,R = map(int,input())
if N < 10:
  R = 100 * (10 - N)
  print(R)
else:
  print(R)

### FIXED CODE ###

N,R = map(int,input().split())
if N < 10:
  R = R + 100 * (10 - N)
  print(R)
else:
  print(R)
A={1, 3, 5, 7, 8, 10, 12}
B={4, 6, 9, 11}
C={2}
x, y = {map(int, input().split())}
print("Yes" if {x, y} <= A or {x, y} <= B or {x, y} <= C else "No")
    

### FIXED CODE ###

x, y = map(int, input().split())
A=[1, 3, 5, 7, 8, 10, 12]
B=[4, 6, 9, 11]
C=[2]
if (x in A and y in A) or (x in B and y in B) or (x in C and y in C):
    print("Yes")
else:
    print("No")
n = int(input())
a = list(map(int, input().split()))

flag = True
for i in range(n):
    if a[i+1] != 0:
        flag = False
        break

if n != 0 and a[0] != 0:
    print(-1)
    exit()
elif n == 0 and a[0] == 1:
    print(1)
    exit()

nleaf = 1
ans = 0
v = list()

for i in range(n):
    nleaf -= a[i]
    v.append(nleaf)
    nleaf *= 2

if nleaf < a[i]:
    print(-1)
    exit()

nleaf = a[n]
ans += a[n]
for i in range(n-1, -1, -1):
    if v[i]*2 < nleaf:
        print(-1)
        exit()
    if v[i] > nleaf:
        v[i] = nleaf
    nleaf = v[i] + a[i]
    ans += nleaf
print(ans)

### FIXED CODE ###

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

flag = True
for i in range(n):
    if a[i+1] != 0:
        flag = False
        break

if n != 0 and a[0] != 0:
    print(-1)
    exit()
elif n == 0 and a[0] == 1:
    print(1)
    exit()

nleaf = 1
ans = 0
v = list()

for i in range(n):
    nleaf -= a[i]
    v.append(nleaf)
    nleaf *= 2

if nleaf < a[n]:
    print(-1)
    exit()

nleaf = a[n]
ans += a[n]
for i in range(n-1, -1, -1):
    if v[i]*2 < nleaf:
        print(-1)
        exit()
    if v[i] > nleaf:
        v[i] = nleaf
    nleaf = v[i] + a[i]
    ans += nleaf
print(ans)
def dfs(v, p=-1):
    for nx in G[v]:
        if nx==p: continue
        ans[nx] += ans[v]
        dfs(nx, v)

n, q = map(int, input().split())
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(lambda x:x-1, map(int, input().split()))
    G[a].append(b)
    G[b].append(a)

ans = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x

dfs(0)
print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
n, q = map(int, input().split())
G = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(lambda x: x-1, map(int, input().split()))
    G[a].append(b)
    G[b].append(a)

ans = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x

def dfs(v, pre=-1):  
    for nx in G[v]:
        if nx==pre:
            continue
        ans[nx] += ans[v]
        dfs(nx,v)
dfs(0)
print(*ans)
N,M = map(int,input().split())
m = 0
v = input().split()
for i in range(N): v[i] = int(v[i])
  
v.sort(reverse=True)
v_min = sum(v)/4/M

while v[0]:
  if v.pop(0) >= v_min:
    m += 1

if M <= m:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N,M = map(int,input().split())
m = 0
v = input().split()
for i in range(N): v[i] = int(v[i])
  
v.sort(reverse=True)
v_min = sum(v)/4/M

while len(v):
  if v.pop(0) >= v_min:
    m += 1
  else:
    break

if M <= m:
  print("Yes")
else:
  print("No")
from math import gcd
n,k = map(int,input().split())
a = list(map(int,input().split()))
G = a[0]
for i in a:
    G = gcd(G,i)
if k<=max(a) and k%G==0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


### FIXED CODE ###

from fractions import gcd
n,k = map(int,input().split())
a = list(map(int,input().split()))
G = a[0]
for i in a:
    G = gcd(G,i)
if k<=max(a) and k%G==0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
print("ABC{0}".format(input())

### FIXED CODE ###

print("ABC{0}".format(input()))
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    flag = 1
    for i in range(m):
        if int(input()) == 1:
            flag = 0
    print('{:.10f}'.format(n/2 if flag else 0))

### FIXED CODE ###

while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    p = sorted(list(map(int, input().split())))
    flag = 0 if p[0]==1 else 1
    print('{:.10f}'.format(n/2 if flag else 0))
if sotred(list(map(int,input().split())))==[5,5,7]:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

if sorted(list(map(int,input().split())))==[5,5,7]:
  print('YES')
else:
  print('NO')
import sys
sys.setrecursionlimit(1000000000000)

def process():
    data = []
    for line in get_data():
        line = line.split()
        if len(line) == 2:
            if line[0] == line[1] == '0':
                data = []
                continue
            H = int(line[0])
            W = int(line[1])
        elif len(line) == 0:
            pass
        else:
            data.append(line[0])
            if len(data) == H:
                field = create_field(H, W)
                print search(H, W, data, field)


def search(H, W, data, field):
    count = 0
    for i in xrange(H):
        for j in xrange(W):
            if field[i][j] == 0:
                continue
            _search(i, j, H, W, data[i][j], data, field)
            count += 1
    return count


def _search(i, j, H, W, cell, data, field):
    field[i][j] = 0
    for a in xrange(i-1, i+2):
        if -1 < a < H:
            pass
        else:
            continue
        for b in xrange(j-1, j+2):
            if -1 < b < W:
                pass
            else:
                continue

            if a != i and b != j:
                continue

            if field[a][b] == 0:
                continue
            if cell == data[a][b]:
                _search(a, b, H, W, cell, data, field)
    return


def create_field(H, W):
    field = []
    for i in xrange(H):
        raw = []
        for j in xrange(W):
            raw.append(1)
        field.append(raw)
    return field


def get_data():
    return [line.strip() for line in raw_input()]

process()

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)


def main():
    solve()


def solve():
    for data in get_dataset():
        print search(data)


def search(data):
    count = 0
    H = len(data)
    W = len(data[0])
    for i in xrange(H):
        for j in xrange(W):
            if data[i][j] == '.':
                continue
            _search(i, j, H, W, data[i][j], data)
            count += 1
    return count


def _search(i, j, H, W, cell, data):
    data[i][j] = '.'
    for a in xrange(i-1, i+2):
        if not -1 < a < H:
            continue
        for b in xrange(j-1, j+2):
            if not -1 < b < W:
                continue

            if a != i and b != j:
                continue

            if data[a][b] == '.':
                continue

            if cell == data[a][b]:
                _search(a, b, H, W, cell, data)
    return


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(list(raw_input().rstrip()))
        dataset.append(data)
    return dataset


if __name__ == '__main__':
    main()
k=int(input())
s=str(input())

a=len(s)

if k>=a:
print(s)

else :
print(s[:k]+"...")

### FIXED CODE ###


k= int(input())
s= input()

a=len(s)

if k >= a:
  print(s)

else :
  print(s[:k]+"...")
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 30 09:04:16 2018

@author: Yamazaki Kenichi
"""
#L,N = map(int, input().split(' '))
#X = [int(input()) for i in range(N) ]

inp = input().split()
inp = [int(i) for i in inp]
L, N = inp[0],inp[1]
X = inp[2:]

X = [0] + X 
temp = L - X[1]
ans =  temp

itr1 = 0
itr2 = N

a = N%2

for i in range(-(N-1),N):
    if (i+a)%2 == 1:
        itr1 += 1
    else:
        itr2 -= 1

    if X[i]-X[i-itr1] >=0:
        minus = X[i]-X[i-itr1]
    else:
        minus = L+(X[i]-X[i-itr1])

    if X[i+itr2]-X[i] >=0:
        plus = X[i+itr2]-X[i]
    else:
        plus = L+(X[i+itr2]-X[i])
    temp = temp - minus + plus
    print(temp)
    ans = max(ans,temp)
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Dec 30 09:04:16 2018

@author: Yamazaki Kenichi
"""
L,N = map(int, input().split(' '))
X = [int(input()) for i in range(N) ]

#inp = input().split()
#inp = [int(i) for i in inp]
#L, N = inp[0],inp[1]
#X = inp[2:]

X = [0] + X 
temp = L - X[1]
ans =  temp

itr1 = 0
itr2 = N

a = N%2

for i in range(-(N-1),N):
    if (i+a)%2 == 1:
        itr1 += 1
    else:
        itr2 -= 1

    if X[i]-X[i-itr1] >=0:
        minus = X[i]-X[i-itr1]
    else:
        minus = L+(X[i]-X[i-itr1])

    if X[i+itr2]-X[i] >=0:
        plus = X[i+itr2]-X[i]
    else:
        plus = L+(X[i+itr2]-X[i])
    temp = temp - minus + plus
#    print(temp)
    ans = max(ans,temp)
print(ans)