Number of steps

2.6

465 votes
Basic Programming, Input/Output
Problem

You are given two arrays a1,a2,,an and b1,b2,,bn. In each step, you can set ai=aibi if aibi. Determine the minimum number of steps that are required to make all a's equal.

Input format

  • First line: n 
  • Second line: a1,a2,,an
  • Third line: b1,b2,,bn

Output format

Print the minimum number of steps that are required to make all a's equal. If it is not possible, then print -1.

Constraints

 0n,ai,bi5000

Sample input

25 64 3

Sample output

-1

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

-

Editor Image

?