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

def main():
    N = int(input())

    A = [int(input()) for _ in range(N)]

    for i in range(len(A)):
        tmp = A[i]
        A[i] = 0
        print(max(A))
        A[i] = tmp

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    max1st = max(A)
    max1stIndex = A.index(max1st)

    for i in range(len(A)):
        if i == max1stIndex:
            tmp = A[i]
            A[i] = 0
            print(max(A))
            continue

        print(max1st)




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

n = int(input())

a = list(map(int, input().split()))
ngcounter = 0
for i in range(n):
  num = a[i]
  a[i] = num - 1
  if num in a:
    ngcounter += 1
    break
  else:
    a[i] += 1
    
if ngcounter > 0:
  print("NO")
else:
  print("YES")

### FIXED CODE ###

n = int(input())

a = list(map(int, input().split()))
ngcounter = 0
a.sort()
for i in range(n-1):
  if a[i] == a[i+1]:
    ngcounter += 1
    break
  
if ngcounter > 0:
  print("NO")
else:
  print("YES")
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from itertools import accumulate

def main():
  n = int(input())
  A = list(map(int, input().split()))
  L = [0] + list(accumulate(A))
  dp = [[0]*(n+1) for i in range(n+1)]
  for d in range(1, n+1):
    for i in range(n+1-d):
      dp[i][i+d] = max(A[i] + L[i+d] - L[i+1] - dp[i+1][i+d], A[i+d-1] + L[i+d-1] - L[i] - dp[i][i+d-1])
  ans = 2*dp[0][n] - L[n]
  print(ans)
if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from itertools import accumulate

n = int(input())
A = list(map(int, input().split()))
L = [0] + list(accumulate(A))
dp = [[0]*(n+1) for i in range(n+1)]
for d in range(1, n+1):
  for i in range(n+1-d):
    dp[i][i+d] = max(A[i] + L[i+d] - L[i+1] - dp[i+1][i+d], A[i+d-1] + L[i+d-1] - L[i] - dp[i][i+d-1])
ans = 2*dp[0][n] - L[n]
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
A.sort()
A_sl = list(set(A))
A_sl.sort()
count_list = []
ans_list = []
if len(A_sl) == 1:
    print(len(A))
elif len(A_sl) == 2:
    if A_sl[1] - A_sl[0] <= 2:
        print(len(A))
    else:
        count_l = A.count(A_sl[1])
        count_s = A.count(A_sl[0])
        print(max(count_l,count_s))
else:
    for i in range(A_sl[0],A_sl[-1]+1):
        count = A.count(i)
        count_list.append(count)
    for i in range(len(A_sl)-2):
        count_total = count_list[i] + count_list[i+1] + count_list[i+2]
        ans_list.append(count_total)
    print(max(ans_list))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
l = [0]*(10**5)
for e in A:
    if e == 0:
        l[0] += 1
        l[1] += 1
    elif e == 99999:
        l[99999] += 1
        l[99998] += 1
    else:
        l[e-1] += 1
        l[e] += 1
        l[e+1] += 1
print(max(l))
### BUGGY CODE ###

n = int(input())
a = 1
for i in range(1, n + 1):
    a *= i
print(a % 1000000007)

### FIXED CODE ###

n = int(input())
a = 1
for i in range(1, n + 1):
    a = (a * i) % (10 ** 9 + 7)
print(a)
### 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 union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    a-=1; b-=1
    uf.union(a, b)

print(max([len(i) for i in uf.all_group_members().values()]))




### FIXED 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 union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    a-=1; b-=1
    uf.union(a, b)

print(max([uf.size(i) for i in uf.roots()]))
### BUGGY CODE ###

N, M, Q = map(int, input().split())
l = []
for i in range(Q):
  l.append(list(map(int, input().split())))

A_N = [[i] for i in range(1, M+1)]
for i in range(N-1):
  a = []
  for j in range(len(A_N)):
    last = A_N[j][-1]
    for k in range(last, M+1):
      a.append(A_N[j] + [k])
  A_N = a

high_score = 0
for i in range(len(A_N)):
    A = A_N[i]
    score = 0
    for j in range(len(l)):
        aj, bj, cj, dj = l[j]
        if A[bj-1]-A[aj-1] == cj:
            score += dj
        high_score = max(high_score, score) 
        
print(high_score)

### FIXED CODE ###

N, M, Q = map(int, input().split())
l = []
for i in range(Q):
  l.append(list(map(int, input().split())))

