Harryxun/stf_run huggingface dataset:
def search(x, num):
    nodes.remove(x)
    for y in edge[x]:
        edge[y].discard(x)
    for y in list(edge[x]):
        if y in nodes:
            num = search(y, num)
    return num + 1

(n,m),*d  = [list(map(int, s.split())) for s in open(0)]

edge = [set() for _ in range(n+1)]
for x in d:
    edge[x[0]].add(x[1])
    edge[x[1]].add(x[0])

nodes = set(range(1,n+1))
ans = 1
for x in list(nodes):
    if x in nodes:
        ans = max(ans, search(x, 0))
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(int(1e6))

def search(x, num):
    nodes.remove(x)
#     for y in edge[x]:
#         edge[y].discard(x)
#     for y in list(edge[x]):
    for y in edge[x]:
        if y in nodes:
            num = search(y, num)
    return num + 1

(n,m),*d  = [list(map(int, s.split())) for s in open(0)]

edge = [set() for _ in range(n+1)]
for x in d:
    edge[x[0]].add(x[1])
    edge[x[1]].add(x[0])

nodes = set(range(1,n+1))
ans = 1
for x in list(nodes):
    if x in nodes:
        ans = max(ans, search(x, 0))
print(ans)
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    a = ILI()
    return (N, a)

def solve(N, a):
    a_lef = a[0:N]
    a_mid = a[N:2 * N]
    a_rig = a[2 * N : 3 * N]
    heapq.heapify(a_lef)
    heapq._heapify_max(a_rig)

    i_lef = 0
    i_rig = N - 1

    for __ in range(N):
        n_lef = a_lef[0] * -1 + a_mid[i_lef]
        n_rig = a_rig[0] - a_mid[i_rig]
        if n_lef >= n_rig:
            heapq.heappop(a_lef)
            heapq.heappush(a_lef, a_mid[i_lef])
            i_lef += 1
        else:
            heapq._heapreplace_max(a_rig, a_mid[i_rig])
            i_rig -= 1

    ans = sum(a_lef) - sum(a_rig)
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


### FIXED CODE ###

# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    a = ILI()
    return (N, a)


def solve(N, a):
    a_lef = a[0: N]
    a_rig = [-i for i in a[2 * N: 3 * N]]
    heapq.heapify(a_lef)
    heapq.heapify(a_rig)
    sum_lef = sum(a_lef)
    sum_rig = sum(a_rig)
    l_sum_lef = [sum_lef]
    l_sum_rig = [sum_rig]
    
    for i in range(1, N + 1):
        heapq.heappush(a_lef, a[N - 1 + i])
        lef_pop = heapq.heappop(a_lef)
        sum_lef += a[N - 1 + i] - lef_pop
        l_sum_lef.append(sum_lef)
        
        heapq.heappush(a_rig, -a[2 * N - i])
        rig_pop = heapq.heappop(a_rig)
        sum_rig += -a[2 * N - i] - rig_pop
        l_sum_rig.append(sum_rig)

    ans = -INF

    for i in range(N + 1):
        num_dif = l_sum_lef[i] + l_sum_rig[N - i]
        ans = max(ans, num_dif)

    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()
def rally():
    N=input()
    X=list(map(int,input().split()))
    dispersion=[]
    cnt=0
    for i in range(min(X),max(X)):
        for j in X:
            cnt+=abs(j-i)**2
        dispersion.append(cnt)
        cnt=0
    print(min(dispersion))

rally()


### FIXED CODE ###

N=int(input())
X=list(map(int,input().split()))
dispersion=[]
cnt=0
for i in range(100):
    for j in range(N):
        cnt+=abs(X[j]-i)**2
    dispersion.append(cnt)
    cnt=0
print(min(dispersion))
N = int(input())
H = list(map(int, input().split()))
def move_right(i):
    count = 0
    for j in range(i, N-1):
        if H[j+1]<=H[j]:
            count += 1
        else:
            break
    return count
A = [move_right(i) for i in range(N-1)]
print(max(A))

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
count = 0
answer = 0
for j in range(N-1):
    if H[j+1] <= H[j]:
        count += 1
    else:
        answer = max(count, answer)
        count = 0
answer = max(count, answer)
print(answer)
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = LIST()
S = input()

