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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
#include <bits/stdc++.h>
using namespace std;

// loops
#define FOR_3(i, a, b) for (int i = (a), bb##i = (b); i <= bb##i; ++i)
#define FORR_3(i, a, b) for (int i = (b), aa##i = (a); i >= aa##i; --i)

#define FOR_2(i, n) FOR_3(i, 0, (n)-1)
#define FORR_2(i, n) FORR_3(i, 0, (n)-1)

#define FOR_1(n) FOR_2(_i##__LINE__, n)
#define FOR_0() for (;;)

#define OVERLOAD(_0, _1, _2, _3, NAME, ...) NAME
#define FOR(...)                                                       \
	OVERLOAD(_0 __VA_OPT__(, )##__VA_ARGS__, FOR_3, FOR_2, FOR_1, FOR_0) \
	(__VA_ARGS__)

#define FORR(...)                                                         \
	OVERLOAD(_0 __VA_OPT__(, )##__VA_ARGS__, FORR_3, FORR_2, FORR_1, FOR_0) \
	(__VA_ARGS__)

#ifdef LOCAL
#include <sys/prctl.h>
#include <sys/wait.h>
#include <unistd.h>

void print_trace()
{
	char pid_buf[30];
	sprintf(pid_buf, "%d", getpid());
	char name_buf[512];
	name_buf[readlink("/proc/self/exe", name_buf, 511)] = 0;
	prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0);
	int child_pid = fork();
	if (!child_pid)
	{
		dup2(2, 1); // redirect output to stderr - edit: unnecessary?
		execl("/usr/bin/gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt",
					name_buf, pid_buf, NULL);
		abort(); /* If gdb failed to start */
	}
	else
	{
		waitpid(child_pid, NULL, 0);
	}
}

extern const char *const sys_siglist[];

void handler(int sig)
{
	cerr << "SIGNAL " << sig << " (" << sys_siglist[sig] << ")" << endl;
	print_trace();
	exit(1);
}

#define INDENT_SIZE 2
string indent;

void _E() { cerr << endl; }
template <class ARG, class... ARGS>
void _E(ARG &&arg, ARGS &&...args)
{
	cerr << std::forward<ARG>(arg) << " ";
	_E(std::forward<ARGS>(args)...);
}

#define ERR(...)                               \
	{                                            \
		cerr << indent << "[" << __LINE__ << "] "; \
		_E(__VA_ARGS__);                           \
	}

#define _V5(x) #x, "==", (x)
#define _V4(x, ...) #x, "==", (x)__VA_OPT__(, "|", _V5(__VA_ARGS__))
#define _V3(x, ...) #x, "==", (x)__VA_OPT__(, "|", _V4(__VA_ARGS__))
#define _V2(x, ...) #x, "==", (x)__VA_OPT__(, "|", _V3(__VA_ARGS__))
#define _V1(x, ...) #x, "==", (x)__VA_OPT__(, "|", _V2(__VA_ARGS__))
#define ERRV(...) ERR(_V1(__VA_ARGS__))
#define INDENT auto _indenter = Indenter();

struct Indenter
{
	Indenter()
	{
		FOR(INDENT_SIZE)
		indent.push_back(' ');
	}
	~Indenter()
	{
		FOR(INDENT_SIZE)
		indent.pop_back();
	}
};

#define FAIL(str)                                                             \
	{                                                                           \
		cerr << "ASSERT FAILED   " << str << "   " << __FILE__ << ':' << __LINE__ \
				 << endl;                                                             \
		abort();                                                                  \
	}

#define SLEEP this_thread::sleep_for(100ms);

#else
#define INDENT
#define SLEEP
#define FAIL(x) \
	{             \
	}
#define ERR(...) \
	{              \
	}
#define ERRV(...) \
	{               \
	}
#endif

// asserts
#define CHECK(cond) \
	if (!(cond))      \
	FAIL(#cond)

#define CHECK_OP(op, a, b, res) \
	if (!(res))                   \
	FAIL(#a " " op " " #b "   (" + to_string(a) + " vs " + to_string(b) + ")")

#define CHECK_EQ(a, b) CHECK_OP("==", a, b, (a) == (b))
#define CHECK_NE(a, b) CHECK_OP("!=", a, b, (a) != (b))
#define CHECK_LE(a, b) CHECK_OP("<=", a, b, (a) <= (b))
#define CHECK_GE(a, b) CHECK_OP(">=", a, b, (a) >= (b))
#define CHECK_LT(a, b) CHECK_OP("<", a, b, (a) < (b))
#define CHECK_GT(a, b) CHECK_OP(">", a, b, (a) > (b))

#define CHECK_RANGE(x, a, b) \
	if (!(a <= x && x < b))    \
	FAIL(#x " in [" #a "," #b ")")

// min / max
template <class T>
auto min(T &&t) { return move(t); };
template <class T, class... TS>
auto min(T &&t, TS &&...ts)
{
	auto rest = min(forward<TS>(ts)...);
	return t < rest ? t : rest;
}

template <class T>
auto max(T &&t) { return move(t); };
template <class T, class... TS>
auto max(T &&t, TS &&...ts)
{
	auto rest = max(forward<TS>(ts)...);
	return t > rest ? t : rest;
}

#define REMIN(a, b) ((a) = min(a, b));
#define REMAX(a, b) ((a) = max(a, b));

// containers / arrays
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) int((x).size())
#define ZERO(x) memset(x, 0, sizeof(x));

// other
#define UNUSED(...) (void)(__VA_ARGS__);

// magic 1-indexed vector
template <class T>
struct vec : vector<T>
{
	decltype(vector<T>()[0]) operator[](int i)
	{
		CHECK_GE(i, 1);
		while (i > size())
			vector<T>::emplace_back();
		return vector<T>::operator[](i - 1);
	}
	int size() { return vector<T>::size(); }
};

// magic 1-indexed deque
template <class T>
struct deq : deque<T>
{
	auto &operator[](int i)
	{
		CHECK_GE(i, 1);
		while (i > size())
			deque<T>::emplace_back();
		return deque<T>::operator[](i - 1);
	}
	int size() { return deque<T>::size(); }
};

// magic 1-indexed array
template <class T, int sz>
struct arr : array<T, sz>
{
	auto &operator[](int i) { return array<T, sz>::operator[](i - 1); }
};

// types
#define umap unordered_map
#define deq deque
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

using vi = vec<int>;
using vll = vec<ll>;
using vpii = vec<pii>;
using vb = vec<bool>;

using di = deq<int>;
using dll = deq<ll>;
using dpii = deq<pii>;

// abbrevs
#define push push_back
#define pop pop_back
#define CMP bool operator<(const auto &o) const

// array operations
#define SORT(v) sort(ALL(v));
#define UNIQUE(c)                     \
	{                                   \
		SORT(c);                          \
		c.erase(unique(ALL(c)), c.end()); \
	}

auto PERM(int n)
{
	di v(n);
	FOR(i, n)
	v[i] = i;
	return v;
}

template <class V>
auto esort(const V &v)
{
	auto perm = PERM(SZ(v));
	sort(ALL(perm), [&](int a, int b)
			 { return v[a] < v[b]; });
	return perm;
}

template <class V>
auto eremap(V &&vv)
{
	auto v = move(vv);
	SORT(v);
	umap<typename V::value_type, int> r;
	int nxt = 0;
	for (auto &e : v)
		if (r.emplace(e, nxt).second)
			++nxt;
	return r;
}

template <class X, class FR, class TO>
bool range(const X &x, const FR &fr, const TO &to)
{
	return !(x < fr) && x < to;
}

template <class A, class B>
auto divup(A a, B b) { return (a + b - 1) / b; }

// bit operations
int msb(int x)
{
	CHECK_GT(x, 0)
	return 31 - __builtin_clz(x);
}

int msb(ll x)
{
	CHECK_GT(x, 0)
	return 63 - __builtin_clzll(x);
}

int lsb(int x)
{
	CHECK_GT(x, 0)
	return __builtin_ctz(x);
}

int lsb(ll x)
{
	CHECK_GT(x, 0)
	return __builtin_ctzll(x);
}

int popcount(int x) { return __builtin_popcount(x); }
int popcount(ll x) { return __builtin_popcountll(x); }

#define FORB(b, mask) \
	for (auto m = mask, bit = lsb(m); m; m ^= (1 << b), bit = lsb(m))

#define FORS(s, mask) \
	for (auto s = mask; s; s = (s - 1) & mask) // iterate subsets

template <class T>
int log2up(T x)
{
	return x <= 1 ? 0 : msb(x - 1) + 1;
}

default_random_engine RNG(123);
#define SHUFFLE(c) shuffle(ALL(c), RNG);

// stdin
template <class T>
T read()
{
	T x;
	cin >> x;
	return x;
}
#define II read<int>()
#define ILL read<ll>()

void _I()
{
}
template <class ARG, class... ARGS>
void _I(ARG &&arg, ARGS &&...args)
{
	cin >> arg;
	_I(forward<ARGS>(args)...);
}
#define I(...) _I(__VA_ARGS__);

// stdout
template <class T>
void _print(T x)
{
	cout << x;
	bool space = true;
	if constexpr (is_same_v<T, char>)
	{
		if (x == '\n')
			space = false;
	}
	if (space)
		cout << " ";
}
template <class T>
void _print(deq<T> &d)
{
	for (auto &e : d)
		cout << e << " ";
}
void _O() {}
template <class ARG, class... ARGS>
void _O(ARG &&arg, ARGS &&...args)
{
	_print(arg);
	_O(forward<ARGS>(args)...);
}
#define O(...) _O(__VA_ARGS__ __VA_OPT__(, ) '\n');
#define OO(...) _O(__VA_ARGS__);

// stderr
template <class T>
auto &operator<<(ostream &os, deq<T> &v)
{
	os << "{";
	bool first = true;
	for (auto &e : v)
	{
		if (first)
			first = false;
		else
			os << " ";
		os << e;
	}
	return os << "}";
}

template <class A, class B>
auto &operator<<(ostream &os, pair<A, B> &p)
{
	return os << "{" << p.first << " " << p.second << "}";
}

////////////////////////////////////////////////////////////////////////////////
// snippets/modulo.hpp
//
template <class T, class E>
T fpow(T a, E exp)
{
	T r = 1;
	while (exp)
	{
		if (exp & 1)
		{
			r *= a;
			--exp;
		}
		else
		{
			exp >>= 1;
			a *= a;
		}
	}
	return r;
}

template <int MOD>
class Modulo
{
public:
	using H = int;
	H h = 0;

public:
	Modulo() = default;

	Modulo(H x) : h((x + MOD) % MOD) { CHECK_GE(x + MOD, 0); }

	Modulo(const Modulo &) = default;

public:
	Modulo &operator+=(const Modulo &o)
	{
		h += o.h;
		if (h >= MOD)
			h -= MOD;
		return *this;
	}

	Modulo &operator-=(const Modulo &o)
	{
		h = MOD + h - o.h;
		if (h >= MOD)
			h -= MOD;
		return *this;
	}

	Modulo &operator*=(const Modulo &o)
	{
		h = (1ULL * h * o.h) % MOD;
		return *this;
	}

	Modulo &operator/=(const Modulo &o)
	{
		const auto TOTIENT = MOD - 1;
		*this *= fpow(o, TOTIENT - 1);
		return *this;
	}

	bool operator==(const Modulo &o) const { return h == o.h; }
	bool operator!=(const Modulo &o) const { return h != o.h; }

	Modulo operator+(const Modulo &o) const { return Modulo(*this) += o; }
	Modulo operator-(const Modulo &o) const { return Modulo(*this) -= o; }
	Modulo operator*(const Modulo &o) const { return Modulo(*this) *= o; }
	Modulo operator/(const Modulo &o) const { return Modulo(*this) /= o; }

	Modulo &operator--()
	{
		if (h == 0)
			h = MOD;
		--h;
		return *this;
	}
	Modulo &operator++()
	{
		++h;
		if (h == MOD)
			h = 0;
		return *this;
	}
	Modulo operator--(int)
	{
		auto m = *this;
		--(*this);
		return m;
	}
	Modulo operator++(int)
	{
		auto m = *this;
		++(*this);
		return m;
	}

	explicit operator H() const { return h; }
};

template <int INT>
ostream &operator<<(ostream &os, const Modulo<INT> &modulo)
{
	return os << modulo.h;
}
// snippets/modulo.hpp
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//
// snippets/graph.hpp
//
template <class V, class _E>
struct Graph
{
	Graph() : _p_vs(make_shared<vec<V>>()), vs(*_p_vs) {}
	template <class _EE>
	Graph(Graph<V, _EE> &o) : _p_vs(o._p_vs), vs(*_p_vs) {}

	shared_ptr<vec<V>> _p_vs;
	vec<V> &vs;
	vec<vi> ves;
	auto &operator[](int i)
	{
		vs[i];
		return ves[i];
	}
	int size() { return SZ(vs); }

	struct E : _E
	{
		E(_E &&e = _E()) : _E(move(e)) {}

		struct EV
		{
			int dest = 0;
			int ith = 0;
		};

		arr<EV, 2> ev;
		auto &operator[](int i) { return ev[i]; }
	};
	vec<E> es;

	int dest(int v, int ve)
	{
		int e = ves[v][ve];
		int ith = 1 + (es[e][2].dest != v);
		return es[e][ith].dest;
	}

	void e(int a, int b, _E &&_e = _E())
	{
		CHECK_NE(a, b);
		operator[](a);
		operator[](b);
		ves[a].push(SZ(es) + 1);
		ves[b].push(SZ(es) + 1);
		es.emplace_back(move(_e));
		es.back()[1] = {a, SZ(ves[a])};
		es.back()[2] = {b, SZ(ves[b])};
	}
};

vi _vis;
int _cvis = 0;
template <class G>
struct Dfs
{
	struct S
	{
		int v;
		int ve;
	};

	function<bool(int, int, int)> can_visit;
	function<void(int, int, int)> visit;
	function<void(int, int, int)> leave;

#define CAN_VISIT .can_visit = [&](int p, int v, int e)
#define VISIT .visit = [&](int p, int v, int e)
#define LEAVE .leave = [&](int p, int v, int e)

	Dfs()
	{
		++_cvis;
	}

	void run(G &g)
	{
		FOR(i, SZ(g))
		run(g, i);
	}

	void run(G &g, int v0)
	{
		_vis.resize(SZ(g));
		if (_vis[v0] == _cvis)
			return;

		vec<S> s;

		s.push({v0, 1});
		_vis[v0] = _cvis;
		if (visit)
			visit(0, v0, 0);

		while (!s.empty())
		{
			auto [v, ve] = s.back();
			if (ve > SZ(g[v]))
			{
				s.pop();
				if (!s.empty() && leave)
					leave(s.back().v, g.dest(s.back().v, s.back().ve - 1),
								g[s.back().v][s.back().ve - 1]);
				continue;
			}
			s.back().ve++;

			int e = g.ves[v][ve];
			int dest = g.dest(v, ve);

			int p = 0;
			if (SZ(s) - 1 >= 1)
				p = s[SZ(s) - 1].v;

			if (dest != p && (!can_visit || can_visit(v, dest, e)) &&
					_vis[dest] != _cvis)
			{
				s.push({dest, 1});
				_vis[dest] = _cvis;
				if (visit)
					visit(v, dest, e);
			}
		}
	}
};
// snippets/graph.hpp
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//  _          _     _   _                                                    //
// | |        | |   | | | |                                                   //
// | |     ___| |_  | |_| |__   ___    __ _  __ _ _ __ ___   ___              //
// | |    / _ \ __| | __| '_ \ / _ \  / _` |/ _` | '_ ` _ \ / _ \             //
// | |___|  __/ |_  | |_| | | |  __/ | (_| | (_| | | | | | |  __/             //
// \_____/\___|\__|  \__|_| |_|\___|  \__, |\__,_|_| |_| |_|\___|             //
//                                     __/ |                                  //
//                                    |___/                                   //
//  ██████▓▓▒▒░░░░░░▒▒▒▒▒▒▒▒░░░░▒▒▒▒░░▒▒▒▒░░░░░░░░▒▒▒▒▒▒▒▒░░░░░░░░░░░░██████  //
//  ██████░░░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒░░░░░░░░░░▒▒░░▒▒░░░░░░░░░░░░  ░░▒▒████  //
//  ████░░░░░░░░░░▒▒░░░░░░░░░░░░░░░░▒▒▒▒▒▒░░░░▒▒░░░░▒▒    ░░░░░░░░░░  ░░████  //
//  ████░░░░░░▒▒▓▓████▓▓▓▓▓▓░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▓▓▓▓████▓▓▒▒░░  ▓▓██  //
//  ████░░▒▒▓▓██████▓▓▓▓▓▓▓▓██▒▒░░░░░░░░▓▓▓▓░░░░░░░░██▓▓▓▓▒▒▒▒████▓▓▒▒░░████  //
//  ████▓▓▒▒▒▒▓▓████▓▓▓▓██▓▓████░░░░░░░░▒▒▒▒░░░░░░████▓▓▓▓▓▓░░▓▓██▓▓░░░░████  //
//  ████▒▒▒▒▓▓▓▓████▓▓▓▓▓▓▓▓████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▓▓▓▓▓▓▒▒████▓▓░░░░▓▓██  //
//  ████▒▒▒▒▒▒▓▓▓▓██████▓▓██████░░▒▒▒▒▒▒▒▒▒▒░░░░░░████▓▓▓▓▓▓████▓▓▒▒░░░░▓▓██  //
//  ████▓▓▓▓▓▓▒▒▓▓▓▓▓▓██████▓▓▒▒▒▒▒▒▒▒░░▒▒░░░░░░░░▒▒████████▓▓▓▓▒▒░░▒▒▒▒░░██  //
//  ██▓▓░░░░▒▒▓▓██▒▒▒▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░▒▒▓▓▓▓▒▒▒▒▒▒▓▓▓▓░░▒▒██  //
//  ██░░▓▓▓▓▒▒▒▒▒▒▓▓▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░    ░░░░░░░░▒▒░░▒▒▓▓▒▒░░░░░░▓▓  //
//  ██░░░░▒▒▓▓▓▓▒▒▓▓▓▓▒▒▒▒▒▒░░▒▒░░░░░░░░░░░░      ░░░░░░░░▒▒▒▒▓▓▒▒▒▒▓▓▓▓▒▒▒▒  //
//  ▓▓▒▒▒▒▒▒░░▓▓▓▓▒▒▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░░░      ░░░░░░░░▒▒▓▓▓▓▒▒▓▓░░        //
//  ▓▓▒▒▒▒▓▓▒▒▒▒▓▓▒▒▓▓▓▓▒▒▒▒░░░░░░░░░░░░░░░░      ░░░░░░▒▒▒▒██▒▒▓▓▓▓░░▒▒▒▒▒▒  //
//  ▓▓▒▒░░░░▓▓░░▓▓▓▓▒▒▓▓▒▒▒▒░░░░░░░░░░░░░░░░        ░░▒▒▒▒▓▓▓▓▒▒▓▓▒▒▒▒░░  ░░  //
//  ██▒▒▒▒░░▒▒▓▓▒▒▓▓▒▒▓▓▒▒▒▒░░░░░░░░░░░░░░░░        ░░░░▒▒▓▓▓▓▒▒▓▓░░▓▓  ▒▒    //
//  ██▒▒▒▒▒▒▒▒▓▓░░▓▓▒▒▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░      ░░░░▒▒▒▒▒▒▓▓░░▓▓░░▓▓░░░░▓▓  //
//  ██▓▓▓▓▓▓▓▓▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒░░░░░░░░░░░░    ░░▒▒▒▒▒▒▒▒▒▒▓▓▒▒▓▓░░▒▒▒▒░░██  //
//  ████▓▓▒▒▒▒▓▓▓▓▒▒▓▓▒▒▒▒▓▓▒▒▒▒░░░░░░░░░░░░      ░░▓▓▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▒▒████  //
//  ██████████▓▓▒▒▒▒▒▒▒▒██▓▓▓▓▒▒░░░░░░░░░░░░      ░░░░░░▒▒▒▒░░▒▒▒▒▓▓████████  //
//  ██████████████░░░░░░▒▒██▓▓▓▓██▓▓░░░░░░░░    ▓▓▒▒▒▒▓▓▓▓▒▒░░  ▒▒██████████  //
//  ████████████████░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▒▒░░░░▒▒▓▓▓▓▓▓▓▓▒▒▒▒      ████████████  //
//  ████████████████░░░░░░▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒░░      ░░████████████  //
//  ████████████████░░░░░░▒▒░░▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒░░░░░░▒▒        ██████████████  //
//  ████████████████▒▒░░░░▒▒░░░░░░░░░░░░▒▒▒▒░░░░░░░░▒▒░░    ▒▒██████████████  //
//  ██████████████████░░░░▒▒░░░░░░░░░░▒▒▒▒▒▒▒▒░░░░  ▓▓░░    ████████████████  //
//  ██████████████████░░░░▒▒░░░░░░░░░░▒▒▒▒▒▒▒▒░░░░  ▓▓░░  ▓▓████████████████  //
//                                                                            //
//           ;;;;;              ██████╗ ███████╗ ██████╗ ██╗███╗   ██╗        //
//           ;;;;;              ██╔══██╗██╔════╝██╔════╝ ██║████╗  ██║        //
//           ;;;;;              ██████╔╝█████╗  ██║  ███╗██║██╔██╗ ██║        //
//         ..;;;;;..            ██╔══██╗██╔══╝  ██║   ██║██║██║╚██╗██║        //
//          ':::::'             ██████╔╝███████╗╚██████╔╝██║██║ ╚████║        //
//            ':`               ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝╚═╝  ╚═══╝        //
//                                                                            //

const bool MULTIPLE_TEST_CASES = false;

// using F = Modulo<1e9 + 7>;
// using F = Modulo<998'244'353>;

struct V
{
	//   int c = 0;
};
struct E
{
	//   int c = 0;
};
using G = Graph<V, E>;
using DFS = Dfs<G>;

struct Pt
{
	arr<int, 2> x;
	// int c = -1;
	bool operator<(const Pt &o) const { return x < o.x; }
};

struct Test_Case
{
	vec<Pt> pts;

	ll n, m = -1, k, q;
	dll in;

	G g;

	int yes = -1;

	void read_graph(int nn, int mm = -1)
	{
		if (mm == -1)
			mm = nn - 1;

		FOR(mm)
		{
			int a = II;
			int b = II;
			// int w = II;
			ERR("INPUT", a, b)

			g.e(a, b);
			//   g.e(a, b, {w});
		}
	}

	Test_Case()
	{
		n = ILL;
		// m = ILL;
		// k = ILL;
		// q = ILL;

		// ERRV(n, m, k, q)

		string str;
		I(str);

		bool bad[10];
		ZERO(bad);

		FOR(i, SZ(str))
		{
			int ith = i * 10 / n;
			if (str[i] == 'N')
				bad[ith] = true;
		}

		int result = 0;
		FOR(i, 10)
		{
			if (!bad[i])
				++result;
		}

		O(result);

		// FOR(n) pts.push({{II, II}, II});

		// read_graph(n); // tree
		// read_graph(n, m);

		// {
		//   DFS dfs;
		//   dfs CAN_VISIT{
		//       // p, v, e
		//   };
		//   dfs VISIT{
		//       // p, v, e
		//   };
		//   dfs LEAVE{
		//       // p, v, e
		//   };
		//   dfs.run(g);
		// }

		if (yes == 1)
		{
			O("YES")
			// dfs_print(0, -1);
		}
		else if (yes == 0)
			O("NO")
	}
};

//                                                                            //
// ════════════ ('\../') ═════════════                                        //
// ════════════ (◕.◕) ═══════════════                                        //
// ════════════ (,,)(,,) ═════════════                                        //
// .▀█▀.█▄█.█▀█.█▄.█.█▄▀ █▄█.█▀█.█─█.                                        //
// ─.█.─█▀█.█▀█.█.▀█.█▀▄ ─█.─█▄█.█▄█- for reading my code!                   //
// ═══════════════════════════════════              --Adam                    //
////////////////////////////////////////////////////////////////////////////////

int main()
{
#ifdef LOCAL
	signal(SIGSEGV, handler);
	signal(SIGABRT, handler);
#endif
	ios_base::sync_with_stdio(0);
	cout.precision(20);
	cout << fixed;

	int num_cases = 1;
	if (MULTIPLE_TEST_CASES)
		cin >> num_cases;

	FOR(i, num_cases)
	{
		ERR()
		ERR("TEST CASE", i + 1)
		INDENT
		Test_Case tc;
	}

	return 0;
}