Hi guys

Problem:https://codeforces.com/contest/1165/problem/E

I don't know why this solution (https://ideone.com/Q3bmkC) works and this (https://ideone.com/YJx6XI) doesn't

Both are the same idea the problem is just with the mod. I thought in the wrong solution that mod is distributed on multiplication so I didn't write (a[i]%mod *b[i]%mod) instead I wrote it as (a[i]*b[i])%mod so can someone explain it to me why this gave WA!