/*
Sprendimo autorius: Linas Petrauskas

I assume that x < y, otherwise we swap
"vertical" with "horizontal")

1) if possible, we try to turn rectangle into a
square (if we can make it once, we will surely
"square" our oponent down to 1x1). 

2) if we cannot make a square, we try to make
sure that our opponent won't "square" us too. We
try to reduce y to 2x+1. If it's not possible,
then to 2(2x+1)+1, then to 2(2(2x+1)+1)+1 and so
on... It will be possible to reduce y to one of
these values, unless y already equals one of
them. In this case we're loosing the game.

*/


#include <cstdio>
#include "creclib.h"

    using namespace std;
    
inline int swap(int &a, int &b)
{
    int t = a;
        a = b;
        b = t;
}    

int main()
{
    while (true) {
        int x = dimension_x();
        int y = dimension_y();
        
        direction dir = (x < y) ? horizontal : vertical;
        
        if (x > y) swap(x, y);
        
        if (y <= 2*x && y > x) {
            cut(dir, x);    
        } else {
            int k = x;
            while (2 * k < y)
                k = 2 * k + 1;
            if (k < y)
                cut(dir, k);
            else
                cut(dir, y-1);
        }
    }    
}
