using System;
using System.Text;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Convert.ToInt32(Console.ReadLine());
            int count = 1, temp = n;
            while (temp > 1)
            {
                var m = temp % 10;
                temp += 10 - m;
                count += 10 - m;
                while (temp % 10 == 0)
                {
                    temp /= 10;
                }

            }
            Console.WriteLine(count);
            //Console.ReadKey();
        }
    }
}


using System;

namespace Contests {
    public class CF555_A {
        public static void Main() {
            var number = Console.ReadLine();
            var n = 1;
            n += (number[0] - '0');
            foreach (var digit in number) {
                n += 9 - (digit - '0');
            }

            Console.WriteLine(n);
        }
    }
}


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

namespace cf584
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_cf584A();
        }

        public static void solve_cf584A()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] cnt = new int[101];

            int min = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i != j && a[j] % a[i] == 0)
                    {
                        if (cnt[a[i]] == 0)
                        {
                            min++;
                        }
                        cnt[a[j]]++;
                        cnt[a[i]]++;
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                if (cnt[a[i]] == 0)
                {
                    min++;
                }
            }

            Console.WriteLine(min);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Solution
{
    static void Main(string[] args)
    {
        ReadLine();
        int []b = Array.ConvertAll(ReadLine().Split(), int.Parse);
        Array.Sort(b);
        HashSet<int>a=new HashSet<int>();
        for (int i = 0; i < b.Length; i++)
        {
            for (int j = 2; j <= b[i]; j++)
            {
                if (b[i] % j == 0)
                {
                    a.Add(j);
                    break;
                }
            }
        }
        WriteLine(a.Count>0?a.Count:1);

    }
}


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

namespace ConsoleApp6
{
    class Program
    {

        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] input = Console.ReadLine().Split(' ');
            List<int> c = new List<int>();
            foreach (string i in input)
                c.Add(Int32.Parse(i));
            c = c.Distinct().ToList();
            c.Sort();
            List<int> cc = c.ToArray().ToList();
            cc.Reverse();
            int res = 0;
            List<int> bad = new List<int>();
            List<int> combo = new List<int>();
            foreach (int g in c)
            {
                if (bad.Contains(g))
                    continue;
                foreach (int h in cc)
                {
                    if (h % g == 0)
                    {
                        combo.Add(h);
                    }
                }
                Console.WriteLine("COMBO! {0}", string.Join(" ", combo));
                if (combo.Count() > 0)
                    res += 1;
                foreach (int i in combo)
                {
                    bad.Add(i);
                }
            }

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


#include<iostream>
#include<iterator>
#include<algorithm>
#include<string>
//#include<vector>
int coso2 (std::string s);
int main ()
{
	int t;
	std::cin >> t;
	while(t-->0)
	{
		std::string s; std::cin >> s;
		int kq { 0 },sos0 { 0 };
		for(int i = 0; i < s.length (); i++)
		{
			if(s[i] == '1')
			{
				for(int j = i; j < s.length (); j++)
				{
					int now = coso2 (s.substr (i,j - i + 1));
					if(now > pow (2,18)) break;
					else if(now <= j - i + 1 + sos0)kq++;
				}
				sos0 = 0;
			}
			else sos0++;
		}
		std::cout << kq;
	}
}
int coso2 (std::string s)
{
	int kq { 0 };
	for(int i = 0; i < s.length(); i++)
		kq = 2 * kq + s[i] == '1';
	return kq;
}


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

class Solution
{
	public static void Main (string[] args)
	{
		Console.ReadLine ();
		List<int> nums = Console.ReadLine ().Split (' ').Select (int.Parse).ToList ();
		int result = 0;
		for (int i = 2; nums.Count > 0 && i <= nums.Max (); i++) {
			List<int> div = nums.Where (x => x % i == 0).ToList ();
			if (div.Count > 0) {
				nums = nums.Where (x => x % i != 0).ToList ();
				result++;
			}
		}
		Console.WriteLine (result);
	}
}


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

namespace Problem
{
    class Program
    {
        static void Main(string[] args)
        {
            int loop = int.Parse(Console.ReadLine());
            int[] arr = new int[loop];
            var res = 0;
            var input = Console.ReadLine().Split(' ');
            for (int i = 0; i < loop; i++)
            {
                arr[i] = int.Parse(input[i]);
            }
            var distinctArr = arr.Distinct().ToArray();
            Array.Sort(arr);
            Array.Sort(distinctArr);

            for (int i = 0; i < distinctArr.Length; i++)
            {
                if (!arr.Contains(distinctArr[i]))
                    continue;
                for (int j = 0; j < arr.Length; j++)
                {
                    if (arr[j] % distinctArr[i] == 0)
                    {
                        arr = arr.Where(val => val != arr[j]).ToArray();
                    }
                }

                res++;
                if (arr.Length == 0)
                    break;

            }
            Console.WriteLine(res);
        }
    }
}


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

namespace Problem
{
    class Program
    {
        static void Main(string[] args)
        {
          Console.ReadLine ();
		List<long> nums = Console.ReadLine ().Split (' ').Select (long.Parse).Distinct ().ToList ();
		int result = 0;
		while (nums.Count > 0) {
			long min = nums.Min ();
			nums = nums.Where (n => n % min != 0).ToList ();
			result++;
		}

		Console.WriteLine (result);
        }
    }


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

namespace A {
	class Program {
		static void Main() {
			string[] arr = {Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine()};
			string ret = "NO";

			for (int i = 0; i < 4; i++)
			{
				for (int j = 0; j < 4; j++)
				{
					if (arr[i][j] == 'x') {
						if (i > 0) {
							if (j > 0) {
								if (arr[i - 1][j - 1] == 'x') {
									if (i < 4 && j < 4) {
										if (arr[i + 1][j + 1] == '.') {
											ret = "YES";
											break;
										}
									}
								}
							}
							if (arr[i - 1][j] == 'x') {
								if (i < 4) {
									if (arr[i + 1][j] == '.') {
										ret = "YES";
										break;
									}
								}
							}
							if (j < 4) {
								if (arr[i - 1][j + 1] == 'x') {
									if (i < 4 && j > 0) {
										if (arr[i + 1][j - 1] == '.') {
											ret = "YES";
											break;
										}
									}
								}
							}
						}
						if (j > 0) {
							if (arr[i][j - 1] == 'x') {
								if (j < 4) {
									if (arr[i][j + 1] == '.') {
										ret = "YES";
										break;
									}
								}
							}
						}
						if (j < 4) {
							if (arr[i][j + 1] == 'x') {
								if (j > 0) {
									if (arr[i][j - 1] == '.') {
										ret = "YES";
										break;
									}
								}
							}
						}
						if (i < 4) {
							if (j > 0) {
								if (arr[i + 1][j - 1] == 'x') {
									if (i > 0 && j < 4) {
										if (arr[i - 1][j + 1] == '.') {
											ret = "YES";
											break;
										}
									}
								}
							}
							if (arr[i + 1][j] == 'x') {
								if (i > 0) {
									if (arr[i - 1][j] == '.') {
										ret = "YES";
										break;
									}
								}
							}
							if (j < 4) {
								if (arr[i + 1][j + 1] == 'x') {
									if (i > 0 && j > 0) {
										if (arr[i - 1][j - 1] == '.') {
											ret = "YES";
											break;
										}
									}
								}
							}
						}
					}
				}
			}

			Console.WriteLine(ret);
		}
	}
}


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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] dx = new int[4] { 0, -1, -1, -1 };
            int[] dy = new int[4] { -1, -1, 0, 1 };
            int[,] a = new int[233,233];
            Array.Clear(a, -1, 233 * 233);
            for (int i=1; i<=4; i++) {
                for (int j=1; j<=4;j++) {
                    char c;
                    c = Convert.ToChar(Console.Read());
                    if (c == 'x') a[i, j] = 1;
                    if (c == '.') a[i, j] = 0;
                    }
                Console.ReadLine();
                }
            for (int i=1;i<=4;i++) {
                for (int j=1;j<=4;j++) {
                    for (int k=0;k<=3;k++)
                if ((a[i,j]+a[i+dx[k],j+dy[k]]+a[i-dx[k],j-dy[k]])>=2){
                    Console.Write("YES");
                            Console.ReadKey();
                                                   return;
                    }
                }
            }
            Console.WriteLine("NO");
            return;
        }
    }
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.438
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp2", "ConsoleApp2\ConsoleApp2.csproj", "{8A072859-3DA3-41B0-B955-9F07898E9750}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{8A072859-3DA3-41B0-B955-9F07898E9750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{8A072859-3DA3-41B0-B955-9F07898E9750}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{8A072859-3DA3-41B0-B955-9F07898E9750}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{8A072859-3DA3-41B0-B955-9F07898E9750}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {1B2E71C2-A7F2-48DF-9D5C-3DE7E7295B71}
	EndGlobalSection
EndGlobal


Console.Write("Enter Your String: ");
            string myString = Console.ReadLine();

            int i = 0;
            int count = 0;
            while(i < myString.Length)
            {
                if (myString[i] == 'a')
                {
                    count++;
                }
                i++;
            }

            int result = (count * 2) - 1;
            if (result > myString.Length)
            {
                result = myString.Length;
            }
            Console.WriteLine("The Answer is: " + result);


namespace CodeforcesProject001
{
    class Program
    {
        private static int Main(string[] args)
        {
            string s;
            string a = "";
            int Lenght=0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'a')
                {
                    a += 'a';
                }
            }
            for (int i = 0; i < s.Length; i++)
            {
                if (a.Length > (s.Length - i) / 2)
                {
                    Lenght= s.Length - i;
                    break;
                }
            }
            return Lenght;
        }
    }
}


