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;

int main() {
    int x,y,ans = 0;
    cin >> x >> y;
    int hx = 0,lx = 0,hy = 0,ly = 0;
    int a = 0,b = 1,c = 0;
    int count = 0;
    int line;
    while(true){
        if(lx <= x && x <= hx && ly <= y && y <= hy){
            ans = count % 3;
            ans = ans + 1;
            break;
        }
        c = a + b;
        a = b;
        b = c;
        line = count % 4;
        if(line == 0)hx += c;
        if(line == 1)hy += c;
        if(line == 2)lx -= c;
        if(line == 3)ly -= c;
        count += 1;
    }
    cout << ans << endl;
}

C++: #include <iostream>
using namespace std;

int x, y, c = 0, sx = 0, sy = 0, i = 1, j = 1;

bool in(int x, int y) {
	if (c % 4 == 0 && sx <= x && sx + j - 1 >= x && sy <= y && sy + j - 1 >= y)
		return true;
	else if (c % 4 == 1 && sx >= x && sx - j + 1 <= x && sy <= y && sy + j - 1 >= y)
		return true;
	else if (c % 4 == 2 && sx >= x && sx - j + 1 <= x && sy >= y && sy - j + 1 <= y)
		return true;
	else if (c % 4 == 3 && sx <= x && sx + j - 1 >= x && sy >= y && sy - j + 1 <= y)
		return true;
	else
		return false;
}

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

	while (!in(x, y)) {
		int m = i + j - 1;

		if (c % 4 == 0)
			sx += m;
		else if (c % 4 == 1)
			sy += m;
		else if (c % 4 == 2)
			sx -= m;
		else
			sy -= m;

		int w = i;
		i = i + j;
		j = w;

		c++;
	}

	cout << (c % 3) + 1 << endl;

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	cin >> x >> y;
	int turn = 0;
	int minx = 0;
	int miny = 0;
	int maxx = 1;
	int maxy = 1;
	while(true){
		if( minx <= x  && x < maxx && miny <= y  && y < maxy){
			break;
		}
		switch(turn%4){
			case 0:// R
				maxx += max(maxx-minx, maxy-miny);
				break;
			case 1:// U
				maxy += max(maxx-minx, maxy-miny);
				break;
			case 2:// L
				minx -= max(maxx-minx, maxy-miny);
				break;
			case 3:// D
				miny -= max(maxx-minx, maxy-miny);
				break;
		}
		++turn;
	}
	
	
	// 1:red, 2:yellow, 3:blue
	cout << (turn%3+1) <<endl;
}

C++: #include <iostream>
using namespace std;

