LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDEInteractive TasksOutput-Only Tasks
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search FunctionsBinary Search by AnswerDivide and Conquer
Binary Numbers
Binary NumbersNumbers in codeBitwise OperationsBitmasks
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueueMapsSetsPriority QueueCustom Criteria for FunctionsSegment TreesFenwick TreesSparse TablesUnion FindSqrt Decomposition
Combinatorics
Addition RuleMultiplication RuleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsCross and Dot ProductLinesPolygonsPoints and PolygonsConvex Hull
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPDP problemsTree DPBitmask DP
Graph Theory
GraphsDFS and BFSShortest PathsTreesTopological SortingDijkstra's AlgorithmMinimum Spanning TreesShortest Path Algorithms
Advanced Graph Theory
BiconnectivityStrongly Connected ComponentsBipartite GraphGraph FlowAugmenting PathsFlow - Minimum Cut DualityHeavy-Light DecompositionCentroid Decomposition
Advanced Data Structures
2D and 3D Segment TreesLazy PropagationImplicit Segment TreesPersistent Segment TreesLowest Common AncestorTrieBalanced Binary Search TreesMo's Algorithm

Permutation Check

Super EasyProblem #40
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

Look at how big the values can get before you choose the type of the key.

Lena wrote a function that shuffles an array - it should return the same numbers in a random order and nothing else. She ran it on a pile of test arrays, but looking at the results she cannot tell whether the function is correct.

Help her: given the array she started from and the array her function returned, check whether the second one is a permutation of the first, meaning it can be obtained from it by only changing the order of its elements. Equal numbers may repeat, and then they have to repeat the same number of times in both arrays.

Input

First line of input will be a single integer t - the number of testcases.
First line of each testcase contains an integer n - the length of the starting array, and the second line contains its n elements.
Third line contains an integer m - the length of the returned array, and the fourth line contains its m elements.

Output

For every testcase print YES if the second array is a permutation of the first one, and NO otherwise.

Example

Input
2
5
1 3 2 4 3
5
4 3 2 3 1
3
1000000000000000000 5 1000000000000000000
3
1000000000000000000 5 5
Output
YES
NO

In the first testcase both arrays contain one 1, one 2, two 3s and one 4. In the second one the value 1018 appears twice in the starting array but only once in the returned one, so the function lost a number.

Constraints

1≤t≤10
1≤n,m≤105
the sum of n+m over all testcases does not exceed 4⋅105
1≤ai​≤1018


This problem was adapted, with permission, from Provera permutacija, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit