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


import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
##############################

S = input().rstrip()
K = int(input())

N = len(S)

ret = []
for nums in range(1, N+1):
    for i in range(N):
        s = S[i:i+nums]
        ret.append(s)

ret = sorted(set(ret))

print(ret[K-1])

### FIXED CODE ###


import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
##############################

S = input().rstrip()
K = int(input())

N = len(S)

ret = []
for nums in range(1, K+1):
    for i in range(N):
        s = S[i:i+nums]
        ret.append(s)

ret = sorted(set(ret))
print(ret[K-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]
  def unite(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 -size.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_group_members(self):
    return {r:self.members(r) for r in self.roots()}
n,k,l=map(int,input().split())
uf1=UnionFind(n)
for _ in range(k):
  u,v=map(int,input().split())
  uf1.unite(u-1,v-1)
uf2=UnionFind(n)
for _ in range(l):
  u,v=map(int,input().split())
  uf2.unite(u-1,v-1)
r=[[] for i in range(n)]
for i in range(n):
  if len(r[i])==0:
    x=uf1.members(i)
    for j in x:
      r[j]=set(x)
t=[[] for i in range(n)]
for i in range(n):
  if len(t[i])==0:
    x=uf2.members(i)
    for j in x:
      t[j]=set(x)
ans=[]
for i in range(n):
  ans.append(len(r[i]&t[i]))
print(*ans)

### FIXED CODE ###

from collections import defaultdict
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]
  def unite(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 -size.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_group_members(self):
    return {r:self.members(r) for r in self.roots()}
n,k,l=map(int,input().split())
uf1=UnionFind(n)
for _ in range(k):
  u,v=map(int,input().split())
  uf1.unite(u-1,v-1)
uf2=UnionFind(n)
for _ in range(l):
  u,v=map(int,input().split())
  uf2.unite(u-1,v-1)
d=defaultdict(int)
for i in range(n):
  d[(uf1.find(i),uf2.find(i))]+=1
ans=[d[(uf1.find(i),uf2.find(i))] for i in range(n)]
print(*ans)
### BUGGY CODE ###

n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
idx=1
li=[]
idx_li=[1]
for i in range(k):
    idx=a[idx-1]
    if idx in idx_li:
        break
    idx_li.append(idx)
non_loop=idx_li[:idx_li.index(idx)]
loop = idx_li[idx_li.index(idx):]
size=len(loop)
print(loop[(k-len(non_loop))%size])

### FIXED CODE ###

n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
idx=1
idx_li=[]
ord_=[-1]*n
flag=False
for i in range(k):
    idx_li.append(idx)
    ord_[idx-1]=1
    idx=a[idx-1]
    if ord_[idx-1]==1:
        flag=True
        break
if flag:
    #non_loop=idx_li[:idx_li.index(idx)]
    loop = idx_li[idx_li.index(idx):]
    
    size=len(loop)
    print(loop[(k-(len(idx_li)-len(loop)))%size])
else:
    print(idx)
### BUGGY CODE ###

n=int(input())
l=[int(input()) for _ in range(n)]
a=0
for i in set(l):
  if l.count(i)%2:a+=1
print(a)

### FIXED CODE ###

from collections import Counter as co
n=int(input())
l=[int(input()) for _ in range(n)]
print(len([1 for (a,d) in co(l).items() if d%2]))
### BUGGY CODE ###

def main():
    N = int(input())
    ans = 1
    for a in [int(x) for x in input().split()]:
        ans *= a
    if ans > 10**18:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    if 0 in A:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            return
    print(ans)

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

n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = []

for _ in range(q):
    b, c = map(int, input().split())
    if b not in a:
        l.append(sum(a))
        continue
    a = [c if e == b else e for e in a]
    l.append(sum(a))

for a in l:
    print(a)

### FIXED CODE ###

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

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)
### BUGGY CODE ###

while 1:
	su = 0
	stack = []
	try:
		raw = raw_input().split()
	except:
		pass
	else:
		for s in raw:
			if s == "-":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) / stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) * stack.pop())
			elif s == "%":
				stack.append(stack.pop(-2) % stack.pop())
			else:
				stack.append(int(s))
	
		print "%.6f" % (stack[0])

### FIXED CODE ###

