## Tutorials:

### Source Code:

//Thu Jun  2 12:10:18 CDT 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

class CandyShop {
public:
int countProbablePlaces(vector <int>, vector <int>, vector <int>);
};

int CandyShop::countProbablePlaces(vector <int> X, vector <int> Y, vector <int> R) {
set<pair<int, int> > positions;
deque<pair<pair<int, int>, int> > q;
int N = X.size();
int mmax = 0;
set<pair<int, int> >::iterator it;
for(int i=0; i<N; i++){
set<pair<int, int> > tmp;
q.clear();
q.push_back(make_pair(make_pair(X[i], Y[i]), R[i]));
tmp.insert(make_pair(X[i], Y[i]));
while(!q.empty()){
int x = q.front().first.first;
int y = q.front().first.second;
int r = q.front().second;
q.pop_front();
if(r <= 0) continue;
for(int j=0; j<4; j++){
int xx = x + dx[j];
int yy = y + dy[j];
int sz = tmp.size();
tmp.insert(make_pair(xx, yy));
if(tmp.size() != sz)
q.push_back(make_pair(make_pair(xx, yy), r-1));
}
}
if(i==0)
positions = tmp;
else{
set<pair<int,int> > res;
for(it = tmp.begin(); it!=tmp.end(); it++){
if(positions.count(*it))
res.insert(*it);
}
positions = res;
}
}
return positions.size();
}