Chocolate
InterviewTime limit2sMemory limit512 MB
Given a grid of domino pieces, decide whether a full horizontal or vertical cut can split the bar without cutting through any piece.
- Level
Medium5 of 10
- Topics
- Implementation, Array, Matrix, Brute force
- Solved
- No attempts yet
Problem
Petya loves chocolate very much. Masha loves chocolate very much too. Recently Petya bought a chocolate bar and now he wants to share it with Masha. The chocolate bar is an rectangle filled entirely with small chocolate pieces, each a rectangle.

Petya splits the bar into two parts by breaking it along a line parallel to one of its sides. Neither Petya nor Masha likes broken pieces, so Petya wants to break the bar without damaging any piece.
Help Petya share the chocolate with Masha.
Input
The first line contains two integers and (; at least one of and is even). The next lines contain numbers each: the numbers of the pieces that contain the corresponding cells of the bar. The pieces are numbered from to , and no two pieces share a number.
Output
Print <<Yes>> if Petya can break the bar without damaging any piece. Otherwise print <<No>>.