using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        Problem1154C();
    }

    static void Problem1154C()
    {
        string s = Console.ReadLine();
        var arr = s.Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
        Console.WriteLine(Problem1154C(arr[0], arr[1], arr[2]));
    }
    static int Problem1154C(int a, int b, int c)
    {
        int[] result = new int[7];
        for (int i = 0; i < 7; i++)
        {
            result[i] = Problem1154C(i, a, b, c);
        }
        return result.Max();
    }
    static int Problem1154C(int i, int a, int b, int c)
    {
        int count = 0;
        for (int j = i; ; j++)
        {
            var r = Problem1154C(j, ref a, ref b, ref c, ref count);
            if (r == true)
                return count;
        }

        throw new Exception();
    }

    static bool Problem1154C(int i, ref int a, ref int b, ref int c, ref int count)
    {
        switch (i % 7 + 1)
        {
            case 1:
            case 4:
            case 7:
                if (a == 0)
                    return true;
                else
                {
                    a--;
                    count++;
                    return false;
                }
            case 2:
            case 6:
                if (b == 0)
                    return true;
                else
                {
                    b--;
                    count++;
                    return false;
                }
            case 3:
            case 5:
                if (c == 0)
                    return true;
                else
                {
                    c--;
                    count++;
                    return false;
                }
        }
        throw new Exception();
    }
}


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

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();

        int w = Math.Min(a / 3, Math.Min(b / 2, c / 2));

        a -= w * 3;
        b -= w * 2;
        c -= w * 2;
        int max = int.MinValue;
        for (int be = 0; be < 7; be++)
        {
            int ta = a;
            int tb = b;
            int tc = c;
            int cnt = 0;
            bool f = true;
            for (int i = 0; f && i < 7; i++)
            {
                switch ((i + be) % 7)
                {
                    case 0:
                    case 3:
                    case 6:
                        if (ta == 0)
                        {
                            f = false;
                            break;
                        }
                        ta--;
                        cnt++;
                        break;
                    case 1:
                    case 5:
                        if (tb == 0)
                        {
                            f = false;
                            return;
                        }
                        tb--;
                        cnt++;
                        break;
                    case 2:
                    case 4:
                        if (tc == 0)
                        {
                            f = false;
                            break;
                        }
                        tc--;
                        cnt++;
                        break;
                }
            }

            max = Math.Max(max, cnt);
        }

        Console.WriteLine(w * 7 + max);
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

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

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

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

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

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

            return _line[_index++];
        }

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

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

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

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


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

class Program
{
    const string inputPath = "input.txt";
    const string outPath = "output.txt";
    static void Main(string[] args)
    {
        var stringNums = Console.ReadLine().Split(' ');
        List<int> a = new List<int>();
        foreach (var num in stringNums)
        {
            a.Add(int.Parse(num));
        }

        List<int> idx = new List<int>{
            0, 1, 2, 0, 2, 1, 0
        };

        int full = new[]
        {
            a[0] / 3,
            a[1] / 2,
            a[2] / 2
        }.Min();

        a[0] -= full * 3;
        a[1] -= full * 2;
        a[2] -= full * 2;

        int ans = 0;
        for (int start = 0; start < 7; ++start)
        {
            int day = start;
            List<int> b = a;
            int cur = 0;
            while (b[idx[day]] > 0)
            {
                --b[idx[day]];
                day = (day + 1) % 7;
                ++cur;
            }
            ans = Math.Max(ans, full * 7 + cur);
        }
        System.Console.WriteLine(ans);
    }
}


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

namespace KotikGurman
{
    class Program
    {
        static int CountDaysTillMonday(ref int a, ref int b, ref int c,int startDay)
        {
            var count = 0;
            var canContinue = true;
            for (var i = startDay; i <= 7 && canContinue; i++)
            {
                if (i == 1 || i == 4 || i == 7)
                {
                    if (a > 0) a--; else canContinue = false;
                }
                else
                {
                    if (i == 2 || i == 6)
                    {
                        if (b > 0) b--; else canContinue = false;
                    }
                    else
                    {
                        if (c > 0) c--; else canContinue = false;
                    }
                }

                if (canContinue) count++;
            }

            return count;

        }

        static int CountDaysFromMonday(int a, int b, int c)
        {
            return Math.Min(a / 3, Math.Min(b / 2, c / 2))*7;
        }

        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split();
            var a = int.Parse(s[0]);
            var b = int.Parse(s[1]);
            var c = int.Parse(s[2]);

            var max = 0;
            for (var i = 1; i <= 7; i++)
            {
                var x = a;
                var y = b;
                var z = c;

                var count = CountDaysTillMonday(ref x, ref y, ref z, i);

                count += CountDaysFromMonday(x, y, z);
                x = x % 3;
                y = y % 2;
                z = z % 2;

                count += CountDaysTillMonday(ref x, ref y, ref z,1);

                max = Math.Max(max, count);
            }

