Problem: Construct an N-gon that satisfies the following conditions:

* The polygon is simple (see notes for the definition).
* Each edge of the polygon is parallel to one of the coordinate axes.
* Each coordinate is an integer between 0 and 10^9, inclusive.
* The vertices are numbered 1 through N in counter-clockwise order.
* The internal angle at the i-th vertex is exactly a_i degrees.



In case there are multiple possible answers, you can output any.

Constraints

* 3 ≤ N ≤ 1000
* a_i is either 90 or 270.

Input

The input is given from Standard Input in the following format:


N
a_1
:
a_N


Output

In case the answer exists, print the answer in the following format:


x_1 y_1
:
x_N y_N


Here (x_i, y_i) are the coordinates of the i-th vertex.

In case the answer doesn't exist, print a single `-1`.

Examples

Input

8
90
90
270
90
90
90
270
90


Output

0 0
2 0
2 1
3 1
3 2
1 2
1 1
0 1


Input

3
90
90
90


Output

-1

Solution (in CPP):

Solution:
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
template<class T> struct Deque {
    // deque { 0, 1, 2, 3, 4, 5,};
    // fr { 2, 1, 0 } | bk { 3, 4, 5 };
    vector<T> fr, bk;

    Deque() { }

    template<class Iter> Deque(Iter first, Iter last) : bk(first, last) {}

    size_t size() const {
	return fr.size() + bk.size();
    }

    bool empty() const {
	return fr.empty() && bk.empty();
    }

    T& operator[](size_t i) {
	if (i < fr.size()) return fr[fr.size() - 1 - i];
	return bk[i - fr.size()];
    }

    const T& operator[](size_t i) const {
	if (i < fr.size()) return fr[fr.size() - 1 - i];
	return bk[i - fr.size()];
    }

    T& back() {
	if (bk.empty()) return fr[0];
	return bk.back();
    }

    const T& back() const {
	if (bk.empty()) return fr[0];
	return bk.back();
    }

    void push_back(const T &t) {
	bk.push_back(t);
    }

    template<typename... Args>
    void emplace_back(Args&&... args) {
	bk.emplace_back(forward<Args>(args)...);
    }

    void pop_back() {
	if (bk.empty()) {
	    pop_back_helper(fr, bk);
	} else {
	    bk.pop_back();
	}
    }

    T& front() {
	if (fr.empty()) return bk[0];
	return fr.back();
    }

    const T& front() const {
	if (fr.empty()) return bk[0];
	return fr.back();
    }

    void push_front(const T &t) {
	fr.push_back(t);
    }

    template<typename... Args>
    void emplace_front(Args&&... args) {
	fr.emplace_back(forward<Args>(args)...);
    }

    void pop_front() {
	if (fr.empty()) {
	    pop_back_helper(bk, fr);
	} else {
	    fr.pop_back();
	}
    }

    void reverse() {
	swap(fr, bk);
    }

    static void pop_back_helper(vector<T> &fr, vector<T> &bk) {
	size_t s = fr.size();
	size_t t = (s-1)/2;
	bk.resize(t);
	for (size_t i=1; i<=t; i++) bk[t-i] = fr[i];
	for (size_t i=t+1; i<s; i++) fr[i-t-1] = fr[i];
	fr.resize(s-1-t);
    }

    struct iterator {
	using difference_type   = size_t;
	using value_type        = T;
	using pointer           = T*;
	using reference         = T&;
	using iterator_category = typename vector<T>::iterator::iterator_category;

	using sup_iter = typename vector<T>::iterator;

	sup_iter fr_it, bk_it;
	sup_iter fr_begin, bk_begin;

	iterator(sup_iter fr_it_, sup_iter bk_it_, sup_iter fr_begin_, sup_iter bk_begin_) {
	    fr_it = fr_it_;
	    bk_it = bk_it_;
	    fr_begin = fr_begin_;
	    bk_begin = bk_begin_;
	}

	iterator& operator=(const iterator &y) {
	    fr_it = y.fr_it;
	    bk_it = y.bk_it;
	    fr_begin = y.fr_begin;
	    bk_begin = y.bk_begin;
	    return *this;
	}

	iterator& operator++() {
	    if (fr_it == fr_begin) ++bk_it;
	    else --fr_it;
	    return *this;
	}

	iterator operator++(int) {
	    iterator tmp = *this;
	    ++*this;
	    return tmp;
	}

	iterator& operator--() {
	    if (bk_it == bk_begin) ++fr_it;
	    else --bk_it;
	    return *this;
	}

	iterator operator--(int) {
	    iterator tmp = *this;
	    --*this;
	    return tmp;
	}

	T& operator*() {
	    if (fr_it == fr_begin) return *bk_it;
	    else return *prev(fr_it);
	}

	T* operator->() {
	    if (fr_it == fr_begin) return bk_it;
	    else return prev(fr_it);
	}

	bool operator==(const iterator &y) const { return fr_it == y.fr_it && bk_it == y.bk_it; }
	bool operator!=(const iterator &y) const { return !(*this == y); }

	bool operator<(const iterator &y) const { return fr_it > y.fr_it || bk_it < y.bk_it; }
	bool operator>(const iterator &y) const { return y < *this; }
	bool operator<=(const iterator &y) const { return !(y < *this); }
	bool operator>=(const iterator &y) const { return !(*this < y); }

	size_t operator-(const iterator &y) const {
	    return (bk_it - y.bk_it) + (y.fr_it - fr_it);
	}

	iterator& operator+=(size_t k) {
	    size_t s = fr_it - fr_begin;
	    if (s >= k) {
		fr_it -= k;
	    } else {
		fr_it = fr_begin;
		bk_it += k-s;
	    }
	    return *this;
	}

	iterator operator+(size_t k) const {
	    iterator it = *this;
	    return it += k;
	}

	iterator& operator-=(size_t k) {
	    size_t s = bk_it - bk_begin;
	    if (s >= k) {
		bk_it -= k;
	    } else {
		bk_it = bk_begin;
		fr_it += k-s;
	    }
	    return *this;
	}

	iterator operator-(size_t k) const {
	    iterator it = *this;
	    return it -= k;
	}

    };

    iterator begin() {
	return iterator(fr.end(), bk.begin(), fr.begin(), bk.begin());
    }

    iterator end() {
	return iterator(fr.begin(), bk.end(), fr.begin(), bk.begin());
    }
};

