Problem:
Floor
The floor of Dr. Hideyo's house is covered with square tiles. Dr. Hideyo, who has an interest in art, decides to paint the tiles with red, yellow, and blue paint. To begin, he selects one appropriate tile in the room and paint it with the following method.
Change the color of the tile to be painted in the following order: red (number 1 in the figure), yellow (number 2 in the figure), blue (number 3 in the figure), and after blue, start with red again.
Add a square next to the already colored area and color it. The combined area should be a rectangle. Add squares in the following order: east, north, west, south, and after south, start from the east again (in the figure, north is up and east is to the right).
What color are the tiles in the east-west direction $x$ and in the north-south direction $y$ moved from the first tile painted red? Let the east direction be the positive direction of $x$ and the north direction be the positive direction of $y$.
Write a program that takes $x$ and $y$ as input and outputs the color of the tile.
Input
The input is given in the following form.
$x$ $y$
$x$ and $y$ ($-10^6 \leq x,y \leq 10^6$) are given in a line.
Output
Output 1 when the tile color is red, 2 when the tile color is yellow, and 3 when the tile color is blue on one line.
Sample Input and Output
Sample Input 1
0 0
Sample Output 1
1
Sample Input 2
-4 5
Sample Output 2
2
Sample Input 3
8 -14
Sample Output 3
3

Submitted solutions:

code_snippet: #include <iostream>
using namespace std;

int fib(int n)
{
    if(n==0 || n==1) 
        return 1;
    return fib(n-1)+fib(n-2);
}

int main()
{
    int x, y;
    cin >> x >> y;
    int x_min = 0;
    int x_max = 1;
    int y_min = 0;
    int y_max = 1;
    int c = 0;
    while(true){ 
        if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
            cout << c%3+1 << endl;
            return 0;
        }
        // 東 
        c++; 
        x_min = x_max;
        x_max = x_min+fib(c); 
        y_min = y_min; 
        y_max = y_min+fib(c);
        
        if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
            cout << c%3+1 << endl;
            return 0; 
        }
        // 北 
        c++; 
        x_max = x_max; 
        x_min = x_max-fib(c); 
        y_min = y_max; 
        y_max = y_min+fib(c); 
        
        if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
            cout << c%3+1 << endl;
            return 0; 
        }
        // 西 
        c++; 
        x_max = x_min; 
        x_min = x_max-fib(c);
        y_max = y_max; 
        y_min = y_max-fib(c);
 
        if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
            cout << c%3+1 << endl;
            return 0; 
        }
        // 南 
        c++; 
        x_min = x_min; 
        x_max = x_min+fib(c); 
        y_max = y_min; 
        y_min = y_max-fib(c);
    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3104
final_rank: 4

code_snippet: // 2020/07/20 Tazoe
#include <iostream>
using namespace std;
// フィボナッチ数
int fib(int n){
    if(n==0 || n==1) 
        return 1;
    return fib(n-1)+fib(n-2);
}
int main(){
    int x, y;
    cin >> x >> y;
    int x_min = 0;
    int x_max = 1;
    int y_min = 0;
    int y_max = 1;
    int c = 0;
    while(true){ 
        if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
            cout << c%3+1 << endl;
            return 0; 
        }
    // 東 
    c++; 
    x_min = x_max; 
    x_max = x_min+fib(c); 
    y_min = y_min; 
    y_max = y_min+fib(c);
    if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
        cout << c%3+1 << endl;
        return 0; 
    }
    // 北 
    c++; 
    x_max = x_max; 
    x_min = x_max-fib(c); 
    y_min = y_max; 
    y_max = y_min+fib(c);
    if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
        cout << c%3+1 << endl;
        return 0; 
    }
    // 西 
    c++; 
    x_max = x_min; 
    x_min = x_max-fib(c);
    y_max = y_max; 
    y_min = y_max-fib(c);
    if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
        cout << c%3+1 << endl;
        return 0;
    }
    // 南 
    c++; 
    x_min = x_min; 
    x_max = x_min+fib(c); 
    y_max = y_min; 
    y_min = y_max-fib(c);
    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3100
