using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace codeforces
{
    class CodeforcesBeta73
    {
        public static void Main()
        {
            string[] tones = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };
            string[] output = { "major", "minor", "strange" };
            string[] str = Console.ReadLine().Split(' ');

            int[][] ijk = { new int[] { 0, 1, 2 }, new int[] { 2, 0, 1 }, new int[] { 1, 2, 0 }, new int[] { 0, 2, 1 }, new int[] { 1, 0, 2 },new int[]  {2,1,0 } };
            for (int k = 0; k < ijk.Length; k++)
            {
                int[] index = new int[3];
                for (int i = 0; i < tones.Length; i++)
                {
                    if (str[ijk[k][0]] == tones[i])
                        index[0] = i;
                    if (str[ijk[k][1]] == tones[i])
                        index[1] = i;
                    if (str[ijk[k][2]] == tones[i])
                        index[2] = i;
                }

                int diff1 = (index[1] - index[0]) > 0 ? (index[1] - index[0]) : (12 + (index[1] - index[0]));
                int diff2 = (index[2] - index[1]) > 0 ? (index[2] - index[1]) : (12 + (index[2] - index[1]));

                if (diff1 == 4 && diff2 == 3)
                {
                    Console.WriteLine(output[0]);
                    return;
                }
                else if (diff1 == 3 && diff2 == 4)
                {
                    Console.WriteLine(output[1]);
                    return;
                }
            }
            Console.WriteLine(output[2]);
        }
    }

}


using System;
using System.Collections.Generic;
using System.Text;

namespace codeforces_cs
{
    class Program
    {
        static string[] c = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"};
        static Dictionary<string, int> d = new Dictionary<string, int>();
        static int dist(int x, int y)
        {
            return (y - x + 12) % 12;
        }
        static void Main(string[] args)
        {
            for (int i = 0; i < c.Length; i++)
            {
                d[c[i]] = i;
            }

            string input = Console.ReadLine();
            string[] inputs = input.Split(' ');
            List<int> sinputs = new List<int>();
            for (int i = 0; i < 3; i++)
            {
                sinputs.Add(d[inputs[i]]);
            }
            for (int i = 0; i < 12; i++)
            {
                for(int j=0;j<3;j++)
                {
                    sinputs[j] = (sinputs[j]+1)%12;
                }
                sinputs.Sort();
                int X = sinputs[0];
                int Y = sinputs[1];
                int Z = sinputs[2];
                if (dist(X, Y) == 4 && dist(Y, Z) == 3)
                {
                    Console.WriteLine("major");
                    return;
                }
                else if (dist(X, Y) == 3 && dist(Y, Z) == 4)
                {
                    Console.WriteLine("minor");
                    return;
                }
            }
            Console.WriteLine("strange");
        }
    }
}


using System;
using System.Collections.Generic;

namespace Task
{

    class Solve
    {

        private int pos(string a)
        {
            string[] abc = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H",};
            for (int i = 0; i < abc.Length; ++i)
                if (abc[i] == a)
                    return i;
            return int.MinValue;
        }

        private int dist(string a, string b)
        {
            int pa = pos(a), pb = pos(b);
            if (pa < pb)
                return pb - pa;
            else
                return 12 - pa + pb;
        }

        private bool CheckMajor(string x, string y, string z)
        {
            if (dist(x, y) == 4 && dist(y, z) == 3 && dist(x, z) == 7)
                return true;
            else
                return false;
        }

        private bool CheckMinor(string x, string y, string z)
        {
            if (dist(x, y) == 3 && dist(y, z) == 4 && dist(x, z) == 7)
                return true;
            else
                return false;
        }

