2 arrays
Practice
3.3 (75 votes)
1 D array
Arrays
Data structures
Easy
Problem
91% Success 21613 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given \(2\) arrays \(A\) and \(B\), each of the size \(N\). Each element of these arrays is either a positive integer or \(-1\). The total number of \(-1's\) that can appear over these \(2\) arrays are \(\ge 1\) and \(\le 2\).

Now, you need to find the number of ways in which we can replace each \(-1\) with a non-negative integer, such that the sum of both of these arrays is equal.

Input format

  • First line: An integer \(N\)
  • Second line: \(N\) space-separated integers, where the of these denotes \(A[i]\)
  • Third line: \(N\) space-separated integers, where the \(i^{th}\) of these denotes \(B[i]\)

Output format

If there exists a finite number \(X\), then print it. If the answer is not a finite integer, then print 'Infinite'.

Constraints

\(1 \le N \le 10^5 \)

\(-1 \le A[i],B[i] \le 10^9\)

The \(-1's\) may spread out among both arrays, and their quantity is between \(1\) and \(2\) (both inclusive)

Sample Input 2

4
1 2 -1 4
3 3 -1 1

Sample Output 2

Infinite

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
138 votes
Tags:
ArraysData StructuresEasyOne-dimensional
Points:20
62 votes
Tags:
Arrays1-DData Structures
Points:20
37 votes
Tags:
1-D ArrayArraysData StructuresEasyOne-dimensional