Harryxun/stf_run huggingface dataset:
n=int(input())
lst=[]
for i in range(n):
  c,s,f=map(int,input().split())
  lst.append([c,s,f])
for j in range(n-1):
  time=lst[j][0]+lst[j][1]
  ind=j
  for k in range(n-j-1):
    if time<=lst[ind+1][1] :
      time=lst[ind+1][0]+lst[ind+1][1]
      ind+=1
    elif (time-lst[ind+1][1])%lst[ind+1][2]==0:
      time+=lst[ind+1][2]
      ind+=1
    else:
      time+=lst[ind+1][2]+lst[ind+1][2]-(time-lst[ind+1][1])%lst[ind+1][2]
      ind+=1
  print(time)
print(0)


### FIXED CODE ###

n=int(input())
lst=[]
for i in range(n-1):
  c,s,f=map(int,input().split())
  lst.append([c,s,f])
for j in range(n-1):
  time=lst[j][0]+lst[j][1]
  ind=j
  for k in range(n-j-2):
    if time<=lst[ind+1][1] :
      time=lst[ind+1][0]+lst[ind+1][1]
      ind+=1
    elif (time-lst[ind+1][1])%lst[ind+1][2]==0:
      time+=lst[ind+1][0]
      ind+=1
    else:
      time+=lst[ind+1][0]+lst[ind+1][2]-(time-lst[ind+1][1])%lst[ind+1][2]
      ind+=1
  print(time)
print(0)
a,b=map(int, input().split())
if a>b:
  string(a)*b
  print(string(a)*b)
else:
  print(string(b)*a)

### FIXED CODE ###

a,b=map(int, input().split())
if a<b:
    str(a)*b
    print(str(a)*b)
else:
    print(str(b)*a)
A=int(input())
B=int(input())
if (A+B)>(A-B) and (A+B)>(A*B):
  print(A+B)
elif (A-B)>(A+B) and (A-B)>(A*B):
  print(A-B)
else (A*B)>(A+B) and (A*B)>(A-B):
  print(A*B)

### FIXED CODE ###

A,B=map(int,input().split())
print(max(A+B,A-B,A*B))
from fractions import gcd
import math
import numpy as np
N = list(map(int, input().split()))
g = gcd(N[0], N[1])
max_prime = int(np.sqrt(g))+1
primes = np.ones(g + 1)
#print(g+1, primes.shape)
primes[0] = 0
#print(primes)
for i in range(2, max_prime):
  if i * 2 < g + 1:
    primes[i*2::i] = 0
    #print(i, primes)

primes = primes.nonzero()[0]
#print(primes.nonzero()[0])

factor = primes[g % primes == 0]

#print(g, original_g, factor)
print(len(factor))

### FIXED CODE ###

from fractions import gcd
import math
import numpy as np
N = list(map(int, input().split()))
g = gcd(N[0], N[1])

def factorize(g):
  factor = []
  for i in range(2, int(np.sqrt(g))+2):
    if g % i != 0:
      continue
    while g % i == 0:
      g //= i
    factor.append(i)
  if g != 1:
    factor.append(g)
  return factor
print(len(factorize(g))+1)
import sys

n , m = map(int,input().split())
if m == 0:
    m += 1
a = []

for i in range(m):
    a.append(list(map(int,input().split())))

ans = [-1] * n

for j in a:
    if ans[j[0]-1] == -1:
        if j[0] > n:
            print(-1)
            sys.exit()
        else:
            ans[j[0]-1] = j[1]
    elif ans[j[0]-1] == j[1]:
        continue
    else:
        print(-1)
        sys.exit()

if n == 3 and ans[0] == -1 and ans[1] == 0:
    ans[0] = 1

for index,l in enumerate(ans):
    if l == -1 :
        ans[index] = 0
    elif index == 0 and n != 1:
        if ans[index] == 0:
            print(-1)
            sys.exit()

for index , x in enumerate(ans):
    ans[index] = str(ans[index])

b = "".join(ans)

if b == "000" or b == "00" or b == "0":
    print(0)
else:
    print(int(b))

### FIXED CODE ###

import sys

n , m = map(int,input().split())
#if m == 0:
#    m += 1
a = []

for i in range(m):
    a.append(list(map(int,input().split())))

ans = [-1] * n

