Harryxun/stf_run huggingface dataset:
class UnionFind:
    def __init__(self, num):
        self.p = [x for x in range(num)]
    def root(self, x):
        if self.p[x] == x:
            return x
        self.p[x] = self.root(self.p[x])
        return self.p[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return
        self.p[rx] = ry

def main():
    N, M = (int(x) for x in input().split())
    u = UnionFind(N)

    for i in range(M):
        x,y,_ = map(int, input().split())
        u.unite(x-1, y-1)

    rlist = set()
    for i in range(N):
        parent = u.root(i)
        rlist.add(parent)

    print(len(rlist))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

class UnionFind:
    def __init__(self, num):
        self.p = [x for x in range(num)]
    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx != ry:
            self.p[ry] = rx

def main():
    N, M = (int(x) for x in input().split())
    u = UnionFind(N)

    for i in range(M):
        x,y,_ = map(int, input().split())
        u.unite(x-1, y-1)

    rlist = set()
    for i in range(N):
        rlist.add(u.root(i))

    print(len(rlist))

if __name__ == '__main__':
    main()
import math
r = input()
print(2 * math.pi * r)
quit()


### FIXED CODE ###

import math
r = int(input())
print(2 * math.pi * r)
quit()
import math
n=int(input())
for i in range(n,10**6):
  for j in range(2,int(math.sqrd(i**0.5))+1):
    if i%j==0:
      break
  else:
    print(i)
    break


### FIXED CODE ###

n=int(input())
for i in range(n,10**6):
  for j in range(2,int(i**0.5)+1):
    if i%j==0:
      break
  else:
    print(i)
    break
# https://atcoder.jp/contests/abc098/submissions/5418660
N = int(input())
S = input()
ans = 0
moji = 'abcdefghijklmnopqrstuvwxyz'
for i in range(1, N):
  l, r = S[:i], S[i:]
  cnt = 0
  for c in moji:
    if c in l an c in r:
      cnt += 1
  ans = max(ans, cnt)
  
print(ans)

### FIXED CODE ###

# https://atcoder.jp/contests/abc098/submissions/5418660
N = int(input())
S = input()
ans = 0
moji = 'abcdefghijklmnopqrstuvwxyz'
for i in range(1, N):
  l, r = S[:i], S[i:]
  cnt = 0
  for c in moji:
    if c in l and c in r:
      cnt += 1
  ans = max(ans, cnt)
  
print(ans)
X, N = map(int,input().split(' '))
if N == 0:
    print(X)
    exit()

p = input().split(' ')
p =[int(i) for i in p]
if X not in p:
    print(X)
    exit()

num_list = [int(i) for i in range(102)]
[num_list.remove(p[i]) for i in range(N)]
tmp = [0] * int(len(num_list))


for i in range(len(num_list)):
    tmp[i] = abs(num_list[i] - X)

ans = tmp.index(min[tmp])

print(num_list[ans])


### FIXED CODE ###

X, N = map(int,input().split(' '))
if N == 0:
    print(X)
    exit()

p = input().split(' ')
p =[int(i) for i in p]
if X not in p:
    print(X)
    exit()

num_list = [int(i) for i in range(102)]
[num_list.remove(p[i]) for i in range(N)]
tmp = [0] * int(len(num_list))


for i in range(len(num_list)):
    tmp[i] = abs(num_list[i] - X)

ans = tmp.index(min(tmp))

print(num_list[ans])
N,X =[int(i) for i in input().split()]
c = [int(i) for i in input().split()]

c.append(X)
c.sort()

D = float('inf')

for i in range(1,N+2):
    if c[i] - c[i-1] < D:
        D = c[i] - c[i-1]

print(int(D))

### FIXED CODE ###

import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


N,X =[int(i) for i in input().split()]
c = [int(i) for i in input().split()]

for i in range(N):
    c[i] = abs(c[i] - X)

print(gcd_list(c))
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

result = []
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i + 1) * (j + 1) * (k + 1) <= K:
                result.append(A[i] + B[j] + C[k])
            else:
                break
result.sort(reversed=True)
for rs in result[:K]:
    print(rs)

### FIXED CODE ###

