    using System;

    namespace reverseString
    {
        class Program
        {
            static void Main(string[] args)
            {

                System.Int64 ans, rem, r, s;
                String str = Console.ReadLine();

                int len = str.Length;
                r = 0;
                for (int i = 0; i < len - 1; i++)
                {
                    r = r * 10 + str[i] - '0';
                }

               // Console.WriteLine("r is {0}", r);
                s = str[len - 1];

               // Console.WriteLine("s is {0}", s);

                rem = (r - 1) / 4;
              //  Console.WriteLine("rem is {0}", rem);

                ans = rem * 12;
              // Console.WriteLine("ans is {0}", ans);

                if (r % 2 == 0)
                {
                    ans += 6;
                    //Console.WriteLine("ans1 is {0}", ans);
                }

                if (r % 4 == 1 || r % 4 == 2)
                {
                    ans += r - 1;
                   // Console.WriteLine("ans2 is {0}", ans);
                }
                else if (r % 4 == 3 || r % 4 == 0)
                {
                    ans += r - 3;
                  //  Console.WriteLine("ans3 is {0}", ans);
                }

                if (s == 'a')
                {
                    ans += 4;
                   // Console.WriteLine("ans4 is {0}", ans);
                }
                else if (s == 'b')
                {
                    ans += 5;
                    //Console.WriteLine("ans5 is {0}", ans);
                }
                else if (s == 'c')
                {
                    ans += 6;
                  //  Console.WriteLine("ans6 is {0}", ans);
                }
                else if (s == 'd')
                {
                    ans += 3;
                   // Console.WriteLine("ans is {0}", ans);
                }
                else if (s == 'e')
                {
                    ans += 2;
                   // Console.WriteLine("ans is {0}", ans);
                }
                else
                {
                    ans += 1;
                  //  Console.WriteLine("ans is {0}", ans);
                }

                Console.WriteLine(ans);

        }
        }

}


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

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Solve();
            p.Out(x);
        }

        object Solve()
        {
            checked
            {
                var s = Read();
                var c = s.Last();
                var row = long.Parse(s.Substring(0, s.Length - 1)) - 1;
                var mod = row % 4;
                var result = (row / 4) * 16;

                if (mod % 2 != 0)
                    result += 7;
                switch (c)
                {
                    case 'f':
                        break;
                    case 'e':
                        result += 1;
                        break;
                    case 'd':
                        result += 2;
                        break;
                    case 'a':
                        result += 3;
                        break;
                    case 'b':
                        result += 4;
                        break;
                    case 'c':
                        result += 5;
                        break;
                    default:
                        throw new Exception("HUJ");
                }
                return result + 1;
            }
        }
    }

    class UnionFind
    {
        private int[] arr;
        private Random r = new Random();
        public UnionFind(int n)
        {
            arr = new int[n];
            for (int i = 0; i < n; i++)
            {
                arr[i] = i;
            }
        }

        public int Find(int x)
        {
            if (arr[arr[x]] == arr[x])
                return arr[x];
            var y = Find(arr[x]);
            arr[x] = y;
            return y;
        }

        public void Union(int x, int y)
        {
            var p1 = Find(x);
            var p2 = Find(y);
            if (p1 == p2)
                return;
            if (r.NextDouble() < 0.5)
                arr[p1] = p2;
            else
                arr[p2] = p1;
        }

        public int[][] Enumerate()
        {
            return arr.Select((x, i) => new { g = Find(x), i }).GroupBy(x => x.g, (k, e) => e.Select(y => y.i).ToArray()).ToArray();
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

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

        protected long[] ReadLongs()
        {
            var s = Read();
            if (s == "")
                return new long[0];
            var tokens = s.Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> s, string d) { return string.Join(d, s.ToArray()); }

        public static string JoinStrings(this IEnumerable<int> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
        public static string JoinStrings(this IEnumerable<long> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
    }
}


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 input = Console.ReadLine();
            long row = Convert.ToInt64(input.Substring(0, input.Length - 1));
            int col = input[input.Length - 1] - 'c'; //a = -2, b = -1, c = 0, d = 1, e = 2, f = 3
            long seconds = 0;

            if(col <= 0) {
                seconds += 6 + col;
            } else {
                seconds += 4 - col;
            }

            //1, 2, 5, 6, 9, 10 - attendant A
            if((row - 2) % 4 == 0 || (row - 1) % 4 == 0) { //attendant A rows
                seconds += 6 * (row / 2); //people served
                seconds += row - 1; //rows moved
            } else if(row % 4 == 0 || (row + 1) % 4 == 0) { //attendant B rows, //3, 4, 7, 8, 11, 12 - attendant B
                seconds += 6 * ((row - 2) / 2); //people served
                seconds += row - 3; //rows moved
            }

            Console.WriteLine(seconds);
        }
    }
}


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

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First < y.First || (x.First == y.First && x.Second > y.Second))
					return -1;
				return 1;
			}
		}

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;

			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		public static int BinarySearch(List<int> list, int value)
		{
			var l = -1;
			var r = list.Count;
			while (r - l > 1)
			{
				var m = (r + l) / 2;
				if (list[m] >= value)
					r = m;
				else
					l = m;
			}

			return r;
		}

		private static void Main()
		{
			var s = ReadString();
			var p = s.Last();
			var n = long.Parse(s.Substring(0, s.Length - 1));
			long ans = 0;
			ans = (n - 1) / 4 * 16;
			n = n % 2;
			if (n % 2 == 0)
				ans += 7;
			if (p == 'f')
				ans++;
			if (p == 'e')
				ans += 2;
			if (p == 'd')
				ans += 3;
			if (p == 'a')
				ans += 4;
			if (p == 'b')
				ans += 5;
			if (p == 'c')
				ans += 6;
			Console.WriteLine(ans);
			Console.ReadLine();
		}
	}
}


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();
            long n = long.Parse(s.Substring(0, s.Length - 1)) - 1;
            char seat = s[s.Length - 1];
            int sec = seat <= 'c' ? seat - 'a' + 4 : 'f' - seat + 1;
            long answer = ((n >> 2) << 4) + (n & 1)*7 + sec;

            Console.WriteLine(Math.Abs(answer));
        }
    }
}


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

class Solution
{
	static void Main(string[] args)
	{
		string s = Console.ReadLine ();
		char col = s.Last ();
		s = s.Substring (0, s.Length - 1);
		long row = long.Parse(s);
		long time = (row-1) / 4 * 2 * 8;
		row %= 4;
		if (row % 2 == 0)
			time += 7;
		time += "fedabc".IndexOf (col) + 1;
		Console.WriteLine (time);
	}
}


