macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
#[derive(Debug)]
struct KnuthMorrisPratt<T: Eq> {
    n: usize,
    pattern: Vec<T>,
    table: Vec<isize>,
}
impl<T: Eq> KnuthMorrisPratt<T> {
    fn new(pattern: Vec<T>) -> KnuthMorrisPratt<T> {
        let n = pattern.len();
        let mut table = vec![-1isize; n + 1];
        let mut j = 0;
        for i in 1..n {
            table[i] = j;
            j += if pattern[i] == pattern[j as usize] {
                1
            } else {
                -j
            };
        }
        table[n] = j;
        KnuthMorrisPratt {
            n: n,
            pattern: pattern,
            table: table,
        }
    }
    #[allow(dead_code)]
    fn search(&self, s: &Vec<T>) -> Option<usize> {
        let mut i = 0;
        let mut m = 0;
        while m + i < s.len() {
            if self.pattern[i] == s[m + i] {
                i += 1;
                if i != self.n {
                    continue;
                }
                return Some(m);
            }
            m = (m as isize + i as isize - self.table[i]) as usize;
            i = std::cmp::max(0, self.table[i]) as usize;
        }
        None
    }
    fn search_all(&self, s: &Vec<T>) -> Vec<usize> {
        let mut i = 0;
        let mut m = 0;
        let mut res = vec![];
        while m + i < s.len() {
            if self.pattern[i] == s[m + i] {
                i += 1;
                if i != self.n {
                    continue;
                }
                res.push(m);
            }
            m = (m as isize + i as isize - self.table[i]) as usize;
            i = std::cmp::max(0, self.table[i]) as usize;
        }
        res
    }
}
fn main() {
    input! { n, a: [usize; n], b: [usize; n] };
    let mut c = (0..n).map(|i| a[i] ^ a[(i + 1) % n]).collect::<Vec<_>>();
    let v = c.iter().take(n - 1).cloned().collect::<Vec<_>>();
    c.extend(v);
    let d = (0..n).map(|i| b[i] ^ b[(i + 1) % n]).collect::<Vec<_>>();
    let kmp = KnuthMorrisPratt::new(d);
    let res = kmp.search_all(&c);
    for r in res.into_iter() {
        println!("{} {}", r, a[r] ^ b[0]);
    }
}


Measured memory_bytes: 24808