#!/usr/bin/perl use v5.14; use warnings; use constant DEBUG => 0; BEGIN { if (DEBUG) { require DDP; DDP->import; } else { eval 'sub p { }'; } } my $input; if (DEBUG) { $input = *DATA; } else { $input = *STDIN; } my $nr_dots = <$input>; my ($prev_x, $prev_y, $x, $y); my $on_same_line = 1; while ($nr_dots--) { my ($x, $y) = split ' ', <$input>; if (!defined($prev_x)) { ($prev_x, $prev_y) = ($x, $y); } else { if ($x != $prev_x && $y != $prev_y) { $on_same_line = 0; last; } } } say $on_same_line ? 'YES' : 'NO'; __DATA__ 5 0 1 0 2 1 3 0 4 0 5