using System;
  class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();// Console.In.ReadToEnd().Split(new char[] { '\n', '\r'}, StringSplitOptions.RemoveEmptyEntries)[1];
            long row = long.Parse(input.Substring(0, input.Length - 1));
            long res = ((row - 1L) / 4L)*16L;
            if ((row % 4L) % 2L == 0L) res += 7L;
            row = input[input.Length - 1];
            if (row < 100L) { res += 3L; res += row == 97L ? 1L : row == 99L ? 3L : 2L; }
            else res += row == 102L ? 1L : row == 100L ? 3L : 2L;
            Console.WriteLine(res);
        }
    }


using System;
using System.Linq;

namespace CSharp
{
    class _725B
    {
        public static void Main()
        {
            var ns = Console.ReadLine();

            long n = long.Parse(ns.Substring(0, ns.Length - 1));
            char s = ns.Last();

            long t = (n - 1) / 4 * 16 + (n - 1) % 2 * 7;

            switch (s)
            {
                case 'a':
                    t += 4;
                    break;
                case 'b':
                    t += 5;
                    break;
                case 'c':
                    t += 6;
                    break;
                case 'd':
                    t += 3;
                    break;
                case 'e':
                    t += 2;
                    break;
                case 'f':
                    t += 1;
                    break;
            }

            Console.WriteLine(t);
        }
    }
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            var row = ulong.Parse(line.Substring(0, line.Length - 1));
            var place = line[line.Length - 1];

            var rowsIn4 = row % 4;
            ulong ans = 0;
            if (rowsIn4 == 0)
            {
                if (row > 4)
                {
                    var rows4 = row / 4 - 1;
                    if (rows4 > 0)
                    {
                        ans = rows4 * (6 + 6 + 1) + rows4 * 3;
                        row = row - rows4 * 4;
                    }
                }
            }
            else
            {
                var rows4 = row / 4;
                if (rows4 > 0)
                {
                    ans = rows4 * (6 + 6 + 1) + rows4 * 3;
                    row = row - rows4 * 4;
                }
            }

            var times = new Dictionary<char, ulong>
            {
                {'a', 4}, {'b', 5}, {'c', 6},
                {'f', 1}, {'e', 2}, {'d', 3}
            };
            var firstOrSecond = row % 2;
            if (firstOrSecond == 1) // 1 or 3
            {
                ans = ans + times[place];
            }
            else // 2 or 4
            {
                ans = 7 + ans + times[place];
            }

            Console.WriteLine(ans);
        }
    }
}


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

class Program
{

    //////////////////////////////////////////////////
    void Solution()
    {
        var s = rs;
        char ch = s[s.Length - 1];
        var n = long.Parse(s.Remove(s.Length - 1)) - 1;
        long res = 0;

        res += (n / 4) * 16;
        var q = n % 4;

        if (q == 1 || q == 3)
        {
            res += 7;
        }
        var a = "fedabc";
        for (int i = 0; i < 6; i++)
            if (a[i] == ch)
            {
                res += i + 1;
                break;
            }
        wln(res);
    }
    //////////////////////////////////////////////////

    static void swap<T>(ref T o1, ref T o2) { var o = o1; o1 = o2; o2 = o; }

    static void wln() { Console.WriteLine(); }
    static void wln<T>(T o) { Console.WriteLine(o); }
    static void wsp<T>(T o) { Console.Write(o + " "); }
    static void wrt<T>(T o) { Console.Write(o); }

    static void wln(double o) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }
    static void wsp(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12} ", o)); }
    static void wrt(double o) { Console.Write(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }

    static long gcd(long a, long b) { return (b != 0) ? gcd(b, a % b) : a; }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { _count = 0; _ind = 0; return _str.Substring(_ind); }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    int[] ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    long[] rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    double[] rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res;
    }
    string[] rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res; }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main() { new Program().Solution(); }
}


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(){

		Func<char,int> f = c =>{
			int ret = 0;
			switch(c){
				case 'a' :ret = 4;break;
				case 'b' :ret = 5;break;
				case 'c' :ret = 6;break;
				case 'd' :ret = 3;break;
				case 'e' :ret = 2;break;
				case 'f' :ret = 1;break;
			}
			return ret;
		};

		long ans = ((R-1)/4)*16;
		if(R%4 == 1)ans += f(C);
		if(R%4 == 3)ans += f(C);
		if(R%4 == 2)ans += 7 + f(C);
		if(R%4 == 0)ans += 7 + f(C);

		Console.WriteLine(ans);

	}
	long R;
	char C;
	public Sol(){

		var s = rs();
		R = long.Parse(s.Substring(0,s.Length-1));
		C = s[s.Length-1];
	}

	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;
using System.Text;
using System.Threading.Tasks;

namespace _733B {
	class Program {
		static void Main(string[] args) {
			string input = Console.ReadLine();
			char c = input[input.Length - 1];
			long s = long.Parse(input.Substring(0, input.Length - 1));
			long res = 0;
			if (s % 2 == 0) {
				res++;
			}
			res += (((s - 1) / 4) * 2);
			res *= 8;
			if (s % 2 == 0)
				res--;
			string order = "fedabc";
			res += Array.IndexOf(order.ToCharArray(), c) + 1;
			Console.WriteLine(res);
			//Console.ReadKey();
		}
	}
}


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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            ulong n = ulong.Parse(s.Substring(0, s.Length - 1));
            char c = s[s.Length - 1];
            ulong k = 0;
            if (n % 2 == 0)
            {
                if ((n / 2) % 2 != 0)
                {
                    k = (n + 2) / 2;
                }
                else
                {
                    k = n / 2;
                }
            }
            else
            {
                if ((n / 2) % 2 == 0)
                {
                    k = (n + 2) / 2;
                }
                else
                {
                    k = n / 2;
                }
            }
            ulong ans = (k - 1) * 6 + ((k - 1) / 2) * 3 + (k - 1) - ((k - 1) / 2);
            ulong temp = 0;
            switch (c)
            {
                case 'a': temp = 4; break;
                case 'b': temp = 5; break;
                case 'c': temp = 6; break;
                case 'd': temp = 3; break;
                case 'e': temp = 2; break;
                default: temp = 1; break;
            }
            ans += temp;
            Console.WriteLine(ans);
        }
    }
}