x,y,z,k = map(int,input().split())
lisa = list(map(int,input().split()))
lisb = list(map(int,input().split()))
lisc = list(map(int,input().split()))
lisa.sort(reverse=True)
lisb.sort(reverse=True)
lisc.sort(reverse=True)
an = []
ans = []
for num in lisb:
    for nu in lisa:
        an.append(num+nu)
an.sort(reverse=True)
an = an[:min(3001,x*y*z+1)]
for num in lisc:
    for nu in an:
        ans.append(num+nu)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])
a, b = input().strip().split()
print(a/b)

### FIXED CODE ###

a, b = map(int, input().strip().split())
print(a/b)
print((int(input())-1)*(int(input())-1))


### FIXED CODE ###

a, b = map(int, input().split())
print((a-1)*(b-1))
a = str(input())
ans = str(upper(a))
if a = ans:
  print("A")
else:
  print("a")

### FIXED CODE ###

a = input()
ans = a.upper()
if a == ans:
  print("A")
else:
  print("a")
n = str(input())

result = n.replace('1', '2').replace('9','1').replace('2','9')

return result


### FIXED CODE ###

n = str(input())

result = n.replace('1', '2').replace('9','1').replace('2','9')

print(result)
N = int(input())
ans = 0
for i in range(4)
 a = N%10
 if a==2:
  ans += 1
 N /= 10
print(ans)


### FIXED CODE ###

N = int(input())
ans = 0
for i in range(4):
 a = N%10
 if a==2:
  ans = ans+ 1
 N /= 10
 N = int(N)
print(ans)
import numpy as np

H, N = map(int, input().split())
A, B = np.zeros(N, dtype=np.int), np.zeros(N, dtype=np.int)

for i in range(N):
    A[i], B[i] = map(int, input().split())

C = np.zeros(H+1, dtype=np.int)
min_cost_A = int(A[B.argmin()])
C[1:min_cost_A+1] = min(B)
sa = np.zeros(N, dtype=np.int)

def hoggg(C, A, B, i, N):
    for j in range(N):
        if A[j] >= i:
            sa[j] = B[j]
        else:
            sa[j] = C[i - A[j]] + B[j]
    return min(sa)

for i in range(min_cost_A, H+1):
    C[i] = hoggg(C, A, B, i, N)

print(int(C[H]))

### FIXED CODE ###

H, A = map(int, input().split())

i, m = divmod(H, A)

if m != 0:
    i += 1

print(i)
s = [input() for i in range(2)]
#出力['s_1', 's_2']

x=s[0].split(',')
y=s[1].split(',')

ans = 0
if x[0]==y[0]:
  ans += 1
  if x[1]==y[1]:
    ans += 1
    if x[2]==y[2]:
      ans += 1
print(ans)

### FIXED CODE ###

S=input()
T=input()

ans=0
for s,t in zip(S,T):
  if s==t:
    ans+=1
print(ans)
# -*- coding:utf-8 -*-

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

SUM_CARD = sum(a)

i=1

diff_sum = 0
sunuke = sum(a[0:i])
diff_sum = abs(sunuke*2-SUM_CARD)
i+=1

while(i<N):
    sunuke = sum(a[0:i])
    diff_sum_new = abs(sunuke*2-SUM_CARD)
    if diff_sum_new<diff_sum:
        diff_sum = diff_sum_new
    i += 1

print(diff_sum)


### FIXED CODE ###

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

A,B = map(int,input().split())

if (A+B)%3 == 0 or A%3==0 or B%3==0:
    print ("Possible")
else:
    print ("Impossible")
string = int().split()
print(string[1] + string[0])

### FIXED CODE ###

