What is wrong in this code? Giving runtime error- SIGSEGV

Refer this question - CodeChef: Practical coding for everyone (Oct Cook-Off 2021)

int main(){

int t ; cin>>t;
while(t--){
    int n; cin>>n;
    vector<int> even, odd; int sum=0;
    
    for(int i=0 ; i<n;i++){
        int a ; cin>>a;
        if(i%2==0) even.push_back(a);
        else {
            odd.push_back(a);
            sum+=a;
        }
    }
    
    sort(odd.begin(), odd.end());
    sort(even.begin(), even.end(), greater<int> ());
    
    int ans=0;
    int size=max(even.size(), odd.size());
    
    for(int i=0; i<size; i++){
        if(even[i]) cout<<even[i]<<" ";
        if(odd[i]) cout<<odd[i]<<" ";
    }
    cout<<endl;
    
    for(int i=0 ; i<size; i++){
        if(even[i]) ans+=even[i]*sum;
        if(odd[i]) sum-=odd[i];
    }
    cout<<ans<<endl;
}


return 0;

}

Out-of-bounds access on the following test input:

1
5
2 3 4 3 2
[simon@simon-laptop][07:32:12]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling m_vaidya-ZEROONE.cpp
Executing command:
  g++ -std=c++17 m_vaidya-ZEROONE.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG    -fsanitize=undefined -ftrapv
m_vaidya-ZEROONE.cpp: In function ‘int main()’:
m_vaidya-ZEROONE.cpp:24:21: warning: conversion to ‘int’ from ‘long unsigned int’ may alter its value [-Wconversion]
         int size=max(even.size(), odd.size());
                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Successful
[simon@simon-laptop][07:33:04]
[~/devel/hackerrank/otherpeoples]>echo "
1
5
2 3 4 3 2" | ./a.out
/usr/include/c++/7/debug/vector:417:
Error: attempt to subscript container with out-of-bounds index 2, but 
container only holds 2 elements.

Objects involved in the operation:
    sequence "this" @ 0x0x7ffd0f7ce690 {
      type = std::__debug::vector<int, std::allocator<int> >;
    }
Aborted (core dumped)

Change the line of int size=max(even.size(),odd.size()) to int size=min(even.size(),odd.size()) and then try to traverse the extra length of whoever has greater size, because of taking max your code is accessing some elements out of bounds from the vector of smaller size out of odd and even.

Thank You