using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {
            //var s = Console.ReadLine().Split(' ');
            var str = Console.ReadLine();
            var k = long.Parse(str.Substring(0,str.Length-1));
            byte g = 0;
            switch (str[str.Length - 1])
            {
                case 'a':
                    g = 4;
                    break;
                case 'b':
                    g = 5;
                    break;
                case 'c':
                    g = 6;
                    break;
                case 'd':
                    g = 3;
                    break;
                case 'e':
                    g = 2;
                    break;
                case 'f':
                    g = 1;
                    break;
            }
            var result = (k%4==0?k-1:k)/4*16;
            k = k%4 == 0 ? 4 : k%4;
            result += g;
            if (k%2 == 0)
                result += 7;
            Console.WriteLine(result);
        }
    }
}


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

namespace ConsoleApplication1
{
    class CanadaCup2
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"D:\Sergey\Code\1.txt"));

            string ns = Console.ReadLine();
            ulong n = ulong.Parse(ns.Substring(0, ns.Length - 1));
            char s = ns[ns.Length - 1];
            int c = s - 'a';
            int[] d = new int[] { 3, 4, 5, 2, 1, 0 };
            ulong a = (n - 1) % 2;
            ulong b = (n - 1) / 4;
            //if (b > 1)
            //    b -= 2;

            ulong e = b * 16;
            if (a > 0)
                e+=7;
            e += (ulong)(d[c] + 1);

            Console.WriteLine(e);

        } // Main
    }
}


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

namespace CanadaCup2016
{
    class Submit
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var r = long.Parse(s.Substring(0, s.Length-1)) - 1;
            var c = 0;
            switch (s[s.Length - 1])
            {
                case 'a':
                    c = 4;
                    break;
                case 'b':
                    c = 5;
                    break;
                case 'c':
                    c = 6;
                    break;
                case 'd':
                    c = 3;
                    break;
                case 'e':
                    c = 2;
                    break;
                case 'f':
                    c = 1;
                    break;
            }
            Console.WriteLine(16 * (r / 4) + 7 * (r % 2) + c);
        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        string s = ReadToken();

        long n = long.Parse(s.Substring(0, s.Length - 1)) - 1;
        int m = "fedabc".IndexOf(s[s.Length - 1]);

        Write(n / 4 * 16 + n % 2 * 7 + m + 1);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;

class Program
{
    static Func<string, long> GetInt = x => { return Convert.ToInt64(x); };
    static void Main(string[] args)
    {
        Dictionary<char, int> sit = new Dictionary<char, int> {['f'] = 1, ['e'] = 2, ['d'] = 3, ['a'] = 4, ['b'] = 5, ['c'] = 6 };
        string str = Console.ReadLine();
        char ch = str[str.Length - 1];
        long n = GetInt(str.Substring(0, str.Length - 1));
        if (n % 4 == 3 || n % 4 == 0) n -= 2;
        long sec = sit[ch] + (n / 2) * 6 + n - 1;
        Console.Write(sec);
    }
}


using System;
using System.Globalization;
using System.IO;
using System.Linq;

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

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.NextString();
			var n = Int64.Parse(input.Substring(0, input.Length - 1));
			var m = input[input.Length - 1];
			var first = GetFirst(n);
			var second = GetSecond(n);

			sw.WriteLine(first * 6M + second + Count(m));
		}

		private long GetFirst(long n)
		{
			if (n % 2 == 0) {
				if (n % 4 != 0)
					n += 2;

				return (n / 4L) * 2L - 1L;
			}
			else {
				if ((n + 1)%4 == 0)
					n += 1;
				else
					n += 3;

				return (n / 4L) * 2L - 2L;
			}
		}

		private long GetSecond(long n)
		{
			if (n % 2 == 0) {
				if (n % 4 != 0)
					n += 2;

				return 1L + ((n / 4L) - 1L) * 4L;
			}
			if ((n + 1) % 4 == 0)
				n += 1;
			else
				n += 3;

			return (n / 4L - 1L) * 4L;
		}

		private long Count(char ch)
		{
			if (ch == 'f')
				return 1L;
			if (ch == 'e')
				return 2L;
			if (ch == 'd')
				return 3L;
			if (ch == 'c')
				return 6L;
			if (ch == 'b')
				return 5L;
			return 4L;
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	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(NextString());
	}

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

	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.Text;

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


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

namespace tes
{
	class contest
	{

		static void Main(string[] args)
		{

   string s = Console.ReadLine();
            string r = "";
            string c = "";
            int len = s.Length;
            for(int i=0; i< len; i++)
            {
                if (i < len - 1) r += s[i];
                else c += s[i];
            }

            var col = new string[]{"f","e","d","a","b","c" };
            long row = long.Parse(r);

            long time = (Array.IndexOf(col,c))+1;

            long a = row/3;
            long b = row % 3;

            long turn = row / 4;
            if (row % 4 > 0) turn++;

            time += (turn+turn-2) * 7;
            time += (turn -1) * 2;

            if (row % 2 == 0)
            {
                time += 7;
            }

            Console.WriteLine(time);

        }

	}
}


namespace Play.Codeforces
{
    using System;

    class Program
    {
        static void Main(string[] args)
        {
            string token = Console.ReadLine();

            long n = long.Parse(token.Substring(0, token.Length - 1));
            char s = token[token.Length - 1];

            long result = ((n-1)/4)*16;
            if (n%2 == 0)
            {
                result += 7;
            }
            switch (s)
            {
                case 'a':
                case 'b':
                case 'c':
                    result += (s - 'a' + 4);
                    break;
                case 'd':
                case 'e':
                case 'f':
                    result += ('f' - s + 1);
                    break;
            }
            Console.WriteLine(result);

        }

    }

}


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

namespace D
{
    class Program
    {
        static int GetNumberInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }

