﻿namespace LinkedListTraversal
{
    using System;
    using System.Linq;
    using System.Reflection;

    public class StartUp
    {
        public static void Main(string[] args)
        {
            CustomLinkedList<int> customList = new CustomLinkedList<int>();
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] data = Console.ReadLine().Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);
                string methodName = data[0];
                int value = int.Parse(data[1]);

                MethodInfo method = customList.GetType()
                    .GetMethods(BindingFlags.Instance | BindingFlags.Public)
                    .FirstOrDefault(x => x.Name == methodName);

                method.Invoke(customList, new object[] {value});
            }

            Console.WriteLine(customList.Count);

            foreach (var item in customList)
            {
                Console.Write($"{item} ");
            }

            Console.WriteLine();
        }
    }
}