        public void solve()
        {
            string[] w = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            bool ok = CheckMajor(w[0], w[1], w[2]) | CheckMajor(w[0], w[2], w[1]) | CheckMajor(w[1], w[0], w[2]) |
                      CheckMajor(w[1], w[2], w[0]) | CheckMajor(w[2], w[0], w[1]) | CheckMajor(w[2], w[1], w[0]);

            if (ok)
                Console.WriteLine("major");
            else
            {
                ok = CheckMinor(w[0], w[1], w[2]) | CheckMinor(w[0], w[2], w[1]) | CheckMinor(w[1], w[0], w[2]) |
                     CheckMinor(w[1], w[2], w[0]) | CheckMinor(w[2], w[0], w[1]) | CheckMinor(w[2], w[1], w[0]);
                if (ok)
                    Console.WriteLine("minor");
                else
                    Console.WriteLine("strange");
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            new Solve().solve();
//            Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Contest.A
{
    class Program
    {
        /////////////////////

        public static T Read<T>()
        {
            return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
        }

        public static List<T> ReadList<T>(char[] delimiters = null)
        {
            var line = Read<string>();
            var split = line.Split(delimiters ?? new[] { ' ' });
            var list = split.Select(item => (T)Convert.ChangeType(item, typeof(T))).ToList();
            return list;
        }

        public static List<KeyValuePair<int, T>> ReadIndexedList<T>(char[] delimiters = null)
        {
            var line = Read<string>();
            var split = line.Split(delimiters ?? new[] { ' ' });
            var list = split.Select((item, index) => new KeyValuePair<int, T>(index + 1, (T)Convert.ChangeType(item, typeof(T)))).ToList();
            return list;
        }

        public static void ReadFromFile()
        {
            Console.SetIn(new StreamReader(@"..\..\input.txt"));
        }

        ///////////////////////////////////

        static List<string> notes = new List<string>() { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };

        static void Main(string[] args)
        {
            try
            {
                List<string> readList = ReadList<string>();
                int r = 0;
                foreach (string x in readList)
                {
                    List<string> t = readList.Except(new [] {x}).ToList();
                    string y = t[0];
                    string z = t[1];
                    r = Determine(x, y, z);
                    if (r != 0)
                        break;
                    z = t[0];
                    y = t[1];
                    r = Determine(x, y, z);
                    if (r != 0)
                        break;
                }
                switch (r)
                {
                    case 1:
                        Console.WriteLine("major");
                        break;
                    case 2:
                        Console.WriteLine("minor");
                        break;
                    default:
                        Console.WriteLine("strange");
                        break;
                }
            }
            catch
            {
                Console.Write("strange");
            }
        }

        private static int Determine(string x, string y, string z)
        {
            int xi = notes.IndexOf(x);
            int yi = notes.IndexOf(y);
            int zi = notes.IndexOf(z);
            int a = xi < yi ? yi - xi : notes.Count - xi + yi;
            int b = yi < zi ? zi - yi : notes.Count - yi + zi;
            if (a == 4 && b == 3)
                return 1;
            if (a == 3 && b == 4)
                return 2;
            return 0;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace first
{
    class Program
    {
        static TextReader tr;
        static void cin(out int value)
        {
            if (tr == null) tr = Console.In;
            StringBuilder sb = new StringBuilder();
            while (tr.Peek() == (char)(' ') || tr.Peek() == 13 || tr.Peek() == 10)
                tr.Read();
            while (tr.Peek() != (char)(' ') && tr.Peek() != 13 && tr.Peek() != 10)
            {
                char ch = (char)tr.Read();
                sb.Append(ch);
            }
            value = int.Parse(sb.ToString());
        }
        static void cin(out string value)
        {
            if (tr == null) tr = Console.In;
            StringBuilder sb = new StringBuilder();
            while (tr.Peek() == (char)(' ') || tr.Peek() == 13 || tr.Peek() == 10)
                tr.Read();
            while (tr.Peek() != (char)(' ') && tr.Peek() != 13 && tr.Peek() != 10)
            {
                char ch = (char)tr.Read();
                sb.Append(ch);
            }
            value = sb.ToString();
        }
        static void cin(out double value)
        {
            if (tr == null) tr = Console.In;
            StringBuilder sb = new StringBuilder();
            while (tr.Peek() == (char)(' ') || tr.Peek() == 13 || tr.Peek() == 10)
                tr.Read();
            while (tr.Peek() != (char)(' ') && tr.Peek() != 13 && tr.Peek() != 10)
            {
                char ch = (char)tr.Read();
                if (ch == '.') ch = ',';
                sb.Append(ch);
            }
            value = double.Parse(sb.ToString());
        }
        static void Main(string[] args)
        {
            //int n, m;
            string[] strnots = Console.ReadLine().Split(' ');
            int[] nots = new int[3];
            System.Collections.Generic.Dictionary<string, int> map = new Dictionary<string, int>();
            map.Add("C",0);
            map.Add("C#",1);
            map.Add("D",2);
            map.Add("D#",3);
            map.Add("E",4);
            map.Add("F",5);
            map.Add("F#",6);
            map.Add("G",7);
            map.Add("G#",8);
            map.Add("A",9);
            map.Add("B",10);
            map.Add("H",11);
            nots[0] = map[strnots[0]];
            nots[1] = map[strnots[1]];
            nots[2] = map[strnots[2]];

            if (len(nots[0], nots[1]) == 3 && len(nots[1], nots[2]) == 4 ||
                len(nots[0], nots[2]) == 3 && len(nots[2], nots[1]) == 4 ||
                len(nots[1], nots[2]) == 3 && len(nots[2], nots[0]) == 4 ||
                len(nots[1], nots[0]) == 3 && len(nots[0], nots[2]) == 4 ||
                len(nots[2], nots[1]) == 3 && len(nots[1], nots[0]) == 4 ||
                len(nots[2], nots[0]) == 3 && len(nots[0], nots[1]) == 4

                )
            {
                Console.WriteLine("minor");
            }
            else
            if(
                len(nots[0], nots[1]) == 4 && len(nots[1], nots[2]) == 3 ||
                len(nots[0], nots[2]) == 4 && len(nots[2], nots[1]) == 3 ||
                len(nots[1], nots[2]) == 4 && len(nots[2], nots[0]) == 3 ||
                len(nots[1], nots[0]) == 4 && len(nots[0], nots[2]) == 3 ||
                len(nots[2], nots[1]) == 4 && len(nots[1], nots[0]) == 3 ||
                len(nots[2], nots[0]) == 4 && len(nots[0], nots[1]) == 3
                )
                Console.WriteLine("major");
            else Console.WriteLine("strange");
        }
        static int  len(int a, int b)
        {
            if (b - a > 0) return b - a;
            else return b + 12 - a;
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Chord
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            var notes = new[] {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"};
            string[] ss = reader.ReadLine().Split(' ');

            var nn = new int[3];
            for (int i = 0; i < nn.Length; i++)
            {
                nn[i] = Array.IndexOf(notes, ss[i]);
            }
            Array.Sort(nn);

            if ((nn[1] - nn[0] == 3 && nn[2] - nn[1] == 4) || (nn[2] - nn[1] == 3 && nn[0] + notes.Length - nn[2] == 4) ||
                (nn[0] - nn[2] + notes.Length == 3 && nn[1] - nn[0] == 4))
            {
                writer.WriteLine("minor");
            }
            else if ((nn[1] - nn[0] == 4 && nn[2] - nn[1] == 3) || (nn[2] - nn[1] == 4 && nn[0] + notes.Length - nn[2] == 3) ||
                     (nn[0] - nn[2] + notes.Length == 4 && nn[1] - nn[0] == 3))
            {
                writer.WriteLine("major");
            }
            else
            {
                writer.WriteLine("strange");
            }

            writer.Flush();
        }
    }
}


namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] akk = new int[3];
            for (int i = 0; i < 3; i++)
            {
                switch (input[i])
                {
                    case "C": akk[i] = 0; break;
                    case "C#": akk[i] = 1; break;
                    case "D": akk[i] = 2; break;
                    case "D#": akk[i] = 3; break;
                    case "E": akk[i] = 4; break;
                    case "F": akk[i] = 5; break;
                    case "F#": akk[i] = 6; break;
                    case "G": akk[i] = 7; break;
                    case "G#": akk[i] = 8; break;
                    case "A": akk[i] = 9; break;
                    case "B": akk[i] = 10; break;
                    case "H": akk[i] = 11; break;
                    default: akk[i] = -1; break;
                }
            }
            int type = 0;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int k = 3 - (i + j);
                    if (d(akk[i], akk[j]) == 7)
                    {
                        if ((d(akk[i], akk[k]) == 4) & (d(akk[k], akk[j]) == 3)) { type = 1; break; }
                        else if ((d(akk[i], akk[k]) == 3) & (d(akk[k], akk[j]) == 4)) type = -1;
                    }
                }
            }
            switch (type)
            {
                case 1: Console.Write("major"); break;
                case -1: Console.Write("minor"); break;
                default: Console.Write("strange"); break;
            }
        }
        static int d(int a1, int a2)
        {
            if (a2 >= a1) return a2 - a1; else return 12 - (a1 - a2);
        }
    }
}


Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "A", "A\A.csproj", "{7C02893E-192C-4692-BDCC-E2D81901F781}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|x86 = Debug|x86
		Release|x86 = Release|x86
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{7C02893E-192C-4692-BDCC-E2D81901F781}.Debug|x86.ActiveCfg = Debug|x86
		{7C02893E-192C-4692-BDCC-E2D81901F781}.Debug|x86.Build.0 = Debug|x86
		{7C02893E-192C-4692-BDCC-E2D81901F781}.Release|x86.ActiveCfg = Release|x86
		{7C02893E-192C-4692-BDCC-E2D81901F781}.Release|x86.Build.0 = Release|x86
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A88
{
    class Program
    {
        static String[] temp = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };

        static int Count(string x, string y)
        {
            bool boolya = false;
            int count = 0;
            int i = 0;
            while (true)
            {
                if (temp[i].Equals(x))
                {
                    boolya = true;
                    i++;
                    if (i == 12)
                        i = 0;
                }
                if (!(boolya))
                {
                    i++;
                    if (i == 12)
                        i = 0;
                }
                if (boolya && (!(temp[i].Equals(x))) && (!(temp[i].Equals(y))))
                {
                    count++;
                    i++;
                    if (i == 12)
                        i = 0;
                }
                if (boolya && (temp[i].Equals(y)))
                {
                    break;
                }

            }
            return count++;
        }
        static void Main(string[] args)
        {
            String[] s = Console.ReadLine().Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
            int flag = 0;
            int r = Count(s[0], s[1]);
            int l = Count(s[1], s[2]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            r = Count(s[0], s[2]);
            l = Count(s[2], s[1]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            r = Count(s[1], s[0]);
            l = Count(s[0], s[2]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            r = Count(s[1], s[2]);
            l = Count(s[0], s[2]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            r = Count(s[2], s[0]);
            l = Count(s[0], s[1]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            r = Count(s[2], s[1]);
            l = Count(s[1], s[0]);
            if (r == 4 && l == 3)
                flag = 1;
            else
                if (r == 3 && l == 4)
                    flag = 2;
            switch (flag)
            {
                case 0:
                    Console.WriteLine("strange");
                    break;
                case 1:
                    Console.WriteLine("major");
                    break;
                case 2:
                    Console.WriteLine("minor");
                    break;
                default:
                    break;
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace codeforces
{
    class CodeforcesBeta73
    {
        public static void Main() {
            string[] tones = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };
            string[] output = { "major", "minor", "strange" };
            string[] str = Console.ReadLine().Split(' ');

            int[][] ijk = { new int[] { 0, 1, 2 }, new int[] { 2, 0, 1 }, new int[] { 1, 2, 0 }, new int[] { 0, 2, 1 }, new int[] { 1, 0, 2 } };
            for (int k = 0; k < ijk.Length; k++)
            {
                int[] index = new int[3];
                for (int i = 0; i < tones.Length; i++)
                {
                    if (str[ijk[k][0]] == tones[i])
                        index[0] = i;
                    if (str[ijk[k][1]] == tones[i])
                        index[1] = i;
                    if (str[ijk[k][2]] == tones[i])
                        index[2] = i;
                }

                int diff1 = (index[1] - index[0]) > 0 ? (index[1] - index[0]) : (12 + (index[1] - index[0]));
                int diff2 = (index[2] - index[1]) > 0 ? (index[2] - index[1]) : (12 + (index[2] - index[1]));

                if (diff1 == 4 && diff2 == 3)
                {
                    Console.WriteLine(output[0]);
                    return;
                }
                else if (diff1 == 3 && diff2 == 4)
                {
                    Console.WriteLine(output[1]);
                    return;
                }
            }
                Console.WriteLine(output[2]);
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;

public class CF_Chord
{
    static string[] N = new string[] { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H" };

    public static int dist(string a, string b)
    {
        int pos1 = Array.IndexOf(N, a);
        int pos2 = Array.IndexOf(N, b);
        int d = Math.Abs(pos2 - pos1) % 12;
        return Math.Min(d, 12 - d);
    }

    public static string chord(string a, string b, string c)
    {
        int d1 = dist(a, b);
        int d2 = dist(b, c);

        string ans = "strange";
        if (d1 == 4 && d2 == 3) ans = "major";
        else if (d1 == 3 && d2 == 4) ans = "minor";
        return ans;
    }

    public static void Main(string[] args)
    {
        string[] notes = Console.ReadLine().Split();
        int n = notes.Length;
        string a = notes[0];
        string b = notes[1];
        string c = notes[2];
        int d1 = dist(notes[0], notes[1]);
        int d2 = dist(notes[1], notes[2]);

        string ans = chord(a, b, c);
        if (ans == "strange") ans = chord(a, c, b);
        if (ans == "strange") ans = chord(b, a, c);
        if (ans == "strange") ans = chord(b, c, a);
        if (ans == "strange") ans = chord(c, a, b);
        if (ans == "strange") ans = chord(c, b, a);

        Console.WriteLine(ans);
        Console.ReadLine();
    }
}


using System;
using static System.Console;
namespace ConsoleScratch
{
    class Program
    {
        static void Main()
        {
            var a = ReadLine().ToCharArray();
            char c = 'z';
            for (int i = a.Length - 1; i >= 0 && c != '`'; i--)
            {
                if (a[i] <= c) { a[i] = c--; }
            }
            WriteLine(c == '`' ? string.Concat(a) : "-1");
        }
    }
}


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

namespace Problem946C
{
    class Program
    {
        static void Main(string[] args)
        {
            string al = "abcdefghijklmnopqrstuvwxyz";
            StringBuilder inp = new StringBuilder(Console.ReadLine());

            int ilp, inpp;
            for (ilp = 0, inpp = 0; ilp < al.Length && inpp < inp.Length; inpp++)
            {
                if (inp[inpp] <= al[ilp])
                {
                    inp[inpp] = al[ilp];
                    ilp++;
                }
            }

            if (ilp < al.Length)
                Console.WriteLine("-1");
            else
                Console.WriteLine(inp.ToString());
        }
    }
}


using System;

namespace CSharp
{
    class _946C
    {
        public static void Main()
        {
            var s = Console.ReadLine().ToCharArray();

            int i = 0;
            for (char c = 'a'; c <= 'z'; c++)
            {
                while (i < s.Length && s[i] > c)
                {
                    i++;
                }

                if (i < s.Length)
                {
                    s[i++] = c;
                }
                else
                {
                    Console.WriteLine(-1);
                    return;
                }
            }

            Console.WriteLine(new string(s));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace CF
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
//       using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
                //using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var s = sr.NextString().ToCharArray();
            var currCh = 0;
            for (var i = 0; i < s.Length; i++) {
                if (currCh <= 25) {
                    if (currCh >= (s[i] - 'a')) {
                        s[i] = (char) ('a' + currCh);
                        currCh++;
                    }
                }
                else {
                    break;
                }
            }

            if (currCh >= 26) {
                sw.WriteLine(new string(s));
            }
            else {
                sw.WriteLine(-1);
            }
        }

        ~Task()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Compete.CFE39 {
    public class TaskC  {
        public static void Main(string[] args) {
            new TaskC().Solve(Console.In, Console.Out);
        }

        public void Solve(TextReader input, TextWriter output) {
            // INPUT
            var s = input.ReadLine();
            var n = s.Length;

            // SOLUTION
            var next = 'a';
            var c = new List<char>();
            for (var i = 0; i < n; i++) {
                if (next <= 'z') {
                    if (s[i] > next) { c.Add(s[i]); } // cut
                    else /* c[i] <= next */ { c.Add(next); next++; } // replace
                }
                else c.Add(s[i]);
            }
            var rv = next <= 'z' ? "-1" : new string(c.ToArray());

            // OUTPUT
            output.WriteLine(rv);
        }
    }
}


using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        string s = sc.Next();

        int n = s.Length;

        // 文字列 s
        // 任意の文字を次の文字にできる
        // abcde.... wxyzができる部分文字列

        string abc = "abcdefghijklmnopqrstuvwxyz";
        int index = 0;
        char[] ans = s.ToArray();
        for(int i = 0;i < n; i++)
        {
            if(index < 26 && ans[i] <= abc[index])
            {
                ans[i] = abc[index];
                index++;
            }
        }
        if(index < 26)
        {
            Console.WriteLine("-1");
            return;
        }

        Console.WriteLine(new string(ans));
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;

namespace G4
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] Steps = new int[10];
            Steps[0] = 1;
            for (int i = 1; i < 10; i++)
            {
                Steps[i] = Steps[i - 1] * 10;
            }

            string sin = Console.ReadLine();
            char[] FO = new char[sin.Length];

            byte n = 97;
            for (int i = 0; i < sin.Length; i++)
            {
                if (((byte)sin[i] <= n) && (n < 123))
                {
                    FO[i] = (char)n;
                    n++;
                }
                else
                {
                    FO[i] = sin[i];
                }
            }

            if (n > 122)
            {
                Console.Write(buffer : FO);
            }
            else
            {
                Console.Write("-1");
            }
        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] s = Console.ReadLine().ToArray();
            char curr = 'a';
            for(int i = 0; i < s.Length; i++)
            {
                if(s[i] <= curr)
                {
                    s[i] = curr;
                    curr++;
                    if(curr > 122)
                    {
                        foreach(char c in s)
                        {
                            Console.Write(c);
                        }
                        return;
                    }
                }
            }
            Console.WriteLine("-1");
            return;
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace String_Transformation
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            Solve(args);
            writer.Flush();
        }

        private static void Solve(string[] args)
        {
            char[] s = reader.ReadLine().ToCharArray();

            int index = 0;
            for (char i = 'a'; i <= 'z'; i++)
            {
                while (index < s.Length && s[index] > i)
                {
                    index++;
                }
                if (index < s.Length)
                    s[index] = i;
                else
                {
                    writer.WriteLine("-1");
                    return;
                }
                index++;
            }

            writer.WriteLine(new string(s));
        }
    }
}


using System;
using System.Text;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            StringBuilder result = new StringBuilder("", input.Length);
            bool found = false;
            string last = "";
            int current = 97;
            //97-122
            if (input.Length >= 26)
                for (int i = 0; i < input.Length; i++)
                {
                    if (input[i] <= current)
                    {
                        result.Append((char)current);
                        current++;
                    }
                    else
                        result.Append(input[i]);
                    if (current > 122)
                    {
                        found = true;
                        if (i != input.Length - 1)
                            last = input.Substring(i + 1);
                        break;
                    }
                }
            if (found)
                Console.WriteLine(result + last);
            else
                Console.WriteLine("-1");

            Console.ReadLine();
        }
    }
}


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

namespace CodeForces
{
   class C
   {
      static void Main(string[] args)
      {
        string s = Console.ReadLine();

        string A = "abcdefghijklmnopqrstuvwxyz";

        char[] arr = s.ToCharArray();

        int cnt = 0;

        for(int i=0;i<s.Length;i++){
          if(cnt<26){
            if(s[i]<=A[cnt]){
              arr[i] = A[cnt];
              cnt++;
            }
          }
        }

          if(cnt<=25){
            Console.WriteLine(-1);
          }else{
            string ans = new string(arr);
            Console.WriteLine(ans);
          }

        }
      }
   }


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

namespace Code
{
    public class Program
    {

        static string Read()
        {
            var a = Convert.ToChar(Console.Read());
            var t = new StringBuilder();

            while (a != ' ' && a != '\r' && a != '\n')
            {
                t.Append(a);
                a = Convert.ToChar(Console.Read());
            }
            return t.ToString();
        }

        static int ReadNum()
        {
            return int.Parse(Read());
        }

        static ulong ReadUNum()
        {
            return ulong.Parse(Read());
        }

        public static void Main()
        {
            var a = 97;
            var sb = new StringBuilder();

            var r = Console.Read();
            var c = Convert.ToChar(r);
            while (c != '\r' && c != '\n')
            {
                if (a != 123)
                {
                    if (r <= a)
                    {
                        c = Convert.ToChar(a);
                        a++;
                    }
                }
                sb.Append(c);
                r = Console.Read();
                c = Convert.ToChar(r);
            }

            if (a != 123) Console.WriteLine(-1);
            else Console.WriteLine(sb.ToString());
        }
    }
}


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

namespace ProblemC
{
	public class Problem
	{
		string s;

		public int[] ReadLine()
		{
			return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
		}

		public Problem()
		{
			s = Console.ReadLine();
		}

		public void Solve()
		{
			var i = 0;
			var c = 'a';
			var st = "abcdefghijklmnopqrstuvwxyz";
			for (; i < s.Length; i++)
			{
				if (s[i] <= c)
					c++;
				else
					c = 'a';
				if (c > 'z')
				{
					i++;
					break;
				}
			}
			if (c <= 'z')
				Console.WriteLine(-1);
			else
				Console.WriteLine(s.Substring(0, i - 26) + st + s.Substring(i));
		}
	}

	class ProblemC
	{
		static void Main(string[] args)
		{
			new Problem().Solve();
		}
	}
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Compete.CFE39 {
    public class TaskC {
        public static void Main(string[] args) {
            new TaskC().Solve(Console.In, Console.Out);
        }

        public void Solve(TextReader input, TextWriter output) {
            // INPUT
            var s = input.ReadLine();
            var n = s.Length;

            // SOLUTION
            var next = 'a';
            var i = 0;
            var rv = new List<char>();
            while (i < n && next <= 'z') {
                if (s[i] > next) { rv.Add(s[i]); i++; } // cut
                else /* c[i] <= next */ { rv.Add(next); next++; i++; } // replace
            }
            var result = next <= 'z' ? "-1" : new string(rv.ToArray());

            // OUTPUT
            output.WriteLine(result);
        }
    }
}


using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            bool found = false;
            int firstIndex = -1;
            string last = "";
            int current = 97;
            //97-122
            if (input.Length >= 26)
                for (int i = 0; i < input.Length; i++)
                {
                    if (input[i] <= current)
                    {
                        current++;
                        if (firstIndex == -1)
                            firstIndex = i;
                    }
                    if (current > 122)
                    {
                        found = true;
                        if (i != input.Length - 1)
                            last = input.Substring(i);
                        break;
                    }
                }
            if (found)
                Console.WriteLine(input.Substring(0, firstIndex) + "abcdefghijklmnopqrstuvwxyz" + last);
            else
                Console.WriteLine("-1");

            Console.ReadLine();
        }
    }
}


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

namespace CodeForces
{
   class C
   {
      static void Main(string[] args)
      {
        string s = Console.ReadLine();

        string A = "abcdefghijklmnopqrstuvwxyz";

        char[] arr = s.ToCharArray();

        int cnt = 0;

        for(int i=0;i<s.Length;i++){
          if(cnt<26){
            if(s[i]<=A[cnt]){
              arr[i] = A[cnt];
              cnt++;

            }
          }
        }

          if(cnt<25){
            Console.WriteLine(-1);
          }else{
            string ans = "";
            for(int i=0;i<arr.Length;i++){
              ans += arr[i].ToString();
            }
            Console.WriteLine(ans);
          }

        }
      }
   }


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

namespace ProblemC
{
	public class Problem
	{
		string s;

		public int[] ReadLine()
		{
			return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
		}

		public Problem()
		{
			s = Console.ReadLine();
		}

		public void Solve()
		{
			var i = 0;
			var c = 'a';
			var st = "abcdefghijklmnopqrstuvwxyz";
			for (; i < s.Length; i++)
			{
				if (s[i] <= c)
					c++;
				else
					c = 'a';
				if (c > 'z')
				{
					i++;
					break;
				}
			}
			if (i < 26)
				Console.WriteLine(-1);
			else
				Console.WriteLine(s.Substring(0, i - 26) + st + s.Substring(i));
		}
	}

	class ProblemC
	{
		static void Main(string[] args)
		{
			new Problem().Solve();
		}
	}
}


using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            bool found = false;
            int current = 97;
            //97-122
            if (input.Length >= 26)
                for (int i = 0; i < input.Length; i++)
                {
                    if (input[i] <= current)
                        current++;
                    if (current == 122)
                    {
                        found = true;
                        break;
                    }
                }
            if (found)
                Console.WriteLine("abcdefghijklmnopqrstuvwxyz");
            else
                Console.WriteLine("-1");

            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Compete.CFE39 {
    public class TaskC {
        public static void Main(string[] args) {
            new TaskC().Solve(Console.In, Console.Out);
        }

        public void Solve(TextReader input, TextWriter output) {
            // INPUT
            var s = input.ReadLine();
            var n = s.Length;

            // SOLUTION
            var next = 'a';
            var i = 0;
            var rv = new List<char>();
            while (i < n && next <= 'z') {
                if (s[i] > next) { i++; } // cut
                else /* c[i] <= next */ { rv.Add(next); next++; i++; } // use
            }
            var result = next <= 'z' ? "-1" : new string(rv.ToArray());

            // OUTPUT
            output.WriteLine(result);
        }
    }
}


using System;

class MainClass {
    static void Main() {
        int c;
        int i = 0;
        while ((c = Console.Read()) != -1)
            i++;
        Console.WriteLine(i);
    }
}


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

namespace ProblemC
{
	public class Problem
	{
		string s;

		public int[] ReadLine()
		{
			return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
		}

		public Problem()
		{
			s = Console.ReadLine();
		}

		public void Solve()
		{
			var i = 0;
			var c = 'a';
			var st = "abcdefghijklmnopqrstuvwxyz";
			for (; i < s.Length; i++)
			{
				if (s[i] <= c)
					c++;
				else
					c = 'a';
				if (c > 'z')
					break;
			}
			i++;
			Console.WriteLine(s.Substring(0, i - 26) + st + s.Substring(i));
		}
	}

	class ProblemC
	{
		static void Main(string[] args)
		{
			new Problem().Solve();
		}
	}
}


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

namespace CodeForces
{
   class C
   {
      static void Main(string[] args)
      {
        string s = Console.ReadLine();

        string A = "abcdefghijklmnopqrstuvwxyz";

        char[] arr = s.ToCharArray();

        int cnt = 0;

        for(int i=0;i<s.Length;i++){
          if(cnt<26){
            if(s[i]<=A[cnt]){
              arr[i] = A[cnt];
              cnt++;

            }
          }
        }

          if(cnt<=25){
            Console.WriteLine(-1);
          }else{
            string ans = "";
            for(int i=0;i<arr.Length;i++){
              ans += arr[i].ToString();
            }
            Console.WriteLine(ans);
          }

        }
      }
   }


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		for(int i=0;i<4;i++){
			if(Inside(A[2*i], A[2*i+1], B)){
				Console.WriteLine("YES");
				return;
			}
			if(Inside(B[2*i], B[2*i+1], A)){
				Console.WriteLine("YES");
				return;
			}
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(OnLine(A[2*i], A[2*i+1], B[2*j], B[2*j+1], B[(2*j+2)%8], B[(2*j+3)%8])){
					Console.WriteLine("YES");
					return;
				}
				if(OnLine(B[2*i], B[2*i+1], A[2*j], A[2*j+1], A[(2*j+2)%8], A[(2*j+3)%8])){
					Console.WriteLine("YES");
					return;
				}
			}
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(Intersects(A[2*i], A[2*i+1], A[(2*i+2)%8], A[(2*i+3)%8], B[2*j], B[2*j+1], B[(2*j+2)%8], B[(2*j+3)%8])){
					Console.WriteLine("YES");
					return;
				}
			}
		}
		Console.WriteLine("NO");

	}

