This is my CPP solution.
class Solution {
public:
int sumOddLengthSubarrays(vector<int>& arr) {
int sum = 0;
int n = arr.size();
int ans = 0;
for(int i=0; i<n; i++) {
int odd=1;
int sum=0;
for(int j=i; j<n; j++) {
sum+=arr[j];
if(odd%2==1) ans += sum;
odd++;
}
}
return ans;
}
};