Problem: ioi05_e
Categories: game, math
Difficulty: easy
Time limit: 1000 ms | Memory limit: 256 MB

This problem was reconstructed to fullfill the interactive problem environment. It differs from the judging system that was available on IOI.

We consider a two-player game. The players are given an $x \times y$ rectangle (where $x$ and $y$ are positive integers). The players take turns moving. A move consists of dividing a rectangle into two rectangles with a single vertical or horizontal cut. The resulting rectangles must have positive integer dimensions.

![](https://ioi.contest.codeforces.com/espresso/fedc778d2b76f4e2b94fb3fe2736f63461f6e0e5.png)

After each cut, the smaller rectangle (that is the one with smaller area) is discarded and the other one is passed to the other player. If the rectangle is cut into two equal halves, then one half is discarded. The player who receives a $1 \times 1$ rectangle, and therefore is not able to make a move, loses the game.

Your task is to write a program to play and win the rectangle game. Initial rectangle sizes are from $1$ to $100\,000\,000$. At least on of them is greater than 1.

Interaction

Before first move and after each oponent's move your program will receive two integers on standard input — current rectangle sizes. When game is end, you will receive two -1.

In respond, you should print your move. Move description contains of symbol «H» or «V» and id of horizontal or vertical cut correspondent.

You can assume that for the test data, there always exists a winning strategy for your program.

Scoring

In 50% of test cases, the dimensions do not exceed 25.

Example

Input

```
4 3

3 2

2 1

-1 -1
```

Output

```
V 1

H 1

V 1
```

Interactor / grader files:
non_adaptive.cpp: // IOI05_E (rec) - Rectangle Game Interactor
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static int queries = 0;
static int query_limit = 100000;

void log_metrics() {
    tout << "queries=" << queries << endl;
    tout << "query_limit=" << query_limit << endl;
}

void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int main(int argc, char* argv[]) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    inf.readLong();  // seed (unused)
    int x = inf.readInt();
    int y = inf.readInt();

    log_metrics();

    cout << x << " " << y << endl;
    cout.flush();

    while (x > 1 || y > 1) {
        char dir;
        int pos;
        if (!(cin >> dir >> pos)) {
            finish(_pe, "Invalid input format");
        }

        queries++;
        if (queries > query_limit) {
            finish(_wa, "Too many moves");
        }

        if (dir == 'V' || dir == 'v') {
            if (pos <= 0 || pos >= x) {
                finish(_wa, "Invalid vertical cut");
            }
            x = max(pos, x - pos);
        } else if (dir == 'H' || dir == 'h') {
            if (pos <= 0 || pos >= y) {
                finish(_wa, "Invalid horizontal cut");
            }
            y = max(pos, y - pos);
        } else {
            finish(_pe, "Invalid direction");
        }

        cout << x << " " << y << endl;
        cout.flush();
    }

    finish(_ok, "Correct");
    return 0;
}

rec_interactor.cpp: // IOI05_E (rec) - Rectangle Game Interactor
// Opponent strategy: always keep the larger piece
#include <bits/stdc++.h>
using namespace std;

int x, y;
int moves = 0;
const int MAX_MOVES = 100000;

void finish(int code, const char* msg) {
    fprintf(stderr, "%s\n", msg);
    // Write to tout.txt for harness
    FILE* tout = fopen("tout.txt", "w");
    if (tout) {
        fprintf(tout, "queries=%d\n", moves);
        fprintf(tout, "query_limit=%d\n", MAX_MOVES);
        fclose(tout);
    }
    exit(code);
}

int main(int argc, char* argv[]) {
    if (argc < 2) {
        finish(2, "Usage: interactor <input_file>");
    }

    FILE* fin = fopen(argv[1], "r");
    if (!fin) {
        finish(2, "Cannot open input file");
    }

    long long seed;
    fscanf(fin, "%lld %d %d", &seed, &x, &y);
    fclose(fin);

    // Send initial dimensions
    printf("%d %d\n", x, y);
    fflush(stdout);

    while (x > 1 || y > 1) {
        char dir;
        int pos;
        if (scanf(" %c %d", &dir, &pos) != 2) {
            finish(2, "PE: Invalid input format");
        }

        moves++;
        if (moves > MAX_MOVES) {
            finish(1, "WA: Too many moves");
        }

        if (dir == 'V' || dir == 'v') {
            if (pos <= 0 || pos >= x) {
                finish(1, "WA: Invalid vertical cut position");
            }
            x = max(pos, x - pos);
        } else if (dir == 'H' || dir == 'h') {
            if (pos <= 0 || pos >= y) {
                finish(1, "WA: Invalid horizontal cut position");
            }
            y = max(pos, y - pos);
        } else {
            finish(2, "PE: Invalid direction");
        }

        printf("%d %d\n", x, y);
        fflush(stdout);
    }

    finish(0, "OK");
    return 0;
}