﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            Hangman h = new Hangman(s);
            Play(ref h);
        }

        static void Play(ref Hangman h)
        {
            char[] word = h.GetWord();
            while (h.IsAlive())
            {
                Console.Clear();
                Console.WriteLine("--------------------------------");
                int lives = h.GetLives();
                Console.WriteLine("Lives: " + lives);
                Console.Write("Current Guess: ");
                char[] current = h.GetCurrent();
                for (int i = 0; i < current.Length; ++i)
                {
                    Console.Write(current[i] + " ");
                }
                Console.Write("\nUsed Letters: ");
                List<char> used = h.GetUsed();
                for (int i = 0; i < used.Count; ++i)
                {
                    Console.Write(used[i]);
                    if (used.Count - i != 1)
                    {
                        Console.Write(", ");
                    }
                }
                Console.Write("\nTried Letters: ");
                List<char> tried = h.GetTried();
                for (int i = 0; i < tried.Count; ++i)
                {
                    Console.Write(tried[i]);
                    if (tried.Count - i != 1)
                    {
                        Console.Write(", ");
                    }
                }
                Console.WriteLine("\n--------------------------------");
                Console.Write("Your Guess: ");
                char guess = Convert.ToChar(Console.ReadLine());
                if (!used.Contains(guess) && !tried.Contains(guess))
                {
                    if (word.Contains(guess))
                    {
                        for (int i = 0; i < word.Length; ++i)
                        {
                            if (word[i] == guess)
                            {
                                current[i] = guess;
                            }
                        }
                        h.SetCurrent(current);
                        used.Add(guess);
                        h.SetUsed(used);
                    }
                    else
                    {
                        tried.Add(guess);
                        h.SetTried(tried);
                        h.LoseLife();
                    }
                }
                bool check = true;
                for (int i = 0; i < word.Length; ++i)
                {
                    if (word[i] != current[i])
                    {
                        check = false;
                        break;
                    }
                }
                if (check)
                {
                    break;
                }
            }
            if (!h.IsAlive())
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Game Over!");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Congrats!");
            }
            while (Console.ReadKey().Key != ConsoleKey.Enter) { }
        }
    }

    class Hangman
    {
        private int lives;
        private char[] word;
        private char[] current;
        private List<char> used;
        private List<char> tried;

        public Hangman()
        {
            lives = 5;
            word = "default".ToCharArray();
            current = new char[7];
            for (int i = 0; i < 7; ++i)
            {
                current[i] = '_';
            }
            used = new List<char>();
            tried = new List<char>();
        }

        public Hangman(string s)
        {
            lives = 5;
            word = s.ToCharArray();
            current = new char[s.Length];
            for (int i = 0; i < s.Length; ++i)
            {
                current[i] = '_';
            }
            used = new List<char>();
            tried = new List<char>();
        }

        public bool IsAlive()
        {
            if (lives > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public int GetLives()
        {
            return lives;
        }

        public void LoseLife()
        {
            lives--;
        }

        public char[] GetWord()
        {
            return word;
        }

        public char[] GetCurrent()
        {
            return current;
        }

        public List<char> GetUsed()
        {
            return used;
        }

        public List<char> GetTried()
        {
            return tried;
        }

        public void SetCurrent(char[] c)
        {
            current = c;
        }

        public void SetUsed(List<char> c)
        {
            used = c;
        }

        public void SetTried(List<char> c)
        {
            tried = c;
        }
    }
}