	bool Inside(int x, int y, int[] rect){
		var h = new HashSet<int>();
		for(int i=0;i<4;i++){
			var d = det(rect[2*i] - x, rect[2*i+1] - y, rect[(2*i+2)%8] - x, rect[(2*i+3)%8] - y);
			if(d == 0) return false;
			d = d > 0 ? 1 : -1;
			h.Add(d);
		}
		return h.Count == 1;
	}
	bool OnLine(int x, int y, int x1, int y1, int x2, int y2){
		if(x == x1 && y == y1) return true;
		if(x == x2 && y == y2) return true;
		if(det(x1 - x, y1 - y, x2 - x, y2 - y) != 0) return false;
		return (x1 - x) * (x2 - x) + (y1 - y) * (y2 - y) < 0;
	}
	bool Intersects(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){

		int d0 = det0(x3 - x1, y3 - y1, x2 - x1, y2 - y1);
		int d1 = det0(x4 - x1, y4 - y1, x2 - x1, y2 - y1);
		if(d0 == 0 || d1 == 0 || d0 == d1) return false;
		int d2 = det0(x1 - x3, y1 - y3, x4 - x3, y4 - y3);
		int d3 = det0(x2 - x3, y2 - y3, x4 - x3, y4 - y3);
		if(d2 == 0 || d3 == 0 || d2 == d3) return false;
		return true;

	}