        static long GetNumberLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }

        static int[] GetArrayInt()
        {
            string[] @string = Console.ReadLine().Split(' ');
            int[] array = new int[@string.Length];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = Convert.ToInt32(@string[i]);
            }
            return array;
        }

        static long[] GetArrayLong()
        {
            string[] @string = Console.ReadLine().Split(' ');
            long[] array = new long[@string.Length];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = Convert.ToInt64(@string[i]);
            }
            return array;
        }
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            char place2 = str[str.Length - 1];
            str = str.Remove(str.Length - 1); //Console.WriteLine(str);
            ulong place1 = Convert.ToUInt64(str);
            ulong countRow = (place1 - 1) / 4;                    //Количество полных прошедших рядов
            place1 = (place1  % 4);
            if (place1 == 0)
                place1 = 4;
            ulong time = countRow * 16;
            switch (place2)
            {
                case 'f':
                    time += 1;
                    break;
                case 'e':
                    time += 2;
                    break;
                case 'd':
                    time += 3;
                    break;
                case 'a':
                    time += 4;
                    break;
                case 'b':
                    time += 5;
                    break;
                case 'c':
                    time += 6;
                    break;
            }
            if (place1 == 2 || place1 == 4)
                time += 7;
            Console.WriteLine(time);
        }
    }
}


using Boilerplate.IO;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Boilerplate.IO
{
    #region helpers
    class FormattedStreamWriter : StreamWriter
    {
        public FormattedStreamWriter(Stream stream) : base(stream) { }
        public FormattedStreamWriter(string filePath) : base(filePath) { }
        public override IFormatProvider FormatProvider
        {
            get
            {
                return CultureInfo.InvariantCulture;
            }
        }
    }
    static class IOExtensions
    {
        public static string ReadString(this StreamReader reader)
        {
            return reader.ReadToken();
        }
        public static int ReadInt(this StreamReader reader)
        {
            return int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
        }
        public static uint ReadUnsignedInt(this StreamReader reader)
        {
            return uint.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
        }
        public static long ReadLong(this StreamReader reader)
        {
            return long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
        }
        public static double ReadDouble(this StreamReader reader)
        {
            return double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
        }
        public static decimal ReadDecimal(this StreamReader reader)
        {
            return decimal.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
        }

        public static void ResetBuffer()
        {
            buffer = new Queue<string>(1000);
        }

        static Queue<string> buffer = new Queue<string>(1000);
        static string ReadToken(this StreamReader reader)
        {
            while (buffer.Count == 0)
            {
                reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach((t) =>
                {
                    buffer.Enqueue(t);
                });
            } return buffer.Dequeue();
        }
    }
    #endregion
}

#region launch
class Program
{
    static void Main2(string[] args)
    {
        var cycles = 100;
        while (cycles-- > 0)
        {
            Main2(new[] { "g" });
            Main2(new[] { "r" });
        }
    }

    static void Main(string[] args)
    {
#if SOLVER_ATWORKSPACE
        var run = true;
        var outputFile = "output.txt";
        var inputFile = "input.txt";
        switch (args[0])
        {
            case "g":
                run = false;
                outputFile = "input.txt";
                inputFile = "output.txt";
                break;
            case "r":
            default:
                run = true;
                inputFile = "input.txt";
                outputFile = "output.txt";
                break;
        }
#endif

        using (var writer = new FormattedStreamWriter(
#if SOLVER_ATWORKSPACE
outputFile
#else
            Console.OpenStandardOutput()
#endif
))
        {
            using (var reader = new StreamReader(
#if SOLVER_ATWORKSPACE
inputFile
#else
            Console.OpenStandardInput()
#endif
))
            {
#if SOLVER_ATWORKSPACE
                var stopw = new Stopwatch();
                stopw.Start();
#endif
#if SOLVER_ATWORKSPACE
                if (run)
                    new Solver(reader, writer).Do();
                else
                    new Generator(reader, writer).Create();

#else
                new Solver(reader, writer).Do();
#endif
#if SOLVER_ATWORKSPACE
                stopw.Stop();
                writer.WriteLine("> {0}ms", stopw.ElapsedMilliseconds);
#endif
            }
        }
    }
}
#endregion

public class Solver
{
    private readonly StreamReader reader;
    private readonly StreamWriter writer;

    public Solver(StreamReader reader, StreamWriter writer)
    {
        this.reader = reader;
        this.writer = writer;
    }

    public void Do()
    {
        var s = reader.ReadString();
        var pos = s[s.Length - 1];
        s = s.Substring(0, s.Length - 1);
        var n = long.Parse(s);
        long res = 0;
        var dc = new Dictionary<char, int>() {
            {'a', 4 },
            {'b', 5 },
            {'c', 6 },
            {'d', 3 },
            {'e', 2 },
            {'f', 1 },
        };
        --n;
        var nd = n / 4;
        var nr = n % 4;
        res += nd * 16;
        if (nr % 2 == 1)
            res += 7;
        res += dc[pos];
        writer.WriteLine(res);
    }
}


    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Threading;

    namespace Codeforces
    {
        class Program : IDisposable
        {
            private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
            private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

            private void Solve()
            {
                long ans = 0;
                var s = Console.ReadLine();
                var letter = s.Last();
                var numberS = s.Substring(0, s.Length - 1);
                long number = long.Parse(numberS);
                long lastNumber = long.Parse(numberS.Last().ToString());
                long rows = 0;

                var xEven = new List<long> {2, 6};
                var yEven = new List<long> {0, 4, 8};
                var xOdd = new List<long> {1, 5, 9};
                var yOdd = new List<long> {3, 7};

                long numberOfTen = number/10;
                bool numberOfTenIsEven = numberOfTen%2 == 0;
                bool isEven = number%2 == 0;

                if (numberOfTenIsEven)
                {
                    if (isEven)
                    {
                        if (lastNumber == 2 || lastNumber == 6)
                        {
                            rows = number/2 + 1;
                            ans += number;
                        }
                        else
                        {
                            rows = number/2;
                            ans += (number - 2);
                        }
                    }
                    else
                    {
                        if (lastNumber == 1 || lastNumber == 5 || lastNumber == 9)
                        {
                            rows = number / 2 + 1;
                            ans += number;
                        }
                        else
                        {
                            rows = number / 2;
                            ans += (number - 2);
                        }
                    }
                }
                else
                {
                    if (isEven)
                    {
                        if (lastNumber == 2 || lastNumber == 6)
                        {
                            rows = number / 2;
                            ans += (number - 2);
                        }
                        else
                        {
                            rows = number / 2+1;
                            ans += number;
                        }
                    }
                    else
                    {
                        if (lastNumber == 1 || lastNumber == 5 || lastNumber == 9)
                        {
                            rows = number / 2;
                            ans += (number - 2);
                        }
                        else
                        {
                            rows = number / 2+1;
                            ans += number;
                        }
                    }
                }
                ans--;
                ans += ((rows-1)*6);
                if (letter =='f')
                {
                    ans += 1;
                }
                else if (letter == 'e')
                    ans += 2;
                else if (letter == 'd')
                    ans += 3;
                else if (letter == 'a')
                    ans += 4;
                else if (letter == 'b')
                    ans += 5;
                else if (letter == 'c')
                    ans += 6;

                Console.WriteLine(ans);
            }

            static void Main(string[] args)
            {
                var p = new Program();
                p.Solve();
                //Console.ReadLine();
                p.Dispose();
            }

            #region Helpers

            private static int ReadInt()
            {
                return int.Parse(textReader.ReadLine());
            }

            private static long ReadLong()
            {
                return long.Parse(textReader.ReadLine());
            }

            private static int[] ReadIntArray()
            {
                return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }
            #endregion

            public void Dispose()
            {
                textReader.Close();
                textWriter.Close();
            }
        }
    }


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) {
            int row = Console.Read() - '0';
            int col = Console.Read() - 'c'; //a = -2, b = -1, c = 0, d = 1, e = 2, f = 3
            int seconds = 0;

            if(col <= 0) {
                seconds += 6 + col;
            } else {
                seconds += 4 - col;
            }

            //1, 2, 5, 6, 9, 10 - attendant A
            //3, 4, 7, 8, 11, 12 - attendant B
            int a = 1;
            int b = 3;
            for(; (a != row) && (b != row); a++, b++) { //quit when attendant reaches row
                if(a % 2 == 0) {
                    a += 2;
                    b += 2;
                    seconds += 2;
                }
                seconds += 7;
            }
            Console.WriteLine(seconds);
        }
    }
}


