Problem: Problem F Pizza Delivery

Alyssa is a college student, living in New Tsukuba City. All the streets in the city are one-way. A new social experiment starting tomorrow is on alternative traffic regulation reversing the one-way directions of street sections. Reversals will be on one single street section between two adjacent intersections for each day; the directions of all the other sections will not change, and the reversal will be canceled on the next day.

Alyssa orders a piece of pizza everyday from the same pizzeria. The pizza is delivered along the shortest route from the intersection with the pizzeria to the intersection with Alyssa's house.

Altering the traffic regulation may change the shortest route. Please tell Alyssa how the social experiment will affect the pizza delivery route.

Input

The input consists of a single test case in the following format.


$n$ $m$
$a_1$ $b_1$ $c_1$
...
$a_m$ $b_m$ $c_m$


The first line contains two integers, $n$, the number of intersections, and $m$, the number of street sections in New Tsukuba City ($2 \leq n \leq 100 000, 1 \leq m \leq 100 000$). The intersections are numbered $1$ through $n$ and the street sections are numbered $1$ through $m$.

The following $m$ lines contain the information about the street sections, each with three integers $a_i$, $b_i$, and $c_i$ ($1 \leq a_i n, 1 \leq b_i \leq n, a_i \ne b_i, 1 \leq c_i \leq 100 000$). They mean that the street section numbered $i$ connects two intersections with the one-way direction from $a_i$ to $b_i$, which will be reversed on the $i$-th day. The street section has the length of $c_i$. Note that there may be more than one street section connecting the same pair of intersections.

The pizzeria is on the intersection 1 and Alyssa's house is on the intersection 2. It is guaranteed that at least one route exists from the pizzeria to Alyssa's before the social experiment starts.

Output

The output should contain $m$ lines. The $i$-th line should be

* HAPPY if the shortest route on the $i$-th day will become shorter,
* SOSO if the length of the shortest route on the $i$-th day will not change, and
* SAD if the shortest route on the $i$-th day will be longer or if there will be no route from the pizzeria to Alyssa's house.



Alyssa doesn't mind whether the delivery bike can go back to the pizzeria or not.

Sample Input 1


4 5
1 3 5
3 4 6
4 2 7
2 1 18
2 3 12


Sample Output 1


SAD
SAD
SAD
SOSO
HAPPY


Sample Input 2


7 5
1 3 2
1 6 3
4 2 4
6 2 5
7 5 6


Sample Output 2


SOSO
SAD
SOSO
SAD
SOSO


Sample Input 3


10 14
1 7 9
1 8 3
2 8 4
2 6 11
3 7 8
3 4 4
3 2 1
3 2 7
4 8 4
5 6 11
5 8 12
6 10 6
7 10 8
8 3 6


Sample Output 3


SOSO
SAD
HAPPY
SOSO
SOSO
SOSO
SAD
SOSO
SOSO
SOSO
SOSO
SOSO
SOSO
SAD






Example

Input

4 5
1 3 5
3 4 6
4 2 7
2 1 18
2 3 12


Output

SAD
SAD
SAD
SOSO
HAPPY

Solution (in CPP):

Solution:
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (int)(n) ; i++)
#define INF 1e15
#define int long long

struct Edge{
	int a,b,c, id;
};

struct Node{
	int p,c;
};

bool operator < (Node a,Node b){
	return a.c > b.c;
}

vector<int> dijkstra(int s, vector< vector<Edge> > g){
	vector<int> dist(g.size(), INF);
	priority_queue<Node> Q;
	Q.push({s,0});
	while( Q.size() ){
		auto q = Q.top(); Q.pop();
		if( dist[q.p] != INF ) continue;
		dist[q.p] = q.c;
		for( auto e : g[q.p] ){
			Q.push({e.b, q.c + e.c});
		}
	}
	return dist;
}

int visited[100010];
int currentTime = 0;

set<int> bridges;

map< pair<int,int> , int> counter;

int dfs(int x, int p, const vector< vector<Edge> > &g){
	currentTime++;
	visited[x] = currentTime;

	int ans = currentTime;
	for( auto &&e : g[x] ){
		if( e.b == p ) continue;

		if( visited[e.b] != 0 ){
			ans = min(ans, visited[e.b]);
		}else{
			ans = min(ans, dfs(e.b, x, g));
		}
	}
	if( p != -1 && ans > visited[p]){
	
		counter[{x, p}]++;
		counter[{p, x}]++;
	}
	return ans;
}

signed main(){
	int n,m;
	cin >> n >> m;
	vector<Edge> es;
	vector< vector<Edge> > g(n),rg(n);
	for(int i = 0 ; i < m ; i++){
		int a,b,c;
		cin >> a >> b >> c;
		--a,--b;
		es.push_back({a,b,c, i});
		g[a].push_back({a,b,c, i});
		rg[b].push_back({b,a,c, i});
	}

	int S = 0;
	int G = 1;
	auto gDist = dijkstra(S, g);
	auto rgDist = dijkstra(G, rg);
	
	vector< vector<Edge> > dag(n);
	for( auto e : es ){
		if( gDist[e.a] + e.c + rgDist[e.b] == gDist[G] ){
			dag[e.a].push_back(e);
			dag[e.b].push_back({e.b,e.a,e.c,e.id});
		}
	}
	dfs(0, -1, dag);

	for( auto e : es ){
		if( gDist[e.b] + e.c + rgDist[e.a] < gDist[G] ){
			cout << "HAPPY" << endl;
		}else if( gDist[e.a] + e.c + rgDist[e.b] != gDist[G] ){
			cout << "SOSO" << endl;
		}else if( counter[{e.a,e.b}] != 1 ){
			cout << "SOSO" << endl;
		}else{
			cout << "SAD" << endl;
		}
	}
}