program Connect4; uses crt; type boardtype = array[1..6,1..7] of char; var infile,outfile:text; x,y,z:integer; s: string; winner: boolean; chipsdropped: integer; column:integer; board: boardtype; empty:integer; winnername:string; function determinewinner(c:char):boolean; var row,col:integer; winner:boolean; begin winner:=false; for row := 1 to 6 do for col := 1 to 4 do if (board[row,col]=c) and (board[row,col+1]=c) and (board[row,col+2]=c) and (board[row,col+3]=c) then winner := true; for col := 1 to 7 do for row := 1 to 3 do if (board[row,col]=c) and (board[row+1,col]=c) and (board[row+2,col]=c) and (board[row+3,col]=c) then winner := true; for row := 1 to 3 do for col := 1 to 4 do if (board[row,col]=c) and (board[row+1,col+1]=c) and (board[row+2,col+2]=c) and (board[row+3,col+3]=c) then winner := true; for row := 4 to 6 do for col := 1 to 4 do if (board[row,col]=c) and (board[row-1,col+1]=c) and (board[row-2,col+2]=c) and (board[row-3,col+3]=c) then winner := true; determinewinner := winner; end; begin assign(infile,'DATA41.txt'); reset(infile); assign(outfile,'OUT41.txt'); rewrite(outfile); for x:=1 to 5 do begin readln(infile,s); for y:=1 to 6 do for z:=1 to 7 do board[y,z]:=' '; winner := false; chipsdropped:=0; repeat inc(chipsdropped); val(s[chipsdropped],column); empty:=0; repeat inc(empty); until board[empty,column]=' '; board[empty,column]:='R'; winner := determinewinner('R'); if winner then winnername:='RED' else begin inc(chipsdropped); val(s[chipsdropped],column); empty:=0; repeat inc(empty); until board[empty,column]=' '; board[empty,column]:='B'; winner := determinewinner('B'); if winner then winnername:='BLUE' end; until winner; writeln(outfile,winnername,'-',chipsdropped); end; close(infile); close(outfile); end.