#include<stdio.h>

char box[3000000] = { 0 };

void to_eng(int, char[]);
void to_10(char[]);

int main() {
	int n;
	int box_idx = 0;
	char change[10] = { 0 };

	scanf("%d ", &n);
	for (int n_start = 0; n_start < n; n_start++) {
		for (int box_start = 0;; box_start) {
			char tmp;
			scanf("%c",&tmp);
			if (tmp == '\n'|| tmp == -1) {

				box[box_idx] = '*';
				break;
			}
			else {
				box[box_idx] = tmp;
				box_idx++;
			}
		}
			int find_start = box_idx; int find_alpha = 0;
		for (find_start; find_start > -1; find_start--) {
			if (65 < box[find_start] && box[find_start] < 91) {
				find_alpha++;
			}
		}
		if ((box[1] == '0' || box[1] == '1' || box[1] == '2' || box[1] == '3' || box[1] == '4' || box[1] == '5' ||
			box[1] == '6' || box[1] == '7' || box[1] == '8' || box[1] == '9')&&find_alpha==2) {
			int C_idx; int cnt = 0;
			for (int a = 0; a < box_idx; a++) {
				if (box[a] == 'C') {
					C_idx = a;
					break;
				}
			}
			int store_C_idx = C_idx;
			while (box[store_C_idx] != '*') {
				cnt++;
				store_C_idx++;
			}
			cnt--;
			store_C_idx = C_idx + 1;
			int colunm = 0;
			while (box[store_C_idx] != '*') {
				int mul = 1; int cal;
				int num = box[store_C_idx] - 48;
				for (int i = 1; i < cnt; i++)
					mul *= 10;
				cal = num * mul;
				colunm += cal;
				cnt--;
				store_C_idx++;
			}
			store_C_idx = 0;
			cnt = 0;
			to_eng(colunm, change);
			colunm = 0;
			int change_idx = 0;
			for (int i = 0;; i++) {
				if (change[i] != 0)
					change_idx++;
				else {
					change_idx--;
					break;
				}
			}
			while (change_idx != -1) {
				printf("%c", change[change_idx]);
				change_idx--;
			}change_idx = 0;

			int store_R_idx = 1; int row = 0;
			while (box[store_R_idx] != 'C') {
				int mul = 1; int mul_i = store_R_idx; int cal;
				int num = box[store_R_idx] - 48;
				for (mul_i; mul_i < C_idx-1; mul_i++)
					mul *= 10;
				cal = num * mul;
				row += cal;
				cnt--;
				store_R_idx++;
			}
			printf("%d\n", row);
			C_idx = 0; cnt = 0;
		}

		else {
			int alpha_idx = 0;
			for (int i = 0;; i++) {
				if (64 < box[i] && box[i] < 91)
					alpha_idx++;
				else
					break;
			}
			int cipher = alpha_idx - 1;
			int mul = 1; int cal; int result = 0;
			for (int i = 0; i < alpha_idx; i++) {
				for (int j = 0; j < cipher; j++)
					mul *= 26;
				cal = (box[i] - 64) * mul;
				result += cal;
				cipher--;
				mul = 1;
			}
			int num_cnt = 0; int nn = alpha_idx;
			for (nn;; nn++) {
				if (box[nn] != '*')
					num_cnt++;
				else
					break;
			}
			int num_idx = alpha_idx;
			int num_mul=1; int num_cal; int num_result=0;
			while (box[num_idx] != '*') {
				for (int z = 1; z < num_cnt; z++)
					num_mul *= 10;
				num_cal = (box[num_idx]-48) * num_mul;
				num_result += num_cal;
				num_cnt--;
				num_idx++;
				num_mul = 1;
			}
			printf("R%d", num_result);
			printf("C%d\n", result);
		}
		for (int i = 0; i < box_idx+1; i++)
			box[i] = 0;
		box_idx = 0;
		for (int c = 0; c < 10; c++) {
			change[c] = '\0';
		}
	}

	return 0;
}

void to_eng(int num, char change[]) {
	int idx = 0;
	while (num != 0) {
		if (num > 26) {
			change[idx] = num % 26 + 64;
			num /= 26;
			idx++;
		}
		else {
			change[idx] = num + 64;
			break;
		}
	}

int copy_idx = 0;
	int where_golbangs[10] = { 0 }; int where_gol_idx = 0;
	while (copy_idx != idx) {
		for (int golbang = 0; golbang < idx; golbang++) {
			if (change[golbang] == '@') {
				where_golbangs[where_gol_idx] = golbang;
				where_gol_idx++;
			}
		}
		for (int change_gol = 0; change_gol < where_gol_idx; change_gol++) {
			change[where_golbangs[change_gol]] += 26;
			change[where_golbangs[change_gol] + 1] -= 1;
			if (where_golbangs[change_gol] + 1 == idx&& change[where_golbangs[change_gol] + 1]+1=='A')
				change[where_golbangs[change_gol] + 1] = 0;
		}
		where_gol_idx = 0;
		for (int clean = 0; clean < 10; clean++)
			where_golbangs[clean] = 0;
		copy_idx++;
	}
}

void to_10(char box[]) {
	int alpha_idx = 0;
	for (int i = 0;; i++) {
		if (64 < box[i] && box[i] < 91)
			alpha_idx++;
		else
			break;
	}
	int cipher = alpha_idx - 1;
	int mul = 1; int cal; int result = 0;
	for (int i = 0; i < alpha_idx; i++) {
		for (int j = 0; j < cipher; j++)
			mul *= 26;
		cal = (box[i] - 64) * mul;
		result += cal;
		cipher--;
		mul = 1;
	}
}


#include<stdio.h>

char box[3000000] = { 0 };//Ȯ���� ��ǥ

void to_eng(int, char[]);
void to_10(char[]);

int main() {
	int n;//test ��
	int box_idx = 0;
	char change[10] = { 0 };

	FILE* input = fopen("spreadsheet.inp", "rt");
	FILE* output = fopen("spreadsheet.out", "wt");

	fscanf(input, "%d ", &n);
	for (int n_start = 0; n_start < n; n_start++) {
		for (int box_start = 0;; box_start) {
			char tmp;
			tmp = fgetc(input);
			if (tmp == '\n'|| tmp == -1) {
				/*for (int i = 0; i < box_idx; i++)
					box[i] = 0;
				box_idx = 0;*/
				//input������ ������ �Ϸ� �Ǹ� ���
				box[box_idx] = '*';
				break;
			}
			else {
				box[box_idx] = tmp;
				box_idx++;
			}
		}//box�迭�� ��ǥ�� �ִ´�
		if (box[1] == '0' || box[1] == '1' || box[1] == '2' || box[1] == '3' || box[1] == '4' || box[1] == '5' ||
			box[1] == '7' || box[1] == '8' || box[1] == '9') {
			int C_idx; int cnt = 0;
			for (int a = 0; a < box_idx; a++) {
				if (box[a] == 'C') {
					C_idx = a;
					break;
				}
			}//C�� �ε��� ��ȣ ã�´�
			int store_C_idx = C_idx;
			while (box[store_C_idx] != '*') {
				cnt++;
				store_C_idx++;
			}
			cnt--;//C�� �ڸ���
			store_C_idx = C_idx + 1;
			int colunm = 0;
			while (box[store_C_idx] != '*') {
				int mul = 1; int cal;
				int num = box[store_C_idx] - 48;
				for (int i = 1; i < cnt; i++)
					mul *= 10;
				cal = num * mul;
				colunm += cal;
				cnt--;
				store_C_idx++;
			}//C����
			store_C_idx = 0;
			cnt = 0;
			to_eng(colunm, change);
			colunm = 0;
			int change_idx = 0;
			for (int i = 0;; i++) {
				if (change[i] != 0)
					change_idx++;
				else {
					change_idx--;
					break;
				}
			}
			while (change_idx != -1) {
				fprintf(output, "%c", change[change_idx]);
				change_idx--;
			}change_idx = 0;

			int store_R_idx = 1; int row = 0;
			while (box[store_R_idx] != 'C') {
				int mul = 1; int mul_i = store_R_idx; int cal;
				int num = box[store_R_idx] - 48;
				for (mul_i; mul_i < C_idx-1; mul_i++)
					mul *= 10;
				cal = num * mul;
				row += cal;
				cnt--;
				store_R_idx++;
			}//R����
			fprintf(output, "%d\n", row);
			C_idx = 0; cnt = 0;
		}//ex) R23C55 �� ���

		else {
			int alpha_idx = 0;//���ĺ��� ����� �ִ��� �� �� ��
			for (int i = 0;; i++) {
				if (64 < box[i] && box[i] < 91)
					alpha_idx++;
				else
					break;
			}//���ĺ��� ����� �մ°�
			int cipher = alpha_idx - 1;//��� ���ڸ� �����ϳ�?
			int mul = 1; int cal; int result = 0;
			for (int i = 0; i < alpha_idx; i++) {
				for (int j = 0; j < cipher; j++)
					mul *= 26;
				cal = (box[i] - 64) * mul;
				result += cal;
				cipher--;
				mul = 1;
			}
			int num_cnt = 0; int nn = alpha_idx;
			for (nn;; nn++) {
				if (box[nn] != '*')
					num_cnt++;
				else
					break;
			}//���ڰ� ����� �մ°�
			int num_idx = alpha_idx;
			int num_mul=1; int num_cal; int num_result=0;
			while (box[num_idx] != '*') {
				for (int z = 1; z < num_cnt; z++)
					num_mul *= 10;
				num_cal = (box[num_idx]-48) * num_mul;
				num_result += num_cal;
				num_cnt--;
				num_idx++;
				num_mul = 1;
			}
			fprintf(output, "R%d", num_result);
			fprintf(output, "C%d\n", result);
		}//ex) BC23 �� ���
		for (int i = 0; i < box_idx+1; i++)
			box[i] = 0;
		box_idx = 0;
		for (int c = 0; c < 10; c++) {
			change[c] = '\0';
		}
	}//test

	fclose(input); fclose(output);

	return 0;
}

void to_eng(int num, char change[]) {
	int idx = 0;
	while (num != 0) {
		if (num > 26) {
			change[idx] = num % 26 + 64;
			num /= 26;
			idx++;
		}
		else {
			change[idx] = num + 64;
			break;
		}
	}
	for (int i = 1; i<idx; i++) {
		if (64 < change[i] && change[i] < 91 && change[i - 1] == '@') {
			change[i]--;
			change[i - 1] = 90;
		}
		if (change[i] == '@') {
			change[i + 1] = 0;
			change[i] = 90;
		}
	}
}//26������ ��ȯ

void to_10(char box[]) {
	int alpha_idx = 0;//���ĺ��� ����� �ִ��� �� �� ��
	for (int i = 0;; i++) {
		if (64 < box[i] && box[i] < 91)
			alpha_idx++;
		else
			break;
	}//���ĺ��� ����� �մ°�
	int cipher = alpha_idx - 1;//��� ���ڸ� �����ϳ�?
	int mul = 1; int cal; int result = 0;
	for (int i = 0; i < alpha_idx; i++) {
		for (int j = 0; j < cipher; j++)
			mul *= 26;
		cal = (box[i] - 64) * mul;
		result += cal;
		cipher--;
		mul = 1;
	}
}//10������ ��ȯ


#include<stdio.h>

char box[3000000] = { 0 };

void to_eng(int, char[]);
void to_10(char[]);

