maxpain is calculated in 2 ways. The basic open interest method and the cash value method.
The open interest method is not correct, but it is quick and easy to calculate. Here, one simply looks at the combined open interest for both calls and puts. Then, the strike price with highest combine open interest is considered maxpain.
The cash value method is the correct method for determining maxpain.
Assume the stock will close at the first strike price. Determine the intrinsic value of each call option by finding the difference between the stock price and strike price. Remember that an out of the money option has zero intrinsic value. Determine the cash value of each call option by multiplying the intrinsic value by the open interest by 100 shares per contract. Add up all the call cash values to find the cash value of all call contracts at that stock price. Now do the same for put options, calculating intrinsic values, cash values and a total cash value. You now have the total call and put cash values for all options at that stock price.
Now assume the stock will close at the second strike price. Repeat your call and put option calculations to find the total cash values at that price.
Continue repeating for strike prices, assuming the stock price will close at the strike.
Finally, when you have the cash value for each strike price, simply look for the lowest amount. That is the maxpain cash value. The corresponding strike price is maxpain.