while 1:
	try:
		stack = []
		for s in raw_input().split():
			if s == "-":
				stack.append(stack.pop(-2) - stack.pop())
			elif s == "+":
				stack.append(stack.pop(-2) + stack.pop())
			elif s == "/":
				stack.append(stack.pop(-2) / stack.pop())
			elif s == "*":
				stack.append(stack.pop(-2) * stack.pop())
			else:
				stack.append(float(s))
	
		print "%.6f" % (stack[0])
	except:
		break
### BUGGY CODE ###

from collections import deque

[H, W] = [int(i) for i in input().split()]
S = [0]*(H+2)
S[0] = ['#']*(W+2)
S[H+1] = ['#']*(W+2)

for i in range(1, H+1):
    row = ['#'] + list(input()) + ['#']
    S[i] = row

dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]
    
def bfs(p, q, c):
    distance = {(p, q):0}
    que = deque([(p, q)])
    reached = [[0]*(W+2) for k in range(H+2)]
    
    while len(que) > 0: 
        (y, x) = que.popleft()
        
        if c[y][x] == '#':
            continue
        
        reached[y][x] = 1
        
        for k in range(4):
            yy, xx = y + dy[k], x + dx[k]
            if reached[yy][xx] == 1 or c[yy][xx] == '#':
                continue
            else:
                distance[(yy, xx)] = distance[(y, x)] + 1
                que.append((yy, xx))
        
    distances = list(distance.values())
    return max(distances)

anss = [0]*(H*W)
times = 0

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == '.':
            anss[times] = bfs(i, j, S)
        times += 1

print(max(anss))

### FIXED CODE ###

from collections import deque

[H, W] = [int(i) for i in input().split()]
S = [list(input()) for _ in range(H)]
dy, dx = [1, 0, -1, 0], [0, 1, 0, -1]

def bfs(sy, sx):
    if S[sy][sx] == '#':
        return 0
        
    reached = [[-1]*W for _ in range(H)]
    que = deque([[sy, sx]])
    reached[sy][sx] = 0
    
    while que:
        [y, x] = que.pop()
        for i in range(4):
            yy, xx = y + dy[i], x + dx[i]
            if yy < 0 or xx < 0 or yy > H-1 or xx > W-1 or S[yy][xx] == '#' or reached[yy][xx] != -1:
                continue
            else:
                reached[yy][xx] = reached[y][x] + 1
                que.appendleft([yy, xx])
                
    distance = 0
    for i in range(H):
        for j in range(W):
            distance = max(distance, reached[i][j])
            
    return distance

ans = 0
for a in range(H):
    for b in range(W):
        ans = max(ans, bfs(a, b))

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

n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        if a[j] + a[i] == j - i:
            cnt += 1
print(cnt)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]*n
c=[0]*n
d=0
sums=0
for j in range(n):
    if j-a[j]<1:
        das=0
    else:
        b[j-a[j]]=b[j-a[j]]+1
    if j+a[j]>n-2:
        das=0
    else:
        c[j+a[j]]=c[j+a[j]]+1
for k in range(n):
    d=b[k]*c[k]
    sums=sums+d
print(sums)
### BUGGY CODE ###

N, K = map(int, input().split())
hlist = list(map(int, input().split()))
inf = float("inf")
dp = [inf] * N


def abs_sbn(a, b):
    return abs(hlist[b] - hlist[a])


dp[0] = 0
dp[1] = abs_sbn(0, 1)
for i in range(2, N):
    for j in range(1, K + 1):
        if (i - j) >= 0:
            dp[i] = min(dp[i], dp[i - j] + abs_sbn(i, i - j))

print(dp[-1])


### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
inf = 10**9
dp = [inf] * N
dp[0] = 0


def chmin(num: int, sbn: int):
    dp[num + sbn] = min((dp[num + sbn], dp[num] + abs(h[i + sbn] - h[num])))


for i in range(N):
    for sbn in range(K):
        try:
            chmin(i, sbn + 1)
        except IndexError:
            break
print(dp[-1])
### BUGGY CODE ###

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()

def exp(num):
  ret = (1+num)/2
  return ret

mx=0

pp = list(map(exp,p))

for i in range(n-k+1):
  mx = max(sum(pp[i:i+k]),mx)
print(mx)

### FIXED CODE ###

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()

def exp(num):
  ret = (1+num)/2
  return ret

mx=0