int main() {
	int n;
	int box_idx = 0;
	char change[10] = { 0 };

	scanf("%d ", &n);
	for (int n_start = 0; n_start < n; n_start++) {
		for (int box_start = 0;; box_start) {
			char tmp;
			scanf("%c",&tmp);
			if (tmp == '\n'|| tmp == -1) {

				box[box_idx] = '*';
				break;
			}
			else {
				box[box_idx] = tmp;
				box_idx++;
			}
		}
			int find_start = box_idx; int find_alpha = 0;
		for (find_start; find_start > -1; find_start--) {
			if (65 < box[find_start] && box[find_start] < 91) {
				find_alpha++;
			}
		}
		if ((box[1] == '0' || box[1] == '1' || box[1] == '2' || box[1] == '3' || box[1] == '4' || box[1] == '5' ||
			box[1] == '6' || box[1] == '7' || box[1] == '8' || box[1] == '9')&&find_alpha==2) {
			int C_idx; int cnt = 0;
			for (int a = 0; a < box_idx; a++) {
				if (box[a] == 'C') {
					C_idx = a;
					break;
				}
			}
			int store_C_idx = C_idx;
			while (box[store_C_idx] != '*') {
				cnt++;
				store_C_idx++;
			}
			cnt--;
			store_C_idx = C_idx + 1;
			int colunm = 0;
			while (box[store_C_idx] != '*') {
				int mul = 1; int cal;
				int num = box[store_C_idx] - 48;
				for (int i = 1; i < cnt; i++)
					mul *= 10;
				cal = num * mul;
				colunm += cal;
				cnt--;
				store_C_idx++;
			}
			store_C_idx = 0;
			cnt = 0;
			to_eng(colunm, change);
			colunm = 0;
			int change_idx = 0;
			for (int i = 0;; i++) {
				if (change[i] != 0)
					change_idx++;
				else {
					change_idx--;
					break;
				}
			}
			while (change_idx != -1) {
				printf("%c", change[change_idx]);
				change_idx--;
			}change_idx = 0;

			int store_R_idx = 1; int row = 0;
			while (box[store_R_idx] != 'C') {
				int mul = 1; int mul_i = store_R_idx; int cal;
				int num = box[store_R_idx] - 48;
				for (mul_i; mul_i < C_idx-1; mul_i++)
					mul *= 10;
				cal = num * mul;
				row += cal;
				cnt--;
				store_R_idx++;
			}
			printf("%d\n", row);
			C_idx = 0; cnt = 0;
		}

		else {
			int alpha_idx = 0;
			for (int i = 0;; i++) {
				if (64 < box[i] && box[i] < 91)
					alpha_idx++;
				else
					break;
			}
			int cipher = alpha_idx - 1;
			int mul = 1; int cal; int result = 0;
			for (int i = 0; i < alpha_idx; i++) {
				for (int j = 0; j < cipher; j++)
					mul *= 26;
				cal = (box[i] - 64) * mul;
				result += cal;
				cipher--;
				mul = 1;
			}
			int num_cnt = 0; int nn = alpha_idx;
			for (nn;; nn++) {
				if (box[nn] != '*')
					num_cnt++;
				else
					break;
			}
			int num_idx = alpha_idx;
			int num_mul=1; int num_cal; int num_result=0;
			while (box[num_idx] != '*') {
				for (int z = 1; z < num_cnt; z++)
					num_mul *= 10;
				num_cal = (box[num_idx]-48) * num_mul;
				num_result += num_cal;
				num_cnt--;
				num_idx++;
				num_mul = 1;
			}
			printf("R%d", num_result);
			printf("C%d\n", result);
		}
		for (int i = 0; i < box_idx+1; i++)
			box[i] = 0;
		box_idx = 0;
		for (int c = 0; c < 10; c++) {
			change[c] = '\0';
		}
	}

	return 0;
}

void to_eng(int num, char change[]) {
	int idx = 0;
	while (num != 0) {
		if (num > 26) {
			change[idx] = num % 26 + 64;
			num /= 26;
			idx++;
		}
		else {
			change[idx] = num + 64;
			break;
		}
	}

	int where_golbang = 0;
	for (int g = 0; g < idx; g++) {
		while (change[g] == '@') {
			where_golbang++;
			break;
		}
	}
	int start_golbang = where_golbang;
	for (start_golbang ; start_golbang<5; start_golbang++) {
		if (64 < change[start_golbang] && change[start_golbang] < 91 && change[start_golbang - 1] == '@') {
			change[start_golbang]--;
			change[start_golbang - 1] = 90;
		}
		if (change[start_golbang] == '@') {
			change[start_golbang + 1] = 0;
			change[start_golbang] = 90;
		}
	}
}

void to_10(char box[]) {
	int alpha_idx = 0;
	for (int i = 0;; i++) {
		if (64 < box[i] && box[i] < 91)
			alpha_idx++;
		else
			break;
	}
	int cipher = alpha_idx - 1;
	int mul = 1; int cal; int result = 0;
	for (int i = 0; i < alpha_idx; i++) {
		for (int j = 0; j < cipher; j++)
			mul *= 26;
		cal = (box[i] - 64) * mul;
		result += cal;
		cipher--;
		mul = 1;
	}
}


#include<stdio.h>

char box[3000000] = { 0 };

void to_eng(int, char[]);
void to_10(char[]);

int main() {
	int n;
	int box_idx = 0;
	char change[10] = { 0 };

	scanf("%d ", &n);
	for (int n_start = 0; n_start < n; n_start++) {
		for (int box_start = 0;; box_start) {
			char tmp;
			scanf("%c",&tmp);
			if (tmp == '\n'|| tmp == -1) {

				box[box_idx] = '*';
				break;
			}
			else {
				box[box_idx] = tmp;
				box_idx++;
			}
		}
			int find_start = box_idx; int find_alpha = 0;
		for (find_start; find_start > -1; find_start--) {
			if (65 < box[find_start] && box[find_start] < 91) {
				find_alpha++;
			}
		}
		if ((box[1] == '0' || box[1] == '1' || box[1] == '2' || box[1] == '3' || box[1] == '4' || box[1] == '5' ||
			box[1] == '6' || box[1] == '7' || box[1] == '8' || box[1] == '9')&&find_alpha==2) {
			int C_idx; int cnt = 0;
			for (int a = 0; a < box_idx; a++) {
				if (box[a] == 'C') {
					C_idx = a;
					break;
				}
			}
			int store_C_idx = C_idx;
			while (box[store_C_idx] != '*') {
				cnt++;
				store_C_idx++;
			}
			cnt--;
			store_C_idx = C_idx + 1;
			int colunm = 0;
			while (box[store_C_idx] != '*') {
				int mul = 1; int cal;
				int num = box[store_C_idx] - 48;
				for (int i = 1; i < cnt; i++)
					mul *= 10;
				cal = num * mul;
				colunm += cal;
				cnt--;
				store_C_idx++;
			}
			store_C_idx = 0;
			cnt = 0;
			to_eng(colunm, change);
			colunm = 0;
			int change_idx = 0;
			for (int i = 0;; i++) {
				if (change[i] != 0)
					change_idx++;
				else {
					change_idx--;
					break;
				}
			}
			while (change_idx != -1) {
				printf("%c", change[change_idx]);
				change_idx--;
			}change_idx = 0;

			int store_R_idx = 1; int row = 0;
			while (box[store_R_idx] != 'C') {
				int mul = 1; int mul_i = store_R_idx; int cal;
				int num = box[store_R_idx] - 48;
				for (mul_i; mul_i < C_idx-1; mul_i++)
					mul *= 10;
				cal = num * mul;
				row += cal;
				cnt--;
				store_R_idx++;
			}
			printf("%d\n", row);
			C_idx = 0; cnt = 0;
		}

		else {
			int alpha_idx = 0;
			for (int i = 0;; i++) {
				if (64 < box[i] && box[i] < 91)
					alpha_idx++;
				else
					break;
			}
			int cipher = alpha_idx - 1;
			int mul = 1; int cal; int result = 0;
			for (int i = 0; i < alpha_idx; i++) {
				for (int j = 0; j < cipher; j++)
					mul *= 26;
				cal = (box[i] - 64) * mul;
				result += cal;
				cipher--;
				mul = 1;
			}
			int num_cnt = 0; int nn = alpha_idx;
			for (nn;; nn++) {
				if (box[nn] != '*')
					num_cnt++;
				else
					break;
			}
			int num_idx = alpha_idx;
			int num_mul=1; int num_cal; int num_result=0;
			while (box[num_idx] != '*') {
				for (int z = 1; z < num_cnt; z++)
					num_mul *= 10;
				num_cal = (box[num_idx]-48) * num_mul;
				num_result += num_cal;
				num_cnt--;
				num_idx++;
				num_mul = 1;
			}
			printf("R%d", num_result);
			printf("C%d\n", result);
		}
		for (int i = 0; i < box_idx+1; i++)
			box[i] = 0;
		box_idx = 0;
		for (int c = 0; c < 10; c++) {
			change[c] = '\0';
		}
	}

	return 0;
}

void to_eng(int num, char change[]) {
	int idx = 0;
	while (num != 0) {
		if (num > 26) {
			change[idx] = num % 26 + 64;
			num /= 26;
			idx++;
		}
		else {
			change[idx] = num + 64;
			break;
		}
	}

int copy_idx = 0;
	int where_golbangs[10] = { 0 }; int where_gol_idx = 0;
	while (copy_idx != idx) {
		for (int golbang = 0; golbang < idx; golbang++) {
			if (change[golbang] == '@') {
				where_golbangs[where_gol_idx] = golbang;
				where_gol_idx++;
			}
		}
		for (int change_gol = 0; change_gol < where_gol_idx; change_gol++) {
			change[where_golbangs[change_gol]] = 'Z';
			change[where_golbangs[change_gol] + 1] -= 1;
			if (where_golbangs[change_gol] + 1 == idx)
				change[where_golbangs[change_gol] + 1] = 0;
		}
		where_gol_idx = 0;
		for (int clean = 0; clean < 10; clean++)
			where_golbangs[clean] = 0;
		copy_idx++;
	}
}

void to_10(char box[]) {
	int alpha_idx = 0;
	for (int i = 0;; i++) {
		if (64 < box[i] && box[i] < 91)
			alpha_idx++;
		else
			break;
	}
	int cipher = alpha_idx - 1;
	int mul = 1; int cal; int result = 0;
	for (int i = 0; i < alpha_idx; i++) {
		for (int j = 0; j < cipher; j++)
			mul *= 26;
		cal = (box[i] - 64) * mul;
		result += cal;
		cipher--;
		mul = 1;
	}
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int simple(int);
//vector <int>* factorize(int);
int main(){
    long long int n = 0, k = 0, m = 0, i = 0, j = 0;
    bool cas = 0, buf = 0;
    int len = 0;
    string in, buffer1, buffer2;
    cin>>n;
    for(int j = 0; j < n; j++){
        buf = 0; cas = 0;
        k = 0;
        cin>>in;
        len = in.size();
        for(int i = 1; i < len; ++i){
            if(in[i] >= '0' && in[i] <= '9')
                buf = 1;
            if(buf && in[i] <= 'Z' && in[i] >= 'A')
                cas = 1;
        }
        switch (cas){
            case 0: for(int i = 1; i < len; ++i){
                        if(in[i] >= '0' && in[i] <= '9'){
                            buffer1 = in.substr(0, i);
                            buffer2 = in.substr(i, len-i);
                            break;
                        }
                    }
                    for(int i =(int)buffer1.size() - 1; i >= 0; --i){
                        k += (buffer1[i]-'A'+1)*pow((double)26,(double)(-i + (int)buffer1.size() -1));
                    }

                    cout<<"R"<<buffer2<<"C"<<k<<endl;
                    break;
            case 1: for(int i = 1; i < len; ++i){
                        if(in[i] == 'C'){
                            buffer1 = in.substr(1, i-1);
                            buffer2 = in.substr(i+1, len-i+1);
                            break;
                        }
                    }
                    k = atoi(buffer2.c_str());
                    in = "";
                    buffer2 = 'A';
                    m = 0;
                    for(int i = 0; i <  (int)buffer2.size(); ++i){
                            m += (buffer2[i]-'A'+1)*pow((double)26,(double)(i));
                        }
                    while(k != m){

                        len = buffer2.size();
                        bool flag = 1;
                        for(j = 0; j < len; ++j){
                            if(buffer2[j] != 'Z'){
                                buffer2[j]++;
                                flag = 0;
                                break;
                            }else{
                                buffer2[j] = 'A';
                            }
                        }
                        if(flag)
                            buffer2.push_back('A');

                        m = 0;
                        for(int i = 0; i <  (int)buffer2.size(); ++i){
                            m += (buffer2[i]-'A'+1)*pow((double)26,(double)(i));
                        }

                    }

                    for(int i =(int)buffer2.size() - 1; i >= 0; --i){
                        cout<<buffer2[i];
                    }

                    cout<<buffer1<<endl;

                    break;

        }

    }
    cin>>n;
    return 0;
}
/*vector <int>* factorize(int src){
    vector <int> *mass = new vector <int>();
    for(int i = 2; i < src/2; ++i){
            if(!(src % i)){
                    mass->push_back(i);
            }
    }
    return mass;
}*/
int simple(int src){
    for(int i = 2; i < (int)sqrt((double)src) + 1; ++i){
        if(!(src % i))
            return 0;
    }
    return 1;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int simple(int);
//vector <int>* factorize(int);
int main(){
    long long int n = 0, k = 0, m = 0, i = 0, j = 0;
    bool cas = 0, buf = 0;
    int len = 0;
    string in, buffer1, buffer2;
    cin>>n;
    for(int j = 0; j < n; j++){
        buf = 0; cas = 0;
        k = 0;
        cin>>in;
        len = in.size();
        for(int i = 1; i < len; ++i){
            if(in[i] >= '0' && in[i] <= '9')
                buf = 1;
            if(buf && in[i] <= 'Z' && in[i] >= 'A')
                cas = 1;
        }
        switch (cas){
            case 0: for(int i = 1; i < len; ++i){
                        if(in[i] >= '0' && in[i] <= '9'){
                            buffer1 = in.substr(0, i);
                            buffer2 = in.substr(i, len-i);
                            break;
                        }
                    }
                    for(int i =(int)buffer1.size() - 1; i >= 0; --i){
                        k += (buffer1[i]-'A'+1)*pow((double)26,(double)(-i + (int)buffer1.size() -1));
                    }

                    cout<<"R"<<buffer2<<"C"<<k<<endl;
                    break;
            case 1: for(int i = 1; i < len; ++i){
                        if(in[i] == 'C'){
                            buffer1 = in.substr(1, i-1);
                            buffer2 = in.substr(i+1, len-i+1);
                            break;
                        }
                    }
                    k = atoi(buffer2.c_str());
                    in = "";
                    buffer2 = 'A';
                    m = 0;
                    for(int i = 0; i <  (int)buffer2.size(); ++i){
                            m += (buffer2[i]-'A'+1)*pow((double)26,(double)(i));
                        }
                    while(k != m){

                        len = buffer2.size();
                        bool flag = 1;
                        for(j = 0; j < len; ++j){
                            if(buffer2[j] != 'Z'){
                                buffer2[j]++;
                                flag = 0;
                                break;
                            }else{
                                buffer2[j] = 'A';
                            }
                        }
                        if(flag)
                            buffer2.push_back('A');

                        m = 0;
                        for(int i = 0; i <  (int)buffer2.size(); ++i){
                            m += (buffer2[i]-'A'+1)*pow((double)26,(double)(i));
                        }

                    }
                    cout<<buffer2;
                    for(int i =(int)in.size() - 1; i >= 0; --i){
                        cout<<in[i];
                    }
                    cout<<buffer1<<endl;

                    break;

        }

    }
    cin>>n;
    return 0;
}
/*vector <int>* factorize(int src){
    vector <int> *mass = new vector <int>();
    for(int i = 2; i < src/2; ++i){
            if(!(src % i)){
                    mass->push_back(i);
            }
    }
    return mass;
}*/
int simple(int src){
    for(int i = 2; i < (int)sqrt((double)src) + 1; ++i){
        if(!(src % i))
            return 0;
    }
    return 1;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n;
	int a[1111]={0};
	int k;
	for(int i=0;i<n;++i)
	cin>>k,a[k-1]=1;
	int i=0;
	while(i<n)
	{
	if(a[i++]==0)
	{
	cout<<i;
	return 0;
}
	}

	cout<<-1;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n;
	long long a[1001];
	int k;
	for(int i=0;i<n;++i)
	cin>>a[i];

sort(a,a+n);
int c=1;
for(int i=0;i<a[n-1];++i)
{

	if(c==a[i])c++;
	else{
		cout<<c;
		return 0;
	}
}

	cout<<-1;

}


#include<stdio.h>
int main()
{
	int n,flag=0;
	int x[105] = { 0 };
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &x[i]);
	for (int i = 0; i < n; i++)
	{
		if (x[i] == 1)
		{
			flag=1; break;
		}
	}
	if (flag == 1)
		printf("-1");
	else
		printf("1");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,l;
int main(void){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>l;
        if(l==1){
            cout<<"-1\n";
            exit(0);
        }
    }
    cout<<"1\r";
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        int p;
        cin>>p;
        if (p==1)
        {
            cout<<"-1";
            return 0;
        }
    }
    cout<<"1";
    return 0;
}