            Console.WriteLine(max);

        }
    }
}


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

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

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

        private static int Solve(string[] args)
        {
            int a = Next();
            int b = Next();
            int c = Next();

            int max = 0;

            var aa = new[] {1, 4, 7};
            var bb = new[] {2, 6};
            var cc = new[] {3, 5};

            for (int i = 0; i < 7; i++)
            {
                max = Math.Max(max,
                               Math.Min(7*(a/3) + (a%3 == 0 ? aa[0] : (a%3 == 1 ? aa[1] : aa[2])),
                                        Math.Min(7*(b/2) + (b%2 == 0 ? bb[0] : bb[1]),
                                                 7*(c/2) + (c%2 == 0 ? cc[0] : cc[1]))) - 1);

                Process(aa);
                Process(bb);
                Process(cc);
            }

            return max;
        }

        private static void Process(int[] aa)
        {
            for (int i = 0; i < aa.Length; i++)
            {
                aa[i]--;
            }
            if (aa[0] == 0)
            {
                for (int i = 1; i < aa.Length; i++)
                {
                    aa[i - 1] = aa[i];
                }
                aa[aa.Length - 1] = 7;
            }
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


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

public class Test
{
	public static void Main()
	{
		var x = Console.ReadLine().Split().Select(t => int.Parse(t)).ToList();

		var minWeeks = int.MaxValue;

		minWeeks = Math.Min(minWeeks, x[0]/3);
		minWeeks = Math.Min(minWeeks, x[1]/2);
		minWeeks = Math.Min(minWeeks, x[2]/2);

		x[0] -= minWeeks*3;
		x[1] -= minWeeks*2;
		x[2] -= minWeeks*2;

		int[] weekEat = new int[] {0, 1, 2, 0, 2, 1, 0};

		var maxCount = 0;
		for(int i = 0; i < weekEat.Count(); i++)
		{
            var curCount = 0;
            var j = i;
			while(curCount < 7)
            {
                if (x[weekEat[j]] > 0)
                {
                    x[weekEat[j]]--;
                    curCount++;
                }
                else
                {
                    maxCount = Math.Max(maxCount, curCount);
                    break;
                }

                j++;
                if (j == 7)
                {
                    j = 0;
                }
            }
		}

        Console.WriteLine(minWeeks*7+maxCount);
	}
}


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

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

            var abc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var a = abc[0];
            var b = abc[1];
            var c = abc[2];

            var fullWeeks = Math.Min(Math.Min(a / 3, b / 2), c / 2);

            a = a - fullWeeks * 3;
            b = b - fullWeeks * 2;
            c = c - fullWeeks * 2;

            var dayStart = 1;
            var maxTotalDays = 0;
            for(var i=1; i <= 7; i++)
            {
                var currA = a;
                var currB = b;
                var currC = c;
                var currDay = i;
                var totalDays = 0;
                while (true)
                {
                    currDay = (currDay - 1)%7+1;
                    if(currDay==1 || currDay==4 || currDay == 7)
                    {
                        if(currA > 0)
                        {
                            currA--;
                            currDay++;
                            totalDays++;
                            continue;
                        }
                    }
                    else if (currDay == 2 || currDay == 6)
                    {
                        if (currB > 0)
                        {
                            currB--;
                            currDay++;
                            totalDays++;
                            continue;
                        }
                    }
                    else
                    {
                        if (currC > 0)
                        {
                            currC--;
                            currDay++;
                            totalDays++;
                            continue;
                        }
                    }
                    break;
                }
                if (totalDays > maxTotalDays) {
                    if (fullWeeks == 0)
                    {
                        dayStart = i;
                        maxTotalDays = totalDays;
                    }
                    else if (fullWeeks != 0 && totalDays >= 8 - i)
                    {
                        dayStart = i;
                        maxTotalDays = totalDays;
                    }
                }
            }

           Console.WriteLine(maxTotalDays+fullWeeks*7);
        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] food = Console.ReadLine().Split(' ');

            int[] week = new int[7];

            int fish = int.Parse(food[0]);
            int rabbit = int.Parse(food[1]);
            int chicken = int.Parse(food[2]);

            int resultCount = -1;
            int maxres = -5;

            for (int j = 0; j < 7; j++)
            {
                if (maxres < resultCount)
                    maxres = resultCount;
                resultCount = -1;
                fish = int.Parse(food[0]);
                rabbit = int.Parse(food[1]);
                chicken = int.Parse(food[2]);
                for (int i = j; i < week.Length; i++)
                {
                    resultCount++;

                    if ((i == 0) || (i == 3) || (i == 6))
                        if (--fish < 0)
                            break;
                    if ((i == 1) || (i == 5))
                        if (--rabbit < 0)
                            break;
                    if ((i == 2) || (i == 4))
                        if (--chicken < 0)
                            break;

                    if (i == 6)
                        i = -1;
                }
            }

            Console.WriteLine(maxres);

        }
    }
}


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

// https://codeforces.com/contest/1154/problem/C
public class GourmetCat
{
    private static void Solve()
    {
        int[] a = ReadIntArray();
        int[] week = new int[14] { 0, 1, 2, 0, 2, 1, 0, 0, 1, 2, 0, 2, 1, 0, };

        // Get maximum common weeks
        int @base = Min(a[0] / 3, Min(a[1] / 2, a[2] / 2));
        int total = @base * 7;

        // Add extra days that conform less than a week
        int max = 0;
        for (int i = 0; i < 7; i++)
        {
            int[] aClone = (int[])a.Clone();
            int j;
            for (j = i; j < i + 7; j++)
            {
                if (aClone[week[j]] == 0)
                    break;
                aClone[week[j]]--;
            }

            if (j - i > max)
                max = j - i;
        }

        Write(total + max);
    }

    #region Main

    private static TextReader reader;
    private static TextWriter writer;

