PROGRAM MinMax(Input, Output);

    { Program 6.1 - Find the largest and smallest number in a given list. }

    CONST
        MaxSize = 6;
    TYPE
        ListSize = 1..MaxSize;
    VAR
        Item: ListSize;
        Min, Max, First, Second: Integer;
        A: Array[ListSize] OF Integer;

BEGIN
    FOR Item := 1 TO MaxSize DO BEGIN
        Read(Input, A[Item]);
        Write(Output, A[Item]:4)
    END;
    WriteLn(Output);

    Min  := A[1];
    Max  := Min;
    Item := 2;

    WHILE Item < MaxSize DO BEGIN
        First := A[Item];
        Second := A[Item+1];

        IF First > Second THEN BEGIN
            IF First > Max THEN
                Max := First;
            IF Second < Min THEN
                Min := Second
        END ELSE BEGIN
            IF Second > Max THEN
                Max := Second;
            IF First < Min THEN
                Min := First
        END;

        Item := Item + 2;
    END;

    IF Item = MaxSize THEN
        IF A[MaxSize] > Max THEN
            Max := A[MaxSize]
        ELSE IF A[MaxSize] < Min THEN
            Min := A[MaxSize];

    WriteLn(Output, Max:4, Min:4)
END.
