#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <functional>
using namespace std;
template <class InputIterator1, class InputIterator2>
bool _is_permutation (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2)
{
//tie函数将first1和first2绑定,后面对first1和first2的操作同时影响前面,
//返回的是第一处不匹配的两个指针
tie (first1,first2) = mismatch (first1,last1,first2);
if (first1==last1) return true;
InputIterator2 last2 = first2;
advance (last2,distance(first1,last1));//将last2指针后移
for (InputIterator1 it1=first1; it1!=last1; ++it1) {
if (find(first1,it1,*it1)==it1) {//这么处理是为了避免多次计算重复的元素
auto n = count (first2,last2,*it1);
if (n==0 || count (it1,last1,*it1)!=n) return false;
}
}
return true;
}
int main(){
array<int,8> t1 = {3,5,7,11,13,17,19,23};
array<int,8> t2 = {19,23,3,5,7,11,13,17};
if(_is_permutation(t1.begin(),t1.end(),t2.begin()))cout<<"is";
return 0;
}