using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Linq;
class
GFG{
static
bool
check(List<
int
> arr,
List<List<
int
>> pieces)
{
Dictionary<
int
,
int
> m =
new
Dictionary<
int
,
int
>();
for
(
int
i = 0; i < arr.Count; i++)
m.Add(arr[i], i);
for
(
int
i = 0; i < pieces.Count; i++)
{
if
(pieces[i].Count == 1 &&
m.ContainsKey(pieces[i][0]))
{
continue
;
}
else
if
(pieces[i].Count > 1 &&
m.ContainsKey(pieces[i][0]))
{
int
idx = m[pieces[i][0]];
idx++;
if
(idx >= arr.Count)
return
false
;
for
(
int
j = 1; j < pieces[i].Count; j++)
{
if
(arr[idx] == pieces[i][j])
{
idx++;
if
(idx >= arr.Count &&
j < pieces[i].Count - 1)
return
false
;
}
else
{
return
false
;
}
}
}
else
{
return
false
;
}
}
return
true
;
}
static
public
void
Main()
{
List<
int
> arr =
new
List<
int
>(){ 1, 2, 4, 3 };
List<List<
int
> > pieces =
new
List<List<
int
> >();
pieces.Add(
new
List<
int
>(){ 1 });
pieces.Add(
new
List<
int
>(){ 4, 3 });
pieces.Add(
new
List<
int
>(){ 2 });
if
(check(arr, pieces))
{
Console.WriteLine(
"Yes"
);
}
else
{
Console.WriteLine(
"No"
);
}
}
}