Algorithm


A. Triangle
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle to Peter. Peter said that Bob's triangle is not right-angled, but is almost right-angled: the triangle itself is not right-angled, but it is possible to move one of the points exactly by distance 1 so, that all the coordinates remain integer, and the triangle become right-angled. Bob asks you to help him and find out if Peter tricks him. By the given coordinates of the triangle you should find out if it is right-angled, almost right-angled, or neither of these.

Input

The first input line contains 6 space-separated integers x1, y1, x2, y2, x3, y3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero.

Output

If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER.

Examples
input
Copy
0 0 2 0 0 1
output
Copy
RIGHT
input
Copy
2 3 4 5 6 6
output
Copy
NEITHER
input
Copy
-1 0 2 0 0 1
output
Copy
ALMOST

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <cstdio>
#include <iostream>
#include <algorithm>

bool isRight(int *c){

    int sides[3] = {0};
    sides[0] = (c[4] - c[2]) * (c[4] - c[2]) + (c[5] - c[3])* (c[5] - c[3]); 
    sides[1] = (c[4] - c[0]) * (c[4] - c[0]) + (c[5] - c[1])* (c[5] - c[1]); 
    sides[2] = (c[2] - c[0]) * (c[2] - c[0]) + (c[3] - c[1])* (c[3] - c[1]); 

    std::sort(sides, sides + 3);
    if(sides[0] > 0 && sides[2] == sides[0] + sides[1]){return 1;}
    else{return 0;}
}


int main(){

    int points[6] = {0};
    for(int k = 0; k < 6; k++){scanf("%d", points + k);}

    std::string output = "NEITHER";
    if(isRight(points)){output = "RIGHT";}
    else{
        for(int k = 0; k < 6; k++){
            ++points[k];    if(isRight(points)){output = "ALMOST"; break;}
            points[k] -= 2; if(isRight(points)){output = "ALMOST"; break;}
            ++points[k];
        }
    }

    std::cout << output << std::endl;
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
0 0 2 0 0 1

Output

x
+
cmd
RIGHT
Advertisements

Demonstration


Codeforces Solution-A. Triangle-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+