Harryxun/stf_run huggingface dataset:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

B = []
C = []

l = {}

for i in range(Q):
    b, c = list(map(int, input().split()))

    B.append(b)
    C.append(c)

res = 0
for i in A:
    if i in l:
        l[i] += 1
    else:
        l[i] = 1

    res += i

t = 0
for i in range(Q):
    t = l[B[i]]

    res += (C[i] - B[i]) * t

    l[B[i]] = 0
    l[C[i]] += t

    print(res)

### FIXED CODE ###

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

B = []
C = []

l = {}

for i in range(Q):
    b, c = list(map(int, input().split()))

    B.append(b)
    C.append(c)

res = 0
for i in A:
    if i in l:
        l[i] += 1
    else:
        l[i] = 1

    res += i

t = 0
for i in range(Q):
    if B[i] in l:
        t = l[B[i]]


        res += (C[i] - B[i]) * t

        l[B[i]] = 0
        if C[i] in l:
            l[C[i]] += t
        else:
            l[C[i]] = t

    print(res)
import numpy as np
N=int(input())
AN=map(int, input().split())
BN=[0 for i in range(N)]
for i in AN:
    BN[i-1] += 1
BN=[i for i in BN if i > 0]
BN.sort(reverse=True)

for K in range(1, N+1):
    x = np.zeros(K)
    for i in BN:
        x[x.argmin()] += i

    print (int(x.min()))


### FIXED CODE ###

N=int(raw_input())
AN=map(int, raw_input().split())

BN=[0 for i in xrange(N)]
for i in AN:
    BN[i-1] += 1
BN.sort()

LN = [0 for i in xrange(N)]
s = 0
j = 0
try:
    for X in xrange(1, N+1):
        while j<N and  BN[j] < X:
            s += BN[j]
            j += 1
        LN[X-1] = (s + X*(N - j)) / X
except IndexError:
    pass

KN = [0 for i in xrange(N)]
for i in xrange(len(LN)):
    KN[LN[i]-1] = i+1

for i in xrange(len(KN)-2, -1, -1):
    if KN[i] == 0:
        KN[i] = KN[i+1]

for i in KN:
    print (str(i))
