       real*8 meanr, meang, meanb, mean
       real*8 sdr, sdg, sdb, xyr, xyg, xyb
       real*8 xr, xg, xb, yr, yg, yb
       real*8 xxr, xxg, xxb, betar, betag
       real*8 betab, bb, ab, ag, bg, rmsr
       real*8 rmsg, rmsb, rsdr, gsdg, bsdb
       dimension a(1)
       dimension b(1000000)
       dimension c(1000000)
       dimension d(1000000)
       dimension e(1000000)
       dimension f(1000000)
       integer x, y, z, w, q
       open (1,file='no')
       read (1,*) (a(x), x=1, 1)

       n = a(1)

       open (2,file='rflux')
       read (2,*) (b(y), y=1, n)

       open (3,file='gflux')
       read (3,*) (c(z), z=1, n)

       open (4,file='bflux')
       read (4,*) (d(w), w=1, n)
 
       open (5,file='time')
       read (5,*) (e(q), q=1, n)

       meanr = 0.0
       do i=1, n
       meanr = meanr + b(i)
       end do
       meanr = meanr/n
  
       rmsr = 0.0
       do i=1, 20
       rmsr = rmsr + b(i)
       end do
       rmsr = rmsr/20.0
 
      
       sdr = 0.0
       do i=1, n
       sdr = sdr+(b(i)-meanr)**2
       end do
       sdr = sqrt(sdr/n)

       rsdr = 0.0
       do i=1, 20
       rsdr = rsdr+(b(i)-rmsr)**2
       end do
       rsdr = sqrt(rsdr/20.0)

       xyr = 0.0
       do i=1, n
       xyr = xyr + b(i)*e(i)
       end do
   
       xr = 0.0
       do i=1, n
       xr = xr + e(i)
       end do

       yr = 0.0
       do i=1, n
       yr = yr + b(i)
       end do
  
       xxr = 0.0
       do i=1, n
       xxr = xxr + e(i)**2
       end do

       betar = (n*xyr-xr*yr)/(n*xxr-xr**2)
  
       meang = 0.0
       do i=1, n
       meang = meang + c(i)
       end do
       meang = meang/n

       rmsg = 0.0
       do i=1, 20
       rmsg = rmsg + c(i)
       end do
       rmsg = rmsg/20.0


       sdg = 0.0
       do i=1, n
       sdg = sdg+(c(i)-meang)**2
       end do
       sdg = sqrt(sdg/n)

       gsdg = 0.0
       do i=1, 20
       gsdg = gsdg+(c(i)-rmsg)**2
       end do
       gsdg = sqrt(gsdg/20.0)


       xyg = 0.0
       do i=1, n
       xyg = xyg + c(i)*e(i)
       end do
   
       xg = 0.0
       do i=1, n
       xg = xg + e(i)
       end do

       yg = 0.0
       do i=1, n
       yg = yg + c(i)
       end do
  
       xxg = 0.0
       do i=1, n
       xxg = xxg + e(i)**2
       end do

       betag = (n*xyg-xr*yg)/(n*xxg-xg**2)
       ag = (yg*xxg-xgxyg)/(n*xxg-xg**2)



       meanb = 0.0
       do i=1, n
       meanb = meanb + d(i)
       end do
       meanb = meanb/n

       rmsb = 0.0
       do i=1, 20
       rmsb = rmsb + d(i)
       end do
       rmsb = rmsb/20.0



       sdb = 0.0
       do i=1, n
       sdb = sdb+(d(i)-meanb)**2
       end do
       sdb = sqrt(sdb/n)

       bsdb = 0.0
       do i=1, 20
       bsdb = bsdb+(d(i)-rmsb)**2
       end do
       bsdb = sqrt(bsdb/20.0)



       xyb = 0.0
       do i=1, n
       xyb = xyb + d(i)*e(i)
       end do
   
       xb = 0.0
       do i=1, n
       xb = xb + e(i)
       end do

       yb = 0.0
       do i=1, n
       yb = yb + d(i)
       end do
  
       xxb = 0.0
       do i=1, n
       xxb = xxb + e(i)**2
       end do

       betar = sdr/rsdr
       betag = sdg/gsdg
       betab = sdb/bsdb
       write (*,*) betar, betag, betab
c       betab = (n*xyb-xr*yb)/(n*xxb-xb**2)
c       ab = (yb*xxb-xbxyb)/(n*xxb-xb**2)
c       br = betar
c       bg = betag
c       bb = betab

c       betar = abs(betar)
c       betag = abs(betag)
c       betab = abs(betab)

       flagma = 0
       flagmi = 0
       if (betar.gt.betag) then
       flagma = 1
       else 
       flagma = 2
       endif
 
       if (flagma.eq.1) then
       if (betar.gt.betab) then
       flagma = 1
       else
       flagma = 3
       endif
       else
       endif

       if ((flagma.ne.1).and.(betag.gt.betab)) then
       flagma = 2
       else
       endif

       if ((flagma.ne.1).and.(betab.gt.betag)) then
       flagma = 3
       else
       endif


       if (betar.gt.betag) then
       flagmi = 2
       else 
       flagmi = 1
       endif

       if (flagmi.eq.2) then
       if (betag.gt.betab) then
       flagmi = 3
       else 
       flagmi = 2
       endif
       else
       endif

       if ((flagmi.ne.2).and.(betar.gt.betab)) then
       flagmi = 3
       else
       endif

       if ((flagmi.ne.2).and.(betab.gt.betar)) then
       flagmi = 1
       else
       endif





       if ((flagma.eq.1).and.(flagmi.eq.2)) then
       do i=1, n
       mean = (b(i)+c(i))/2.0
       write (7,*) mean
       write (8,*) c(i)
       write (9,*) d(i)
       end do 
       else
       endif

       if ((flagma.eq.1).and.(flagmi.eq.3)) then
       do i=1, n
       mean = (b(i)+d(i))/2.0
       write (7,*) mean
       write (8,*) c(i)
       write (9,*) d(i)
       end do 
       else
       endif



       if ((flagma.eq.2).and.(flagmi.eq.1)) then
       do i=1, n
       mean = (b(i)+c(i))/2.0
       write (7,*) b(i)
       write (8,*) mean
       write (9,*) d(i)
       end do 
       else
       endif


       if ((flagma.eq.2).and.(flagmi.eq.3)) then
       do i=1, n
       mean = (d(i)+c(i))/2.0
       write (7,*) b(i)
       write (8,*) mean
       write (9,*) d(i)
       end do 
       else
       endif



       if ((flagma.eq.3).and.(flagmi.eq.1)) then
       do i=1, n
       mean = (b(i)+d(i))/2.0
       write (7,*) b(i)
       write (8,*) c(i)
       write (9,*) mean
       end do 
       else
       endif

       if ((flagma.eq.3).and.(flagmi.eq.2)) then
       do i=1, n
       mean = (c(i)+d(i))/2.0
       write (7,*) b(i)
       write (8,*) c(i)
       write (9,*) mean
       end do 
       else
       endif


       end 