	int det (int a, int b, int c, int d){
		return a * d - b * c;
	}
	int det0 (int a, int b, int c, int d){
		var ret = a * d - b * c;
		if(ret == 0) return 0;
		if(ret > 0) return 1;
		return -1;
	}

	int[] A, B;
	public Sol(){
		A = ria();
		B = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      var q1x = new int[4];
      var q1y = new int[4];
      var q2x = new int[4];
      var q2y = new int[4];
      for (var i = 0; i < 4; i++)
      {
        q1x[i] = input.ReadInt();
        q1y[i] = input.ReadInt();
      }
      for (var i = 0; i < 4; i++)
      {
        q2x[i] = input.ReadInt();
        q2y[i] = input.ReadInt();
      }
      var x1min = q1x.Min();
      var y1min = q1y.Min();
      var x1max = q1x.Max();
      var y1max = q1y.Max();
      var x2min = q2x.Min();
      var y2min = q2y.Min();
      var x2max = q2x.Max();
      var y2max = q2y.Max();
      var d = (x2max - x2min) / 2;
      for (var x = Max(x1min, x2min); x <= Min(x1max, x2max); x++)
      {
        for (var y = Max(y1min, y2min); y <= Min(y1max, y2max); y++)
        {
          if (x >= x1min && x <= x1max &&
              y >= y1min && y <= y1max &&
              x >= x2min && x <= x2max &&
              y >= y2min && y <= y2max)
          {
            var x0 = x - x2min - d;
            var y0 = y - y2min - d;
            if (x0 + y0 <= d &&
                x0 + y0 >= -d &&
                y0 - x0 <= d &&
                y0 - x0 >= -d)
            {
              Write("YES");
              return;
            }
          }
        }
      }
      Write("NO");
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private readonly TextReader reader;

    public string ReadToEnd()
    {
      return reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = reader.Read();
        if (c == -1)
          throw new EndOfStreamException("Digit expected, but end of stream occurs");
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
      var result = (char)c - '0';
      c = reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
        result = result * 10 + (char)c - '0';
        c = reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public (int, int) Read2Int() =>
      (ReadInt(), ReadInt());

    public (int, int, int) Read3Int() =>
      (ReadInt(), ReadInt(), ReadInt());

    public (int, int, int, int) Read4Int() =>
      (ReadInt(), ReadInt(), ReadInt(), ReadInt());

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      var c = reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main()
    {
      var solver = new ProblemSolver(In);
      solver.Solve();
    }
  }

  #endregion
}


using System;
using System.IO;

class CF
{
	static Stream stdin = Console.OpenStandardInput();
	static byte[] buf = new byte[16 << 10];
	static int cap = 1;
	static int pos = 1;
	public static byte nextByte()
	{
		if (cap == 0) return 0;
		if (pos == cap)
		{
			cap = stdin.Read(buf, 0, 16 << 10);
			if (cap == 0) return 0;
			pos = 0;
		}
		return buf[pos++];
	}
	public static int nextInt()
	{
		byte c = nextByte();
		while ((c < '0' || c > '9') && c != '-') c = nextByte();
		int sign = 1;
		if (c == '-')
		{
			c = nextByte();
			sign = -1;
		}
		int res = 0;
		while (c >= '0' && c <= '9')
		{
			res = res * 10 + c - '0';
			c = nextByte();
		}
		return res * sign;
	}

	struct P
	{
		public int x;
		public int y;
	}

