#include<iostream>
#include<fstream>
using namespace std;
int N;int d[1024];
int lowbit(int x)//求某个点的管辖范围
{
return x&(-x);
}
void update(int x,int num)修改树状数组
{
while(x<=N)
{
d[x]+=num;
x+=lowbit(x);
}
}
int getsum(int x)//区间求和即:d[1]+d[2]....+d[x];
{
int s=0;
while(x>0)
{
s+=d[x];
x-=lowbit(x);
}
return s;
}
int main()
{
int n;in>>N;
int i;int s[1024];
for(i=1;i<=n;++i)
s[i]=i;
for(i=1;i<=n;++i)
update(i,s[i]);//生成树状数组
for(i=1;i<=n;++i)
cout<<d[i]<<" ";
int x;cin>>x;
cout<<getsum(x)<<endl;//获得从1到x的s[1]~s[x]的和
return 0;
}