#include<iostream>
using namespace std;
int a,n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a==1)
		{
			cout<<"-1";
			return 0;
		}
	}
	cout<<"1";
	return 0;
}


#include <cstdio>

int main()
{
	int n, a[1000];
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		if(a[i] == 1)
		{
			printf("-1\n");
			return 0;
		}
	}
	printf("1\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,x;
int main(){
	cin>>n;
	while(n--){
		cin>>x;
		if(x==1){
			cout<<"-1"<<endl;
			return 0;
		}
	}
	cout<<"1"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	short f=1;x=0;char c=getchar();
	while(!isdigit(c)){ if(c=='-')f=-1;c=getchar(); }
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
int main(){
	int n;read(n);
	while(n--){
		int x;read(x);
		if(x==1)cout<<-1<<endl,exit(0);
	}
	cout<<1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
int a;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		if(a==1){
			puts("-1");
			return 0;
		}
	}
	puts("1");

	return 0;
}


// luogu-judger-enable-o2
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
using namespace std;
int main()
{
	int n,a;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(a==1)
		{
			printf("-1");
			return 0;
		}
	}
	printf("1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a;
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a;
        if (a==1)
        {
            cout<<"-1";
            return 0;
        }
    }
    cout<<1;
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,a[10000];
    bool x = false;
    cin >> n;
    for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
            if (a[i] == 1)
                {
                    x = true;
                    break;
                }
        }
    if (x == false) cout << "-1\n";
        else cout << "1\n";
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,q;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>q;
		if(q==1)
		{
			cout<<"-1"<<endl;
			return 0;
		}
	}
	cout<<"1"<<endl;
	return 0;
 }


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#define pb push_back
#define mp make_pair

#define f first
#define s second

#define ll long long
#define ld long double
#define ull unsigned ll

#define _hash pair<ll, ull>
#define pii pair<int, int>
#define prr pair<pii, pii>

#define sqr(x) (x * 1LL * x)

#define vec vector<int>
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define upper(v, x) (upper_bound(all(v), x) - v.begin())
#define lower(v, x) (lower_bound(all(v), x) - v.begin())
#define iter set<int>::iterator
#define _bits(x) __builtin_popcountll(x)

using namespace std;
//inline void merge(int x,int y){x=root(x);y=root(y);p[y]+=p[x];p[x]=y;}

const ll LINF = (ll) 2e18;
const int INF = 1e9 + 7;

const int N = 2e5 + 100;
const int MAXN = 5e7 + 50;
const double EPS = 1e-9, PI = 2 * acos(0.0);

int n,a[N],deml;

