using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;//for StringBuilder
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
        a.Add(0);
        var list = new List<int>();
        list.Add(0);
        bool judge = false;
        for (int i = 0; i < n; i++)
        {
            if (a[i] < a[i + 1]) judge = true;
            if (a[i] > a[i + 1] && judge) { list.Add(i); judge = false; }
        }
        long money = 1000;
        foreach (var x in list) Console.WriteLine(x);
        while (list.Count() >= 2)
        {
            int min = a.Where((f, g) => g >= list[0] && g <= list[1]).Min();
            int max = a.Where((f, g) => g >= list[0] && g <= list[1]).Max();
            long kabu = money / min;
            money = money - kabu * min + kabu * max;
            Console.WriteLine("{0},{1},{2},{3}", min, max, kabu, money);
            list.RemoveAt(0);
        }
        Console.WriteLine(money);
    }
}