final_rank: 3

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
inline int fib(int n){
    if(n==0||n==1){
        return 1;
    }
    return fib(n-1)+fib(n-2);
}
int main(){
    int x,y;
    cin >> x >> y;

    int xmin=0;
    int xmax=1;
    int ymin=0;
    int ymax=1;
    int c=0;

    while(1){
        if(xmin<=x&&x<xmax&&ymin<=y&&y<ymax){
            cout << c%3+1 <<endl;
            return 0;
        }
        
        c++;
        xmin=xmax;
        xmax=xmin+fib(c);
        ymin=ymin;
        ymax=ymin+fib(c);
        if(xmin<=x&&x<xmax&&ymin<=y&&y<ymax){
            cout << c%3+1 <<endl;
            return 0;
        }

        c++;
        xmax=xmax;
        xmin=xmax-fib(c);
        ymin=ymax;
        ymax=ymin+fib(c);
        if(xmin<=x&&x<xmax&&ymin<=y&&y<ymax){
            cout << c%3+1 <<endl;
            return 0;
        }

        c++;
        xmax=xmin;
        xmin=xmax-fib(c);
        ymax=ymax;
        ymin=ymax-fib(c);
        if(xmin<=x&&x<xmax&&ymin<=y&&y<ymax){
            cout << c%3+1 <<endl;
            return 0;
        }

        c++;
        xmin=xmin;
        xmax=xmin+fib(c);
        ymax=ymin;
        ymin=ymax-fib(c);
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3132
final_rank: 1

code_snippet: #include <iostream>
using namespace std;
// フィボナッチ数
int fib(int n)
{
if(n==0 || n==1) return 1;
return fib(n-1)+fib(n-2);
}
int main()
{
int x, y;
cin >> x >> y;
int x_min = 0;
int x_max = 1;
int y_min = 0;
int y_max = 1;
int c = 0;
while(true){ if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 // 東 
 c++; x_min = x_max; x_max = x_min+fib(c); y_min = y_min; y_max = y_min+fib(c);
 if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 // 北 
 c++; x_max = x_max; x_min = x_max-fib(c); y_min = y_max; y_max = y_min+fib(c);
 if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 // 西 
 c++; x_max = x_min; x_min = x_max-fib(c); y_max = y_max; y_min = y_max-fib(c);
 if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 // 南 
 c++; x_min = x_min; x_max = x_min+fib(c); y_max = y_min; y_min = y_max-fib(c);
}
return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3124
final_rank: 6

code_snippet: #include <iostream>
using namespace std;
// フィボナッチ数
int fib(int n)
{
if(n==0 || n==1) return 1;
return fib(n-1)+fib(n-2);
}
int main()
{
int x, y;
cin >> x >> y;
int x_min = 0;
int x_max = 1;
int y_min = 0;
int y_max = 1;
int c = 0;
while(true){ if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 c++; x_min = x_max; x_max = x_min+fib(c); y_min = y_min; y_max = y_min+fib(c);
 if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 c++; x_max = x_max; x_min = x_max-fib(c); y_min = y_max; y_max = y_min+fib(c);
 if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 c++; x_max = x_min; x_min = x_max-fib(c); y_max = y_max; y_min = y_max-fib(c);
 if(x_min<=x && x<x_max && y_min<=y && y<y_max){ cout << c%3+1 << endl;
return 0; }
 c++; x_min = x_min; x_max = x_min+fib(c); y_max = y_min; y_min = y_max-fib(c);
}
return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3092
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

int fib(int n){
    if(n==0 || n==1){
       return 1; 
    } 
    return fib(n-1)+fib(n-2);
}
int main(){
    int x, y;
    cin >> x >> y;
    int x_min = 0;
    int x_max = 1;
    int y_min = 0;
    int y_max = 1;
    int c = 0;
    while(true){ 
        if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
            cout << c%3+1 << endl;
            return 0; 
        }
        // 東 
        c++; 
        x_min = x_max; 
        x_max = x_min+fib(c); 
        y_min = y_min; 
        y_max = y_min+fib(c);
        if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
            cout << c%3+1 << endl;
            return 0; 
        }
        
        // 北 
        c++; 
        x_max = x_max; 
        x_min = x_max-fib(c); 
        y_min = y_max; 
        y_max = y_min+fib(c);
        if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
            cout << c%3+1 << endl;
            return 0; 
        }
        
        // 西 
        c++; 
        x_max = x_min; 
        x_min = x_max-fib(c);
        y_max = y_max; 
        y_min = y_max-fib(c);
        if(x_min<=x && x<x_max && y_min<=y && y<y_max){ 
            cout << c%3+1 << endl;
            return 0; 
        }
        
        // 南 
        c++; 
        x_min = x_min; 
        x_max = x_min+fib(c); 
        y_max = y_min; 
        y_min = y_max-fib(c);
    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3124
final_rank: 6

code_snippet: // 2020/07/20 Tazoe

#include <iostream>
using namespace std;

// フィボナッチ数
int fib(int n)
{
	if(n==0 || n==1)
		return 1;

	return fib(n-1)+fib(n-2);
}


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

	int x_min = 0;
	int x_max = 1;
	int y_min = 0;
	int y_max = 1;
	int c = 0;

	while(true){
		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 東
		c++;
		x_min = x_max;
		x_max = x_min+fib(c);
		y_min = y_min;
		y_max = y_min+fib(c);

		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 北
		c++;
		x_max = x_max;
		x_min = x_max-fib(c);
		y_min = y_max;
		y_max = y_min+fib(c);

		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 西
		c++;
		x_max = x_min;
		x_min = x_max-fib(c);
		y_max = y_max;
		y_min = y_max-fib(c);

		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 南
		c++;
		x_min = x_min;
		x_max = x_min+fib(c);
		y_max = y_min;
		y_min = y_max-fib(c);
	}

	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3124
final_rank: 6

code_snippet: // 2020/07/20 Tazoe

#include <iostream>
using namespace std;

int fib(int n)
{
	if(n==0 || n==1)
		return 1;

	return fib(n-1)+fib(n-2);
}


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

	int x_min = 0;
	int x_max = 1;
	int y_min = 0;
	int y_max = 1;
	int c = 0;

	while(true){
		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 東
		c++;
		x_min = x_max;
		x_max = x_min+fib(c);
		y_min = y_min;
		y_max = y_min+fib(c);

		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 北
		c++;
		x_max = x_max;
		x_min = x_max-fib(c);
		y_min = y_max;
		y_max = y_min+fib(c);

		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 西
		c++;
		x_max = x_min;
		x_min = x_max-fib(c);
		y_max = y_max;
		y_min = y_max-fib(c);

		if(x_min<=x && x<x_max && y_min<=y && y<y_max){
			cout << c%3+1 << endl;
			return 0;
		}

		// 南
		c++;
		x_min = x_min;
		x_max = x_min+fib(c);
		y_max = y_min;
		y_min = y_max-fib(c);
	}

	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3120
final_rank: 5

code_snippet: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int flag=1,count=0,x,y,minx=0,miny=0,maxx=0,maxy=0,flag2=0,falg3=0;
  vint fi(10000000,0);
  cin>>x>>y;
  if(x==0 && y==0){
    cout<<1<<'\n';
    return(0);
  }
  while(true){
    if(count%4==0){
      if(count==0){
	maxx=1;
	fi[0]=1;
      }
      else{
	fi[count]=fi[count-1]+fi[count-2];
	maxy=fi[count];
      }
    }
    if(count%4==1){
      if(count==1){
	maxy=1;
	fi[1]=1;
      }
      else{
	fi[count]=fi[count-1]+fi[count-2];
	maxx=fi[count];
      }
    }
    if(count%4==2){
      fi[count]=fi[count-1]+fi[count-2];
      minx=fi[count];
    }
    if(count%4==3){
      fi[count]=fi[count-1]+fi[count-2];
      miny=fi[count];
    }
    count++;
    if(x>0 && y>0){
      if(maxy>=y && maxx>=x){
	cout<<count%3+1<<'\n';
	break;
      }
    }
    else if(y>0 && x<0){
      if(maxy>=y && minx+x>=0){
	cout<<count%3+1<<'\n';
	break;
      }
    }
    else if(y<0 && x<0){
      if(miny+y>=0 && minx+x>=0){
	cout<<count%3+1<<'\n';
	break;
      }
    }
    else if(y<0 && x>0){
      if(miny+y>=0 && maxx>=x){
	cout<<count%3+1<<'\n';
	break;
      }
    }      
  }
  return(0);
}
accuracy: 0.1
time_ms: 10
memory_kb: 41772
final_rank: 9