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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
template <typename A, typename B>
using unordered_map2 = __gnu_pbds::gp_hash_table<A, B>;
using namespace __gnu_pbds;
template <typename T> using ordered_set =
  __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,
                   __gnu_pbds::tree_order_statistics_node_update>;
// ordered_set<int> s; s.insert(1); s.insert(2);
// s.order_of_key(1);    // Out: 0.
// *s.find_by_order(1);  // Out: 2.

using ld = long double;
using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int odw2 = (mod + 1) / 2;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, ll b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }

template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }

bool Square(int x) {
  int y = sqrt(x);
  return y * y == x;
}

// Array [-Size, Size] x [-Size, Size].
template <int Size>
class NegArray {
 public:
  unsigned& operator()(int r, int c) {
    #ifdef LOCAL
    assert(-Size <= r and r <= Size);
    assert(-Size <= c and c <= Size);
    #endif
    return tab[r + Size][c + Size];
  }

  void Clear() {
    memset(tab, 0, sizeof(tab));
  }

 private:
  unsigned tab[Size * 2 + 1][Size * 2 + 1];
};

// Array [-Size, Size] x [0, Size].
template <int Size>
class NegArray2 {
 public:
  unsigned& operator()(int r, int c) {
    #ifdef LOCAL
    assert(-Size <= r and r <= Size);
    assert(0 <= c and c <= Size);
    #endif
    return tab[r + Size][c];
  }

  void Clear() {
    memset(tab, 0, sizeof(tab));
  }

 private:
  unsigned tab[Size * 2 + 1][Size + 1];
};

int X, Y, K, n;
vector<pair<int, int>> vs;

unsigned Zmiesc(int x, int y) {
  assert(0 <= x and 0 <= y);
  if (x > X or y > Y) return 0;
  return unsigned(X - x + 1) * unsigned(Y - y + 1);
}

void WszystkieWielokaty() {
  vector<pair<int, int>> wektory;
  for (auto& v : vs) {
    const int x = v.first;
    const int y = v.second;
    wektory.emplace_back( x,  y);
    wektory.emplace_back( y, -x);
    wektory.emplace_back(-x, -y);
    wektory.emplace_back(-y,  x);
  }
  debug() << imie(wektory) imie(wektory.size());
  const int m = (int) wektory.size();
  unsigned wynik = 0;
//  unsigned suma_xy = 0;
//  unsigned suma_x = 0;
//  unsigned suma_y = 0;
//  unsigned wszystkie = 0;
  for (int i = 0; i < (1 << m); i++) {
    if (__builtin_popcount(i) < 3) {
      continue;
    }
    int x = 0, y = 0;
    int xmod = 0, ymod = 0;
    for (int j = 0; j < m; j++) {
      if ((i >> j) & 1) {
        x += wektory[j].first;
        y += wektory[j].second;
        xmod += abs(wektory[j].first);
        ymod += abs(wektory[j].second);
      }
    }
    if (x == 0 and y == 0) {
//      wszystkie += 1;
//      suma_xy += (xmod / 2) * (ymod / 2);
//      suma_x += (xmod / 2);
//      suma_y += (ymod / 2);
      assert(xmod % 2 == 0 and ymod % 2 == 0);
      wynik += Zmiesc(xmod / 2, ymod / 2);
    }
  }
  cout << wynik << endl;
  //debug() << imie(suma_xy) imie(suma_x) imie(suma_y) imie(wszystkie);
}

void MaleXY() {
  unsigned wynik = 0;
  vector<NegArray<150>> dp(151);
  for (int maxx = 0; maxx <= X; maxx++) {
    NegArray<150>& arr = dp[maxx];
    arr.Clear();
    arr(0, 0) = 1;
    for (auto& v : vs) {
      const int dx = v.second;
      const int dy = v.first;
      for (int x = maxx - dx; x >= 0; x--) {
        for (int y = Y - dy; y >= 0; y--) {
          arr(x + dx, y + dy) += arr(x, y);
        }
      }
    }
    for (int x = 0; x < maxx; x++) {
      for (int y = 0; y <= Y; y++) {
        arr(x, y) = 0;
      }
    }
    for (auto& v : vs) {
      const int dx = -v.first;
      const int dy = v.second;
      for (int x = maxx - X - dx; x <= maxx; x++) {
        for (int y = Y - dy; y >= 0; y--) {
          arr(x + dx, y + dy) += arr(x, y);
        }
      }
    }
  }
  for (int maxx = 0; maxx <= X; maxx++) {
    for (int minx = 0; minx >= maxx - X; minx--) {
      for (int x = minx; x <= maxx; x++) {
        for (int y = 0; y <= Y; y++) {
          const int xdiff = maxx - minx;
          const int ydiff = y;
          const unsigned sposoby = dp[maxx](x, y) * dp[x - minx](x, y);
          if (sposoby) {
            wynik += Zmiesc(xdiff, ydiff) * sposoby;
          }
        }
      }
    }
  }
  for (auto& v : vs) {
    const int x = v.first;
    const int y = v.second;
    wynik -= Zmiesc(x, y);
    wynik -= Zmiesc(y, x);
  }
  wynik -= Zmiesc(0, 0);
  cout << wynik << endl;
}

