Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3
import sys
from collections import deque
INF = float("inf")


def solve(H: int, W: int, A: "List[str]"):
    # 黒の位置をx, y座標として持つ。
    black = []
    B = [[0]*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                black.append((i, j))
            B[i][j] = 0 if A[i][j] == "#" else -INF  # 黒は1

    black2 = black.copy()
    black.sort(key=lambda x: x[0])
    black2.sort(key=lambda x: x[1])

    gene = 0
    q = deque()
    q.extend(black)
    q2 = deque()
    counter = len(black)
    while True:
        gene += 1
        while len(q) > 0:
            y, x = q.popleft()
            for yy, xx in zip([y-1, y, y+1, x], [x, x-1, x, x+1]):
                if 0 <= yy < H and 0 <= xx < W and B[yy][xx] < 0:
                    B[yy][xx] = gene
                    q2.append((yy, xx))
                    counter += 1
        q = q2
        q2 = deque()
        if counter == H*W:
            break
    print(gene)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import deque
INF = float("inf")


def solve(H: int, W: int, A: "List[str]"):
    # 黒の位置をx, y座標として持つ。黒からの距離も一緒に持つ
    black = []
    B = [[-1]*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                black.append((i, j, 0))
                B[i][j] = 0

    q = deque()
    q.extend(black)

    while len(q) > 0:
        cy, cx, dis = q.popleft()
        for y, x in zip([cy-1, cy, cy+1, cy], [cx, cx-1, cx, cx+1]):
            if 0 <= y < H and 0 <= x < W and B[y][x] < 0:
                B[y][x] = dis+1
                q.append((y, x, dis+1))

    m = -INF
    for i in range(H):
        a = max(B[i])
        if m < a:
            m = a
    print(m)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, A)


if __name__ == '__main__':
    main()
pr = int(input())
li =[]

for i in range(pr):
    li.append(int(input))

disc = max(li)

print(sum(li) - disc)

### FIXED CODE ###

pr = int(input())
li =[]

for i in range(pr):
    li.append(int(input()))

disc = max(li) // 2

print(sum(li) - disc)
from fractions import gcd

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

gcd=gcd(a,b)

f=[]
for i in range(2,int(gcd(a,b)**0.5)+1):
    while gcd%i==0:
        gcd=gcd//i
        f.append(i)
        break
print(len(set(f))+1)


### FIXED CODE ###

from fractions import gcd

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

gcd=gcd(a,b)
ab_gcd=gcd

f=[]
for i in range(2,int(ab_gcd**0.5)+1):
    while gcd%i==0:
        gcd=gcd//i
        f.append(i)
if gcd!=1:
    f.append(gcd)

print(len(set(f))+1)
X = int(input())
Y = int(input())

x = int(X + Y/2)
print(x)

### FIXED CODE ###

X,Y = map(int,input().split())
print(X+Y//2)
import collections
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

count_D = collections.Counter(D)
count_T = collections.Counter(T)

ans = 'YES'
for k,v in count_T.items():
  if D[k] < v:
    ans = 'NO'
    break
print(ans)

### FIXED CODE ###

import collections
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

count_D = collections.Counter(D)
count_T = collections.Counter(T)

ans = 'YES'
for k,v in count_T.items():
  if count_D[k] < v:
    ans = 'NO'
    break
print(ans)
from numba import njit


@njit('void(i8)')
def main(n, m):

    A = []
    B = []
    cnt = 0
    ans = 0

    for _ in range(n):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    while cnt < m:
        A_min = min(A)
        A_min_index = A.index(A_min)
        if cnt + B[A_min_index] < m:
            ans += A_min * B[A_min_index]
            cnt += B[A_min_index]
            A.pop(A_min_index)
            B.pop(A_min_index)
        else:
            for i in range(B[A_min_index]):
                if cnt == m:
                    break
                ans += A_min
                cnt += 1

    print(ans)


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

main(n, m)


### FIXED CODE ###

n, m = map(int, input().split())
drink = sorted([list(map(int, input().split())) for _ in range(n)])

ans = 0

for a,b in drink:
    ans += a*min(b,m)
    m -= min(b,m)
    if m == 0:
        break

print(ans)
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if abs(A-B)/abs(W-V) > T:
    print('NO')
else:
    print('YES')

### FIXED CODE ###

A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())

if W>=V or abs(A-B)/abs(W-V) > T:
    print('NO')
else:
    print('YES')
I = lambda: map(int, input().split())
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
minf = -float('inf')
n, _ = I()
*A, = sorted(I(), reverse = True)
digs = [0]*(n+1)+[-1]*9
for i in range(1, n+1):
    d = []
    for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
    digs[i] = max(d)
ans = []
while n > 0:
    for a in A:
        if digs[n-nums[a]] == digs[n]-1:
            ans.append(a)
            n -= nums[a]
            break
print(*ans, sep = '')

### FIXED CODE ###

a, b = map(int, input().split())
print((-1)**(b%a != 0)*a+b)
for _ in range(3):
  A = list(map(int, input().split())) 
N = int(input())

for _ in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if A[y][x] == b:
                A[y][x] = -1

for y in range(3):
    f = True
    for x in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

for x in range(3):
    f = True
    for y in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

f = True
for x in range(3):
    if A[2 - x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

print('No')

### FIXED CODE ###

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
mark = [[False, False, False] for _ in range(3)]
for i in range(3):
    for j in range(3):
        if a[i][j] in b:mark[i][j] = True

ans = 'No'
for i in range(3):
    if all(mark[i]):
        ans = 'Yes'
        break      
for j in range(3):
    if mark[0][j] and mark[1][j] and mark[2][j]:
        ans = 'Yes'
        break
if (mark[0][0] and mark[1][1] and mark[2][2]) or (mark[0][2] and mark[1][1] and mark[2][0]): ans = 'Yes'
print(ans)
a = str(input())

if (a == 'A'): 
    print('T')
elif (a == 'T):
    print('A')
elif (a == 'G'):
    print('C')
elif(a =='C'):
    print('G')
else: print("none")  
    
    
    

### FIXED CODE ###

a = str(input())

if (a == 'A'): 
    print('T')
elif (a == 'T'):
    print('A')
elif (a == 'G'):
    print('C')
elif(a =='C'):
    print('G')
else: print("none")
n,m=map(int,input().split())
a=[]
for i in range(m):
	a.append(int(input()))
if a[0]!=1:
	a.insert(0,-1)
if a[-1]!=n-1:
	a.append(n+1)
b=[]
for i in range(len(a)-1):
	b.append(a[i+1]-a[i]-1)
	if a[i+1]-a[i]==1:
		print(0)
		exit()
def Fib(n, memo={}):
    if n == 1:
        return 1
    elif n == 2:
        return 1
    elif n in memo:
        return memo[n]
    else:
        memo[n] = Fib(n-1,memo)+Fib(n-2,memo)
        return memo[n]
ans=1
for i in range(len(b)):
	ans*=Fib(b[i])
	ans%=10**9+7
print(ans)


### FIXED CODE ###

def Fib(n):
    a=[0,1,1]
    if n<=2:
    	return a[n]
    else:
    	for i in range(n-2):
    		a.append(a[i+1]+a[i+2])
    	return a[n]
n,m=map(int,input().split())
if m==0:
	print(Fib(n+1)%(10**9+7))
	exit()
a=[]
for i in range(m):
	a.append(int(input()))
if a[0]!=1:
	a.insert(0,-1)
if a[-1]!=n-1:
	a.append(n+1)
b=[]
for i in range(len(a)-1):
	b.append(a[i+1]-a[i]-1)
	if a[i+1]-a[i]==1:
		print(0)
		exit()
ans=1
for i in range(len(b)):
	ans*=Fib(b[i])
	ans%=10**9+7
print(ans)
h, w = map(int, input().split())

if h % 2 == 0:
    ans = h / 2 * w
elif w % 2 == 0:
    ans = (h - 1) / 2 * w / 2 + (h + 1) / 2 * w / 2
else:
    ans = (h - 1) / 2 * (w - 1) / 2 + (h + 1) / 2 * (w + 1) / 2

if h == 1 or w == 1:
    ans = 1

print(int(ans))


### FIXED CODE ###

text = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"

li = list(map(int, text.split(', ')))

k = int(input())

print(li[k - 1])
c=list(map(int,input().split()))
bunsi=c[0]
bunbo=c[1]
n=c[2]
k=n//bunbo
d=[n]
if k!=0:
    for i in range(0,k):
        d.append(bunbo*(i+1)-1)
#dの中には候補となるxが入った
def floor(x):
    return ((bunsi*x)//bunbo)-(bunsi*(x//bunbo))
print(max(floor(d[0]),floor(d[-1]),floor(d[-2])))

### FIXED CODE ###

c=list(map(int,input().split()))
bunsi=c[0]
bunbo=c[1]
n=c[2]
k=n//bunbo
d=[n]
if k>=1:
    d.append(bunbo-1)
    d.append(bunbo*k-1)
#dの中には候補となるxが入った
def floor(x):
    return ((bunsi*x)//bunbo)-(bunsi*(x//bunbo))
if len(d)>=2:
    print(max(floor(d[0]),floor(d[-1]),floor(d[-2])))
if len(d)==1:
    print(floor(d[0]))
N = int(input())
S = input()
length = N//2

while length:
  strings = [S[i:i+length] for i in range(N-length+1)]
  print(length, strings)
  for i in range(N-length+1):
    for j in range(i+length,N-length+1):
      if S[i:i+length] == S[j:j+length]:
        print(length)
        break
  
  length -= 1
else:
  print(0)

### FIXED CODE ###

N = int(input())
S = input()
from collections import deque

def is_ok(l):
    hs = set()
    q = deque()
    for i in range(N-l+1):
        h = S[i:i+l]
        if h in hs:
            return True
        q.append(h)
        if len(q) >= l:
            hs.add(q.popleft())
    return False

ok = 0
ng = N//2+1
while ng-ok > 1:
    m = (ng+ok)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)
# 4 5 (4 cities and 5 steps)
# 3 2 4 1

# 1 => 3
# 2 => 2
# 3 => 4
# 4 => 1

N, K = map(int, input().split())
A_i = list(map(int, input().split()))

paths = {}

for i in range(N):
    paths[i+1] = A_i[i]

# print('paths:', paths)

# 6 5 2 5 3 2

# 1 => 6 (1)
# 6 => 2 (2)
# 2 => 5 (3)
# 5 => 3 (4)
# 3 => 2 (5)

state = 1
steps = 0
flag = False
known_states = {}

while steps < K:
    known_states[state] = steps # state => 2, steps => 2

    state = paths[state] # state => 5
    steps += 1 # steps => 3

    # print(f'steps: {steps}, state: {state}')

    if state in known_states and not flag: # state => 2 steps => 5
        loop_steps = (steps - known_states[state] - 1)
        steps = K - ((K - steps) % loop_steps)
        flag = True
        # print('loop detected')


print(state)


### FIXED CODE ###

# 4 5 (4 cities and 5 steps)
# 3 2 4 1

# 1 => 3
# 2 => 2
# 3 => 4
# 4 => 1

# 1 (0)
# 1 => 3 (1)
# 3 => 4 (2)
# 4 => 1 (3)

# 2 を作る 5 と2 と 1 を使う
# 2  = (5 - 3) % 2 + 3 - 1

N, K = map(int, input().split())
A_i = list(map(int, input().split()))

paths = {}

for i in range(N):
    paths[i+1] = A_i[i]

# print('paths:', paths)

# 6 5 2 5 3 2

# 1 => 6 (1)
# 6 => 2 (2)
# 2 => 5 (3)
# 5 => 3 (4)
# 3 => 2 (5)

# loop_steps = 5 - 2 - 1 = 2
# 5 + 2 * m + r = 727202214173249351
# steps + loop_steps * m + r = K
# r = (K - steps) % loop_steps

state = 1
steps = 0
flag = False
known_states = {}

while steps < K:
    known_states[state] = steps # state => 2, steps => 2

    state = paths[state] # state => 5
    steps += 1 # steps => 3

    # print(f'steps: {steps}, state: {state}')

    if state in known_states and not flag: # state => 2 steps => 5
        loop_steps = steps - known_states[state]
        K = (steps - loop_steps) + (K - (steps - loop_steps))  % loop_steps
        # print('loop_steps:', loop_steps)
        # print('steps - loop_steps:', steps - loop_steps)
        # print('K:', K)
        state = 1
        steps = 0
        # print('steps:', steps)
        flag = True
        # print('loop detected')



print(state)
from numba.np.ufunc import parallel
from numba import njit,prange


@njit(cache=True,parallel=True)
def solve(n,x,y):
    ans = [0] * (n - 1)
    for i in prange(n):
        for j in prange(n):
            c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
            if c:
                ans[c-1] += 1
    return ans


n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = solve(n,x,y)
for ai in ans:
    print(ai//2)


### FIXED CODE ###

n, x, y = map(int, input().split())
ans = [0] * (n - 1)

x -= 1
y -= 1
for i in range(n):
    for j in range(n):
        c = min(abs(i - j), abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
        if c:
            ans[c-1] += 1

for ai in ans:
    print(ai//2)
import math
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
ans=1

def fib(n):
  if n==1:
    return 1
  elif n<=0:
    return 0
  tmp1,tmp2=1,2
  for _ in range(n-2):
    tmp1,tmp2=tmp2,tmp1+tmp2
  return tmp2

for i in range(m):
  if i==0 and a[0]==1:
    pass
  if i==0 and a[0]!=1:
    ans*=a[i]-1
  elif i>0:
  	ans*=fib(a[i]-a[i-1]-2)
  ans%=1000000007

ans*=fib(n-a[-1]-1)
ans%=1000000007
print(ans)

### FIXED CODE ###

import math

def fib(n):
  if n==1:
    return 1
  elif n<=0:
    return 0
  tmp1,tmp2=1,2
  for _ in range(n-2):
    tmp1,tmp2=tmp2,tmp1+tmp2
  return tmp2

n,m=map(int,input().split())
if m==0:
  print(fib(n)%1000000007)
  exit()
a=[int(input()) for _ in range(m)]
ans=1

if n==2 and a[0]==1:
  print(1)
  exit()

for i in range(m):
  if i==0 and a[0]==1:
    pass
  if i==0 and a[0]!=1:
    ans*=fib(a[i]-1)
  elif i>0 and a[i]-a[i-1]==2:
    pass
  elif i>0 and a[i]-a[i-1]!=2:
  	ans*=fib(a[i]-a[i-1]-2)
  ans%=1000000007
  
if n-a[-1]>1: 
  ans*=fib(n-a[-1]-1)
ans%=1000000007
print(ans)
X = int(input())

print(X // 500 * 1000 + X % 500 // 5 * 5)


### FIXED CODE ###

S = input()

if S[2] == S[3] and S[4] == S[5]:
  print("Yes")
else:
  print("No")
import sys

N = input()
num =[input() for i in range(N)]
for i in range(len(num)):
    print "Case 1: " + num[i]

### FIXED CODE ###

i = 0
while True:
    i += 1
    num = raw_input()
    if num == "0":
        break
    print "Case %d: %s" % (i,num)
a=2019
for i in range(int(a**0.5)):
  if a%i==0:
    print(i)
    break

### FIXED CODE ###

s = input()
p=2019;n=len(s)
digit_rm = [0 for _ in range(n)]
for i in range(n):
	digit_rm[i] = (int(s[n-1-i]) * pow(10, i, p) ) % p

remain = [0 for _ in range(n)]
for i in range(n):
	if i == 0:
		remain[i] = digit_rm[i]
	else:
		remain[i] = (remain[i-1] + digit_rm[i]) % p
pcnt = [0 for _ in range(p)]
for i in remain:
	pcnt[i] += 1
ans = pcnt[0]
for num in pcnt:
	if num != 0:
		ans += num * (num - 1) // 2
print(ans)
A,B = (int(x) for x in input().split())

L = [(int((i+1)*0.08),int((i+1)*0.1)) for i in range(1000)]

check = 1

for i in range(1000):
    if L[i] == (A,B):
        print(i+1)
        check = 0
        break
A,B = (int(x) for x in input().split())

L = [(int((i+1)*0.08),int((i+1)*0.1)) for i in range(1010)]

check = 1

for i in range(1010):
    if L[i] == (A,B):
        print(i+1)
        check = 0
        break

if check == 1:
    print(-1)

if check == 1:
    print(-1)

### FIXED CODE ###


import math

# 入力
A,B = (int(x) for x in input().split())

LA = list(range(math.ceil(12.5*A),math.ceil(12.5*(A+1))))
LB = list(range(math.ceil(10*B),math.ceil(10*(B+1))))

intersect = set(LA) & set(LB)

if intersect == set():
    print(-1)
else:
    print(min(intersect))
word1=list(input())
word2=list(input2())
i = 0
for i, j in word1, word2 :
  if i!=J:
    i++
print(i)
    

### FIXED CODE ###

word1 = list(input())
word2 = list(input())
i = 0
for p, q in zip(word1, word2):
	if p!=q:
		i+=1
print(i)
S = input()
N = len(S)

if S[-1] == "1":
    print(-1)
    exit()

R = []
for i in range(N // 2):
    if S[i] == "1":
        if S[N - i - 2] == "1":
            R.append(i + 1)
        else:
            print(-1)
            exit()

# 構築
T = [[] for i in range(N)]

next = 1
mark = 0
for i in range(N):
    child = mark + 1
    if S[i] == "0":
        next += 1
    else:
        for n in range(next):
            T[mark].append(child)
            child += 1

        mark = child - 1

for i in range(N):
    for t in T[i]:
        print(i+1, t+1)


### FIXED CODE ###

S = input()
N = len(S)

if S[0] == "0" or S[-1] == "1":
    print(-1)
    exit()

D = {}
for i in range(N - 1):
    D[i + 1] = S[i]
for i in range(1, N):
    if D[i] != D[N - i]:
        print(-1)
        exit()

# 構築
T = [[] for i in range(N)]

next = 1
mark = 0
for i in range(N):
    child = mark + 1
    if S[i] == "0":
        next += 1
    else:
        for n in range(next):
            T[mark].append(child)
            child += 1
        next = 1
        mark = child - 1

for i in range(N):
    for t in T[i]:
        print(i + 1, t + 1)
s = str(input())


print(0:len(s):2)

### FIXED CODE ###

s = str(input())


print(s[0:len(s):2])
size = int(raw_input())
rabbit_list = raw_input().split()
rabbits = [int(x) for x in rabbits_input]
count = 0
for i in range(size):
    if (rabbits[i] - 1) > i and (rabbits[rabbits[i]-1] - 1) == i:
        count += 1
print(count)

### FIXED CODE ###

size = int(input())
rabbits = list(map(int, input().split()))
count = 0
for i in range(size):
    if (rabbits[i] - 1) > i and (rabbits[rabbits[i]-1] - 1) == i:
        count += 1
print(count)
A, B =[int(input()) for i in range(2)]
result = int(int(A)*int(B))
if 9 < int(A):
    print(-1)
elif 9 < int(B):
    print(-1)
else:
    print(result)

### FIXED CODE ###

list = input().split(' ')
A = int(list[0])
B = int(list[1])
if A <= 9 and B <= 9:
    print(A*B)
else:
    print(-1)
x = int(input())
y = int(input())
z = int(input())

a = z
b = y
c = x

print("%i %i %i" %(a,b,c))



### FIXED CODE ###

x,y,z = input().split()

a = z
b = x
c = y

print(str(a)+" "+str(b)+" "+str(c))
# https://atcoder.jp/contests/abc148/tasks/abc148_c
import math


def main():
    (a, b) = [int(i) for i in input().split(" ")]
    print(a * b // math.gcd(a, b))
    


if __name__ == '__main__':
    main()


### FIXED CODE ###

# https://atcoder.jp/contests/abc148/tasks/abc148_c
import fractions
# math.gcdは3.5からなのでAtCoderで使えない
# import math


def main():
    (a, b) = [int(i) for i in input().split(" ")]
    print(int(a * b / fractions.gcd(a, b)))


if __name__ == '__main__':
    main()
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
a.sort(reverse=True)


def waru(i, tempb):
    if a[i] >= 1:
        a[i - 1] = a[i]
        a[i] = tempb

        if a[i] < a[i + 1]:
            waru(i + 1, tempb)


while m > 0:
    a[0] = a[0] // 2
    if a[0] < a[1]:
        waru(1, a[0])
    if a[0] < 1:
        break
    m -= 1

if a[0] < 1:
    print(0)
else:
    print(sum(a))



### FIXED CODE ###

import heapq

n,m  = map(int,input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    tmax = heapq.heappop(a)
    tmax = -(-tmax //2)
    heapq.heappush(a,tmax)

print(-1*sum(a))
s = input()
str = ""
count = 0
for i in range(len(s)):
    #print("str",str)
    if s[i] == "0":
        str += s[i]
        count += 1
    elif s[i] == "1":
        str += s[i]
        count += 1
    elif s[i] == "B":
        if count > 0:
            str = str.rstrip(str[count-1])
            count -= 1


print(str)


### FIXED CODE ###

s = input()
str = ""
count = 0
for i in range(len(s)):
    #print("count",count)
    if s[i] == "0":
        str += s[i]
        count += 1
    elif s[i] == "1":
        str += s[i]
        count += 1
    elif s[i] == "B":
        if count > 0:
            str = str[:-1]
            count -= 1
#print("str",str)


print(str)
m=[1819,2003,876,2840,1723,1673,3776,2848,1592,922]
m.sort().reverse()
print m[0|2]

### FIXED CODE ###

m=[]
for i in range(10):
	x = input()
	m.append(x)
m.sort()
m.reverse()
for i in range(0,3):
	print m[i]
def func(c,x):
    c[x][0] = 1
    for i in c[x][1:]:
        if c[i][0] == 0:
            func(c,i)
    return c

# 入力
N,M = map(int,input().split())
XYZ = list(list(map(int,input().split()))for i in range(M))
############################################
card = [[0]for i in range(N)]
set = 0
############################################
# グラフを描く
for x,y,z in XYZ:
    card[x-1].append(y-1)
    card[y-1].append(x-1)
############################################
for i in range(N):
    if card[i][0] == 0:
        set += 1
        card = func(card,i)
############################################
print(set)

### FIXED CODE ###

import sys
sys.setrecursionlimit(2000000)
def func(c,x):
    c[x][0] = 1
    for i in c[x][1:]:
        if c[i][0] == 0:
            func(c,i)
    return c

# 入力
N,M = map(int,input().split())
XYZ = list(list(map(int,input().split()))for i in range(M))
############################################
card = [[0]for i in range(N)]
set = 0
############################################
# グラフを描く
for x,y,z in XYZ:
    card[x-1].append(y-1)
    card[y-1].append(x-1)
############################################
for i in range(N):
    if card[i][0] == 0:
        set += 1
        card = func(card,i)
############################################
print(set)
print('TCGA'[id('')%5])

### FIXED CODE ###

print({'A':'T','T':'A','C':'G','G':'C'}[input()])
N = int(input())
L = [2, 1]
for i in range(2, N+1):
    L.append(L[i - 1] + L[i - 2])
print(L[i])


### FIXED CODE ###

N = int(input())
L = [2, 1]
for i in range(2, N+1):
    L.append(L[i - 1] + L[i - 2])
print(L[N])
s=int(input())
if s[0]==s[1] or s[1]==s[2] or s[2]=s[3]:
  print("Good")
else:
  print("Bad")

### FIXED CODE ###

s=input()
a=int(s[0])-int(s[1])
b=int(s[1])-int(s[2])
c=int(s[2])-int(s[3])
if a!=0 and b!=0 and c!=0:
  print("Good")
else:
  print("Bad")
s = input()
t = input()
slist = []
for i in range(0, len(s)):
	slist.append(s[i])
tlist = []
for i in range(0, len(t)):
slist.sort()
tlist.sort(reverse = True)
news = ''
for i in range(0, len(slist)):
	news = news + slist[i]
newt = ''
for i in range(0, len(tlist)):
	newt = newt + tlist[i]
if news < newt: print('Yes')
else: print('No')

### FIXED CODE ###

s = input()
t = input()
slist = []
for i in range(0, len(s)):
	slist.append(s[i])
tlist = []
for i in range(0, len(t)):
	tlist.append(t[i])
slist.sort()
tlist.sort(reverse = True)
news = ''
for i in range(0, len(slist)):
	news = news + slist[i]
newt = ''
for i in range(0, len(tlist)):
	newt = newt + tlist[i]
if news < newt: print('Yes')
else: print('No')
n = int(input())
count = 0
for i in range(len(n)):
  if n[i] == 1:
    count += 1
  else:
    count += 0
print(count)

### FIXED CODE ###

n = str(input())
count = 0
for i in range(len(n)):
  if n[i] == '1':
    count += 1
  else:
    count += 0
print(count)
n = int(input())

x = list(map(int,input().split()))

from statistics import median

for i in range(n):
    print(median(x[:i]+x[i+1:]))

### FIXED CODE ###

n = int(input())

xx = list(map(int,input().split()))
x = sorted(xx)

left = x[n//2-1]
right = x[n//2]
mid = (left+right)/2

for i in range(n):
    if xx[i] >= mid:
        print(left)
    else:print(right)
n = int(input())
for i in range(n):
    t, x, y = map(int, input().split())
    if x + y < t or (x+y-t)%2 /= 0:
        print("No")
        exit()
print("Yes")

### FIXED CODE ###

n = int(input())
ti=0
xi=0
yi=0
for i in range(n):
    t, x, y = map(int, input().split())
    if abs(x-xi) + abs(y-yi) > abs(t-ti) or (abs(x-xi) + abs(y-yi) + abs(t-ti)) % 2 != 0:
        print("No")
        exit()
    ti=t
    xi=x
    yi=y
print("Yes")
n = int(input())
s = input()
k = int(input())

moji = s[k]
ans = ''
for i in range(n):
    if s[i] == moji:
        ans = ans + moji
    else:
        ans = ans + '*'
print(ans)

### FIXED CODE ###

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

moji = s[k-1]
ans = ''
for i in range(n):
    if s[i] == moji:
        ans = ans + moji
    else:
        ans = ans + '*'
print(ans)