跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1933. Dancing Lessons

    ID: 1939 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数据结构提高难度共享题库Codeforces英文题面题目来源题面语言

Dancing Lessons

题目描述

C. Dancing Lessons
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, having the minimal difference in dancing skills start to dance. If there are several such couples, the one first from the left starts to dance. After a couple leaves to dance, the line closes again, i.e. as a result the line is always continuous. The difference in dancing skills is understood as the absolute value of difference of ai variable. Your task is to find out what pairs and in what order will start dancing.

Input

The first line contains an integer n (1≤n≤2·105) − the number of people. The next line contains n symbols B or G without spaces. B stands for a boy, G stands for a girl. The third line contains n space-separated integers ai (1≤ai≤107) − the dancing skill. People are specified from left to right in the order in which they lined up.

Output

Print the resulting number of couples k. Then print k lines containing two numerals each − the numbers of people forming the couple. The people are numbered with integers from 1 to n from left to right. When a couple leaves to dance you shouldn't renumber the people. The numbers in one couple should be sorted in the increasing order. Print the couples in the order in which they leave to dance.

Examples
Input
4
BGBG
4 2 4 3
Output
2
3 4
1 2
Input
4
BBGG
4 6 1 5
Output
2
2 3
1 4
Input
4
BGBB
1 1 2 3
Output
1
1 2

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1513 题。保留原作者与原赛事署名。