pp = list(map(exp,p))
pd = [0]*(n+1)



for i in range(1,n+1):
  pd[i] = pd[i-1] + pp[i-1]




for i in range(n-k+1):
  mx = max(pd[i+k]-pd[i],mx)

print(mx)
### BUGGY CODE ###

n = int(input())
c_str = input()
c_list = list(c_str)

cnt = 0
flag = 1
w_pos = 0
r_pos = 0

while flag:
    for i in range(0,n):
        if c_list[i] == "W":
            w_pos = i
            break
        if i == n-1:
            w_pos = n-1
    for j in reversed(range(0,n)):
      if c_list[j] == "R":
        r_pos = j
        break
    if w_pos < r_pos:
        c_list[w_pos] = "R"
        c_list[r_pos] = "W"
        cnt += 1
    else:
      flag = 0

print(cnt)

### FIXED CODE ###

n = int(input())
c_str = input()
c_list = list(c_str)

cnt = 0
flag = 1
w_pos = 0
r_pos = 0
range_start = 0
range_end = n

while flag:
    for i in range(range_start, range_end):
        if c_list[i] == "W":
            w_pos = i
            range_start = i
            break
        if i == range_end-1:
            w_pos = range_end-1 
    for j in reversed(range(range_start, range_end)):
      if c_list[j] == "R":
        r_pos = j
        range_end = j
        break
      if j == range_start:
        r_pos = range_start 
    if w_pos < r_pos:
        c_list[w_pos] = "R"
        c_list[r_pos] = "W"
        cnt += 1
    else:
      flag = 0

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

x,y,a,b,c = map(int,input().split())

p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

red = []
green = []

# for i in range(x):
#     red.append(p[i])
# for j in range(y):
#     green.append(q[j])

# print(p[:x])
# print(q[:y]
# print(red)
# print(green)

all = p[:x] + q[:y]
all.sort()

# for i in range(len(all)):
#     if min(r) > all[i]:
#         print(i)
#         break
# if i >= len(r):
#     ans = all[len(r) + 1:] + r
# else:
#     ans = all[i + 1:] + r[:i]

for mushoku in r:
    for i in range(len(all)):
        if mushoku > all[i]:
            all[i] = mushoku


print(sum(all))

### FIXED CODE ###

x,y,a,b,c = map(int,input().split())

p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort()


all = p[:x] + q[:y] + r
all.sort(reverse=True)

print(sum(all[:x+y]))
### BUGGY CODE ###

import sys
MAX_INT = int(10e9)
MIN_NUM = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = [IL()[::-1] for i in range(N)]

cnt = N*(N-1)//2
flag = 1
days = 0
while flag:
  flag = 0
  used = [False]*N
  for i in range(N):
    #print(a)
    #print(i+1)
    if len(a[i]) > 0 and used[i] == False:
      numIND = a[i][-1] -1
      #print(numIND+1)
      if a[numIND][-1] == i+1 and used[numIND] == False:
        a[i].pop(-1)
        a[numIND].pop(-1)
        used[i] = True
        used[numIND] = True
        flag = 1
        cnt -= 1
  else:
    if flag == 1:
      days += 1
#print(a)
#print(cnt)
if cnt != 0:
  print(-1)
else:
  print(days)

### FIXED CODE ###

import sys
MAX_INT = int(10e9)
MIN_NUM = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = [IL()[::-1] for i in range(N)]

used = [-1]*N
updatelist = [i for i in range(N)]
total = N*(N-1)//2
cnt = 0
days = 0
ul = []
while updatelist:
  ul = []
  for i in updatelist:
    #print(a)
    #print(i+1)
    if len(a[i]) > 0 and used[i] != days:
      numIND = a[i][-1] -1
      #print(numIND+1)
      if a[numIND][-1] == i+1 and used[numIND] != days:
        a[i].pop(-1)
        a[numIND].pop(-1)
        used[i] = days
        used[numIND] = days
        ul.append(i)
        ul.append(numIND)
        cnt += 1
  else:
    updatelist = ul[:]
    if len(ul) != 0:
      days += 1
#print(a)
#print(cnt)
if cnt == total:
  print(days)
else:
  print(-1)
### BUGGY CODE ###

