Why is this code not getting submitted and not passing any testcases

#include<bits/stdc++.h>

using namespace std;

void tripletsum(int a[],int n,int key){

int i=0;

while(i<n){

int p=ia+1;

int j=n-1;

while(i+p<=j){

//5 7 9 1 2 4 6 8 3

//1 2 3 4 5 6 7 8 9

if(a[i]+a[p]+a[j]==key){

cout<<a[i]<<", “<<a[p]<<” and "<<a[j]<<endl;

p++ and j-- ;

}

if(a[i]+a[p]+a[j]>key){

j–;

}

if(a[i]+a[p]+a[j]<key){

p++;

}

}

i++;

}

}

int main() {

int n;

cin>>n;

auto a =new int [n];

for(int i=0;i<n;i++){

cin>>a[i];

}

int key;

cin>>key;

sort(a,a+n);

tripletsum(a,n,key);

delete[]a;

}