# stand = []
# reverse = []
# state = None
# count = 0
# tmp = None
# for i in S:
# 	if i == "0":
# 		state = "stand"
# 	else:
# 		state = "reverse"
# 	if tmp == "stand" and state == "reverse":
# 		stand.append(count)
# 		count = 1
# 	elif tmp == "reverse" and state == "stand":
# 		reverse.append(count)
# 		count = 1
# 	else: # 状態が前と同じ
# 		count += 1
# 	tmp = state
# if state == "stand":
# 	stand.append(count)
# else:
# 	reverse.append(count)

# if "0" not in S:
# 	print(len(S))
# else:
# 	if K >= len(stand): # 全員逆立ちにできる
# 		print(len(S))
# 	else:
# 		if len(stand) > len(reverse):
# 			reverse.append(0)
# 			reverse.insert(0, 0)
# 		if len(stand) == len(reverse) and S[0] == "0":
# 			reverse.insert(0, 0)
# 		if len(stand) == len(reverse) and S[0] == "1":
# 			reverse.append(0)
# 		# print(stand)
# 		# print(reverse)
# 		max_ = 0
# 		for i in range(max(1, 1+len(reverse)-(K+1))):
# 			# print(reverse[i:i+K+1],stand[i:i+K])
# 			tmp = sum(reverse[i:i+K+1]+stand[i:i+K])
# 			if tmp > max_:
# 				max_ = tmp
# 		print(max_)

indexes = []
tmp = ""
for i in range(len(S)):
	if S[i] == "0":
		state = "stand"
	else:
		state = "reverse"
	if tmp != state:
		indexes.append(i)
	else: # 状態が前と同じ
		pass
	tmp = state
indexes.append(N)
ans = []
# print(indexes)
for i in range(len(indexes)):
	# print(i)
	if S[indexes[i]] == "0":
		if i+2*K >= len(indexes):
			pass
		ans.append(indexes[i+2*K]-indexes[i])
	else:
		if i+2*K+1 >= len(indexes):
			pass
		ans.append(indexes[i+2*K+1]-indexes[i])
if ans == []:
	print(len(S))
else:
	print(max(ans))

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A, B = MAP()

print(max(A+A-1,A+B, B+B-1))
x= int(input())
y = round(x/2)
return y/x

### FIXED CODE ###

n = int(input())
if n%2==0:
    print(str((n/2)/n))
else:
    print(str(((n+1)/2)/n))
def power2(n):
    i=1
    while n>0:
        i*=2
        n-=1
    return i

i=0
n=input()
while power2(i)<=n:
    i=i+1
    
print(power2(i-1))

### FIXED CODE ###

import logging
logging.basicConfig(level=logging.CRITICAL,format=' %(asctime)s - %(levelname)s - %(message)s')

def power(n):
    i = 1
    logging.info('func start')
    while n > 0:
        i *= 2
        n -= 1
        logging.debug('i = {}, n = {}'.format(i,n))
    logging.info('func end')
    return i

i = 0
n = int(input())
logging.info('in loop')
while not (power(i + 1) > n):
    i = i + 1
    logging.debug('i = {}, pow(i) = {}'.format(i,power(i)))

logging.info('out loop')
print(power(i ))
n,k = map(int,input().split())
a = list(map(int,input().split()))

ok = max(a)
ng = 0
for _ in range(50):
    mid = (ok+ng)//2
    cnt = 0
    for ai in a:
        cnt += (ai-1)//mid
    if(cnt <= k):
        ok = mid
    else:
        ng = mid

print(ok)

### FIXED CODE ###

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

ok = max(a)
ng = 0
for _ in range(50):
    mid = (ok+ng)//2
    if(mid==0):
        print(1)
        exit()
    cnt = 0
    for ai in a:
        cnt += (ai-1)//mid
    if(cnt <= k):
        ok = mid
    else:
        ng = mid

print(ok)
n=int(input())
l=list(map(int,input().split()))
a=[0]*(10**6+1)
for i in range(n):
    if(a[l[i]]==0):
       for j in range(2*l[i],10**6+1,l[i]):
           a[j]=2
    a[l[i]]+=1
print(a.count(1))       


### FIXED CODE ###

a,b,c,d,e=map(int,input().split())
if(a==0):
    print(1)
if(b==0):
    print(2)
if(c==0):
    print(3)
if(d==0):
    print(4)
if(e==0):
    print(5)
H, W = map(int, input().split())
X = [[[0, 1][a=="#"] for a in input()] for i in range(H)]
def countRD(n, i, j):
    return ccc(n, i, j, 1, 1)
def countRU(n, i, j):
    return ccc(n, i, j, -1, 1)
def countLD(n, i, j):
    return ccc(n, i, j, 1, -1)
