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
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#ifdef DEBUG
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif

struct Num {
	static constexpr int digits_per_elem = 9, base = int(1e9);
	vector<int> x;

	Num& shorten() {
		while(ssize(x) and x.back() == 0)
			x.pop_back();
		for(int a : x)
			assert(0 <= a and a < base);
		return *this;
	}

	Num(const string& s) {
		for(int i = ssize(s); i > 0; i -= digits_per_elem)
			if(i < digits_per_elem)
				x.emplace_back(stoi(s.substr(0, i)));
			else
				x.emplace_back(stoi(s.substr(i - digits_per_elem, digits_per_elem)));
		shorten();
	}
	Num() {}
	Num(LL s) : Num(to_string(s)) {
		assert(s >= 0);
	}
};

string to_string(const Num& n) {
	stringstream s;
	s << (ssize(n.x) ? n.x.back() : 0);
	for(int i = ssize(n.x) - 2; i >= 0; --i)
		s << setfill('0') << setw(n.digits_per_elem) << n.x[i];
	return s.str();
}

ostream& operator<<(ostream &o, const Num& n) {
	return o << to_string(n).c_str();
}

Num operator+(Num a, const Num& b) {
	int carry = 0;
	for(int i = 0; i < max(ssize(a.x), ssize(b.x)) or carry; ++i) {
		if(i == ssize(a.x))
			a.x.emplace_back(0);
		a.x[i] += carry + (i < ssize(b.x) ? b.x[i] : 0);
		carry = bool(a.x[i] >= a.base);
		if(carry)
			a.x[i] -= a.base;
	}
	return a.shorten();
}

bool operator<(const Num& a, const Num& b) {
	if(ssize(a.x) != ssize(b.x))
		return ssize(a.x) < ssize(b.x);
	for(int i = ssize(a.x) - 1; i >= 0; --i)
		if(a.x[i] != b.x[i])
			return a.x[i] < b.x[i];
	return false;
}

bool operator==(const Num& a, const Num& b) {
	return a.x == b.x;
}

bool operator<=(const Num& a, const Num& b) {
	return a < b or a == b;
}

Num operator-(Num a, const Num& b) {
	assert(b <= a);
	int carry = 0;
	for(int i = 0; i < ssize(b.x) or carry; ++i) {
		a.x[i] -= carry + (i < ssize(b.x) ? b.x[i] : 0);
		carry = a.x[i] < 0;
		if(carry)
			a.x[i] += a.base;
	}
	return a.shorten();
}

Num operator*(Num a, int b) {
	assert(0 <= b and b < a.base);
	int carry = 0;
	for(int i = 0; i < ssize(a.x) or carry; ++i) {
		if(i == ssize(a.x))
			a.x.emplace_back(0);
		LL cur = a.x[i] * LL(b) + carry;
		a.x[i] = int(cur % a.base);
		carry = int(cur / a.base);
	}
	return a.shorten();
}

Num operator*(const Num& a, const Num& b) {
	Num c;
	c.x.resize(ssize(a.x) + ssize(b.x));
	REP(i, ssize(a.x))
		for(int j = 0, carry = 0; j < ssize(b.x) or carry; ++j) {
			LL cur = c.x[i + j] + a.x[i] * LL(j < ssize(b.x) ? b.x[j] : 0) + carry;
			c.x[i + j] = int(cur % a.base);
			carry = int(cur / a.base);
		}
	return c.shorten();
}

Num operator/(Num a, int b) {
	assert(0 < b and b < a.base);
	int carry = 0;
	for(int i = ssize(a.x) - 1; i >= 0; --i) {
		LL cur = a.x[i] + carry * LL(a.base);
		a.x[i] = int(cur / b);
		carry = int(cur % b);
	}
	return a.shorten();
}

// zwraca a * pow(a.base, b)
Num shift(Num a, int b) {
	vector v(b, 0);
	a.x.insert(a.x.begin(), v.begin(), v.end());
	return a.shorten();
}

Num operator/(Num a, const Num& b) {
	assert(ssize(b.x));
	Num c;
	for(int i = ssize(a.x) - ssize(b.x); i >= 0; --i) {
		if (a < shift(b, i)) continue;
		int l = 0, r = a.base - 1;
		while (l < r) {
			int m = (l + r + 1) / 2;
			if (shift(b * m, i) <= a)
				l = m;
			else
				r = m - 1;
		}
		c = c + shift(l, i);
		a = a - shift(b * l, i);
	}
	return c.shorten();
}

template<typename T>
Num operator%(const Num& a, const T& b) {
	return a - ((a / b) * b);
}

Num nwd(const Num& a, const Num& b) {
	if(b == Num())
		return a;
	return nwd(b, a % b);
}

using IT = Num;

struct Frac {
	IT a, b;
	Frac() : a(0), b(1) {}
	Frac(LL x) : a(x), b(1) {}
	Frac(IT aa, IT bb) {
		while (aa % 2 == 0 and bb % 2 == 0) {
			aa = aa / 2;
			bb = bb / 2;
		}
		a = aa;
		b = bb;
	}
	friend Frac operator+(Frac x, Frac y) {
		return Frac(x.a * y.b + x.b * y.a, x.b * y.b);
	}
	Frac inv() {
		return Frac(b, a);
	}
	friend Frac operator*(Frac x, Frac y) {
		return Frac(x.a * y.a, x.b * y.b);
	}
	friend Frac operator/(Frac x, Frac y) {
		return x * (y.inv());
	}
	friend auto& operator<<(ostream& o, Frac x) {
		return o << x.a << '/' << x.b;
	}
};

void solven1(int n, int m) {
	using T = Frac;
	assert(n == 1);

	auto f = [&](int x) -> T {
		return T(int(x != 2 and x != 0));
	};

	vector<char> v(m);
	REP(i, m)
		cin >> v[i];
	v.insert(v.begin(), '.');
	vector<T> dp(m + 1);

	dp[0] = T(0);
	FOR(i, 1, m) {
		if (v[i] == '.') {
			dp[i] = dp[i - 1];
			continue;
		}
		int x = i;
		T chance = T(1);
		while (true) {
			while (v[x] == 'O') {
				--x;
			}
			T val = (f(i - x) + (x == 0 ? 0 : dp[x - 1])) * chance;
			debug(i, x, val, chance, dp[i]);
			if (v[x] == '.') {
				dp[i] = dp[i] + val;
				break;
			}
			dp[i] = dp[i] + val / T(2);
			chance = chance / T(2);
			--x;
		}
	}
	debug(dp);
	cout << dp[m] << '\n';
}

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int n, m;
	cin >> n >> m;
	if (n == 1) {
		solven1(n, m);
		return 0;
	}
}