using System;
using System.Collections.Generic;
class Program
{
static bool IsPossible(string A, string B, List<int> arr)
{
int N = A.Length;
int M = B.Length;
if (N != M)
{
return false;
}
// Create a 2D boolean array to store if it is possible to
// transform A[0...i] to B[0...j] with the given constraints
bool[,] dp = new bool[N, M];
// Initialize dp[0][0] as true if A[0] == B[0]
dp[0, 0] = (A[0] == B[0]);
// Initialize dp[0][j] for j > 0
for (int j = 1; j < M; j++)
{
dp[0, j] = (A[0] == B[j]);
dp[0, j] = dp[0, j] && !arr.Contains(j);
dp[0, j] = dp[0, j] && dp[0, j - 1];
}
// Initialize dp[i][0] for i > 0
for (int i = 1; i < N; i++)
{
dp[i, 0] = (A[i] == B[0]);
dp[i, 0] = dp[i, 0] && !arr.Contains(i);
dp[i, 0] = dp[i, 0] && dp[i - 1, 0];
}
// Fill the remaining cells of the dp table
for (int i = 1; i < N; i++)
{
for (int j = 1; j < M; j++)
{
dp[i, j] = false;
if (A[i] == B[j])
{
dp[i, j] = dp[i, j] || dp[i - 1, j - 1];
}
if (i > 1 && j > 0 && A[i] == B[j - 1] && A[i - 1] == B[j] && !arr.Contains(j - 1) && !arr.Contains(j))
{
dp[i, j] = dp[i, j] || dp[i - 2, j - 2];
}
if (j > 1)
{
dp[i, j] = dp[i, j] || (A[i] == B[j - 2] && A[i] == B[j - 1] && !arr.Contains(j - 2) && !arr.Contains(j - 1) && dp[i, j - 2]);
}
if (i > 1)
{
dp[i, j] = dp[i, j] || (A[i] == B[j] && A[i - 1] == B[j - 1] && !arr.Contains(j) && !arr.Contains(j - 1) && dp[i - 2, j - 1]);
}
}
}
return dp[N - 1, M - 1];
}
static void Main()
{
string A = "abcabka";
string B = "acbakba";
List<int> arr = new List<int> { 0, 3, 6 };
if (IsPossible(A, B, arr))
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
}
}