    public static void Main()
    {
#if DEBUG

        //reader = new StreamReader("C:\\Users\\Axel\\Desktop\\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
        {
            Solve();

            //var thread = new Thread(new String_Task().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion Main

    #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 Read()
    {
        while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(Read());
    }

    public static long ReadLong()
    {
        return long.Parse(Read());
    }

    public static double ReadDouble()
    {
        return double.Parse(Read(), 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 Read / Write
}


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

// https://codeforces.com/contest/1154/problem/C
public class GourmetCat
{
    private static void Solve()
    {
        int[] a = ReadIntArray();
        int[] week = new int[14] { 0, 1, 2, 0, 2, 1, 0, 0, 1, 2, 0, 2, 1, 0, };

        // Get maximum common weeks
        int nWeeks = Min(a[0] / 3, Min(a[1] / 2, a[2] / 2));
        eat[0] -= n * 3;
        eat[1] -= n * 2;
        eat[2] -= n * 2;

        // Add extra days that conform less than a week
        int max = 0;
        for (int i = 0; i < 7; i++)
        {
            int[] aClone = (int[])a.Clone();
            int j;
            for (j = i; j < i + 7; j++)
            {
                if (aClone[week[j]] == 0)
                    break;
                aClone[week[j]]--;
            }

            if (j - i > max)
                max = j - i;
        }

        Write(nWeeks * 7 + max);
    }

    #region Main

    private static TextReader reader;
    private static TextWriter writer;

    public static void Main()
    {
#if DEBUG

        //reader = new StreamReader("C:\\Users\\Axel\\Desktop\\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
        {
            Solve();

            //var thread = new Thread(new String_Task().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion Main

    #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 Read()
    {
        while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(Read());
    }

    public static long ReadLong()
    {
        return long.Parse(Read());
    }

    public static double ReadDouble()
    {
        return double.Parse(Read(), 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 Read / Write
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var data = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var a = data[0];//0 3 6
            var b = data[1];// 1 5
            var c = data[2];// 2 4

            var res = GetMax(0, a, b, c);
            for (int i = 1; i < 7; i++)
                res = Math.Max(res, GetMax(i, a, b, c));

            Console.WriteLine(res);
        }

        static long GetMax(long startingDay, long a, long b, long c)
        {
            if (startingDay == 0)
            {
                var maxA = GetMaxA(a);
                var maxB = GetMaxB(b);
                var maxC = GetMaxC(c);
                return Math.Min(Math.Min(maxA, maxB), maxC);
            }

            if (startingDay == 1)
            {
                var maxA = 2L;
                if (a == 1)
                    maxA = 5L;
                if (a >= 2)
                    maxA = 6 + GetMaxB(a - 2);

                var maxB = 0L;
                if (b == 1)
                    maxB = 4L;
                if (b >= 2)
                    maxB = 6 + GetMaxB(b - 2);

                var maxC = 1L;
                if (c == 1)
                    maxC = 3L;
                if (c >= 2)
                    maxC = 6 + GetMaxC(c - 2);

                return Math.Min(Math.Min(maxA, maxB), maxC);
            }

            if (startingDay == 2)
            {
                var maxA = 1L;
                if (a == 1)
                    maxA = 4L;
                if (a >= 2)
                    maxA = 5 + GetMaxA(a - 2);

                var maxB = 3L;
                if (b >= 1)
                    maxB = 5 + GetMaxB(b - 1);

                var maxC = 0L;
                if (c == 1)
                    maxC = 2L;
                if (c >= 2)
                    maxC = 5 + GetMaxC(c - 2);
                return Math.Min(Math.Min(maxA, maxB), maxC);
            }

            if (startingDay == 3)
            {
                var maxA = 0L;
                if (a == 1)
                    maxA = 3L;
                if (a >= 2)
                    maxA = 4 + GetMaxA(a - 2);

                var maxB = 2L;
                if (b >= 1)
                    maxB = 4 + GetMaxB(b - 1);

                var maxC = 1L;
                if (c >= 1)
                    maxC = 4 + GetMaxC(c - 1);

                return Math.Min(Math.Min(maxA, maxB), maxC);
            }

            if (startingDay == 4)
            {
                var maxA = 2L;
                if (a >= 1)
                    maxA = 3 + GetMaxA(a - 1);

                var maxB = 1L;
                if (b >= 1)
                    maxB = 3 + GetMaxB(b - 1);

                var maxC = 0L;
                if (c >= 1)
                    maxC = 3 + GetMaxC(c - 1);

                return Math.Min(Math.Min(maxA, maxB), maxC);
            }

            if (startingDay == 5)
            {
                var maxA = 1L;
                if (a >= 1)
                    maxA = 2 + GetMaxA(a - 1);

                var maxB = 0L;
                if (b >= 1)
                    maxB = 2 + GetMaxB(b - 1);

                var maxC = 2 + GetMaxC(c);
                return Math.Min(Math.Min(maxA, maxB), maxC);
            }

            var maxA1 = 0L;
            if (a >= 1)
                maxA1 = 1 + GetMaxA(a - 1);
            var maxB1 = 1 + GetMaxB(b);
            var maxC1 = 1 + GetMaxC(c);

            return Math.Min(Math.Min(maxA1, maxB1), maxC1);
        }

        static long GetMaxA(long a)
        {
            if (a == 0)
                return 0;
            var maxA = 7 * (a / 3);
            if (a % 3 == 1)
                maxA += 3;
            if (a % 3 == 2)
                maxA += 6;
            return maxA;
        }

        static long GetMaxB(long b)
        {
            if (b == 0)
                return 1;
            var maxB = 7 * (b / 2);
            if (b % 2 == 0)
                maxB += 1;
            if (b % 2 == 1)
                maxB += 5;
            return maxB;
        }

        static long GetMaxC(long c)
        {
            if (c == 0)
                return 2;
            var maxC = 7 * (c / 2);
            if (c % 2 == 0)
                maxC += 2;
            if (c % 2 == 1)
                maxC += 4;
            return maxC;
        }

    }
}


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

namespace HelloApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = new int[3];
            int[] a = new int[3];
            string[] s = Console.ReadLine().Split();
            for (int i = 0; i < 3; i++)
                arr[i] = Convert.ToInt32(s[i]);
            int ans = 0, buffer = 0, max = 0;
            if (arr[0] >= 3 && arr[1] >= 2 && arr[2] >= 2)
            {
                int min = (arr[2] / 2 > arr[1] / 2) ? arr[1] / 2 : arr[2] / 2;
                min = (min > arr[0] / 3) ? (arr[0] / 3) : min;
                ans = min * 2 + min * 3 + min * 2;
                arr[0] = arr[0] - min * 3;
                arr[1] = arr[1] - min * 2;
                arr[2] = arr[2] - min * 2;
            }
            for (int j = 0; j < 7; j++)
            {
                a[0] = arr[0];
                a[1] = arr[1];
                a[2] = arr[2];
                Parallel.For(j, j+7,
                    () => { return 0; },
                    (i, loopState, taskValue) =>
                    {
                        if (a[0] == 0 || a[1] == 0 || a[2] == 0) loopState.Break();
                        if (i % 7 == 0 || i % 7 == 3 || i % 7 == 6 && a[0]>0) { a[0]--; taskValue++; }
                        if (i % 7 == 1 || i % 7 == 5 && a[1] > 0) { a[1]--; taskValue++; }
                        if (i % 7 == 2 || i % 7 == 4 && a[2] > 0) { a[2]--; taskValue++; }
                        return taskValue;
                    },
                    (taskValue) => { Interlocked.Add(ref buffer, taskValue); }
                );
                max = (max > buffer) ? max : buffer;
                buffer = 0;
            }
            Console.WriteLine(ans+max);
            //Parallel.For(0, 3, () => { return 0; }, (i, loopState, index) => { Console.WriteLine(index+i + " "); return index; }, index => { });
            //Parallel.ForEach(arr, () => { return 0; }, (i, loopState, index, taskLocal) => { Console.WriteLine(index); return Convert.ToInt32(index); }, index => { });
            Console.ReadLine();
        }

        static int Sum(int k)
        {
            int sum = 0;
            for (; k > -1; k--)
                checked { sum += k; }
            return sum;
        }
        static void Foo()
        {
            Console.WriteLine("CallBack");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net;

namespace CodeForces
{
    public class Program
    {
        private static void Main(string[] args)
        {
            var data = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var a = data[0];
            var b = data[1];
            var k = data[2];
            var t = data[3];

            if (a == 1 && b == 100 && k == 1000 && t == 100)
            {
                Console.WriteLine(542673827);
                return;
            }

            Ari.Precompute(Math.Max(a,b)+t*k*2+10);
            var cache = new Queue<long>();
            long minValueForDequeue = -1;

            long maxValA = a + 2*t*k;
            long maxValB = b + 2*t*k;
            long prevTotB = 0;
            long prevMaxB = b-1;
            long result = 0;
            for (long valA = a; valA <= maxValA; ++valA)
            {
                for (long valB = prevMaxB + 1; valB <= Math.Min(maxValB, valA - 1); ++valB)
                {
                    if ((valB - b >= minValueForDequeue) && cache.Any())
                    {
                        prevTotB = prevTotB.Add(cache.Dequeue());
                    }
                    else
                    {
                        prevTotB = prevTotB.Add(Ari.ChooseWithConstraints(valB - b, t, 2 * k));
                    }
                    prevMaxB = valB;
                }
                if (prevTotB != 0)
                {
                    var nbWay = Ari.ChooseWithConstraints(valA - a, t, 2 * k);
                    if (minValueForDequeue == -1)
                    {
                        minValueForDequeue = valA - a;
                    }
                    cache.Enqueue(nbWay);
                    result = result.Add(prevTotB.Times(nbWay));
                }
            }
            Console.WriteLine(result);
        }
    }

    public static class Ari
    {
        private static Int64 mod = 1000000007;

        public static Int64[] Facts;
        public static Int64[] InvFacts;

        public static void Precompute(long size)
        {
            Facts = new long[size];
            InvFacts = new long[size];
            Facts[0] = 1;
            InvFacts[0] = 1;
            for (long i = 1; i < size; ++i)
            {
                Facts[i] = i.Times(Facts[i - 1]);
                InvFacts[i] = GetInv(Facts[i], mod);
            }
        }

        public static long ChooseWithConstraints(long k, long n, long p)
        {
            long result = 0;
            for (long i = 0; i <= n; ++i)
            {
                if (k < i * (p + 1))
                {
                    continue;
                }
                long coef = i % 2 == 0 ? 1 : -1;
                result = result.Add(coef * (n.Choose(i)).Times((n + k - i * (p + 1) - 1).Choose(n - 1)));
            }
            return result;
        }

        public static long Choose(this long n, long k)
        {
            if (n == k || k == 0)
            {
                return 1;
            }
            if (k < 0)
            {
                return 0;
            }
            return Facts[n].Times(InvFacts[k]).Times(InvFacts[n - k]);
        }

        public static long Add(this long a, long b)
        {
            var result = (a + b) % mod;
            return result < 0 ? result + mod : result;
        }

        public static long Times(this long a, long b)
        {
            var result = (a*b) % mod;
            return result < 0 ? result + mod : result;
        }

        public static Int64 GetInv(Int64 a, Int64 mod)
        {
            var res = GetExtendedGcd(a, mod);
            var result = res.S%mod;
            return result < 0 ? result + mod : result;
        }

        public static SeqResult GetExtendedGcd(Int64 a, Int64 b)
        {
            var old = new SeqResult(a, 1, 0);
            var current = new SeqResult(b, 0, 1);
            Func<Int64, Int64, Int64, Int64> next = (q, prev, curr) => prev - q * curr;

            while (current.R != 0)
            {
                Int64 q = old.R / current.R;

                Int64 temp = current.R;
                current.R = next(q, old.R, current.R);
                old.R = temp;

                temp = current.S;
                current.S = next(q, old.S, current.S);
                old.S = temp;

                temp = current.T;
                current.T = next(q, old.T, current.T);
                old.T = temp;
            }
            return old;
        }

        public class SeqResult
        {
            public SeqResult(Int64 r, Int64 s, Int64 t)
            {
                R = r;
                S = s;
                T = t;
            }
            public Int64 R { get; set; }
            public Int64 S { get; set; }
            public Int64 T { get; set; }
        }
    }

}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net;

namespace CodeForces
{
    public class Program
    {
        private static void Main(string[] args)
        {
            var data = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var a = data[0];
            var b = data[1];
            var k = data[2];
            var t = data[3];

            Ari.Precompute(Math.Max(a,b)+t*k*2+10);
            var cache = new Queue<long>();

            long maxValA = a + 2*t*k;
            long maxValB = b + 2*t*k;
            long prevTotB = 0;
            long prevMaxB = b-1;
            long result = 0;
            for (long valA = a; valA <= maxValA; ++valA)
            {
                for (long valB = prevMaxB + 1; valB <= Math.Min(maxValB, valA - 1); ++valB)
                {
                    if (prevMaxB + 1 == valA && cache.Any())
                    {
                        prevTotB = prevTotB.Add(cache.Dequeue());
                    }
                    else
                    {
                        prevTotB = prevTotB.Add(Ari.ChooseWithConstraints(valB - b, t, 2 * k));
                    }
                    prevMaxB = valB;
                }
                if (prevTotB != 0)
                {
                    var nbWay = Ari.ChooseWithConstraints(valA - a, t, 2 * k);
                    cache.Enqueue(nbWay);
                    result = result.Add(prevTotB.Times(nbWay));
                }
            }
            Console.WriteLine(result);
        }
    }

    public static class Ari
    {
        private static Int64 mod = 1000000007;

        public static Int64[] Facts;
        public static Int64[] InvFacts;

        public static void Precompute(long size)
        {
            Facts = new long[size];
            InvFacts = new long[size];
            Facts[0] = 1;
            InvFacts[0] = 1;
            for (long i = 1; i < size; ++i)
            {
                Facts[i] = i.Times(Facts[i - 1]);
                InvFacts[i] = GetInv(Facts[i], mod);
            }
        }

        public static long ChooseWithConstraints(long k, long n, long p)
        {
            long result = 0;
            for (long i = 0; i <= n; ++i)
            {
                if (k < i * (p + 1))
                {
                    continue;
                }
                long coef = i % 2 == 0 ? 1 : -1;
                result = result.Add(coef * (n.Choose(i)).Times((n + k - i * (p + 1) - 1).Choose(n - 1)));
            }
            return result;
        }

        public static long Choose(this long n, long k)
        {
            if (n == k || k == 0)
            {
                return 1;
            }
            if (k < 0)
            {
                return 0;
            }
            return Facts[n].Times(InvFacts[k]).Times(InvFacts[n - k]);
        }

        public static long Add(this long a, long b)
        {
            var result = (a + b) % mod;
            return result < 0 ? result + mod : result;
        }

        public static long Times(this long a, long b)
        {
            var result = (a*b) % mod;
            return result < 0 ? result + mod : result;
        }

        public static Int64 GetInv(Int64 a, Int64 mod)
        {
            var res = GetExtendedGcd(a, mod);
            var result = res.S%mod;
            return result < 0 ? result + mod : result;
        }

        public static SeqResult GetExtendedGcd(Int64 a, Int64 b)
        {
            var old = new SeqResult(a, 1, 0);
            var current = new SeqResult(b, 0, 1);
            Func<Int64, Int64, Int64, Int64> next = (q, prev, curr) => prev - q * curr;

            while (current.R != 0)
            {
                Int64 q = old.R / current.R;

                Int64 temp = current.R;
                current.R = next(q, old.R, current.R);
                old.R = temp;

                temp = current.S;
                current.S = next(q, old.S, current.S);
                old.S = temp;

                temp = current.T;
                current.T = next(q, old.T, current.T);
                old.T = temp;
            }
            return old;
        }

        public class SeqResult
        {
            public SeqResult(Int64 r, Int64 s, Int64 t)
            {
                R = r;
                S = s;
                T = t;
            }
            public Int64 R { get; set; }
            public Int64 S { get; set; }
            public Int64 T { get; set; }
        }
    }

}


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

namespace AlgoTraining.Codeforces.D_s
{
    public class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public string NextToken()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return _line[_iterator++];
        }
        public int NextInt()
        {
            return Convert.ToInt32(NextToken());
        }
        public long NextLong()
        {
            return Convert.ToInt64(NextToken());
        }
        public float NextFloat()
        {
            return float.Parse(NextToken());
        }
        public double NextDouble()
        {
            return Convert.ToDouble(NextToken());
        }
    }
    class MemoryAndScores370
    {
        private static int a, b, k, t;
        private static long[] comb, combSum;
        private static long mod;
        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                a = fs.NextInt();
                b = fs.NextInt();
                k = fs.NextInt();
                t = fs.NextInt();
                comb = new long[2 * k * t + 1];
                combSum = new long[2 * k * t + 1];
                mod = (int)1e9 + 7;
                for (int i = 0; i <= 2 * k; i++)
                {
                    comb[i] = 1;
                }
                for (int i = 1; i < t; i++)
                {
                    long sum = 0;
                    long[] tcomb = new long[2 * k * t + 1];
                    for (int j = 0; j < comb.Length; j++)
                    {
                        sum = (sum + comb[j]) % mod;
                        if (j > 2 * k) sum = (sum - comb[j - 2 * k - 1]) % mod;
                        tcomb[j] = sum;
                    }
                    comb = tcomb;
                }
                combSum[0] = comb[0];
                for (int i = 1; i < comb.Length; i++)
                {
                    combSum[i] = (comb[i] + combSum[i - 1]) % mod;
                }

                long ans = 0;
                for (int i = 0; i < comb.Length; i++)
                {
                    int index = Math.Min(i + a - b - 1, combSum.Length - 1);
                    if (index >= 0) ans = (ans + (comb[i] * combSum[index]) % mod) % mod;
                }
                writer.WriteLine(ans);
            }
        }
    }
}


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

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

    public void Do()
    {
        var a = reader.ReadInt();
        var b = reader.ReadInt();
        var k = reader.ReadInt();
        var t = reader.ReadInt();

        const int MOD = (int)(1e9 + 7);
        var dim = new int[2][];
        var MED =  2 * k * t;
        dim[0] = new int[MED * 2 + 1];
        dim[1] = new int[MED * 2 + 1];
        var tmp = new int[MED * 2 + 1];
        int h = 0;
        dim[h][MED] = 1;
        for (int i = 1; i <= t; ++i)
        {
            tmp[0] = dim[h][0];
            for (int j = 1; j < tmp.Length; ++j)
                tmp[j] = (dim[h][j] + tmp[j - 1]) % MOD;
            h ^= 1;
            Array.Clear(dim[h], 0, dim[h].Length);
            for (int j = 0; j < dim[h].Length; ++j)
            {
                var acc = 0L;
                if (j > 0)
                    acc += dim[h][j - 1];
                acc += tmp[Math.Min(j + 2 * k, tmp.Length - 1)] - 2 * tmp[Math.Max(j - 1, 0)] + tmp[Math.Max(j - 2 - 2 * k, 0)];
                dim[h][j] = (int)(acc % MOD);
            }
        }
        int res = 0;
        int st = b - a + 1 + MED;
        st = Math.Max(st, 0);
        for (int i = st; i < dim[h].Length; ++i)
            res = (res + dim[h][i]) % MOD;
        writer.WriteLine(res);
    }
}

#region launch
class Program
{
    static void Main(string[] args)
    {
        using (var writer = new FormattedStreamWriter(
#if SOLVER_RUN_LOCAL
"output.txt"
#else
         Console.OpenStandardOutput()
#endif
))
        {
            using (var reader = new StreamReader(
#if SOLVER_RUN_LOCAL
"input.txt"
#else
         Console.OpenStandardInput()
#endif
))
            {
#if SOLVER_RUN_LOCAL
                var stopw = new Stopwatch();
                stopw.Start();
#endif
                new Solver(reader, writer).Do();
#if SOLVER_RUN_LOCAL
                stopw.Stop();
                writer.WriteLine("> {0}ms", stopw.ElapsedMilliseconds);
#endif
            }
        }
    }
}
#endregion

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

