1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

#define N_MAX 300005

#ifndef DEB_VAL
  #define DEB_VAL 0
#endif
#define DEB if(debug)

#define MP make_pair
#define PB push_back
#define FT first
#define SD second

int debug = DEB_VAL;

int n;
char input[N_MAX];

int L_left[N_MAX];
int L_right[N_MAX];
int P_left[N_MAX];
int P_right[N_MAX];

int main() {
  DEB { printf("UWAGA\n"); }
  scanf("%d", &n);
  scanf("%s", input);
  int act_l=0;
  int act_p=0;
  for(int i=0;i<n;i++) {
    L_left[i] = act_l;
    P_left[i] = act_p;
    if(input[i]=='L') {
      act_l++;
    } else {
      act_p++;
    }
  }
  act_l=0;
  act_p=0;
  for(int i=n-1;i>=0;i--) {
    L_right[i] = act_l;
    P_right[i] = act_p;
    if(input[i]=='L') {
      act_l++;
    } else {
      act_p++;
    }
  }
  DEB {
    for(int i=0;i<n;i++) {
      printf("%d, ", L_left[i]);
    }
    printf("\n");
    for(int i=0;i<n;i++) {
      printf("%d, ", L_right[i]);
    }
    printf("\n");
    for(int i=0;i<n;i++) {
      printf("%d, ", P_left[i]);
    }
    printf("\n");
    for(int i=0;i<n;i++) {
      printf("%d, ", P_right[i]);
    }
    printf("\n");
  }
  //output
  for(int i=0;i<n;i++) {
    if(input[i]=='P') {
      if(L_right[i] > P_left[i]) printf("%d ", P_left[i]*2+1);
      else printf("%d ", L_right[i]*2);
    } else {
      if(P_left[i] > L_right[i]) printf("%d ", L_right[i]*2+1);
      else printf("%d ", P_left[i]*2);
    }
  }
  DEB { printf("\n"); }
  return 0;
}