Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int,int> pr;
typedef pair<pr , pr > ppr;
typedef array<int,5> arafi;
int num[5]={},numTimes[5]={},numbers;
vector<array<int,5> > p; 
void search(int times,int gets[5]){
	if(times==numbers){
	
		int sum=0;
		for(int i=0;i<numbers;i++)
			sum+=num[i]*gets[i];
		if(sum==10){
			arafi a={gets[0],gets[1],gets[2],gets[3],gets[4]};
		p.push_back(a);
		}
	}
	else{
		for(int i=0;i<=numTimes[times] && i<=10 ;i++){
		gets[times]=i;
		search(times+1,gets);
		}
	}
}
int findAns(int x,int times[]){
	if (x==p.size())
		return 0;
	int maxim=0,ans=1;
	arafi ar=p[x];
	for(int i=0;i<numbers;i++){
		if(ar[i]>times[i])
			ans=0;
		times[i]-=ar[i];
	}
	if(ans)
	maxim=max(maxim,1+findAns(x,times));
	for(int i=0;i<numbers;i++)
		times[i]+=ar[i];
	maxim=max(maxim,findAns(x+1,times));
	return maxim;
}
int solved(vector<pr> v){
		int ans=0;
		for(int i=0;i<v.size();i++){
			num[i]=v[i].first;
			numTimes[i]=v[i].second;
		}
		numbers=v.size();
		int gets[5]={};
		search(0,gets);
		return findAns(0,numTimes);
}
int main() {
	// your code goes here
	int n,tmp;
	while(cin >> n && n!=0){
		p.clear();
		numbers=0;
		vector<pr > v;
		int nums[10]={},sum=0;
		for(int i=0;i<n;i++){
			cin >> tmp;
			nums[tmp]++;
		}
		for(int i=1;i<=4;i++)
			if(nums[i] && nums[10-i]){
				int manju=min(nums[i],nums[10-i]);
				sum+=manju;
				nums[i]-=manju;
				nums[10-i]-=manju;
			}
		sum+=nums[5]/2;
		nums[5]%=2;
		for(int i=1;i<=8;i++)
			if(nums[i])
				v.push_back(pr(i,nums[i]));
		cout << sum+solved(v) << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'void search(int, int*)':
a.cc:18:31: error: variable 'arafi a' has initializer but incomplete type
   18 |                         arafi a={gets[0],gets[1],gets[2],gets[3],gets[4]};
      |                               ^
a.cc: In function 'int findAns(int, int*)':
a.cc:33:15: error: variable 'arafi ar' has initializer but incomplete type
   33 |         arafi ar=p[x];
      |               ^~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]':
/usr/include/c++/14/bits/stl_vector.h:531:7:   required from here
  531 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:369:49: error: invalid use of incomplete type 'struct std::array<int, 5>'
  369 |                       _M_impl._M_end_of_storage - _M_impl._M_start);
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
   99 |     struct array;
      |            ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; size_type = long unsigned int]':
a.cc:30:15:   required from here
   30 |         if (x==p.size())
      |                ~~~~~~^~
/usr/include/c++/14/bits/stl_vector.h:993:50: error: invalid use of incomplete type 'struct std::array<int, 5>'
  993 |       { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
   99 |     struct array;
      |            ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; reference = std::array<int, 5>&; size_type = long unsigned int]':
a.cc:33:14:   required from here
   33 |         arafi ar=p[x];
      |                     ^
/usr/include/c++/14/bits/stl_vector.h:1131:41: error: invalid use of incomplete type 'struct std::array<int, 5>'
 1131 |         return *(this->_M_impl._M_start + __n);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
   99 |     struct array;
      |            ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'void std::vector<_Tp, _Alloc>::_M_erase_at_end(pointer) [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; pointer = std::array<int, 5>*]':
/usr/include/c++/14/bits/stl_vector.h:1608:9:   required from 'void std::vector<_Tp, _Alloc>::clear() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]'
 1608 |       { _M_erase_at_end(this->_M_impl._M_start); }
      |         ^~~~~~~~~~~~~~~
a.cc:61:10:   required from here
   61 |                 p.clear();
      |                 ~~~~~~~^~
/usr/include/c++/14/bits/stl_vector.h:1945:53: error: invalid use of incomplete type 'struct std::array<int, 5>'
 1945 |         if (size_type __n = this->_M_impl._M_finish - __pos)
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
   99 |     struct array;
      |            ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = std::array<int, 5>; size_type = long unsigned int]':
/usr/include/c++/14/bits/alloc_traits.h:550:23:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::deallocate(allocator_type&, pointer, size_type) [with _Tp = std::array<int, 5>; allocator_type = std::allocator<std::array<int, 5> >; pointer = std::array<int, 5>*; size_type = long unsigned int]'
  550 |       { __a.deallocate(__p, __n); }
      |         ~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:389:19:   required from 'void std::_Vector_base<_Tp, _Alloc>::_M_deallocate(pointer, std::size_t) [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; pointer = std::array<int, 5>*; std::size_t = long unsigned int]'
  389 |           _Tr::deallocate(_M_impl, __p, __n);
      |           ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:368:2:   required from 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]'
  368 |         _M_deallocate(_M_impl._M_start,
      |         ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:531:7:   required from here
  531 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/14/bits/new_allocator.h:165:13: error: invalid application of '__alignof__' to incomplete type 'std::array<int, 5>'
  165 |         if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
      |             ^~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:167:38: error: invalid application of 'sizeof' to incomplete type 'std::array<int, 5>'
  167 |             _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n),
      |                                      ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:168:55: error: invalid application of '__alignof__' to incomplete type 'std::array<int, 5>'
  168 |                                      std::align_val_t(alignof(_Tp)));
      |                                                       ^~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:172:34: error: invalid application of 'sizeof' to incomplete type 'std::array<int, 5>'
  172 |         _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
      |                                  ^~~~~~~~~~~~~~~~~~~~~~