https://onlinegdb.com/i3Q2Vg9Gr

why this code is giving run error?

in your code at line no 11
int* a = new int(n); this is not correct
correct statement is
int* a = new int[n];

after this your code will pass all testcases