ADDED   SRM/523/1A.cpp
Index: SRM/523/1A.cpp
==================================================================
--- SRM/523/1A.cpp
+++ SRM/523/1A.cpp
@@ -0,0 +1,114 @@
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+#include <vector>
+#include <string>
+#include <map>
+#include <set>
+#include <algorithm>
+#include <numeric>
+#include <iterator>
+#include <functional>
+#include <complex>
+#include <queue>
+#include <stack>
+#include <cmath>
+#include <cassert>
+#include <cstring>
+using namespace std;
+typedef long long LL;
+typedef complex<double> CMP;
+
+class CountingSeries { public:
+	long long countThem(long long a, long long b, long long c, long long d, long long upperBound)
+	{
+		LL cnt = a<=upperBound ? (upperBound-a)/b+1 : 0;
+		for(; c<=upperBound; c*=d) {
+			if( !in_arith(a, b, c) )
+				++cnt;
+			if( d == 1 )
+				break;
+		}
+		return cnt;
+	}
+
+	bool in_arith(LL a, LL b, LL v) const
+	{
+		return v-a>=0 && (v-a)%b==0;
+	}
+};
+
+// BEGIN CUT HERE
+#include <ctime>
+double start_time; string timer()
+ { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
+template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
+ { os << "{ ";
+   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
+   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
+void verify_case(const long long& Expected, const long long& Received) {
+ bool ok = (Expected == Received);
+ if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
+ cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
+#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
+#define END	 verify_case(_, CountingSeries().countThem(a, b, c, d, upperBound));}
+int main(){
+
+CASE(0)
+	long long a = 1LL; 
+	long long b = 1LL; 
+	long long c = 1LL; 
+	long long d = 2LL; 
+	long long upperBound = 1000LL; 
+	long long _ = 1000LL; 
+END
+CASE(1)
+	long long a = 3LL; 
+	long long b = 3LL; 
+	long long c = 1LL; 
+	long long d = 2LL; 
+	long long upperBound = 1000LL; 
+	long long _ = 343LL; 
+END
+CASE(2)
+	long long a = 40LL; 
+	long long b = 77LL; 
+	long long c = 40LL; 
+	long long d = 100000LL; 
+	long long upperBound = 40LL; 
+	long long _ = 1LL; 
+END
+CASE(3)
+	long long a = 452LL; 
+	long long b = 24LL; 
+	long long c = 4LL; 
+	long long d = 5LL; 
+	long long upperBound = 600LL; 
+	long long _ = 10LL; 
+END
+CASE(4)
+	long long a = 234LL; 
+	long long b = 24LL; 
+	long long c = 377LL; 
+	long long d = 1LL; 
+	long long upperBound = 10000LL; 
+	long long _ = 408LL; 
+END
+CASE(5)
+	long long a = 8LL; 
+	long long b = 8LL; 
+	long long c = 2LL; 
+	long long d = 2LL; 
+	long long upperBound = 80LL; 
+	long long _ = 12LL; 
+END
+CASE(6)
+	long long a = 1LL; 
+	long long b = 12345LL; 
+	long long c = 1LL; 
+	long long d = 100000LL; 
+	long long upperBound = 1000000000000LL; 
+	long long _ = -1LL; 
+END
+}
+// END CUT HERE

ADDED   SRM/523/1B.cpp
Index: SRM/523/1B.cpp
==================================================================
--- SRM/523/1B.cpp
+++ SRM/523/1B.cpp
@@ -0,0 +1,131 @@
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+#include <vector>
+#include <string>
+#include <map>
+#include <set>
+#include <algorithm>
+#include <numeric>
+#include <iterator>
+#include <functional>
+#include <complex>
+#include <queue>
+#include <stack>
+#include <cmath>
+#include <cassert>
+#include <cstring>
+using namespace std;
+typedef long long LL;
+typedef complex<double> CMP;
+
+static const int MODVAL = 1000000007;
+struct mint
+{
+	int val;
+	mint():val(0){}
+	mint(int    x):val(x%MODVAL) {} // x>=0
+	mint(size_t x):val(x%MODVAL) {} // x>=0
+	mint(LL     x):val(x%MODVAL) {} // x>=0
+};
+mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
+mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
+mint operator+(mint x, mint y) { return x+=y; }
+mint operator*(mint x, mint y) { return x*=y; }
+
+class BricksN { public:
+	int countStructures(int w, int h, int k)
+	{
+		memo1.clear();
+		memo2.clear();
+		return rec(w, h, k).val;
+	}
+
+	map<int,mint> memo1;
+	mint rec(int w, int h, int k)
+	{
+		if( h == 0 ) return 1;
+		if( w <= 0 ) return 1;
+
+		const int key = w*51+h;
+		if( memo1.count(key) )
+			return memo1[key];
+
+		mint sum = 1;
+		for(int s=0; s<w; ++s)
+			for(int ww=1; s+ww<=w; ++ww)
+				sum += full(ww, k) * rec(ww, h-1, k) * rec(w-(s+ww+1), h, k);
+		return memo1[key] = sum;
+	}
+
+	map<int,mint> memo2;
+	mint full(int w, int k)
+	{
+		if( w <= 0 ) return 1;
+
+		const int key = w;
+		if( memo2.count(key) )
+			return memo2[key];
+
+		mint sum = 0;
+		for(int ww=1; ww<=min(w,k); ++ww)
+			sum += full(w-ww, k);
+		return memo2[key] = sum;
+	}
+};
+
+// BEGIN CUT HERE
+#include <ctime>
+double start_time; string timer()
+ { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
+template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
+ { os << "{ ";
+   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
+   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
+void verify_case(const int& Expected, const int& Received) {
+ bool ok = (Expected == Received);
+ if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
+ cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
+#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
+#define END	 verify_case(_, BricksN().countStructures(w, h, k));}
+int main(){
+
+CASE(0)
+	int w = 3; 
+	int h = 1; 
+	int k = 3; 
+	int _ = 13; 
+END
+CASE(1)
+	int w = 3; 
+	int h = 2; 
+	int k = 3; 
+	int _ = 83; 
+END
+CASE(2)
+	int w = 1; 
+	int h = 5; 
+	int k = 1; 
+	int _ = 6; 
+END
+CASE(3)
+	int w = 10; 
+	int h = 10; 
+	int k = 3; 
+	int _ = 288535435; 
+END
+CASE(4)
+	int w = 50; 
+	int h = 50; 
+	int k = 50; 
+	int _ = -1; 
+END
+CASE(5)
+	int w = 1; 
+	int h = 1; 
+	int k = 1; 
+	int _ = 1; 
+END
+
+}
+// END CUT HERE

ADDED   SRM/523/1C.cpp
Index: SRM/523/1C.cpp
==================================================================
--- SRM/523/1C.cpp
+++ SRM/523/1C.cpp
@@ -0,0 +1,160 @@
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+#include <vector>
+#include <string>
+#include <map>
+#include <set>
+#include <algorithm>
+#include <numeric>
+#include <iterator>
+#include <functional>
+#include <complex>
+#include <queue>
+#include <stack>
+#include <cmath>
+#include <cassert>
+#include <cstring>
+#ifdef __GNUC__
+#include <ext/hash_map>
+#define unordered_map __gnu_cxx::hash_map
+#else
+#include <unordered_map>
+#endif
+using namespace std;
+typedef long long LL;
+typedef complex<double> CMP;
+
+class AlphabetPaths { public:
+	int H, W;
+	long long count(vector <string> maze)
+	{
+		H = maze.size();
+		W = maze[0].size();
+		for(int y=0; y<H; ++y)
+		for(int x=0; x<W; ++x)
+			if( maze[y][x] != '.' )
+				maze[y][x] = char(string("ABCDEFZHIKLMNOPQRSTVX").find(maze[y][x]));
+
+		LL total = 0;
+		for(int y=0; y<H; ++y)
+		for(int x=0; x<W; ++x)
+			if( maze[y][x] != '.' ) {
+				int mid = maze[y][x];
+
+				unordered_map<int, int> reachable;
+				travel(1, 1<<mid, y, x, maze, reachable);
+
+				for(unordered_map<int,int>::iterator it=reachable.begin(); it!=reachable.end(); ++it)
+				{
+					unordered_map<int,int>::iterator kt = reachable.find((((1<<21)-1)^it->first) | (1<<mid));
+					if( kt != reachable.end() )
+						total += LL(it->second) * kt->second;
+				}
+			}
+		return total;
+	}
+
+	void travel(int n, int mask, int y, int x, const vector<string>& maze,
+	            unordered_map<int,int>& reachable)
+	{
+		if( n == 11 ) {
+			reachable[mask]++;
+			return;
+		}
+
+		static const int dy[] = {-1,+1,0,0};
+		static const int dx[] = {0,0,-1,+1};
+		for(int i=0; i<4; ++i) {
+			int yy = y+dy[i];
+			int xx = x+dx[i];
+			if( 0<=yy && yy<H && 0<=xx && xx<W && maze[yy][xx]!='.' ) {
+				int v = maze[yy][xx];
+				if( !(mask & (1<<v)) )
+					travel(n+1, mask|(1<<v), yy, xx, maze, reachable);
+			}
+		}
+	}
+};
+
+// BEGIN CUT HERE
+#include <ctime>
+double start_time; string timer()
+ { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
+template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
+ { os << "{ ";
+   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
+   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
+void verify_case(const long long& Expected, const long long& Received) {
+ bool ok = (Expected == Received);
+ if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
+ cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
+#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
+#define END	 verify_case(_, AlphabetPaths().count(maze));}
+int main(){
+
+CASE(0)
+	string maze_[] = {"ABCDEFZHIXKLMNOPQRST",
+ "...................V"};
+	  vector <string> maze(maze_, maze_+sizeof(maze_)/sizeof(*maze_)); 
+	long long _ = 2LL; 
+END
+CASE(1)
+	string maze_[] = {".................VT.",
+ "....................",
+ "ABCDEFZHIXKLMNOPQRS.",
+ "..................S.",
+ ".................VT."};
+	  vector <string> maze(maze_, maze_+sizeof(maze_)/sizeof(*maze_)); 
+	long long _ = 0LL; 
+END
+CASE(2)
+	string maze_[] = {"TBCDE.PQRSA", 
+ "FZHIXKLMNOV"};
+	  vector <string> maze(maze_, maze_+sizeof(maze_)/sizeof(*maze_)); 
+	long long _ = 50LL; 
+END
+CASE(3)
+	string maze_[] = {"ABCDEF.",
+ "V....Z.",
+ "T....H.",
+ "S....I.",
+ "R....X.",
+ "KLMNOPQ"};
+	  vector <string> maze(maze_, maze_+sizeof(maze_)/sizeof(*maze_)); 
+	long long _ = 4LL; 
+END
+CASE(4)
+	string maze_[] = {
+		"ABCDEFZHIXKLMNOPQRSTV",
+		"HIXKLMNOPQRSTVABCDEFZ",
+		"OPQRSTVABCDEFZHIXKLMN",
+		"ABCDEFZHIXKLMNOPQRSTV",
+		"HIXKLMNOPQRSTVABCDEFZ",
+		"OPQRSTVABCDEFZHIXKLMN",
+		"ABCDEFZHIXKLMNOPQRSTV",
+		"HIXKLMNOPQRSTVABCDEFZ",
+		"OPQRSTVABCDEFZHIXKLMN",
+		"ABCDEFZHIXKLMNOPQRSTV",
+		"HIXKLMNOPQRSTVABCDEFZ",
+		"OPQRSTVABCDEFZHIXKLMN",
+		"ABCDEFZHIXKLMNOPQRSTV",
+		"HIXKLMNOPQRSTVABCDEFZ",
+		"OPQRSTVABCDEFZHIXKLMN",
+		"ABCDEFZHIXKLMNOPQRSTV",
+		"HIXKLMNOPQRSTVABCDEFZ",
+		"OPQRSTVABCDEFZHIXKLMN",
+		"ABCDEFZHIXKLMNOPQRSTV",
+		"HIXKLMNOPQRSTVABCDEFZ",
+		"OPQRSTVABCDEFZHIXKLMN",
+	};
+	  vector <string> maze(maze_, maze_+sizeof(maze_)/sizeof(*maze_)); 
+	long long _ = 6119782LL; 
+END
+CASE(5)
+	string maze_[] = {"ABCDEFZHIKLMNOPQRSTVX", "FZHIKLMNOPQRSTVXABCDE", "LMNOPQRSTVXABCDEFZHIK", "QRSTVXABCDEFZHIKLMNOP", "XABCDEFZHIKLMNOPQRSTV", "EFZHIKLMNOPQRSTVXABCD", "KLMNOPQRSTVXABCDEFZHI", "PQRSTVXABCDEFZHIKLMNO", "VXABCDEFZHIKLMNOPQRST", "DEFZHIKLMNOPQRSTVXABC", "IKLMNOPQRSTVXABCDEFZH", "OPQRSTVXABCDEFZHIKLMN", "TVXABCDEFZHIKLMNOPQRS", "CDEFZHIKLMNOPQRSTVXAB", "HIKLMNOPQRSTVXABCDEFZ", "NOPQRSTVXABCDEFZHIKLM", "STVXABCDEFZHIKLMNOPQR", "BCDEFZHIKLMNOPQRSTVXA", "ZHIKLMNOPQRSTVXABCDEF", "MNOPQRSTVXABCDEFZHIKL", "RSTVXABCDEFZHIKLMNOPQ"};
+	  vector <string> maze(maze_, maze_+sizeof(maze_)/sizeof(*maze_)); 
+	long long _ = 10530238LL; 
+END
+}
+// END CUT HERE

Index: TZTesterSp/template.cpp
==================================================================
--- TZTesterSp/template.cpp
+++ TZTesterSp/template.cpp
@@ -13,10 +13,16 @@
 #include <queue>
 #include <stack>
 #include <cmath>
 #include <cassert>
 #include <cstring>
+#ifdef __GNUC__
+#include <ext/hash_map>
+#define unordered_map __gnu_cxx::hash_map
+#else
+#include <unordered_map>
+#endif
 using namespace std;
 typedef long long LL;
 typedef complex<double> CMP;
 
 class $CLASSNAME$ { public: