def max_carpet_area(h, w): 
    dp = [[0]*(w+1) for _ in range(h+1)] 
    for i in range(1, h+1): 
        for j in range(1, w+1): 
            dp[i][j] = max(dp[i][j], dp[i-1][j] + i*j) 
            for k in range(1, j): 
                dp[i][j] = max(dp[i][j], dp[i][k] + dp[i][j-k]) 
            for k in range(1, i): 
                dp[i][j] = max(dp[i][j], dp[k][j] + dp[i-k][j]) 
    return dp[h][w] 
 
print(max_carpet_area(2, 2))  # 12 
print(max_carpet_area(2, 2))  # 22