def countLU(n, i, j):
    return ccc(n, i, j, -1, -1)
def countR(n, i, j):
    return cc(n, i, j, 0, 1)
def countL(n, i, j):
    return cc(n, i, j, 0, -1)
def countD(n, i, j):
    return cc(n, i, j, 1, 0)
def countU(n, i, j):
    return cc(n, i, j, -1, 0)
def ccc(n, i, j, DU, RL):
    c = 0
    for k in range(1, n):
        if i+k*DU >= 0 and i+k*DU < H:
            if j+(n-k)*RL >= 0 and j+(n-k)*RL < W:
                c += X[i+k*DU][j+(n-k)*RL]
    return c
def cc(n, i, j, DU, RL):
    ret = 0
    if i+n*DU >= 0 and i+n*DU < H:
        if j+n*RL >= 0 and j+n*RL < W:
            ret = X[i+n*DU][j+n*RL]
    return ret

ans = 0
for i in range(H):
    for j in range(W):
        for n in range(1, min(max(i+j,H-i+W-j), max(i+W-j,H-i+J))+2):
            if countR(n, i, j) and countD(n, i, j):
                ans += countLU(n, i, j)
            if countR(n, i, j) and countU(n, i, j):
                ans += countLD(n, i, j)
            if countL(n, i, j) and countD(n, i, j):
                ans += countRU(n, i, j)
            if countL(n, i, j) and countU(n, i, j):
                ans += countRD(n, i, j)
            if countR(n, i, j) and countD(n, i, j) and countL(n, i, j):
                ans += 1
            if countR(n, i, j) and countD(n, i, j) and countU(n, i, j):
                ans += 1
            if countR(n, i, j) and countU(n, i, j) and countL(n, i, j):
                ans += 1
            if countD(n, i, j) and countU(n, i, j) and countL(n, i, j):
                ans += 1
            
            
print (ans)





### FIXED CODE ###

H, W = map(int, input().split())
I = [input() for _ in range(H)]
X = [[[0, 1][a=="#"] for a in inp] for inp in I]
k = 32
def r():
    global H, W, I
    I = ["".join([I[H - 1 - j][i] for j in range(H)]) for i in range(W)]
    H, W = W, H
def st1(s):
    return int(s.replace("#", "1" * k).replace(".", "0" * k), 2)
def st2(s):
    return int(s.replace("#", "0" * (k - 1) + "1").replace(".", "0" * k), 2)
def getsum(x):
    for i in range(8):
        x += x >> (k << i)
    return x & ((1 << k) - 1)

ans = 0
for _ in range(4):
    A1 = [st1(inp) for inp in I]
    A2 = [st1("".join([I[i][j] for i in range(H)])) for j in range(W)]
    B = [st2(inp[::-1]) for i, inp in enumerate(I)]
    C = [[0] * W for _ in range(H)]
    for j in range(W):
        s = 0
        m = (1 << j * k) - 1
        for i in range(H)[::-1]:
            s <<= k
            s += B[i] >> (j+1) * k
            s &= m
            C[i][j] = s
    for i in range(1, H):
        for j in range(1, W):
            ans += A1[i] >> (W - j) * k & A2[j] >> (H - i) * k & C[i][j]
    r()
            
print(getsum(ans))
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))
for i in range(n):
	for k in range(len(d)):
		if len(t) == 0:
			answer = 1
			break
		elif t[0] == d[k]:
			del d[k]
			del t[0]
			break
if answer == 1:
	print('YES')
else:
	print('NO')

### FIXED CODE ###

import collections
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))
dcounter = collections.Counter(d)
tcounter = collections.Counter(t)
check = True
for i in tcounter.items():
	if dcounter[i[0]] < i[1]:
		check = False
if check:
	print('YES')
else:
	print('NO')
import math
n, x = list(map(int, input().split()))
list = list(map(int, input().split()))
list = [abs(i - x) for i in list]
min = min(list)
for num in list:
    min = math.gcd(min, num)
print(min)

### FIXED CODE ###

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

n, x = list(map(int, input().split()))
list = list(map(int, input().split()))
list = [abs(i - x) for i in list]
min = min(list)
for num in list:
    min = gcd(min, num)
print(min)
N = int(input())
X = input()
ones = X.count('1')
Xd = int(X, 2)

from functools import lru_cache

@lru_cache(maxsize=None)
def f(i):
	if i == 0: return 0

	return 1 + f(i % popcount(i))

