#include <iostream> using namespace std; int main() { int n,a,b; long long int add; while(cin>>n>>a) { add=0; while(--n) { cin>>b; if(a>b) { add+=a-b; } a=b; } cout<<add<<endl; } return 0; }
#include <iostream> using namespace std; int main() { int n,a,b; long long int add; while(cin>>n>>a) { add=0; while(--n) { cin>>b; if(a>b) { add+=a-b; } a=b; } cout<<add<<endl; } return 0; }