description: You are given a matrix, consisting of n rows and m columns. The rows are numbered top to bottom, the columns are numbered left to right.
  
  Each cell of the matrix can be either free or locked.
  
  Let's call a path in the matrix a staircase if it: 
  
    * starts and ends in the free cell; 
    * visits only free cells; 
    * has one of the two following structures: 
      1. the second cell is 1 to the right from the first one, the third cell is 1 to the bottom from the second one, the fourth cell is 1 to the right from the third one, and so on; 
      2. the second cell is 1 to the bottom from the first one, the third cell is 1 to the right from the second one, the fourth cell is 1 to the bottom from the third one, and so on. 
  
  
  
  In particular, a path, consisting of a single cell, is considered to be a staircase.
  
  Here are some examples of staircases:
  
  <image>
  
  Initially all the cells of the matrix are free.
  
  You have to process q queries, each of them flips the state of a single cell. So, if a cell is currently free, it makes it locked, and if a cell is currently locked, it makes it free.
  
  Print the number of different staircases after each query. Two staircases are considered different if there exists such a cell that appears in one path and doesn't appear in the other path.
  
  Input
  
  The first line contains three integers n, m and q (1 ≤ n, m ≤ 1000; 1 ≤ q ≤ 10^4) — the sizes of the matrix and the number of queries.
  
  Each of the next q lines contains two integers x and y (1 ≤ x ≤ n; 1 ≤ y ≤ m) — the description of each query.
  
  Output
  
  Print q integers — the i-th value should be equal to the number of different staircases after i queries. Two staircases are considered different if there exists such a cell that appears in one path and doesn't appear in the other path.
  
  Examples
  
  Input
  
  
  2 2 8
  1 1
  1 1
  1 1
  2 2
  1 1
  1 2
  2 1
  1 1
  
  
  Output
  
  
  5
  10
  5
  2
  5
  3
  1
  0
  
  
  Input
  
  
  3 4 10
  1 4
  1 2
  2 3
  1 2
  2 3
  3 2
  1 3
  3 4
  1 3
  3 1
  
  
  Output
  
  
  49
  35
  24
  29
  49
  39
  31
  23
  29
  27
  
  
  Input
  
  
  1000 1000 2
  239 634
  239 634
  
  
  Output
  
  
  1332632508
  1333333000
solution: #include <bits/stdc++.h>
  using namespace std;
  const int DIR4[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  const int DIR8[8][2] = {{1, 0},   {-1, 0}, {0, 1},  {0, -1},
                          {-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
  const int MOD197 = 1e9 + 7;
  const int MOD19 = 1e9;
  const int MOD353 = 998244353;
  const int INF = 0x3f3f3f3f;
  const long long LINF = 0x3f3f3f3f3f3f3f3f;
  const int NINF = 0xc0c0c0c0;
  const long long LNINF = 0xc0c0c0c0c0c0c0c0;
  inline int LT(int x) { return x << 1; }
  inline int RT(int x) { return (x << 1) | 1; }
  inline int LB(int x) { return x & -x; }
  inline int MSK(int x) { return 1 << x; }
  inline int HF(int x) { return x >> 1; }
  inline int DB(int x) { return x << 1; }
  inline int GT(int x, int i) { return (x >> i) & 1; }
  inline int ST(int x, int i) { return x | (1 << i); }
  inline int ODD(int x) { return x & 1; }
  inline int SGN(int x) { return x >= 0 ? (x == 0 ? 0 : 1) : -1; }
  template <int mod>
  long long fpow(long long a, long long b) {
    long long ans = 1;
    for (; b; b >>= 1, a = (a * a) % mod)
      if (b & 1) ans = (ans * a) % mod;
    return ans;
  }
  template <int mod>
  struct MODINT {
    long long val;
    MODINT() : val(0) {}
    MODINT(long long v) : val(v % mod) {}
    MODINT operator+(const MODINT &o) const { return MODINT(val + o.val); }
    MODINT &operator+=(const MODINT &o) {
      val = (val + o.val) % mod;
      return *this;
    }
    MODINT operator*(const MODINT &o) const { return MODINT(val * o.val); }
    MODINT &operator*=(const MODINT &o) {
      val = (val * o.val) % mod;
      return *this;
    }
    MODINT operator-(const MODINT &o) const {
      return MODINT((val - o.val) % mod + mod);
    }
    MODINT &operator-=(const MODINT &o) {
      val = ((val - o.val) % mod + mod) % mod;
      return *this;
    }
    MODINT operator/(const MODINT &o) const {
      return MODINT(val * fpow<mod>(o.val, mod - 2));
    }
    MODINT &operator/=(const MODINT &o) {
      val = (val * fpow<mod>(o.val, mod - 2)) % mod;
      return *this;
    }
  };
  long long dp[1005][1005][2];
  int flip[1005][1005];
  int n, m;
  long long solve1(int r, int c) {
    int ur = r, uc = c;
    long long ut = 0;
    while (1) {
      if (uc - 1 > 0 && !flip[ur][uc - 1]) {
        ut++;
        uc--;
      } else
        break;
      if (ur - 1 > 0 && !flip[ur - 1][uc]) {
        ut++;
        ur--;
      } else
        break;
    }
    int br = r, bc = c;
    long long bt = 0;
    while (1) {
      if (br + 1 <= n && !flip[br + 1][bc]) {
        bt++;
        br++;
      } else
        break;
      if (bc + 1 <= m && !flip[br][bc + 1]) {
        bt++;
        bc++;
      } else
        break;
    }
    return ut * bt + ut + bt;
  }
  long long solve2(int r, int c) {
    int ur = r, uc = c;
    long long ut = 0;
    while (1) {
      if (ur - 1 > 0 && !flip[ur - 1][uc]) {
        ut++;
        ur--;
      } else
        break;
      if (uc - 1 > 0 && !flip[ur][uc - 1]) {
        ut++;
        uc--;
      } else
        break;
    }
    int br = r, bc = c;
    long long bt = 0;
    while (1) {
      if (bc + 1 <= m && !flip[br][bc + 1]) {
        bt++;
        bc++;
      } else
        break;
      if (br + 1 <= n && !flip[br + 1][bc]) {
        bt++;
        br++;
      } else
        break;
    }
    return ut * bt + ut + bt;
  }
  void solve() {
    int t;
    cin >> n >> m >> t;
    long long all = 0;
    for (int r = 1; r <= n; r++) {
      for (int c = 1; c <= m; c++) {
        dp[r][c][0] += dp[r][c - 1][1] + 1;
        dp[r][c][1] += dp[r - 1][c][0] + 1;
        all += dp[r][c][0] + dp[r][c][1] - 1;
      }
    }
    while (t--) {
      int x, y;
      cin >> x >> y;
      int tmp = flip[x][y];
      flip[x][y] = 0;
      long long a = solve1(x, y);
      long long b = solve2(x, y);
      flip[x][y] = 1 - tmp;
      if (flip[x][y]) {
        all -= a + b + 1;
      } else {
        all += a + b + 1;
      }
      cout << all << endl;
    }
  }
  int main() {
    ;
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
  }
  