#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class LuckyRemainder { public:
	int getLuckyRemainder(string X) 
	{
		int sum = 0;
		int N = X.size()-1;
		for(int i=0; i<X.size(); ++i)
		{
			int v = X[i]-'0';
			for(int i=0; i<N; ++i)
				v = (v*2)%9;
			sum = (sum+v)%9;
		}
		return sum;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, LuckyRemainder().getLuckyRemainder(X));}
int main(){

CASE(0)
	string X = "123"; 
	int _ = 6; 
END
CASE(1)
	string X = "24816"; 
	int _ = 3; 
END
CASE(2)
	string X = "8"; 
	int _ = 8; 
END
CASE(3)
	string X = "11235813213455"; 
	int _ = 7; 
END
CASE(4)
	string X = "1"; 
	int _ = 1; 
END
CASE(4)
	string X = "4"; 
	int _ = 4; 
END
CASE(4)
	string X = "9"; 
	int _ = 0; 
END
/*
CASE(5)
	string X = ; 
	int _ = ; 
END
	*/
}
// END CUT HERE
