Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03272 (python)

Fixed submission:
print((lambda a:a[0]-a[1]+1)(list(map(int,input().split()))))

Buggy submission (verdict: Runtime Error):
print(int(input())-int(input())+1)
Problem p02549 (python)

Fixed submission:
def resolve():
    n, k = map(int, input().split())
    mod = 998244353
    dp = [0] * (3*n)
    imos = [0] * (3*n)
    lr = []
    for i in range(k):
        l, r = map(int, input().split())
        lr.append((l, r+1))
    for l, r in lr:
        imos[l] += 1
        imos[r] += -1
    for i in range(1, n+1):
        dp[i] = (dp[i-1] + imos[i]) %mod
        for l, r in lr:
            imos[min(i+l, n+2)] += dp[i]
            imos[min(i+r, n+2)] += -1*dp[i]
    print(dp[n-1]%mod)

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    n, k = map(int, input().split())
    mod = 998244353
    dp = [0] * (2*n)
    imos = [0] * (2*n)
    lr = []
    for i in range(k):
        l, r = map(int, input().split())
        lr.append((l, r+1))
    for l, r in lr:
        imos[l] = 1
        imos[r] = -1
    now = 0
    for i in range(1, n):
        now += imos[i]
        now %= mod
        dp[i] = now
        for l, r in lr:
            imos[min(i+l, n+2)] += now
            imos[min(i+r, n+2)] += -1*now
    print(dp[n-1]%mod)


resolve()
Problem p02571 (python)

Fixed submission:
def resolve():
    s = input()
    t = input()
    ans = 10**4

    for i in range(len(s)-len(t)+1):
        ch = 0
        for j in range(len(t)):
            if s[i+j] != t[j]:
                ch += 1
        ans = min(ch, ans)
    print(ans)

resolve()

Buggy submission (verdict: Runtime Error):

def resolve():
    s = input()
    t = input()
    ans = 0

    for i in range(len(t)):
        for j in range(i, len(t)):
            test = t[i:(j + 1)]
            if test in s[i:(len(s) - (len(t) - j) + 1)]:
                print(test)
                ans = max(ans, len(test))
    print(len(t) - ans)

resolve()
Problem p02580 (python)

Fixed submission:
def resolve():
    h,w,m = map(int, input().split())
    mine = []
    mineh = [0]*h
    minew = [0]*w
    for i in range(m):
        a,b = map(int, input().split())
        a -= 1
        b -= 1
        mine.append((a,b))
        mineh[a] += 1
        minew[b] += 1
    mine = set(mine)
    maxh = max(mineh)
    hnum = []
    maxw = max(minew)
    wnum = []
    for i in range(h):
        if mineh[i] == maxh:
            hnum.append(i)
    for i in range(w):
        if minew[i] == maxw:
            wnum.append(i)
    hnum = set(hnum)
    wnum = set(wnum)
    NO = 0
    for i, j in mine:
        if i in hnum and j in wnum:
            NO += 1
    if len(hnum)*len(wnum) > NO:
        print(maxw+maxh)
    else:
        print(maxw+maxh-1)
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    h,w,m = map(int, input().split())
    mine = []
    mineh = [0]*h
    minew = [0]*w
    for i in range(m):
        a,b = map(int, input().split())
        a -= 1
        b -= 1
        mine.append((a,b))
        mineh[a] += 1
        minew[b] += 1
    mine = set(mine)
    maxh = max(mineh)
    hnum = []
    maxw = max(minew)
    wnum = []
    for i in range(h):
        if mineh[i] == maxh:
            hnum.append(i)
        if minew[i] == maxw:
            wnum.append(i)
    hnum = set(hnum)
    wnum = set(wnum)
    NO = 0
    for i, j in mine:
        if i in hnum and j in wnum:
            NO += 1
    if len(hnum)*len(wnum) > NO:
        print(maxw+maxh)
    else:
        print(maxw+maxh-1)
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    h,w,m = map(int, input().split())
    mine = []
    mineh = [0]*h
    minew = [0]*w
    for i in range(m):
        a,b = map(int, input().split())
        a -= 1
        b -= 1
        mine.append((a,b))
        mineh[a] += 1
        minew[b] += 1
    mine = set(mine)
    maxh = max(mineh)
    hnum = []
    maxw = max(minew)
    wnum = []
    for i in range(h):
        if mineh[i] == maxh:
            hnum.append(i)
        if minew[i] == maxw:
            wnum.append(i)
    for i in hnum:
        for j in wnum:
            if [i,j] in mine:
                continue
            else:
                print(maxw+maxh)
                exit()
    print(maxw+maxh-1)
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    h,w,m = map(int, input().split())
    mine = []
    mineh = [0]*h
    minew = [0]*w
    for i in range(m):
        a,b = map(int, input().split())
        a -= 1
        b -= 1
        mine.append([a,b])
        mineh[a] += 1
        minew[b] += 1
    maxh = max(mineh)
    hnum = []
    maxw = max(minew)
    wnum = []
    for i in range(h):
        if mineh[i] == maxh:
            hnum.append(i)
        if minew[i] == maxw:
            wnum.append(i)
    for i in hnum:
        for j in wnum:
            if [i,j] in mine:
                continue
            else:
                print(maxw+maxh)
                exit()
    print(maxw+maxh-1)