for j in a:
    if ans[j[0]-1] == -1:
        if j[0] > n:
            print(-1)
            sys.exit()
        else:
            ans[j[0]-1] = j[1]
    elif ans[j[0]-1] == j[1]:
        continue
    else:
        print(-1)
        sys.exit()

if n == 3 and ans[0] == -1:
    ans[0] = 1

if n == 2 and ans[0] == -1:
    ans[0] = 1

for index,l in enumerate(ans):
    if l == -1 :
        ans[index] = 0
    elif index == 0 and n != 1:
        if ans[index] == 0:
            print(-1)
            sys.exit()

for index , x in enumerate(ans):
    ans[index] = str(ans[index])

b = "".join(ans)

if b == "000" or b == "00" or b == "0":
    print(0)
else:
    if len(b) == n:
        print(int(b))
    else:
        print(-1)
import sys
s=list(input())
s=list(set(s))
s.sort()
#print(s)
for i in range(26):
    if chr(ord("a")+i)!=s[i]:
        print(chr(ord("a")+i))
        sys.exit()
print("None")

### FIXED CODE ###

import sys
s=list(input())
s=list(set(s))
s.sort()
s.append("eof")

for i in range(26):
    if chr(ord("a")+i)!=s[i]:
        print(chr(ord("a")+i))
        sys.exit()
print("None")
import pdb

def judgePrime(n):
  result = True
  i = 2
  while i < int(round(n)):
    if n % i == 0:
      result = False
      break
    i += 1
  return [result, i]

def getPrimeNumFromList(list):
  count = 0
  for i in xrange(len(list)):
    target = 0
    if i == 0:
      target = list[0]
      if judgePrime(target):
        count += 1
      else:
        pass

  return count

n = int(raw_input())
list = []

for i in xrange(n):
  list.append(int(raw_input()))
list.sort()

prime_list = []

while True:
  v = list.pop(0)
  result = judgePrime(v)
  if result[0]:
    # pdb.set_trace()
    prime_list.append(v)
  else:
    v = result[1]
  # print "list : "
  # print list
  # print "prime_list : "
  # print prime_list
  i = 0
  while True:
    # print "i = " + str(i)
    if i >= len(list):
      break
    elif list[i] % v == 0:
      list.pop(i)
      # print "i = " + str(i) + ", list: "
      # print list
    else:
      i += 1
  if len(list) == 0:
    break
  elif prime_list[len(prime_list) - 1] ^ 2 >= list[len(list) - 1]:
    prime_list.append(list)
    break

print len(prime_list)

### FIXED CODE ###

import pdb

n = int(raw_input())
count = 0
for x in xrange(n):
  target = int(raw_input())
  # pdb.set_trace()
  if target == 2:
    count += 1
  elif target < 3 or not target & 1:
    continue
  else:
    if pow(2, target - 1, target) == 1:
      count += 1

print count
n = int(input())
an = []
for _ in range(n):
  an.append(int(input()))
maxl = [an[0]]
maxr = [an[-1]]
for a in an[1:]:
  maxl.append(max(maxl[-1], a))
for a in an[1::-1]:
  maxr.insert(0, max(maxr[0], a))

print(maxr[1])
for i in range(1, n-1):
  print(max(maxl[i-1], maxr[i+1]))
print(maxl[n-2])

### FIXED CODE ###

n = int(input())
an = []
for _ in range(n):
  an.append(int(input()))
maxl = [an[0]]
maxr = [an[-1]]
for a in an[1:]:
  maxl.append(max(maxl[-1], a))
for a in an[:-1][::-1]:
  maxr.append(max(maxr[-1], a))
maxr = maxr[::-1]

print(maxr[1])
for i in range(1, n-1):
  print(max(maxl[i-1], maxr[i+1]))
print(maxl[n-2])
# coding:utf-8

import sys


input = sys.stdin.readline


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

a = max(A)
tmp = 0
for i in range(N):
    x = A[i]
    if x == a: continue
    x = max(x, a - x)
    if tmp < a - x:
        b = A[i]
        tmp = a - x

print(a, b)


### FIXED CODE ###

# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()

n = max(A)
r = max(A)
tmp = 0
for i in range(N):
    a = A[i]
    if a == n: continue
    if a < n - a: a = n - a
    if tmp <= n - a:
        r = A[i]
        tmp = n - a

print(n, r)
#n=int(input())
a,b,x=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

import math

