#K47272. Find the First Difference Position
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:
- An integer \( n \) (\(1 \leq n \leq 10^5\)).
- \( n \) space-separated integers representing the first sequence.
- \( 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.
5
10 20 30 40 50
10 20 30 40 50
0