Codeforces 1744 D Help needed

I tried to solve this problem. I am getting TLE with this solution but my this solution is accepted. The only difference in this is the calculation of initial power of 2 in the product of ai.

In the TLE solution I calculated the product first:

 ll product = 1;
   for(int i=0;i<n;i++) {
      cin >> a[i];
      product*= a[i];
   }

   int req = n;
   while(product%2==0) product/=2,req--;

and in my accepted solution I calculated initial powers of 2 individually,

   int req = n;
 
   for(int i=0;i<n;i++) {
      cin >> a[i];
      while(a[i]%2==0) a[i]/=2,req--;
   }

I am not getting why the 2nd approach is accepted while 1st one is getting TLE? Can someone please help me to find out what is getting wrong?

you can’t store the product in long long (even in any of the datatype), since ai can be as large as 10^9. Hence even the product of 3 such values will result overflow.