/*
    基本情報技術者試験          平成13年度・春期・午後 問6
                                BohYoh Shibata PREPARATION
*/

typedef struct {
  unsigned  char  Red ;
  unsigned  char  Green ;
  unsigned  char  Blue ;
} RGB ;

#define   Width   320
#define   Height  240
#define   TRUE    1
#define   FALSE   0

RGB Image[ Height ][ Width ] ;

long int  CountColors( int sx, int sy, int dx, int dy )
{
  int  w, h ;
  int  px, py ;
  long int  Colors ;
  int  Counted[ Height ][ Width ] ;

  for( h = sy ; h <= dy ; h++ )
    for( w = sx ; w <= dx ; w++ )
      Counted[h][w] = FALSE ;

  Colors = 0 ;
  for( py = sy ; py <= dy ; py++ )
    for( px = sx ; px <= dx ; px++ ) {
      if ( Counted[py][px] == FALSE ) {
        Colors++ ;
        Counted[py][px] = TRUE ;

        for( h = py ; h <= dy ; h++ )
          for( w = ( h == py ? px + 1 : sx ) ; w <= dx ; w++ ) {
            if ( Counted[h][w] == FALSE ) {
              if (( Image[py][px].Red == Image[h][w].Red   )
              &&( Image[py][px].Green == Image[h][w].Green )
              &&( Image[py][px].Blue  == Image[h][w].Blue  ))
                 Counted[h][w] = TRUE ;
            }
          }
      }
    }
  return Colors ;
}