Problem:
Problem B:
The Last Ant
A straight tunnel without branches is crowded with busy ants coming and going. Some ants walk left to right and others right to left. All ants walk at a constant speed of 1 cm/s. When two ants meet, they try to pass each other. However, some sections of the tunnel are narrow and two ants cannot pass each other. When two ants meet at a narrow section, they turn around and start walking in the opposite directions. When an ant reaches either end of the tunnel, it leaves the tunnel.
The tunnel has an integer length in centimeters. Every narrow section of the tunnel is integer centimeters distant from the both ends. Except for these sections, the tunnel is wide enough for ants to pass each other. All ants start walking at distinct narrow sections. No ants will newly enter the tunnel. Consequently, all the ants in the tunnel will eventually leave it. Your task is to write a program that tells which is the last ant to leave the tunnel and when it will.
Figure B.1 shows the movements of the ants during the first two seconds in a tunnel 6 centimeters long. Initially, three ants, numbered 1, 2, and 3, start walking at narrow sections, 1, 2, and 5 centimeters distant from the left end, respectively. After 0.5 seconds, the ants 1 and 2 meet at a wide section, and they pass each other. Two seconds after the start, the ants 1 and 3 meet at a narrow section, and they turn around.
Figure B.1 corresponds to the first dataset of the sample input.
Figure B.1. Movements of ants
Input
The input consists of one or more datasets. Each dataset is formatted as follows.
n
l
d
1
p
1
d
2
p
2
...
d
n
p
n
The first line of a dataset contains two integers separated by a space.
n
(1 ≤
n
≤ 20) represents the number of ants, and
l
(
n
+ 1 ≤
l
≤ 100) represents the length of the tunnel in centimeters. The following
n
lines describe the initial states of ants. Each of the lines has two items,
d
i
and
p
i
, separated by a space. Ants are given numbers 1 through
n
. The ant numbered
i
has the initial direction
d
i
and the initial position
p
i
. The initial direction
d
i
(1 ≤
i
≤
n
) is
L
(to the
left) or
R
(to the right). The initial position
p
i
(1 ≤
i
≤
n
) is an integer specifying the distance from the left end of the tunnel in centimeters. Ants are listed in the left to right order, that is, 1 ≤
p
1
<
p
2
< ... <
p
n
≤
l
- 1.
The last dataset is followed by a line containing two zeros separated by a space.
Output
For each dataset, output how many seconds it will take before all the ants leave the tunnel, and which of the ants will be the last. The last ant is identified by its number. If two ants will leave at the same time, output the number indicating the ant that will leave through the left end of the tunnel.
Sample Input
3 6
R 1
L 2
L 5
1 10
R 1
2 10
R 5
L 7
2 10
R 3
L 8
2 99
R 1
L 98
4 10
L 1
R 2
L 8
R 9
6 10
R 2
R 3
L 4
R 6
L 7
L 8
0 0
Output for the Sample Input
5 1
9 1
7 1
8 2
98 2
8 2
8 3

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  while(1){
    int n,L;cin >> n >> L;
    if(!n)break;
    vector<pii> v(n);
    vi C(L+1);
    rep(i,0,n){
      char d;int p;cin >> d >> p;
      if(d == 'L')v[i] = {p,-1};
      else v[i] = {p,1};
      C[p]++;
    }
    int lst = -1,tm = -1;
    rep(_,0,n*n*(L+1)+10){
      rep(i,0,n){
        auto &[p,d] = v[i];
        if(p == 0 || p == L)continue;
        C[p]--;p += d;C[p]++;
        if(p == 0){lst = i+1;tm = _;}
        else if(p == L){
          if(tm != _){lst = i+1;tm = _;}
        }
      }
      rep(i,0,n){
        auto &[p,d] = v[i];
        if(p != 0 && p != L && C[p] > 1)d *= -1;
      }
    }
    cout << tm+1 << " " << lst << "\n";
  }
  

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3304
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    while (1) {
        ll N,L;
        cin>>N>>L;
        if(N==0)return 0;
        vll D(N,-1),P(N);
        vll AN(N,-1);
        rep(i,N){
            char C;
            cin>>C>>P[i];
            if(C=='R')D[i]=1;
        }
        ll an=0;
        ll A=-1;
        rep(j,10000){
            map<ll,ll> M;
            rep(i,N){
                P[i]+=D[i];
                //cout<<i<<" "<<P[i]<<endl;
                M[P[i]]++;
            }
            rep(i,N){
                if(M[P[i]]>=2){
                    D[i]*=-1;
                }
                
                if(P[i]==L){
                    P[i]=1e17;
                    if(an==j)continue;
                    //cout<<"#"<<i<<" "<<j<<endl;
                    an=j;
                    A=i+1;
                }
                if(P[i]==0){
                    P[i]=1e17;
                    //cout<<i<<" "<<j<<endl;
                    an=j;
                    A=i+1;
                }
            }
        }
        cout<<an+1<<" "<<A<<endl;


    }

}
accuracy: 1
time_ms: 210
memory_kb: 3148
final_rank: 7