s=x/a
if s<= a*b/s:
    c=2*s/b
    deg=math.degrees(math.atan(c/b))
    ans=90.0-deg
    print('{:.9f}'.format(ans))
else:
    s=a*b-s
    h=2*s/a
    deg=math.degrees(math.atan(a/h))
    ans=90.0-deg
    print('{:.9f}'.format(ans))


### FIXED CODE ###

#n=int(input())
a,b,x=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

import math

s=x/a
if x==a*a*b:
    print(0)
elif s<= a*b/2:
    c=2*s/b
    deg=math.degrees(math.atan(c/b))
    ans=90.0-deg
    print('{:.9f}'.format(ans))
else:
    s=a*b-s
    h=2*s/a
    deg=math.degrees(math.atan(a/h))
    ans=90.0-deg
    print('{:.9f}'.format(ans))
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
INF = float("inf")
num = [INF,2,5,5,4,5,6,3,7,6]
if N,M = 2,9:
    print(1)
    exit()

dp = [0]+[-INF]*N
#dpテーブルを作成
for i in range(1,N+1):
    ins = -INF
    for a in A:
        try:
            tmp = dp[i-num[a]]+1
            ins = max(ins,tmp)
        except:
            continue
    dp[i] = ins

#各桁の数字を決定
A.sort(reverse=True)
digit = ["0"]*dp[N]
mat = 0
for i in range(dp[N]):
    for a in A:
        try:
            t1 = dp[N-mat-num[a]]
            t2 = dp[N-mat]-1
        except:
            continue
        if t1 == t2:
            digit[i] = str(a)
            mat += num[a]
            break
print("".join(digit))


### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
INF = float("inf")
num = [INF,2,5,5,4,5,6,3,7,6]
if N==2 and M==9:
    print(1)
    exit()

dp = [0]+[-INF]*N
#dpテーブルを作成
for i in range(1,N+1):
    ins = -INF
    for a in A:
        try:
            tmp = dp[i-num[a]]+1
            ins = max(ins,tmp)
        except:
            continue
    dp[i] = ins

#各桁の数字を決定
A.sort(reverse=True)
digit = ["0"]*dp[N]
mat = 0
for i in range(dp[N]):
    for a in A:
        try:
            t1 = dp[N-mat-num[a]]
            t2 = dp[N-mat]-1
        except:
            continue
        if t1 == t2:
            digit[i] = str(a)
            mat += num[a]
            break
print("".join(digit))
import numpy as np

H, W = map(int, input().split())
field = []
for i in range(H):
    field.append(list(map(int, input().split())))

urdl = [(0,-1,0), (1,0,1), (0,1,2), (-1,0,3)]

move_records = []

if H != 1 or W != 1:
    for i in range(H):
        for j in range(W):
            if field[i][j] % 2 == 0:
                continue
            adj_values = np.array([-1, -1, -1, -1])
            if not i == 0:
                adj_values[0] = field[i-1][j]
            if not j == W-1:
                adj_values[1] = field[i][j+1]
            if not i == H-1:
                adj_values[2] = field[i+1][j]
            if not j == 0:
                adj_values[3] = field[i][j-1]

            if sum(adj_values[adj_values != -1] % 2) == 0:
                h,w,k = urdl[np.where(adj_values != -1)[0][0]]
                field[i][j] -= 1
                field[i+h][j+w] += 1
                
            else:
                for w,h,k in urdl:
                    if adj_values[k] == -1:
                        continue

                    if adj_values[k] % 2 != 0:
                        field[i][j] -= 1
                        field[i+h][j+w] += 1
                        break
            
            move_records.append([i+1,j+1,i+h+1,j+w+1])

M = len(move_records)
print(M)
for i in range(M):
    print('{} {} {} {}'.format(move_records[i][0],
                               move_records[i][1],
                               move_records[i][2],
                               move_records[i][3]))

### FIXED CODE ###

import numpy as np
H, W = map(int, input().split())
field = []
for i in range(H):
    field.append(list(map(int, input().split())))
