/*      TESTING OF THE REDUCTION CLAUSE .
      REDUCTION OPERATION : SUM.PRODUCT,MAX,MIN,AND,OR,MAXLOC,MINLOC AND
      THEIR COMBINATION ARE EXECUTED
      FOR DISTRIBUTED ARRAY A[N][M].
*/
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

#define N 8
#define M 8
#define NL 1000
#define RNL 1000.
#define PNL 1
#define RPNL 1.

static void red2101();
static void red2102();
static void red2103();
static void red2104();
static void red2105();
static void red2106();
static void red2107();
static void red2108();
static void red2109();
static void red2111();
static void red2112();
static void red2113();
static void red2114();

static int sersum2(int AR[N][M], int NN, int NM, int NNL);
static int sersum2m(int AR[N][M], int NN, int NM, int NNL);
static float sers2mr(float RAR[N][M], int NN, int NM, float RNNL);
static long serprod2(int AR[N][M], int NN, int NM, int NNL);
static float serprodr2(float AR[N][M], int NN, int NM, float NNL);
static int serand2(int AR[N][M], int NN, int NM, int NNL);
static int seror2(int AR[N][M], int NN, int NM, int NNL);
static int serxor2(int AR[N][M], int NN, int NM, int NNL);
static void ansyes(const char tname[]);
static void ansno(const char tname[]);

int main(int argc, char *argv[])
{
    printf("===START OF red21m ========================\n");
    red2101();
    red2102();
    red2103();
    red2104();
    red2105();
    red2106();
    red2107();
    red2108();
    red2109();
    red2111();
    red2112();
    red2113();
    red2114();

    printf("=== END OF red21m ========================= \n");
    return 0;
}
/* ---------------------------------------------RED2101  */
void red2101()
{
    int C[N][M];
    char tname[] = "RED2101";
    int i, j, NN, NM, NNL, ISUM1, isum1, isumt1;

    #pragma dvm array distribute[block][block]
    int A[N][M];

    NN = N;
    NM = M;
    NNL = NL;
    isum1 = sersum2(C, NN, NM, NNL);
/*      printf("isum1=%d\n",isum1);*/

    isumt1 = 0;
    #pragma dvm actual(isumt1)
    #pragma dvm region local(A)
    {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            A[i][j] = NL + i + j;

    #pragma dvm parallel([i][j] on A[i][j]) reduction(sum(isumt1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            isumt1 = isumt1 + A[i][j];
    } /*end region*/

    #pragma dvm get_actual(isumt1)

    if (isum1 == isumt1)
        ansyes(tname);
    else
        ansno(tname);
//      printf("isum1=%d isumt1=%d\n",isum1,isumt1);
}
/* ---------------------------------------------RED2102  */
void red2102()
{
    int C[N][M], CL[N][M];
    char tname[] = "RED2102";
    int i, j, NN, NM, NNL;
    long iprod1, iprodt1;

    #pragma dvm array distribute[block][block]
    int A[N][M];

    NN = N;
    NM = M;
    NNL = PNL;

    iprod1 = serprod2(C, NN, NM, NNL);

    iprodt1 = 1;
    #pragma dvm actual(iprodt1)
    #pragma dvm region local(A)
    {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            A[i][j] = NNL + i + j;
    #pragma dvm parallel([i][j] on A[i][j]) reduction(product(iprodt1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            iprodt1 = iprodt1 * A[i][j];
/*       printf("iprodt1=%ld\n",iprodt1);*/
     } /*end region*/

    #pragma dvm get_actual(iprodt1)
/*       printf("iprod1=%ld iprodt1=%ld \n",
             iprod1,iprodt1);*/

    if (iprod1 == iprodt1)
        ansyes(tname);
    else
        ansno(tname);
}
/*  ---------------------------------------------RED2103*/
void red2103()
{
    int C[N][M];
    char tname[] = "RED2103";
    int i, j, NN, NM, NNL, imax1, imaxt1, ni, nj;

    #pragma dvm array distribute[block][block]
    int A[N][M];

    NN = N;
    NM = M;
    NNL = NL;
    ni = N / 2 - 1;
    nj = M / 2 - 1;
    imax1 = N + M + 1 + NL;

    #pragma dvm actual(imax1, ni, nj)
//      #pragma dvm region local(A)
//      {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            A[i][j] = NNL + i + j;
    A[ni][nj] = N + M + 1 + NNL;

    #pragma dvm actual(A)
    #pragma dvm region in(A)
    {
    #pragma dvm host_section
    {
    #pragma dvm remote_access(A[0][0])
    {
    imaxt1=A[0][0];
//      printf("imaxt1=%d\n",imaxt1);
    }
    #pragma dvm actual(imaxt1)
    }
    #pragma dvm parallel([i][j] on A[i][j]) reduction(max(imaxt1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            if (A[i][j] > imaxt1) imaxt1=A[i][j];

    } /*end region*/

    #pragma dvm get_actual(imaxt1)

    if (imax1 == imaxt1)
        ansyes(tname);
    else
        ansno(tname);
//     printf("imax1=%d imaxt1=%d\n",imax1,imaxt1);
}

 /*---------------------------------------------RED2104 */