resolve()
Problem p02623 (python)

Fixed submission:

def resolve():
    import bisect
    n,m,k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    cuma = [0]
    cumb = [0]
    for i in range(n):
        cuma.append(cuma[-1]+ a[i])
    for i in range(m):
        cumb.append(cumb[-1] + b[i])

    ans = 0
    for i in range(n+1):
        if k-cuma[i] < 0:
            continue
        ans = max(ans, i + bisect.bisect_right(cumb, k-cuma[i])-1)
    print(ans)
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    from collections import deque
    n,m,k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a = deque(a)
    b = deque(b)
    min = 0
    ans = 0
    while True:
        if len(a) == 0 and len(b)==0:
            break
        elif len(a) == 0:
            bb = b.popleft()
            read = bb
            if min + read <= k:
                min += read
                ans += 1
            else:
                break
        elif len(b) == 0:
            ab = a.popleft()
            read = ab
            if min + read <= k:
                min += read
                ans += 1
            else:
                break
        else:
            ab = a.popleft()
            bb = b.popleft()
            if ab == bb:
                if a[0] < b[0]:
                    b.appendleft(bb)
                    read = ab
                else:
                    a.appendleft(ab)
                    read = bb

            elif ab < bb:
                b.appendleft(bb)
                read = ab
            else:
                a.appendleft(ab)
                read = bb
            if min + read <= k:
                min += read
                ans += 1
            else:
                break

    print(ans)
resolve()
Problem p02726 (python)

Fixed submission:
def resolve():
    n,x,y = map(int, input().split())
    ans = {}
    for i in range(1, n):
        for j in range(i+1, n+1):
            dist1 = j-i
            dist2 = abs(x-i)+1+abs(y-j)
            dist =min (dist1, dist2)
            if dist in ans:
                ans[dist] += 1
            else:
                ans[dist] = 1
    for i in range(1,n):
        if i not in ans:
            ans[i] =0
        print(ans[i])
resolve()

Buggy submission (verdict: Runtime Error):

def resolve():
    import numpy as np
    from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
    from scipy.sparse import csr_matrix
    n, x, y = map(int, input().split())
    netw = [[0]*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if abs(j-i) == 1:
                netw[i][j] = 1
    netw[x-1][y-1] = 1
    netw[y-1][x-1] = 1
    netw = np.array(netw)
    csr = csr_matrix(netw)
    ans = {}
    for i in range(n-1):
        a = shortest_path(csr, indices=i)
        for j in range(i+1, n):
            if a[j] in ans:
                ans[a[j]] += 1
            else:
                ans[a[j]] = 1
    for i in range(1, n):
        if i in ans:
            continue
        else:
            ans[i] =0
    for i in range(1, n):
        print(ans[i])
resolve()
Problem p02771 (python)

Fixed submission:
def resolve():
    a = set(map(int, input().split()))
    if len(a)==2:
        print("Yes")
    else:
        print("No")
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    import sys
    from collections import Counter
    n = int(input())
    s = [sys.stdin.readline().rstrip() for i in range(n)]
    d = Counter(s).most_common()
    e = d[0][1]
    ans = []
    for i in range(len(d)):
        if d[i][1] != e:
            break
        else:
            ans.append(d[i][0])
    for j in sorted(ans):
        print(j)
resolve()
Problem p02792 (python)

Fixed submission:
def resolve():
    n = int(input())
    c = [[0] * 10 for i in range(10)]
    for i in range(n+1):
        b = i % 10
        for j in range(6):
            if i//(10**(j+1)) == 0:
                a = i//(10**j)
                break
        c[a][b] += 1
    ans = 0
    for i in range(1,10):
        for j in range(1,10):
            ans += c[i][j] * c[j][i]
    print(ans)
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])
        if temp!=1:
            arr.append([temp, 1])
        if arr==[]:
            arr.append([n, 1])
        return arr

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    import copy

    gcddict = {}
    adiv = []
    for i in range(n):
        primes = factorization(a[i])
        adiv.append(primes)
        for j in range(len(primes)):
            if primes[j][0] in gcddict:
                gcddict[primes[j][0]] = max(gcddict[primes[j][0]], primes[j][1])
            else:
                gcddict[primes[j][0]] = primes[j][1]
    ans = 0
    for i in range(n):
        val = 1
        test = copy.deepcopy(gcddict)
        primes = adiv[i]
        for j in range(len(primes)):
            test[primes[j][0]] -= primes[j][1]
        for k in test.keys():
            val *= pow(k, test[k], mod)
        ans += val
    print(ans % mod)