	struct E : IComparable<E>
	{
		public double x;
		public int type;
		public int c;
		public int CompareTo(E e)
		{
			if (x < e.x) return -1;
			if (x > e.x) return 1;
			if (type > e.type) return -1;
			if (type < e.type) return 1;
			return 0;
		}
	}

	static bool HasPoints(P[] r1, P[] r2)
	{
		for (int i = 0; i < 4; i++)
			for (int j = 0; j < 4; j++)
				if (r1[i].x == r2[j].x && r1[i].y == r2[j].y) return true;
		return false;
	}

	static bool HasEdge(P[] r, P p)
	{
		for (int i = 0; i < 4; i++)
		{
			P cur = r[i];
			P next = r[(i + 1) % 4];
			int a = next.y - cur.y;
			int b = cur.x - next.x;
			int c = -(a * cur.x + b * cur.y);
			if (p.x * a + p.y * b + c != 0) continue;
			if (p.x < Math.Min(cur.x, next.x)) continue;
			if (p.x > Math.Max(cur.x, next.x)) continue;
			if (p.y < Math.Min(cur.y, next.y)) continue;
			if (p.y > Math.Max(cur.y, next.y)) continue;
			return true;
		}
		return false;
	}

	static bool Intersect(P a, P b, int y, out E e)
	{
		e = new E();
		if (a.y == b.y) return false;
		int rev = 1;
		if (b.y < a.y)
		{
			rev = -1;
			P t = a;
			a = b;
			b = t;
		}
		if (a.y > y) return false;
		if (b.y < y) return false;
		double p = (double)(y - a.y) / (double)(b.y - a.y);
		double x = a.x + (b.x - a.x) * p;
		e = new E(){ x = x, type = rev, c = 0 };
		return true;
	}

	public static void Main()
	{
		P[] r1 = new P[4];
		for (int i = 0; i < 4; i++)
		{
			r1[i].x = nextInt();
			r1[i].y = nextInt();
		}
		P[] r2 = new P[4];
		for (int j = 0; j < 4; j++)
		{
			r2[j].x = nextInt();
			r2[j].y = nextInt();
		}
		if (HasPoints(r1, r2))
		{
			Console.WriteLine("yes");
			return;
		}
		for (int i = 0; i < 4; i++)
			if (HasEdge(r1, r2[i]) || HasEdge(r2, r1[i]))
			{
				Console.WriteLine("yes");
				return;
			}

		int[] ys = new int[8];
		for (int i = 0; i < 4; i++)
		{
			ys[i] = r1[i].y;
			ys[i + 4] = r2[i].y;
		}
		for (int j = 0; j < 8; j++)
		{
			int y = ys[j];
			E[] e = new E[8];
			int ec = 0;
			for (int i = 0; i < 4; i++)
			{
				E ne;
				if (!Intersect(r1[i], r1[(i + 1) % 4], y, out ne)) continue;
				ne.c = 1;
				e[ec++] = ne;
			}
			for (int i = 0; i < 4; i++)
			{
				E ne;
				if (!Intersect(r2[i], r2[(i + 1) % 4], y, out ne)) continue;
				ne.c = 2;
				e[ec++] = ne;
			}
			Array.Resize(ref e, ec);
			Array.Sort(e);

			int c1 = 0;
			int c2 = 0;
			for (int i = 0; i < ec; i++)
			{
				if (e[i].c == 1) c1 += e[i].type;
				else c2 += e[i].type;
				if (c1 != 0 && c2 != 0)
				{
					Console.WriteLine("yes");
					return;
				}
			}
		}
		Console.WriteLine("no");
	}
}


#define EXTENDSTACKSIZE

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
 using System.Text;
 using System.Threading;

namespace CF
{
    internal class Program
    {
        private const int stackSize = 32 * 1024 * 1024;

        private static void Run()
        {
            using (var sr = new InputReader(Console.In))
//            using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
//            using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }

        private static void Main(string[] args)
        {
#if EXTENDSTACKSIZE
            var threadStart = new ThreadStart(Run);
            var thread = new Thread(threadStart, stackSize);
            thread.Start();
            thread.Join();
#else
            Run();
#endif
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var c1 = sr.ReadArrayOfInt32();
            var c2 = sr.ReadArrayOfInt32();
            var coords1 = new int[10];
            var coords2 = new int[10];
            for (var i = 0; i < c1.Length; i++) {
                coords1[i] = c1[i];
                coords2[i] = c2[i];
            }

            coords1[8] = c1[0];
            coords1[9] = c1[1];
            coords2[8] = c2[0];
            coords2[9] = c2[1];
            for (var i = 0; i < 4; i++) {
                for (var j = 0; j < 4; j++) {
                    if (IsIntersect(coords1[i * 2], coords1[i * 2 + 1], coords1[(i + 1) * 2], coords1[(i + 1) * 2 + 1],
                        coords2[j * 2], coords2[j * 2 + 1], coords2[(j + 1) * 2], coords2[(j + 1) * 2 + 1])) {
                        sw.WriteLine("YES");
                        return;
                    }
                }
            }

            for (var i = 0; i < 4; i++) {
                if (Inside(coords1[i * 2], coords1[i * 2 + 1], coords2)) {
                    sw.WriteLine("YES");
                    return;
                }
            }

            for (var i = 0; i < 4; i++) {
                if (Inside(coords2[i * 2], coords2[i * 2 + 1], coords1)) {
                    sw.WriteLine("YES");
                    return;
                }
            }

            sw.WriteLine("NO");
        }

        private bool Inside(int x1, int y1, int[] coords)
        {
            var intersectsCount = 0;
            for (var i = 0; i < 4; i++) {
                if (IsIntersect(x1, y1, 100, 100, coords[i * 2], coords[i * 2 + 1], coords[(i + 1) * 2], coords[(i + 1) * 2 + 1])) {
                    intersectsCount++;
                }
            }

            return intersectsCount == 1;
        }

        private int Cross(int x1, int y1, int x2, int y2, int x, int y)
        {
            return (x1 - x) * (y2 - y) - (x2 - x) * (y1 - y);
        }

        private bool IsIntersect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
        {
            var d1 = Cross(x2, y2, x3, y3, x1, y1);
            var d2 = Cross(x2, y2, x4, y4, x1, y1);
            var d3 = Cross(x4, y4, x2, y2, x3, y3);
            var d4 = Cross(x4, y4, x1, y1, x3, y3);
            if (((d1 > 0 && d2 < 0) || (d2 > 0 && d1 < 0)) && ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0)))
                return true;
            if (d1 == 0 && InSegment(x1, y1, x2, y2, x3, y3))
                return true;
            if (d2 == 0 && InSegment(x1, y1, x2, y2, x4, y4))
                return true;
            if (d3 == 0 && InSegment(x3, y3, x4, y4, x2, y2))
                return true;
            if (d4 == 0 && InSegment(x3, y3, x4, y4, x1, y1))
                return true;

            return false;
        }

        private bool InSegment(int x1, int y1, int x2, int y2, int x, int y)
        {
            return x >= Math.Min(x1, x2) && x <= Math.Max(x1, x2) && y >= Math.Min(y1, y2) && y <= Math.Max(y1, y2);
        }

        ~Task()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public struct Vector2
    {
      public int x;
      public int y;

      public static Vector2 operator +(Vector2 v1, Vector2 v2) =>
        new Vector2(v1.x + v2.x, v1.y + v2.y);

      public static Vector2 operator -(Vector2 v1, Vector2 v2) =>
        new Vector2(v1.x - v2.x, v1.y - v2.y);

      public Vector2(int x, int y)
      {
        this.x = x;
        this.y = y;
      }
    }

    public class Segment2
    {
      public Vector2 a;
      public Vector2 b;
      public Segment2(Vector2 a, Vector2 b)
      {
        this.a = a;
        this.b = b;
      }
    }

    public class Quad
    {
      public Vector2[] v;

      public bool ContainsPoint(Vector2 p) =>
        Enumerable.Range(0, 4).All(i => Cross(v[(i + 1) % 4] - v[i], p - v[i]) <= 0);

      public IEnumerable<Vector2> Points() => v;

      public IEnumerable<Segment2> Edjes() =>
        Enumerable.Range(0, 4).Select(i => new Segment2(v[i], v[(i + 1) % 4]));

      public Quad(Vector2 a, Vector2 b, Vector2 c, Vector2 d) =>
        v = new[] { a, b, c, d };
    }

    public static int Cross(Vector2 v1, Vector2 v2) => v1.x * v2.y - v2.x * v1.y;

    public static bool Intersect(Segment2 a, Segment2 b) =>
      Intersect(a.a, a.b, b.a, b.b);

    public static bool Intersect(Vector2 a, Vector2 b, Vector2 c, Vector2 d)
    {
      var ca = c - a;
      var cd = c - d;
      var cb = c - b;
      var ac = a - c;
      var ab = a - b;
      var ad = a - d;
      var d1 = Cross(cd, ca);
      var d2 = Cross(cd, cb);
      var d3 = Cross(ab, ac);
      var d4 = Cross(ab, ad);
      return (d1 * d2 < 0 && d3 * d4 < 0) ||
        d1 == 0 && PointOnEdge(a, c, d) ||
        d2 == 0 && PointOnEdge(b, c, d) ||
        d3 == 0 && PointOnEdge(c, a, b) ||
        d4 == 0 && PointOnEdge(d, a, b);
    }

