## Algorithm

Problem Name: 2 AD-HOC - beecrowd | 1250

# KiloMan

By TopCoder* USA

Timelimit: 1

You've reached one of the last bosses in the new hit 2-D side-scrolling action game, KiloMan. The boss has a large gun that can shoot projectiles at various heights. For each shot, KiloMan can either stand still or jump. If he stands still and the shot is at height 1 or 2, then he gets hit. If he jumps and the shot is at a height above 2, then he is also hit. Otherwise, he is not hit. Given the height of each shot and a sequence of jumps, how many hits will KiloMan take?

## Input

The input contains several test cases. The first line of input contain an integer N that indicates the number of test cases. Each test case is composed by three lines and starts with a line containing the number of shots S (1 ≤ S ≤ 50). The second line contains S integers, that represent the pattern of heights at which the shots are being fired. Each element of pattern will be between 1 and 7, inclusive. The third line of input contains the string 'jumps', that represents the sequence of jumps that KiloMan will attempt; 'J' means he will jump and 'S' means he will stand still. For example, if the first number of the pattern is 3 and the first character of jumps is 'J', then KiloMan will jump right as a shot is fired at height 3 (and thus he will be hit).

## Output

For each case, your program should print an integer representing the number of times KiloMan is hit.

 Sample Input Sample Output 4 9 1 3 2 3 3 1 2 2 1 JJSSSJSSJ 49 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 7 7 7 SSSSSSSSSSSSSSJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 4 1 2 2 1 SJJS 1 1 J 4 49 2 0

## Code Examples

### #1 Code Example with C++ Programming

```Code - C++ Programming```

``````
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define MAX 210
#define INF 1000000000000000LL

using namespace std;

typedef long long int64;
typedef pair < int, int> ii;
typedef vector<int> vi;
const double EPS = 1e-10;

char comm[100];

int main()
{
int a, s, t;
scanf("%d", &t);
while (t--) {
vi res;
scanf("%d", &s);
while (s--) {
scanf("%d", &a);
res.pb(a);
}
scanf(" %s", &comm);
int resp = 0;
for (int i = 0; i  <  strlen(comm); ++i)
if (comm[i] == 'S' && res[i] <= 2)
resp++;
else if (comm[i] == 'J' && res[i] > 2)
resp++;
printf("%d\n", resp);
}
return 0;
}
``````
Copy The Code &

Input

cmd
4
9
1 3 2 3 3 1 2 2 1
JJSSSJSSJ
49
1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4
4 4 4 5 5 5 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 7 7 7
SSSSSSSSSSSSSSJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
4
1 2 2 1
SJJS
1
1
J

Output

cmd
4
49
2
0

### #2 Code Example with Python Programming

```Code - Python Programming```

``````
q = int(input())
for p in range(q):
s = int(input())
a = [int(x) for x in str(input()).split()]
m = str(input())
f = 0
for i in range(s):
if m[i] == 'S' and a[i] <= 2:
f += 1
elif m[i] == 'J' and a[i] > 2:
f += 1
print(f)

``````
Copy The Code &

Input

cmd
4
9
1 3 2 3 3 1 2 2 1
JJSSSJSSJ
49
1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4
4 4 4 5 5 5 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 7 7 7
SSSSSSSSSSSSSSJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
4
1 2 2 1
SJJS
1
1
J

Output

cmd
4
49
2
0