ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Турниры > CEN303 2013-15 Questions > задача:


15FE-01. 50838 - Balanced Numbers

CEN303 2013-15 Questions

Старт: 15.дек.2013 в 14:00:00
Финиш: 15.дек.2013 в 19:00:00
Турнир завершён!
• Турнирная таблица

Задачи турнира

• 14-Fall2-10. 50751 - The biggest Mi...
• 14-Fall2-20. 50794 - Writing Files Int...
• 14-Fall2-30. 50490 - Across the River
• 14-Fall2-40. 50772 - The Path of a N...
• 14-Fall2-50. 50681 - Center of a Series
• 14-FallResit-10. 50525 - Ordering Pizza
• 14-FallResit-20. 50488 - Connecting...
• 15FE-01. 50851 - Repeated Numbers
• 15FE-01. 50838 - Balanced Nu...
• 15FE-04. 50997 - Dynamic Knights
• 15HW-10. 50826 - Olive Containers
• 15HW-30. 50828 - Arranging Time ...
• 15HW-40. 50676 - Cinema Millennium
• 15HW-40. 50829 - Decode an Image
• 15HW-50. 50830 - Sorting BST Nodes
• 15HW-60. 50678 - The Jumping Rabbit
• 15MdE-10. 50802 - Comparing Exams

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Question by Ibrahim Mesecan.

Balanced Numbers

Balanced number is a number whose sum of the digits in the first half is the same as sum of the digits in the second half. For example: 735465 is balanced number with the length three. However, the number 732523 is not a balanced number because sum of the digits in the first half (732) is 12 and sum of the digits in the second half (523) is 10.

The number may be balanced with only the divisors of the length given. For example, for the length 9, the number may be balanced with the lengths 1, 2 and 3. For example, the number 732855 is another balanced number with the length 2 (sum of the digits (7+3)==(2+8)==(5+5)==10). 5555 is also balanced number with the length 1.

Question:
Write a program that gets an n-digit number and then it decides the minimum length of the balance for the given number.

Input specification
Firstly, you will be given an integer: n the length of given number where 1 ≤ n ≤ 250. Then, in the next line, you will be given the number.

Output specification
Show the minimum length of balance. Show -1, if it is not balanced in any length.

Sample Input I
6
735465
Sample Input II
7
5432765
Sample Output I  
3
Sample Output II
-1


Для отправки решений необходимо выполнить вход.

www.contester.ru