void red2104()
{
    int C[N][M];
    char tname[] = "RED2104";
    int i, j, NN, NM, NNL, imin1, imint1, ni, nj;

    #pragma dvm array distribute[block][block]
    int A[N][M];

    NN = N;
    NM = M;
    NNL = NL;

    ni = N / 2 +1;
    nj = M / 2 + 1;
    imin1 = -(N + M + 1 + NL);

    #pragma dvm actual(imin1, ni, nj)
//      #pragma dvm region local(A)
//      {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            A[i][j] = NL + i + j;

    A[ni][nj] = -(N + M + 1 + NL);

    #pragma dvm actual(A)
    #pragma dvm region in(A)
    {

    #pragma dvm host_section
    {
    #pragma dvm remote_access(A[0][0])
    {
    imint1=A[0][0];
//      printf("imint1=%d\n",imint1);
    }
    #pragma dvm actual(imint1)
    }
    #pragma dvm parallel([i][j] on A[i][j]) reduction(min(imint1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            if (A[i][j] < imint1) imint1=A[i][j];

    } /*end region*/

    #pragma dvm get_actual(imint1)

    if (imin1 == imint1)
        ansyes(tname);
    else
        ansno(tname);
//      printf("imin1=%d imint1=%d\n",imin1,imint1);
}
/* ---------------------------------------------RED2105*/
void red2105()
{
    float C[N][M];
    char tname[] = "RED2105";
    int i, j, NN, NM, NNL, ni, nj;
    float imax1, imaxt1;

    #pragma dvm array distribute[block][block]
    float A[N][M];

    NN = N;
    ni = N / 2 - 1;
    nj = M / 2 - 1;
    imax1= N + M + 1. + RNL;

    #pragma dvm actual(imax1, ni, nj)
//      #pragma dvm region local(A)
//      {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            A[i][j] = NL + i + j;
    A[ni][nj] = N + M + 1. + RNL;

    #pragma dvm actual(A)
    #pragma dvm region in(A)
    {
    #pragma dvm host_section
    {
    #pragma dvm remote_access(A[0][0])
    {
    imaxt1=A[0][0];
    }
    #pragma dvm actual(imaxt1)
    }
    #pragma dvm parallel([i][j] on A[i][j]) reduction(max(imaxt1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            if (A[i][j] > imaxt1) imaxt1 = A[i][j];

    } /*end region*/

    #pragma dvm get_actual(imaxt1)
    if (imax1 == imaxt1)
        ansyes(tname);
    else
        ansno(tname);
/*      printf("imax1=%f imaxt1=%f\n",imax1,imaxt1); */
}
/* ---------------------------------------------RED2106 */
void red2106()
{
    float C[N][M], CL[N][M];
    char tname[] = "RED2106";
    int i, j, NN, NM, NNL;
    float iprod1, iprodt1, RNNL;

    #pragma dvm array distribute[block][block]
    float A[N][M];

    NN = N;
    NM = M;
    RNNL = RPNL;

    iprod1 = serprodr2(C, NN, NM, RNNL);
    iprodt1 = 1;

    #pragma dvm actual(iprodt1)
    #pragma dvm region local(A)
    {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            A[i][j] = NL + i + j;
    #pragma dvm parallel([i][j] on A[i][j]) reduction(product(iprodt1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            iprodt1 = iprodt1 * A[i][j];
/*       printf("iprodt1=%ld\n",iprodt1);*/
    } /*end region*/

    #pragma dvm get_actual(iprodt1)
/*       printf("iprod1=%ld iprodt1=%ld \n",
             iprod1,iprodt1);
*/
    if (iprod1 == iprodt1)
        ansyes(tname);
    else
        ansno(tname);
}

