Problem p02997 (python)

Fixed submission:
def check(N, K):
    if K <= (N - 1)*(N-2) /2:
        k = int((N - 1)*(N-2)/2 - K)
        print(N-1 + k)
        for i in range(2, N+1):
            print(1, i)
        l = 2
        r = 3
        if k != 0:
            for i in range(k):
                if l > N or r > N:
                    break
                print(l, r)
                r+=1
                if r == N+1:
                    l+=1
                    r=l+1
        return
    else:
        print(-1)
        return


if __name__ == "__main__":
    N, K = map(int, input().split())
    check(N, K)

Buggy submission (verdict: Runtime Error):
def check(N, K):
    if K < N - 2:
        print(-1)
        return
    if K == N - 2:
        print(N-1)
        for i in range(1, N):
            print(i, i+1)
        return
    if N-1 <= K and K < (N - 1)*(N-2) /2:
        k = (N - 1)*(N-2) /2 - K
        print(N-1 + k)
        for i in range(2, N+1):
            print(1, i)
        l = 2
        r = 3
        for i in range(k):
            print(l, r)
            r+=1
            if r == N+2:
                l+=1
                r=l+1
        return
    if (N - 1)*(N-2) /2 == K:
        print(-1)
        for i in range(2, N+1):
            print(1, i)
        return
    if (N - 1)*(N - 2) /2 < K:
        print(-1)
        return


if __name__ == "__main__":
    N, K = map(int, input().split())
    check(N, K)

Buggy submission (verdict: Runtime Error):
def check(N, K):
    # k < N-2
    if K < N - 2:
        print(-1)
        return
    # k == N -2
    if K == N - 2:
        print(N-1)
        for i in range(1, N):
            print(i, i+1)
        return
    # N -1 <= k <= (N - 1)*(N-2) /2
    if N-1 <= K and K < (N - 1)*(N-2) /2:
        k = (N - 1)*(N-2) /2 - K
        print(N-1 + k)
        for i in range(2, N+1):
            print(1, i)
        l = 2
        r = 3
        for i in range(k):
            print(l, r)
            r+=1
            if r == N+2:
                l+=1
                r=l+1
    # K = (N - 1)*(N-2) /2
    if (N - 1)*(N-2) /2 == K:
        print(-1)
        for i in range(2, N+1):
            print(1, i)
        return
    #  (N - 1)*(N-2) /2 < k
    if (N - 1)*(N - 2) /2 < K:
        print(-1)
        return


if __name__ == "__main__":
    N, K = map(int, input().split())
    check(N, K)

Buggy submission (verdict: Runtime Error):
def check(N, K):
    if N - 1 == K:
        print(N-1)
        for i in range(i + 2, N + 1):
            print(1, i)
        return
    elif N - 2 == K:
        print(N-1)
        for i in range(1, N):
            print(i, i+1)
        return
    elif N-2 > K:
        print(-1)
        return
    else:
        print(-1)
        return



if __name__ == "__main__":
    N, K = map(int, input().split())
    check(N, K)

Buggy submission (verdict: Runtime Error):
def check(N, K):
    if N - 1 == K:
        print(N-1)
        for i in range(i + 2, N + 1):
            print(1, i)
        return
    elif N - 2 == K:
        print(N-1)
        for i in range(1, N):
            print(i, i+1)
        return
    elif N-2 > K:
        return
    else:
        print(-1)
        return



if __name__ == "__main__":
    N, K = map(int, input().split())
    check(N, K)

Buggy submission (verdict: Runtime Error):
def check(N, K):
    if N - 1 == K:
        print(N-1)
        for i in range(i + 2, N + 1):
            print(1, i)
        return
    elif N - 2 == K:
        print(N-1)
        for i in range(1, N):
            print(i, i+1)
        return
    elif N >= K:
        return
    else:
        print(-1)
        return



if __name__ == "__main__":
    N, K = map(int, input().split())
    check(N, K)

Buggy submission (verdict: Runtime Error):
def check(N, K):
    if N - 1 == K:
        for i in range(i + 2, N + 1):
            print(1, i)
        return
    elif N - 2 == K:
        for i in range(1, N):
            print(i, i+1)
        return
    elif N >= K:
        return
    else:
        print(-1)
        return



if __name__ == "__main__":
    N, K = map(int, input().split())
    check(N, K)

Buggy submission (verdict: Runtime Error):
def check(N, K):
    if N - 1 == K:
        for i in range(i + 2, N + 1):
            print(1, i)
        return
    elif N - 1 > K:
        
        return
    else:
        print(-1)
        return



if __name__ == "__main__":
    N, K = map(int, input().split())
    check(N, K)