Problem:
Score : 200 points

Problem Statement

There are four towns, numbered 1,2,3 and 4.
Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally.
No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.

Determine if we can visit all the towns by traversing each of the roads exactly once.

Constraints

1 \leq a_i,b_i \leq 4(1\leq i\leq 3)

a_i and b_i are different. (1\leq i\leq 3)

No two roads connect the same pair of towns.

Any town can be reached from any other town using the roads.

Input

Input is given from Standard Input in the following format:

a_1 b_1
a_2 b_2
a_3 b_3

Output

If we can visit all the towns by traversing each of the roads exactly once, print YES; otherwise, print NO.

Sample Input 1

4 2
1 3
2 3

Sample Output 1

YES

We can visit all the towns in the order 1,3,2,4.

Sample Input 2

3 2
2 4
1 2

Sample Output 2

NO

Sample Input 3

2 1
3 2
4 3

Sample Output 3

YES

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int nodeSize = 4;
        int edgeSize = 3;
        List<Integer[]> edgeList = new ArrayList<>();
        for (int i = 0; i < edgeSize; i++) {
            int nodeFrom = Integer.parseInt(sc.next());
            int nodeTo = Integer.parseInt(sc.next());
            edgeList.add(new Integer[] { nodeFrom, nodeTo });
        }
        sc.close();

        Map<Integer, HashSet<Integer>> graph = createGraph(nodeSize, edgeList, false);
        int start = 1;
        int target = 4;
        int distance = getDistance(nodeSize, graph, start, target);

        boolean judge = distance == 3;
        String result = judge ? "YES" : "NO";

        // 出力
        System.out.println(result);
    }

    public static Map<Integer, HashSet<Integer>> createGraph(int nodeSize, List<Integer[]> edgeList,
            boolean isDirected) {
        Map<Integer, HashSet<Integer>> graph = new HashMap<>();
        for (int i = 1; i <= nodeSize; i++) {
            graph.put(i, new HashSet<>());
        }
        if (isDirected) {
            for (Integer[] edge : edgeList) {
                graph.get(edge[0]).add(edge[1]);
            }
        } else {
            for (Integer[] edge : edgeList) {
                graph.get(edge[0]).add(edge[1]);
                graph.get(edge[1]).add(edge[0]);
            }
        }
        return graph;
    }

    public static int getDistance(int nodeSize, Map<Integer, HashSet<Integer>> graph, int start, int target) {
        Deque<Integer> deque = new ArrayDeque<>();
        deque.add(start);

        int[] distance = new int[nodeSize + 1];
        distance[start]++;

        int dist = 0;
        while (!deque.isEmpty()) {
            int point = deque.poll();
            if (point == target) {
                dist = distance[point] - 1;
                break;
            }
            for (int nextPoint : graph.get(point)) {
                if (distance[nextPoint] == 0) {
                    deque.add(nextPoint);
                    distance[nextPoint] = distance[point] + 1;
                }
            }
        }

        return dist;
    }
}