    public static bool PointOnEdge(Vector2 p, Vector2 a, Vector2 b)
    {
      return p.x <= Max(a.x, b.x) && p.x >= Min(a.x, b.x) &&
             p.y <= Max(a.y, b.y) && p.y >= Min(a.y, b.y);
    }

    public bool Intersect(Quad q1, Quad q2)
    {
      return q1.Points().Any(q2.ContainsPoint) ||
             q2.Points().Any(q1.ContainsPoint) ||
             q1.Edjes().Any(e1 => q2.Edjes().Any(e2 => Intersect(e1, e2)));
    }

    private Vector2 ReadPoint() => new Vector2(input.ReadInt(), input.ReadInt());

    public void Solve()
    {
      var v1 = new[] { ReadPoint(), ReadPoint(), ReadPoint(), ReadPoint() };
      var v2 = new[] { ReadPoint(), ReadPoint(), ReadPoint(), ReadPoint() };
      v1 = v1.OrderBy(p => p.y).ThenBy(p => p.x).ToArray();
      v2 = v2.OrderBy(p => p.y).ThenBy(p => p.x).ToArray();
      var q1 = new Quad(v1[0], v1[2], v1[3], v1[1]);
      var q2 = new Quad(v2[0], v2[1], v2[3], v2[2]);
      Write(Intersect(q1, q2) ? "YES" : "NO");
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private readonly TextReader reader;

    public string ReadToEnd()
    {
      return reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = reader.Read();
        if (c == -1)
          throw new EndOfStreamException("Digit expected, but end of stream occurs");
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
      var result = (char)c - '0';
      c = reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
        result = result * 10 + (char)c - '0';
        c = reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public (int, int) Read2Int() =>
      (ReadInt(), ReadInt());

    public (int, int, int) Read3Int() =>
      (ReadInt(), ReadInt(), ReadInt());

    public (int, int, int, int) Read4Int() =>
      (ReadInt(), ReadInt(), ReadInt(), ReadInt());

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      var c = reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main()
    {
      var solver = new ProblemSolver(In);
      solver.Solve();
    }
  }

  #endregion
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		for(int i=0;i<4;i++){
			if(Inside(A[2*i], A[2*i+1], B)){
				Console.WriteLine("YES");
				return;
			}
			if(Inside(B[2*i], B[2*i+1], A)){
				Console.WriteLine("YES");
				return;
			}
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(OnLine(A[2*i], A[2*i+1], B[2*j], B[2*j+1], B[(2*j+2)%8], B[(2*j+3)%8])){
					Console.WriteLine("YES");
					return;
				}
				if(OnLine(B[2*i], B[2*i+1], A[2*j], A[2*j+1], A[(2*j+2)%8], A[(2*j+3)%8])){
					Console.WriteLine("YES");
					return;
				}
			}
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(Intersects(A[2*j], A[2*j+1], A[(2*j+2)%8], A[(2*j+3)%8], B[2*j], B[2*j+1], B[(2*j+2)%8], B[(2*j+3)%8])){
					Console.WriteLine("YES");
					return;
				}
			}
		}
		Console.WriteLine("NO");

	}

	bool Inside(int x, int y, int[] rect){
		var h = new HashSet<int>();
		for(int i=0;i<4;i++){
			var d = det(rect[2*i] - x, rect[2*i+1] - y, rect[(2*i+2)%8] - x, rect[(2*i+3)%8] - y);
			if(d == 0) return false;
			d = d > 0 ? 1 : -1;
			h.Add(d);
		}
		return h.Count == 1;
	}
	bool OnLine(int x, int y, int x1, int y1, int x2, int y2){
		if(x == x1 && y == y1) return true;
		if(x == x2 && y == y2) return true;
		if(det(x1 - x, y1 - y, x2 - x, y2 - y) != 0) return false;
		return (x1 - x) * (x2 - x) + (y1 - y) * (y2 - y) < 0;
	}
	bool Intersects(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){

		int d0 = det0(x3 - x1, y3 - y1, x2 - x1, y2 - y1);
		int d1 = det0(x4 - x1, y4 - y1, x2 - x1, y2 - y1);
		if(d0 == 0 || d1 == 0 || d0 == d1) return false;
		int d2 = det0(x1 - x3, y1 - y3, x4 - x3, y4 - y3);
		int d3 = det0(x2 - x3, y2 - y3, x4 - x3, y4 - y3);
		if(d2 == 0 || d3 == 0 || d2 == d3) return false;
		return true;

	}

	int det (int a, int b, int c, int d){
		return a * d - b * c;
	}
	int det0 (int a, int b, int c, int d){
		var ret = a * d - b * c;
		if(ret == 0) return 0;
		if(ret > 0) return 1;
		return -1;
	}

	int[] A, B;
	public Sol(){
		A = ria();
		B = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		for(int i=0;i<4;i++){
			if(Inside(A[2*i], A[2*i+1], B)){
				Console.WriteLine("YES");
				return;
			}
			if(Inside(B[2*i], B[2*i+1], A)){
				Console.WriteLine("YES");
				return;
			}
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(OnLine(A[2*i], A[2*i+1], B[2*j], B[2*j+1], B[(2*j+2)%8], B[(2*j+3)%8])){
					Console.WriteLine("YES");
					return;
				}
				if(OnLine(B[2*i], B[2*i+1], A[2*j], A[2*j+1], A[(2*j+2)%8], A[(2*j+3)%8])){
					Console.WriteLine("YES");
					return;
				}
			}
		}
		Console.WriteLine("NO");

	}

	bool Inside(int x, int y, int[] rect){
		var h = new HashSet<int>();
		for(int i=0;i<4;i++){
			var d = det(rect[2*i] - x, rect[2*i+1] - y, rect[(2*i+2)%8] - x, rect[(2*i+3)%8] - y);
			if(d == 0) return false;
			d = d > 0 ? 1 : -1;
			h.Add(d);
		}
		return h.Count == 1;
	}
	bool OnLine(int x, int y, int x1, int y1, int x2, int y2){
		if(x == x1 && y == y1) return true;
		if(x == x2 && y == y2) return true;
		if(det(x1 - x, y1 - y, x2 - x, y2 - y) != 0) return false;
		return (x1 - x) * (x2 - x) + (y1 - y) * (y2 - y) < 0;
	}

	int det (int a, int b, int c, int d){
		return a * d - b * c;
	}

	int[] A, B;
	public Sol(){
		A = ria();
		B = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace CodeForces
{
    static class Program
    {
        static void Main()
        {
            const string filePath = @"Data\R488C.txt";
            if (System.IO.File.Exists(filePath))
            {
                Console.SetIn(new System.IO.StreamReader(filePath));
            }

            IProblem counter = new R488C();

            foreach (var result in counter.GetResults())
            {
                Console.WriteLine(result);
            }
        }
    }

    internal class R488C : ProblemBase
    {
        public class Point
        {
            public double X { get; set; }
            public double Y { get; set; }
        }

        private double Area(Point a, Point b, Point c)
        {
            return (b.X - a.X) * (c.Y - a.Y) - (b.Y - a.Y) * (c.X - a.X);
        }

        private bool HasProjectionIntersection(double a, double b, double c, double d)
        {
            double temp;
            if (a > b)
            {
                temp = a;
                a = b;
                b = temp;
            }

            if (c > d)
            {
                temp = c;
                c = d;
                d = temp;
            }
            return Math.Max(a, c) <= Math.Min(b, d);
        }

        private bool HasIntersection(Point a,  Point b, Point c, Point d)
        {
            return HasProjectionIntersection(a.X, b.X, c.X, d.X)
                   && HasProjectionIntersection(a.Y, b.Y, c.Y, d.Y)
                   && Area(a, b, c) * Area(a, b, d) <= 0
                   && Area(c, d, a) * Area(c, d, b) <= 0;
        }

        public override IEnumerable<string> GetResults()
        {
            var line = this.ReadIntArray();
            var first = new Point[4];
            for (int i = 0; i < 4; i++)
            {
                first[i] = new Point {X = line[2 * i], Y = line[2 * i + 1]};
            }

            var second = new Point[4];
            line = this.ReadIntArray();
            for (int i = 0; i < 4; i++)
            {
                second[i] = new Point { X = line[2 * i], Y = line[2 * i + 1] };
            }

            var hasIntersection = SimpleCheck(first, second);
            if (!hasIntersection)
            {
                var centerX = second.Sum(item => item.X) / 4.0;
                var centerY = second.Sum(item => item.Y) / 4.0;

                for (int i = 0; i < 4; i++)
                {
                    first[i].X -= centerX;
                    first[i].Y -= centerY;
                    second[i].X -= centerX;
                    second[i].Y -= centerY;
                }

                first = Rotate45(first);
                second = Rotate45(second);

                hasIntersection = SimpleCheck(second, first);
            }

            yield return hasIntersection? "YES" : "n/a";
        }

        private Point[] Rotate45(Point[] first)
        {
            var cos45 = Math.Cos(Math.PI / 4.0);
            var sin45 = Math.Sin(Math.PI / 4.0);
            var newPoints = new Point[4];
            for (int i = 0; i < 4; i++)
            {
                newPoints[i] = new Point
                {
                    X = cos45 * first[i].X + sin45 * first[i].Y,
                    Y = -sin45 * first[i].X + cos45 * first[i].Y
                };
            }

            return newPoints;
        }

        private bool SimpleCheck(Point[] first, Point[] second)
        {
            bool hasIntersection = false;
            for (int firstIndex = 0; firstIndex < 4; firstIndex++)
            {
                for (int secondIndex = 0; secondIndex < 4; secondIndex++)
                {
                    if (HasIntersection(first[firstIndex], first[(firstIndex + 1) % 4], second[secondIndex],
                        second[(secondIndex + 1) % 4]))
                    {
                        hasIntersection = true;
                        break;
                    }
                }
            }

            if (!hasIntersection)
            {
                var point = new Point
                {
                    X = second.Sum(item => item.X) / 4.0,
                    Y = second.Sum(item => item.Y) / 4.0
                };

                var minX = first[0].X;
                var maxX = first[0].X;
                var minY = first[0].Y;
                var maxY = first[0].Y;
                for (int i = 1; i < 4; i++)
                {
                    if (first[i].X < minX)
                    {
                        minX = first[i].X;
                    }

                    if (first[i].Y < minY)
                    {
                        minY = first[i].Y;
                    }

                    if (first[i].X > maxX)
                    {
                        maxX = first[i].X;
                    }

                    if (first[i].Y > maxY)
                    {
                        maxY = first[i].Y;
                    }
                }

                if (point.X <= maxX && point.X >= minX && point.Y >= minY && point.Y <= maxY)
                {
                    hasIntersection = true;
                }
            }

            return hasIntersection;
        }
    }

    internal class R488D : ProblemBase
    {
        public override IEnumerable<string> GetResults()
        {
            yield return "n/a";
        }
    }

    abstract class MultipleTestsBase : ProblemBase
    {
        public sealed override IEnumerable<string> GetResults()
        {
            var t = Convert.ToInt32(Console.ReadLine());
            for (int testCaseNumber = 0; testCaseNumber < t; testCaseNumber++)
            {
                foreach (var result in GetTestResult(testCaseNumber + 1))
                {
                    yield return result;
                }

            }

        }

        protected abstract IEnumerable<string> GetTestResult(int caseNumber);
    }

    public interface IProblem
    {
        IEnumerable<string> GetResults();
    }

    public abstract class ProblemBase : IProblem
    {
        public void PrintArray<T>(IEnumerable<T> items, string prefixMessage)
        {
            Console.WriteLine("{0}: {1}", prefixMessage, string.Join(",", items));
        }

        public void WriteDiagnostics(string message, params object[] objects)
        {
            Console.WriteLine(message, objects);
        }

        public virtual IEnumerable<string> GetResults()
        {
            yield return "No result";
        }

        protected int[] ReadIntArray()
        {
            return Array.ConvertAll(ReadTokens(), Convert.ToInt32);
        }

        protected long[] ReadLongArray()
        {
            return Array.ConvertAll(ReadTokens(), Convert.ToInt64);
        }

        protected string[] ReadTokens()
        {
            var readLine = Console.ReadLine();
            if (readLine == null)
            {
                throw new Exception("Value read from Console is null");
            }
            return readLine.Split(' ');
        }

        protected int ReadInt32()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
    }
}


using System;

namespace Test
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var res = new int[]
                {0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1};

            for (int i = 0; i < 30; i++)
            {
                Console.WriteLine(res[i]);
            }
        }
    }
}