int main(void){
  int x,y,f0,f1,f;
  int swx,swy,nex,ney,col;
  int dir; // E>N>W>S>E...
  
  swx=swy=0; nex=ney=1;
  col = 0; dir = 0;
  cin >> x >> y;
  f0 = 0; f1 = 1;
  while(1){
    //cout << "("<<swx<<","<<swy<<")-("<<nex<<","<<ney<<"): "<<col+1<<endl;
    if (swx<=x && x<nex && swy<=y && y<ney){
      cout << col+1 << endl;
      break;
    }
    // expand
    f = f0+f1;
    switch(dir){
      case 0: nex += f; break;
      case 1: ney += f; break;
      case 2: swx -= f; break;
      case 3: swy -= f; break;
    }
    col = (col+1)%3;
    dir = (dir+1)%4;
    f0=f1; f1=f;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
//グローバル変数(どの関数からでもOK)
int LX,LY,RX,RY;
int sizeX, sizeY;
//プロトタイプ宣言(mainのあとに定義できる)
void dump();//出力用
void addFloor(int);//床を追加
int getColor(int, int);//座標から色を取得
//メイン関数
int main() {
  int x, y;
  cin >> x >> y;
  
  LX = 0; LY = 0;
  RX = 1; RY = 1;
  sizeX = sizeY = 1;
  
  cout << getColor(x, y) << endl;
}

void dump() {
  //出力用
  printf("(%d,%d)(%d,%d)\n",LX,LY,RX,RY);
  return;
}

void addFloor(int d) {
  //d: 次の方向をに床を追加する
  //1:左 2:上 3:右 4:下
  switch(d){
  case 1:
    //left
    RX += sizeY;
    sizeX += sizeY;
    break;
  case 2:
    //up
    RY += sizeX;
    sizeY += sizeX;
    break;
  case 3:
    //right
    LX -= sizeY;
    sizeX += sizeY;
    break;
  case 4:
    //down
    LY -= sizeX;
    sizeY += sizeX;
    break;
  }
  return;
}

int getColor(int x, int y) {
  int color = 1;
  int d = 1;
  for(;;) {
    //dump();
    
    //範囲に入った場合
    if(x >= LX and y >= LY and x < RX and y < RY) break;
    else {
      //床を追加する
      addFloor(d);
      d++;
      color++;
    }
    if(color > 3) color = 1;
    if(d > 4) d = 1;
  }
  return color;
}

C++: #include <iostream>

using namespace std;

int main() {
	int fib[40] = {};
	fib[1] = fib[2] = 1;
	for (int i = 3; i < 40; ++i) fib[i] = fib[i - 1] + fib[i - 2];
	int x, y; cin >> x >> y;
	int i = 0, l = 0, r = 0, u = 0, d = 0;
	while (!(l <= x && x <= r && d <= y && y <= u)) {
		if (i % 4 == 0) r += fib[i + 2];
		else if (i % 4 == 1) u += fib[i + 2];
		else if (i % 4 == 2) l -= fib[i + 2];
		else d -= fib[i + 1];
		i++;
	}
	cout << 1 + i % 3 << endl;

	return 0;
}

C++: #include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll dp[100], d, co;
P a, b;
int main() {
	ll x, y;
	cin >> x >> y;
	a = b = P(0, 0);
	dp[0] = dp[1] = 1;
	REP(i, 80)dp[i + 2] = dp[i + 1] + dp[i];
	REPO(i, 90) {
		if (a.first <= x and b.first >= x and a.second <= y and b.second >= y) {
			cout << co + 1 << endl;
			return 0;
		}
		co = (co + 1) % 3;
		if (d == 0) a = P(a.first + dp[i - 1], a.second), b = P(b.first + dp[i], b.second + dp[i] - dp[i - 1]);
		if (d == 1) a = P(a.first - dp[i] + dp[i - 1], a.second + dp[i - 1]), b = P(b.first, b.second + dp[i]);
		if (d == 2) a = P(a.first - dp[i], a.second - dp[i] + dp[i - 1]), b = P(b.first - dp[i - 1], b.second);
		if (d == 3) a = P(a.first, a.second - dp[i]), b = P(b.first + dp[i] - dp[i - 1], b.second - dp[i - 1]);
		d = (d + 1) % 4;
		//cout << a.first << " " << a.second << " " << b.first << " " << b.second << endl;
  	}
}

C++: #include <cstdio>

// [lx, rx), [dy, uy)
int solve(int lx, int rx, int dy, int uy, int d, int color, int tx, int ty)  {
    if(lx <= tx and tx < rx and dy <= ty and ty < uy) return color;
    // fprintf(stderr, "[%d, %d), [%d, %d), color = %d\n", lx, rx, dy, uy, color);
    
    if(d == 0) rx += (uy - dy);
    if(d == 1) uy += (rx - lx);
    if(d == 2) lx -= (uy - dy);
    if(d == 3) dy -= (rx - lx);
    return solve(lx, rx, dy, uy, (d+1)%4, (color+1)%3, tx, ty);
}

int main() {
    int x, y; scanf("%d%d", &x, &y);
    printf("%d\n", solve(0, 1, 0, 1, 0, 0, x, y) + 1);
}