public static void Main()
string atobFlags = Console.ReadLine();
string first = Console.ReadLine();
string second = Console.ReadLine();
bool canSee1 = CanSee(atobFlags, first, second);
bool canSee2 = CanSeeReversed(atobFlags, first, second);
if(canSee1 == true && canSee2 == true)
Console.WriteLine("both");
Console.WriteLine("forward");
Console.WriteLine("backward");
Console.WriteLine("fantasy");
public static bool CanSee(string flags, string first, string second)
int indexFirstStart = flags.IndexOf(first);
int indexFirstEnd = indexFirstStart + first.Length;
int indexSecondStart = flags.IndexOf(second, indexFirstEnd) + indexFirstEnd;
if(indexSecondStart > indexFirstEnd)
public static bool CanSeeReversed(string flags, string first, string second)
for(int i = flags.Length - 1; i >= 0; i--)
for(int j = 0; j < first.Length; j++)
Console.WriteLine("i = " + i + " " + "k = " + k + " " + "equal = " + equal);
for(int j = 0; j < second.Length; j++)
if(flags[k] == second[j])
Console.WriteLine("k = " + k + " " + "equal = " + equal);