rd = [(0,1,0), (1,0,1)]
move_records = []
if H != 1 or W != 1:
    for i in range(H):
        for j in range(W):
            if field[i][j] % 2 == 0:
                continue
            if i == H-1 and j == W-1:
                continue
            if i == H-1 and j == W-2:
                # import ipdb; ipdb.set_trace()
                if (field[H-1][W-1] + field[H-1][W-2]) % 2 != 0:
                    continue
                else:
                    field[H-1][W-2] -= 1
                    field[H-1][W-1] += 1
                    move_records.append([i+1,j+1,i+1,j+2])
            elif j != W-1:
                field[i][j] -= 1
                field[i][j+1] += 1
                move_records.append([i+1,j+1,i+1,j+2])
            else:
                field[i][j] -= 1
                field[i+1][j] += 1
                move_records.append([i+1,j+1,i+2,j+1])
M = len(move_records)
print(M)
for i in range(M):
    print('{} {} {} {}'.format(move_records[i][0],
                               move_records[i][1],
                               move_records[i][2],
                               move_records[i][3]))
def mapt(fn, *args):
    return list(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))

def main():
    N, X = Input()
    x = Input()

    if N == 1:
        print(abs(x[0] - X))
        exit()

    x.append(X)
    x.sort()
    data = [abs(x[i] - x[i+1]) for i in range(N)]

    ans = data[0]
    for i in range(1, N):
        ans = gcd(data[i], ans)
    print(ans)



main()

### FIXED CODE ###

def gcd(a, b):
    """最大公約数"""
    if b == 0: return a
    return gcd(b, a % b)
  

def mapt(fn, *args):
    return list(map(fn, *args))
 
 
def Input():
    return mapt(int, input().split(" "))
 
def main():
    N, X = Input()
    x = Input()
 
    if N == 1:
        print(abs(x[0] - X))
        exit()
 
    x.append(X)
    x.sort()
    data = [abs(x[i] - x[i+1]) for i in range(N)]
 
    ans = data[0]
    for i in range(1, N):
        ans = gcd(data[i], ans)
    print(ans)
 
 
 
main()
n = input()

l = len(n)

ans = 0
j = 1
for i in range(1, l, 2):
    ans += 9 * j
    j *= 100

if l % 2 == 0:
    print(ans)
else:
    ans += (int(n[0]) - 1) * j
    ans += int(n[1:]) + 1
    print(ans)

### FIXED CODE ###

n = input()

l = len(n)

ans = 0
j = 1
for i in range(1, l, 2):
    ans += 9 * j
    j *= 100

if l % 2 == 0:
    print(ans)
else:
    ans += (int(n[0]) - 1) * j
    if l != 1:
        ans += int(n[1:]) + 1
    else:
        ans += 1
    print(ans)
n, k = map(int, input().split())

li = [0]
li.extend(list(map(int, input().split())))

tuita = [0]*(n+1)

def search(town, li, times):
  if times == 0:
    return town
  return search(li[town], li, times-1)

cnt = 0
town = 1
while True:
  town = li[town]
  cnt += 1
  if tuita[town] == 0:
    tuita[town] = cnt
  else:
    if k < tuita[town]:
      print(search(1, li, k))
    elif k == tuita[town]:
      print(town)
    else:
      print(search(town, li, (k - tuita[town]) % (cnt - tuita[town])))
    break
 
 
  
    

### FIXED CODE ###

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

li = [0]
li.extend(list(map(int, input().split())))
tuita = [0]*(n+1)
cnt = 0
town = 1

lastTown = 1
while True:
  town = li[town]
  cnt += 1
  if tuita[town] == 0:
    tuita[town] = cnt
  else:
    if k < tuita[town]:
      lastTown = 1
      times = k
    elif k == tuita[town]:
      lastTown = town
      times = 0
    else:
      lastTown = town
      times = (k - tuita[town]) % (cnt - tuita[town])
    break

town = lastTown
while times > 0:
  if times <= 0:
    break
  times -= 1
  town = li[town]
print(town)
A,B=map(int,input().split())
Aset=set([int(i) for i in range(1,1263) if int(i*0.08)==A])
Bset=set([int(i) for i in range(1,1010) if int(i*0.1)==B])
print(min(Aset&Bset))




### FIXED CODE ###

A,B=map(int,input().split())
Aset=set([int(i) for i in range(1,1010) if int(i*0.08)==A])
Bset=set([int(i) for i in range(1,1010) if int(i*0.1)==B])
if Aset&Bset :
    print(min(Aset&Bset))
else:
    print(-1)
N, A, B = [int(x) for x in input().strip().split()]
if (A - B) % 2 == 0:
  print('Alice')
eles:
  print('Borys')

### FIXED CODE ###