A_N = [[i] for i in range(1, M+1)]
for i in range(N-1):
  a = []
  for j in range(len(A_N)):
    last = A_N[j][-1]
    for k in range(last, M+1):
      a.append(A_N[j] + [k])
  A_N = a

high_score = 0
for i in range(len(A_N)):
  A = A_N[i]
  score = 0
  for j in range(len(l)):
    aj, bj, cj, dj = l[j]
    if A[bj-1]-A[aj-1] == cj:
      score += dj
  if high_score < score:
    high_score = score 

print(high_score)
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	G_fix_3
# CreatedDate:  2020-07-28 22:54:01 +0900
# LastModified: 2020-07-28 23:31:55 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import deque


class Graph():
    def __init__(self, vertex):
        self.V = vertex
        self.path = [[] for _ in range(self.V+1)]
        self.Q = deque()
        self.distance = [0] * (self.V+1)

    def addedge(self, s, t):
        self.path[s].append(t)

    def bfs(self, init):
        self.Q.append(init)
        while self.Q:
            u = self.Q.popleft()
            for v in self.path[u]:
                if self.distance[v] < self.distance[u]+1:
                    self.distance[v] = self.distance[u]+1
                    self.Q.append(v)
        return max(self.distance)

    def clear(self):
        self.distance = [0] * (self.V+1)


def main():
    N, M = map(int, input().split())
    graph = Graph(N)
    init_recommend = [0] * (N+1)
    for _ in range(M):
        s, t = map(int, input().split())
        graph.addedge(s, t)
        init_recommend[t] += 1
    ans = 0
    for init in range(1, N+1):
        if init_recommend[init] == 0:
            ans = max(ans, graph.bfs(init))
            graph.clear()
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import collections

# input処理を高速化する
input = sys.stdin.readline

def chmax(a, b):
    """ 最大値を返す関数 """
    if a >= b:
        return a
    return b

def main():
    # 入力
    N, M = map(int, input().split())
    # 隣接関係は隣接リストで管理する
    lst_edge = [[] for _ in range(N)]
    # 各頂点の入力辺の本数
    deg = [0] * N
    for _ in range(M):
        x, y = map(int, input().split())
        # 最初のindexをゼロにする
        lst_edge[x-1].append(y-1)
        deg[y-1] += 1

    # 入力辺を持たない頂点をqueueに入れる
    que = collections.deque()
    for v in range(N):
        if deg[v] == 0:
            que.append(v)

    # 各頂点の最初に入力辺を持たなかった点からの距離
    dp = [0] * N

    # For sequences, (strings, lists, tuples), use the fact that empty sequences are false.
    # https://www.python.org/dev/peps/pep-0008/#programming-recommendations
    while que:
        v = que.popleft()
        lst_nv = lst_edge[v]
        for nv in lst_nv:
            # エッジ(v, nv)をグラフから削除する
            deg[nv] -= 1
            if deg[nv] == 0:
                # エッジがなくなったことで、入力辺がなくなったらqueueに入れる
                que.append(nv)
                # 最初に入力辺を持たなかった点からの距離
                dp[nv] = chmax(dp[nv], dp[v] + 1)

    print(max(dp))

main()
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
X = [list(map(int, input().split()))for _ in range(Q)]
l =[]

def get(n):
    ans = 0
    for i in range(n):
        if S[i] =="A" and S[i+1] =="C":
            ans += 1
    return ans

for i in range(len(S)):
    l.append(get(i))
for i in range(Q):
    print(l[X[i][1]-1]-l[X[i][0]-1])

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
X = [list(map(int, input().split()))for _ in range(Q)]

a =[0]*N
for i in range(1,N):
    if S[i] =="C" and S[i-1] =="A":
        a[i] = a[i-1]+1
    else:
        a[i] = a[i-1]
# print(a)
for i in range(Q):
    print(a[X[i][1]-1]-a[X[i][0]-1])
### BUGGY CODE ###

n,k = map(int,input().split())
h = list(map(int, input().split()))

cnt = [float('inf')]*n
cnt[0], cnt[1] = 0, abs(h[0]-h[1])
for i in range(2, n):
    cnt[i] = min(abs(h[m]-h[i])+cnt[m] for m in range(max(0,i-k),i))
print(cnt[n-1])


### FIXED CODE ###

n,k = map(int,input().split())
h = list(map(int, input().split()))

cnt = [0]*n
for i in range(1, n):
    j = max(0,i-k)
    cnt[i] = min(abs(h[m]-h[i])+cnt[m] for m in range(j,i))