int N;
int A[2011];
int B[2011];
VI G[2011];
int X[2011], Y[2011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);

    bool yes = true;
    if (N % 2) yes = false;
    if (yes) {
	int cnt = 0;
	REP (i, N) {
	    if (A[i] == 90) cnt++;
	    else cnt--;
	}
	if (cnt != 4) yes = false;
    }

    Deque<int> dq;
    if (yes) {
	int len = N;
	REP (i, N) dq.push_back(i);
	int cnt = 0;
	while (cnt <= (int)dq.size()) {
	    if (A[dq[0]] == 270 && A[dq[1]] == 90 && A[dq[2]] == 90) {
		G[len].push_back(dq[0]);
		G[len].push_back(dq[1]);
		G[len].push_back(dq[2]);
		A[len] = 90;
		dq.pop_front();
		dq.pop_front();
		dq.pop_front();
		dq.push_back(len);
		len++;
		cnt = 0;
	    } else {
		int y = dq.front();
		dq.pop_front();
		dq.push_back(y);
		cnt++;
	    }
	}

	if (dq.size() != 4) yes = false;
    }
    if (yes) {
	X[dq[0]] = 1;
	Y[dq[0]] = 1;
	X[dq[1]] = 0;
	Y[dq[1]] = 1;
	X[dq[2]] = 0;
	Y[dq[2]] = 0;
	X[dq[3]] = 1;
	Y[dq[3]] = 0;
	int dir = 0;
	auto getX = [&](int i) {
	    if (dir % 4 == 0) return X[i];
	    if (dir % 4 == 1) return Y[i];
	    if (dir % 4 == 2) return -X[i];
	    if (dir % 4 == 3) return -Y[i];
	    return 0;
	};
	auto getY = [&](int i) {
	    if (dir % 4 == 0) return Y[i];
	    if (dir % 4 == 1) return -X[i];
	    if (dir % 4 == 2) return -Y[i];
	    if (dir % 4 == 3) return X[i];
	    return 0;
	};
	auto putX = [&](int i, int v) {
	    if (dir % 4 == 0) X[i] = v;
	    if (dir % 4 == 1) Y[i] = v;
	    if (dir % 4 == 2) X[i] = -v;
	    if (dir % 4 == 3) Y[i] = -v;
	};
	auto putY = [&](int i, int v) {
	    if (dir % 4 == 0) Y[i] = v;
	    if (dir % 4 == 1) X[i] = -v;
	    if (dir % 4 == 2) Y[i] = -v;
	    if (dir % 4 == 3) X[i] = v;
	};
	while ((int)dq.size() != N) {
	    int p = max_element(dq.begin(), dq.end()) - dq.begin();
	    REP (t, p) {
		int y = dq[0];
		dq.pop_front();
		dq.push_back(y);
		if (A[dq[0]] == 90) dir++;
		else dir += 3;
	    }

	    for (int i=1; i<(int)dq.size(); i++) {
		if (getX(dq[0]) < getX(dq[i])) putX(dq[i], getX(dq[i]) + 1);
		if (getY(dq[0]) > getY(dq[i])) putY(dq[i], getY(dq[i]) - 1);
	    }

	    int a = G[dq[0]][0];
	    int b = G[dq[0]][1];
	    int c = G[dq[0]][2];
	    putX(a, getX(dq[0]));
	    putY(a, getY(dq[0]) - 1);
	    putX(b, getX(dq[0]) + 1);
	    putY(b, getY(dq[0]) - 1);
	    putX(c, getX(dq[0]) + 1);
	    putY(c, getY(dq[0]));
	//    printf("%d %d : %d %d, %d %d, %d %d\n",
	//	    getX(dq[0]), getY(dq[0]),
	//	    getX(a), getY(a),
	//	    getX(b), getY(b),
	//	    getX(c), getY(c));
	    dq.push_back(a);
	    dq.push_back(b);
	    dq.pop_front();
	    dq.push_front(c);

	//    rprintf("%d", dq.begin(), dq.end());
	//    REP (i, dq.size()) {
	//	printf("%d %d, ", getX(dq[i]), getY(dq[i]));
	//    }
	//    puts("");
	}
    }

    if (yes) {
	int x_min = *min_element(X, X+N);
	int y_min = *min_element(Y, Y+N);
	REP (i, N) {
	    printf("%d %d\n", X[i] - x_min, Y[i] - y_min);
	}
    } else {
	puts("-1");
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}