using System;

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


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

namespace CanadaCup2016
{
    class Submit
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var r = int.Parse(s[0].ToString()) - 1;
            var c = 0;
            switch (s[1])
            {
                case 'a':
                    c = 4;
                    break;
                case 'b':
                    c = 5;
                    break;
                case 'c':
                    c = 6;
                    break;
                case 'd':
                    c = 3;
                    break;
                case 'e':
                    c = 2;
                    break;
                case 'f':
                    c = 1;
                    break;
            }
            Console.WriteLine(12 * (r / 4) + 6 * (r % 2) + r - 2 * ((r % 4) / 2) + c);
        }
    }
}


using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {
            //var s = Console.ReadLine().Split(' ');
            var str = Console.ReadLine();
            var k = long.Parse(str.Substring(0,str.Length-1));
            byte g = 0;
            switch (str[str.Length - 1])
            {
                case 'a':
                    g = 4;
                    break;
                case 'b':
                    g = 5;
                    break;
                case 'c':
                    g = 6;
                    break;
                case 'd':
                    g = 3;
                    break;
                case 'e':
                    g = 2;
                    break;
                case 'f':
                    g = 1;
                    break;
            }
            var result = k/5*16;
            k = k%4 == 0 ? 4 : k%4;
            if (k%2 == 0)
            {
                result += 7 + g;
            }
            else result += g;
            Console.WriteLine(result);
        }
    }
}


using System;
using System.Globalization;
using System.IO;
using System.Linq;

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

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.NextString();
			var n = Int64.Parse(input.Substring(0, input.Length - 1));
			var m = input[input.Length - 1];
			var first = GetFirst(n);
			var second = GetSecond(n);

			sw.WriteLine((decimal)first*6M + (decimal)second + (decimal)Count(m));
		}

		private long GetFirst(long n)
		{
			if (n % 2 == 0) {
				if (n % 4 != 0) {
					n += 2;
				}

				return (n / 4L) * 2L - 1L;
			}
			else {
				if (n % 3 == 0) {
					n += 1;
				}
				else {
					n += 3;
				}

				return (n / 4L) * 2L - 2L;
			}
		}

		private long GetSecond(long n)
		{
			if (n % 2 == 0) {
				if (n % 4 != 0) {
					n += 2;
				}

				return 1L + ((n / 4L) - 1L) * 4L;
			}
			if (n % 3 == 0) {
				n += 1;
			}
			else {
				n += 3;
			}

			return (n / 4L - 1L) * 4L;
		}

		private long Count(char ch)
		{
			if (ch == 'f')
				return 1L;
			if (ch == 'e') {
				return 2L;
			}
			if (ch == 'd')
				return 3L;
			if (ch == 'c')
				return 6L;
			if (ch == 'b')
				return 5L;
			return 4L;
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	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(NextString());
	}

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

	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.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CanadaCup2016
{
    class Submit
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var r = long.Parse(s[0].ToString()) - 1;
            var c = 0;
            switch (s[1])
            {
                case 'a':
                    c = 4;
                    break;
                case 'b':
                    c = 5;
                    break;
                case 'c':
                    c = 6;
                    break;
                case 'd':
                    c = 3;
                    break;
                case 'e':
                    c = 2;
                    break;
                case 'f':
                    c = 1;
                    break;
            }
            Console.WriteLine(16 * (r / 4) + 7 * (r % 2) + c);
        }
    }
}


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

namespace CanadaCup2016
{
    class Submit
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var r = int.Parse(s[0].ToString()) - 1;
            var c = 0;
            switch (s[1])
            {
                case 'a':
                    c = 4;
                    break;
                case 'b':
                    c = 5;
                    break;
                case 'c':
                    c = 6;
                    break;
                case 'd':
                    c = 3;
                    break;
                case 'e':
                    c = 2;
                    break;
                case 'f':
                    c = 1;
                    break;
            }
            Console.WriteLine(16 * (r / 4) + 7 * (r % 2) + c);
        }
    }
}


    using System;

    namespace reverseString
    {
        class Program
        {
            static void Main(string[] args)
            {
            while (true)
            {
                System.Int64 ans, rem, r, s;
                String str = Console.ReadLine();

                int len = str.Length;
                r = 0;
                for (int i = 0; i < len - 1; i++)
                {
                    r = r * 10 + str[i] - '0';
                }

               // Console.WriteLine("r is {0}", r);
                s = str[len - 1];

               // Console.WriteLine("s is {0}", s);

                rem = (r - 1) / 4;
              //  Console.WriteLine("rem is {0}", rem);

                ans = rem * 12;
              // Console.WriteLine("ans is {0}", ans);

                if (r % 2 == 0)
                {
                    ans += 6;
                    //Console.WriteLine("ans1 is {0}", ans);
                }

                if (r % 4 == 1 || r % 4 == 2)
                {
                    ans += r - 1;
                   // Console.WriteLine("ans2 is {0}", ans);
                }
                else if (r % 4 == 3 || r % 4 == 0)
                {
                    ans += r - 3;
                  //  Console.WriteLine("ans3 is {0}", ans);
                }

                if (s == 'a')
                {
                    ans += 4;
                   // Console.WriteLine("ans4 is {0}", ans);
                }
                else if (s == 'b')
                {
                    ans += 5;
                    Console.WriteLine("ans5 is {0}", ans);
                }
                else if (s == 'c')
                {
                    ans += 6;
                  //  Console.WriteLine("ans6 is {0}", ans);
                }
                else if (s == 'd')
                {
                    ans += 3;
                   // Console.WriteLine("ans is {0}", ans);
                }
                else if (s == 'e')
                {
                    ans += 2;
                   // Console.WriteLine("ans is {0}", ans);
                }
                else
                {
                    ans += 1;
                  //  Console.WriteLine("ans is {0}", ans);
                }

                Console.WriteLine(ans);

            }

        }
        }

}


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