/* ---------------------------------------------RED2107*/
void red2107()
{
    int C[N][M], CL[N][M];
    char tname[] = "RED2107";
    int i, j, NN, NM, NNL;
    int land1, landt1;

    #pragma dvm array distribute[block][block]
    int A[N][M];


    NN = N;
    NM = M;
    NNL = NL;

    land1 = serand2(CL, NN, NM, NNL);

    #pragma dvm actual(land1)
    #pragma dvm region local(A)
    {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j += 2)
            A[i][j] = 1;

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 1; j < M; j += 2)
            A[i][j] = 0;
    #pragma dvm host_section
    {
    #pragma dvm remote_access(A[0][0])
    {
    landt1=A[0][0];
    }
    #pragma dvm actual(landt1)
    }
    #pragma dvm parallel([i][j] on A[i][j]) reduction(and(landt1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            landt1 = landt1 && A[i][j];
     } /*end region*/

    #pragma dvm get_actual(landt1)
/*       printf(" land1=%d landt1=%d\n",
             land1,landt1);*/

    if (land1 == landt1)
        ansyes(tname);
    else
        ansno(tname);
}
/* ---------------------------------------------RED2108*/
void red2108()
{
    int C[N][M], CL[N][M];
    char tname[] = "RED2108";
    int i, j, NN, NM, NNL;
    int lor1, lort1;

    #pragma dvm array distribute[block][block]
    int A[N][M];


    NN = N;
    NM = M;
    NNL = NL;

    lor1 = seror2(CL, NN, NM, NNL);

    #pragma dvm actual(lor1)
    #pragma dvm region local(A)
    {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j += 2)
            A[i][j] = 1;

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 1; j < M; j += 2)
            A[i][j] = 0;
    #pragma dvm host_section
    {
    #pragma dvm remote_access(A[0][0])
    {
    lort1=A[0][0];
    }
    #pragma dvm actual(lort1)
    }
    #pragma dvm parallel([i][j] on A[i][j]) reduction(or(lort1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            lort1 = lort1 || A[i][j];
    } /*end region*/

    #pragma dvm get_actual(lort1)

    if (lor1 == lort1)
        ansyes(tname);
    else
        ansno(tname);
}
/* ---------------------------------------------RED2109*/
void red2109()
{
    int C[N][M], CL[N][M];
    char tname[] = "RED2109";
    int i, j, NN, NM, NNL;
    int lxor1, lxort1;

    #pragma dvm array distribute[block][block]
    int A[N][M];


    NN = N;
    NM = M;
    NNL = NL;

    lxor1 = serxor2(CL, NN, NM, NNL);

    #pragma dvm actual(lxor1)
    #pragma dvm region local(A)
    {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j += 2)
            A[i][j] = 1;

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 1; j < M; j += 2)
            A[i][j] = 0;
    #pragma dvm host_section
    {
    lxort1 = 0;
    #pragma dvm actual(lxort1)
    }
    #pragma dvm parallel([i][j] on A[i][j]) reduction(xor(lxort1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            lxort1 = lxort1 ^ A[i][j];
    } /*end region*/

    #pragma dvm get_actual(lxort1)

    if (lxor1 == lxort1)
        ansyes(tname);
    else
        ansno(tname);
}

/* ---------------------------------------------RED2111*/
void red2111()
{
    int C[N][M];
    char tname[] = "RED2111";
    int i, j, NN, NM, NNL, imax1, imaxt1, ni, ni1, nj, nj1;
    int imaxloct1;
    int coor[2];
    #pragma dvm array distribute[block][block]
    int A[N][M];

    NN = N;
    NM = M;
    NNL = NL;

    ni = N / 2 - 1;
    nj = M / 2 - 1;
    imax1 = N + M + 1 + NL;

    #pragma dvm actual(imax1,ni,nj)
//      #pragma dvm region local(A)
//      {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
             A[i][j] = NL + i + j;
    A[ni][nj] = N + M + 1 + NL;

    #pragma dvm actual(A)
    #pragma dvm region in(A)
    {
    #pragma dvm host_section
    {
    #pragma dvm remote_access(A[0][0])
    {
     imaxt1=A[0][0];
    }
    #pragma dvm actual(imaxt1)
    }
    imaxloct1 = imaxt1;
    coor[0] = 0;
    coor[1] = 0;
    #pragma dvm parallel([i][j] on A[i][j]) reduction(maxloc(imaxloct1, coor))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            if (A[i][j] > imaxloct1)
            {
                imaxloct1 = A[i][j];
                coor[0] = i;
                coor[1] = j;
            }

    } /*end region*/

    #pragma dvm get_actual(imaxloct1, coor)
    if ((imaxloct1 == imax1) && (coor[0] == ni) && (coor[1] == nj))
        ansyes(tname);
    else
        ansno(tname);
/*      printf("imax1=%d imaxt1=%d imaxloct1=%d coor=%d %d ni=%d\n",
            imax1,imaxt1,imaxloct1,coor[0],coor[1],ni); */
}
 /*---------------------------------------------RED2112*/
