ololo.cpp
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cstring>
#include <string>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FI(i,b) FOR(i,0,b)
#define V(t) vector < t >
#define pb push_back
#define MEMS(a,b) memset((a),(b),sizeof(a))
#define U unsigned
#define LL long long
#define pnt pair<int,int>
#define mp make_pair
using namespace std;
vector<pair<int,int> > a;
vector<int> pos;
char s[3];
int main()
{
int l,n;
while (scanf("%d%d",&l,&n)!=EOF)
{
a.clear();
pos.clear();
int res=0;
FOR(i,0,n)
{
int x;
scanf("%d%s",&x,&s);
if (s[0]=='L')
{
a.push_back(mp(x,0));
res=max(res,x);
}
else
{
a.push_back(mp(l-x,1));
res=max(res,l-x);
}
pos.push_back(x);
}
sort(pos.begin(),pos.end());
sort(a.begin(),a.end());
int l=0,r=(int)pos.size()-1;
FOR(i,0,a.size())
{
//cout<<a[i].second<<endl;
int sz=(int)a.size();
if (i+2==sz)
{
if (a[i].first==a[i+1].first)
{
printf("The last ant will fall down in %d seconds - started at %d and %d.\n",res,pos[l],pos[l+1]);
break;
}
}
if (i+1==sz)
{
printf("The last ant will fall down in %d seconds - started at %d.\n",res,pos[l]);
break;
}
if (a[i].second==0)
l++;
else
r--;
}
}
return 0;
}