using System;

namespace Test
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var res = new int[]
                {0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0};

            for (int i = 0; i < 30; i++)
            {
                Console.WriteLine(res[i]);
            }

        }

    }
}


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();
            ulong n = ulong.Parse(s.Substring(0, s.Length - 1));
            ulong res = (((n - 1) / 4) * 16);
            ulong row = n % 4;
            if (row == 1 || row == 3)
                res += 1;
            else
                res += 8;
            if (s[s.Length - 1] == 'f') res += 0;
            if (s[s.Length - 1] == 'e') res += 1;
            if (s[s.Length - 1] == 'd') res += 2;

            if (s[s.Length - 1] == 'a') res += 3;
            if (s[s.Length - 1] == 'b') res += 4;
            if (s[s.Length - 1] == 'c') res += 5;

            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#pragma warning disable

class Segtree<T>
{
    int n;
    T[] tree;
    Func<T, T, T> f;
    T exnum;
    public Segtree(int m, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ex;
    }
    public Segtree(int m, T ini, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ini;
        for (int i = 0; i < m; ++i) update(i, ini);
    }
    public void update(int j, T x)
    {
        int i = j + n - 1;
        tree[i] = x;
        while (i > 0)
        {
            i = (i - 1) >> 1;
            tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
        }
    }
    public T look(int i) { return tree[i + n - 1]; }

    // [s, t]
    public T run(int s, int t) { return query(s, t + 1, 0, 0, n); }
    T query(int s, int t, int k, int l, int r)
    {
        if (r <= s || t <= l) return exnum;
        if (s <= l && r <= t) return tree[k];

        return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r));
    }
}

class PriorityQueue<T>
{
    private Comparison<T> comp;
    private List<T> list;
    private int count;
    public PriorityQueue() : this((x, y) => ((IComparable<T>)x).CompareTo(y)) { }
    public PriorityQueue(Comparison<T> comparison)
    {
        comp = comparison;
        list = new List<T>();
        count = 0;
    }
    public void Enqueue(T x)
    {
        var pos = count++;
        list.Add(x);
        while (pos > 0)
        {
            var p = (pos - 1) / 2;
            if (comp(list[p], x) <= 0) break;
            list[pos] = list[p];
            pos = p;
        }
        list[pos] = x;
    }
    public T Dequeue()
    {
        var value = list[0];
        var x = list[--count];
        list.RemoveAt(count);
        if (count == 0) return value;
        var pos = 0;
        while (pos * 2 + 1 < count)
        {
            var a = 2 * pos + 1;
            var b = 2 * pos + 2;
            if (b < count && comp(list[b], list[a]) < 0) a = b;
            if (comp(list[a], x) >= 0) break;
            list[pos] = list[a];
            pos = a;
        }
        list[pos] = x;
        return value;
    }
    public T Peek() { return list[0]; }
    public bool Any() { return count > 0; }
    public int Count() { return count; }
}

namespace Codeforces
{
    class Program
    {
        class mymath
        {
            static int Mod = 1000000007;
            public void setMod(int m) { Mod = m; }
            public bool isprime(long a)
            {
                if (a < 2) return false;
                for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
                return true;
            }
            public bool[] sieve(int n)
            {
                var isp = new bool[n + 1];
                for (int i = 2; i <= n; i++) isp[i] = true;
                for (int i = 2; i * i <= n; i++) if (isp[i]) for (int j = i * i; j <= n; j += i) isp[j] = false;
                return isp;
            }
            public List<int> getprimes(int n)
            {
                var prs = new List<int>();
                var isp = sieve(n);
                for (int i = 2; i <= n; i++) if (isp[i]) prs.Add(i);
                return prs;
            }
            public long[][] E(int n)
            {
                var ret = new long[n][];
                for (int i = 0; i < n; i++)
                {
                    ret[i] = new long[n];
                    ret[i][i] = 1;
                }
                return ret;
            }
            public long[][] powmat(long[][] A, long n)
            {
                if (n == 0) return E(A.Length);
                var t = powmat(A, n / 2);
                if ((n & 1) == 0) return mulmat(t, t);
                return mulmat(mulmat(t, t), A);
            }
            public long[] mulmat(long[][] A, long[] x)
            {
                int n = A.Length, m = x.Length;
                var ans = new long[n];
                for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ans[i] = (ans[i] + x[j] * A[i][j]) % Mod;
                return ans;
            }
            public long[][] mulmat(long[][] A, long[][] B)
            {
                int n = A.Length, m = B[0].Length, l = B.Length;
                var ans = new long[n][];
                for (int i = 0; i < n; i++)
                {
                    ans[i] = new long[m];
                    for (int j = 0; j < m; j++) for (int k = 0; k < l; k++) ans[i][j] = (ans[i][j] + A[i][k] * B[k][j]) % Mod;
                }
                return ans;
            }
            public long[] addmat(long[] x, long[] y)
            {
                int n = x.Length;
                var ans = new long[n];
                for (int i = 0; i < n; i++) ans[i] = (x[i] + y[i]) % Mod;
                return ans;
            }
            public long[][] addmat(long[][] A, long[][] B)
            {
                int n = A.Length, m = A[0].Length;
                var ans = new long[n][];
                for (int i = 0; i < n; i++) ans[i] = addmat(A[i], B[i]);
                return ans;
            }
            public long powmod(long a, long b)
            {
                if (a >= Mod) return powmod(a % Mod, b);
                if (a == 0) return 0;
                if (b == 0) return 1;
                var t = powmod(a, b / 2);
                if ((b & 1) == 0) return t * t % Mod;
                return t * t % Mod * a % Mod;
            }
            public long inv(long a) { return powmod(a, Mod - 2); }
            public long gcd(long a, long b)
            {
                while (b > 0) { var t = a % b; a = b; b = t; }
                return a;
            }
            public long lcm(long a, long b) { return a * (b / gcd(a, b)); }
            public long Comb(int n, int r)
            {
                if (n < 0 || r < 0 || r > n) return 0;
                if (n - r < r) r = n - r;
                if (r == 0) return 1;
                if (r == 1) return n;
                var numerator = new int[r];
                var denominator = new int[r];
                for (int k = 0; k < r; k++)
                {
                    numerator[k] = n - r + k + 1;
                    denominator[k] = k + 1;
                }
                for (int p = 2; p <= r; p++)
                {
                    int pivot = denominator[p - 1];
                    if (pivot > 1)
                    {
                        int offset = (n - r) % p;
                        for (int k = p - 1; k < r; k += p)
                        {
                            numerator[k - offset] /= pivot;
                            denominator[k] /= pivot;
                        }
                    }
                }
                long result = 1;
                for (int k = 0; k < r; k++) if (numerator[k] > 1) result = result * numerator[k] % Mod;
                return result;
            }
        }

