Vladik and flights CodeForces

来源:互联网 发布:山东大学 李利平 知乎 编辑:程序博客网 时间:2024/05/18 03:46

Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.

Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport.

To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airportb.

Each airport belongs to one of two companies. The cost of flight from the airport ito the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.

Print the minimum cost Vladik has to pay to get to the olympiad.

Input

The first line contains three integers na, and b (1 ≤ n ≤ 1051 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.

The second line contains a string with length n, which consists only of characters 0and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.

Output

Print single integer — the minimum cost Vladik has to pay to get to the olympiad.

Example
Input
4 1 41010
Output
1
Input
5 5 210110
Output
0
Note

In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1(because the airports belong to different companies), and then fly from the airport2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1.

In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.

题意:有个人要坐飞机,“0”“1”代表两家不同的航空公司,第一个数代表航线中的公司分布,后面的两个数是起始点和重点站的位置,如果跨行的话会收取|1-2|的费用,也就是1,如果相同公司就不会收取费用,求最少的费用,

分析:结果只有两种情况,一种是0另一种是1因为就两家公司,所以结果显而易见

#include <cstdio>#include <algorithm>#include <iostream>#include <queue>#include <string.h>#include <math.h>#include <cmath>using namespace std;int main(){    int n,a,b;    cin>>n>>a>>b;    char sum[100001];    cin>>sum;    if(sum[a-1]==sum[b-1])    {        printf("0\n");    }    else    {        printf("1\n");    }}


原创粉丝点击