namespace ConsoleApplication1
{
    class CanadaCup2
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"D:\Sergey\Code\1.txt"));

            string ns = Console.ReadLine();
            int n = int.Parse(ns.Substring(0, ns.Length - 1));
            char s = ns[ns.Length - 1];
            int c = s - 'a';
            int[] d = new int[] { 3, 4, 5, 2, 1, 0 };
            int a = (n - 1) % 2;
            int b = (n - 1) / 4;
            //if (b > 1)
            //    b -= 2;

            int e = b * 16;
            if (a > 0)
                e+=7;
            e += d[c] + 1;

            Console.WriteLine(e);

        } // Main
    }
}


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; int A2 = 0;
            char C = char.Parse(S.Substring(L-1));
            int N = int.Parse(S.Substring(0,L-1));

            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;

            }

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

            Console.WriteLine(T);

        }
    }
}


using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {
            //var s = Console.ReadLine().Split(' ');
            var str = Console.ReadLine();
            var k = long.Parse(str.Substring(0,str.Length-1));
            byte g = 0;
            switch (str[str.Length - 1])
            {
                case 'a':
                    g = 4;
                    break;
                case 'b':
                    g = 5;
                    break;
                case 'c':
                    g = 6;
                    break;
                case 'd':
                    g = 3;
                    break;
                case 'e':
                    g = 2;
                    break;
                case 'f':
                    g = 1;
                    break;
            }
            var result = 0;
            while (k > 4)
            {
                result += 16;
                k -= 4;
            }
            if (k%2 == 0)
            {
                result += 7 + g;
            }
            else result += g;
            Console.WriteLine(result);
        }
    }
}


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

namespace D
{
    class Program
    {
        static double p_select(int l, int r, int inl, int inr)
        {
            inl = Math.Max(inl, l);
            inr = Math.Min(inr, r);
            if (inl > inr)
                return 0.0;

            return (double)(inr - inl + 1) / (double)(r - l + 1);
        }

        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            List<int>[] lucky = new List<int>[10];
            for (int i = 0; i < 10; i++)
                lucky[i] = new List<int>();
            lucky[1].Add(4);
            lucky[1].Add(7);

            int m = 10;
            for (int i = 2; i < 10; i++)
            {
                foreach (int x in lucky[i - 1])
                {
                    int y4 = m * 4 + x;
                    int y7 = m * 7 + x;
                    lucky[i].Add(y4);
                    lucky[i].Add(y7);
                }
                m *= 10;
            }

            lucky[0].Add(-1); // stop value
            lucky[0].Add(int.MaxValue - 1); // stop value
            int[] luckyAll = lucky[0].Union(lucky[1]).Union(lucky[2]).Union(lucky[3]).Union(lucky[4]).Union(lucky[5]).Union(lucky[6]).Union(lucky[7]).Union(lucky[8]).Union(lucky[9]).ToArray();
            Array.Sort(luckyAll);

            string[] line = Console.ReadLine().Split();
            int pl = int.Parse(line[0]);
            int pr = int.Parse(line[1]);
            int vl = int.Parse(line[2]);
            int vr = int.Parse(line[3]);
            int k = int.Parse(line[4]);

            double S = 0.0;

            int p = pl;
            while (p <= pr)
            {
                int fp = Array.BinarySearch(luckyAll, p);
                int q;
                if (fp < 0)
                {
                    fp = ~fp;
                    q = luckyAll[fp] - 1;
                    q = Math.Min(q, pr);

                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(pl, pr, p, q) * p_select(vl, vr, q1, q2);
                }
                else
                {
                    q = p;
                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    if (k == 1)
                    {
                        q1 = p + 1;
                    }
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(pl, pr, p, q) * p_select(vl, vr, q1, q2);
                }

                p = q + 1;
            }

            p = vl;
            while (p <= vr)
            {
                int fp = Array.BinarySearch(luckyAll, p);
                int q;
                if (fp < 0)
                {
                    fp = ~fp;
                    q = luckyAll[fp] - 1;
                    q = Math.Min(q, vr);

                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(vl, vr, p, q) * p_select(pl, pr, q1, q2);
                }
                else
                {
                    q = p;
                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    if (k == 1)
                    {
                        q1 = p + 1;
                    }
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(vl, vr, p, q) * p_select(pl, pr, q1, q2);
                }

                p = q + 1;
            }

            if (k == 1)
            {
                for (int i = 1; i < luckyAll.Length - 1; i++)
                {
                    int a = luckyAll[i];
                    if(a >= pl && a <= pr && a >= vl && a <= vl)
                        S += p_select(pl, pr, a, a) * p_select(vl, vr, a, a);
                }
            }

