ants.cpp
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define DEBUG(x) cerr << ">>> " << #x << " : " << x << endl;
#define REP(i,a) for (int i = 0; i < (a); ++i)
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for (int i = (a); i >= (b); --i)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
//////////////////////////////////
#define MAXN 100000
int start[MAXN];
bool dir[MAXN];
int L, N;
int main() {
char tmp[5];
while(scanf("%d%d", &L, &N) != EOF){
int left = 0;
int max_left = -1, max_right = -1;
REP(i, N){
scanf("%d %s", start + i, tmp);
dir[i] = (tmp[0] == 'L');
left += dir[i];
if(dir[i]) max_left = max(max_left, start[i]);
else max_right = max(max_right, L - start[i]);
}
sort(start, start + N);
if(max_left > max_right) printf("The last ant will fall down in %d seconds - started at %d.\n", max_left, start[left-1]);
if(max_left < max_right) printf("The last ant will fall down in %d seconds - started at %d.\n", max_right, start[left]);
if(max_left == max_right) printf("The last ant will fall down in %d seconds - started at %d and %d.\n", max_right, start[left-1], start[left]);
}
return 0;
}