Back
Close

Logically reasonable inequalities

Statement

 Goal

We are looking at a system of inequalities. Here all inequalities are simple and consist of one variable on each side. Considering a system of strict inequalities, determine whether this system is inherently consistent or if there is a flaw. A flaw is a contradiction of two or more inequalities, e.g. A > B > C > A. This is not possible from a logical point of view.
Input
Line 1: a positive integer n
The following n lines: inequalities of format LETTER > LETTER
Output
A string "consistent" if all inequalities are consistent or "contradiction" if there is a contradiction found.
Constraints
0 < n < 26
LETTER is a single letter in uppercase
Example
Input
2
A > B
B > C
Output
consistent

Tags
Graphs

Difficulty
Easy

Test cases
Test 1 Test
Input
2 A > B B > C
Output
consistent

Validator 1 Validator
Input
5 A > B B > C C > X X > S S > F
Output
consistent

Test 2 Test
Input
3 A > B B > C C > A
Output
contradiction

Validator 2 Validator
Input
6 A > B B > C C > X X > S S > F F > C
Output
contradiction

Test 3 Test
Input
5 L > Z Z > F F > E E > K L > E
Output
consistent

Validator 3 Validator
Input
18 A > Z Z > G G > D D > K K > C C > O O > U U > F F > B Z > D Z > K Z > F D > C O > F U > B A > D A > K A > B
Output
consistent

Test 4 Test
Input
11 L > Z Z > F B > Z F > E E > K L > E Z > K K > B B > I P > I I > X
Output
contradiction

Validator 4 Validator
Input
21 A > Z Z > R R > E E > K K > F F > O O > L L > C C > P P > N N > M M > C C > B B > T R > F A > P F > L N > R B > E A > F E > K
Output
contradiction

Test 5 Test
Input
3 B > C A > C C > B
Output
contradiction

Validator 5 Validator
Input
3 B > C A > C C > B
Output
contradiction

Solution language

Solution

Stub generator input