void red2112()
{
    int C[N][M];
    char tname[] = "RED2112";
    int i, j, NN, NM, NNL, imin1, imint1, ni, ni1, nj1;
    int iminloct1;
    int coor[2];
    #pragma dvm array distribute[block][block]
    int A[N][M];

    NN = N;
    NM = M;
    NNL = NL;
    ni1 = N /2 + 1;
    nj1 = M / 2 +1;
    imin1 = -(N + 1 + M + NL);

    #pragma dvm actual(imin1, ni1, nj1)
//      #pragma dvm region local(A)
//      {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            A[i][j] = NL + i + j;
    A[ni1][nj1] = -(N + 1 + M + NL);

    #pragma dvm actual(A)
    #pragma dvm region in(A)
    {
    #pragma dvm host_section
    {
    #pragma dvm remote_access(A[0][0])
    {
     imint1 = A[0][0];
    }
    #pragma dvm actual(imint1)
    }
    iminloct1 = imint1;
    coor[0] = 0;
    coor[1] = 0;
    #pragma dvm parallel([i][j] on A[i][j]) reduction(minloc(iminloct1,coor))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            if (A[i][j] < iminloct1)
            {
                iminloct1 = A[i][j];
                coor[0] = i;
                coor[1] = j;
            }
    } /*end region*/

    #pragma dvm get_actual(iminloct1, coor)

    if ((iminloct1 == imin1) && (coor[0] == ni1) && (coor[1] == nj1))
        ansyes(tname);
    else
        ansno(tname);
/*      printf("imin1=%d imint1=%d iminloct1=%d coor=%d %d ni1=%d\n",
            imin1,imint1,iminloct1,coor[0],coor[1],ni1);*/
}

/* ---------------------------------------------RED2113*/
void red2113()
{
    int C[N][M];
    char tname[] = "RED2113";
    int i, j, NN, NM, NNL, ISUM1, isum1, isumt1, imax1, imaxt1, imin1, imint1, ni, nj;

    #pragma dvm array distribute[block][block]
    int A[N][M];

    NN = N;
    NM = M;
    NNL = NL;
    isum1 = sersum2m(C, NN, NM, NNL);
    imax1 = N + M + 1 + NL;

    ni = N / 2 - 1;
    nj = M / 2 - 1;
    imin1 = -(N + M + 1 + NL);
    isumt1 = 0;

    #pragma dvm actual(imin1, imax1, isumt1, ni, nj)
//      #pragma dvm region local(A)
//      {

    #pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            A[i][j] = NL + i + j;

    A[ni][nj] = -(N + M + 1 + NL);
    A[ni+1][nj+1] = N + M + 1 + NL;

    #pragma dvm actual(A)
    #pragma dvm region in(A)
    {

    #pragma dvm host_section
    {
    #pragma dvm remote_access(A[0][0])
    {
     imaxt1 = A[0][0];
    }
    #pragma dvm actual(imaxt1)
    }
    imint1 = imaxt1;

    #pragma dvm parallel([i][j] on A[i][j]) reduction(sum(isumt1), max(imaxt1), min(imint1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
        {
            isumt1 = isumt1 + A[i][j];
            if (A[i][j] > imaxt1) imaxt1 = A[i][j];
            if (A[i][j] < imint1) imint1 = A[i][j];
        }
    } /*end region*/

    #pragma dvm get_actual(isumt1, imaxt1, imint1)

    if ((isum1 == isumt1) && (imax1 == imaxt1) && (imin1 == imint1))
        ansyes(tname);
    else
        ansno(tname);
/*     printf("isum1=%d isumt1=%d\n",isum1,isumt1);
    printf("imax1=%d imaxt1=%d\n",imax1,imaxt1);
    printf("imin1=%d imint1=%d\n",imin1,imint1);  */
}
/* ---------------------------------------------RED2114*/
void red2114()
{
    int C[N][M], CL[N][M];
    char tname[] = "RED2114";
    int i, j, NN, NM, NNL;
    int iprod1, iprodt1;
    int land1, landt1;

    #pragma dvm array distribute[block][block]
    int A[N][M];
    #pragma dvm array align([i][j]with A[i][j])
    int B[N][M];


    NN = N;
    NM = M;
    NNL = NL;

    iprod1 = serprod2(C, NN, NM, NNL);
    land1 = serand2(CL, NN, NM, NNL);

    #pragma dvm actual(iprod1, land1)
    #pragma dvm region local(A), local(B)
    {

    #pragma dvm parallel([i][j] on B[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            A[i][j] = NL + i + j;
    #pragma dvm parallel([i][j] on B[i][j])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j += 2)
            B[i][j] = 1;

    #pragma dvm parallel([i][j] on B[i][j])
    for (i = 0; i < N; i++)
        for (j = 1; j < M; j += 2)
            B[i][j] = 0;

    #pragma dvm host_section
    {
    #pragma dvm remote_access(B[0][0])
    {
    landt1 = B[0][0];
    }
    #pragma dvm actual(landt1)
    }

    iprodt1 = 1;
    #pragma dvm parallel([i][j] on A[i][j]) reduction(product(iprodt1), and(landt1))
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
        {
            iprodt1 = iprodt1*A[i][j];
            landt1 = landt1 && B[i][j];
        }

    } /*end region*/
    #pragma dvm get_actual(iprodt1,landt1)

/*       printf("iprod1=%d iprodt1=%d land1=%d landt1=%d\n",
             iprod1,iprodt1,land1,landt1); */

    if ((iprod1 == iprodt1) && (land1 == landt1))
        ansyes(tname);
    else
        ansno(tname);
}