def popcount(x):
      b=0
      while(x > 0):
          x &= x - 1
          b+=1
      return b

for i in range(N):
	div = ones + 1 if X[i] == '0' else ones - 1
	print(1 + f((Xd ^ (1 << (N-i-1))) % div))


### FIXED CODE ###

import sys
sys.setrecursionlimit(1<<30)

N = int(input())
X = input()
ones = X.count('1')

v1 = 0
v2 = 0
m1 = ones + 1
m2 = ones - 1
p1 = 1 % m1
p2 = 1

for i, v in enumerate(reversed(X)):
	if v == '1':
		v1 = (v1 + p1) % m1

		if m2 > 0:
			v2 = (v2 + p2) % m2

	p1 = p1 * 2 % m1
	if m2 > 0:
		p2 = p2 * 2 % m2

from functools import lru_cache

@lru_cache(maxsize=None)
def f(i):
	if i == 0: return 0

	return 1 + f(i % popcount(i))

def popcount(x):
      b=0
      while(x > 0):
          x &= x - 1
          b+=1
      return b


for i in range(N):
	div = ones + 1 if X[i] == '0' else ones - 1
	if div == 0:
		print(0)
	elif div == 1:
		print(1)
	else:

		if div == m1:
			x = (v1 + pow(2, N-i-1, m1)) % m1
		elif div == m2:
			x = (v2 - pow(2, N-i-1, m2)) % m2
		else:
			assert False

		#print(x, (int(X, 2) ^ (1 << (N-i-1))) % div, div)

		print(1 + f(x))
n,a,b=map(int,input().split())

if n*a >= b:
  ptiny(b)
else:
  print(n*a)

### FIXED CODE ###

n,a,b=map(int,input().split())
 
if n*a >= b:
  print(b)
else:
  print(n*a)
n=int(input())
x=[]
for i in range(n):
    t=int(input())
    x.append(t)


ans=x[0]
for j in range(1,len(x)):
    ans=ans*x[j]//fractions.gcd(ans,x[j])

print(ans)


### FIXED CODE ###

import fractions

n=int(input())
x=[]
for i in range(n):
    t=int(input())
    x.append(t)


ans=x[0]
for j in range(1,len(x)):
    ans=ans*x[j]// fractions.gcd(ans,x[j])

print(ans)
n=int(input())
print("Hello World" if n==1)
print(int(input())+int(input()))


### FIXED CODE ###

n=int(input())
if n==1:print("Hello World")
else:print(int(input())+int(input()))
n,m=map(int,input().split())


xyz=[tuple(map(int, input().split())) for _ in range(n)]

#m個食べる
#abs(sum(x))+abs(sum(y))+abs(sum(z))の最大化

#i個中m個食べた時の、最小のxyz
#dp[i][m][0]=(x,y,z)
#i個中m個食べた時の、最大のxyz
#dp[i][m][1]=(x,y,z)

dp=[[[(0,0,0)]*8 for _ in range(m+1)] for _ in range(n)]

for k in range(8):
    dp[0][1][k]=xyz[0]
    dp[0][1][k]=xyz[0]

#- + +
#- - +
#- - - 
#+ + +
#+ - +
#+ - -
#+ + -
#- + -  で最強を目指せば良い

kk=[]
for i in [1,-1]:
    for j in [1,-1]:
        for k in [1,-1]:
            kk.append((i,j,k))

for i in range(1,n):
    for j in range(1,m+1):
        for k in range(8):
            bk=0
            now=0
            for ind in range(3):
                #print(i,j,k,ind,dp)
                #print(kk)
                #print(i,j,k,ind)
                #print(dp[i-1][j][k])
                #print(dp[i-1][j][k][ind])
                #print("kk",kk[k][ind])
                bk+=dp[i-1][j][k][ind]*kk[k][ind]
                now+=dp[i-1][j-1][k][ind]*kk[k][ind]+xyz[i][ind]*kk[k][ind]
            if abs(bk)>abs(now):
                dp[i][j][k]=dp[i-1][j][k]
            else:
                x=dp[i-1][j-1][k][0]*kk[k][ind]+xyz[i][0]*kk[k][0]
                y=dp[i-1][j-1][k][1]*kk[k][ind]+xyz[i][1]*kk[k][1]
                z=dp[i-1][j-1][k][2]*kk[k][ind]+xyz[i][2]*kk[k][2]
                dp[i][j][k]=(x,y,z)

        """
        #最小値
        x=min(dp[i-1][j-1][0][0]+xyz[j][0],dp[i-1][j][0][0])
        y=min(dp[i-1][j-1][0][1]+xyz[j][1],dp[i-1][j][0][1])
        z=min(dp[i-1][j-1][0][2]+xyz[j][2],dp[i-1][j][0][2])
        dp[i][j][0]=(x,y,z)
        #最大値
        x=max(dp[i-1][j-1][1][0]+xyz[j][0],dp[i-1][j][1][0])
        y=max(dp[i-1][j-1][1][1]+xyz[j][1],dp[i-1][j][1][1])
        z=max(dp[i-1][j-1][1][2]+xyz[j][2],dp[i-1][j][1][2])
        dp[i][j][1]=(x,y,z)
        """

