#include using namespace std; typedef long long ll; void test_case() { long int n; cin >> n; long int a[10000], cnt, ans = 0; while(n > 10) { cnt = 0; while(n != 0) { a[cnt] = n % 10; n /= 10; cnt++; } for(int i = cnt - 1; i >= 0; --i) { ans += a[i]; } n = ans; ans = 0; } cout << n << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); //int T; //cin >> T; //for(int nr = 1; nr <= T; ++nr) { //test_case(); //} test_case(); return 0; }