        static Queue<string> buffer = new Queue<string>(100);
        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
}


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

class Program
{

    private static long SolveBf(int a, int b, int k, int t)
    {
        long[] prev = new long[222222];
        long[] dp = new long[222222];
        int shift = 110001;

        prev[shift] = 1;

        for (int i = 0; i < t; i++)
        {
            int min = -i * k;
            int max = i * k;
            for (int j = min; j <= max; j++)
            {
                for (int offset = -k; offset <= k; offset++)
                {
                    dp[j + shift] += prev[j + offset + shift];
                    dp[j + shift] %= Mod;
                }
            }
            prev = dp;
            dp = new long[222222];
        }

        int delta = a - b;

        long[] sum = new long[222222];
        for (int i = prev.Length - 2; i >= 0; i--)
            sum[i] = (sum[i + 1] + prev[i]) % Mod;

        long answer = 0;
        for (int i = 1000; i < 220000; i++)
            answer = (answer + prev[i] * sum[i - delta + 1]) % Mod;

        Console.WriteLine("Bf = " + answer);
        return answer;
    }

    private static long SolveAc(int a, int b, int k, int t)
    {
        int mid = (k + 4) * t + 1;

        long[] prev = new long[222222];
        long[] dp = new long[222222];

        prev[mid] = 1;

        long[] sum = new long[222222];
        for (int i = 0; i < t; i++)
        {
            Array.Clear(sum, 0, sum.Length);
            for (int j = 1; j < sum.Length; j++)
                sum[j] = (sum[j - 1] + prev[j]) % Mod;

            int min = -(i+1) * k;
            int max = (i + 1) * k;
            for (int j = min; j <= max; j++)
            {
                dp[j + mid] += sum[j + mid + k] - sum[j + mid - k-1];
                dp[j + mid] = (dp[j + mid] + Mod) % Mod;
                //Console.Write(dp[j + mid] + " ");
            }
            //Console.WriteLine();

            //var tmp = prev;
            prev = dp;
            //dp = tmp;
            dp = new long[222222];
            //Array.Clear(dp, 0, dp.Length);
        }

        int delta = a - b;

        Array.Clear(sum, 0, sum.Length);
        for (int i = prev.Length - 2; i >= 0; i--)
            sum[i] = (sum[i + 1] + prev[i]) % Mod;

        long answer = 0;

        int st = Math.Max(delta - 1, 0);
        for (int i = st; i < 220000; i++)
                answer = (answer + prev[i] * sum[i - delta + 1]) % Mod;

        Console.WriteLine(answer);
        return answer;
    }

    static void Main(string[] args)
    {
        //PushTestData(@"13 100 1000 13 ");
        //PushTestData(@" 1 2 2 1 ");
        int a = RI();
        int b = RI();
        int k = RI();
        int t = RI();

        var a1 = SolveAc(a, b, k, t);
        //SolveBf(a, b, k, t);

    }

    private const int Mod = 1000000000 + 7;

    #region Data Read
    private static char ReadSign()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans == '+' || ans == '-')
                return (char)ans;
        }
    }

    private static long GCD(long a, long b)
    {
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < n; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = RI() - 1;
            int b = RI() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = RI();
            int b = RI();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int RI()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong RUL()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long RL()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] RIA(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = RI();
        return ans;
    }

    private static long[] RLA(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = RL();
        return ans;
    }

    private static char[] ReadString()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char[] ReadStringLine()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans == 10 || ans == 13);

        List<char> s = new List<char>();

        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans != 10 && ans != 13);

        return s.ToArray();
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(string data)
    {
#if TOLYAN_TEST
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
    #endregion
}


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

namespace Task
{
    class Program
    {
        public class PossibleDigit
        {
            public int digit;
            public int possibleLength;

            public PossibleDigit(int p)
            {
                possibleLength = p;
            }
        }
        static void Main(string[] args)
        {
            /*string[] input = Console.ReadLine().Split(' ');

            int n = Convert.ToInt32(input[0]),
                m = Convert.ToInt32(input[1]),
                x = Convert.ToInt32(input[3]),
                y = Convert.ToInt32(input[4]);
            long k = Convert.ToInt64(input[2]);

            long max, min, serg;

            if (n == 1)
            {
                if (k % m == 0)
                {
                    serg = min = max = k / m;
                }
                else
                {
                    min = k / m;
                    max = min + 1;
                    serg = k % m < y ? min : max;
                }
            }
            else if (n == 2)
            {
                min = k / (n * m);
                max = (k % (n * m) == 0 || (k - n * m) % ((n - 1) * m) == 0) ? min : min + 1;
            }
            else
            {
                int[] count = new int[3];

                if (k < 100000)
                {
                    for (int i = 0; i < k; ++i)
                    {
                        if ((i / m) == 1 || )
                    }
                }
            }

            Console.WriteLine($"{max} {min} {serg}");*/

            int n = Convert.ToInt32(Console.ReadLine());
            string num = Console.ReadLine();

            long answer = 0;
            int cur = n.ToString().Length;
            List<PossibleDigit> nums = new List<PossibleDigit>() {new PossibleDigit(cur)};

            for (int i = num.Length; i >= 0;)
            {
                /*Console.WriteLine("Список");

                Console.WriteLine();
                Console.WriteLine(i);*/
                if (i - nums[nums.Count - 1].possibleLength >= 0)
                {
                    i -= nums[nums.Count - 1].possibleLength;
                    //Console.WriteLine(i + " " + nums[nums.Count - 1].possibleLength);
                }
                else
                {
                    nums[nums.Count - 1].possibleLength = i;
                    i = 0;
                }
                if (num.Length < cur)
                {
                    nums[nums.Count - 1].digit = Convert.ToInt32(num);
                    nums.Add(new PossibleDigit(cur));
                    break;
                }
                if (nums[nums.Count - 1].possibleLength == 0) break;
                //Console.WriteLine($"Convert.ToInt32(num.Substring({i}, {nums[nums.Count - 1].possibleLength})) {Convert.ToInt32(num.Substring(i, nums[nums.Count - 1].possibleLength))}");
                int temp = Convert.ToInt32(num.Substring(i, nums[nums.Count - 1].possibleLength));
                if (num.Substring(i, nums[nums.Count - 1].possibleLength)[0] == '0' && nums[nums.Count - 1].possibleLength != 1)
                    temp = int.MaxValue;
                //Console.WriteLine($"Ето темп{temp}");

                if (temp < n)
                {
                    nums[nums.Count - 1].digit = temp;
                    nums.Add(new PossibleDigit(cur));
                }
                else
                {
                    //Console.WriteLine(-1);
                    i += nums[nums.Count - 1].possibleLength--;
                    if (nums[nums.Count - 1].possibleLength == 0)
                        --nums[nums.Count - 2].possibleLength;
                }
            }

            /*foreach (var t in nums) Console.Write(t.digit + " ");
            Console.WriteLine();*/
            for(int i = 0; i < nums.Count; ++i)
            {
                answer += (long)Math.Pow(n, i) * nums[i].digit;
            }

            Console.Write(answer);
        }
    }
}


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