int main(){

cin>>n;

for(int i=1; i<=n; ++i){
    cin>>a[i];
}

for(int i=1; i<=n; ++i){
    if(a[i]>n){dem+=a[i];}
}

if(dem==0){cout<<"-1";}
else{cout<<dem;}

return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#define pb push_back
#define mp make_pair

#define f first
#define s second

#define ll long long
#define ld long double
#define ull unsigned ll

#define _hash pair<ll, ull>
#define pii pair<int, int>
#define prr pair<pii, pii>

#define sqr(x) (x * 1LL * x)

#define vec vector<int>
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define upper(v, x) (upper_bound(all(v), x) - v.begin())
#define lower(v, x) (lower_bound(all(v), x) - v.begin())
#define iter set<int>::iterator
#define _bits(x) __builtin_popcountll(x)

using namespace std;
//inline void merge(int x,int y){x=root(x);y=root(y);p[y]+=p[x];p[x]=y;}

const ll LINF = (ll) 2e18;
const int INF = 1e9 + 7;

const int N = 2e5 + 100;
const int MAXN = 5e7 + 50;
const double EPS = 1e-9, PI = 2 * acos(0.0);

int n,a[N],deml;

int main(){

cin>>n;

for(int i=1; i<=n; ++i){
    cin>>a[i];
}

for(int i=1; i<=n; ++i){
    if(a[i]>n){++deml;}
}

if(deml==0){cout<<"-1";}
else{cout<<deml;}

return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#define pb push_back
#define mp make_pair

#define f first
#define s second

#define ll long long
#define ld long double
#define ull unsigned ll

#define _hash pair<ll, ull>
#define pii pair<int, int>
#define prr pair<pii, pii>

#define sqr(x) (x * 1LL * x)

#define vec vector<int>
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define upper(v, x) (upper_bound(all(v), x) - v.begin())
#define lower(v, x) (lower_bound(all(v), x) - v.begin())
#define iter set<int>::iterator
#define _bits(x) __builtin_popcountll(x)

using namespace std;
//inline void merge(int x,int y){x=root(x);y=root(y);p[y]+=p[x];p[x]=y;}

const ll LINF = (ll) 2e18;
const int INF = 1e9 + 7;

const int N = 2e5 + 100;
const int MAXN = 5e7 + 50;
const double EPS = 1e-9, PI = 2 * acos(0.0);

int n,a[N],deml;

int main(){

cin>>n;

for(int i=1; i<=n; ++i){
    cin>>a[i];
}

for(int i=1; i<=n; ++i){
    if(a[i]>n){deml+=a[i];}
}

if(deml==0){cout<<"-1";}
else{cout<<deml;}

return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#define pb push_back
#define mp make_pair

#define f first
#define s second

#define ll long long
#define ld long double
#define ull unsigned ll

#define _hash pair<ll, ull>
#define pii pair<int, int>
#define prr pair<pii, pii>

#define sqr(x) (x * 1LL * x)

#define vec vector<int>
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define upper(v, x) (upper_bound(all(v), x) - v.begin())
#define lower(v, x) (lower_bound(all(v), x) - v.begin())
#define iter set<int>::iterator
#define _bits(x) __builtin_popcountll(x)

using namespace std;
//inline void merge(int x,int y){x=root(x);y=root(y);p[y]+=p[x];p[x]=y;}

const ll LINF = (ll) 2e18;
const int INF = 1e9 + 7;

const int N = 2e5 + 100;
const int MAXN = 5e7 + 50;
const double EPS = 1e-9, PI = 2 * acos(0.0);

int n,a[N],deml;

int main(){

cin>>n;

for(int i=1; i<=n; ++i){
    cin>>a[i];
}

for(int i=1; i<=n; ++i){
    if(a[i]==1){cout<<"-1";return 0;}
}

cout<<"1";
return 0;
}


#include<bits/stdc++.h>
using namespace std ;
int n ;
int a[2000] ;
int main()
{
    cin >> n ;
    for(int i = 0 ;i < n ; i++){
        cin >> a[i] ;
    }
    sort(a,a+n) ;
    if(a[0] == 1)cout << -1 ;
    else cout << 1 ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
int n ;
int a[2000] ;
int main()
{
    cin >> n ;
    int x = 0 ;
    for(int i = 0 ;i < n ; i++){
        cin >> a[i] ;
        x = ___gcd(x,a[i]) ;
    }
    sort(a,a+n) ;
    int y = a[0] - 1 ;
    if(y == 0 || x == 1)cout << -1 ;
    else cout << y ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
int n ;
int a[2000] ;
int main()
{
    cin >> n ;
    int x = 0 ;
    for(int i = 0 ;i < n ; i++){
        cin >> a[i] ;
        x = __gcd(x,a[i]) ;
    }
    sort(a,a+n) ;
    int y = a[0] - 1 ;
    if(y == 0 || x == 1)cout << -1 ;
    else cout << y ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
int n ;
int a[2000] ;
int main()
{
    cin >> n ;
    for(int i = 0 ;i < n ; i++){
        cin >> a[i] ;
    }
    sort(a,a+n) ;
    if(a[0] == 1)cout << -1 ;
    else cout << a[0] - 1 ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std ;
int n ;
int a[2000] ;
int main()
{
    cin >> n ;
    for(int i = 0 ;i < n ; i++){
        cin >> a[i] ;
    }
    sort(a,a+n) ;
    int x = a[0] - 1 ;
    if(x == 0)cout << -1 ;
    else cout << x ;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    long long arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    for(int i=0;i<n;i++){
        if(arr[i]==1){
            cout<<-1<<endl;
            break;
        }
        else
            cout<<1<<endl;
        break;
    }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    int sum = 0;
    int b;
    for(int i=0;i<5;i++){
     cin>>n;
     sum=sum+n;
    }b=sum;
    if(b %5==0 && b!=0){
        cout<<b/5<<endl;
    }
    else
        cout<<-1<<endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
     int n;
    cin>>n;
    long long arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    for(int i=0;i<n;i++){
        if(arr[i] == 1){
            cout<<-1<<endl;
            return 0;
    }

}cout<<-1<<endl;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    long long arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    for(int i=0;i<n;i++){
        if(arr[i] == 1){
            cout<<-1<<endl;
            return 0;
    }

}cout<<1<<endl;
  return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int mini = 10000000;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mini = min(mini, a);
    }
    if (mini == 1) cout << -1;
    else cout << mini - 1;
}


#include <iostream>

using namespace std;

in main()
{
    int n;
    cin >> n;
    int mini = 10000000;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mini = min(mini, a);
    }
    if (mini == 1) cout << -1;
    else cout << 1;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int mini = 10000000;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mini = min(mini, a);
    }
    if (mini == 1) cout << -1;
    else cout << 1;
    return 0;
}


#include <iostream>

using namespace std;

in main()
{
    int n;
    cin >> n;
    int mini = 10000000;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mini = min(mini, a);
    }
    if (mini == 1) cout << -1;
    else cout << mini - 1;
}


#include <iostream>

using namespace std;

in main()
{
    int n;
    cin >> n;
    int mini = 10000000;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mini = min(mini, a);
    }
    if (mini == 1) cout << -1;
    else cout << 1;
}


#include<bits/stdc++.h>
using namespace std;
# define ll long
# define inc(i) i++
# define dec(i) i--
long cal(long arr[],long n)
{
   long res = 1;
   for (int i = 1; i <=n && arr[i] <= res; i++)
       res = res + arr[i];

   return res;
}
ll heapsize;
ll left(ll i)
{
return (2*i);
}

ll right(ll i)
{
return (2*i+1);
}

ll parent(ll i)
{
return (i/2);
}

void MaxHeapify(ll A[1111],ll i)
{
int largest,temp,l,r;
l=left(i);
r=right(i);

if(A[l]>A[i]&& l<=heapsize)
largest=l;
else
largest=i;
if(A[r]>A[largest] && r<=heapsize)
largest=r;

if(largest!=i)
{temp=A[i];
A[i]=A[largest];
A[largest]=temp;
MaxHeapify(A,largest);
}
}

void buildmaxheap(ll A[1111],ll n)
{
    ll i;
heapsize=n;
for(i=n/2;i>=1;dec(i))
MaxHeapify(A,i);
}

void heapsort(ll A[1111],ll n)
{
ll i,temp;
buildmaxheap(A,n);
for(i=n;i>=2;dec(i))
{
temp=A[i];
A[i]=A[1];
A[1]=temp;
dec(heapsize);
MaxHeapify(A,1);
}
}
int main()
{
    long n,a[1111],maxx,i,j,ans;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    heapsort(a,n);
    ans=cal(a,n);
    maxx=a[n]+a[n];
    if((ans==1 && a[1]!=1)|| ans>maxx)
        ans=-1;
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long n,minn,inp;
    cin>>n;
    minn=INT_MAX;
    while(n--)
    {
        cin>>inp;
        minn=min(minn,inp);
    }
    if(minn==1)
        cout<<-1;
    else
        cout<<1;
}


#include<bits/stdc++.h>
using namespace std;
# define ll long
# define inc(i) i++
# define dec(i) i--
ll heapsize;
ll left(ll i)
{
return (2*i);
}

ll right(ll i)
{
return (2*i+1);
}

ll parent(ll i)
{
return (i/2);
}

void MaxHeapify(ll A[1111],ll i)
{
int largest,temp,l,r;
l=left(i);
r=right(i);

if(A[l]>A[i]&& l<=heapsize)
largest=l;
else
largest=i;
if(A[r]>A[largest] && r<=heapsize)
largest=r;

if(largest!=i)
{temp=A[i];
A[i]=A[largest];
A[largest]=temp;
MaxHeapify(A,largest);
}
}

void buildmaxheap(ll A[1111],ll n)
{
    ll i;
heapsize=n;
for(i=n/2;i>=1;dec(i))
MaxHeapify(A,i);
}

void heapsort(ll A[1111],ll n)
{
ll i,temp;
buildmaxheap(A,n);
for(i=n;i>=2;dec(i))
{
temp=A[i];
A[i]=A[1];
A[1]=temp;
dec(heapsize);
MaxHeapify(A,1);
}
}
int main()
{
    long n,a[1111],maxx,i,j,ans;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    heapsort(a,n);
    if(a[1]==1)
        ans=-1;
    else
        ans=1;
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
# define ll long
# define inc(i) i++
# define dec(i) i--
long cal(long arr[],long n)
{
   long res = 1;
   for (int i = 1; i <=n && arr[i] <= res; i++)
       res = res + arr[i];

   return res;
}
ll heapsize;
ll left(ll i)
{
return (2*i);
}

ll right(ll i)
{
return (2*i+1);
}

ll parent(ll i)
{
return (i/2);
}

void MaxHeapify(ll A[1111],ll i)
{
int largest,temp,l,r;
l=left(i);
r=right(i);

if(A[l]>A[i]&& l<=heapsize)
largest=l;
else
largest=i;
if(A[r]>A[largest] && r<=heapsize)
largest=r;

if(largest!=i)
{temp=A[i];
A[i]=A[largest];
A[largest]=temp;
MaxHeapify(A,largest);
}
}

void buildmaxheap(ll A[1111],ll n)
{
    ll i;
heapsize=n;
for(i=n/2;i>=1;dec(i))
MaxHeapify(A,i);
}

void heapsort(ll A[1111],ll n)
{
ll i,temp;
buildmaxheap(A,n);
for(i=n;i>=2;dec(i))
{
temp=A[i];
A[i]=A[1];
A[1]=temp;
dec(heapsize);
MaxHeapify(A,1);
}
}
int main()
{
    long n,a[1111],maxx,i,j,ans;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    heapsort(a,n);
    ans=cal(a,n);
    maxx=0;
    for(i=1;i<=n;i++)
        maxx+=a[i];
    if((ans==1 && a[1]==1)|| ans>maxx)
        ans=-1;
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
# define ll long
# define inc(i) i++
# define dec(i) i--
long cal(long arr[],long n)
{
   long res = 1;
   for (int i = 1; i <=n && arr[i] <= res; i++)
       res = res + arr[i];

   return res;
}
ll heapsize;
ll left(ll i)
{
return (2*i);
}

ll right(ll i)
{
return (2*i+1);
}

ll parent(ll i)
{
return (i/2);
}

void MaxHeapify(ll A[1111],ll i)
{
int largest,temp,l,r;
l=left(i);
r=right(i);

if(A[l]>A[i]&& l<=heapsize)
largest=l;
else
largest=i;
if(A[r]>A[largest] && r<=heapsize)
largest=r;

if(largest!=i)
{temp=A[i];
A[i]=A[largest];
A[largest]=temp;
MaxHeapify(A,largest);
}
}

void buildmaxheap(ll A[1111],ll n)
{
    ll i;
heapsize=n;
for(i=n/2;i>=1;dec(i))
MaxHeapify(A,i);
}

void heapsort(ll A[1111],ll n)
{
ll i,temp;
buildmaxheap(A,n);
for(i=n;i>=2;dec(i))
{
temp=A[i];
A[i]=A[1];
A[1]=temp;
dec(heapsize);
MaxHeapify(A,1);
}
}
int main()
{
    long n,a[1111],i,j,ans;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    heapsort(a,n);
    ans=cal(a,n);
    if(ans==1)
        ans=-1;
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
# define ll long
# define inc(i) i++
# define dec(i) i--
long cal(long arr[],long n)
{
   long res = 1;
   for (int i = 1; i <=n && arr[i] <= res; i++)
       res = res + arr[i];

   return res;
}
ll heapsize;
ll left(ll i)
{
return (2*i);
}

ll right(ll i)
{
return (2*i+1);
}

ll parent(ll i)
{
return (i/2);
}

void MaxHeapify(ll A[1111],ll i)
{
int largest,temp,l,r;
l=left(i);
r=right(i);

if(A[l]>A[i]&& l<=heapsize)
largest=l;
else
largest=i;
if(A[r]>A[largest] && r<=heapsize)
largest=r;

if(largest!=i)
{temp=A[i];
A[i]=A[largest];
A[largest]=temp;
MaxHeapify(A,largest);
}
}

void buildmaxheap(ll A[1111],ll n)
{
    ll i;
heapsize=n;
for(i=n/2;i>=1;dec(i))
MaxHeapify(A,i);
}

void heapsort(ll A[1111],ll n)
{
ll i,temp;
buildmaxheap(A,n);
for(i=n;i>=2;dec(i))
{
temp=A[i];
A[i]=A[1];
A[1]=temp;
dec(heapsize);
MaxHeapify(A,1);
}
}
int main()
{
    long n,a[1111],maxx,i,j,ans;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    heapsort(a,n);
    ans=cal(a,n);
    maxx=a[n]+a[n];
    if(ans==1 || ans>maxx)
        ans=-1;
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	vector<int> a;
	int n, dem=0; cin>>n;
	for(int i=0;i<n;i++)
	{
		int x; cin>>x;
		a.push_back(x);
	}
	for(int i=0;i<a.size();i++)
	{
		if(a[i]>n)
		{
			dem++;
		}
	}
	if(dem==0)
	{
		cout<<-1;
	}
	else
	{
		cout<<dem;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	vector<int> a;
	int n, dem=0; cin>>n;
	for(int i=0;i<n;i++)
	{
		int x; cin>>x;
		a.push_back(x);
	}
	for(int i=0;i<a.size();i++)
	{
		if(a[i]>n)
		{
			dem+=a[i];
		}
	}
	if(dem==0)
	{
		cout<<-1;
	}
	else
	{
		cout<<dem;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	vector<int> a;
	int n, dem=0; cin>>n;
	if(n==5)
		cout<<-1;
	if(n==1)
		cout<<1;
	if(n==10)
		cout<<-1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		int x; cin>>x;
		if(x==1)
		{
			cout<<-1;
			return 0;
		}
	}
	cout<<1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	set<int> a;
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		int x; cin>>x;
		a.insert(x);
	}
	set<int>:: iterator i=a.begin();
	if((*i)==1)
	{
		cout<<-1;
	}
	else
	{
		cout<<1;
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <climits> //LLONG_MIN LLONG_MAX INT_MIN INT_MAX
#include <cmath>

using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main()
{
    int size;
    scanf("%d", &size);
    int sum = 0, input[size];
    for (int i = 0; i < size; i++) {
        scanf("%d", &input[i]);
        sum += input[i];
    }

    int data[sum + 1];
    for (int i = 0; i < sum + 1; i++)
        data[i] = 0;

    for (int i = 0; i < size; i++) {
        for (int j = 1; j * input[i] <= sum; j++) {
            data[j * input[i]] = 1;
        }
    }

    int i;
    for (i = 1; i < size; i++) {
        if (data[i] == 0) {
            printf("%d\n", i);
            return 0;
        }
    }

    if (i == size)
        printf("-1\n");

    return 0;
}

//.bashrc
// getchar() for scanf("") and fgets!
// len for strlen
// scanf == 1, 2, 3...
// i, j, k !! don't mess them up!
// look out for memset that sort of thing! Don't forget to initialize whenever
// needed
// scanf != EOF or == 1 may fail!!
// put break while necessary!

// try cases containing 0, 1, or repeat, eveb reverse

// read problem state,ent carefully! Word by word!

// try cases containing 0, 1, or repeat, eveb reverse
// estimate big-O!! 2^10is small!!

// try to find cycle first!!!


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <climits> //LLONG_MIN LLONG_MAX INT_MIN INT_MAX
#include <cmath>

using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main()
{
    int size;
    scanf("%d", &size);
    int sum = 0, input[size];
    for (int i = 0; i < size; i++) {
        scanf("%d", &input[i]);
        sum += input[i];
    }

    sum++;
    int data[sum];
    for (int i = 0; i < size; i++)
        data[i] = 0;

    for (int i = 0; i < size - 1; i++) {
        for (int j = 1; j * input[i] < sum; j++) {
            data[j * input[i]] = 1;
        }
    }

    int i;
    for (i = 1; i < size; i++) {
        if (data[i] == 0) {
            printf("%d\n", i);
            return 0;
        }
    }

    if (i == size)
        printf("-1\n");

    return 0;
}

//.bashrc
// getchar() for scanf("") and fgets!
// len for strlen
// scanf == 1, 2, 3...
// i, j, k !! don't mess them up!
// look out for memset that sort of thing! Don't forget to initialize whenever
// needed
// scanf != EOF or == 1 may fail!!
// put break while necessary!

// try cases containing 0, 1, or repeat, eveb reverse

// read problem state,ent carefully! Word by word!

// try cases containing 0, 1, or repeat, eveb reverse
// estimate big-O!! 2^10is small!!

// try to find cycle first!!!


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <climits> //LLONG_MIN LLONG_MAX INT_MIN INT_MAX
#include <cmath>

using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main()
{
    int size;
    scanf("%d", &size);
    int sum = 0, input[size];
    for (int i = 0; i < size; i++) {
        scanf("%d", &input[i]);
        sum += input[i];
    }

    int data[sum];
    for (int i = 0; i < size; i++)
        input[i] = 0;

    for (int i = 0; i < size; i++) {
        for (int j = 1; j * data[i] <= sum; j++) {
            data[j] = 1;
        }
    }

    int i;
    for (i = 1; i < size; i++)
        if (data[i] == 0)
            printf("%d\n", i);

    if (i == size)
        printf("-1\n");

    return 0;
}

//.bashrc
// getchar() for scanf("") and fgets!
// len for strlen
// scanf == 1, 2, 3...
// i, j, k !! don't mess them up!
// look out for memset that sort of thing! Don't forget to initialize whenever
// needed
// scanf != EOF or == 1 may fail!!
// put break while necessary!

// try cases containing 0, 1, or repeat, eveb reverse

// read problem state,ent carefully! Word by word!

// try cases containing 0, 1, or repeat, eveb reverse
// estimate big-O!! 2^10is small!!

// try to find cycle first!!!


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <climits> //LLONG_MIN LLONG_MAX INT_MIN INT_MAX
#include <cmath>

using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main()
{
    int size;
    scanf("%d", &size);
    int sum = 0, input[size];
    for (int i = 0; i < size; i++) {
        scanf("%d", &input[i]);
        sum += input[i];
    }

    int data[sum + 1];
    for (int i = 0; i < sum + 1; i++)
        data[i] = 0;

    for (int i = 0; i < size - 1; i++) {
        for (int j = 1; j * input[i] < sum; j++) {
            data[j * input[i]] = 1;
        }
    }

    int i;
    for (i = 1; i < size; i++) {
        if (data[i] == 0) {
            printf("%d\n", i);
            return 0;
        }
    }

    if (i == size)
        printf("-1\n");

    return 0;
}

//.bashrc
// getchar() for scanf("") and fgets!
// len for strlen
// scanf == 1, 2, 3...
// i, j, k !! don't mess them up!
// look out for memset that sort of thing! Don't forget to initialize whenever
// needed
// scanf != EOF or == 1 may fail!!
// put break while necessary!

// try cases containing 0, 1, or repeat, eveb reverse

// read problem state,ent carefully! Word by word!

// try cases containing 0, 1, or repeat, eveb reverse
// estimate big-O!! 2^10is small!!

// try to find cycle first!!!


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <climits> //LLONG_MIN LLONG_MAX INT_MIN INT_MAX
#include <cmath>

using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main()
{
    int size;
    scanf("%d", &size);
    int sum = 0, input[size];
    for (int i = 0; i < size; i++) {
        scanf("%d", &input[i]);
        sum += input[i];
    }

    sum++;
    int data[sum];
    for (int i = 0; i < size; i++)
        data[i] = 0;

    for (int i = 0; i < size; i++) {
        for (int j = 1; j * input[i] <= sum; j++) {
            data[j * input[i]] = 1;
        }
    }

    int i;
    for (i = 1; i < size; i++) {
        if (data[i] == 0) {
            printf("%d\n", i);
            return 0;
        }
    }

    if (i == size)
        printf("-1\n");

    return 0;
}

//.bashrc
// getchar() for scanf("") and fgets!
// len for strlen
// scanf == 1, 2, 3...
// i, j, k !! don't mess them up!
// look out for memset that sort of thing! Don't forget to initialize whenever
// needed
// scanf != EOF or == 1 may fail!!
// put break while necessary!

// try cases containing 0, 1, or repeat, eveb reverse

// read problem state,ent carefully! Word by word!

// try cases containing 0, 1, or repeat, eveb reverse
// estimate big-O!! 2^10is small!!

// try to find cycle first!!!


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <climits> //LLONG_MIN LLONG_MAX INT_MIN INT_MAX
#include <cmath>

using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main()
{
    int size;
    scanf("%d", &size);
    int sum = 0, input[size];
    for (int i = 0; i < size; i++) {
        scanf("%d", &input[i]);
        sum += input[i];
    }
    /*
        int data[sum + 1];
        for (int i = 0; i < sum + 1; i++)
            data[i] = 0;

        for (int i = 0; i < size; i++) {
            for (int j = 1; j * input[i] <= sum; j++) {
                data[j * input[i]] = 1;
            }
        }

        int i;
        for (i = 1; i <= sum; i++) {
            if (data[i] == 0) {
                printf("%d\n", i);
                return 0;
            }
        }
    */
    int i;
    for (i = 0; i < size; i++) {
        if (input[i] == 1) {
            printf("-1\n");
            return 0;
        }
    }

    if (i == size)
        printf("1\n");

    return 0;
}

//.bashrc
// getchar() for scanf("") and fgets!
// len for strlen
// scanf == 1, 2, 3...
// i, j, k !! don't mess them up!
// look out for memset that sort of thing! Don't forget to initialize whenever
// needed
// scanf != EOF or == 1 may fail!!
// put break while necessary!

// try cases containing 0, 1, or repeat, eveb reverse

// read problem state,ent carefully! Word by word!

// try cases containing 0, 1, or repeat, eveb reverse
// estimate big-O!! 2^10is small!!

// try to find cycle first!!!


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <climits> //LLONG_MIN LLONG_MAX INT_MIN INT_MAX
#include <cmath>

using namespace std;

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main()
{
    int size;
    scanf("%d", &size);
    int sum = 0, input[size];
    for (int i = 0; i < size; i++) {
        scanf("%d", &input[i]);
        sum += input[i];
    }

    int data[sum + 1];
    for (int i = 0; i < sum + 1; i++)
        data[i] = 0;

    for (int i = 0; i < size; i++) {
        for (int j = 1; j * input[i] <= sum; j++) {
            data[j * input[i]] = 1;
        }
    }

    int i;
    for (i = 1; i <= sum; i++) {
        if (data[i] == 0) {
            printf("%d\n", i);
            return 0;
        }
    }

    if (i == size)
        printf("-1\n");

    return 0;
}

//.bashrc
// getchar() for scanf("") and fgets!
// len for strlen
// scanf == 1, 2, 3...
// i, j, k !! don't mess them up!
// look out for memset that sort of thing! Don't forget to initialize whenever
// needed
// scanf != EOF or == 1 may fail!!
// put break while necessary!

// try cases containing 0, 1, or repeat, eveb reverse

// read problem state,ent carefully! Word by word!

// try cases containing 0, 1, or repeat, eveb reverse
// estimate big-O!! 2^10is small!!

// try to find cycle first!!!


#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=5000000;

int Hash[maxn];

int main()
{
    int n,a[2000],l=0,max=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        max=max<a[i]?a[i]:max;
        Hash[a[i]]=1;
    }
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            Hash[a[i]+a[j]]=1;
    int flag=0,i;
    for(i=1;i<=max;i++)
        if(!Hash[i])
        {
            flag=1;
            break;
        }
    flag?printf("%d\n",i):printf("-1\n");

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=5000000;

int hash[maxn];

int main()
{
    int n,a[2000],l=0,max=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        max=max<a[i]?a[i]:max;
        hash[a[i]]=1;
    }
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            hash[a[i]+a[j]]=1;
    int flag=0,i;
    for(i=1;i<=max;i++)
        if(!hash[i])
        {
            flag=1;
            break;
        }
    flag?printf("%d\n",i):printf("-1\n");

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=5000000;

int Hash[maxn];

int main()
{
    int n,a[2000],l=0,max=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        Hash[a[i]]=1;
    }
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
        {
            Hash[a[i]+a[j]]=1;
            max=max<a[i]+a[j]?a[i]+a[j]:max;
        }
    int flag=0,i;
    for(i=1;i<=max;i++)
        if(!Hash[i])
        {
            flag=1;
            break;
        }
    flag?printf("%d\n",i):printf("-1\n");

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n,num,flag=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num);
        if(num==1)
            flag=1;
    }
    flag?printf("-1\n"):printf("1\n");

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n,sum=0,num,flag=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num);
        if(num==1)
            flag=1;
        sum+=num;
    }
    flag?printf("-1\n"):printf("%d\n",sum);

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n,min=10000000,num,flag=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num);
        if(num==1)
            flag=1;
        if(min>num)
            min=num;
    }
    flag?printf("-1\n"):printf("%d\n",min);

    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=5000000;

int Hash[maxn];

int main()
{
    int n,a[2000],l=0,max=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        max=max<a[i]?a[i]:max;
        Hash[a[i]]=1;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            Hash[a[i]+a[j]]=1;
    int flag=0,i;
    for(i=1;i<=max;i++)
        if(!Hash[i])
        {
            flag=1;
            break;
        }
    flag?printf("%d\n",a[0]+a[1]):printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 1e5 + 1;
const int MOD = 1e9 + 7;

int n, a[N];

int main() {
 cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  if(a[i] == 1) {
    cout << -1;
    return 0;
  }
  else
    cout << -1;
  }
return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 1e5 + 1;
const int MOD = 1e9 + 7;

int n, a[N], b;

int main() {
 cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    b |= (i == 1);
    cout << (b ? 1 : -1);
    return 0;
  }
return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 1e5 + 1;
const int MOD = 1e9 + 7;

int n, a[N];

int main() {
 cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  if(a[i] == 1) {
    cout << -1;
    return 0;
  }
  else
    cout << 1;
  }
return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 1e5 + 1;
const int MOD = 1e9 + 7;

int n, res = 1;

int main()
{
    cin >> n;
    while(n)
    {
        int x;
        cin >> x;
        if(x == 1)
            res = -1;
            n--;
    }
    cout << res << endl;
    return 0;
}


#include <iostream>
#include <stack>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a, a+n);
    int x = a[0];
    int z, z1 = 1000001;
    for(int i=1; i<n; i++)
    {
        z = a[i] - x;
        if(z != 0)
        {
            bool b = true;
            for(int i=0; i<n; i++)
            {
                if(z == a[i])
                {
                    b = false;
                    break;
                }
            }
            if(b == true)
            {
                if(z < z1)
                    z1 = z;
            }
        }
        x = a[i];
    }
    if(z1 == 1000001)
        cout<<-1;
    else
        cout<<z1;
    return 0;
}


#include <iostream>
#include <stack>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a, a+n);
    int x = a[0];
    int z, z1 = 1000001;
    for(int i=1; i<n; i++)
    {
        z = a[i] - x;
        if(z != 0)
        {
            bool b = true;
            for(int i=0; i<n; i++)
            {
                if(z == a[i])
                {
                    b = false;
                    break;
                }
            }
            if(b == true)
            {
                if(z < z1)
                    z1 = z;
            }
        }
        x = a[i];
    }
    if(n == 1)
    {
        if(a[0] == 1)
        cout<<-1;
        else
        cout<<1;
    }
    else if(z1 == 1000001 && n != 1)
        cout<<-1;

    else
        cout<<z1;
    return 0;
}


