Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
INF = float("inf")


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = N
    return Z


def zfindall(text, pattern, separator="$"):
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    return {i-N-1 for i in range(len(conc)) if Z[i] == N}


def solve(N: int, a: "List[int]", b: "List[int]"):

    a1 = [0]*(2*N)
    b1 = [0]*N
    b2 = [0]*N
    k_cand = [True]*N
    for keta in range(30):
        for i, aa in enumerate(a):
            a1[i] = a1[i+N] = (aa >> keta) & 1
        for i, bb in enumerate(b):
            b1[i] = v = (bb >> keta) & 1
            b2[i] = 1-v
        k_cand1 = zfindall(a1, b1, separator=[-1])
        k_cand2 = zfindall(a1, b2, separator=[-1])
        k_cand1 = k_cand1 | k_cand2
        for i in range(N):
            if k_cand[i]:
                k_cand[i] = i in k_cand1

    for i in range(N):
        if k_cand[i]:
            print(i, b[0] ^ a[i])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    """テキストからパターンと一致する部分文字列を探す。
    開始インデックスを返す
    Zアルゴリズムを利用する
    """
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    return [i-N-1 for i in range(len(conc)) if Z[i] == N]


def solve(N: int, a: "List[int]", b: "List[int]"):

    c = [a[i] ^ a[(i+1) % N]for i in range(N)]
    d = [b[i] ^ b[(i+1) % N]for i in range(N)]*2
    i = -1
    k_cand = zfindall(d, c, separator=[-1])
    # print(k_cand)

    ans = []
    if len(k_cand) == 0:
        return
    if k_cand[0] % N == 0:
        print(0, b[0] ^ a[0])
        for k in k_cand[:0:-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    else:
        for k in k_cand[::-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    """テキストからパターンと一致する部分文字列を探す。
    開始インデックスを返す
    Zアルゴリズムを利用する
    """
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    return {i-N-1 for i in range(len(conc)) if Z[i] == N}


def solve(N: int, a: "List[int]", b: "List[int]"):

    c = [a[i] ^ a[(i+1) % N]for i in range(N)]
    d = [b[i] ^ b[(i+1) % N]for i in range(N)]*2
    i = -1
    a1 = [0]*N
    a2 = [0]*N
    b1 = [0]*(2*N)
    k_cand = [True]*N
    for keta in range(30):
        mask = 1 << keta
        for i, aa in enumerate(a):
            a1[i] = (aa & mask) >> keta
            a2[i] = (~aa & mask) >> keta
        for i, bb in enumerate(b):
            b1[i] = (bb & mask) >> keta
            b1[i+N] = (bb & mask) >> keta
        k_cand1 = zfindall(b1, a1, separator=[-1])
        k_cand2 = zfindall(b1, a2, separator=[-1])
        for i in range(N):
            k_cand[i] = k_cand[i] & ((i in k_cand1) or (i in k_cand2))

    ans = []
    if len(k_cand) == 0:
        return
    if k_cand[0] == True:
        print(0, b[0] ^ a[0])
        for i, k in enumerate(k_cand[:0:-1], start=1):
            if k:
                print(i, b[0] ^ a[i])
    else:
        for i, k in enumerate(k_cand[::-1], start=1):
            if k:
                print(i, b[0] ^ a[i])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    """テキストからパターンと一致する部分文字列を探す。
    開始インデックスを返す
    Zアルゴリズムを利用する
    """
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    return [i-N-1 for i in range(len(conc)) if Z[i] == N]


def solve(N: int, a: "List[int]", b: "List[int]"):

    c = [a[i] ^ a[(i+1) % N]for i in range(N)]
    d = [b[i] ^ b[(i+1) % N]for i in range(N)]*2
    i = -1
    k_cand = zfindall(d, c, separator=[-1])
    # print(k_cand)

    ans = []
    if len(k_cand) == 0:
        return
    if k_cand[0] % N == 0:
        print(0, b[0] ^ a[0])
        for k in k_cand[:0:-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    else:
        for k in k_cand[::-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def contain(T, S):
    # TはSに含まれているか
    if len(T) > len(S):
        return len(S)
    t = 1
    for i in range(len(T)):
        t *= B
        t %= MOD
    th, sh = 0, 0
    for i in range(len(T)):
        th = th*B+T[i]
        th %= MOD
    for i in range(len(T)):
        sh = sh*B+S[i]
        sh %= MOD

    for i in range(len(S)-len(T)):
        if th == sh:
            if T == S[i:i+len(T)]:
                return i
        if i + len(T) < len(S):
            sh = sh*B+S[i+len(T)]-S[i]*t
            sh %= MOD
    return len(S)


def solve(N: int, a: "List[int]", b: "List[int]"):

    c = [a[i] ^ a[(i+1) % N]for i in range(N)]
    d = [b[i] ^ b[(i+1) % N]for i in range(N)]*2
    i = -1
    k_cand = []
    # print(c, d)
    while i < N:
        i = i+1+contain(c, d[i+1:])
        if i < N:
            k_cand.append(i)
    # print(k_cand)

    ans = []
    if len(k_cand) == 0:
        return
    if k_cand[0] % N == 0:
        print(0, b[0] ^ a[0])
        for k in k_cand[:0:-1]:
            print(-k % N, b[0] ^ a[-k % N])
    else:
        for k in k_cand[::-1]:
            print(-k % N, b[0] ^ a[-k % N])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    """テキストからパターンと一致する部分文字列を探す。
    開始インデックスを返す
    Zアルゴリズムを利用する
    """
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    return [i-N-1 for i in range(len(conc)) if Z[i] == N]


def solve(N: int, a: "List[int]", b: "List[int]"):

    c = [a[i] ^ a[(i+1) % N]for i in range(N)]
    d = [b[i] ^ b[(i+1) % N]for i in range(N)]*2
    i = -1
    k_cand = zfindall(d, c, separator=[-1])
    # print(k_cand)

    ans = []
    if len(k_cand) == 0:
        return
    if k_cand[0] % N == 0:
        print(0, b[0] ^ a[0])
        for k in k_cand[:0:-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    else:
        for k in k_cand[::-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def contain(T, S):
    # TはSに含まれているか
    if len(T) > len(S):
        return len(S)
    t = 1
    for i in range(len(T)):
        t *= B
        t %= MOD
    th, sh = 0, 0
    for i in range(len(T)):
        th = th*B+T[i]
        th %= MOD
    for i in range(len(T)):
        sh = sh*B+S[i]
        sh %= MOD

    for i in range(len(S)-len(T)):
        if th == sh:
            if T == S[i:i+len(T)]:
                return i
        if i + len(T) < len(S):
            sh = sh*B+S[i+len(T)]-S[i]*t
            sh %= MOD
    return len(S)


def solve(N: int, a: "List[int]", b: "List[int]"):

    c = [a[i] ^ a[(i+1) % N]for i in range(N)]
    d = [b[i] ^ b[(i+1) % N]for i in range(N)]*2
    i = -1
    k_cand = [False]*N
    # print(c, d)
    while i < N:
        i = i+1+contain(c, d[i+1:])
        if i < N:
            k_cand[i] = True
    # print(k_cand)

    ans = []
    for i, k in enumerate(k_cand):
        if k == True:
            ans.append(((N-i) % N, b[0] ^ a[(N-i) % N]))
    ans.sort()
    for a, b in ans:
        print(a, b, sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    """テキストからパターンと一致する部分文字列を探す。
    開始インデックスを返す
    Zアルゴリズムを利用する
    """
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    return [i-N-1 for i in range(len(conc)) if Z[i] == N]


def solve(N: int, a: "List[int]", b: "List[int]"):

    c = [a[i] ^ a[(i+1) % N]for i in range(N)]
    d = [b[i] ^ b[(i+1) % N]for i in range(N)]*2
    i = -1
    k_cand = zfindall(d, c, separator=[-1])
    # print(k_cand)

    ans = []
    if len(k_cand) == 0:
        return
    if k_cand[0] % N == 0:
        print(0, b[0] ^ a[0])
        for k in k_cand[:0:-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    else:
        for k in k_cand[::-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def contain(T, S):
    # TはSに含まれているか
    if len(T) > len(S):
        return len(S)
    t = 1
    for i in range(len(T)):
        t *= B
        t %= MOD
    th, sh = 0, 0
    for i in range(len(T)):
        th = th*B+T[i]
        th %= MOD
    for i in range(len(T)):
        sh = sh*B+S[i]
        sh %= MOD

    for i in range(len(S)-len(T)):
        if th == sh:
            if T == S[i:i+len(T)]:
                return i
        if i + len(T) < len(S):
            sh = sh*B+S[i+len(T)]-S[i]*t
            sh %= MOD
    return len(S)


def solve(N: int, a: "List[int]", b: "List[int]"):

    K = [True]*N
    for i in range(3):
        a_pat = []
        a_pat2 = []
        b_pat = []
        for n, (aa, bb) in enumerate(zip(a, b)):
            a_pat.append((aa >> i) & 1)
            a_pat2.append(1-((aa >> i) & 1))
            b_pat.append((bb >> i) & 1)
        b_pat = b_pat*2
        cand = [False]*(2*N)
        cand2 = [False]*(2*N)
        j = -1
        while j < N:
            j = j+1+contain(a_pat, b_pat[j+1:])
            if j < 2*N:
                cand[j] = True
        j = -1
        while j < N:
            j = j+1+contain(a_pat2, b_pat[j+1:])
            if j < 2*N:
                cand2[j] = True
        for j in range(N):
            if cand[j] == False and cand2[j] == False:
                K[j] = False
        # print("K", K)

    ans = []
    for i, k in enumerate(K):
        if k == True:
            ans.append(((N-i) % N, b[0] ^ a[(N-i) % N]))
    ans.sort()
    for a, b in ans:
        print(a, b, sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    """テキストからパターンと一致する部分文字列を探す。
    開始インデックスを返す
    Zアルゴリズムを利用する
    """
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    return [i-N-1 for i in range(len(conc)) if Z[i] == N]


def solve(N: int, a: "List[int]", b: "List[int]"):

    c = [a[i] ^ a[(i+1) % N]for i in range(N)]
    d = [b[i] ^ b[(i+1) % N]for i in range(N)]*2
    i = -1
    k_cand = zfindall(d, c, separator=[-1])
    # print(k_cand)

    ans = []
    if len(k_cand) == 0:
        return
    if k_cand[0] % N == 0:
        print(0, b[0] ^ a[0])
        for k in k_cand[:0:-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    else:
        for k in k_cand[::-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
INF = float("inf")


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    """テキストからパターンと一致する部分文字列を探す。
    開始インデックスを返す
    Zアルゴリズムを利用する
    """
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    ans = [False]*(len(text)-1)
    for i in range(len(conc)):
        if Z[i] == N:
            ans[i-N-1] = True
    return ans


def solve(N: int, a: "List[int]", b: "List[int]"):

    def bit_most(v):
        # 最高位の桁を得る
        if v == 0:
            return 0
        else:
            return len(bin(v))-2

    K = [True]*N
    for i in range(30):
        a_pat = []
        a_pat2 = []
        b_pat = []
        for n, (aa, bb) in enumerate(zip(a, b)):
            a_pat.append(str((aa >> i) & 1))
            a_pat2.append(str(1-((aa >> i) & 1)))
            b_pat.append(str((bb >> i) & 1))
        a_pat = "".join(a_pat)
        a_pat2 = "".join(a_pat2)
        b_pat = "".join(b_pat)*3
        # print(a_pat, b_pat)
        # print(a_pat2, b_pat)
        zzz = zfindall(b_pat, a_pat)
        zzz2 = zfindall(b_pat, a_pat2)
        # print(zzz)
        # print(zzz2)
        for i in range(N):
            if not ((zzz[i] == True and zzz[i+N] == True) or
                    (zzz2[i] == True and zzz2[i+N] == True)):
                K[i] = False

    ans = []
    for i, k in enumerate(K):
        if k == True:
            ans.append(((N-i) % N, b[0] ^ a[(N-i) % N]))
    ans.sort()
    for a, b in ans:
        print(a, b, sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    """テキストからパターンと一致する部分文字列を探す。
    開始インデックスを返す
    Zアルゴリズムを利用する
    """
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    return [i-N-1 for i in range(len(conc)) if Z[i] == N]


def solve(N: int, a: "List[int]", b: "List[int]"):

    c = [a[i] ^ a[(i+1) % N]for i in range(N)]
    d = [b[i] ^ b[(i+1) % N]for i in range(N)]*2
    i = -1
    k_cand = zfindall(d, c, separator=[-1])
    # print(k_cand)

    ans = []
    if len(k_cand) == 0:
        return
    if k_cand[0] % N == 0:
        print(0, b[0] ^ a[0])
        for k in k_cand[:0:-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    else:
        for k in k_cand[::-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
INF = float("inf")


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    """テキストからパターンと一致する部分文字列を探す。
    開始インデックスを返す
    Zアルゴリズムを利用する
    """
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    ans = [False]*(len(text)-1)
    for i in range(len(conc)):
        if Z[i] == N:
            ans[i-N-1] = True
    return ans


def solve(N: int, a: "List[int]", b: "List[int]"):

    def bit_most(v):
        # 最高位の桁を得る
        if v == 0:
            return 0
        else:
            return len(bin(v))-2

    K = [True]*N
    for i in range(30):
        a_pat = []
        a_pat2 = []
        b_pat = []
        for n, (aa, bb) in enumerate(zip(a, b)):
            a_pat.append(str((aa >> i) & 1))
            a_pat2.append(str(1-((aa >> i) & 1)))
            b_pat.append(str((bb >> i) & 1))
        a_pat = "".join(a_pat)
        a_pat2 = "".join(a_pat2)
        b_pat = "".join(b_pat)*3
        # print(a_pat, b_pat)
        # print(a_pat2, b_pat)
        zzz = zfindall(b_pat, a_pat)
        zzz2 = zfindall(b_pat, a_pat2)
        # print(zzz)
        # print(zzz2)
        for i in range(N):
            if not ((zzz[i] == True and zzz[i+N] == True) or
                    (zzz2[i] == True and zzz2[i+N] == True)):
                K[i] = False

    ans = []
    for i, k in enumerate(K):
        if k == True:
            ans.append(((N-i) % N, b[0] ^ a[(N-i) % N]))
    ans.sort()
    for a, b in ans:
        print(a, b, sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
INF = float("inf")


B = 10**7+7
MOD = 10**9+7


def z_algorithm(S):
    """Zアルゴリズム
    https://snuke.hatenablog.com/entry/2014/12/03/214243 の二番目のコード
    """
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    """テキストからパターンと一致する部分文字列を探す。
    開始インデックスを返す
    Zアルゴリズムを利用する
    """
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)
    return [i-N-1 for i in range(len(conc)) if Z[i] == N]


def solve(N: int, a: "List[int]", b: "List[int]"):

    c = [a[i] ^ a[(i+1) % N]for i in range(N)]
    d = [b[i] ^ b[(i+1) % N]for i in range(N)]*2
    i = -1
    k_cand = zfindall(d, c, separator=[-1])
    # print(k_cand)

    ans = []
    if len(k_cand) == 0:
        return
    if k_cand[0] % N == 0:
        print(0, b[0] ^ a[0])
        for k in k_cand[:0:-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    else:
        for k in k_cand[::-1]:
            if k < N:
                print(-k % N, b[0] ^ a[-k % N])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, a, b)


if __name__ == '__main__':
    main()