def main():  
  #Union Find

  #xの根を求める
  def find(x):
      if par[x] < 0:
          return x
      else:
          par[x] = find(par[x])
          return par[x]
  #xとyの属する集合の併合
  def unite(x,y):
      x = find(x)
      y = find(y)

      if x == y:
          return False
      else:
          #sizeの大きいほうがx
          if par[x] > par[y]:
              x,y = y,x
          par[x] += par[y]
          par[y] = x
          return True

  #xとyが同じ集合に属するかの判定
  def same(x,y):
      return find2(x) == find2(y)

  def find2(x):
    if pa[x] < 0:
        return x
    else:
        pa[x] = find2(pa[x])
        return pa[x]

  #根なら-size,子なら親の頂点

  import sys
  input = sys.stdin.readline

  n,k,l = [int(i) for i in input().split()]
  par = [-1]*n
  pa = [-1]*n
  ans = [0]*n

  for i in range(k):
    p,q = [int(i) for i in input().split()]
    unite(p-1,q-1)

  def unite2(x,y):
      x = find2(x)
      y = find2(y)
      if x == y:
          return False
      else:
          if pa[x] > pa[y]:
              x,y = y,x
          pa[x] += pa[y]
          pa[y] = x
          return True

  for i in range(l):
    r,s = [int(i) for i in input().split()]
    unite2(r-1,s-1)

  #print(par,pa)
  chk = []
  for i in range(n):
    chk_append = chk.append
    chk_append(find(i)*10**6+find2(i))

  import collections
  for i in range(n):
    c = collections.Counter(chk)
    ans[i] += c[chk[i]]

  ans = list(map(str,ans))
  print(' '.join(ans))
  
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():  
  #Union Find

  #xの根を求める
  def find(x):
      if par[x] < 0:
          return x
      else:
          par[x] = find(par[x])
          return par[x]
  #xとyの属する集合の併合
  def unite(x,y):
      x = find(x)
      y = find(y)

      if x == y:
          return False
      else:
          #sizeの大きいほうがx
          if par[x] > par[y]:
              x,y = y,x
          par[x] += par[y]
          par[y] = x
          return True

  def find2(x):
    if pa[x] < 0:
        return x
    else:
        pa[x] = find2(pa[x])
        return pa[x]

  import sys
  input = sys.stdin.readline

  n,k,l = [int(i) for i in input().split()]
  par = [-1]*n
  pa = [-1]*n
  ans = [0]*n

  for i in range(k):
    p,q = [int(i) for i in input().split()]
    unite(p-1,q-1)

  def unite2(x,y):
      x = find2(x)
      y = find2(y)
      if x == y:
          return False
      else:
          if pa[x] > pa[y]:
              x,y = y,x
          pa[x] += pa[y]
          pa[y] = x
          return True

  for i in range(l):
    r,s = [int(i) for i in input().split()]
    unite2(r-1,s-1)

  dic = {}
  chk = []
  for i in range(n):
      p1 = find(i)
      p2 = find2(i)
      chk.append((p1,p2))
      if (p1,p2) in dic:
          dic[(p1,p2)] += 1
      else: 
          dic[(p1,p2)] = 1
  print(' '.join([str(dic[chk[i]]) for i in range(n)]))
  
if __name__ == '__main__':
    main()
### BUGGY CODE ###

h,w=map(int,input().split())
s=set()
from collections import deque
q=deque([])
for i in range(h):
    tmp=input()
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j))
            s.add((i,j))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    l=[]
    while q:
        i,j=q.popleft()
        for x,y in ll:
            if i+x>=0 and i+x<h and j+y>=0 and j+y<w:
                if (i+x,j+y) not in s:
                    s.add((i+x,j+y))
                    l.append((i+x,j+y))
    q=deque(l)
    ans+=1

print(ans-1)





### FIXED CODE ###

h,w=map(int,input().split())
s=set()
a=[]
from collections import deque
q=deque([])
for i in range(h):
    tmp=list(input())
    a.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j,0))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    x,y,v=q.popleft()
    ans=max(ans,v)
    for i,j in ll:
        if 0<=x+i<h and 0<=y+j<w and a[i+x][j+y]==".":
            a[i+x][j+y]="#"
            q.append((i+x,j+y,v+1))

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

import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
import numpy as np
n,k,q =  map(int, sys.stdin.readline().split())
l=[0]*n
l = np.array(l)
# def penalty(b):
#     return b + 1