ans=0
for item in dp[-1][-1]:
    #print(item)
    ans=max(ans,abs(item[0])+abs(item[1])+abs(item[2]))

print(ans)

### FIXED CODE ###

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

xyz=[tuple(map(int, input().split())) for _ in range(n)]
kk=[]
for i in [1,-1]:
    for j in [1,-1]:
        for k in [1,-1]:
            kk.append((i,j,k))

ans=[[] for _ in range(8)]

for (x,y,z) in xyz:
    for i,k in enumerate(kk):
        ans[i].append(x*k[0]+y*k[1]+z*k[2])

result=0

for i in range(8):
    ans[i].sort(reverse=True)
    #print(sum(ans[i][:m]))
    result=max(result,sum(ans[i][:m]))

print(result)
a8, a10 = input().split(' ')
a8 = int(a8)
a10 = int(a10)
 
value1 = int(a8 / 0.08)
value2 = int(a10 / 0.1)
if int(value1 * 0.1) == a10:
  print(value1)
elif int(value2 * 0.08 == a8):
  print(value2)
else:
  print(-1)

### FIXED CODE ###

s = input()

if 'A' in s and 'B' in s:
  print('Yes')
else:
  print('No')
A, B = map(int, raw_input().split())

return A*B if A <= 9 and B <= 9 else -1

### FIXED CODE ###

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

print A*B if A <= 9 and B <= 9 else -1
n, d = (int(i) for i in input().split())
num = list((list(map(int, input().split())) for j in rage(n)))
sum = 0
cnt = 0
for k in range(n - 1) :
  for h in range(d) :
    sum += (num[k][h] - num[k + 1][n])**2
  if (isinstance(sum **(1 / 2)), int) :
    cnt += 1
  sum = 0
print(sum)

### FIXED CODE ###

n, d = (int(i) for i in input().split())
num = list((list(map(int, input().split())) for j in range(n)))
sum = 0
cnt = 0
for k in range(n - 1) :
  for t in range(k + 1, n) :
    for h in range(d) :
      sum += (num[k][h] - num[t][h])**2
    work = sum**(1 / 2)
    temp = work * 10
    temp = temp % 10
    if temp == 0 :
      cnt += 1
    sum = 0
print(cnt)
from collections import deque
h,w=map(int,input().split())
c=[list(input()) for _ in range(h)]
dhdw = [[-1,0],[1,0],[0,-1],[0,1]]
min_dis=[[-1]*w for _ in range(h)]
que=deque()
def bfs(x,y):
  que.append([x,y])
  min_dis[x][y]=0
  while que:
    sh,sw=que.popleft()
    for dh,dw in dhdw:
      nh,nw = sh+dh,sw+dw
      if not(0<=nh<=h-1) or not(0<=nw<=w-1) or min_dis[nh][nw]!=-1 or c[nh][nw]=='#':
        continue
      min_dis[nh][nw]=min_dis[sh][sw]+1
      que.append([nh,nw])
      if [nh,nw]==[h-1,w-1]:
        return min_dis[sh][sw]+1
a=bfs(0,0) or ans-2
ans=0
for i in c:
  ans+=i.count(".")
print(ans-1-a)

### FIXED CODE ###

from collections import deque
def bfs():
  d=[[float("inf")]*m for _ in range(n)]
  dx=[1,0,-1,0]
  dy=[0,1,0,-1]
  
  que=deque([])
  que.append((0,0))
  d[0][0]=0

  while que:
    p = que.popleft()
    if p[0]==n-1 and p[1]==m-1:
      break
    for i in range(4):
      nx=p[0]+dx[i]
      ny=p[1]+dy[i]
      if 0 <= nx < n and 0 <= ny < m and c[nx][ny] != "#" and d[nx][ny] == float("inf"):
                # 移動できるならキューに入れ、その点の距離を p からの距離 +1 で確定する
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
  return d[n-1][m-1]

