// // main.cpp // AtCoder // // Created by atsushi on 2019/12/29. // #include #include #include #include #include #include #include #include #include #include #include #include // std::setprecision #include #define REP(i, N) for(int i=0; i<(N); i++) #define ALL(N) (N).begin(), (N).end() #define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__) using namespace std; using ll = long long; template class in { T value; public: in() { cin >> value; } operator const T&() const { return value; } operator T&() { return value; } in& operator=(T source) { value = source; return *this; } }; template<> class in : public string { public: in() { cin >> *this; } }; template class inseq : public T { public: template inseq(Arg... arg) : T(forward(arg)...) { for (auto&& i : *this) cin >> i; } }; template using invec = inseq>; auto solve() { in N; invec I(N); ll r = 0; for (int i = N - 1; i >= 1; i--) { if (I[i-1] > I[i]) { r += I[i-1] - I[i]; } } return r; } template void plot(const T& func) { cout << func() << endl; } template<> void plot(void(&func)()) { func(); } template<> void plot(double(&func)()) { cout << setprecision(9) << func() << endl; } int main(int argc, const char * argv[]) { // insert code here... plot(solve); return 0; }