IDENTIFICATION DIVISION.
PROGRAM-ID. 098C.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 S          PIC X(300000).
*>
WORKING-STORAGE SECTION.
01 N          PIC 9(6) COMP.
01 I          PIC 9(6) COMP.
01 W-CNT      PIC 9(6) COMP.
01 E-CNT      PIC 9(6) COMP.
01 WW         PIC 9(6) COMP.
01 EW         PIC 9(6) COMP.
01 M          PIC 9(6) COMP.
01 MIN        PIC 9(6) COMP.  
01 OUT        PIC Z(5)9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  OPEN INPUT STDIO.
  READ STDIO.         
  CLOSE STDIO.
*>
  MOVE 0 TO W-CNT E-CNT.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    IF (S(I:1) = 'W')
      ADD 1 TO W-CNT
    ELSE
      ADD 1 TO E-CNT
    END-IF
  END-PERFORM.
*>
  MOVE N TO MIN.
  MOVE 0 TO WW EW.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    IF (S(I:1) = 'E')
      ADD 1 TO EW
    END-IF
*>
    COMPUTE M = WW + (E-CNT - EW)
    IF (MIN > M)
      MOVE M TO MIN
    END-IF   
*>
    IF (S(I:1) = 'W')
      ADD 1 TO WW
    END-IF
  END-PERFORM.
*>
  MOVE MIN TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
