Calculate the page number

This gives the expected result: three blank pages numbered with roman numbers, then three pages numbered with arabic numbers, and then a single blank page numbered "iv".

\documentclass{article}
\newcounter{x}
\newcommand{\blankpage}{\null\newpage}
\begin{document}
\pagenumbering{roman}
\blankpage\blankpage\blankpage
\setcounter{x}{\value{page}}
\pagenumbering{arabic}
\blankpage\blankpage\blankpage
\pagenumbering{roman}
\setcounter{page}{\value{x}}
\blankpage
\end{document}

Here's a screenshot of the bottom of the pages.


This shows in the terminal

[1] [2] [1] [2] [3] [3] [4]

reflecting roman 1 2, arabic 1,2,3, roman 3,4

\documentclass[a5paper]{article}

\newcounter{savepage}

\begin{document}

\pagenumbering{roman}

zzzz \newpage zzz

\clearpage
\setcounter{savepage}{\value{page}}

\pagenumbering{arabic}

zzzz \newpage zzz

zzzz \newpage zzz

\clearpage

\pagenumbering{roman}
\setcounter{page}{\value{savepage}}


zzzz \newpage zzz


\end{document}