Algorithm


A. Spit Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.

The trajectory of a camel's spit is an arc, i.e. if the camel in position x spits d meters right, he can hit only the camel in position x + d, if such a camel exists.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the amount of camels in the zoo. Each of the following n lines contains two integers xi and di ( - 104 ≤ xi ≤ 104, 1 ≤ |di| ≤ 2·104) — records in Bob's notepad. xi is a position of the i-th camel, and di is a distance at which the i-th camel spitted. Positive values of di correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.

Output

If there are two camels, which spitted at each other, output YES. Otherwise, output NO.

Examples
input
Copy
2
0 1
1 -1
output
Copy
YES
input
Copy
3
0 1
1 1
2 -2
output
Copy
NO
input
Copy
5
2 -10
3 10
0 5
5 -5
10 1
output
Copy
YES



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

int main(){

    long n(0); scanf("%ld", &n);

    std::vector<std::pair<long, long>> events;
    for(long k = 0; k < n; k++){
        long pos(0), spit(0); scanf("%ld %ld", &pos, &spit);
        if(spit < 0){spit *= -1; pos -= spit;}
        events.push_back(std::pair<long,long>(pos,spit));
    }

    std::sort(events.begin(), events.end());

    bool mutual(0);
    for(long k = 0; k < n - 1; k++){if(events[k].first == events[k+1].first && events[k].second == events[k+1].second){mutual = 1; break;}}

    if(mutual){puts("YES");} else{puts("NO");}

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2
0 1
1 -1

Output

x
+
cmd
YES
Advertisements

Demonstration


Codeforces Solution-A. Spit Problem-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+