1784: 网络连接

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

TCP/IP 协议是网络通信领域的一项重要协议。今天你的任务,就是尝试利用这个协议,还原一个简化后的网络连接场景。

在本问题中,计算机分为两大类:服务机(Server)和客户机(Client)。服务机负责建立连接,客户机负责加入连接。

需要进行网络连接的计算机共有 lns="http://www.w3.org/1998/Math/MathML">n 台,编号为 lns="http://www.w3.org/1998/Math/MathML">1 \sim n,这些机器将按编号递增的顺序,依次发起一条建立连接或加入连接的操作。

每台机器在尝试建立或加入连接时需要提供一个地址串。服务机提供的地址串表示它尝试建立连接的地址,客户机提供的地址串表示它尝试加入连接的地址。

一个符合规范的地址串应当具有以下特征:

  1. 必须形如 a.b.c.d:e 的格式,其中 lns="http://www.w3.org/1998/Math/MathML">a, b, c, d, e 均为非负整数;
  2. lns="http://www.w3.org/1998/Math/MathML">0 \le a, b, c, d \le 255lns="http://www.w3.org/1998/Math/MathML">0 \le e \le 65535
  3. lns="http://www.w3.org/1998/Math/MathML">a, b, c, d, e 均不能含有多余的前导 lns="http://www.w3.org/1998/Math/MathML">0

相应地,不符合规范的地址串可能具有以下特征:

  1. 不是形如 a.b.c.d:e 格式的字符串,例如含有多于 lns="http://www.w3.org/1998/Math/MathML">3 个字符 . 或多于 lns="http://www.w3.org/1998/Math/MathML">1 个字符 : 等情况;
  2. 整数 lns="http://www.w3.org/1998/Math/MathML">a, b, c, d, e 中某一个或多个超出上述范围;
  3. 整数 lns="http://www.w3.org/1998/Math/MathML">a, b, c, d, e 中某一个或多个含有多余的前导 lns="http://www.w3.org/1998/Math/MathML">0

例如,地址串 192.168.0.255:80 是符合规范的,但 192.168.0.999:80192.168.00.1:10192.168.0.1:088192:168:0:1.233 均是不符合规范的。

如果服务机或客户机在发起操作时提供的地址串不符合规范,这条操作将被直接忽略。

在本问题中,我们假定凡是符合上述规范的地址串均可参与正常的连接,你无需考虑每个地址串的实际意义。

由于网络阻塞等原因,不允许两台服务机使用相同的地址串,如果此类现象发生,后一台尝试建立连接的服务机将会无法成功建立连接;除此之外,凡是提供符合规范的地址串的服务机均可成功建立连接。

如果某台提供符合规范的地址的客户机在尝试加入连接时,与先前某台已经成功建立连接的服务机提供的地址串相同,这台客户机就可以成功加入连接,并称其连接到这台服务机;如果找不到这样的服务机,则认为这台客户机无法成功加入连接。

请注意,尽管不允许两台不同的服务机使用相同的地址串,但多台客户机使用同样的地址串,以及同一台服务机同时被多台客户机连接的情况是被允许的。

你的任务很简单:在给出每台计算机的类型以及地址串之后,判断这台计算机的连接情况。

Input

第一行,一个正整数 lns="http://www.w3.org/1998/Math/MathML">n

接下来 lns="http://www.w3.org/1998/Math/MathML">n 行,每行两个字符串 lns="http://www.w3.org/1998/Math/MathML">\mathit{op}, \mathit{ad},按照编号从小到大给出每台计算机的类型及地址串。

其中 lns="http://www.w3.org/1998/Math/MathML">\mathit{op} 保证为字符串 Server 或 Client 之一,lns="http://www.w3.org/1998/Math/MathML">\mathit{ad} 为一个长度不超过 lns="http://www.w3.org/1998/Math/MathML">25 的,仅由数字、字符 . 和字符 : 组成的非空字符串。

每行的两个字符串之间用恰好一个空格分隔开,每行的末尾没有多余的空格。

Output

输出共 lns="http://www.w3.org/1998/Math/MathML">n 行,每行一个正整数或字符串表示第 lns="http://www.w3.org/1998/Math/MathML">i 台计算机的连接状态。其中:

如果第 lns="http://www.w3.org/1998/Math/MathML">i 台计算机为服务机,则:

  1. 如果其提供符合规范的地址串且成功建立连接,输出字符串 OK
  2. 如果其提供符合规范的地址串,但由于先前有相同地址串的服务机而无法成功建立连接,输出字符串 FAIL
  3. 如果其提供的地址串不是符合规范的地址串,输出字符串 ERR