resolve()
Problem p02793 (python)

Fixed submission:
def resolve():
    def lcm(X, Y):
        x = X
        y = Y
        if y > x:
            x, y = y, x
        while x % y != 0:
            x, y = y, x % y
        return X * Y // y
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    lsd = a[0]
    for i in range(1, n):
        lsd = lcm(lsd, a[i])
    lsd = lsd % mod

    ans = 0
    for i in range(n):
        ans += (lsd * pow(a[i], mod-2, mod)) % mod

    print(int(ans % mod))

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    from fractions import gcd
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    lsd = a[0]
    for i in range(1, n):
        lsd = int((lsd * a[i]) / (gcd(lsd, a[i])))
 
    ans = 0
    for i in range(n):
        ans += int(lsd/a[i]) % mod
 
    print(int(ans % mod))
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    from fractions import gcd
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    lsd = a[0]
    for i in range(1, n):
        lsd = int((lsd * a[i]) / (gcd(lsd, a[i])))

    ans = 0
    for i in range(n):
        ans += (lsd/a[i]) % mod

    print(int(ans % mod))

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    from fractions import gcd
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    lsd = a[0]
    for i in range(1, n):
        lsd = (lsd * a[i]) // gcd(lsd, a[i])

    ans = 0
    for i in range(n):
        ans += (lsd/a[i]) % mod

    print(int(ans % mod))

resolve()
Problem p02819 (python)

Fixed submission:
def resolve():
    n = int(input())
    primel = [2]
    for i in range(3,331):
        k = 0
        for j in range(len(primel)):
            if i % primel[j] == 0:
                break
            else:
                k += 1
            if k == len(primel):
                primel.append(i)

    for i in range(0, 100000):
        k=0
        for j in range(len(primel)):
            if (n+i) == primel[j]:
                print(n + i)
                exit()
            if (n+i) % primel[j] == 0:
                break
            else:
                k += 1
            if k == len(primel):
                print(n + i)
                exit()
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    n = int(input())
    if n==2:
        print("2")
    for j in range(10000):
        flag = 1
        a = int((n+j)**0.5)+1
        for i in range(2, a+1):
            if (n+i) % j == 0:
                flag = -1
            if i == a and flag ==1:
                print(n+j)
                exit()
resolve()
Problem p02847 (python)

