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 ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int x, y;
VI memo(100, -1);
int fib(int n) {
    if (n <= 2)return 1;
    if (memo[n] != -1)return memo[n];
    return memo[n] = fib(n - 1) + fib(n - 2);
}

int dfs(int sx, int sy, int gx, int gy, int n) {
    int f = fib(n);
    if (n % 4 == 2)gx += f;
    else if (n % 4 == 3)gy += f;
    else if (n % 4 == 0)sx -= f;
    else sy -= f;
    if (sx <= x && x <= gx && sy <= y && y <= gy) {
        if (n % 3 == 1)return 1;
        if (n % 3 == 2)return 2;
        if (n % 3 == 0)return 3;
    }
    return dfs(sx, sy, gx, gy, n + 1);
}

int main() {
    init();

    cin >> x >> y;
    if (x == 0 && y == 0)cout << "1\n";
    else cout << dfs(0, 0, 0, 0, 2) << "\n";
}

C++: #include <bits/stdc++.h>
#define int int64_t
#define fi first
#define se second
#define mod 1000000007
using namespace std;
signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int x,y,p=0;
  int fx=0,fy=0;
  int p1=1,p2=1,p3=0,p4=0,t=0;
  int s[100000];
  s[0]=1,s[1]=1;
  cin>>x>>y;
  while(true){
    if(p3<=x&&x<p1&&p4<=y&&y<p2){
      cout<<p%3+1<<"\n";
      //cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";
      break;
    }
    t++;
    //cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";
    if(p%4==0) p1+=s[t];
    else if(p%4==1) p2+=s[t];
    else if(p%4==2) p3-=s[t];
    else p4-=s[t];
    s[t+1]=s[t-1]+s[t];
    p++;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll i;
  vector<ll> fib;
  fib.push_back(1);
  fib.push_back(2);
  for(i=2;i<60;i++){
    fib.push_back(fib[i-2]+fib[i-1]);
  }
  ll x,y,a=0,b=0,c=0,d=0;
  cin >> x >> y;
  for(i=0;i<60;i++){
    if(x>=a && x<=c && y>=b && y<=d){
      cout << i%3+1 << endl;
      return 0;
    }
    if(i%4==0){
      c+=fib[i];
    }
    else if(i%4==1){
      d+=fib[i];
    }
    else if(i%4==2){
      a-=fib[i];
    }
    else{
      b-=fib[i];
    }
  }
}

C++: #include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int x, y;
	cin >> x >> y;

	int c = 1, d = 0;
	int rx = 0, ry = 0, lx = 0, ly = 0;

	int pre = 1, ppre = 0;
	
	while(1) {

		int now = pre + ppre;

		if (lx <= x && x <= rx && ly <= y && y <= ry) {
			cout << c << endl;
			return 0;
		}

		if (d == 0) {
			rx += now;
		}
		else if (d == 1) {
			ry += now;
		}
		else if (d == 2) {
			lx -= now;
		}
		else if (d == 3) {
			ly -= now;
		}

		//cout << lx << " " << ly << " : " << rx << " " << ry << endl;

		swap(pre, ppre);
		swap(now, pre);

		if (c + 1 == 4) c = 1;
		else c++;

		if (d + 1 == 4) d = 0;
		else d++;
	}
}