IDENTIFICATION DIVISION.
PROGRAM-ID. 103C.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP   PIC X(700000).
*>
WORKING-STORAGE SECTION.
01 N         PIC 9(6) COMP.
01 H         PIC 9(6) COMP.
01 N1        PIC 9(6) COMP VALUE 100000.
01 TBL1.
   03 TBL1-S                OCCURS 100000 DEPENDING ON N1. 
      05 K1  PIC 9(6).
      05 V1  PIC 9(6).
01 TBL2.      
   03 TBL2-S                OCCURS 100000 DEPENDING ON N1. 
      05 K2  PIC 9(6).
      05 V2  PIC 9(6).
01 VW        PIC 9(6) COMP.
01 CNT       PIC 9(6) COMP.
01 OUT       PIC Z(5)9.
01 P1        PIC 9(6) COMP.
01 P2        PIC 9(6) COMP.
01 I         PIC 9(6) COMP.
01 IX        PIC 9(1).
*>
PROCEDURE DIVISION.
  ACCEPT N.
  COMPUTE H = N / 2. 
*>
  OPEN INPUT STDIO.
  READ STDIO.
  CLOSE STDIO.
*>
  MOVE ZERO TO TBL1 TBL2 CNT.
  MOVE 1    TO P1 IX.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
  *>
    MOVE INP(P1:P2 - P1) TO VW
    IF (IX = 1)
      ADD  1  TO K1(VW)
      MOVE VW TO V1(VW)
    ELSE
      ADD  1  TO K2(VW)
      MOVE VW TO V2(VW)
    END-IF  
  *>
    COMPUTE IX = 3 - IX
    COMPUTE P1 = P2 + 1    
  END-PERFORM.
*>
  SORT TBL1-S DESCENDING KEY K1.
  SORT TBL2-S DESCENDING KEY K2.
*>
  EVALUATE TRUE
    WHEN (V1(1) = V2(1))
      IF (K1(1) + K2(2) >= K1(2) + K2(1))
        COMPUTE CNT = N - K1(1) - K2(2)
      ELSE
        COMPUTE CNT = N - K1(2) - K2(1)
      END-IF       
    WHEN OTHER
      COMPUTE CNT = N - K1(1) - K2(1)
  END-EVALUATE.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