        const long InfL = 4011686018427387913L;
        static char[] sep = new char[] { ' ', '/' };

        //static int[] dx = { -1, 0, 1, -1, 1, -1, 0, -1 };
        //static int[] dy = { 1, 1, 1, 0, 0, -1, -1, -1 };

        static int[] dx = { -1, 0, 0, 1 };
        static int[] dy = { 0, 1, -1, 0 };

        /// <summary>
        /// basic dfs function
        /// </summary>
        ///
        /* public class List_of_List<T> : List<List<T>> { }
        static int result = 0;

        static List<bool> visited = new List<bool>();
        static List_of_List<int> adj = new List_of_List<int>();

        static void dfs(int here)
        {
            if (here == n * m - 1)
            {
                result++;
                return;
            }
            visited[here] = true;

            for(int i = 0; i<adj[here].Count; i++)
            {
                int there = adj[here][i];
                if (!visited[there])
                    dfs(there);
                visited[there] = false;
            }
        }

        static void dfsAll()
        {
            for(int i = 0; i<adj.Count; i++)
            {
                dfs(i);
            }
        }

        /* static int getInt => int.Parse(Console.ReadLine());
        static int[] getIntArr => Console.ReadLine().Trim().Split(sep).Select(a => int.Parse(a)).ToArray();
        static List<int> getIntList => Console.ReadLine().Trim().Split(sep).Select(a => int.Parse(a)).ToList<int>();
        static string getString => Console.ReadLine().Trim();
        static string[] getStrArr => Console.ReadLine().Trim().Split(sep);
        static List<string> getStrList => Console.ReadLine().Trim().Split(sep).ToList<string>();
        */
        static int m;
        static int n;
        static int[] input = new int[100001];

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            char seat = input[input.Length - 1];
            string num = "";
            for (int i = 0; i < input.Length - 1; i++) num += input[i];
            long row = long.Parse(num);

            long result = 0;
            result += 16 * ((row - 1) / 4);
            row = (row-1) % 4 + 1;
            if (seat == 'f') result += 1;
            else if (seat == 'e') result += 2;
            else if (seat == 'd') result += 3;
            else if (seat == 'a') result += 4;
            else if (seat == 'b') result += 5;
            else if (seat == 'c') result += 6;

            if (row == 2 || row == 4) result += 7;

            Console.WriteLine(result);
        }

        /*
        /// <summary>
        /// 이분 매칭 알고리즘
        /// </summary>

        static bool[,] adj; // 연결 리스트. 이분 매칭이기 때문에 bool 형식이다. 혹-시라도 타임아웃이 뜬다면 인접리스트로 바꿔볼 것. 조금 빨라진다.
        static List<bool> visited; // 왼쪽의 한 정점에서 오른쪽의 모든 정점으로 방문 기록을 정리하는 리스트
        static List<int> m_match; // 왼쪽에 있는 정점들의 집합
        static List<int> n_match; // 오른쪽에 있는 정점들의 집합

        static bool dfs(int a) // 왼쪽 정점 a 에서 오른쪽 정점으로 가는 경로를 찾는다
        {
            if (visited[a]) return false;
            visited[a] = true;
            for (int b = 0; b < n; b++)
            {
                if (adj[a, b]) // 왼쪽 정점 a 에서 오른쪽 정점중 b에 연결할 수 있는 경우
                {
                    if (n_match[b] == -1 || dfs(n_match[b])) // b가 이미 매칭되어 있다면 n_match[b]에서 시작되는 증가경로를 찾는다
                    {
                        // 증가 경로를 발견한 경우 a와 b를 매치시키고 true를 반환한다
                        m_match[a] = b;
                        n_match[b] = a;
                        return true;
                    }
                }
            }
            return false;
        }

        static int bipartite_match()
        {
            m_match = Enumerable.Repeat(-1, m).ToList(); // 왼쪽에 있는 정점들의 각 원소가 오른쪽에 있는 어떤 정점과 대응되는지 기록하는 리스트
            n_match = Enumerable.Repeat(-1, n).ToList(); // 오른쪽에 있는 정점들의 각 원소가 왼쪽에 있는 어떤 정점과 대응되는지 기록하는 리스트

            int size = 0; // 몇 쌍이 대응되는지 기록하는 변수
            for (int start = 0; start < m; start++) // m_match (왼쪽에 있는 정점들 집합) 의 모든 원소에 대해 dfs 실시
            {
                visited = Enumerable.Repeat(false, m).ToList(); // 모든 점에 대해 초기화 (방문하지 않음으로 표시)

                if (dfs(start)) size++; // 각 왼쪽 정점에서 dfs를 실시해서 갈 수 있는 경로가 있다면 경로의 개수를 1 늘린다
            }
            return size;
        }
        */

        /*
        /// <summary>
        /// 네트워크 유량 문제용 포드-풀커슨 알고리즘
        /// </summary>

        const int INF = 987654321;
        static int v; // 정점의 수. source와 sink가 있으므로 감안해서 계산
        static int max_v;
        static int[,] capacity, flow;
        // capacity[u,v] = u에서 v로 보낼 수 있는 용량, flow[u,v] = u에서 v로 흘러가는 유량 (반대방향인 경우 음수)

        // flow[,] 를 계산하고 총 유량을 반환하는 함수
        static int networkFlow(int source, int sink)
        {
            flow = new int[max_v, max_v]; // flow 배열의 초기화
            int totalFlow = 0;
            while (true)
            {
                List<int> parent = Enumerable.Repeat(-1, max_v).ToList();
                Queue<int> q = new Queue<int>();
                parent[source] = source;
                q.Enqueue(source);
                while (q.Count != 0 && parent[sink] == -1)
                {
                    int here = q.Dequeue();
                    for (int there = 0; there < v; there++)
                    {
                        if (capacity[here, there] - flow[here, there] > 0 && parent[there] == -1)
                        {
                            q.Enqueue(there);
                            parent[there] = here;
                        }
                    }
                }

                if (parent[sink] == -1) break;

                int amount = INF;
                for(int p = sink; p != source; p = parent[p])
                {
                    amount = Math.Min(capacity[parent[p], p] - flow[parent[p], p], amount);
                }
                for(int p = sink; p != source; p = parent[p])
                {
                    flow[parent[p], p] += amount;
                    flow[p, parent[p]] -= amount;
                }

                totalFlow += amount;
            }
            return totalFlow;
        }
        */
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string a = "";
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] <= '9' && s[i] >= '0') a += ""+s[i];
            }
            long ch = Convert.ToInt64(a);
            long part=0, p=0, sum=0;
            if (s[s.Length-1]=='f') sum=1;
            else if (s[s.Length-1]=='e') sum=2;
            else if (s[s.Length-1]=='d') sum=3;
            else if (s[s.Length-1]=='a') sum=4;
            else if (s[s.Length-1]=='b') sum=5;
            else if (s[s.Length-1]=='c') sum=6;
            part=(ch+3)/4;
            sum += (part - 1) * 6 * 2;
            sum += (part - 1) * 4;
            if ((ch + 2) % 4 == 0 || ch % 4 == 0) sum += 7;
            Console.WriteLine(sum);
        }
    }
}


using System;

namespace ConsoleApplication13
{
    class Program
    {
        static void Main(string[] args)
        {
            UInt64 n, time = 0;
            string str = Console.ReadLine();
            n = Convert.ToUInt64(str.Substring(0, str.Length - 1));
            time = (n - 1) / 4 * 16;
            if (n % 2 == 0)
                time += 7;
            if (str[str.Length - 1] == 'f')
                time++;
            else if (str[str.Length - 1] == 'e')
                time += 2;
            else if (str[str.Length - 1] == 'd')
                time += 3;
            else if (str[str.Length - 1] == 'a')
                time += 4;
            else if (str[str.Length - 1] == 'b')
                time += 5;
            else if (str[str.Length - 1] == 'c')
                time += 6;
            Console.WriteLine(time);
        }
    }
}


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

namespace _725B
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int L = S.Length; sbyte A2 = 0;
            char C = char.Parse(S.Substring(L-1));
            string SN = (S.Substring(0, L - 1));
            long N = long.Parse(SN);

            switch (C)
            {
                case 'f':
                    A2 = 1;
                    break;
                case 'e':
                    A2 = 2;
                    break;
                case 'd':
                    A2 = 3;
                    break;
                case 'a':
                    A2 = 4;
                    break;
                case 'b':
                    A2 = 5;
                    break;
                case 'c':
                    A2 = 6;
                    break;

            }

            long A1 = 16 * ((N - 1) / 4);
            sbyte A3 = 0;
            if ((N % 2) == 0) A3 = 7;
            long T = A1 + A2 + A3;

            Console.WriteLine(T);

        }
    }
}