There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts.

  • Current character pointer (CP);
  • Direction pointer (DP) which can point left or right;

Initially CP points to the leftmost character of the sequence and DP points to the right.

We repeat the following steps until the first moment that CP points to somewhere outside the sequence.

  • If CP is pointing to a digit the interpreter prints that digit then CP moves one step according to the direction of DP. After that the value of the printed digit in the sequence decreases by one. If the printed digit was 0 then it cannot be decreased therefore it's erased from the sequence and the length of the sequence decreases by one.
  • If CP is pointing to "<" or ">" then the direction of DP changes to "left" or "right" correspondingly. Then CP moves one step according to DP. If the new character that CP is pointing to is "<" or ">" then the previous character will be erased from the sequence.

If at any moment the CP goes outside of the sequence the execution is terminated.

It's obvious the every program in this language terminates after some steps.

We have a sequence s1, s2, ..., sn of "<", ">" and digits. You should answer q queries. Each query gives you l and r and asks how many of each digit will be printed if we run the sequence sl, sl + 1, ..., sr as an independent program in this language.

Input

The first line of input contains two integers n and q (1 ≤ n, q ≤ 100) — represents the length of the sequence s and the number of queries.

The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces.

The next q lines each contains two integers li and ri (1 ≤ li ≤ ri ≤ n) — the i-th query.

Output

For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input.

Examples

input

7 4
1>3>22<
1 3
4 7
7 7
1 7

output

0 1 0 1 0 0 0 0 0 0
2 2 2 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
2 3 2 1 0 0 0 0 0 0

这是一道模拟题,模拟一个他叙述的过程就是一个指针一个方向标记遇到>改成向右的方向,遇见<改成向左,每次遇到数字输出数字并将数字减一,减到零就删去,遇到连续的两个方向就删去先访问的那一个,给定一个子区间,求0-9输出了几遍。

#include<bits/stdc++.h>
#define Swap(a,b) a^=b^=a^=b
#define cini(n) scanf("%d",&n)
#define cinl(n) scanf("%lld",&n)
#define cinc(n) scanf("%c",&n)
#define coui(n) printf("%d",n)
#define couc(n) printf("%c",n)
#define coul(n) printf("%lld",n)
#define speed ios_base::sync_with_stdio(0);//切不可用scnaf;
#define Max(a,b) a>b?a:b
#define Min(a,b) a<b?a:b
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=1e6+10;
const double esp=1e-9;
int m,n,x,y,lll[maxn],rr[maxn];
int l[110];
int r[110];
int ans[10];
string w;
int a[10]; int main()
{
cin>>n>>m>>w;
while(m--)
{
int l,r;
cin>>l>>r;
memset(a,0,sizeof(a));
string t=w.substr(l-1,r-l+1);
int lll=0,rr=1;
int E=t.size();
while(lll>=0&&lll<E)
{
if(t[lll]>='0'&&t[lll]<='9')
{
a[t[lll]-'0']++;
t[lll]--;
if(t[lll]<'0')
{
t.erase(lll,1);
if(rr<0)lll+=rr;
}
else lll+=rr;
}
else
{
if(t[lll]=='<') rr=-1;
else rr=1;
if(lll+rr>=0&&lll+rr<E&&(t[lll+rr]=='<'||t[lll+rr]=='>'))
{
t.erase(lll,1);
if(rr<0) lll+=rr;
}
else lll+=rr;
}
}
for(int i=0;i<10; i++)
cout<<a[i]<<' ';
cout<<endl;
}
return 0;
}

最新文章

  1. UI: 概述, 启动屏幕, 屏幕方向
  2. 【入门】 jpa--实体管理器的基本应用
  3. ASP.NET高并发解决方案
  4. 怎么通过URL访问到服务器上的物理文件
  5. innodb buffer pool flush机制
  6. oracle tns in linux
  7. 一段JAVA签名算法的PHP改写
  8. Candy 解答
  9. UpdatePanel + 弹出框
  10. EasyUI - NumberSpinner 组件
  11. POJ 1276  Cash Machine(多重背包)
  12. C++程序中应增加STL、运算和字符串的头文件
  13. 【开发笔记】Spring的配置文件
  14. effective java笔记之单例模式与序列化
  15. Hexo next博客添加折叠块功能添加折叠代码块
  16. Centos 6.5 安装 rar
  17. springboot项目利用devtools实现热部署,改动代码自动生效
  18. ZJOI2019一轮停课刷题记录
  19. [Swift]LeetCode306. 累加数 | Additive Number
  20. sopUI上手教程

热门文章

  1. tp6源码解析-第二天,ThinkPHP6编译模板流程详解,ThinkPHP6模板源码详解
  2. 在OS X环境下MySQL启动时报错
  3. Web Scraper 高级用法——使用 CouchDB 存储数据 | 简易数据分析 18
  4. 1 - Apache HttpClient 简单使用
  5. bfs和dfs辨析—基础复习(从stack和queue的角度来理解区别,加深理解,不再模糊)
  6. UML(续)
  7. Matlab学习-(3)
  8. TortoiseSVN的使用,以及冲突解决办法
  9. mysql 使用记录
  10. Serlvet容器与Web应用