public class Test
{

    public static int[] ReadArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m));
    }

    public static int ReadInt()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

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

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

    public static long[] ReadLongArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m));

    }

    public static void Main()
    {

        var S = Console.ReadLine();
        long num = 0;

        for(int i = 0; i < S.Length; i++)
        {
            num = num * 10 + 9;
        }

        long N = Convert.ToInt64(S);
        if (num == Convert.ToInt64(N))
        {
            Console.WriteLine(Cal(N));
        }
        else
        {
            num = num / 10;
            long result = 0;
            for(long i = num; i <= N; i++)
            {
                result = Math.Max(result, Cal(i));
            }

            Console.WriteLine(result);
        }

    }

    public static long Cal(long n)
    {
        long result = 1;

        while( n > 0)
        {
            result = result * (n % 10);
            n = n / 10;

        }

        return result;
    }

}


using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
class Problem
{
    static void Main()
    {
        //--------------------------------input--------------------------------//

        int n = Convert.ToInt32( Console.ReadLine() );

        //--------------------------------solve--------------------------------//

        if(n >= Math.Pow( 10, 9 ) - 1)
            Console.Write( Math.Pow( 9, 9 ) );
        else
        {
            int kq = 0;
            for(int i = n - (int)Math.Pow( 10, Math.Log10( n ) - 1 ) ; i <= n ; i++)
            {
                List<int> pTu = new List<int>();
                int temp = i;
                while(temp > 0)
                {
                    pTu.Add( temp % 10 );
                    temp /= 10;
                }
                int now=1;
                foreach(int j in pTu)
                    now *= j;
                kq = Math.Max( kq, now );
            }
            Console.Write( kq );
        }

    }
}


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{D76EAD0F-3DCA-4720-981A-A1CC8B957629}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>Algoritms</RootNamespace>
    <AssemblyName>Algoritms</AssemblyName>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>


using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            string gen = "ACTG";
            int n = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            int rez = 26*4;
            for (int i = 0; i < n-3; i++)
            {
                int r = 0;
                for (int k = 0; k < 4; k++)
                {
                    r  += Math.Min(Math.Abs(str[i + k] - gen[k]),Math.Abs(gen[k]-'A'+1+('Z'-str[i+k])));
                }
                rez = Math.Min(rez, r);
            }
            Console.WriteLine(rez);
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Diagnostics;
namespace contest1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_553A();
        }

        public static void solve_553A()
        {
            int n = Convert.ToInt32(Console.ReadLine());

            //int actg = 65 + 67 + 84 + 71;
            string str = Console.ReadLine();

            int min = int.MaxValue;
            for (int i = 0; i < n - 3; i++)
            {
                int first = (int)str[i];
                int c1 = first == 90 ? 1 : Math.Abs(first - 65);
                int c2 = Math.Abs((int)str[i + 1] - 67);
                int c3 = Math.Abs((int)str[i + 2] - 84);
                int c4 = Math.Abs((int)str[i + 3] - 71);

                min = Math.Min(min, c1 + c2 + c3 + c4);

            }
            Console.WriteLine(min);
        }
    }
}


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

namespace Problem
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var minimum = int.MaxValue;
            for (var i = 0; i + 4 <= s.Length; i++)
            {
                var currentGenom = GetGenom(s.Substring(i, 4));
                if (currentGenom < minimum)
                {
                    minimum = currentGenom;
                }
            }

            Console.WriteLine(minimum);
        }

        static int GetGenom(string s)
        {
            const string genom = "ACTG";
            var opCount = 0;
            for (var i = 0; i < genom.Length; i++)
            {
                var min = Math.Min(Math.Abs(genom[i] - s[i]), Math.Abs(26 - Math.Max(genom[i], s[i]) + Math.Min(genom[i], s[i])));
                opCount += min;
            }

            return opCount;
        }
    }
}


/*
csc -debug A.cs && mono --debug A.exe <<< "4
ZCTH"
*/

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

public class HelloWorld {
    public static void SolveCodeForces() {
        Console.ReadLine();
        var S = Console.ReadLine();
        var ops = new int[S.Length];

        var ans = int.MaxValue;
        for (var i = 0; i < S.Length - 3; i++) {
            var roll = 0;
            for (var j = 0; j < 4; j++) {
                var c = S[i + j];
                var d = "ACTG"[j];
                roll += Math.Min( Math.Abs(d - c), Math.Abs(d + 26 - c) );
            }
    // System.Console.WriteLine(new {i, roll, ans});
            ans = Math.Min(roll, ans);
        }
        System.Console.WriteLine(ans);
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // System.Console.Write(cout.ToString());
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


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

namespace ConsoleApp24
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            str.ToCharArray();
            int sum = 0;
            int min = 0;
            for (int i = 0; i < N - 3; i++)
            {

                sum = sumer(str[i], 'A') + sumer(str[i + 1], 'C') + sumer(str[i + 2], 'T') + sumer(str[i+3],'G');

                if (i == 0)
                    min = sum;
                else if (sum < min)
                    min = sum;

            }
            Console.WriteLine(min);
        }

        private static int sumer(char v1, char v2)
        {
            int sum = 0;
            if (v1 - v2 > 0 && v1 - v2 < 14)
            {
                sum += v1 - v2;
            }
            else if (v1 - v2 > 0 && v1 - v2 > 14) {
                sum += 26 - v1 + v2;
            }
            else if (v1 - v2 < 0 && v1 - v2 >-14)
            {
                sum +=v2-v1;
            }
            else if (v1 - v2 < 0 && v1 - v2 < -14)
            {
                sum +=26- v2 + v1;
            }
            return sum;
        }
    }
}