N, A, B = [int(x) for x in input().strip().split()]
if (A - B) % 2 == 0:
  print('Alice')
else:
  print('Borys')
import sys,collections as cl
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a

h,w,k = m()

a = [1,1,2,3,5,8,13]

l = [[0 for i in range(w+2)] for j in range(h+1)]
l[0][1] = 1

for i in range(h):
	for j in range(w):
		l[i+1][j+1] = (l[i][j]*(a[max(0,j-1)] * a[w - 1 - j]) +l[i][j+1]*(a[j] * a[w - 1 - j]) + l[i][j+2]*(a[j] * a[max(0,w - 2 - j)]))%(10**9+7)
print(l[h][k])

### FIXED CODE ###

import sys,collections as cl
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a

h,w,k = m()

a = [1,1]

for i in range(98):
	a.append(a[-1] + a[-2])

l = [[0 for i in range(w+2)] for j in range(h+1)]
l[0][1] = 1

for i in range(h):
	for j in range(w):
		l[i+1][j+1] = (l[i][j]*(a[max(0,j-1)] * a[w - 1 - j]) +l[i][j+1]*(a[j] * a[w - 1 - j]) + l[i][j+2]*(a[j] * a[max(0,w - 2 - j)]))%(10**9+7)
print(l[h][k])
N =int(raw_input())
S =[]
P =[]
for i in range(N):
    s,p=map(str,raw_input().split())
    S.append(s)
    P.append(p)
ss=sorted(list(set(S)))
for i in range(len(ss)):
    a =[]
    b =[]
    for j in range(N):
        if ss[i]==S[j]:
            a.append(j)
            b.append(P[i])
    c = list(sorted(b)).reverse()
    if len(c)>0:
        for k in c:
            for j in range(len(b)):
                if k == b[j]:
                    print(a[j])



### FIXED CODE ###

N =int(raw_input())
S =[]
P =[]
for i in range(N):
    s,p=map(str,raw_input().split())
    S.append(s)
    P.append(int(p))
ss=sorted(list(set(S)))
for sss in ss:
    a =[]
    b =[]
    for j in range(N):
        if sss==S[j]:
            a.append(j)
            b.append(P[j])
    if len(b)>0:
        c = sorted(b,reverse=True)
        #print c,b
        for k in c:
            for j in range(len(b)):
                if k == b[j]:
                    print(a[j]+1)
n= int(input())
s= input()
suma=[0]
for i in range(n):
  if s[i] == 'I':
    suma.append(s[i]+1)
  else:
    suma.append(s[i]-1)
print(max(suma))

### FIXED CODE ###

n= int(input())
s= input()
suma=[0]
for i in range(n):
  if s[i] == 'I':
    suma.append(suma[i]+1)
  else:
    suma.append(suma[i]-1)
print(max(suma))
#!/usr/bin/python3

import os
import sys


def main():
    X, Y = read_ints()
    print(solve(X, Y))


MOD = 10 ** 9 + 7


def mpow(a, n):
    p = a
    v = 1
    while n > 0:
        if n & 1:
            v *= p
            v %= MOD
        n >>= 1
        p *= p
        p %= MOD
    return v


def solve(X, Y):
    s = X + Y
    if s % 3 != 0:
        return 0
    s //= 3

    a = 2 * s - X
    b = 2 * s - Y
    c = a + b

    facts = [0] * (c + 1)
    facts[0] = 1
    for i in range(1, c + 1):
        facts[i] = (facts[i - 1] * i) % MOD

    return (facts[c] * mpow(facts[a], MOD - 2) * mpow(facts[b], MOD - 2)) % MOD


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/python3

import os
import sys


def main():
    X, Y = read_ints()
    print(solve(X, Y))


MOD = 10 ** 9 + 7


def mpow(a, n):
    p = a
    v = 1
    while n > 0:
        if n & 1:
            v *= p
            v %= MOD
        n >>= 1
        p *= p
        p %= MOD
    return v


def solve(X, Y):
    s = X + Y
    if s % 3 != 0:
        return 0
    s //= 3

    a = 2 * s - X
    b = 2 * s - Y
    if a < 0 or b < 0:
        return 0

    c = a + b

    facts = [0] * (c + 1)
    facts[0] = 1
    for i in range(1, c + 1):
        facts[i] = (facts[i - 1] * i) % MOD

    return (facts[c] * mpow(facts[a], MOD - 2) * mpow(facts[b], MOD - 2)) % MOD


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()
a=input().split()
pl1=int(a[0])
pl0=int(a[1])
pl_1=int(a[2])
draw=int(a[3])

