LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDE
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 Find
Combinatorics
Addition PrincipleMultiplication PrincipleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsVectorsCross and Dot ProductLinesPolygonsAnglesPoint in PolygonDistances and Intersection PointsConvex HullCircles
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPTree DPBitmask DPDigit 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

The Crowded Pool

MediumProblem #33
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

A visitor who leaves at some moment is not at the pool in that moment.

People came and went from a swimming pool all day, and for every visitor the arrival time and the departure time are known. A visitor is at the pool during the period [a,b): they are there at the moment of their arrival a, and are not there at the moment of their departure b. Your task is to determine the largest number of people that were at the pool at the same moment.

Input

First line of input will be a single integer t - the number of testcases.
Each testcase starts with a line containing an integer n - the number of visitors, followed by n lines with two integers a and b each - one visitor's arrival and departure time.

Output

For every testcase print a single line with the largest number of visitors present at the same moment.

Example

Input
1
8
3 7
7 8
2 5
6 8
4 6
1 6
4 5
1 2
Output
5

At moment 4 the visitors with periods [3,7), [2,5), [4,6), [1,6) and [4,5) are all at the pool - five of them.

Constraints

1≤t≤1000
1≤n≤2⋅105
0≤a<b≤109
n1​+n2​+…+nt​≤2⋅105


This problem was adapted, with permission, from Najbrojniji presek intervala, 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