#K47272. Find the First Difference Position

    ID: 28162 Type: Default 1000ms 256MiB

Find the First Difference Position

Find the First Difference Position

Given two sequences a and b each containing n integers, your task is to find the smallest position \( k \) (using 1-indexing) where the corresponding elements differ, i.e., where \( a_k \neq b_k \). If there is no such position (i.e. the two sequences are identical), print 0.

Input Format:

The input is read from stdin as follows:

  • The first line contains an integer \( n \), representing the number of elements in each sequence.
  • The second line contains \( n \) integers representing the first sequence \( a_1, a_2, \ldots, a_n \).
  • The third line contains \( n \) integers representing the second sequence \( b_1, b_2, \ldots, b_n \).

Output Format:

Output a single integer representing the smallest position \( k \) such that \( a_k \neq b_k \), or 0 if no such position exists.

inputFormat

The input consists of three lines:

  1. An integer \( n \) (\(1 \leq n \leq 10^5\)).
  2. \( n \) space-separated integers representing the first sequence.
  3. \( n \) space-separated integers representing the second sequence.

All input is received from stdin.

outputFormat

Output a single integer to stdout which is the first position \( k \) (1-indexed) where the sequences differ. If there is no difference, output 0.

## sample
5
10 20 30 40 50
10 20 30 40 50
0