for i in range(q):
    a =  int(sys.stdin.readline())
    l+=1
    # l=list(map(penalty, l))
    l[a-1]-=1



for e in l:
    if e >=k:
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
import numpy as np
n,k,q =  map(int, sys.stdin.readline().split())
l=[0]*n
l = np.array(l)
l+=q

# a=[l[i-1]-1 for i in  list(map(int,sys.stdin.readlines()))]
# print(a)
for i in range(q):
    a =  int(sys.stdin.readline())
    l[a-1]-=1

for e in l:
    if e >=k:
        print("No")
    else:
        print("Yes")
### BUGGY CODE ###

# -*- coding: utf-8 -*-

N, M = map(int, raw_input().split())
start, finish = [], []
for i in range(M):
    a, b = map(int, raw_input().split())
    if a == 1:
        start.append([a, b])
    elif b == N:
        finish.append([a, b])

for s in start:
    for f in finish:
        if s[1] == f[0]:
            print 'POSSIBLE'
            exit()

print 'IMPOSSIBLE'


### FIXED CODE ###

# -*- coding: utf-8 -*-

N, M = map(int, raw_input().split())
start, finish = [], []
for i in range(M):
    a, b = map(int, raw_input().split())
    if a == 1:
        start.append(b)
    elif b == N:
        finish.append(a)

if set(start) & set(finish):
    print 'POSSIBLE'
else:
    print 'IMPOSSIBLE'
### BUGGY CODE ###

import math
K = int(input())
cnt = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            cnt += math.gcd(i, math.gcd(j,k))
print(cnt)

### FIXED CODE ###

from math import gcd

K = int(input())
cnt = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            cnt += gcd(gcd(i,j),k)
print(cnt)
### BUGGY CODE ###

import collections

n = int(input())
S = []
ans =0

for i in range(n):
  s = input()
  s = sorted(s)
  S.append(s)

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

### FIXED CODE ###

import collections

n = int(input())

s = [",".join(sorted(input())) for i in range(n)]

c = collections.Counter(s)

ans = 0
for i in c.values():
  ans += i*(i-1)//2

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

s =input()
k = int(input())
#入力

length = len(s)
s_set  =[]
for i in range(length):
    for j in range(i+1):
        s_set.append(s[j:i+1])
s_set = set(s_set)
s_set = list(s_set)
s_set.sort()
#print(s_set)

print(s_set[k-1])

### FIXED CODE ###

s = input()
K = int(input())

sub = set()
for k in range(1, 6):
    for i in range(len(s)):
        sub.add(s[i:i+k])

sub = sorted(list(sub))
print(sub[K-1])
### BUGGY CODE ###

import sys
input=sys.stdin.readline
import bisect
q=int(input())
h=[]
l=0 #hの要素数
b=0 #bの和
s=0 #絶対偏差の和
med=0
for _ in range(q):
    Tmp=list(map(int,input().split()))
    if Tmp[0]==1:
        b+=Tmp[2]
        if l%2:
            s+=abs(Tmp[1]-med)
        else:
            if l:
                med_next=h[(l-1)//2+1]
                if Tmp[1]<=med:
                    s+=abs(Tmp[1]-med)
                elif Tmp[1]>=med_next:
                    s+=abs(Tmp[1]-med_next)                
        l+=1
        bisect.insort(h,Tmp[1])
        med=h[(l-1)//2]
    else:
        print(med,s+b)

### FIXED CODE ###

import sys
input=sys.stdin.readline
from heapq import heappush,heappop
q=int(input())
_,a,b=map(int,input().split())
Small=[-a]; Large=[]
cnt=1
med=a
c=b
s=0
for i in range(q-1):
    query=tuple(map(int,input().split()))
    if query[0]==1:
        _,a,b=query
        c+=b
        if cnt%2:
            s+=abs(a-med)
            if a<-Small[0]:
                heappush(Small,-a)
                heappush(Large,-heappop(Small))
            else:
                heappush(Large,a)
        else:
            if a<=-Small[0]:
                heappush(Small,-a)
                med=-Small[0]
                s+=med-a
            elif a<=Large[0]:
                heappush(Small,-a)
            else:
                heappush(Large,a)
                med=heappop(Large)
                s+=a-med
                heappush(Small,-med)
        cnt+=1
        med=-Small[0]
    else:
        print(med,s+c)