a, b = map(int, raw_input().split())
if (a + b) % 2 == 0:
	print((a + b) // 2)
else:
	print("IMPOSSIBLE") 

### FIXED CODE ###

a, b = map(int, input().split())
if (a+b) % 2 == 0:
  print((a+b) // 2)
else:
  print("IMPOSSIBLE")
N = input()

if (N[0] == N[1] and N[1] == N[2]) or (N[1] == N[2] and N[1] == N[3]):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

print(48 - int(input()))
n, m, p = map(int, input().split())

edges = []
routes  = [[] for i in range(n)]
rev_routes = [[] for i in range(n)]
from_start = set()
to_goal = set()

def dfs(node, routes, seen):
    if node in seen:
        return
    seen.add(node)
    candidates = routes[node]
    for to in candidates:
        dfs(to, routes, seen)


for _ in range(m):
    node1, node2, value = map(int, input().split())
    node1, node2, value = node1-1, node2-1, value - p
    edges.append([node1, node2, value])
    routes[node1].append(node2)
    rev_routes[node2].append(node1)

dfs(0, routes, from_start)
dfs(n-1, rev_routes, to_goal)

from_start_to_goal = from_start & to_goal

graph = [-float('INF')] * n
graph[0] = 0

for i in range(n):
    is_updated = False
    for node, to, value in edges:
        if node not in from_start_to_goal or to not in from_start_to_goal:
            continue
        current_point = graph[node]
        next_point = graph[node] + value
        if graph[to] < next_point:
            graph[to] = next_point
            is_updated = True
        else:
            continue
    if not is_updated:
        score = max(0, graph[n-1])
        break
else:
    score = -1
      
print(score)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

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

edges = []
routes  = [[] for i in range(n)]
rev_routes = [[] for i in range(n)]
from_start = set()
to_goal = set()

def dfs(node, routes, seen):
    if node in seen:
        return
    seen.add(node)
    candidates = routes[node]
    for to in candidates:
        dfs(to, routes, seen)


for _ in range(m):
    node1, node2, value = map(int, input().split())
    node1, node2, value = node1-1, node2-1, value - p
    edges.append([node1, node2, value])
    routes[node1].append(node2)
    rev_routes[node2].append(node1)

dfs(0, routes, from_start)
dfs(n-1, rev_routes, to_goal)

from_start_to_goal = from_start & to_goal

graph = [-float('INF')] * n
graph[0] = 0

for i in range(n):
    is_updated = False
    for node, to, value in edges:
        if node not in from_start_to_goal or to not in from_start_to_goal:
            continue
        current_point = graph[node]
        next_point = graph[node] + value
        if graph[to] < next_point:
            graph[to] = next_point
            is_updated = True
        else:
            continue
    if not is_updated:
        score = max(0, graph[n-1])
        break
else:
    score = -1
      
print(score)
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,m=map(int,input().split())
	li=[]
	li2=[[] for _ in range(n+1)]
	for i in range(m):
		l,r,d=map(int,input().split())
		li.append((l,r,d))
		li.append((r,l,-d))
		li2[l].append((r,d))
		li2[r].append((l,-d))
	
	stack=[]
	check=set()
	a=[]*(n+1)

	for i in li:
		if i[0] in check:
			continue
		else:
			stack.append(i[0])
			a[i[0]]=0
			while stack:
				now=stack.pop()
				check.add(now)
				for j in li2[now]:
					if j[0] in check:
						if a[j[0]]-a[now]!=j[1]:
							print("No")
							exit(0)
						else:
							continue
					if j[0] in stack:
						continue
					a[j[0]] = a[now] + j[1]
					stack.append(j[0])
					
	print("Yes")
	
	
if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,m=map(int,input().split())
	li=[[] for _ in range(n+1)]
	for i in range(m):
		l,r,d=map(int,input().split())
		li[l].append((r,d))
		li[r].append((l,-d))
	
	q=deque()
	a=[None]*(n+1)

	for i in range(1,n+1):
		if a[i]==None:
			q=[i]
			a[i]=0
			while q:
				now=q.pop()
				for r,d in li[now]:
					if a[r]==None:
						a[r] = a[now] + d
						q.append(r)
					else:
						if a[r]-a[now]!=d:
							print("No")
							exit(0)
						else:
							continue
					
	print("Yes")
	
	
if __name__ == '__main__':
	main()
S = input()

if S[0] == 'A' and S[2:-1].count('C') == 1 and sum([c.isupper for c in S]) == 2:
    print('AC')
else:
    print('WA')


### FIXED CODE ###

from sys import stdin

S = stdin.readline().rstrip()

cond1 = S[0] == 'A'
cond2 = S.count('C', 2, -1) == 1
cond3 = S.replace('A', '').replace('C', '').islower()

if cond1 and cond2 and cond3:
    print('AC')
else:
    print('WA')
while 1:
     n=input().split()
     w=int(x[0])
     h=int(x[1])
     if h==w==0:
       break
     for i in range (h):
         if i==0 or i==h-1:
            print("#"*w)
         else:
             print("#", "."*(w-2), "#")
     print()


### FIXED CODE ###

while True:
    x=input().split()
    a=int(x[0])
    b=int(x[1])
    if a ==0 and b==0:
        break
    print("#"*b)
    for i in range(a-2):
        print("#"+"."*(b-2)+"#")
    print("#"*b)
    print("")
n, y = list(map(int, input().split()))
for a in range(n):
    for b in range(n):
        for c in range(n):
            q = a*10000 + b*5000 + c*1000
            if q == y:
                answer = [a, b, c]

print(answer)                

### FIXED CODE ###

n, y = list(map(int, input().split()))
ans = 0
 
for i in range(n+1):
    a1 = 10000 * i
    for j in range(n+1-i):
        a2 = 5000 * j
        k = n- (i+j)
        a3 = k*1000
        if a1 + a2 + a3  == y and i + j + k == n:
            print(i, j , k)
            ans += 1
            exit(0)
    if ans == 1:
        break
if ans == 0:
    print(-1, -1, -1)
l, r = map(int, input().split())

l = l%2019
r = r%2019

if l == 0 or r == 0 :
    print(0)
    exit()

if l > r:
    r += 2019

# print(l, r)

list_score = []
for i in range(l+1, r+1):
    for j in range(l, j):
        # print(i, j)
        list_score.append(i*j%2019)
# print(list_score)
print(int(min(list_score)))

### FIXED CODE ###

l, r = map(int, input().split())

if r-l>=2019 :
    print(0)
    exit()

l = l%2019
r = r%2019

if l == 0 or r == 0 :
    print(0)
    exit()

if l > r:
    r += 2019

# print(l, r)

list_score = []
for i in range(l+1, r+1):
    for j in range(l, i):
        # print(i, j)
        list_score.append(i*j%2019)
# print(list_score)
print(int(min(list_score)))
# -*- coding: utf-8 -*-
"""
E - Travel by Car
https://atcoder.jp/contests/abc143/tasks/abc143_e

"""
import sys


from scipy.sparse.csgraph import floyd_warshall

def main(args):
    N, M, L = map(int, input().split())
    g1 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        g1[i][i] = 0
    for _ in range(M):
        A, B, C = map(int, input().split())
        g1[A][B] = g1[B][A] = C
    d1 = floyd_warshall(g1)
    g2 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        for j in range(N+1):
            if i == j:
                g2[i][j] = 0
            elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
    d2 = floyd_warshall(g2)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1)


if __name__ == '__main__':
    main(sys.argv[1:])


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
E - Travel by Car
https://atcoder.jp/contests/abc143/tasks/abc143_e

"""
import sys


from scipy.sparse.csgraph import floyd_warshall

def main(args):
    N, M, L = map(int, input().split())
    g1 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        g1[i][i] = 0
    for _ in range(M):
        A, B, C = map(int, input().split())
        g1[A][B] = g1[B][A] = C
    d1 = floyd_warshall(g1)
    g2 = [[float('inf')] * (N+1) for _ in range(N+1)]
    for i in range(N+1):
        for j in range(N+1):
            if i == j:
                g2[i][j] = 0
            elif d1[i][j] <= L:
                g2[i][j] = g2[j][i] = 1
    d2 = floyd_warshall(g2)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1)


if __name__ == '__main__':
    main(sys.argv[1:])
N, M = map(int, input().split())
h = {}
c = {}
for i in range(N):
    h[i + 1] = []
    c[i + 1] = 0

for m in range(M):
    x, y, z = map(int, input().split())
    h[x].append(y)
    h[y].append(x)

ans = 0
rest = N

while len(h) > 0:
    p = max([[len(v), k] for k, v in h.items()])
    if p[0] == 0:
        break
    rest = rest - p[0] - 1
    for n in h[p[1]]:
        del h[n]
    del h[p[1]]
    ans += 1

print(ans + rest)


### FIXED CODE ###

from collections import defaultdict


class UnionFindTree:
    def __init__(self):
        self.p = {}
        self.rank = {}

    def make(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def find(self, x):
        if x in self.p:
            if self.p[x] != x:
                # 経路圧縮
                self.p[x] = self.find(self.p[x])
            return self.p[x]
        return None

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        return self._unite(self.find(x), self.find(y))

    def _unite(self, x, y):
        if self.rank[x] < self.rank[y]:
            self.p[x] = y
            return y
        else:
            self.p[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            return x


utf = UnionFindTree()

N, M = map(int, input().split())
for n in range(N):
    utf.make(n + 1)

for m in range(M):
    x, y, z = map(int, input().split())
    utf.unite(x, y)

h = defaultdict(int)
for n in range(N):
    x = utf.find(n + 1)
    h[x] += 1

ans = 0
rest = N
for k, v in h.items():
    ans += 1
    rest -= v
print(ans + rest)
text = input()
if (text == 'a')
    print('vowel')
elif (text == 'i')
    print('vowel')
elif (text == 'u')
    print('vowel')
elif (text == 'e')
    print('vowel')
elif (text == 'o')
    print('vowel')
else:
    print('consonant')

### FIXED CODE ###

s=input()
if s == "a" or s == "i" or s == "u" or s =="e" or s == "o":
    print("vowel")
else:
    print("consonant")
s = input()
ls = list(int(s))

ans = 0
lf = [1]*n
while '01' in s or '10' in s:
  for i in range(len(ls)):
    if sum(ls[i:i+2]) == 1:
      lf[i] = 0
      lf[i+1] = 0
      ans += 1
  ls,lf = *[s,f for s,f in zip(ls,lf) if lf[i]>0]
print(ans)

### FIXED CODE ###

s = input()
print(min(s.count('0'),s.count('1'))*2)
n = int(input())
if n ==0:
  print(0)
s=''
while n !=0:
  if n%2==1:
    s="1"+
    n-=1
  else:
    s='0'+s
  n-=n//2
print(s)


### FIXED CODE ###

n = int(input())
if n ==0:
  print(0)
s=''
while n !=0:
  if n%2==1:
    s="1"+s
    n-=1
  else:
    s='0'+s
  n=-n//2
print(s)
S=input()
if len(S)<26:
    raise TypeError:
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            print(S[:26-len(tmp)]+sorted(tmp)[1])
            exit()
    print(-1)

### FIXED CODE ###

S=input()
if len(S)<26:
    print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])
else:
    tmp = [S[25]]
    for i in range(25):
        tmp.append(S[24-i])
        if S[24-i] < S[25-i]:
            tmp =sorted(tmp)
            print(S[:26-len(tmp)]+tmp[tmp.index(S[24-i])+1])
            exit()
    print(-1)
s = input().strip()
x,y = map(int,input().split())
AX = []
AY = []
flag = 0
cnt = 0
for i in range(len(s)):
    if s[i]=="F":
        cnt += 1
    else:
        if flag==0:
            AX.append(cnt)
            cnt = 0
            flag = 1
        else:
            AY.append(cnt)
            cnt = 0
            flag = 0
if cnt>0 and flag==0:
    AX.append(cnt)
if cnt>0 and flag==1:
    AY.append(cnt)
Nx = sum(AX)
dpX = [[0 for _ in range(2*Nx+1)] for _ in range(len(AX)+1)]
if s[0]=="F":
    dpX[1][Nx+AX[0]] = 1
    for i in range(1,len(AX)):
        for j in range(2*Nx+1):
            if 0<=j+AX[i]<=2*Nx:
                dpX[i+1][j+AX[i]] = dpX[i+1][j+AX[i]] or dpX[i][j]
            if 0<=j-AX[i]<=2*Nx:
                dpX[i+1][j-AX[i]] = dpX[i+1][j-AX[i]] or dpX[i][j]
else:
    dpX[0][Nx] = 1
    for i in range(len(AX)):
        for j in range(2*Nx+1):
            if 0<=j+AX[i]<=2*Nx:
                dpX[i+1][j+AX[i]] = dpX[i+1][j+AX[i]] or dpX[i][j]
            if 0<=j-AX[i]<=2*Nx:
                dpX[i+1][j-AX[i]] = dpX[i+1][j-AX[i]] or dpX[i][j]
Ny = sum(AY)
dpY = [[0 for _ in range(2*Ny+1)] for _ in range(len(AY)+1)]
dpY[0][Ny] = 1
for i in range(len(AY)):
    for j in range(2*Ny+1):
        if 0<=j+AY[i]<=2*Ny:
            dpY[i+1][j+AY[i]] = dpY[i+1][j+AY[i]] or dpY[i][j]
        if 0<=j-AY[i]<=2*Ny:
            dpY[i+1][j-AY[i]] = dpY[i+1][j-AY[i]] or dpY[i][j]
if Nx==0 and x==0 and Ny==0 and y==0:
    print("Yes")
elif Nx==0 and x!=0 or Ny==0 and y!=0:
    print("No")
elif dpX[len(AX)][Nx+x]==1 and dpY[len(AY)][Ny+y]==1:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s = input().strip()
x,y = map(int,input().split())
C = {}
cur = 0
cnt = 0
for i in range(len(s)):
    if s[i]=="F":
        cnt += 1
    else:
        C[cur] = cnt
        cur += 1
        cnt = 0
C[cur] = cnt
AX = []
AY = []
for a in C:
    if a>0 and a%2==0 and C[a]>0:
        AX.append(C[a])
    elif a%2==1 and C[a]>0:
        AY.append(C[a])
cntx = sum(AX)
dpx = [[0 for _ in range(2*cntx+1)] for _ in range(len(AX)+1)]
dpx[0][cntx] = 1
if cntx>0:
    dpx[1][cntx-AX[0]] = 1
    dpx[1][cntx+AX[0]] = 1
    for i in range(2,len(AX)+1):
        for j in range(-cntx,cntx+1):
            if -cntx<=j-AX[i-1]:
                dpx[i][j+cntx] = dpx[i-1][j-AX[i-1]+cntx]
                if j+AX[i-1]<=cntx:
                    dpx[i][j+cntx] = max(dpx[i][j+cntx],dpx[i-1][j+AX[i-1]+cntx])
            elif j+AX[i-1]<=cntx:
                dpx[i][j+cntx] = dpx[i-1][j+AX[i-1]+cntx]
cnty = sum(AY)
dpy = [[0 for _ in range(2*cnty+1)] for _ in range(len(AY)+1)]
dpy[0][cnty] = 1
if cnty>0:
    dpy[1][cnty-AY[0]] = 1
    dpy[1][cnty+AY[0]] = 1
    for i in range(2,len(AY)+1):
        for j in range(-cnty,cnty+1):
            if -cnty<=j-AY[i-1]:
                dpy[i][j+cnty] = dpy[i-1][j-AY[i-1]+cnty]
                if j+AY[i-1]<=cnty:
                    dpy[i][j+cnty] = max(dpy[i][j+cnty],dpy[i-1][j+AY[i-1]+cnty])
            elif j+AY[i-1]<=cnty:
                dpy[i][j+cnty] = dpy[i-1][j+AY[i-1]+cnty]
if C[0]-cntx<=x<=C[0]+cntx and dpx[len(AX)][x-C[0]+cntx]==1 and -cnty<=y<=cnty and dpy[len(AY)][y+cnty]==1:
    print("Yes")
else:
    print("No")
import math
 
N = int(input())
A = list(map(int,input().split()))
L = [0] * N
R = [0] * N

for i in range(1, N):
    L[i] = math.gcd(L[i-1], A[i-1])
    R[-i-1] = math.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = math. gcd(L[i], R[i])

print(max(ans))

### FIXED CODE ###

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

for i in range(1, N):
    L[i] = fractions.gcd(L[i-1], A[i-1])
    R[-i-1] = fractions.gcd(R[-i], A[-i])

ans = [0] * N

for i in range(0, N):
    ans[i] = fractions.gcd(L[i], R[i])

print(max(ans))
n, a, b = map(int, input().split())
    
l = ""
flag = True
count = 0
while True:
    if flag == True:
        for x in range(a):
            l += "b"
            if len(l) == n:
                break
        flag = False
    else:
        for y in range(b):
            l += "r"
            if len(l) == n:
                break
        flag = True

    if len(l) >= n:
        break
         
for c in l:
    if c == "b":
        count += 1

print(count)


### FIXED CODE ###

while True:
    sta = input()
    if len(sta) == 3:
        break

judge = ""
count = 0
result = ""
station = [sta[0], sta[1], sta[2]]
for ss in station:
    if count == 0:
        judge = ss
    else:
        if ss == judge:
            result = "No"
        else:
            result = "Yes"
            break
            
    count = 1
print(result)
x,n=map(int,input().split())
p=list(map(int, input().split()))
youso=[]
for i in range(1,101):
    if not i in p:
        youso+=[i]
hikaku=[]
for i in youso:
    hikaku+=[(i,abs(x-i))]
hikaku1=sorted(hikaku,key=lambda x:x[1])
if n == 0:res = x
else :res=hikaku1[0][0]
print(res)

### FIXED CODE ###

x,n=map(int,input().split())
p=list(map(int, input().split()))
youso=[]
for i in range(-300,1000):
    if not i in p:
        youso+=[i]
hikaku=[]
for i in youso:
    hikaku+=[(i,abs(x-i))]
hikaku1=sorted(hikaku,key=lambda x:x[1])
res=hikaku1[0][0]
print(res)
s = input()

a = s[0]
b =len(s)-2
c = s[-1]

print(a+b+c)


### FIXED CODE ###

n,m =  map(int,input().split())

print((n-1)*(m-1))
def Fib(n):    
    if n == 1:
        return 0
    elif n == 2:
        return 1
    else:
        return Fib(n-1)+Fib(n-2)

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

list=[]
for i in range(M):
    list.append(int(input()))

for i in range(1,len(list)):
    if list[i]-list[i-1] == 1:
        print(0)
        exit()

num_list = []
rest = N
cnt = 0
for i in range(N+1):
    if i in list:
        num_list.append(cnt)
        cnt = 0
    elif i == N:
        num_list.append(cnt + 1)
    else:
        cnt += 1

ans = 1
for i in num_list:
    ans = ans * Fib(i+1)
print(ans % 1000000007)



### FIXED CODE ###

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

a = [int(input()) for i in range(M)]

#初期化
dp=[-1]*N
dp[0]=1

for i in a:
    dp[i-1] = 0

for i in range(1,N):
    if dp[i]==0:
        continue
    elif i==1:
        dp[i]=dp[i-1] + 1
    else:
        dp[i]=dp[i-1]+dp[i-2]

print(dp[N-1]%1000000007)
K = int(input())
S = input()

if len(S) < K:
    print(S)
else:
    for i in range(K):
        print(S[i],end="")
    print("...")

### FIXED CODE ###

N = int(input())
a = 0

if N>=100:
    a = N % 100
    if N >= 10:
        a = a % 10
elif N >= 10:
    a = N % 10
else:
    a = N

if a == 0:
    print("pon")
elif a == 1:
    print("pon")
elif a == 6:
    print("pon")
elif a == 8:
    print("pon")
elif a == 3:
    print("bon")
else:
    print ("hon")
import math
def main():
    x1, y1, x2, y2 = map(int, input().split())
    b = abs(x2 - x1)
    h = abs(y2 - y1)
    d = math.sqrt(b ** 2 + h ** 2)
    print("{0:.8f}".format(d))


if __name__ == "__main__":
    main()

### FIXED CODE ###

import math
def main():
    x1, y1, x2, y2 = map(float, input().split())
    b = abs(x2 - x1)
    h = abs(y2 - y1)
    d = math.sqrt(b ** 2 + h ** 2)
    print("{0:.8f}".format(d))


if __name__ == "__main__":
    main()
import math
n_num,m_num=map(int,input().split())
n_comb=math.factorial(n_num)//(math.factorial(n_num-2)*math.factorial(2))
m_comb=math.factorial(m_num)//(math.factorial(m_num-2)*math.factorial(2))
print(int(n_comb+m_comb))


### FIXED CODE ###

def c(i):
    return i*(i-1)//2

n,m=map(int,input().split())
print(c(n)+c(m))
a,b,c = map(int,input().splite())
print(c,a,b)


### FIXED CODE ###

a, b, c = map(int, input().split())
print(c, a, b)
N, M = map(int, input().split())
A = list(map(int, input().split()))
flag = True
 
for i in  A:
N = N - i
if N < 0:
flag = False
break
 
if flag == True:
  print(N)
else:
  print(-1)

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
flag = True
 
for i in  A:
  N = N - i
  if N < 0:
    flag = False
    break
 
if flag == True:
  print(N)
else:
  print(-1)
while True :
    h, w = [int(x) for x in input().split()]
    if h == w == 0 : break
    for i in range(h) : print(('#.'*w)[i%2:][:w])
    print()


### FIXED CODE ###

n = int(input())
for i in range(1, n+1) :
    x = i
    if (x%3 == 0) :
        print(' %d' % i, end = '')
    else :
        while (x) :
            if (x%10 == 3) :
                print(' %d' % i, end = '')
                break
            x //= 10
print('')