string = input().split()
print(string[1] + string[0])
import sys
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():
	n,k=MI()
	A=LI()
	p=[]
	m=[]
	mod=10**9+7

	for i in A:
		if i>=0:
			p.append(i)
		else:
			m.append(i)
	p.sort(reverse=True)
	m.sort()
	#print(p,m)

	ans=1
	if p==[] and k%2==1:
		for i in range(k):
			ans*=m[-i-1]
			ans%=mod
			#print(k,ans)
	else:
		i=0
		j=0
		pl=len(p)
		ml=len(m)
		while k>=2:
			if i+2<=pl and j+2<=ml:
				pp=p[i]*p[i+1]
				mm=m[j]*m[j+1]
				if pp>mm:
					ans*=pp
					ans%=mod
					i+=2
				else:
					ans*=mm
					ans%=mod
					j+=2
			elif i+2<=pl:
				pp=p[i]*p[i+1]
				ans*=pp
				ans%=mod
				i+=2
			else:
				#print(i,j)
				mm=m[j]*m[j+1]
				ans*=mm
				ans%=mod
				j+=2
			k-=2

		if k==1:
			ans*=p[i]
			ans%=mod
	print(ans)



if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():
	n,k=MI()
	A=LI()
	p=[]
	m=[]
	mod=10**9+7

	for i in A:
		if i>=0:
			p.append(i)
		else:
			m.append(i)
	p.sort(reverse=True)
	m.sort()
	#print(p,m)

	ans=1
	if (p==[] and k%2==1):
		for i in range(k):
			ans*=m[-i-1]
			ans%=mod
			#print(k,ans)

	elif n==k:
		for i in range(n):
			ans*=A[i]
			ans%=mod

	else:
		i=0
		j=0
		pl=len(p)
		ml=len(m)
		while k>=2:
			if i+2<=pl and j+2<=ml:
				pp=p[i]*p[i+1]
				mm=m[j]*m[j+1]
				if pp>mm:
					ans*=pp
					ans%=mod
					i+=2
				else:
					ans*=mm
					ans%=mod
					j+=2
			elif i+2<=pl:
				pp=p[i]*p[i+1]
				ans*=pp
				ans%=mod
				i+=2
			else:
				#print(i,j)
				mm=m[j]*m[j+1]
				ans*=mm
				ans%=mod
				j+=2
			k-=2

		if k==1:
			ans*=p[i]
			ans%=mod
	print(ans)



if __name__ == "__main__":
	main()