Fixed submission:
def resolve():
    s = input()
    if s == "SUN":
        print(7)
    elif s == "MON":
        print(6)
    elif s == "TUE":
        print(5)
    elif s == "WED":
        print(4)
    elif s == "THU":
        print(3)
    elif s == "FRI":
        print(2)
    elif s == "SAT":
        print(1)
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    import math
    a,b,x = map(int, input().split())
    if 10**((x//b)-1) < 10:
        pmax = min (x//a, 10**((x//b)-1))
    else:
        pmax = x//a
    if pmax ==0:
        print(0)
        exit()
    elif pmax > 10**9:
        pmax = 10**9

    for i in range(10**9):
        n1 = pmax-i
        logn1 = int(math.log(n1,10))+1
        if a*n1+b*logn1 <= x:
            print(n1)
            exit()
resolve()
Problem p03104 (python)

Fixed submission:
def resolve():
    import math
    a, b = map(int, input().split())
    if a == 1:
        bina = 0
    elif a == 2:
        bina = 1
    elif a == 3:
        bina = 3
    elif a%4 ==3:
        bina = a
    else:
        lowera = math.floor((a - 3) / 4) * 4 + 3
        bina = 0
        for i in range(lowera + 1, a):
            bina = bina ^ i

    if b ==1:
        binb = 1
    elif b ==2:
        binb = 3
    elif b==3:
        binb =0
    else:
        if b%4 == 3:
            binb = 0
        else:
            lowerb = math.floor((b-3)/4)*4+3
            binb = 0
            for j in range(lowerb+1, b+1):
                binb = binb^j

    print(bina^binb)
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    import math
    a, b = map(int, input().split())
    if a == 1:
        bina = 0
    elif a == 2:
        bina = 1
    elif a == 3:
        bina = 3
    elif a%4 ==3:
        bina = a
    else:
        lowera = math.floor((a - 3) / 4) * 4 + 3
        bina = 0
        for i in range(lowera + 1, a):
            bina = bina ^ i

    if b ==1:
        binb = 1
    elif b ==2:
        binb = 3
    elif b==3:
        binb =0
    else:
        if b%4 == 3:
            binb = 0
        else:
            lowerb = math.floor((b-3)/4)*4+3
            binb = 0
        for j in range(lowerb+1, b+1):
            binb = binb^j

    print(bina^binb)
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    import math
    a, b = map(int, input().split())
    if a == 1:
        bina = 0
    elif a == 2:
        bina = 1
    elif a == 3:
        bina = 3
    elif a%4 ==3:
        bina = a
    else:
        lowera = math.floor((a - 3) / 4) * 4 + 3
        bina = 0
        for i in range(lowera + 1, a):
            bina = bina ^ i

    if b ==1:
        binb = 1
    elif b ==2:
        binb = 3
    elif b==3:
        binb =0
    else:
        if b%4 == 3:
            binb = 0
        else:
            lowerb = math.floor((b-3)/4)*4+3
            binb = 0
        for j in range(lowerb+1, b+1):
                binb = binb^j

    print(bina^binb)
resolve()
Problem p03464 (python)

Fixed submission:
def resolve():
    # from collections import deque
    k = int(input())
    a = list(map(int, input().split()))
    rl = [2, 2]
    ra = a[::-1]

    for i in range(k):
        nxt = []
        nowa = ra[i]
        if (rl[-1] // nowa) - ((rl[0]-1)//nowa) > 0:
            nxt.append((((rl[0]-1)//nowa)+1)*nowa)
            nxt.append((rl[-1]//nowa)*nowa + nowa-1)
        if not nxt:
            print(-1)
            exit()
        rl = nxt

    print("{} {}".format(rl[0], rl[-1]))
resolve()

Buggy submission (verdict: Runtime Error):
    # from collections import deque
    k = int(input())
    a = list(map(int, input().split()))
    now = [2]
    if k == 1:
        print("2 3") if a[0] == 2 else print(-1)
    else:
        for i in reversed(range(1,k)):
            nxt = []
            for j in range(len(now)):
                test = now[j]
                nxtd = a[i-1]
                if test % a[i] == 0:
                    mod = test % nxtd
                    if (nxtd-mod)%nxtd < a[i]:
                        for k in range((nxtd-mod)%nxtd, a[i], nxtd):
                            nxt.append(k+test)
            if not nxt:
                print(-1)
                exit()
            now = nxt
        ans = []
        for i in now:
            test = i
            if test % a[0] == 0:
                ans.append(i)
                ans.append(i+a[0]-1)
        ans = sorted(ans)
        print("{} {}".format(ans[0], ans[-1]))
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    # from collections import deque
    k = int(input())
    a = list(map(int, input().split()))

    ra = a[::-1]
    now = [2]
    for i in range(k-1):
        nxt = []
        for j in range(len(now)):
            test = now[j]
            nxtd = ra[i+1]
            if test % ra[i] == 0:
                mod = test % nxtd
                if (nxtd-mod)%nxtd < ra[i]:
                    for k in range((nxtd-mod)%nxtd, ra[i], nxtd):
                        nxt.append(k+test)

        if not nxt:
            print(-1)
            exit()
        now = nxt
    now = sorted(list(now))
    ans = []
    for i in now:
        test = i
        if test % ra[-1] == 0:
            ans.append(i)
            ans.append(i+ra[-1]-1)
    ans = sorted(ans)
    print("{} {}".format(ans[0], ans[-1]))
resolve()
Problem p03986 (python)

Fixed submission:
def resolve():
    from collections import deque
    x = input()
    final = deque([])
    final.append(x[0])
    for i in range(1, len(x)):
        if x[i] == "S":
            final.append("S")
        else:
            if not final:
                final.append("T")
            else:
                last = final.pop()
                if last == "S":
                    continue
                else:
                    final.append("T")
                    final.append("T")
    print(len(final))
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    from collections import deque
    x = input()
    final = deque([])
    final.append(x[0])
    for i in range(1, len(x)):
        if x[i] == "S":
            final.append("S")
        else:
            last = final.pop()
            if last == "S":
                continue
            else:
                final.append("T")
                final.append("T")
    print(len(final))

resolve()
Problem p02598 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

def f(x):
    return sum((a+x-1)//x - 1 for a in A)

l = 0
r = 10**9+1 
while r - l > 1:
    mid = (l + r) // 2
    if f(mid) <= K:
        r = mid
    else:
        l = mid
print(r)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

def f(x):
    ret = 0
    for a in A:
        ret += a//x
    return ret

if K == 0:
    print(max(A))
    exit()
ok = -1
ng = 10**9 + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    if f(mid) <= K:
        ng = mid
    else:
        ok = mid
print(ng)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

def f(x):
    ret = 0
    for a in A:
        ret += a//x
    return ret

if K == 0:
    print(max(A))
    exit()
ok = -1
ng = 10**9 + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    if f(mid) <= K:
        ng = mid
    else:
        ok = mid
print(ng)
Problem p02819 (python)

Fixed submission:
x = int(input())
n = 2 *(10 ** 5)
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes = list(primes)
import bisect
b = bisect.bisect_right(primes, x)
if x == primes[b - 1]:
    print(x)
else:
    print(primes[b])

Buggy submission (verdict: Runtime Error):
x = int(input())
n = 10 ** 5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes = list(primes)
import bisect
b = bisect.bisect_right(primes, x)
if x == primes[b - 1]:
    print(x)
else:
    print(primes[b])

Buggy submission (verdict: Runtime Error):
x = int(input())
n = 10 ** 5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes = list(primes)
import bisect
b = bisect.bisect_right(primes, x)
print(primes[b])
Problem p02829 (python)

Fixed submission:
a = int(input())
b = int(input())
for i in range(3):
    if a != i+1 and b != i+1:
        print(i+1)

Buggy submission (verdict: Runtime Error):
import fractions
a, b = map(int, input().split(' '))

print(int(a * b / fractions.gcd(a, b)))
Problem p02831 (python)

Fixed submission:
import fractions
a, b = map(int, input().split(' '))

print(int(a * b / fractions.gcd(a, b)))

Buggy submission (verdict: Runtime Error):
import math
a, b = map(int, input().split(' '))

print(int(a * b / math.gcd(a, b)))
Problem p02833 (python)

Fixed submission:
N = int(input())

if N % 2 != 0:
    print(0)
    exit()
ans = 0
d = 10
while d <= N:
    ans += N // d
    d *= 5
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
num = int(input())
n = int(np.log10(num))
a =  n * (num // 10 ** n)
print(a)
for i in range(int(n - 2), 1, -1):
    a += i * 9
print(a)
Problem p02834 (python)

Fixed submission:
from collections import deque

n, s, t = map(int, input().split(' '))
s -= 1
t -= 1

v = [[] for i in range(n)]
f = [0]*n

for i in range(n-1):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
    f[a] += 1
    f[b] += 1
for i in range(n):
    if f[i] == 0:
        l.append(i)
depth = [-1]*n
depth[t] = 0
q = deque([t])
while q:
    x = q.popleft()
    for y in v[x]:
        if depth[y] < 0:
            depth[y] = depth[x]+1
            q.append(y)
l = depth[:]
d = [-1]*n
d[s] = 0
q = deque([s])
while q:
    x = q.popleft()
    for y in v[x]:
        if d[y] < 0:
            d[y] = d[x]+1
            q.append(y)
l = sorted(range(n), key=lambda x:-depth[x])
for i in l:
    if d[i] < depth[i]:
        break
print(depth[i] - 1)

Buggy submission (verdict: Runtime Error):
from collections import deque

n, s, t = map(int, input().split(' '))
s -= 1
t -= 1

v = [[] for i in range(n)]
f = [0]*n

for i in range(n-1):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
    f[a] += 1
    f[b] += 1
for i in range(n):
    if f[i] == 0:
        l.append(i)
depth = [-1]*n
depth[t] = 0
q = deque([t])
while q:
    x = q.popleft()
    for y in v[x]:
        if depth[y] < 0:
            depth[y] = depth[x]+1
            q.append(y)
l = depth[:]
d = [-1]*n
d[s] = 0
q = deque([s])
while q:
    x = popleft()
    for y in v[x]:
        if d[y] < 0:
            d[y] = d[x]+1
            q.append(y)
l = sorted(range(n), key=lambda x:-depth[x])
for i in l:
    if d[i] < depth[i]:
        break
print(depth[i] - 1)