there n people 40 type hat label 1 40given 2D integer array hats hatsi list hat prefer ith personreturn number way n people wear different hat othersince answer large return modulo 109 7 Example 1input hat 34455output 1explanation there way choose hat give condition First person choose hat 3 second person choose hat 4 hat 5example 2input hat 35135output 4explanation there 4 way choose hats35 53 13 15example 3input hat 1234123412341234output 24explanation each person choose hat label 1 4number Permutations 1234 24 Constraintsn hatslength1 n 101 hatsilength 401 hatsij 40hatsi contain list unique integer