n, m = map(int, input().split())
c = [list(input()) for i in range(n)]

count=0
for i in range(n):
  for j in range(m):
    if c[i][j]=="#":
      count+=1
g=bfs()
if 0<g<float("inf"):
  print(n*m-g-1-count)
else:
  print(-1)
N, D = map(int, input().split())
count = 0
for i in range(N):
    x, y = map(int, input().split())
    if x^2+y^2 <= D^2:
      count += 1
return count

### FIXED CODE ###

N, D = map(int, input().split())
count = 0
for i in range(N):
    x, y = map(int, input().split())
    if x*x + y*y <= D*D:
      count += 1
print(count)
h,w=map(int,input().split())
s=[list(input()) for i in range(w)]
inf = h*w
d=[[inf]*h for i in range(w)]
if s[0][0]=="#":
    d[0][0]=1
else:
    d[0][0]=0
for j in range(1,h):
    if s[0][j]=="#" and s[0][j-1]==".":
        d[0][j]=d[0][j-1]+1
    else:
        d[0][j]=d[0][j-1]

for i in range(1,w):
    if s[i][0]=="#" and s[i-1][0]==".":
        d[i][0]=d[i-1][j]+1
    else:
        d[i][0]=d[i-1][0]

for i in range(1,w):
    for j in range(1,h):
        if s[i][j]=="#" and s[i][j-1]==".":
            p=d[i][j-1]+1
        else:
            p=d[i][j-1]
        if s[i][j]=="#" and s[i-1][j]==".":
            q=d[i-1][j]+1
        else:
            q=d[i-1][j]
        d[i][j]=min(p,q)
# for i in d:
#     print(i)
print(d[-1][-1])

### FIXED CODE ###

h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
inf = h*w
d=[[inf]*w for i in range(h)]
if s[0][0]=="#":
    d[0][0]=1
else:
    d[0][0]=0
for j in range(1,w):
    if s[0][j]=="#" and s[0][j-1]==".":
        d[0][j]=d[0][j-1]+1
    else:
        d[0][j]=d[0][j-1]

for i in range(1,h):
    if s[i][0]=="#" and s[i-1][0]==".":
        d[i][0]=d[i-1][0]+1
    else:
        d[i][0]=d[i-1][0]

for i in range(1,h):
    for j in range(1,w):
        if s[i][j]=="#" and s[i][j-1]==".":
            p=d[i][j-1]+1
        else:
            p=d[i][j-1]
        if s[i][j]=="#" and s[i-1][j]==".":
            q=d[i-1][j]+1
        else:
            q=d[i-1][j]
        d[i][j]=min(p,q)
# for i in d:
#     print(i)
print(d[-1][-1])
r, c = [int(i) for i in input().split()]

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input.split()])
    data[ri].append(sum(data[ri]))
    print(" ",join(data[str(d) for d in data[ri]]))
    for ci in renge(c + 1):
        sum_row[ci] += data[ri][ci]

print(" ".join([str(s)for s in sum_row]))

### FIXED CODE ###

(r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
    row = [int(i) for i in input().split()]
    row.append(sum(row))
    src.append(row)
 
last_row = [0 for _ in range(c + 1)]
for rc in range(r):
    for cc in range(c+1):
        last_row[cc] += src[rc][cc]
 
src.append(last_row)
 
 
for rc in range(r + 1):
    print(' '.join([str(a) for a in src[rc]]))
x1, y1, x2, y2 = map(int, input().split())
diff_x, diff_y = x2 - x1, y2 - y1
print('%s %s %s %s'%(x2 - diff_y, y2 + diff_x, x1 - diff_y, y1 + diff_x))



### FIXED CODE ###

k = int(input())
if k % 2 == 0:
    print( (k // 2) * (k // 2 ))
else:
    print( ((k - 1) // 2 + 1) * ((k - 1) // 2) )
r, g = map(int, input().split())
print(2*g-r)

### FIXED CODE ###

r=int(input())
g=int(input())
print(2*g-r)
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


a = input()
k = inp()
i = 0
while a[i] == '1':
    i += 1

if i >= k:
    print(1)
elif len(a) == i:
    print(1)
else:
    print(a[i])


### FIXED CODE ###

# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


a = input()
k = inp()
i = 0
while i < len(a) and a[i] == '1':
    i += 1

if i >= k:
    print(1)
elif len(a) == i:
    print(1)
else:
    print(a[i])