Input Format
The first line contains two space-separated integers denoting the respective values of  (the number of variable-length arrays) and  (the number of queries).
Each line  of the  subsequent lines contains a space-separated sequence in the format k a[i]0 a[i]1 … a[i]k-1 describing the -element array located at .
Each of the  subsequent lines contains two space-separated integers describing the respective values of  (an index in array ) and  (an index in the array referenced by ) for a query.
Constraints
• All indices in this challenge are zero-based.
• All the given numbers are non negative and are not greater than
Output Format
For each pair of  and  values (i.e., for each query), print a single integer denoting the element located at index  of the array referenced by . There should be a total of  lines of output.

## Variable Sized arrays problem solution in C++ programming | HackerRank

#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
int n;
int q;
cin >> n >> q;

// Create an array of pointers to integer arrays
// (i.e., an array of variable-length arrays)
int** outer = new int*[n];

// Fill each index of 'outer' with a variable-length array
for(int i = 0; i < n; i++) {
int k;
cin >> k;
// Create an array of length 'k' at index 'i'
outer[i] = new int[k];

// Fill each cell in the 'inner' variable-length array
for(int j = 0; j < k; j++) {
cin >> outer[i][j];
}
}

// Perform queries:
while(q-- > 0) {
int outer_index;
int inner_index;
cin >> outer_index >> inner_index;

// Find the variable-length array located at outer_index
// and print the value of the element at inner_index.
cout << outer[outer_index][inner_index] << endl;
}

return 0;
}

### Second solution

#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <cassert>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <iostream>

#define pb push_back
#define all(x) (x).begin(), (x).end()

#ifdef KAZAR
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 0
#endif

using namespace std;

template<class T> inline void umax(T &a,T b){if(a < b) a = b;}
template<class T> inline void umin(T &a,T b){if(a > b) a = b;}
template<class T> inline T abs(T a){return a > 0 ? a : -a;}

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

const int inf = 1e9 + 143;
const ll longinf = 1e18 + 143;

inline int read(){int x;scanf(" %d",&x);return x;}

const int N = 123456;

int *a[N];

int main(){

#ifdef KAZAR
freopen("f.input","r",stdin);
freopen("f.output","w",stdout);
freopen("error","w",stderr);
#endif

assert(1 <= n && n <= 1e5);
assert(1 <= q && q <= 1e5);

for (int i = 0; i < n; i++) {
a[i] = new int[k];
for (int j = 0; j < k; j++) {
}
}

for (int i = 0; i < q; i++) {
printf("%d\n", a[x][y]);
}

return 0;
}

### Third Solution

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <cassert>
#include <algorithm>
using namespace std;

int main() {
int *arr[100004], siz[100004];
int n,q;
int tot = 0;
scanf("%d %d", &n, &q);
assert(n >= 1 && n <= 100000 && q >= 1 && q <= 100000);
for(int i = 0 ; i< n ; i++)
{
int num;
scanf("%d", &num);
assert(num >= 1 && num <= 300000);
tot += num;
siz[i] = num;
arr[i] = (int*)malloc(num*sizeof(int));
for(int j = 0 ; j < num; j++)
{
scanf("%d", &arr[i][j]);
assert(arr[i][j] >= 0 && arr[i][j] <= 1000000);
}
}
assert(tot >= 1 && tot <= 300000 && tot >= n);
while(q--)
{
int a,b;
scanf("%d %d", &a, &b);
assert(a >= 0 && a < n && b >= 0 && b < siz[a]);
printf("%d\n", arr[a][b]);
}
return 0;
}