code_snippet: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, l;
    while (cin >> n >> l && n){
        VI p(n), v(n);
        REP(i,n){
            char c;
            cin >> c >> p[i];
            if (c == 'R') v[i] = 1;
            else v[i] = -1;
        }
        FOR(t,1,l){
            map<int, int> a;
            REP(i,n){
                p[i] += v[i];
                a[p[i]]++;
            }
            FOR(i,1,l-1){
                if (a[i] >= 2){
                    REP(j,n){
                        if (p[j] == i) v[j] *= -1;
                    }
                }
            }
            bool f = 1;
            REP(i,n) if (p[i] > 0 && p[i] < l) f = 0;
            if (f){
                int ans;
                REP(i,n) if (p[i] == l) ans = i+1;
                REP(i,n) if (p[i] == 0) ans = i+1;
                cout << t << " " << ans << endl;
                break;
            }
        }

    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3072
final_rank: 5

code_snippet: // Header {{{
// includes {{{
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <unistd.h>
#include <vector>
// }}}
using namespace std;
// consts {{{
static const int INF = 1e9;
static const double PI = acos(-1.0);
static const double EPS = 1e-10;
// }}}
// typedefs {{{
typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<ULL> VULL;
typedef vector<VULL> VVULL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef pair<int, int> PII;
typedef complex<int> P;
// }}}
// macros & inline functions {{{
// syntax sugars {{{
#define FOR(i, b, e) for (typeof(e) i = (b); i < (e); ++i)
#define FORI(i, b, e) for (typeof(e) i = (b); i <= (e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPI(i, n) FORI(i, 0, n)
#define OPOVER(_op, _type) inline bool operator _op (const _type &t) const
// }}}
// conversion {{{
inline int toInt(string s) { int v; istringstream sin(s); sin>>v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout<<x; return sout.str(); }
// }}}
// array and STL {{{
#define ARRSIZE(a) ( sizeof(a) / sizeof(a[0]) )
#define ZERO(a, v) ( assert(v == 0 || v == -1), memset(a, v, sizeof(a)) )
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define SIZE(a) ((LL)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(c, it) for(typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define REACH(c, it) for(typeof((c).rbegin()) it=(c).rbegin(); it!=(c).rend(); ++it)
#define EXIST(s, e) ((s).find(e) != (s).end())
// }}}
// bit manipulation {{{
// singed integers are not for bitwise operations, specifically arithmetic shifts ('>>', and maybe not good for '<<' too)
#define IS_UNSIGNED(n) (!numeric_limits<typeof(n)>::is_signed)
#define BIT(n) (assert(IS_UNSIGNED(n)), assert(n < 64), (1ULL << (n)))
#define BITOF(n, m) (assert(IS_UNSIGNED(n)), assert(m < 64), ((ULL)(n) >> (m) & 1))
inline int BITS_COUNT(ULL b) { int c = 0; while(b != 0) { c += (b & 1); b >>= 1; } return c; }
inline int MSB(ULL b) { int c = 0; while(b != 0) { ++c; b >>= 1; } return c-1; }
inline int MAKE_MASK(ULL upper, ULL lower) { assert(lower < 64 && upper < 64 && lower <= upper); return (BIT(upper) - 1) ^ (BIT(lower) - 1); }
// }}}
// for readable code {{{
#define EVEN(n) (n % 2 == 0)
#define ODD(n) (!EVEN(n))
// }}}
// debug {{{
#define arrsz(a) ( sizeof(a) / sizeof(a[0]) )
#define dprt(fmt, ...) if (opt_debug) { fprintf(stderr, fmt, ##__VA_ARGS__); }
#define darr(a) if (opt_debug) { copy( (a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ") ); cerr << endl; }
#define darr_range(a, f, t) if (opt_debug) { copy( (a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ") ); cerr << endl; }
#define dvec(v) if (opt_debug) { copy( ALL(v), ostream_iterator<int>(cerr, " ") ); cerr << endl; }
#define darr2(a) if (opt_debug) { FOR(__i, 0, (arrsz(a))){ darr( (a)[__i] ); } }
#define WAIT() if (opt_debug) { string _wait_; cerr << "(hit return to continue)" << endl; getline(cin, _wait_); }
#define dump(x) if (opt_debug) { cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl; }
#define dumpl(x) if (opt_debug) { cerr << " [L" << __LINE__ << "] " << #x << endl << (x) << endl; }
#define dumpf() if (opt_debug) { cerr << __PRETTY_FUNCTION__ << endl; }
#define where() if (opt_debug) { cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__ << "]" << endl; }
#define show_bits(b, s) if(opt_debug) { REP(i, s) { cerr << BITOF(b, s-1-i); if(i%4 == 3) cerr << ' '; } cerr << endl; }

// ostreams {{{
// complex
template<typename T> ostream& operator<<(ostream& s, const complex<T>& d) {return s << "(" << d.real() << ", " << d.imag() << ")";}

// pair
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& d) {return s << "(" << d.first << ", " << d.second << ")";}

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d) {
	int len = d.size();
	REP (i, len) {
		s << d[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

// 2 dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& d) {
	int len = d.size();
	REP (i, len) {
		s << d[i] << endl;
	}
	return s;
}

// map
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}
// }}}
// }}}
// }}}
// time {{{
inline double now(){ struct timeval tv; gettimeofday(&tv, NULL); return (static_cast<double>(tv.tv_sec) + static_cast<double>(tv.tv_usec) * 1e-6); }
// }}}
// string manipulation {{{
inline VS split(string s, char delimiter) { VS v; string t; REP(i, s.length()) { if(s[i] == delimiter) v.PB(t), t = ""; else t += s[i]; } v.PB(t); return v; }
inline string join(VS s, string j) { string t; REP(i, s.size()) { t += s[i] + j; } return t; }
// }}}
// geometry {{{
#define Y real()
#define X imag()
// }}}
// 2 dimentional array {{{
P dydx4[4] = { P(-1, 0), P(0, 1), P(1, 0), P(0, -1) };
P dydx8[8] = { P(-1, 0), P(0, 1), P(1, 0), P(0, -1), P(-1, 1), P(1, 1), P(1, -1), P(-1, -1) };
int g_height, g_width;
bool in_field(P p) {
	return (0 <= p.Y && p.Y < g_height) && (0 <= p.X && p.X < g_width);
}
// }}}
// input and output {{{
inline void input(string filename) {
	freopen(filename.c_str(), "r", stdin);
}
inline void output(string filename) {
	freopen(filename.c_str(), "w", stdout);
}
// }}}
// }}}

// Header under development {{{

int LCM(int a, int b) {
	// FIXME
	return a * b;
}

// Fraction class {{{
// ref: http://martin-thoma.com/fractions-in-cpp/
class Fraction {
	public:
		ULL numerator;
		ULL denominator;
		Fraction(ULL _numerator, ULL _denominator) {
			assert(_denominator > 0);
			numerator = _numerator;
			denominator = _denominator;
		};

		Fraction operator*(const ULL rhs) {
			return Fraction(this->numerator * rhs, this->denominator);
		};

		Fraction operator*(const Fraction& rhs) {
			return Fraction(this->numerator * rhs.numerator, this->denominator * rhs.denominator);
		}

		Fraction operator+(const Fraction& rhs) {
			ULL lcm = LCM(this->denominator, rhs.denominator);
			ULL numer_lhs = this->numerator * (this->denominator / lcm);
			ULL numer_rhs = rhs.numerator * (rhs.numerator / lcm);
			return Fraction(numer_lhs + numer_rhs, lcm);
		}

		Fraction& operator+=(const Fraction& rhs) {
			Fraction result = (*this) + rhs;
			this->numerator = result.numerator;
			this->denominator = result.denominator;
			return *this;
		}
};

std::ostream& operator<<(std::ostream &s, const Fraction &a) {
	if (a.denominator == 1) {
		s << a.numerator;
	} else {
		s << a.numerator << "/" << a.denominator;
	}
	return s;
}

// }}}

// }}}

bool opt_debug = false;

class Ant {
	public:
		int id;
		char direction;
		Ant(int _id, char _direction) : id(_id), direction(_direction) {
		}
};

int main(int argc, char** argv) {
	std::ios_base::sync_with_stdio(false);
	// set options {{{
	int __c;
	while ( (__c = getopt(argc, argv, "d")) != -1 ) {
		switch (__c) {
			case 'd':
				opt_debug = true;
				break;
			default:
				abort();
		}
	}
	// }}}

	// input("./inputs/0.txt");
	// output("./outputs/0.txt");

	int n, l;
	while(cin >> n >> l, n | l) {
		vector< vector<Ant> > ants(l + 1, vector<Ant>());
		int n_ants = n;
		REP (i, n) {
			char d; int p; cin >> d >> p;
			Ant a(i+1, d);
			ants[p].PB(a);
		}

		int sec = 0;
		Ant ans(0, ' ');
		while (n_ants) {
			sec++;
			vector< vector<Ant> > next_ants(l + 1, vector<Ant>());
			// REP (i, l + 1) {
			for (int i = l; i >= 0; --i) {
				if (i == l && ants[i].size()) {
					ans = ants[i][0];
					n_ants--;
					continue;
				}
				if (i == 0 && ants[i].size()) {
					ans = ants[i][0];
					n_ants--;
					continue;
				}

				EACH (ants[i], itr) {
					Ant& ant = *itr;
					if (ant.direction == 'L') {
						next_ants[i-1].PB(ant);
					} else {
						next_ants[i+1].PB(ant);
					}
				}
			}

			REP (i, l + 1) {
				assert(next_ants[i].size() <= 2);
				if (next_ants[i].size() == 2) {
					EACH (next_ants[i], itr) {
						(*itr).direction = (*itr).direction == 'L' ? 'R' : 'L';
					}
				}
			}

			ants = next_ants;
		}

		cout << sec - 1 << " " << ans.id << endl;
	}

	return 0;
}

// vim: foldmethod=marker
accuracy: 1
time_ms: 10
memory_kb: 1236
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#include <regex>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 1145141919;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int main()
{
	int n, l;
	while (cin >> n >> l,n)
	{
		vector<P> v;
		REP(i, n)
		{
			char c; int p;
			cin >> c >> p;
			v.push_back(P(c == 'L' ? -1 : 1, p));
		}
		int res = n;
		int cnt = 0;
		P lastl,lastr;
		while (res)
		{
			cnt++;
			map<int, vector<int>> m;
			REP(i, v.size())
			{
				v[i].second += v[i].first;
				m[v[i].second].push_back(i);
				if (v[i].second == 0)
				{
					lastl = P(cnt, i);
					res--;
				}
				if (v[i].second == l)
				{
					lastr = P(cnt, i);
					res--;
				}
			}
			REP(i, l)
			{
				if (m[i].size() == 2)
				{
					swap(v[m[i][0]].first, v[m[i][1]].first);
				}
			}
		}
		cout << cnt << " " << (lastl.first >= lastr.first ? lastl.second + 1 : lastr.second + 1) << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1220
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define MAX 110

bool check(int ant[MAX],int L){
  for(int i = 0 ; i < L ; i++){
    if(ant[i] != 0) return false;
  }
  return true;
}

int main(){
  int N,L,p;
  char d;
  while(cin >> N >> L, N){
    int ant[MAX]={0};
    vector<int> tunnel[MAX],id[MAX];
    L--;
    for(int i = 0 ; i < N ; i++){
      cin >> d >> p;
      ant[p-1]++;
      id[p-1].push_back(i+1);
      tunnel[p-1].push_back((d == 'L' ? 1 : 2));
    }
    int t = 0,last;
    while(!check(ant,L)){
      vector<int> next[MAX],nid[MAX];
      last = -1;
      for(int i = 0 ; i < L ; i++){
        next[i].clear();
        nid[i].clear();
        if(ant[i] && last == -1){
          last = id[i][0];
        }
      }
      for(int i = 0 ; i < L ; i++){
        while(tunnel[i].size()){
          if(tunnel[i][0] == 1){
            tunnel[i].erase(tunnel[i].begin());
            if(i-1 >= 0){
              next[i-1].push_back(1);
              nid[i-1].push_back(id[i][0]);
              id[i].erase(id[i].begin());
            }
          }else if(tunnel[i][0] == 2){
            tunnel[i].erase(tunnel[i].begin());
            if(i+1 < L){
              next[i+1].push_back(2);
              nid[i+1].push_back(id[i][0]);
              id[i].erase(id[i].begin());
            }
          }
        }
      }
      for(int i = 0 ; i < L ; i++){
        tunnel[i] = next[i];
        id[i] = nid[i];
        if(tunnel[i].size() == 2){
          swap(tunnel[i][0],tunnel[i][1]);
        }
        ant[i] = tunnel[i].size();
      }
      t++;
    }
    cout << t << " " << last << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1236
final_rank: 2

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define MAX 110
typedef pair<char,int> P;

bool check(int ant[MAX],int L){
  for(int i = 0 ; i < L ; i++){
    if(ant[i] != 0) return false;
  }
  return true;
}

int main(){
  int N,L,p;
  char d;
  while(cin >> N >> L, N){
    int ant[MAX]={0};
    vector<int> tunnel[MAX],id[MAX];
    L--;
    for(int i = 0 ; i < N ; i++){
      cin >> d >> p;
      ant[p-1]++;
      id[p-1].push_back(i+1);
      tunnel[p-1].push_back((d == 'L' ? 1 : 2));
    }
    int t = 0,last;
    while(!check(ant,L)){
      vector<int> next[MAX],nid[MAX];
      last = -1;
      for(int i = 0 ; i < L ; i++){
        next[i].clear();
        nid[i].clear();
        if(ant[i] && last == -1){
          last = id[i][0];
        }
      }
      for(int i = 0 ; i < L ; i++){
        while(tunnel[i].size()){
          if(tunnel[i][0] == 1){
            tunnel[i].erase(tunnel[i].begin());
            if(i-1 >= 0){
              next[i-1].push_back(1);
              nid[i-1].push_back(id[i][0]);
              id[i].erase(id[i].begin());
            }
          }else if(tunnel[i][0] == 2){
            tunnel[i].erase(tunnel[i].begin());
            if(i+1 < L){
              next[i+1].push_back(2);
              nid[i+1].push_back(id[i][0]);
              id[i].erase(id[i].begin());
            }
          }
        }
      }
      for(int i = 0 ; i < L ; i++){
        tunnel[i] = next[i];
        id[i] = nid[i];
        if(tunnel[i].size() == 2){
          swap(tunnel[i][0],tunnel[i][1]);
        }
        ant[i] = tunnel[i].size();
      }
      t++;
    }
    cout << t << " " << last << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1232
final_rank: 1