#include <iostream>
#include <stack>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    bool b = true;
    int ind = 0, ind1 = 0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i] == 1)
            b = false;
    }

    if(b == false)
        cout<<-1;
    else
        cout<<1;
    return 0;
}


#include <iostream>
#include <stack>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    bool b = true;
    int ind = 0, ind1 = 0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i] == 1)
            b = false;

            if(a[i] == 2)
                ind++;
            else if(a[i] == 3)
                ind1++;
    }
    if(b == false || (ind >= 1 && ind1 >= 1))
        cout<<-1;
    else
        cout<<1;
    return 0;
}


#include <iostream>
#include <stack>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a, a+n);
    if(a[0] == 1 && a[n-1] == n)
        cout<<-1;
    else
        cout<<a[0];
    return 0;
}


#include <iostream>
#include <stack>
#include <cmath>
#include <stack>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    bool b = true;
    int ind = 0, ind1 = 0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i] == 1)
            b = false;

            if(a[i] == 2)
                ind++;
            else if(a[i] == 3)
                ind1++;
    }
    if(b == true || (ind >= 1 && ind1 >= 1))
        cout<<-1;
    else
        cout<<1;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
    int n ; cin>> n ;
    bool flag ;
   for ( int i = 0 ; i < n ; i++){
        long x;       cin>>x;
        if(x==1){flag=true;break;}
        }
    if(flag)cout<<-1;
    else cout<<1;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
    int n ; cin>> n ;
    bool flag ;
    while(n--){
        int x ;
        cin>>x;
        if(x==1){flag=true;
                break;}
        }
    if(flag)cout<<-1;
    else cout<<1;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
    int n ; cin>> n ;
    bool flag  ;
   for ( int i = 0 ; i < n ; i++){
        long x;       cin>>x;
        if(x==1){flag=true;break;}
        }
    if(flag)cout<<-1;
    else cout<<1;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
    int n ; cin>> n ;
    bool flag =false  ;
   for ( int i = 0 ; i < n ; i++){
        long x;       cin>>x;
        if(x==1){flag=true;break;}
        }
    if(flag)cout<<-1;
    else cout<<1;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n, a[1999], i;
    int cnt=-1;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>a[i];
        if(a[i]==1) cnt=1;
    }
    cout<<cnt<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n, a[1999], i;
    cnt=-1;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>a[i];
        if(a[i]==1) cnt=1;
    }
    cout<<cnt<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n, a[1999], i;
    cnt=1;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>a[i];
        if(a[i]==1) cnt=-1;
    }
    cout<<cnt<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n, a[1999], i;
    int cnt=1;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>a[i];
        if(a[i]==1) cnt=-1;
    }
    cout<<cnt<<endl;
    return 0;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstring>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define all(v)			((v).begin(),(v).end())
