Codeforces Round #493 (Div. 2) D. Roman Digits

 

Let’s introduce a number system which is based on a roman digits. There are digits IVXL which correspond to the numbers 11551010 and 5050 respectively. The use of other roman digits is not allowed.

Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.

For example, the number XXXV evaluates to 3535 and the number IXI — to 1212.

Pay attention to the difference to the traditional roman system — in our system any sequence of digits is valid, moreover the order of digits doesn’t matter, for example IX means 1111, not 99.

One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly nn roman digits IVXL.

Input

The only line of the input file contains a single integer nn (1n1091≤n≤109) — the number of roman digits to use.

Output

Output a single integer — the number of distinct integers which can be represented using nn roman digits exactly.

Examples

Input
1
Output
4
Input
2
Output
10
Input
10
Output
244

Note

In the first sample there are exactly 44 integers which can be represented — IVXand L.

In the second sample it is possible to represent integers 22 (II), 66 (VI), 1010 (VV), 1111 (XI), 1515 (XV), 2020 (XX), 5151 (IL), 5555 (VL), 6060 (XL) and 100100 (LL).

打表之后用后面的减前面的发现12项之后是个等差数列。
前面的12项的差值是逐步减少的,一直减少到49稳定,所以得出代码:
代码如下:注释部分是打表用的DFS(直接交DFS代码会TLE4,所以想到会是个规律题),正式代码是AC代码。

 

/*#include<iostream>
#include<set>
using namespace std;
typedef long long ll;
set<int> ans_arr; 
ll ans=0,endstep=0,endsum=0;
int roma[4]={1,5,10,50};
void dfs(ll curr)
{
  if(curr==endstep+1)
  {
    if(ans_arr.find(endsum)!=ans_arr.end())
    {
      return;
    }
    else 
    {
      ans++;
      ans_arr.insert(endsum);
      return;
    }
  }
  for(int i=0;i<4;i++)
  {
    endsum=endsum+roma[i];
    dfs(curr+1);
    endsum=endsum-roma[i];
  }

}
int main(){
    cin>>endstep;
 		dfs(1);
 		cout<<ans<<endl;
 		ans=0;
 		endsum=0;
    ans_arr.clear();
    return 0;
 	}
*/
#include<iostream>
using namespace std;
typedef long long ll;
ll ans[]={0,4,10,20,35,56,83,116,155,198,244,292,341,390};
int main()
{
  ll n=0;
  cin>>n;
  n<=12?cout<<ans[n]<<endl:cout<<341+(n-12)*49<<endl;
  return 0;
}

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

5 × 2 =