using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Problem
{
    static void Main()
    {
        //--------------------------------input--------------------------------//

        int n = Convert.ToInt32( Console.ReadLine() );
        string s = Console.ReadLine();

        //--------------------------------solve--------------------------------/

        int min = 100000;
        for(int i = 0 ; i <= s.Length - 4 ; i++)
        {
            string subs = s.Substring( i, 4 );
            int now = Math.Min( Math.Abs( subs[0] - 'A' ), Math.Abs( subs[0] - 'A' -26) );
            now += Math.Min( Math.Abs( subs[1] - 'C' ), Math.Abs( subs[1] - 'C' -26) );
            now += Math.Min( Math.Abs( subs[2] - 'T' ), Math.Abs( subs[2] - 'T' -26) );
            now += Math.Min( Math.Abs( subs[3] - 'G' ), Math.Abs( subs[3] - 'G' -26) );
            min = Math.Min( min, now );
        }
        Console.WriteLine( min );
    }
}


using System;
namespace ConsoleApplication1{
 class Program {
static void Main (string[] args)
{
A();
}
static void B(){
string x= Console.ReadLine();
 y = Console. ReadLine();
for (int i= 0;i< x. Length; i++)
if (y[i]> x[i]) Console.WriteLine(-1); Console.WriteLine(y);
 static void A(){ var line= Console.ReadLine().ToCharArray();
 int count= GetCount(line);
for (int i =0; i< line.Length; i++)
 {line[i]=(char)( 'V'+'K'- line[i]);
 count = Math.Max(count, GetCount(line));
line[i]=(char)( 'V'+'K'- line[i]);
}
Console.WriteLine(count);
}
static int GetCount(char[] s)
{ int count=0;
 for (int i =1; i < s.Length; i++)
 if (s[i] =='K' && s[i-1]== 'V') count++ ;
return count;
}}}


using System;
using System.Collections.Generic;
namespace ConsoleApp16
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] s = Console.ReadLine().ToCharArray();
            int x = 0;
            int y = 0;
            if (s.Length == 1)
            {
                Console.WriteLine(0);
            }
            else if (s.Length == 2)
            {
                if (s[0] == 'V')
                {
                    Console.WriteLine(1);
                }
                else
                {
                    Console.WriteLine(0);
                }
            }
            else
            {

                for (int i = 0; i < s.Length - 1; i++)
                {
                    if (s[i] == 'V' && s[i + 1] == 'K')
                    {
                        x++;
                        i++;
                        continue;
                    }
                    else if (s[i] == 'K' && s[i + 1] == 'V')
                    {

                        continue;
                    }

                    else if (i < s.Length - 2 && (s[i + 1] != 'V') || s[i + 2] != 'K')
                    {
                        y++;
                    }

                }

                if (y > 0)
                {
                    Console.WriteLine(x + 1);
                }
                else
                {
                    Console.WriteLine(x);
                }
            }
        }
    }
}


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

namespace C.Table_Tennis_Game_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            while (t-- > 0)
            {
                int[] kab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                int k = kab[0];
                int a = kab[1];
                int b = kab[2];
                int wa = a / k;
                int wb = b / k;
                if (a >= k && b >= k)
                {
                    Console.WriteLine(wa + wb);
                }
                else if (a % k == 0 && b <=(a/k)*(k-1))
                {
                    Console.WriteLine(wa);
                }
                else if (b % k == 0 && a <= (b/k)*(k-1))
                {
                    Console.WriteLine(wb);
                }
                else
                {
                    Console.WriteLine(-1);
                }
            }
        }
    }
}


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

namespace test
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                bool flag1 = false, flag2 = false, flag3 = false;//1 - Большая буква, 2 - Маленькая буква, 3 - Цифра.
                Console.Write("Enter password: ");
                string pass = Console.ReadLine();
                for (int i = 0; i < pass.Length; i++)
                {
                    if (pass[i] >= 65 && pass[i] <= 90 && !flag1)
                        flag1 = true;
                    if (pass[i] >= 97 && pass[i] <= 122 && !flag2)
                        flag2 = true;
                    if (Char.IsDigit(pass[i]) && !flag3)
                        flag3 = true;
                }
                if (flag1 && flag2 && flag3 && pass.Length >= 5)
                    Console.WriteLine("Correct");
                else
                    Console.WriteLine("Too Weak");
            }
        }
    }
}


using System;

namespace code
{
    class Program
    {
        static void Main(string[] args)
        {
            string b = Console.ReadLine();
            int sum=0;
            int k=0;
            int j=0;
            if (b.Length < 5)
                Console.WriteLine("Too weak");
            else
            {
                char[] a = b.ToCharArray();
                for(int i=0; i<a.Length+1; i++)
                {
                    if(a[i]>'a' && a[i]<'z')
                    {
                        sum++;
                    }
                    if(a[i]>'A' && a[i]<'B')
                    {
                        k++;
                    }
                    if(Char.IsDigit(a[i]))
                    {
                        j++;
                    }
                }
                if (sum > 0 && k > 0 && j > 0)
                {
                    Console.WriteLine("Correct");
                }
                else Console.WriteLine("Too weak");
            }
            }
                }
            }


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

namespace Task1
{
    class Program
    {
        static void Main(string[] args)
        {
            bool flag = false;
            int[] a = new int[6];
            for (int i=0; i<6; ++i)
            {
                a[i] = int.Parse(Console.ReadLine());
            };
            int sum = a.Sum();
            if (sum % 2 != 1)
            {
                sum /= 2;
                sum = sum - a[0];
                for (int i=1; i<5; ++i)
                {
                    for (int j=i+1; j<6; ++j)
                    {
                        if (a[i] + a[j] == sum)
                        {
                            flag = true;
                        }
                    };
                };
            };
            if (flag)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            };
        }
    }
}


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

namespace TehnoCub1
{
    class Program
    {
        public static double[] Read(string str)
        {
            List<double> doubles = new List<double>();
            double now = 0;
            foreach (var ch in str)
            {
                if (ch == ' ')
                {
                    doubles.Add(now);
                    now = 0;
                }
                else if (Char.IsDigit(ch))
                {
                    now = now * 10 + int.Parse(ch.ToString());
                }
                else
                {
                    break;
                }
            }
            doubles.Add(now);
            return doubles.ToArray();
        }
        static void Main(string[] args)
        {
            double[] input = Read(File.ReadAllText("input.txt"));
            bool was = false;
            for (int i = 0;i < 64; i++)
            {
                int count = 0;
                double sum = 0;
                for (int k = 1; k <= 6; k++)
                {
                    if (i % Math.Pow(2,k) >= Math.Pow(2, k - 1))
                    {
                        sum += input[k - 1];
                        count++;
                    }
                    else
                    {
                        sum -= input[k - 1];
                        count--;
                    }
                }
                if (sum == 0 && count == 0)
                {
                    File.WriteAllText("output.txt","YES");
                    was = true;
                    break;
                }
            }
            if (!was)
            {
                File.WriteAllText("output.txt", "NO");
            }
        }
    }
}


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

namespace Codeforces_Type_A
{
    class Program
    {
        static void Main(string[] args)
        {
			 int[] a;
            a = getLineInt(Console.ReadLine());
            int sum = a.Sum();
            bool yep = false;
            for (int i = 0; i < a.Length && !yep; i++)
            {
                for (int z = i; z < a.Length && !yep; z++)
                {
                    for (int j = z; j < a.Length && !yep; j++)
                    {
                        int temp = a[i]+a[z]+a[j];
                        if (sum - temp == temp)
                        {
                            yep = true;
                        }
                    }
                }
            }
            Console.WriteLine((yep == true) ? "yes" : "no");
        }
    }
}


long X = Convert.ToInt64(Console.ReadLine());
Console.WriteLine(X / 5 + (X % 5 != 0 ? 1 : 0));