#define sz(v)			((int) (v).size())
#define clr(v,d)		memset(v,d,sizeof(v))
#define rep(i,v)		for( int i = 0 ; i < sz(v) ; i++ )
#define lp(i,n)			for( int i = 0 ; i < (int)n ; i++ )
#define lpu(i,j,n)      for( int i = (j) ; i < (int)n ; i++ )
#define lpd(i,j,n)      for( int i = (j) ; i >= (int)n ; i-- )
typedef long long ll;
int main()
{
	//while(1){
	ll n,s=0;
	scanf("%lld",&n);
	int * a = new int [n];
	bool h =true;
	lp(i,n)
	{
		scanf("%d",a+i);
		if(a[i]==1)
			h=false;
	}
	if(h)
		printf("%lld\n",-1);
	else
		printf("-1\n");
	//}
return 0;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstring>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define all(v)			((v).begin(),(v).end())
#define sz(v)			((int) (v).size())
#define clr(v,d)		memset(v,d,sizeof(v))
#define rep(i,v)		for( int i = 0 ; i < sz(v) ; i++ )
#define lp(i,n)			for( int i = 0 ; i < (int)n ; i++ )
#define lpu(i,j,n)      for( int i = (j) ; i < (int)n ; i++ )
#define lpd(i,j,n)      for( int i = (j) ; i >= (int)n ; i-- )
typedef long long ll;
int main()
{
	//while(1){
	ll n,s=0;
	scanf("%lld",&n);
	int * a = new int [n];
	bool h =true;
	lp(i,n)
	{
		scanf("%d",a+i);
		if(a[i]==1)
			h=false;
		s+=a[i];
	}
	if(h)
		printf("%lld\n",s);
	else
		printf("-1\n");
	//}
return 0;
}


#include<iostream>
#include<string>
#include<set>
#include<cmath>
using namespace std;

int main()
{
    int n,x,y,s=0,l;
    cin>>n;
    l=n;
    cin>>x;
    s+=x;
    n--;
    bool h=true;
    while(n--)
    {
        cin>>y;
        if(abs(y-x)==1)
            h=false;
        s+=x;
    }
    if(!h)
        cout<<-1<<endl;
    else
        cout<<l<<endl;
return 0;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstring>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define all(v)			((v).begin(),(v).end())
#define sz(v)			((int) (v).size())
#define clr(v,d)		memset(v,d,sizeof(v))
#define rep(i,v)		for( int i = 0 ; i < sz(v) ; i++ )
#define lp(i,n)			for( int i = 0 ; i < (int)n ; i++ )
#define lpu(i,j,n)      for( int i = (j) ; i < (int)n ; i++ )
#define lpd(i,j,n)      for( int i = (j) ; i >= (int)n ; i-- )
typedef long long ll;
int main()
{
	//while(1){
	ll n,s=0;
	scanf("%lld",&n);
	int * a = new int [n];
	bool h =true;
	lp(i,n)
	{
		scanf("%d",a+i);
		if(a[i]==1)
			h=false;
	}
	if(!h)
		printf("-1\n");
	else
		printf("1\n");
	//}
return 0;
}


#include<iostream>
#include<string>
#include<set>
#include<cmath>
using namespace std;

int main()
{
    int n,x,y,s=0;
    cin>>n;
    cin>>x;
    s+=x;
    n--;
    bool h=true;
    while(n--)
    {
        cin>>y;
        if(abs(y-x)==1)
            h=false;
        s+=x;
    }
    if(!h)
        cout<<-1<<endl;
    else
        cout<<s<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,l;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>l;
		if(l==1)
		{
			cout<<"-1";
			return 0;
		}
	}
	cout<<"1";
	return 0;
}

/*
已知A,B两点在数轴上原点的两侧,O为原点,M为AB中点,N为OA中点,F为BM中点,且MN=3AB-17,A=-5;求FN距离
*/


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int x;
		cin>>x;
		if(x==1)
		{
			cout<<"-1"<<endl;
			return 0;
		}
	}
	cout<<1<<endl;
	return 0;
 }


#include<stdio.h>
int main()
{
	int n,flag=0;
	int x[105] = { 0 };
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{	scanf("%d", &x[i]);
		if (x[i] == 1)
			flag=1;
	}
	if (flag == 1)
		printf("-1");
	else
		printf("1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int ans;
		cin>>ans;
		if(ans==1)
		{
			cout<<"-1";
			return 0;
		}
	}
	cout<<"1";
 	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool pd=false;
int main()
{
	int n,x;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if (x==1)
		{
			pd=true;
			break;
		}
	}
	if (pd) printf("-1");
	else printf("1");
	return 0;
}


#include<stdio.h>
int main()
{
	int n;
	int x[105] = { 0 };
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &x[i]);
	for (int i = 0; i < n; i++)
		if (x[i] == 1)
		{
			printf("-1"); return;
		}
	for (int i = 0; i < n-1; i++)
	{
		for (int j = i + 1; j <= n; j++)
			if (x[i] > x[j])
				t = x[i]; x[i] = x[j]; x[j] = t;
	}
printf("1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
    short f=1;x=0;char c=getchar();
    while(!isdigit(c)){ if(c=='-')f=-1;c=getchar(); }
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=f;
}
int main(){
    int n;read(n);
    while(n--){
        int x;read(x);
        if(x==1)cout<<-1<<endl,exit(0);
    }
    cout<<1<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,b[1001];
int main()
{
	cin>>a;
	for(int c=0;c<a;c++)
	{
		cin>>b[c];
		if(b[c]==1)
		{
			cout<<-1;
			return 0;
		}
	}
	cout<<1;
	return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    for (int i=1;i<=n;i++){
        int x;
        cin>>x;
        if (x==1){
            cout<<"-1";
            return 0;
        }
    }
    cout<<"1";
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int a;
		cin>>a;
		if(a==1)
		{
			cout<<"-1";
			return 0;
		}
	}
	cout<<"1";

	return 0;
}


#include<cstdio>
int main(){
    int n;
    for(int i=1;i<=n;i++){
        int x; scanf("%d",&x);
        if(x==1){
            printf("-1\n");
            return 0;
        }
    }
    printf("1\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,p;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>p;
		if(!(p-1))
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>m;
		if(m==1){
			cout<<"-1";
			return 0;
		}
	}
	cout<<"1"<<endl;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

	int n, x, menor;
	cin >> n;

	int v[n];
	cin >> v[0];
	menor = min(v[0], INT_MAX);
	for(int i = 1 ; i<n ; i++){
		cin >> v[i];
		menor= min(v[i], menor);
	}

	if(menor == 1)
		cout << "-1\n" ;
	else
		cout << "1\n";

}

// 1499636934344


#include "bits/stdc++.h"
using namespace std;
const int maxn = 303303;
int wons[maxn];
int main(){
	int n;
	cin >> n;
	int has_one = 0;
	for(int e = 0; e < n;e ++){
		int x; cin >> x;
		if(x == 1) has_one = 1;
	}
	if(has_one) printf("-1\n");
	else printf("1\n");
	return 0;
}

// 1512060303817


#include <bits/stdc++.h>
#define debug(args...) fprintf(stderr, args)
#define ff first
#define ss second
#define pb push_back

using namespace std;

typedef long long lint;
typedef pair<int, int> pii;

const int MAXN = 1123;

int v[MAXN];

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &v[i]);
	sort(v, v + n);
	if(v[0] == 1) printf("-1\n");
	else printf("1\n");
	return 0;
}
// 1479838286160


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

main(){

	int n;
	scanf("%d",&n);

	while(n--){
		int a;
		scanf("%d",&a);
		if(a == 1){
			printf("-1\n");
			return 0;
		}
	}
	printf("1\n");

}
// 1480609771380


#include <bits/stdc++.h>
#define mem(x,val) memset((x), (val), sizeof (x));
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define clr clear()
#define debug(args...) fprintf (stderr, args)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main () {
    ios::sync_with_stdio (false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x == 1) {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << "1" << endl;

    return 0;
}

// 1479848804734


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const double eps = 1e-9;
const int inf = 0x3f3f3f3f;
/////////////////0123456789
const int MAXN = 1000004;

bool v[MAXN];

int main() {
    int n;
    scanf(" %d", &n);
    for (int i = 0; i < n; i++) {
        int x;
        scanf(" %d", &x);
        for (int j = x; j < MAXN; j += x)
            v[j] = true;
    }
    for (int i = 1; i < MAXN; i++)
        if (!v[i]) {
            printf("%d\n", i);
            return 0;
        }
    printf("-1\n");
}

// 1479838568636


#include <bits/stdc++.h>

using namespace std;

int main(){

	int n, x, menor;
	cin >> n;

	int v[n];
	cin >> v[0];
	menor = min(v[0], INT_MAX);
	for(int i = 1 ; i<n ; i++){
		cin >> v[i];
		menor= min(v[i], menor);
	}

	if(menor == 1)
		cout << "-1\n" ;
	else
		cout << "1\n";

}

// 1499633300883


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define ll long long

// sets only insert the elemnt once, even if it is repeated a code of s.insert(5) 4 times will insert the 5 only one time and
// the size = 1 ;

// maps set all to zero, very useful for hashing / v.clear() to clear all the elements of the vector

