#include <bits/stdc++.h>   const int MAXN = 2020;   int n, m;   int mp[MAXN][MAXN], realx[MAXN], realy[MAXN], cntx, cnty;   char dir[MAXN];   int len[MAXN];   void unique(int *real, int &cnt) {     std::sort(real, real + cnt);     int t2 = 1;     for (int t1 = 1; t1 < cnt; t1++)       if (real[t1] ^ real[t1 - 1]) real[t2++] = real[t1];     cnt = t2;   }   inline bool legal(int x, int y) {     return x >= 0 && x <= cntx && y >= 0 && y <= cnty;   }   void dfs(int x, int y) {     mp[x][y] = -1;     if (legal(x + 1, y) && !mp[x + 1][y]) dfs(x + 1, y);     if (legal(x - 1, y) && !mp[x - 1][y]) dfs(x - 1, y);     if (legal(x, y + 1) && !mp[x][y + 1]) dfs(x, y + 1);     if (legal(x, y - 1) && !mp[x][y - 1]) dfs(x, y - 1);   }   int main() {     scanf( %d , &n);     register int nowx = 0, nowy = 0;     for (int i = 1; i <= n; i++) {       scanf( %s%d , dir + i, len + i);       switch (dir[i]) {         case  L :           realx[cntx++] = nowx + 1;           realx[cntx++] = nowx -= len[i];           realy[cnty++] = nowy;           realy[cnty++] = nowy + 1;           break;         case  R :           realx[cntx++] = nowx;           realx[cntx++] = (nowx += len[i]) + 1;           realy[cnty++] = nowy;           realy[cnty++] = nowy + 1;           break;         case  U :           realy[cnty++] = nowy;           realy[cnty++] = (nowy += len[i]) + 1;           realx[cntx++] = nowx;           realx[cntx++] = nowx + 1;           break;         case  D :           realy[cnty++] = nowy + 1;           realy[cnty++] = nowy -= len[i];           realx[cntx++] = nowx;           realx[cntx++] = nowx + 1;           break;       }     }     unique(realx, cntx);     unique(realy, cnty);     int curx = std::upper_bound(realx, realx + cntx, nowx = 0) - realx,         cury = std::upper_bound(realy, realy + cnty, nowy = 0) - realy, nxt;     for (int i = 1; i <= n; i++) {       switch (dir[i]) {         case  L :           nxt = std::upper_bound(realx, realx + cntx, nowx -= len[i]) - realx;           while (curx > nxt) mp[curx--][cury] = 1;           break;         case  R :           nxt = std::upper_bound(realx, realx + cntx, nowx += len[i]) - realx;           while (curx < nxt) mp[curx++][cury] = 1;           break;         case  U :           nxt = std::upper_bound(realy, realy + cnty, nowy += len[i]) - realy;           while (cury < nxt) mp[curx][cury++] = 1;           break;         case  D :           nxt = std::upper_bound(realy, realy + cnty, nowy -= len[i]) - realy;           while (cury > nxt) mp[curx][cury--] = 1;           break;       }     }     mp[curx][cury] = 1;     for (int i = 0; i <= cntx; i++) {       if (!mp[i][cnty]) dfs(i, cnty);       if (!mp[i][0]) dfs(i, 0);     }     for (int i = 1; i < cnty; i++) {       if (!mp[cntx][i]) dfs(cntx, i);       if (!mp[0][i]) dfs(0, i);     }     long long ans = 0;     for (int i = 1; i <= cntx; i++)       for (int j = 1; j <= cnty; j++)         if (~mp[i][j])           ans += 1ll * (realx[i] - realx[i - 1]) * (realy[j] - realy[j - 1]);     printf( %lld n , ans);     return 0;   }   