print(cnt[n-1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(input())
count = 0
for A in range(1,N):
  for B in range(1,N):
    if A*B >= N:
      break
    else:
      count += 1
print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
count = 0
for A in range(1,N):
  if N % A == 0:
    count += (N//A) - 1
  else:
    count += (N//A)
print(count)
### BUGGY CODE ###

n = int(input())
s = input()

ans = 0

r = []
if s[0] == "R":
    r.append(1)
else:
    r.append(0)

for i in range(1, len(s)):
    if s[i] == "R":
        r.append(r[-1] + 1)
    else:
        r.append(r[-1])

g = []
if s[0] == "G":
    g.append(1)
else:
    g.append(0)

for i in range(1, len(s)):
    if s[i] == "G":
        g.append(g[-1] + 1)
    else:
        g.append(g[-1])

b = []
if s[0] == "B":
    b.append(1)
else:
    b.append(0)

for i in range(1, len(s)):
    if s[i] == "B":
        b.append(b[-1] + 1)
    else:
        b.append(b[-1])

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if s[i] != s[j]:
            target_idx = j + (j - i)

            if "R" != s[i] and "R" != s[j]:
                ans += r[-1] - r[j]
                if target_idx >= len(s):
                    continue
                if s[target_idx] == "R":
                    ans -= 1
            elif "G" != s[i] and "G" != s[j]:
                ans += g[-1] - g[j]
                if target_idx >= len(s):
                    continue
                if s[target_idx] == "G":
                    ans -= 1
            else:
                ans += b[-1] - b[j]
                if target_idx >= len(s):
                    continue
                if s[target_idx] == "B":
                    ans -= 1

print(ans)


### FIXED CODE ###

n = int(input())
s = input()

ans = 0
sn = len(s)

r = []
if s[0] == "R":
    r.append(1)
else:
    r.append(0)
g = []
if s[0] == "G":
    g.append(1)
else:
    g.append(0)
b = []
if s[0] == "B":
    b.append(1)
else:
    b.append(0)

for i in range(1, sn):
    if s[i] == "R":
        r.append(r[-1] + 1)
        g.append(g[- 1])
        b.append(b[- 1])
    elif s[i] == "G":
        r.append(r[-1])
        g.append(g[-1] + 1)
        b.append(b[- 1])
    elif s[i] == "B":
        r.append(r[-1])
        g.append(g[-1])
        b.append(b[-1] + 1)
    else:
        r.append(r[-1])
        g.append(g[- 1])
        b.append(b[- 1])

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if s[i] != s[j]:
            tmp = dict()
            tmp[s[i]] = 0
            tmp[s[j]] = 0
            target_idx = j + (j - i)

            if tmp.get("B", 1) == 1:
                ans += b[-1] - b[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "B":
                    ans -= 1
            elif tmp.get("G", 1) == 1:
                ans += g[-1] - g[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "G":
                    ans -= 1
            else:
                ans += r[-1] - r[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "R":
                    ans -= 1

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

import sys
input=sys.stdin.readline
h,w = map(int, input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])

dp = [[0 for _ in range(6400)] for _ in range(h*w)]
dp[0][d[0][0]]=1

for i in range(h*w):
    nowh,noww = divmod(i,w)
    for k in range(6400):
        if not dp[nowh*w + noww][k]==1:
            continue
        nxth,nxtw=nowh+1, noww+1
        if nxtw<w:
            if k+d[nowh][nxtw] < 6400:
                dp[nowh*w + nxtw][k+d[nowh][nxtw]] = 1
            dp[nowh*w + nxtw][abs(k-d[nowh][nxtw])] = 1
        if nxth<h:
            if k+ d[nxth][noww]< 6400:
                dp[nxth*w + noww][k+d[nxth][noww]] = 1
            dp[nxth*w + noww][abs(k-d[nxth][noww])] = 1


for k in range(6400):
    if dp[-1][k]==1:
        print(k)
        exit()

### FIXED CODE ###

h,w = map(int, input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])

dp = [[0 for _ in range(6400)] for _ in range(h*w)]
dp[0][d[0][0]]=1

for i in range(h*w):
    nowh,noww = divmod(i,w)
    for k in range(6400):
        if not dp[nowh*w + noww][k]==1:
            continue
        nxth,nxtw=nowh+1, noww+1
        if nxtw<w:
            if k+d[nowh][nxtw] < 6400:
                dp[nowh*w + nxtw][k+d[nowh][nxtw]] = 1
            dp[nowh*w + nxtw][abs(k-d[nowh][nxtw])] = 1
        if nxth<h:
            if k+ d[nxth][noww]< 6400:
                dp[nxth*w + noww][k+d[nxth][noww]] = 1
            dp[nxth*w + noww][abs(k-d[nxth][noww])] = 1


for k in range(6400):
    if dp[-1][k]==1:
        print(k)
        exit()
### BUGGY CODE ###

def C_pushpush(x):
    n = x[0]
    a = x[1:]
    b = []
    n_parity = n & 1
    for i in range(n):
        if n_parity == (i + 1) & 1:
            # n,iのパリティが一致
            b.insert(0, a[i])
        else:
            b.append(a[i])
    for idx in range(len(b)):
        print(b[idx], end=' ')

n = int(input())
l = [int(i) for i in input().split()]
x = [n]+l
C_pushpush(x)

### FIXED CODE ###

def C_pushpush(x):
    from collections import deque
    # insertをリストの先頭に行うと、リストの要素の再配置に時間がかかる
    n = int(x[0])
    a = deque(x[1:])
    b = deque([])
    n_parity = n & 1
    for i in range(n):
        if n_parity == (i + 1) & 1:
            # n,iのパリティが一致
            b.appendleft(a[i])
        else:
            b.append(a[i])
    print(' '.join(b))

n = input()
l = [i for i in input().split()]
x = [n]+l
C_pushpush(x)
### BUGGY CODE ###

N=int(input())
a=[0]+list(map(int,input().split()))+[0]
cost=[]
for i in range(N+1):
    if i==0:
        cost.append(abs(a[i]))
    else:
        cost.append(abs(a[i]-a[i-1]))
cost.append(abs(a[N]))
for i in range(N):
    print(sum(cost)-cost[i+1]-cost[i+2]+abs(a[i+2]-a[i]))

### FIXED CODE ###

N=int(input())
a=[0]+list(map(int,input().split()))+[0]
cost=[]
for i in range(N+1):
    cost.append(abs(a[i+1]-a[i]))
S = sum(cost)
for i in range(N):
    print(S-cost[i]-cost[i+1]+abs(a[i+2]-a[i]))
### BUGGY CODE ###

n=int(input())
a=[]
ans=0
for i in range(n):
  aa=str(input())
  if aa in a:
    b=0
  else:
    a.append(aa)
    ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
a={}
ans=0
for i in range(n):
  aa=str(input())
  if aa in a:
    b=0
  else:
    a[aa]=i
    ans+=1
    #print(i)
print(ans)
#print(a)
### BUGGY CODE ###

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

import sys
sys.setrecursionlimit(10 ** 6)

def dfs(n):
    # print('Search Start: ' + str(n))
    if checked[n]:
        # print('Checked: ' + str(n))
        return
    checked[n] = True
    for e in edge:
        if n in e:
            x, y = e
            if n != x:
                dfs(x)
            else:
                dfs(y)
    # print('Search End: ' + str(n))

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

edge = [] * M
checked = [False for _ in range(N)]

con_com = 0

for _ in range(M):
    x, y, _ = list(map(int, input().split()))
    edge.append([x-1, y-1])

for i in range(N):
    if checked[i]:
        continue
    dfs(i)
    # print('--- Connected Components ---')
    con_com += 1

print(con_com)


### FIXED CODE ###

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

import sys
sys.setrecursionlimit(10 ** 6)

class UnionFind(object):
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
        self.components = n

    def find(self, x):
        if self.parent[x] == x:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            elif self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.parent[y] = x
            self.size[x] += self.size[y]
            self.components -= 1

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

    def getSize(self, x):
        return self.size(self.find(x))

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

edge = [] * M
uf = UnionFind(N)

for _ in range(M):
    x, y, _ = list(map(int, input().split()))
    uf.union(x-1, y-1)

print(uf.components)
### BUGGY CODE ###

import copy

n = int(input())
l = [int(input()) for i in range(n)]
for i in range(n):
    s = l[:i]+l[i+1:]
    print(sorted(s)[-1])

### FIXED CODE ###

import copy

n = int(input())
l = [int(input()) for i in range(n)]
Max1 = sorted(l)[-1]
Max2 = sorted(l)[-2]
for i in range(n):
    if l[i] == Max1:
        print(Max2)
    else:
        print(Max1)
### BUGGY CODE ###

import numpy
def main():
  n,m=map(int,input().split())
  a=list(map(int,input().split()))
  for i in range(m):
    a=sorted(a)
    a[-1]=a[-1]//2
  print(sum(a))
main()


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[-_ for _ in a]
import heapq
heapq.heapify(a)
for i in range(m):
  temp=-heapq.heappop(a)
  heapq.heappush(a,-(temp//2))
  
print(-sum(a))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from bisect import bisect_left
from sys import stdin
from heapq import heappush, heappop



readl = stdin.readline
def main():
  ## input
  N,Q = map(int, readl().rstrip().split())
  STX = [[None,None,None] for _ in range(N)]
  for i in range(N):
    STX[i] = list(map(int, readl().rstrip().split()))
  Dn = [None for _ in range(Q+1)]
  for i in range(Q):
    Dn[i] = int(readl().rstrip())
  Dn[Q] = 10**10
  ans = []

  for s,t,x in sorted(STX,key=lambda x:x[2]):
    l = r = bisect_left(Dn,s-x)
    t -= x
    while Dn[r] < t:
      heappush(ans, (Dn[r],x))
      r += 1
    del Dn[l:r]

  for d in Dn[:-1]:
    heappush(ans, (d,-1))

  return ans,Q


if __name__ == "__main__":
  ans,n = main()
  for _ in range(n):
    print(heappop(ans)[1])    


### FIXED CODE ###

import sys
from bisect import bisect_left



N,Q = map(int, input().split())
lines = sys.stdin.readlines()
kkk = []
for line in lines[:N]:
  s, t, x = map(int, line.split())
  kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[N:]))

ans = [-1] * Q
skip = [-1] * Q
for x, s, t in kkk:
  ss = bisect_left(ddd, s - x)
  tt = bisect_left(ddd, t - x)
  while ss < tt:
    sk = skip[ss]
    if sk == -1:
      ans[ss] = x
      skip[ss] = tt
      ss += 1
    else:
      ss = sk

print('\n'.join(map(str, ans)))
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i]=map(int,input().split())
answer=[0]*Q
for j in range(Q):
  counter=[0]*(r[j]-l[j]+1)
  for i in range(len(counter)):
    if i==len(counter)-1:
      answer[j]=sum(counter)
      break
    if S[l[j]-1+i]=="A":
      if S[l[j]+i]=="C":
        counter[i]=1
      else:
        counter[i]=0
    else:
      counter[i]=0
for i in range(len(answer)):
  print(answer[i])

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i]=map(int,input().split())
counter=[0]*N
for i in range(N-1):
  if S[i]=="A":
    counter[i]=counter[i-1]+(S[i+1]=="C")
  else:counter[i]=counter[i-1]
for j in range(Q):
  print(counter[r[j]-2]-counter[l[j]-2])
### BUGGY CODE ###

N,Q = map(int, input().split())
S = input()
lr = [list(map(int,input().split())) for i in range(Q)]

for i in range(Q):
    s_tmp = S[max(lr[i][0] - 1, 0):lr[i][1]]
    s_tmp_aft = S[lr[i][1]:]
    s_tmp_aft_2 = S[lr[i][1] - 1:]
    cnt =s_tmp.count('AC') - max(s_tmp_aft.count('AC'), s_tmp_aft_2.count('AC'))
    if cnt > 0:
        print(cnt)
    else:
        print(0)



### FIXED CODE ###

N,Q = map(int, input().split())
S = input()
lrs = [list(map(int, input().split())) for i in range(Q)]

total = []
total.append(0)
for i in range(1, N):
    if S[i - 1] == 'A' and S[i] == 'C':
        total.append(1)
    else:
        total.append(0)
totsum = 0
for idx, val in enumerate(total):
    totsum += val
    total[idx] = totsum

for lr in lrs:
    print(total[lr[1] - 1] - total[lr[0] - 1])
### BUGGY CODE ###

n = int(input())
i = 1

while True:
    x = i
    if  x % 3 == 0 or x % 10 ==3 or x/10 == 0:
        print(" %d" %i)
        i+=1
        if i > n:
            print()
            break


### FIXED CODE ###

#
# 5d
#

def main():
    n = int(input())
    s = ""
    for i in range(1, n+1):
        x = i
        if x % 3 == 0 or x % 10 == 3:
            s += " " + str(i)
        else:
            x //= 10
            while x:
                if x % 10 == 3:
                    s += " " + str(i)
                    break
                x //= 10
    print(s)


if __name__ == '__main__':
    main()