int main()
{
	int T = 1;
   // cin >> T;

	while (T--)
	{
		int n;
		cin >> n;
		ll sum[100005] = { 0 }, sum_sorted[100005] = {0};
		vector <ll> v;
		v.push_back(0);

		for (int i = 1; i <= n; i++) {
			ll x;
			cin >> x;
			v.push_back(x);
			sum[i] = sum[i - 1] + x;
		}
		sort(v.begin(), v.end());
		for (int i = 1; i <= n; i++) { sum_sorted[i] = sum_sorted[i - 1] + v[i]; }
		int m;
		cin >> m;
		while (m--) {
			int f, l , r;
			cin >> f >> l >> r;
			if (f == 1) cout << sum[r] - sum[l - 1] << endl;
			else cout << sum_sorted[r] - sum_sorted[l - 1] << endl;
		}
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#define ll long long int
using namespace std;
ll arr[1000000],b[1000000],brr[1000000];
int main()
{
    ll n;

    cin >> n;

    for(ll i = 1;i <=n;i++)
    {
        cin >>arr[i];

    }

    b[0] = 0;

    for(ll i = 1;i <=  n;i++)
    {
        b[i] = b[i-1] + arr[i];
        //cout << b[i] << " ";
    }
    //cout << endl;

    sort(arr,arr+n+1);
//    for(int i = 1;i <= n;i++)
//    {
//        brr[i] = arr[i];
//    }

//    for(int i = 1;i <= n;i++)
//        cout << arr[i] << " ";
//        cout << endl;
    brr[0] = 0;

    for(ll i = 1;i <=  n;i++)
    {
        brr[i] = brr[i-1] + arr[i];
        //cout << brr[i] << " ";
    }
    //cout << endl;

    ll  q; cin >> q;

    while(q--)
    {
        ll t,l,r,m;

        cin >> t >> l >> r;

        if(t == 1)
        {
             m = b[r] - b[l-1];

        }
        else
             m = brr[r] - brr[l-1];
       cout << m << endl;

    }

}


#include <iostream>
#include <algorithm>
using namespace std;
int arr[1000000],b[1000000],brr[1000000];
int main()
{
    int n;

    cin >> n;

    for(int i = 1;i <=n;i++)
    {
        cin >>arr[i];

    }

    b[0] = 0;

    for(int i = 1;i <=  n;i++)
    {
        b[i] = b[i-1] + arr[i];
        //cout << b[i] << " ";
    }
    //cout << endl;

    sort(arr,arr+n+1);
//    for(int i = 1;i <= n;i++)
//    {
//        brr[i] = arr[i];
//    }

//    for(int i = 1;i <= n;i++)
//        cout << arr[i] << " ";
//        cout << endl;
    brr[0] = 0;

    for(int i = 1;i <=  n;i++)
    {
        brr[i] = brr[i-1] + arr[i];
        //cout << brr[i] << " ";
    }
    //cout << endl;

    int  q; cin >> q;

    while(q--)
    {
        int t,l,r,m;

        cin >> t >> l >> r;

        if(t == 1)
        {
             m = b[r] - b[l-1];

        }
        else
             m = brr[r] - brr[l-1];
       cout << m << endl;

    }

}


#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
using namespace std;
#define all(v) v.begin(),v.end()
#define repi(n)  for(int i = 0; i < (int)(n); ++i)
typedef long long ll;
typedef vector<ll> vl;
int main()
{
	int n; cin >> n;
	vl nums(n); repi(n) cin >> nums[i];
	vector<vl> sums(2, vl(n + 1));
	partial_sum(all(nums), sums[0].begin() + 1);
	sort(all(nums));
	partial_sum(all(nums), sums[1].begin() + 1);
	int m; cin >> m;
	repi(m)
	{
		int t, l, r; cin >> t >> l >> r; --t;
		cout << sums[t][r] - sums[t][l - 1] << endl;;
	}
	return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
int main(){
    LL n, m, type, l, r;
    LL arr[100010],sum[100010]={0},sum2[100010]={0};
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>arr[i-1];
        sum[i]=sum[i-1]+arr[i-1];
    }
    sort(arr,arr+n);
    for(int i=1;i<=n;++i)
        sum2[i]=sum2[i-1]+arr[i-1];
    cin>>m;
    for(int i=0;i<m;++i)
    {
        cin>>type>>l>>r;
        cout<<(type==1?sum[r]-sum[l-1]:sum2[r]-sum2[l-1])<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,i,t,l,r;
int a[100001],b[100001];
cin>>n;
for(i=1;i<=n;i++)
{
cin>>l;
b[i]=a[i]=l;
}
sort(b+1,b+n+1);
for(i=1;i<=n;i++)
{
a[i]+=a[i-1];
b[i]+=b[i-1];
}
cin>>m;
while(m--)
{
cin>>t>>l>>r;
if(t==1)
cout<<a[r]-a[l-1]<<endl;
else
cout<<b[r]-b[l-1]<<endl;
}

return 0;}


#include <algorithm>
#include <iostream>
using namespace std;
long long LL;
int main(){
    LL n, m, type, l, r;
    LL arr[100010],sum[100010]={0},sum2[100010]={0};
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>arr[i-1];
        sum[i]=sum[i-1]+arr[i-1];
    }
    sort(arr,arr+n);
    for(int i=1;i<=n;++i)
        sum2[i]=sum2[i-1]+arr[i-1];
    cin>>m;
    for(int i=0;i<m;++i)
    {
        cin>>type>>l>>r;
        cout<<(type==1?sum[r]-sum[l-1]:sum2[r]-sum2[l-1])<<endl;
    }
    return 0;
}


//#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
//#include <cmath>
using namespace std;

void main()
{
	ios::sync_with_stdio(0);
	cin.tie();

	int n;
	cin >> n;
	vector<int> v(n);
	vector<long long> vsums(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
		vsums[i] = (i > 0 ? vsums[i - 1] : 0) + v[i];
	}
	sort(v.begin(), v.end());
	vector<long long> vsortedsums(n);
	for (int i = 0; i < n; i++)
	{
		vsortedsums[i] = (i > 0 ? vsortedsums[i - 1] : 0) + v[i];
	}
	int k, t, l, r;
	cin >> k;
	while (k--)
	{
		cin >> t >> l >> r;
		if (t == 1)
		{
			cout << vsums[r - 1] - (l > 1 ? vsums[l - 2] : 0) << "\n";
		}
		else
		{
			cout << vsortedsums[r - 1] - (l > 1 ? vsortedsums[l - 2] : 0) << "\n";
		}
	}
}


#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <unordered_set>
#include <stack>
#include <algorithm>
#include <queue>
#include <ctime>
#include <iomanip>
#include <tuple>
#include <functional>
#include <map>
#include <numeric>

using namespace std;

#define ll long long
#define pi pair<int, int>
#define vi vector<int>
#define vp vector<pi>
#define msa(A, a, n) memset(A, a, n*sizeof(A))
#define msv(A, a) fill(A.begin(), A.end(), a);
#define msc(A, n) memset(A, '\0', n)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
#define pern(i, b) per(i, b - 1, 0)
#define repn(i, b) rep(i, 0, b)
#define repe(i, a, b) for(int i = a; i <= b; i++)
#define repen(i, b) repe(i, 1, b)
#define fast ios_base::sync_with_stdio();cin.tie(0);
#define endl "\n"
//#define MYDEBUG

void my_return(int code)
{
#ifdef MYDEBUG
	std::cout << "\n\nTime = " << fixed << std::setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
	exit(code);
}

int main()
{
	fast
#ifdef MYDEBUG
		freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, m;
	cin >> n;
	vi arr(n), arr2(n);
	repn(i, n) {
		int x;
		cin >> x;
		arr[i] = x, arr2[i] = x;
	}
	sort(arr2.begin(), arr2.end());
	cin >> m;
	repn(i, m) {
		int type, l, r;
		ll sum = 0;
		cin >> type >> l >> r;
		l--;
		if (type == 1)
			rep(i, l, r) sum += arr[i];
		else
			rep(i, l, r) sum += arr2[i];
		cout << sum << endl;
	}

	my_return(0);
}


#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <unordered_set>
#include <stack>
#include <algorithm>
#include <queue>
#include <ctime>
#include <iomanip>
#include <tuple>
#include <functional>
#include <map>
#include <numeric>

using namespace std;

#define ll long long
#define pi pair<int, int>
#define vi vector<int>
#define vp vector<pi>
#define msa(A, a, n) memset(A, a, n*sizeof(A))
#define msv(A, a) fill(A.begin(), A.end(), a);
#define msc(A, n) memset(A, '\0', n)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
#define pern(i, b) per(i, b - 1, 0)
#define repn(i, b) rep(i, 0, b)
#define repe(i, a, b) for(int i = a; i <= b; i++)
#define repen(i, b) repe(i, 1, b)
#define fast ios_base::sync_with_stdio();cin.tie(0);
#define endl "\n"
//#define MYDEBUG

void my_return(int code)
{
#ifdef MYDEBUG
	std::cout << "\n\nTime = " << fixed << std::setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
	exit(code);
}

int main()
{
	fast
#ifdef MYDEBUG
		freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, m;
	cin >> n;
	vi arr(n), arr2(n);
	vector<ll> pre1(n + 1), pre2(n + 1);
	repn(i, n) {
		int x;
		cin >> x;
		arr[i] = x, arr2[i] = x;
	}

	sort(arr2.begin(), arr2.end());

	for (int i = 1; i <= n; i++)
	{
		pre1[i] = pre1[i - 1] + arr[i - 1];
		pre2[i] = pre2[i - 1] + arr2[i - 1];
	}

	cin >> m;
	repn(i, m) {
		int type, l, r;
		cin >> type >> l >> r;
		l--;
		if (type == 1)
			cout << pre1[r] - pre1[l] << endl;
		else
			cout << pre2[r] - pre2[l] << endl;
	}

	my_return(0);
}


#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	long long  int n;
	cin >> n;
	vector<long long int>v(n, 0);
	vector<long long int>increas;

	long long int num, q;
	for (int i = 0; i < n; i++)
	{
		cin >> num;
		increas.push_back(num);
		if (i == 0)
			v[i] = num;
		else
			v[i] = v[i - 1] + num;

	}
	sort(increas.begin(), increas.end());
	cin >> q;
	short type;
	long long int l, r;
	for (int i = 0; i < q; i++)
	{
		cin >> type >> l >> r;
		switch (type)
		{
		case 1:
			if (l == 1)
				cout << v[r-1] << endl;
			else
				cout << v[r - 1] - v[l - 2] << endl;
			break;

		case 2 :
			long long int count = 0;
			for (int i = l - 1; i < r; i++)
				count += increas[i];
			cout << count<<endl;
			break;

		}
	}
	//system("pause");
	return 0;

}


#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	long long  int n;
	cin >> n;
	vector<long long int>v(n, 0);
	vector<long long int>increas;

	long long int num, q;
	for (int i = 0; i < n; i++)
	{
		cin >> num;
		increas.push_back(num);
		if (i == 0)
			v[i] = num;
		else
			v[i] = v[i - 1] + num;

	}
	sort(increas.begin(), increas.end());
	cin >> q;
	short type;
	long long int l, r;
	for (int i = 0; i < q; i++)
	{
		cin >> type >> l >> r;
		switch (type)
		{
		case 1:
			if (l == 1)
				cout << v[r-1] << endl;
			else
				cout << v[r - 1] - v[l - 2] << endl;
			break;

		case 2 :
			int count = 0;
			for (int i = l - 1; i < r; i++)
				count += increas[i];
			cout << count<<endl;
			break;

		}
	}
	//system("pause");
	return 0;

}


#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	long long  int n;
	cin >> n;
	vector<long long int>v(n, 0);
	vector<long long int>increas;
	vector<long long int>sum2(n, 0);

	long long int num, q;
	for (int i = 0; i < n; i++)
	{
		cin >> num;
		increas.push_back(num);
		if (i == 0)
			v[i] = num;
		else
			v[i] = v[i - 1] + num;

	}
	int sum2;
	sort(increas.begin(), increas.end());
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
			sum2[i] = increas[i];

		sum2[i] = sum2[i - 1] + increas[i];

	}
	cin >> q;
	short type;
	long long int l, r;
	for (int i = 0; i < q; i++)
	{
		cin >> type >> l >> r;
		switch (type)
		{
		case 1:
			if (l == 1)
				cout << v[r-1] << endl;
			else
				cout << v[r - 1] - v[l - 2] << endl;
			break;

		case 2 :
			long long int count = 0;
			if (l == 1)
				cout << sum2[r - 1] << endl;
			else
				cout << sum2[r - 1] - sum2[l - 2] << endl;
			cout << count<<endl;
			break;

		}
	}
//	system("pause");
	return 0;

}


#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	long int n;
	cin >> n;
	vector<int>v(n, 0);
	vector<int>increas;

	long long int num, q;
	for (int i = 0; i < n; i++)
	{
		cin >> num;
		increas.push_back(num);
		if (i == 0)
			v[i] = num;
		else
			v[i] = v[i - 1] + num;

	}
	sort(increas.begin(), increas.end());
	cin >> q;
	short type;
	long int l, r;
	for (int i = 0; i < q; i++)
	{
		cin >> type >> l >> r;
		switch (type)
		{
		case 1:
			if (l == 1)
				cout << v[r-1] << endl;
			else
				cout << v[r - 1] - v[l - 2] << endl;
			break;

		case 2 :
			int count = 0;
			for (int i = l - 1; i < r; i++)
				count += increas[i];
			cout << count<<endl;
			break;

		}
	}
	//system("pause");
	return 0;

}


#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	long long  int n;
	cin >> n;
	vector<long long int>v(n, 0);
	vector<long long int>increas;
	vector<long long int>sum2(n, 0);

	long long int num, q;
	for (int i = 0; i < n; i++)
	{
		cin >> num;
		increas.push_back(num);
		if (i == 0)
			v[i] = num;
		else
			v[i] = v[i - 1] + num;

	}
	sort(increas.begin(), increas.end());
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
			sum2[i] = increas[i];
		else
		sum2[i] = sum2[i - 1] + increas[i];

	}
	cin >> q;
	short type;
	long long int l, r;
	for (int i = 0; i < q; i++)
	{
		cin >> type >> l >> r;
		switch (type)
		{
		case 1:
			if (l == 1)
				cout << v[r-1] << endl;
			else
				cout << v[r - 1] - v[l - 2] << endl;
			break;

		case 2 :
			if (l == 1)
				cout << sum2[r - 1] << endl;
			else
				cout << sum2[r - 1] - sum2[l - 2] << endl;
			break;

		}
	}
	//system("pause");
	return 0;

}


// This file is for solving problems, not for projects
// #include "pch.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <stack>
#include <utility>
#include <queue>
#include <cmath>
#include <map>

#define watch(x) cout << "var \"" << x << "\"" << ' ' << "is" << ' ' << x << endl // Show a value of variable x
#define pow2(x) ((x) * (x))
#define print(i) cout << i << endl
#define pb push_back
#define simple_sort(vec) sort(vec.begin(), vec.end())

typedef long long llong;
typedef unsigned int uint;

using namespace std;

struct {
	bool operator()(const string what, const string what1) const {
		return what.length() < what1.length();
	}
} LenCompare;

struct {
	void str(vector<string> VecStr) {
		for (int i = 0; i < VecStr.size(); i++) {
			cout << VecStr[i] << ' ';
		}
		cout << "\n";
	}

	void iint(vector<int> VecInt) {
		for (int i = 0; i < VecInt.size(); i++) {
			cout << VecInt[i] << ' ';
		}
		cout << "\n";
	}

	void chr(vector<char> VecChr) {
		for (int i = 0; i < VecChr.size(); i++) {
			cout << VecChr[i] << ' ';
		}
		cout << "\n";
	}

	void doub(vector<double> VecD) {
		for (int i = 0; i < VecD.size(); i++) {
			cout << VecD[i] << ' ';
		}
		cout << "\n";
	}

} show_vector;

/* Anime i want to watch before my bd (16.02.2019) comes:
 * Darker Than Black  18 \ 25
 * Naruto (1st season done) Shippuuden 32\500
 * Cowboy Bebop 10 \ 25
 * Zombieland: Saga 5 \ 12
 * Steins: Gate 0 (mb) 11 \25
 * Neon Genesis Evangelion 10 \ 26
 * Tengen Tonpa Gurren Lagann
 * Seishun Buta Yarou wa Bunny Girl Senpai no Yume wo Minai
 * Bakemonogatari (done)
 * Kill la Kill 13 \ 25
 * Attack on Titan s03
 * Boku no Hero Academia s03 18 \ 25
 * Mob Psycho 100 (done)
 * K-On! (done)
 * Kakegurui(done)
 * Sakurasou Pet na Kanojo
 * Shingeki no Bahamut: Virgin Soul
 * Violett Evergarden (5 / 12)
 * Yuru Camp
 * Hitsugi no Chaika
 * Nisemonogatari (done)
 * Nekomonogatari (done)
 * SSSS.Gridman
 * Owarimonogatari 1 (7 / 12)
 * Boku dake ga Inai Machi (9 / 12)
 */

vector<llong> stones;
vector<llong> stones1;
vector<llong> s2;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	s2.pb(0);
	stones.pb(0);
	int n;
	cin >> n;
	llong sum = 0;
	for (int i = 0; i < n; i++) {
		int v;
		cin >> v;
		sum += v;
		stones.pb(sum);
		stones1.pb(v);
	}
	sort(stones1.begin(), stones1.end());
	sum = 0;
	for (int i = 0; i < n; i++) {
		sum += stones1[i];
		s2.pb(sum);
	}
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int type, l, r;
		cin >> type >> l >> r;
		if (type == 1) {
			print(stones[r] - stones[l - 1]);
		}
		else {
			print(s2[r] - s2[l - 1]);
		}
	}
	return(0);
}


// This file is for solving problems, not for projects
// #include "pch.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <stack>
#include <utility>
#include <queue>
#include <cmath>
#include <map>

#define watch(x) cout << "var \"" << x << "\"" << ' ' << "is" << ' ' << x << endl // Show a value of variable x
#define pow2(x) ((x) * (x))
#define print(i) cout << i << endl
#define pb push_back
#define simple_sort(vec) sort(vec.begin(), vec.end())