import math
n = int(input())
def f(n):
  g = float('inf')
  for i in [j for j in range(1,math.ceil(n**0.5))+1 if n%j == 0]:
    if g > len(str(max(i,n//i))):
      g = len(str(max(i,n//i)))
    if g == float('inf'):
        g = 1
  return g
print(f(n))

### FIXED CODE ###

import math
n = int(input())
def f(n):
  g = float('inf')
  for i in [j for j in range(1,math.ceil(n**0.5)+1) if n%j == 0]:
    if g > len(str(max(i,n//i))):
      g = len(str(max(i,n//i)))
    if g == float('inf'):
        g = 1
  return g
print(f(n))
L = input(input())
print(pow(L/3,3))


### FIXED CODE ###

L = int(input())
print(pow(L/3,3))
n=int(input())
d,x=map(int,input().split())
ans=x
a=[int(input()) for _ in range(n)]
for i in range(n):
    ans+=((d-1)//a[i])+1
print(ans)


### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
d=int(input())
print(min(a,b)+min(c,d))
N = int(raw_input())
list_input = sorted(map(int, raw_input().split()))
print(sum(list_input[::2]))

### FIXED CODE ###

N = int(raw_input())
L = map(int,raw_input().split())
L.sort(reverse = True)
ans = 0
for i in xrange(N):
    ans += min(L[2*i],L[2*i+1])
print ans
from itertools import groupby
def calc():
  s = 0
  for i in range(h):
    gr = groupby(g[i])
    j = 0
    for key,it in gr:
      l = len(list(it))
      j += l
      if key==-1: continue
      if l >= K:
        g[i][j:j+l] = [-1]*l
        # for k in range(l):
        #   g[i][j+k] = -1
        # # print("s", key, l, key*l)
        s += key*l
 
  return s

def flatten():
  for j in range(w):
    lst = []
    for i in range(h-1, -1, -1):
      if g[i][j] > 0:
        lst.append(g[i][j])

    lst += [-1] * (h - len(lst))

    for i in range(h-1, -1, -1):
      g[i][j] = lst[h-i-1]

h,w,K = map(int,input().split())
mat = [ [int(e) for e in list(input())] for _ in range(h) ]

res = 0
for i in range(h):
  for j in range(w):
    score = 0
    g = [ [ mat[n][m] for m in range(w) ] for n in range(h) ]
    g[i][j] = -1
    time = 0
    flatten()
    while True:
      s = calc(time)
      if s==0: break
      score += s
      flatten()
      time += 1
    res = max(res, score)

print(res)

### FIXED CODE ###

from itertools import groupby

def calc(time):
  t = 0
  for i in range(h):
    gr = groupby(g[i])
    lst = []
    p = 0
    for key,it in gr:
      j = len(list(it))
      lst.append([p,key,j])
      p += j
    for j in range(len(lst)):
      if lst[j][1] == -1:
        continue
      if lst[j][2] >= K:
        t += (2**time)*lst[j][1]*lst[j][2]
        for k in range(lst[j][0],lst[j][0]+lst[j][2]):
          g[i][k] = 0

  return t

def flatten():
  for j in range(w):
    lst = []
    for i in range(h-1, -1, -1):
      if g[i][j] > 0:
        lst.append(g[i][j])

    lst += [-1] * (h - len(lst))

    for i in range(h-1, -1, -1):
      g[i][j] = lst[h-i-1]

h,w,K = map(int,input().split())
mat = [ [int(e) for e in list(input())] for _ in range(h) ]

res = 0
for i in range(h):
  for j in range(w):
    score = 0
    g = [ [ mat[n][m] for m in range(w) ] for n in range(h) ]
    g[i][j] = -1
    time = 0
    flatten()
    while True:
      s = calc(time)
      if s==0: break
      score += s
      flatten()
      time += 1
    res = max(res, score)

print(res)
a,s=map(int,input().split())
A=0
for i in range(a,b+1):
  if str(i)==str(i)[::-1]:A+=1
print(A)

### FIXED CODE ###

a,b=map(int,input().split())
ans=0
for i in range(b+1)[a:]:
  if len(str(i))%2==0:
    p=list(str(i))[:len(str(i))//2]
    q=list(reversed(list(str(i))[len(str(i))//2:]))
    if p==q:
      ans+=1
  else:
    s=list(str(i))[:len(str(i))//2+1]
    d=list(reversed(list(str(i))[len(str(i))//2:]))
    if s==d:
      ans += 1
print(ans)
N = int(input())
S = input()
K = int(input())
T = ""
for s in S:
  if s == S[K]:
    T += s
  else:
    T += "*"
print(T)

### FIXED CODE ###

N = int(input())
S = input()
K = int(input())
t = S[K-1]
ans = ""
for s in S:
  if s == t:
    ans += s
  else:
    ans += "*"
print(ans)
d1 = 24 - M
ans = d1 + 24
print ans

### FIXED CODE ###

M = input()
print 48-M
a,b,x = list(map(int,input().split()))

import math

if x*2 > b:
    y = 0
    y = 2*x/(a**2)-b

    print(90-math.degrees(math.atan(a/(b-y))))
else:
    y = 0
    y = 2*x/(a*b)

    print(90-math.degrees(math.atan(y/b)))

### FIXED CODE ###

import math
a,b,x=list(map(int,input().split()))
maxv=a*a*b
sukima=maxv-x
teimenseki=sukima/a
y=teimenseki*2/a
 
if x > (maxv/2):
    print(math.degrees(math.atan(y/a)))
else:
    tei=x/a
    z=tei*2/b
    print(math.degrees(math.atan(b/z)))
N = int(input())
a = [input() for i in range(N)]

output = int(max(a)) - int(min(a))
print(output)

### FIXED CODE ###

N = int(input())
data = input().split()

output = int(max(data)) - int(min(data))
print(output)
a = input()
if a[2] == a[3] && a[4] == a[5]:
  print(Yes)
else:
  print(No)

### FIXED CODE ###

a = input()
if (a[2] == a[3]) & (a[4] == a[5]):
  print("Yes")
else:
  print("No")
import math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = math.fabs(sqrt((x[0]-x[3])**2 - (x[1]-x[4])**2))
	s = x[2]+x[5]
	r = math.fabs(x[2]-x[5])
	if r >= d:
		if x[2] > x[5]:
			answers.append(2)
		else:
			answers.append(-2)
	elif s < d:
		answers.append(0)
	else:
		answers.append(1)
for val in answers:
	print val

### FIXED CODE ###

import math
N = input()
answers = []
for val in range(1,N+1):
	x = map(float,raw_input().split(' '))
	d = (x[0]-x[3])**2 + (x[1]-x[4])**2
	d = math.sqrt(d)
	d = math.fabs(d)
	s = x[2]+x[5]
	r = math.fabs(x[2]-x[5])
	if d > s:
		answers.append(0)
	elif d == s:
		answers.append(1)
	elif d < s:
		if d < r:
			if x[2] > x[5]:
				answers.append(2)
			else:
				answers.append(-2)
		elif d >= r:
			answers.append(1)
for val in answers:
	print val
# coding: utf-8

list = [int(i) for i in input().rstrip().split(" ")]

matsu_count = list[0]
require = sorted(list[1:])

matsu_list = sorted([int(input().rstrip()) for i in range(matsu_count)])

def get_mp(matsu:list):
    ans = 0
    for i in range(3):
        ans += abs(matsu[i] - require[i])
    return ans
mp = {}
def get_ans(matsu:list):
    if len(matsu) == 3:
        return get_mp(matsu)
    key = "#".join(matsu)
    if key in mp:
        return mp[key]
    ans = 80000
    for i in range(len(matsu) - 3 + 1):
        ans = min(ans, get_mp(matsu[i:]))
    for i in range(len(matsu)):
        for j in range(i + 1, len(matsu)):
            sub_matsu = []
            for k in range(len(matsu)):
                if k == i or k == j:
                    continue
                else:
                    sub_matsu.append(matsu[k])
            sub_matsu.append(matsu[i] + matsu[j])
            ans = min(ans, get_ans(sorted(sub_matsu)) + 10)

    mp[key] = ans
    return ans

ans = get_ans(matsu_list)
print(ans)



### FIXED CODE ###

# coding: utf-8

list = [int(i) for i in input().rstrip().split(" ")]

matsu_count = list[0]
require = sorted(list[1:])

matsu_list = sorted([int(input().rstrip()) for i in range(matsu_count)])

def get_mp(matsu:list):
    ans = 0
    for i in range(3):
        ans += abs(matsu[i] - require[i])
    return ans
mp = {}

def get_ans(matsu:list):
    if len(matsu) == 3:
        return get_mp(matsu)
    key = "#".join(map(str, matsu))
    if key in mp:
        return mp[key]
    ans = 80000
    for i in range(len(matsu) - 3 + 1):
        for j in range(i + 1, len(matsu) - 2 + 1):
            for k in range(j + 1, len(matsu) - 1 + 1):
                ans = min(ans, get_mp([matsu[i],matsu[j], matsu[k]]))
    if ans > 0:
        for i in range(len(matsu)):
            for j in range(i + 1, len(matsu)):
                sub_matsu = []
                for k in range(len(matsu)):
                    if k == i or k == j:
                        continue
                    else:
                        sub_matsu.append(matsu[k])
                sub_matsu.append(matsu[i] + matsu[j])
                ans = min(ans, get_ans(sorted(sub_matsu)) + 10)

    mp[key] = ans
    return ans

ans = get_ans(matsu_list)
print(ans)
A,B = map(int, input().split())
print('Possible' if (A % 3 or B % 3 or (A + B) % 3) in 0 else 'Impossible')

### FIXED CODE ###

A,B = map(int, input().split())
print('Possible' if (A % 3 == 0) or (B % 3 == 0) or ((A + B) % 3 == 0) else 'Impossible')
n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))

l_list=[]
r_list=[0]
ctr1=0
ctr2=0
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        ctr1+=1
        l_list.append(ctr1)
        ctr2+=1
        r_list.append(ctr2)
    else:
        l_list.append(ctr1)
        r_list.append(ctr2)

for i in range(q):
    left=lr[i][0]
    right=lr[i][1]
    print(r_list[right-1]-l_list[left]+1)


### FIXED CODE ###

n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))
ctr1=0
t_list=[0]
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        ctr1+=1
        t_list.append(ctr1)
    else:
        t_list.append(ctr1)

for i in range(q):
    left=lr[i][0]
    right=lr[i][1]
    print(t_list[right-1]-t_list[left-1])
from random import randint
l = list(map(int, input().split()))
ans = 0
for i in range (len(a) - 1) :
  if l[i] == l[i + 1]:
    ans += 1
    l[i + 1] = randint(0, 10000)
print(ans)

### FIXED CODE ###

from random import randint
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range (len(l)-1) :
  try:
    if l[i] == l[i + 1]:
        ans += 1
        l[i + 1] = randint(0, 10000)
  except:
    continue
print(ans)
mod = 10**9 + 7
n = int(input())
lst = list(map(int, input().split()))
koubai = lst[0]
def gcd(a, b):
    if a > b:
        a, b = b, a
    while b > 0:
        a, b = b, a % b
    return a
for i in range(1, n):
    koubai = koubai*lst[i]//gcd(koubai, lst[i])
 
total = 0
for l in lst:
    b += koubai//l

print(total%mod)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
lcm = a[0]

def gcd(a, b):
    if a > b:
        a, b = b, a
    while b > 0:
        a, b = b, a % b
    return a

for i in range(1, n):
    lcm = lcm * a[i] // gcd(lcm, a[i])
mod = 10**9 + 7
ans = 0
for i in range(n):
    ans += lcm // a[i]
print(ans % mod)
a = list(map(int, input().split()))
N = a[0]
M = a[1]

Array = [list(map(int, input().split())) for _ in range(M)]

i = 0
hya = 0
jyu = 0
ich = 0
while i < 3:
    if Array[i][0] == 1:
        hya = Array[i][1]
    elif Array[i][0] == 2:
        jyu = Array[i][1]
    elif Array[i][0] == 3:
        ich = Array[i][1]
    i += 1

for i in range(M):
    for j in range(i+1, M):
        if Array[i][0] == Array[j][0]:
            if Array[i][1] != Array[j][1]:
                print(-1)
            else:
                print(hya, jyu, ich, sep="")

### FIXED CODE ###

n = []

N, M = list(map(int, input().split()))
for i in range(N):
    n.append('W')

for i in range(M):
    s, c = list(map(int, input().split()))
    s -= 1
    if n[s] == "W":
        n[s] = c
    elif n[s] == c:
        pass
    else:
        print(-1)
        exit()
        
if N != 1:
    if n[0] == 0:
        print(-1)
        exit()
    
    if n[0] == "W":
        n[0] = 1
        
    for i in range(N):
        if n[i] =="W":
            n[i] = 0

else:
    if n[0] == "W":
        n[0] = 0
        
print(''.join(map(str,n)))
from collections import deque

h, w = map(int, input().split())
a = [input() for _ in range(h)]

d = [[-1] * w for _ in range(h)]


def bfs():
    s = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                s.append([i, j])

    q = deque()
    for sx, sy in s:
        q.append([sx, sy])
        d[sy][sx] = 0
    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy
            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and \
                    a[vy][vx] == "." and d[vy][vx] == -1:
                d[vy][vx] = d[uy][ux] + 1
                q.append([vx, vy])


bfs()

ans = 0
for row in d:
    for e in row:
        ans = max(ans, e)

print(ans)


### FIXED CODE ###

from scipy.ndimage import distance_transform_cdt


def main():
    h, w = map(int, input().split())
    a = [list(input()) for _ in range(h)]

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()
for i in range(n):
  if i%3==0 or i%10==3:
    print ' %d' % i

### FIXED CODE ###

import sys
n = input()
for i in range(1,n+1):
  x = i
  if x%3==0:
    sys.stdout.write(' %d' % i)
    continue
  while x<=n:
    if x%10==3:
      sys.stdout.write(' %d' % i)
      break
    else:
      x /= 10
      if x==0:
        break
sys.stdout.write('\n')
L, N = map(int, input().split())
S = [input() for i in range(N)]
S.sort()
ans = '';
for j in range(N):
    ans += S[j]
print(ans)


### FIXED CODE ###

n,l = map(int,input().split())
A = [input() for _ in range(n)]
A.sort()
ans = ''
for i in range(n):
    ans += A[i]
 
print(ans)