Company: Infosys_13july
Difficulty: medium
Forbidden Arrangements Problem Description In the land of Zephyria, a grand ritual known as the Cycle of Ascension requires N sages to stand in a perfect sequence from 1 to N. However, two ancient curses have disrupted the process: Hex of Shadows (A): A specific forbidden arrangement A = [A 1 , A 2 , ..., A N ], meaning that sage i cannot stand at position A i . Curse of Starlight (B): Another forbidden arrangement B = [B 1 , B 2 , ..., B N ], meaning that sage i cannot stand at position B i . You want to find the number of valid ways the sages can be arranged while avoiding both forbidden sequences. In other words, Let C denote a valid sequence C = [C 1 , C 2 , ..., C N ] where: No sage i is placed at A[i]. No sage i is placed at B[i]. Find the total number of valid permutations of C that respect these restrictions. Since the answer can be very large return it modulo 10 9 + 7. Input Format The first line contains an integer, N, denoting the number of elements in A. Each line i of the