if(pl1+pl0>draw):
  print(pl1)
else:
  all_card=pl1+pl0+pl_1
  print(all_card)
  draw_pl_1=all_card-draw
  print(draw_pl_1)
  print(pl1-draw_pl_1)

### FIXED CODE ###

a=input()
b=input()
if(a == b[:-1]):
  print('Yes')
else:
  print('No')
# -*- coding: utf-8 -*-
import re

qS = input()

counts = {}


def replace(s, count):
    if counts.get(s, -1) >= 0:
        return counts[s]
    else:
        matches = re.finditer('ABC', s)
        max_count = count
        for m in matches:
            m.span()
            max_count = max(max_count, replace(
                s[:m.span()[0]] + 'BCA' + s[m.span()[1]:], count + 1))
        counts[s] = max_count
        return counts[s]


print(replace(qS, 0))


### FIXED CODE ###

# -*- coding: utf-8 -*-
s = input()

a_num = 0
bc_num = 0
ans = 0
i = 0
while i < len(s):
    if s[i] == 'A':
        a_num += 1
        i += 1
    elif s[i:i+2] == 'BC':
        ans += a_num
        i += 2
    else:
        a_num = 0
        b_num = 0
        i += 1

print(ans)
def SelectionSort(A):
    count = 0
    for i in range(len(A)):
        minj = i
        for j in range(i, range(A)):
            if A[j] < A[minj]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        count += 1
    print(" ".join(map(str, A)))
    print(count)


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

SelectionSort(A)

### FIXED CODE ###

def SelectionSort(A):
    count = 0
    for i in range(len(A)):
        minj = i
        for j in range(i, len(A)):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            count += 1
    print(" ".join(map(str, A)))
    print(count)


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

SelectionSort(A)
x = int(input())
def dp(x):
    if x == 0:
        return True
    if x < 100:
        return False
    return any([dp(x-100), dp(x-101), dp(x-102), dp(x-103), dp(x-104), dp(x-105)])

if dp(x):
    print(1)
else:
    print(0)

### FIXED CODE ###

import sys
x = int(input())
for i in range(1000):
    if 100*i <= x <= 105*i:
        print(1)
        sys.exit()
print(0)
s = input()
ans = []
dp = [""]*(len(s))
if s[0] != "B":
    dp[0] = s[0]
else:
    dp[0] = [""]

#print(dp)
for i in range(len(s)-1):
    if s[i+1] != "B":
        dp[i+1] = dp[i] + s[i+1]
    else:
        dp[i+1] = dp[i][:-1]
    #print(dp)
print(dp[len(s)-1])

### FIXED CODE ###

s = input()
ans = []
dp = [""]*(len(s))
if s[0] != "B":
    dp[0] = s[0]
else:
    dp[0] = ""

for i in range(len(s)-1):
    if s[i+1] != "B":
        dp[i+1] = dp[i] + s[i+1]
    else:
        dp[i+1] = dp[i][:len(dp[i])-1]
print(dp[len(s)-1])
a=int(input())
b=int(input())

print(a*b,2a+2b)


### FIXED CODE ###

l = input().split()
a = int(l[0])
b = int(l[1])
print(a*b,2*a+2*b)
S = input()

count = 0
mod_check = {}
mod_check[0] = 1
check_S = 0
for i in reversed(S):
    check_S += int(i) * (10 ** count)
    mod = check_S % 2019
    mod_check.setdefault(mod, 0)
    mod_check[mod] += 1
    count += 1
mod_match = 0
for x in mod_check.values():
    mod_match += x * (x - 1) // 2
print(mod_match)


### FIXED CODE ###

S, W = map(int, input().split())
if S <= W:
    print("unsafe")
else:
    print("safe")
import numpy as np

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

total = A.sum()
if total%10 == 0:
  if np.any(A%10 != 0):
    total -= A[A%10 != 0].min():
  else:
    total = 0
print(total)    

### FIXED CODE ###

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

total = sum(A)
if total%10 == 0:
  A.sort()
  for a in A:
    if a%10 != 0:
      total -= a
      break
  else: # 全部が10の倍数
    total = 0
print(total)