void LiczDpDlaWszystkich() {
  static NegArray2<12500> *roznica_ = nullptr;
  static NegArray2<12500> *roznica_razy_x_ = nullptr;
  if (roznica_ == nullptr) roznica_ = new NegArray2<12500>();
  if (roznica_razy_x_ == nullptr) roznica_razy_x_ = new NegArray2<12500>();
  auto& roznica = *roznica_;
  auto& roznica_razy_x = *roznica_razy_x_;
  roznica(0, 0) = 1;
  for (auto& v : vs) {
    const int dx = v.first;
    const int dy = v.second;
    for (int x = n - dx; x >= 0; x--) {
      for (int y = n - dy; y >= 0; y--) {
        roznica(x + dx, y + dy) += roznica(x, y);
      }
    }
  }
  for (int x = 0; x <= n; x++) {
    for (int y = 0; y <= n; y++) {
      roznica_razy_x(x, y) = roznica(x, y) * x;
    }
  }
  for (auto& v : vs) {
    const int dx = -v.second;
    const int dy = v.first;
    for (int x = -n - dx; x <= n; x++) {
      for (int y = n - dy; y >= 0; y--) {
        roznica(x + dx, y + dy) += roznica(x, y);
        roznica_razy_x(x + dx, y + dy) += roznica_razy_x(x, y);
      }
    }
  }
  unsigned wszystkie = 0;
  unsigned suma_x = 0;
  unsigned suma_xy = 0;
  for (int dx = -n; dx <= n; dx++) {
    for (int dy = 0; dy <= n; dy++) {
      const unsigned wartosc =
          + roznica_razy_x(dx, dy) * roznica(dx, dy)
          + roznica(dx, dy) * roznica_razy_x(dx, dy)
          - roznica(dx, dy) * roznica(dx, dy) * dx;
      wszystkie += roznica(dx, dy) * roznica(dx, dy);
      suma_x += wartosc;
      suma_xy += wartosc * dy;
    }
  }
  wszystkie -= 1;
  for (auto& v : vs) {
    const int dx = v.first;
    const int dy = v.second;
    suma_x -= dx + dy;
    suma_xy -= dx * dy * 2;
    wszystkie -= 2;
  }
  const unsigned wynik =
      unsigned(X + 1) * unsigned(Y + 1) * wszystkie
      - unsigned(X + 1 + Y + 1) * suma_x
      + suma_xy;
  debug() << imie(suma_x) imie(suma_xy) imie(wszystkie) imie(wynik);
  cout << K << " " << suma_x << " " << suma_xy << " " << wszystkie << endl;
  //cout << wynik << endl;
}

void DawajSpamietane() {
  constexpr unsigned tab[][4] = {
    {250, 1409062405, 395262900, 1039346929},
    {240, 4080245447, 855458420, 3805621621},
    {232, 1278208009, 1421610980, 902879417},
    {228, 1886128043, 3415573876, 4248956733},
    {220, 1075271827, 2573379088, 1914047029},
    {204, 3415855283, 1214744112, 2372749245},
    {196, 554882473, 377641604, 1483982033},
    {192, 896225303, 1284425036, 3184172021},
    {184, 1786444163, 1617219512, 3827362733},
    {180, 3098346457, 1817087796, 2341737569},
    {172, 846438283, 267154732, 319093637},
    {168, 1924356657, 3400781408, 2523528921},
    {156, 2423874379, 854782324, 3013762669},
    {148, 2923759689, 2882341452, 3515497745},
    {144, 729907001, 1424717084, 2032222553},
    {136, 1413599627, 473620188, 3469017693},
    {124, 1625950525, 2391666140, 2907057441},
    {112, 2058969451, 1791013532, 3840732837},
    {108, 698667385, 3324120980, 1654251977},
    {100, 3536561367, 2044903956, 1096062349},
    {96, 3278958857, 60391644, 1690965681},
    {88, 211044991, 1566289608, 3551711205},
    {84, 437712451, 1455219800, 3842663341},
    {72, 3699519905, 3239739328, 3385992273},
    {64, 609747729, 425724720, 2140219417},
    {60, 1737252415, 3727883248, 3296100573},
    {52, 1747674161, 2045608656, 3565658145},
    {40, 994795395, 2775639944, 547682309},
    {36, 3120121977, 4129611228, 1535638041},
    {28, 941471067, 3422116620, 11993245},
    {24, 6322345, 316484604, 133089},
    {16, 45031, 1214188, 1829},
    {12, 585, 5316, 73},
    {4, 1, 1, 1},
  };
  unsigned suma_x = 0, suma_xy = 0, wszystkie = 0;
  for (int i = 0; i < (int) (sizeof(tab) / sizeof(unsigned[4])); i++) {
    if ((int) tab[i][0] >= K) {
      suma_x = tab[i][1];
      suma_xy = tab[i][2];
      wszystkie = tab[i][3];
    }
  }
  const unsigned wynik =
      unsigned(X + 1) * unsigned(Y + 1) * wszystkie
      - unsigned(X + 1 + Y + 1) * suma_x
      + suma_xy;
  cout << wynik << endl;
}

