Help needed with my solution for MAXAND18

My solution gives me 50 points for subtask 2 but WA for the first subtask.
Can someone help me find where I am going wrong.

Here’s the link to my solution;
Solution

Also the link to the problem;
MAXAND18