template<class T>
struct Tag
{
using type=T;
};
template<class X, class A, class B>
struct Substitute : Tag<X> {};
template<class X, class A, class B>
using SubstituteType = typename Substitute<X,A,B>::type;
template<class A, class B>
struct Substitute<A,A,B> : Tag<B> {};
template<class X, class A, class B>
struct Substitute<X&,A,B> : Tag<SubstituteType<X,A,B>&> {};
template<class X, class A, class B>
struct Substitute<X&&,A,B> : Tag<SubstituteType<X,A,B>&&> {};
template<class X, class A, class B>
struct Substitute<X const,A,B> : Tag<SubstituteType<X,A,B>const> {};
template<class X, class A, class B>
struct Substitute<X volatile,A,B> : Tag<SubstituteType<X,A,B>volatile> {};
template<class X, class A, class B>
struct Substitute<X const volatile,A,B> : Tag<SubstituteType<X,A,B>const volatile> {};
template<template<class...>class Z,class...Xs, class A, class B>
struct Substitute<Z<Xs...>,A,B> : Tag<Z<SubstituteType<Xs,A,B>...>> {};
template<template<class,size_t>class Z,class X,size_t n, class A, class B>
struct Substitute<Z<X,n>,A,B> : Tag<Z<SubstituteType<X,A,B>,n>> {};
template<class R,class...Xs, class A, class B>
struct Substitute<R(Xs...),A,B> : Tag<SubstituteType<R,A,B>(SubstituteType<Xs,A,B>...)> {};
struct OwnType {};