class Solution {
public:
int movesToMakeZigzag(vector<int>& nums) {
int ji=0;
int n=nums.size();
if(n==1)
return 0;
if(n==2&&nums[0]!=nums[1])
return 0;
if(n==2&&nums[0]==nums[1])
return 1;
int bb[1005];
for(int i=0;i<n;i++)
bb[i]=nums[i];
for(int i=1;i<n;i+=2)
{
if(nums[i]<=nums[i-1])
ji+=abs(nums[i]-nums[i-1]-1);
if(i!=n-1&&nums[i]<=nums[i+1])
{
ji+=abs(nums[i]-nums[i+1]-1);
nums[i+1]=nums[i]-1;
}
}
int ou=0;
for(int i=0;i<n;i+=2)
{
if(i==0)
{
if(bb[i]<=bb[i+1])
{
ou+=abs(bb[i]-bb[i+1]-1);
bb[i+1]=bb[i]-1;
}
}
else
{
if(bb[i]<=bb[i-1])
ou+=abs(bb[i]-bb[i-1]-1);
if(i!=n-1&&bb[i]<=bb[i+1])
{
ou+=abs(bb[i]-bb[i+1]-1);
bb[i+1]=bb[i]-1;
}
}
}
int ans=min(ji,ou);
return ans;
}
};