如果第 lns="http://www.w3.org/1998/Math/MathML">i 台计算机为客户机,则:

  1. 如果其提供符合规范的地址串且成功加入连接,输出一个正整数表示这台客户机连接到的服务机的编号。
  2. 如果其提供符合规范的地址串,但无法成功加入连接时,输出字符串 FAIL
  3. 如果其提供的地址串不是符合规范的地址串,输出字符串 ERR

Sample Input Copy

5
Server 192.168.1.1:8080
Server 192.168.1.1:8080
Client 192.168.1.1:8080
Client 192.168.1.1:80
Client 192.168.1.1:99999

Sample Output Copy

OK
FAIL
1
FAIL
ERR

HINT

样例输入2


10
Server 192.168.1.1:80
Client 192.168.1.1:80
Client 192.168.1.1:8080
Server 192.168.1.1:80
Server 192.168.1.1:8080
Server 192.168.1.999:0
Client 192.168.1.1.8080
Client 192.168.1.1:8080
Client 192.168.1.1:80
Client 192.168.1.999:0
样例输出



OK
1
FAIL
FAIL
OK
ERR
ERR
5
1
ERR


【样例解释 #1】

计算机 lns="http://www.w3.org/1998/Math/MathML">1 为服务机,提供符合规范的地址串 192.168.1.1:8080,成功建立连接;

计算机 lns="http://www.w3.org/1998/Math/MathML">2 为服务机,提供与计算机 lns="http://www.w3.org/1998/Math/MathML">1 相同的地址串,未能成功建立连接;

计算机 lns="http://www.w3.org/1998/Math/MathML">3 为客户机,提供符合规范的地址串 192.168.1.1:8080,成功加入连接,并连接到服务机 lns="http://www.w3.org/1998/Math/MathML">1

计算机 lns="http://www.w3.org/1998/Math/MathML">4 为客户机,提供符合规范的地址串 192.168.1.1:80,找不到服务机与其连接;

计算机 lns="http://www.w3.org/1998/Math/MathML">5 为客户机,提供的地址串 192.168.1.1:99999 不符合规范。

【数据范围】

测试点编号 lns="http://www.w3.org/1998/Math/MathML">n \le 特殊性质
lns="http://www.w3.org/1998/Math/MathML">1 lns="http://www.w3.org/1998/Math/MathML">10 性质 1 2 3
lns="http://www.w3.org/1998/Math/MathML">2 \sim 3 lns="http://www.w3.org/1998/Math/MathML">100 性质 1 2 3
lns="http://www.w3.org/1998/Math/MathML">4 \sim 5 lns="http://www.w3.org/1998/Math/MathML">1000 性质 1 2 3
lns="http://www.w3.org/1998/Math/MathML">6 \sim 8 lns="http://www.w3.org/1998/Math/MathML">1000 性质 1 2
lns="http://www.w3.org/1998/Math/MathML">9 \sim 11 lns="http://www.w3.org/1998/Math/MathML">1000 性质 1
lns="http://www.w3.org/1998/Math/MathML">12 \sim 13 lns="http://www.w3.org/1998/Math/MathML">1000 性质 2
lns="http://www.w3.org/1998/Math/MathML">14 \sim 15 lns="http://www.w3.org/1998/Math/MathML">1000 性质 4
lns="http://www.w3.org/1998/Math/MathML">16 \sim 17 lns="http://www.w3.org/1998/Math/MathML">1000 性质 5
lns="http://www.w3.org/1998/Math/MathML">18 \sim 20 lns="http://www.w3.org/1998/Math/MathML">1000 无特殊性质

“性质 1”为:保证所有的地址串均符合规范;
“性质 2”为:保证对于任意两台不同的计算机,如果它们同为服务机或者同为客户机,则它们提供的地址串一定不同;
“性质 3”为:保证任意一台服务机的编号都小于所有的客户机;
“性质 4”为:保证所有的地址串均形如 a.b.c.d:e 的格式,其中 lns="http://www.w3.org/1998/Math/MathML">a, b, c, d, e 均为不超过 lns="http://www.w3.org/1998/Math/MathML">{10}^9 且不含有多余前导 lns="http://www.w3.org/1998/Math/MathML">0 的非负整数;
“性质 5”为:保证所有的地址串均形如 a.b.c.d:e 的格式,其中 lns="http://www.w3.org/1998/Math/MathML">a, b, c, d, e 均为只含有数字的非空字符串。

对于 lns="http://www.w3.org/1998/Math/MathML">100 \% 的数据,保证 lns="http://www.w3.org/1998/Math/MathML">1 \le n \le 1000