Language: C++

#include<bits/stdc++.h> 
using namespace std;
int xyz(int i,vector<int> &a,vector<int> &b,vector<int> &c,int k)
 {
  int x;
  if(k==3)
  {
  x=max(a[i],b[i]);
  if(a[i]==b[i])
    {
    if(a[i+1]>b[i+1])
      p=2;
    else p=1;
    }
  else if (x==a[i])
    p=1;
  else if (x==b[i])
    p=2;
   }
  else if(k==2)
  {
  x=max(a[i],c[i]);
  if(a[i]==c[i])
    {
    if(a[i+1]>c[i+1])
      p=3;
    else p=1;
    }
  else if (x==a[i])
    p=1;
  else if (x==c[i])
    p=3;
   }
  else if(k==1)
  {
  x=max(c[i],b[i]);
  if(c[i]==b[i])
    {
    if(c[i+1]>b[i+1])
      p=2;
    else p=3;
    }
  else if (x==c[i])
    p=3;
  else if (x==b[i])
    p=2;
   }
  return p;
  }
int main() 
{ 
  int n,i,j=0,p;
  cin>>n;
  vector<int>a(n);
  vector<int>b(n);
  vector<int>c(n);
  vector<int>x(n);
  vector<int>y(n);
  for(i=0;i<n;i++)
    {
    cin>>a[i];
    cin>>b[i];
    cin>>c[i];
    }
 while(j!=n)
 {
   if(a[j]==b[j] && b[j]==c[j])
     {
     if(j==0)
       y[j]=a[j];
     else
      y[j]=a[j]+y[j-1];
     j++;
      }
   else 
     break;
  }
  if(a[j]==b[j] && a[j]>c[j])
    {
    if (a[j+1]>b[j+1])
      p=2;
    else
      p=1;
    }
  if(a[j]==c[j] && a[j]>b[j])
    {
    if (a[j+1]>c[j+1])
      p=3;
    else
      p=1;
    }
  if(c[j]==b[j] && c[j]>a[j])
    {
    if (c[j+1]>b[j+1])
      p=2;
    else
      p=3;
    }
  else if (a[j]>b[j] && a[j]>c[j])
    p=1;
  else if (c[j]>b[j] && a[j]<c[j])
    p=3;
  else if (a[j]<b[j] && b[j]>c[j])
    p=2;
  if(p==1)
  {
    if(j==0)
      y[j]=a[j];
    else
      y[j]=a[j]+y[j-1];
  }
  else if(p==2)
  {
    if(j==0)
      y[j]=b[j];
    else
      y[j]=b[j]+y[j-1];
  }
  else if(p==3)
  {
    if(j==0)
      y[j]=c[j];
    else
      y[j]=c[j]+y[j-1];
  }
  for (i=j+1;i<n;i++)
  {
    p=xyz(i,a,b,c,p);
    if(p==3)
      y[i]=y[i-1]+c[i];
    else if(p==2)
      y[i]=y[i-1]+b[i];
    else if(p==1)
      y[i]=y[i-1]+a[i];
    }
  cout<<y[n-1]<<endl;
  }

Compiler output:
a.cc: In function 'int xyz(int, std::vector<int>&, std::vector<int>&, std::vector<int>&, int)':
a.cc:12:7: error: 'p' was not declared in this scope
   12 |       p=2;
      |       ^
a.cc:13:10: error: 'p' was not declared in this scope
   13 |     else p=1;
      |          ^
a.cc:16:5: error: 'p' was not declared in this scope
   16 |     p=1;
      |     ^
a.cc:18:5: error: 'p' was not declared in this scope
   18 |     p=2;
      |     ^
a.cc:26:7: error: 'p' was not declared in this scope
   26 |       p=3;
      |       ^
a.cc:27:10: error: 'p' was not declared in this scope
   27 |     else p=1;
      |          ^
a.cc:30:5: error: 'p' was not declared in this scope
   30 |     p=1;
      |     ^
a.cc:32:5: error: 'p' was not declared in this scope
   32 |     p=3;
      |     ^
a.cc:40:7: error: 'p' was not declared in this scope
   40 |       p=2;
      |       ^
a.cc:41:10: error: 'p' was not declared in this scope
   41 |     else p=3;
      |          ^
a.cc:44:5: error: 'p' was not declared in this scope
   44 |     p=3;
      |     ^
a.cc:46:5: error: 'p' was not declared in this scope
   46 |     p=2;
      |     ^
a.cc:48:10: error: 'p' was not declared in this scope
   48 |   return p;
      |          ^