            Console.WriteLine("{0:0.000000000}", S);
        }
    }
}


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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += Intersectie(x1, x2, L[i - 1] + 1, L[i]) * Intersectie(y1, y2, L[j], L[j+1]-1);
            Rez += Intersectie(y1, y2, L[i - 1] + 1, L[i]) * Intersectie(x1, x2, L[j], L[j+1]-1);
        }

        long Posibilitati = (long)(x2 - x1 + 1) * (long)(y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static int Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drA <= drB) return drA - stB + 1;
        if (stB <= stA && drB <= drA) return drB - stA + 1;
        return 0;
    }
}


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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += Intersectie(x1, x2, L[i - 1] + 1, L[i]) * Intersectie(y1, y2, L[j], L[j+1]-1);
            Rez += Intersectie(y1, y2, L[i - 1] + 1, L[i]) * Intersectie(x1, x2, L[j], L[j+1]-1);
        }

        long Posibilitati = (x2 - x1 + 1) * (y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static int Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drB >= drA) return drA - stB + 1;
        if (stB <= stA && drA >= drB) return stA - drB + 1;
        return 0;
    }
}


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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += Intersectie(x1, x2, L[i - 1] + 1, L[i]) * Intersectie(y1, y2, L[j], L[j+1]-1);
            Rez += Intersectie(y1, y2, L[i - 1] + 1, L[i]) * Intersectie(x1, x2, L[j], L[j+1]-1);
        }

        long Posibilitati = (x2 - x1 + 1) * (y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static int Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drA <= drB) return drA - stB + 1;
        if (stB <= stA && drB <= drA) return drB - stA + 1;
        return 0;
    }
}


using System;
using System.IO;
//using System.Reflection;
//using System.Collections;
using System.Collections.Generic;
using System.Linq;
//using System.Text;
//using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static class Scanner
        {
            readonly static IEnumerator<string> Tokens;
            static Scanner()
            {
                Tokens = Enumerable.Range(Int32.MinValue, Int32.MaxValue).
                    Select(s => Console.ReadLine()).
                    TakeWhile(s => s != null).
                    SelectMany(s => s.Split(new[] { ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries)).
                    Concat(Enumerable.Repeat(0, 1).Select(_ => (string)null)).
                    GetEnumerator();
            }

            public static string NextToken()
            {
                Tokens.MoveNext();
                return Tokens.Current;
            }
        }

        int nextInt()
        {
            return int.Parse(Scanner.NextToken());
        }

        bool GoodValue(int a)
        {
            if (a <= 0) return false;
            while (a != 0)
            {
                if (a % 10 != 7 && a % 10 != 4) return false;
                a /= 10;
            }
            return true;
        }

        int[] GenSequence()
        {
            var l = new List<int>();
            var q = new Queue<int>();
            q.Enqueue(0);
            while (q.Count != 0)
            {
                int cur = q.Dequeue();
                l.Add(cur);
                if (GoodValue(cur * 10 + 4)) q.Enqueue(cur * 10 + 4);
                if (GoodValue(cur * 10 + 7)) q.Enqueue(cur * 10 + 7);
            }
            return l.Concat(Enumerable.Range(1111111111, 1)).OrderBy(c => c).ToArray();
        }

        int LowerBound(int v, int[] a)
        {
            int x = 0, y = a.Length;
            while (y - x > 1)
            {
                int z = (x + y) / 2;
                if (a[z] <= v) x = z;
                else y = z;
            }
            return x;
        }

        int Len(int x, int y, int[] a, int p)
        {
            if (p < 1 || p >= a.Length) return 0;
            int tx = Math.Max(x, a[p - 1]), ty = Math.Min(y, a[p]);
            if (GoodValue(tx)) tx++;
            if (GoodValue(ty)) ty--;
            return Math.Max(ty - tx + 1, 0);
        }

        void Solve()
        {
            var values = GenSequence();
            int pl = nextInt(), pr = nextInt(),
                vl = nextInt(), vr = nextInt(),
                k = nextInt();
            long res = 0;
            for (int x = 1; x < values.Length; x++)
            {
                long pc = Len(pl, pr, values, x);
                long rc1 = Len(vl, vr, values, x + k),
                    rc2 = Len(vl, vr, values, x - k);
                res += pc * (rc1 + rc2);
                if (x + k - 1 < values.Length && values[x + k - 1] >= vl && values[x + k - 1] <= vr) res += pc;
                if (x - k > 0 && values[x - k] >= vl && values[x - k] <= vr) res += pc;

                if (values[x] >= pl && values[x] <= pr)
                {
                    res += Len(vl, vr, values, x - k + 1);
                    res += Len(vl, vr, values, x + k);

                    res += new[] { x + k - 1, x - k + 1 }.Distinct().Where(
                        c => c > 0 && c < values.Length &&
                            values[c] >= vl && values[c] <= vr
                        ).Count();
                }
            }
            long all = (pr - pl + 1);
            all *= (vr - vl + 1);
            Console.Write("{0:F12}", (double)res / (double)(all));
        }

        static void Main()
        {
#if MY_SUPER_PUPER_ONLINE_JUDGE
            string dir = Directory.GetCurrentDirectory();
            dir = Directory.GetParent(dir).FullName;
            dir = Directory.GetParent(dir).FullName;
            Console.SetIn(new StreamReader(dir + "\\input.txt"));
            Console.SetOut(new StreamWriter(dir + "\\output.txt"));
#endif
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            new Program().Solve();
#if MY_SUPER_PUPER_ONLINE_JUDGE
            Console.In.Close();
            Console.Out.Close();
#endif
        }
    }
}


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

class LuckyProbability
{

    static int[] L = new int[1024];
    static int[] st = new int[10];
    static int LPos = 0;

    public static int Main()
    {
        //citire
        string[] citire = Console.ReadLine().Split(' ');
        int x1, x2, y1, y2, k;
        x1 = Convert.ToInt32(citire[0]);
        x2 = Convert.ToInt32(citire[1]);
        y1 = Convert.ToInt32(citire[2]);
        y2 = Convert.ToInt32(citire[3]);
        k = Convert.ToInt32(citire[4]);

        //solve
        back(1); L[1023] = 1000000001;
        Array.Sort(L, 1, 1022); //stocare numere Lucky

        int i, j; long Rez = 0;
        for (i = 1; i <= (1023 - k); i++)
        {
            j = i + k - 1;
            Rez += (long)Intersectie(x1, x2, L[i - 1] + 1, L[i]) * (long)Intersectie(y1, y2, L[j], L[j + 1] - 1);
            Rez += (long)Intersectie(y1, y2, L[i - 1] + 1, L[i]) * (long)Intersectie(x1, x2, L[j], L[j + 1] - 1);
            if (k == 1 && x1 <= L[i] && L[i] <= x2 && y1 <= L[i] && L[i] <= y2) Rez--;
        }

        long Posibilitati = (long)(x2 - x1 + 1) * (long)(y2 - y1 + 1);
        decimal Afis = (decimal)Rez / (decimal)Posibilitati;
        Console.WriteLine(Afis.ToString("N12"));
        Console.ReadKey();

        return 0;
    }