typedef long long llong;
typedef unsigned int uint;

using namespace std;

struct {
	bool operator()(const string what, const string what1) const {
		return what.length() < what1.length();
	}
} LenCompare;

struct {
	void str(vector<string> VecStr) {
		for (int i = 0; i < VecStr.size(); i++) {
			cout << VecStr[i] << ' ';
		}
		cout << "\n";
	}

	void iint(vector<int> VecInt) {
		for (int i = 0; i < VecInt.size(); i++) {
			cout << VecInt[i] << ' ';
		}
		cout << "\n";
	}

	void chr(vector<char> VecChr) {
		for (int i = 0; i < VecChr.size(); i++) {
			cout << VecChr[i] << ' ';
		}
		cout << "\n";
	}

	void doub(vector<double> VecD) {
		for (int i = 0; i < VecD.size(); i++) {
			cout << VecD[i] << ' ';
		}
		cout << "\n";
	}

} show_vector;

/* Anime i want to watch before my bd (16.02.2019) comes:
 * Darker Than Black  18 \ 25
 * Naruto (1st season done) Shippuuden 32\500
 * Cowboy Bebop 10 \ 25
 * Zombieland: Saga 5 \ 12
 * Steins: Gate 0 (mb) 11 \25
 * Neon Genesis Evangelion 10 \ 26
 * Tengen Tonpa Gurren Lagann
 * Seishun Buta Yarou wa Bunny Girl Senpai no Yume wo Minai
 * Bakemonogatari (done)
 * Kill la Kill 13 \ 25
 * Attack on Titan s03
 * Boku no Hero Academia s03 18 \ 25
 * Mob Psycho 100 (done)
 * K-On! (done)
 * Kakegurui(done)
 * Sakurasou Pet na Kanojo
 * Shingeki no Bahamut: Virgin Soul
 * Violett Evergarden (5 / 12)
 * Yuru Camp
 * Hitsugi no Chaika
 * Nisemonogatari (done)
 * Nekomonogatari (done)
 * SSSS.Gridman
 * Owarimonogatari 1 (7 / 12)
 * Boku dake ga Inai Machi (9 / 12)
 */

vector<int> stones;
vector<int> stones1;
vector<int> s2;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	s2.pb(0);
	stones.pb(0);
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int v;
		cin >> v;
		sum += v;
		stones.pb(sum);
		stones1.pb(v);
	}
	sort(stones1.begin(), stones1.end());
	sum = 0;
	for (int i = 0; i < n; i++) {
		sum += stones1[i];
		s2.pb(sum);
	}
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int type, l, r;
		cin >> type >> l >> r;
		if (type == 1) {
			print(stones[r] - stones[l - 1]);
		}
		else {
			print(s2[r] - s2[l - 1]);
		}
	}
	return(0);
}


// This file is for solving problems, not for projects
// #include "pch.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <stack>
#include <utility>
#include <queue>
#include <cmath>
#include <map>

#define watch(x) cout << "var \"" << x << "\"" << ' ' << "is" << ' ' << x << endl // Show a value of variable x
#define pow2(x) ((x) * (x))
#define print(i) cout << i << endl
#define pb push_back
#define simple_sort(vec) sort(vec.begin(), vec.end())

typedef long long llong;
typedef unsigned int uint;

using namespace std;

struct {
	bool operator()(const string what, const string what1) const {
		return what.length() < what1.length();
	}
} LenCompare;

struct {
	void str(vector<string> VecStr) {
		for (int i = 0; i < VecStr.size(); i++) {
			cout << VecStr[i] << ' ';
		}
		cout << "\n";
	}

	void iint(vector<int> VecInt) {
		for (int i = 0; i < VecInt.size(); i++) {
			cout << VecInt[i] << ' ';
		}
		cout << "\n";
	}

	void chr(vector<char> VecChr) {
		for (int i = 0; i < VecChr.size(); i++) {
			cout << VecChr[i] << ' ';
		}
		cout << "\n";
	}

	void doub(vector<double> VecD) {
		for (int i = 0; i < VecD.size(); i++) {
			cout << VecD[i] << ' ';
		}
		cout << "\n";
	}

} show_vector;

/* Anime i want to watch before my bd (16.02.2019) comes:
 * Darker Than Black  18 \ 25
 * Naruto (1st season done) Shippuuden 32\500
 * Cowboy Bebop 10 \ 25
 * Zombieland: Saga 5 \ 12
 * Steins: Gate 0 (mb) 11 \25
 * Neon Genesis Evangelion 10 \ 26
 * Tengen Tonpa Gurren Lagann
 * Seishun Buta Yarou wa Bunny Girl Senpai no Yume wo Minai
 * Bakemonogatari (done)
 * Kill la Kill 13 \ 25
 * Attack on Titan s03
 * Boku no Hero Academia s03 18 \ 25
 * Mob Psycho 100 (done)
 * K-On! (done)
 * Kakegurui(done)
 * Sakurasou Pet na Kanojo
 * Shingeki no Bahamut: Virgin Soul
 * Violett Evergarden (5 / 12)
 * Yuru Camp
 * Hitsugi no Chaika
 * Nisemonogatari (done)
 * Nekomonogatari (done)
 * SSSS.Gridman
 * Owarimonogatari 1 (7 / 12)
 * Boku dake ga Inai Machi (9 / 12)
 */

vector<int> stones;
vector<int> stones1;
vector<int> s2;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	s2.pb(0);
	stones.pb(0);
	int n;
	cin >> n;
	llong sum = 0;
	for (int i = 0; i < n; i++) {
		int v;
		cin >> v;
		sum += v;
		stones.pb(sum);
		stones1.pb(v);
	}
	sort(stones1.begin(), stones1.end());
	sum = 0;
	for (int i = 0; i < n; i++) {
		sum += stones1[i];
		s2.pb(sum);
	}
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int type, l, r;
		cin >> type >> l >> r;
		if (type == 1) {
			print(stones[r] - stones[l - 1]);
		}
		else {
			print(s2[r] - s2[l - 1]);
		}
	}
	return(0);
}


#include <iostream>
#include <algorithm>

using namespace std;
int n, m, l, r,x, arr[111111], cum1[111111], cum2[111111];
int main()
{
	cin >> n;

	for (int i = 1; i <= n; ++i)
	{
		cin >> arr[i];
		cum1[i] = cum1[i - 1] + arr[i];
	}
	sort(arr + 1, arr + n + 1);
		for(int i=1;i<=n;++i)
		{
			cum2[i] = cum2[i - 1] + arr[i];
		}
	cin >> m;
	while (m--) {
		cin >> x >> l >> r;
		if (x == 1) {
			cout << cum1[r] - cum1[l - 1] << endl;
		}
		else {
			cout << cum2[r] - cum2[l - 1] << endl;
		}
	}

	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
int n, m, l, r, x, arr[100011];
long long  cum1[111111], cum2[111111];
int main()
{
	cin >> n;

	for (int i = 1; i <= n; ++i)
	{
		cin >> arr[i];
		cum1[i] = cum1[i - 1] + arr[i];
	}
	sort(arr + 1, arr + n + 1);
		for(int i=1;i<=n;++i)
		{
			cum2[i] = cum2[i - 1] + arr[i];
		}
	cin >> m;
	while (m--) {
		cin >> x >> l >> r;
		if (x == 1) {
			cout << cum1[r] - cum1[l - 1] << endl;
		}
		else {
			cout << cum2[r] - cum2[l - 1] << endl;
		}
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main()
{
	long long n;
	cin >> n;
	vector <long long> v(n+1), u(n+1);
	v[0] = u[0] = 0;

	for (long long i = 1; i <= n; ++i)
	{
		long long a;
		cin >> a;
		v[i] = u[i] = a;
	}

	sort(u.begin(), u.end());

	for (long long i = 1; i <= n; ++i)
	{
		v[i] += v[i - 1];
			u[i] += u[i-1];
	}

	long long m;
	cin >> m;

	for (long long i = 0; i < m; ++i)
	{
		long long t;
		long long l, r;
		cin >>t>> l >> r;
		if (t == 1) cout << v[r] - v[l - 1]<<endl;
		else cout << u[r] - u[l - 1]<<endl;
	}

	//system("pause");
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	long n;
	cin >> n;
	vector <long> v(n+1), u(n+1);
	v[0] = u[0] = 0;

	for (int i = 1; i <= n; ++i)
	{
		long a;
		cin >> a;
		v[i] = u[i] = a;
	}

	sort(u.begin(), u.end());

	for (int i = 1; i <= n; ++i)
	{
		v[i] += v[i - 1];
			u[i] += u[i-1];
	}

	long m;
	cin >> m;

	for (int i = 0; i < m; ++i)
	{
		int t;
		long l, r;
		cin >>t>> l >> r;
		if (t == 1) cout << v[r] - v[l - 1]<<endl;
		else cout << u[r] - u[l - 1]<<endl;
	}

	//system("pause");
	return 0;
}


#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
#include<numeric>
#include <cmath>
#include<cstdio>
#include <iomanip>

using namespace std;

// Driver code
int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	long long n,tmp,m;
	cin >> n;
	vector<long long>arr;
	vector<long long>sorted_arr;
	vector<vector<long long>>dp;
	vector<vector<long long>>dp_sorted;
	while (n--)
	{
		cin >> tmp;
		arr.push_back(tmp);
		sorted_arr.push_back(tmp);
	}
	sort(sorted_arr.begin(), sorted_arr.end());

	long long type,l,r;
	n = arr.size();
	vector<long long>tmp_arr;
	vector<long long>tmp_arr_sorted;
	long long sum = 0;
	long long sum_sorted = 0;
	for (int i = 0; i < n; i++) {
		sum = arr[i];
		sum_sorted = sorted_arr[i];
		for (int j = 0 ; j <= i; j++) {
			tmp_arr.push_back(0);
			tmp_arr_sorted.push_back(0);
		}

		for (int j = i+1; j < n;j++) {
			sum += arr[j];
			sum_sorted += sorted_arr[j];
			tmp_arr.push_back(sum);
			tmp_arr_sorted.push_back(sum_sorted);
		}
		dp.push_back(tmp_arr);
		dp_sorted.push_back(tmp_arr_sorted);
		tmp_arr_sorted.clear();
		tmp_arr.clear();
	}
	for (int i = 0; i < n;i++) {
		dp[i][i] = arr[i];
		dp_sorted[i][i] = sorted_arr[i];
	}
	cin >> m;
	while (m--)
	{
		cin >> type >> l >> r;
		if (type == 1) {
			cout << dp[l-1][r-1] << endl;
		}
		else {
			cout << dp_sorted[l - 1][r - 1] << endl;
		}
	}
}


#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
#include<numeric>
#include <cmath>
#include<cstdio>
#include <iomanip>

using namespace std;

long getMid(long s, long e) {
	return s + (e - s) / 2;
}

//get sum given specific range
int getSumUtil(long*st, long ss, long se, long qs, long qe, long si) {
	if (qs <= ss && qe >= se) {
		return st[si];
	}
	if (qe<ss || qs>se) {//if it is outside the range
		return 0;//ignore it
	}
	long mid = getMid(ss,se);
	return getSumUtil(st, ss, mid, qs, qe, 2*si+1)+getSumUtil(st, mid+1, se, qs, qe, 2*si+2);
}

long getSum(long*st, long n, long qs, long qe) {
	if (qs<0 || qe>n - 1 || qs > qe)return -1;
	return getSumUtil(st, 0, n-1, qs, qe, 0);
}

int constructUtil(vector<long>arr, long ss, long se, long*st, long si) {
	if (ss == se)
	{
		st[si] = arr[ss];
		return arr[ss];
	}
	long mid = getMid(ss, se);
	st[si] = constructUtil(arr, ss, mid, st, si*2+1)+constructUtil(arr, mid+1, se, st, si*2+2);
	return st[si];
}

long* constructST(vector<long>arr, long n)
{
	// Allocate memory for the segment tree

	//Height of segment tree
	long x = (long)(ceil(log2(n)));

	//Maximum size of segment tree
	long max_size = 2 * (long)pow(2, x) - 1;

	// Allocate memory
	long* st = new long[max_size];

	// Fill the allocated memory st
	constructUtil(arr, 0, n - 1, st, 0);

	// Return the constructed segment tree
	return st;
}
// Driver code
int main()
{
	long n,tmp,m;
	cin >> n;
	vector<long>arr;
	vector<long>sorted_arr;
	while (n--)
	{
		cin >> tmp;
		arr.push_back(tmp);
		sorted_arr.push_back(tmp);
	}
	sort(sorted_arr.begin(), sorted_arr.end());
	long* stSum = constructST(arr, arr.size());
	long* stMin = constructST(sorted_arr, sorted_arr.size());
	long type,l,r;
	n = arr.size();
	cin >> m;
	while (m--)
	{
		cin >> type >> l >> r;
		if (type == 1) {
			cout << getSum(stSum, n, l-1, r-1) << endl;
		}
		else {
			cout << getSum(stMin, n, l-1, r-1) << endl;
		}
	}
}