// $Id: lists.ici,v 1.0 2003/01/03 12:20:00 dada Exp $
// http://dada.perl.it/shootout
//
// contributed by Tim Long

NUM = argv[1] ? int(argv[1]) : 1;

static SIZE = 10000;

static
test_lists()
{
    li1 = array();
    for (i := 0; i < SIZE; )
        i = li1[i] = i + 1;
    li2 = copy(li1);
    li3 = array();
    while(nels(li2))
        push(li3, rpop(li2));
    while (nels(li3))
        push(li2, pop(li3));
    n := SIZE / 2;
    for (i := 0; i < n; ++i)
        li1[i] <=> li1[SIZE - i - 1];
    if (li1[0] != SIZE || li1 != li2)
        return 0;
    return nels(li1);
}

for (i = 0; i < NUM; ++i)
    result = test_lists();
printf("%d\n", result);