시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB20111052.632%

문제

Juku is learning about electricity and circuits in physics class. He needs to make several measurements in a circuit. It is late and Juku is tired, so he is afraid that he might make mistakes when writing down the results. Juku knows that he can check the validity of measurements using Kirchhoff's voltage law and wants a program that would help him do so.

Kirchhoff's voltage law states that the sum of voltage rises and drops around any closed path has to equal zero. More precisely this means the following. Let us have a circuit with various components, the terminals (ends) of which are connected to nodes. Any number of component terminals can be connected to each node. By connecting a measurement device's (voltmeter's) test probes to two nodes we find out the difference in electric potential (in other words, voltage) between the two nodes. If potential is greater at the node connected to the positive probe than at the node connected to the negative probe, then the device will show a positive number, if it is the other way around, then a negative number, and if electric potential is equal at the two nodes then the result is zero. Kirchhoff's voltage law states that if we form some path consisting of those nodes that ends at the same node it starts from and add up all the rises and falls of electric potential along this path, then the result must be $0$.

You're given a number of electric potential differences Juku measured between some number of pairs of nodes. Determine whether Juku's results agree with Kirchhoff's voltage law.

입력

The first line of the input contains two space-separated integers: number of nodes $N$ ($1 \le N \le 10^5$) and the number of Juku's measurements $M$ ($1 \le M \le 10^5$). Nodes are numbered $1 \ldots N$.

Each of the following $M$ lines contains three space-separated integers $i$, $j$ and $U$: $i$ and $j$ denote nodes ($1 \le i,j \le N$) and $U$ the voltage Juku measured between nodes $i$ and $j$ in volts ($-500\,000 \le U \le 500\,000$) when the positive test probe of the voltmeter was connected to node $i$ and negative one to node $j$.

출력

Write one line to output that contains a single word: JAH if Juku's measurements agree with Kirchhoff's voltage law (there are no contradictions) or EI if they do not agree.

예제 입력 1

3 3
1 2 -3
3 2 2
3 1 5

예제 출력 1

JAH

In this example nothing violates Kirchhoff's voltage law. According to the second line the potential at node $1$ is $3V$ lower than the potential at node $2$ and according to the third line the potential at node $3$ is $2V$ higher than at node $2$. This agrees with the fourth line, which says that the potential at node $3$ is $5V$ higher than at node $1$.

예제 입력 2

4 5
4 4 3
1 2 3
2 1 -3
3 2 7
3 1 5

예제 출력 2

EI

This example violates Kirchhoff's voltage law for several reasons. Let us for example observe the path $1 \rightarrow 2 \rightarrow 3 \rightarrow 1$. The third input line tells us that moving from node $1$ to node $2$ voltage drops by $3V$. Moving from node $2$ to node $3$ voltage rises by $7V$ according to the fifth input line. Lastly, when moving back to node $1$, voltage drops by $5V$ according to the last input line. By adding rises and drops we get $-3 + 7 - 5 = -1$, which is not equal to $0$ and therefore violates Kirchhoff's voltage law.

Another path we can observe is $4 \rightarrow 4$, which according to second input line should mean a difference of $3V$, and thus this line alone already is a contradiction.