1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <algorithm>
#include <bitset>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#include "dzialka.h"
#include "message.h"

using namespace std;

// debugging stuff {{{
#ifdef DEBUG
  #define bDebug 1
  #define bDebug2 0
#else
  #define bDebug 0
  #define bDebug2 0
#endif
#define deb(a) #a << "=" << (a) << " "
#ifndef HOME
  #define assert(a) {}
#endif

template<class T> ostream& operator<<(ostream& os, vector<T> v) //{{{
{
  for(int i=0; i<v.size(); i++)
    os << v[i] << " ";
  os << endl;
  return os;
}  //}}}
// }}} end of debugging stuff

//c++11
#define typeof __typeof__

#define array(a, type, count) type *a = (type*)calloc(sizeof(type), count)
#define eps 1e-9
#define eq(a, b) ( (a) > (b) - eps && (a) < (b) + eps )
#define eraseAll(v) v.erase(v.begin(), v.end())
#define fi first
#define rep(i,n) for(long i=0; i<(n); i++)
#define rep2(i,a,b) for(long i=(a); i<=(b); i++)
#define rep2d(i,a,b) for(long i=(a); i>=(b); i--)
#define zeroMem(a) memset(a, 0, sizeof(a))
#define zeroMem2(a, n) memset(a, 0, sizeof(*a) * n)
#define fore(it,L) for(typeof(L.begin()) it=L.begin(); it!=L.end(); it++)
#define eraseAll(v) v.erase(v.begin(), v.end())
#define se second
#define setMin(a,b) { typeof(a) rv = (b); if (rv < a) a = rv; }
#define setMinP(a,b) { typeof(a) rv = (b); \
                       if (rv >= 0 && (a < 0 || rv < a)) a = rv; }
#define setMax(a,b) { typeof(a) rv = (b); if (rv > a) a = rv; }
#define swap(a,b) { typeof(a) swapVar = a; a = b; b = swapVar; }
#define Int long long

//*********************** SOLUTION    ******************************
#define MAXW 1000
#define MAXH 1000
long w, h;

int isUsableCell(long x, long y) {
  if (x < 0) return 0;
  if (x >= w) return 0;
  if (y < 0) return 0;
  if (y >= h) return 0;
  return IsUsableCell(y, x);
}

int isRangeUsable(long y1, long x1, long y2, long x2) {
  rep2(y, y1, y2)
    rep2(x, x1, x2)
      if (!isUsableCell(y, x))
        return 0;
  return 1;
}

long solveFrom(long x, long y) {
  long r = 0;
  long dx = 0, dy = 0;
  while (isUsableCell(y, x + dx)) {
    dy = 0;
    while (isRangeUsable(y + dy, x, y + dy, x + dx)) {
      r++;
      dy++;
    }
    dx++;
  }
  return r;
}

main ()
{
  cin.sync_with_stdio(false);
  //ifstream cin("0.in");
  cout.sync_with_stdio(false);
  h = GetFieldHeight();
  w = GetFieldWidth();
  if (h * w > 100)
    return 0;
  long r = 0;
  if (MyNodeId() == 0) {
    rep(y, h) {
      rep(x, w) {
        int other = x * w + y + 1;
        PutInt(other, x);
        PutInt(other, y);
        Send(other);
        Receive(other);
        r += GetInt(other);
      }
    }
    cout << r << endl;
    rep2(i, 1, NumberOfNodes() - 1) {
      PutInt(i, -1);
      Send(i);
    }
  } else {
    while(1) {
      int other = Receive(-1);
      int x = GetInt(other);
      if (x < 0)
        break;
      int y = GetInt(other);
      PutInt(other, solveFrom(x, y));
      Send(other);
    }
  }
}