map<pair<int, int>, unsigned> zebrane;

void Baktracz() {
  static NegArray2<2500> tab;
  tab(0, 0) = 1;
  pair<int, int> suma = {0, 0};
  for (auto& v : vs) {
    suma.first += v.first;
    suma.second += v.second;
    const int dx = v.first;
    const int dy = v.second;
    for (int x = n - dx; x >= 0; x--) {
      for (int y = n - dy; y >= 0; y--) {
        tab(x + dx, y + dy) += tab(x, y);
      }
    }
  }
  vector<pair<int, int>> dobre;
  for (int x = 0; x <= n; x++) {
    for (int y = 0; y <= n; y++) {
      if (x + suma.second <= 2000) continue;
      if (y + suma.first <= 2000) continue;
      dobre.emplace_back(x, y);
    }
  }
  debug() << imie(dobre.size());
}

void ZlotySrodek() {
  Baktracz();
  debug() << imie(zebrane);

  static NegArray2<2500> *roznica_ = nullptr;
  static NegArray2<2500> *roznica_razy_x_ = nullptr;
  if (roznica_ == nullptr) roznica_ = new NegArray2<2500>();
  if (roznica_razy_x_ == nullptr) roznica_razy_x_ = new NegArray2<2500>();
  auto& roznica = *roznica_;
  auto& roznica_razy_x = *roznica_razy_x_;
  roznica(0, 0) = 1;
  for (auto& v : vs) {
    const int dx = v.first;
    const int dy = v.second;
    for (int x = n - dx; x >= 0; x--) {
      for (int y = n - dy; y >= 0; y--) {
        roznica(x + dx, y + dy) += roznica(x, y);
      }
    }
  }
  for (int x = 0; x <= n; x++) {
    for (int y = 0; y <= n; y++) {
      roznica_razy_x(x, y) = roznica(x, y) * x;
    }
  }
  for (auto& v : vs) {
    const int dx = -v.second;
    const int dy = v.first;
    for (int x = -n - dx; x <= n; x++) {
      for (int y = n - dy; y >= 0; y--) {
        roznica(x + dx, y + dy) += roznica(x, y);
        roznica_razy_x(x + dx, y + dy) += roznica_razy_x(x, y);
      }
    }
  }
  unsigned wszystkie = 0;
  unsigned suma_x = 0;
  unsigned suma_xy = 0;
  for (int dx = -n; dx <= n; dx++) {
    for (int dy = 0; dy <= n; dy++) {
      const unsigned wartosc =
          + roznica_razy_x(dx, dy) * roznica(dx, dy)
          + roznica(dx, dy) * roznica_razy_x(dx, dy)
          - roznica(dx, dy) * roznica(dx, dy) * dx;
      wszystkie += roznica(dx, dy) * roznica(dx, dy);
      suma_x += wartosc;
      suma_xy += wartosc * dy;
    }
  }
  wszystkie -= 1;
  for (auto& v : vs) {
    const int dx = v.first;
    const int dy = v.second;
    suma_x -= dx + dy;
    suma_xy -= dx * dy * 2;
    wszystkie -= 2;
  }
  const unsigned wynik =
      unsigned(X + 1) * unsigned(Y + 1) * wszystkie
      - unsigned(X + 1 + Y + 1) * suma_x
      + suma_xy;
  debug() << imie(suma_x) imie(suma_xy) imie(wszystkie) imie(wynik);
  cout << K << " " << suma_x << " " << suma_xy << " " << wszystkie << endl;
  //cout << wynik << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> X >> Y >> K;
  X--; Y--;
  //bool to_samo_co_kp1 = true;
  for (int i = 0; i <= K + 1 and i <= max(X, Y); i++) {
    for (int j = 1; j <= K + 1 and j <= max(X, Y); j++) {
      if (__gcd(i, j) == 1 and i * i + j * j <= K * K and
          Square(i * i + j * j)) {
        vs.emplace_back(i, j);
        n += i + j;
      } else if (__gcd(i, j) == 1 and i * i + j * j <= (K + 1) * (K + 1) and
          Square(i * i + j * j)) {
        //to_samo_co_kp1 = false;
      }
    }
  }
  //if (K == 250) to_samo_co_kp1 = false;
  //if (to_samo_co_kp1) return 0;

  debug() << imie(vs);
  debug() << imie(vs.size()) imie(n);

  if (K <= 15) {
    WszystkieWielokaty();
  } else if (X <= 150 and Y <= 150) {
    MaleXY();
  } else if (n <= X and n <= Y) {
    DawajSpamietane();
  } else {
    assert(n <= 2400);
    assert(2000 <= X and 2000 <= Y);
    ZlotySrodek();
  }
  return 0;
}