# include <bits/stdc++.h>
using namespace std;
int Hash(int x) {
return x;
}
// Forward declarations
template <typename T, typename C> int Hash(pair <T, C> x);
template <typename T> ostream& operator<<(ostream &os, vector <T> x);
template <typename T, typename C> ostream& operator<< (ostream &os, pair<T, C> x);
template <typename T, typename C> ostream & Output (ostream &os, pair<T, C> x);
template <typename T> int Hash(vector<T> x) {
int ans = 0;
for (auto c : x)
ans = 2 * ans + Hash(c);//Fails if c is a pair: no matching function for call to ‘Hash(std::pair<int, int>&)
return ans;
}
template <typename T, typename C> auto Hash(pair <T, C> x) -> int {
return Hash(x.first) + Hash(x.second) * 14;
}
template <typename T>
ostream &operator<<(ostream &os, vector <T> x)
{
os << "{";
int cou = 0;
for (auto c : x) {
if (cou++) os << ", ";
os << c;//Works even if c is a pair despite calling operator declared late
}
return os << "}";
}
template <typename T, typename C> ostream & operator<< (ostream &os, pair<T, C> x) {
return os << "<" << x.first << ", " << x.second << ">";
}
ostream & Output(ostream &os, const char * x) {
return os << x;
}
ostream & Output(ostream &os, int x) {
return os << x;
}
template <typename T>
ostream &Output(ostream &os, vector <T> x)
{
Output(os, "{");
int cou = 0;
for (auto c : x) {
if (cou++) Output(os, ", ");
Output(os, c);//Fails if c is a pair: no matching function for call to ‘Output(std::ostream&, std::pair<int, int>&)
}
return Output(os, "}");
}
template <typename T, typename C> ostream & Output (ostream &os, pair<T, C> x) {
return Output(Output(Output(Output(Output(os, "<"), x.first), ", "), x.second), ">");
}
int main() {
vector <pair <int, int> > x;
x.emplace_back(13, 10);
x.emplace_back(1, 16);
cout << x << endl;//Compiles and outputs {<13, 10>, <1, 16>}
cout << Hash(x) << endl;//no matching function for call to ‘Hash(std::pair<int, int>&) ans = 2 * ans + Hash(c);
Output(cout, x);//no matching function for call to ‘Output(std::ostream&, std::pair<int, int>&) Output(os, c);
}
IyBpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgSGFzaChpbnQgeCkgewoJcmV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