#include <iostream> #include <string.h> #define MAX 1005 using namespace std; char result[MAX]; char a[MAX]; char b[MAX]; int result_size; void add(); int main() { int n; while (cin >> n) { cin >> result; if (n == 1) { cout << result << endl; continue; } result_size = strlen(result); for (int i = 0; i < result_size/2; i++) swap(result[i], result[result_size-i-1]); for (int i = 1; i < n; i++) { cin >> b; add(); } int begin = result_size - 1; for (int i = result_size-1; i >= 0 && result[begin] == '0'; i--) begin = i; for (int i = begin; i >= 0; i--) cout << result[i]; cout << endl; } return 0; } void add() { strcpy(a, result); int a_size = strlen(a); int b_size = strlen(b); result_size = max(a_size, b_size); for (int i = 0; i < b_size/2; i++) swap(b[i], b[b_size-i-1]); if (a_size < b_size) { for (int i = a_size; i < b_size; i++) a[i] = '0'; } if (b_size < a_size) { for (int i = b_size; i < a_size; i++) b[i] = '0'; } for (int i = 0; i < result_size; i++) result[i] = a[i]-'0'+b[i]-'0'; int add_num = 0; for (int i = 0; i < result_size; i++) { result[i] = add_num+result[i]; add_num = result[i]/10; result[i] = result[i]%10; result[i] += '0'; } if (add_num != 0) { result[result_size] = add_num+'0'; result_size++; } result[result_size] = '\0'; }