Time Limit: | Memory Limit: | 64bit IO Format: |
Description
The average miner Vaganych took refresher courses. As soon as aminer completes the courses, he should take exams. The hardest oneis a computer test called "Testing Pants for Sadness".
The test consists of
A click is regarded as selecting any answer in any question. Thegoal is to select the correct answer for each ofthe
Vaganych is very smart and his memory is superb, yet he isunbelievably unlucky and knows nothing whatsoever about the test'stheme. How many clicks will he have to perform in the worstcase?
Input
The first line contains a positiveinteger
Output
Print a single number — the minimal number of clicks needed topass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bitintegers in С++. It is preferred to use the cin, cout streams orthe %I64d specificator.
Sample Input
2 1 1
2
2 2 2
5
1 10
10
Hint
Note to the second sample. In the worst-case scenario you willneed five clicks:
- the first click selects the first variant to the firstquestion, this answer turns out to be wrong.
- the second click selects the second variant to the firstquestion, it proves correct and we move on to the secondquestion;
- the third click selects the first variant to the secondquestion, it is wrong and we go back to question 1;
- the fourth click selects the second variant to the firstquestion, it proves as correct as it was and we move on to thesecond question;
- the fifth click selects the second variant to the secondquestion, it proves correct, the test is finished.
#include<iostream>
#include<stdio.h>
#include<cmath>
const int MAX=105;
__int64 a[MAX];
using namespace std;
int main()
{
int n,i;
bool f=true;
__int64 sum,temp;
while(scanf("%d",&n)!=EOF)
{
scanf("%I64d",&a[1]);
if(n==1) { printf("%I64d\n",a[1]);continue;}
sum=a[1];
for(i=2;i<=n;i++)
{
scanf("%I64d",&a[i]);
temp=a[i]+(a[i]-1)*(i-1);
sum+=temp;
}
printf("%I64d\n",sum);
}
return 0;
}