I think the problem is related the following line *total += f[i][j] * when[i][j];*
Since f[][] and when[][] are both int, the result may be overflowed. Change the line to *total += 1LL * f[i][j] * when[i][j];* would solve the problem. Also for calculating average, try avoid using float number instead you can check whether* sum > f[i][j] * neighbor* -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/c028672e-ac35-47b3-b13f-8d95107fbc19%40googlegroups.com.