int sersum2(int AR[N][M], int NN, int NM, int NNL)
{
    int i, j, S;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            AR[i][j] = NNL + i + j;

    S = 0;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            S = S + AR[i][j];

/*      printf("s=%d\n",S);*/
    return S;
}
int sersum2m(int AR[N][M], int NN, int NM, int NNL)
{
    int i, j, ni, nj, S;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            AR[i][j] = NNL + i + j;
    ni = NN / 2 - 1;
    nj = NM / 2 - 1;
    AR[ni][nj] = NN + NM + 1 + NNL;
    ni = NN / 2;
    nj = NM / 2;
    AR[ni][nj] = -(NN + NM + 1 + NNL);
    S = 0;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            S = S + AR[i][j];
/*      printf("s=%d\n",S);*/
    return S;
}
float sers2mr(float RAR[N][M], int NN, int NM, float NNL)
{
    int i, j, ni, nj;
    float S;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            RAR[i][j] = NNL+i+j;

    ni = NN / 2 - 1;
    nj = NM / 2 - 1;
    RAR[ni][nj] = NN + NM + 1. + NNL;
    ni = NN / 2 + 1;
    nj = NM / 2 + 1;
    RAR[ni][nj] = -(NN + NM + 1. + NNL);
    S = 0;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            S = S + RAR[i][j];

/*      printf("s=%d\n",S);*/
    return S;
}
long serprod2(int AR[N][M], int NN, int NM, int NNL)
{
    int i, j, ni, nj;
    long P;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
             AR[i][j] = NNL+i+j;
/*       printf("I=%d J=%d AR=%d\n",I,J,AR[I][J]);*/

    P = 1;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
             P = P * AR[i][j];
    return P;
}
float serprodr2(float AR[N][M], int NN, int NM, float NNL)
{
    int i, j;
    float P;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
             AR[i][j] = NNL+i+j;
    P = 1;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            P = P * AR[i][j];
    return P;
}
int serand2(int AR[N][M], int NN, int NM, int NNL)
{
    int i, j, LAND;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j += 2)
            AR[i][j] = 1;
    for (i = 0; i < NN; i++)
        for (j = 1; j < NM; j += 2)
            AR[i][j] = 0;

    LAND = AR[0][0];
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            LAND = LAND && AR[i][j];

    return LAND;
}

int seror2(int AR[N][M], int NN, int NM, int NNL)
{
    int i, j, LOR;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j += 2)
            AR[i][j] = 1;
    for (i = 0; i < NN; i++)
        for (j = 1; j < NM; j += 2)
            AR[i][j] = 0;

    LOR = AR[0][0];
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            LOR = LOR || AR[i][j];

    return LOR;
}

int serxor2(int AR[N][M], int NN, int NM, int NNL)
{
    int i, j, LXOR;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j += 2)
            AR[i][j] = 1;
    for (i = 0; i < NN; i++)
        for (j = 1; j < NM; j += 2)
            AR[i][j] = 0;

    LXOR = 0;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            LXOR = LXOR ^ AR[i][j];

    return LXOR;
}

void ansyes(const char name[])
{
    printf ("%s  -  complete\n", name);
}

void ansno(const char name[])
{
    printf("%s  -  ***error\n", name);
}