    public static void back(int k)
    {
        int i, j, x;
        for (i = 4; i <= 7; i += 3)
        {
            st[k] = i;
            if (k < 9) back(k + 1);
            x = 0;
            for (j = 1; j <= k; j++) x = x * 10 + st[j];
            L[++LPos] = x;
         }
    }

    public static long Intersectie(int stA, int drA, int stB, int drB)
    {
        if (drA < stB || drB < stA) return 0;
        if (stA <= stB && drB <= drA) return drB - stB + 1;
        if (stB <= stA && drA <= drB) return drA - stA + 1;
        if (stA <= stB && drA <= drB) return drA - stB + 1;
        if (stB <= stA && drB <= drA) return drB - stA + 1;
        return 0;
    }
}


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

namespace D
{
    class Program
    {
        static double p_select(int l, int r, int inl, int inr)
        {
            inl = Math.Max(inl, l);
            inr = Math.Min(inr, r);
            if (inl > inr)
                return 0.0;

            return (double)(inr - inl + 1) / (double)(r - l + 1);
        }

        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            List<int>[] lucky = new List<int>[10];
            for (int i = 0; i < 10; i++)
                lucky[i] = new List<int>();
            lucky[1].Add(4);
            lucky[1].Add(7);

            int m = 10;
            for (int i = 2; i < 10; i++)
            {
                foreach (int x in lucky[i - 1])
                {
                    int y4 = m * 4 + x;
                    int y7 = m * 7 + x;
                    lucky[i].Add(y4);
                    lucky[i].Add(y7);
                }
                m *= 10;
            }

            lucky[0].Add(-1); // stop value
            lucky[0].Add(int.MaxValue - 1); // stop value
            int[] luckyAll = lucky[0].Union(lucky[1]).Union(lucky[2]).Union(lucky[3]).Union(lucky[4]).Union(lucky[5]).Union(lucky[6]).Union(lucky[7]).Union(lucky[8]).Union(lucky[9]).ToArray();
            Array.Sort(luckyAll);

            string[] line = Console.ReadLine().Split();
            int pl = int.Parse(line[0]);
            int pr = int.Parse(line[1]);
            int vl = int.Parse(line[2]);
            int vr = int.Parse(line[3]);
            int k = int.Parse(line[4]);

            double S = 0.0;

            int p = pl;
            while (p <= pr)
            {
                int fp = Array.BinarySearch(luckyAll, p);
                int q;
                if (fp < 0)
                {
                    fp = ~fp;
                    q = luckyAll[fp] - 1;
                    q = Math.Min(q, pr);

                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(pl, pr, p, q) * p_select(vl, vr, q1, q2);
                }
                else
                {
                    q = p;
                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    if (k == 1)
                    {
                        q1 = p + 1;
                    }
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(pl, pr, p, q) * p_select(vl, vr, q1, q2);
                }

                p = q + 1;
            }

            p = vl;
            while (p <= vr)
            {
                int fp = Array.BinarySearch(luckyAll, p);
                int q;
                if (fp < 0)
                {
                    fp = ~fp;
                    q = luckyAll[fp] - 1;
                    q = Math.Min(q, vr);

                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(vl, vr, p, q) * p_select(pl, pr, q1, q2);
                }
                else
                {
                    q = p;
                    int idx1 = fp + k - 1;
                    int idx2 = fp + k;
                    int q1 = idx1 < luckyAll.Length ? luckyAll[idx1] : int.MaxValue;
                    if (k == 1)
                    {
                        q1 = p + 1;
                    }
                    int q2 = idx2 < luckyAll.Length ? luckyAll[idx2] - 1 : int.MaxValue;

                    S += p_select(vl, vr, p, q) * p_select(pl, pr, q1, q2);
                }

                p = q + 1;
            }

            if (k == 1)
            {
                for (int i = 1; i < luckyAll.Length - 1; i++)
                {
                    int a = luckyAll[i];
                    if(a >= pl && a <= pr && a >= vl && a <= vr)
                        S += p_select(pl, pr, a, a) * p_select(vl, vr, a, a);
                }
            }

            Console.WriteLine("{0:0.000000000}", S);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        long N, M, L, R;
        sc.Make(out N, out M, out L, out R);
        R -= L;
        if (N * M % 2 == 1)
        {
            Fail(ModInt.Pow(R + 1, N * M));
        }
        long odd = (R + 1) / 2, even = R / 2 + 1;
        ModInt a = (ModInt)odd / ((R+1) * 2);
        WriteLine(ModInt.Pow(R + 1, N * M - 1) * (a * odd + (1 - a) * even));
    }
}

public struct ModInt
{
    //public const long MOD = (int)1e9 + 7;
    public const long MOD = 998244353;
    public long Value { get; set; }
    public ModInt(long n = 0) { Value = n; }
    private static ModInt[] fac;//階乗
    private static ModInt[] inv;//逆数
    private static ModInt[] facinv;//1/(i!)
    public override string ToString() => Value.ToString();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Value += r.Value;
        if (l.Value >= MOD) l.Value -= MOD;
        return l;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Value -= r.Value;
        if (l.Value < 0) l.Value += MOD;
        return l;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator long(ModInt l) => l.Value;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator ModInt(long n)
    {
        n %= MOD; if (n < 0) n += MOD;
        return new ModInt(n);
    }

    public static ModInt Pow(ModInt m, long n)
    {
        if (n == 0) return 1;
        if (n % 2 == 0) return Pow(m * m, n >> 1);
        else return Pow(m * m, n >> 1) * m;
    }

    public static void Build(int n)
    {
        fac = new ModInt[n + 1];
        facinv = new ModInt[n + 1];
        inv = new ModInt[n + 1];
        inv[1] = 1;
        fac[0] = fac[1] = 1;
        facinv[0] = facinv[1] = 1;
        for (var i = 2; i <= n; i++)
        {
            fac[i] = fac[i - 1] * i;
            inv[i] = MOD - inv[MOD % i] * (MOD / i);
            facinv[i] = facinv[i - 1] * inv[i];
        }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Fac(ModInt n) => fac[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Inv(ModInt n) => inv[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt FacInv(ModInt n) => facinv[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Comb(ModInt n, ModInt r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        var calc = fac[n];
        calc = calc * facinv[r];
        calc = calc * facinv[n - r];
        return calc;
    }
}
#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i];A[i] = A[j];A[j] = t; }
    public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }
}
#endregion