Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func parseToArray2d(lines []string) [][]int64 {
	var result [][]int64
	for _, line := range lines {
		var parsedLine []int64
		for _, element := range strings.Split(line, " ") {
			n, err := strconv.ParseInt(element, 10, 64)
			if err != nil {
				fmt.Printf("Error: element = %v\n", element)
			}
			parsedLine = append(parsedLine, n)
		}
		result = append(result, parsedLine)
	}
	return result
}

func pop(stack []int64) ([]int64, int64) {
	lenStack := len(stack)
	return stack[0:(lenStack - 1)], stack[lenStack-1]
}

func contains(s []int64, e int64) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	content := []string{}
	for scanner.Scan() {
		line := scanner.Text()
		content = append(content, line)
	}
	arr := parseToArray2d(content)
	x := arr[0][0]
	y := arr[0][1]

	if x == 0 && y == 0 {
		fmt.Println(1)
		return
	}

	filledRange := []int64{1, 0, 0, 0}
	direction := 0
	var prev int64 = 1
	var curr int64 = 1
	xSatisfied := false
	ySatisfied := false
	i := 1
	for ; i < 100; i++ {
		filledRange[direction%4] += curr
		direction++
		// fmt.Println(filledRange)

		if (x >= 0 && x <= filledRange[0]) || (x <= 0 && -x <= filledRange[2]) {
			xSatisfied = true
		}
		if (y >= 0 && y <= filledRange[1]) || (y <= 0 && -y <= filledRange[3]) {
			ySatisfied = true
		}

		if xSatisfied && ySatisfied {
			break
		}

		prev, curr = curr, prev+curr
	}

	fmt.Println(i%3 + 1)
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
bool Contains(int x, int y, P<int> RU, P<int> LD) { //　マス目(x,y)を含んだかどうか判定
	bool flag = true;
	if (x < 0) {
		if (LD.first > x) flag = false;
	}
	else {
		if (RU.first < x) flag = false;
	}
	if (y < 0) {
		if (LD.second > y) flag = false;
	}
	else {
		if (RU.second < y) flag = false;
	}
	return flag;
}
int main() {
	int x, y;
	cin >> x >> y;
	ll fib[200]; // フィボナッチ数列を作る
	fib[1] = fib[2] = 1;
	int nxt = 3;
	while (fib[nxt - 2] + fib[nxt - 1] < upper) {
		fib[nxt] = fib[nxt - 2] + fib[nxt - 1];
		nxt++;
	}
	P<int> RU = { 0,0 }; // 右上と左下だけで大丈夫
	P<int> LD = { 0,0 }; // x,y
	if (x == 0 && y == 0) {
		cout << 1 << endl;
		return 0;
	}
	rep1(i, 1010101) {
		if (i % 4 == 1) { // 右
			RU.first += fib[i + 1];
		}
		if (i % 4 == 2) { // 上
			RU.second += fib[i + 1];
		}
		if (i % 4 == 3) { // 左
			LD.first -= fib[i + 1];
		}
		if (i % 4 == 0) { // 下
			LD.second -= fib[i + 1];
		}
		if (Contains(x, y, RU, LD)) {
			int ans = (i + 1) % 3;
			if (ans == 0) ans += 3;
			cout << ans << endl;
			return 0;
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<ll> fibonacci(ll n){
	vector<ll> dp(max(2LL,n+1),0);
	dp[0] = 0;
	dp[1] = 1;
	for(int i=2;i<n+1;i++){
		dp[i] = dp[i-1] + dp[i-2];
	}
	return dp;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int X=in(),Y=in();
	if(!X && !Y){
		out(1);
		return 0;
	}
	auto F=fibonacci(40);
	int LX=0,LY=0,RX=1,RY=1;

	int C=0;
	REP(i,39){
		C = (C+1)%3;
		int M=i%4;
		if(M==0){
			RX += F[i+2];
		}
		else if(M==1){
			RY += F[i+2];
		}
		else if(M==2){
			LX -= F[i+2];
		}
		else{
			LY -= F[i+2];
		}
		if(LX<=X && X<RX && LY<=Y && Y<RY){
			out(C+1);
			return 0;
		}
	}

	return 0;
}

C++: //yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//<ここに一言>

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};

P nyaxt[4] = {{1,-1},{1,1},{-1,1},{-1,-1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
template <typename T>
T gcd(T a,T b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
template <typename T>
T lcm(T a,T b){
  return a/gcd(a,b)*b;
}
int x,y;
int op(int nw){
	return nw%3+1;
}
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
	int a,b;cin>>a>>b;
	int fib[2] = {0,1};
	P z = {0,0};
	int nw = 0;
	while(true){
		P y;
		y.first = z.first+fib[1]*nyaxt[nw%4].first;
		y.second = z.second+fib[1]*nyaxt[nw%4].second;
		if(nw%4==0){
			if(z.first <= a && a < y.first && y.second < b && b <= z.second){
				cout << op(nw) << endl;
				return 0;
			}
		}else if(nw%4==1){
			if(z.first <= a && a < y.first && z.second < b && b <= y.second){
				cout << op(nw) << endl;
				return 0;
			}
		}else if(nw%4==2){
			if(y.first <= a && a < z.first && z.second < b && b <= y.second){
				cout << op(nw) << endl;
				return 0;
			}
		}else{
			if(y.first <= a && a < z.first && y.second < b && b <= z.second){
				cout << op(nw) << endl;
				return 0;
			}
		}
		z = y;
		fib[0] += fib[1];
		swap(fib[0],fib[1]);
		nw++;
	}

}