Lattice Convex Polygon

Time limit2sMemory limit128 MB

Summary
Given a rectangle of size M by N, find the maximum number of vertices a convex lattice polygon can have while staying inside it.
Level

Hard8 of 10

Topics
Geometry, Dynamic programming, Number theory, Combinatorics
Solved
No attempts yet

Problem

Consider the rectangle whose opposite corners are (0, 0) and (M, N). We want to draw a convex polygon inside this rectangle. Every vertex of the polygon must have integer coordinates, and each vertex may lie either inside the rectangle or on its boundary.

Given the rectangle size M and N, find the maximum possible number of vertices of such a convex polygon.

Input

The first line contains two natural numbers M and N, separated by a space. Both M and N are at least 3 and at most 200.

Output

Print the maximum possible number of vertices of a convex polygon that can be drawn.

Examples5

  1. Example 1

    Input
    3 3
    
    Expected output
    8
    
  2. Example 2

    Input
    3 50
    
    Expected output
    8
    
  3. Example 3

    Input
    4 4
    
    Expected output
    9
    
  4. Example 4

    Input
    4 5
    
    Expected output
    10
    
  5. Example 5

    Input
    50 200
    
    Expected output
    74