fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. #include <ext/pb_ds/tree_policy.hpp>
  5. #define ll long long
  6. #define ld long double
  7. #define endl "\n"
  8. #define ON(n , k) ((n) | (1 << (k)))
  9. #define OFF(n , k) ((n) & ~(1 << (k)))
  10. #define isON(n , k) (((n) >> (k)) & 1)
  11. #define all(v) v.begin(), v.end()
  12. #define IN() freopen("bad-memes.in", "r", stdin);
  13. using namespace __gnu_pbds;
  14. using namespace std;
  15.  
  16. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderSet;
  17. void Erase(orderSet &s, int val) {
  18. int rank = s.order_of_key(val);
  19. auto it = s.find_by_order(rank);
  20. s.erase(it);
  21. }
  22. bool is_prime(ll n) {
  23. if(n<2) {
  24. return false;
  25. }
  26. for (int i=2;i*i<=n;++i) {
  27. if(n%i==0) {
  28. return false;
  29. }
  30. }
  31. return true;
  32. }
  33.  
  34. vector<ll> divisors(ll x) {
  35. vector<ll> divs;
  36. for (int i = 1; i * i <= x; i++) {
  37. if (x % i == 0) {
  38. divs.push_back(i);
  39. if (i != x / i) {
  40. divs.push_back(x / i);
  41. }
  42. }
  43. }
  44. sort(divs.begin(), divs.end());
  45. return divs;
  46. }
  47. map<ll, ll> factors(ll n) {
  48. map<ll, ll> fact;
  49. while (n % 2 == 0) {
  50. fact[2]++;
  51. n /= 2;
  52. }
  53. for (ll i = 3; i * i <= n; i += 2) {
  54. while (n % i == 0) {
  55. fact[i]++;
  56. n /= i;
  57. }
  58. }
  59. if (n > 2) {
  60. fact[n]++;
  61. }
  62. return fact;
  63. }
  64.  
  65. ll lcm(ll a, ll b)
  66. {
  67. return a * (b / __gcd(a, b));
  68. }
  69.  
  70. ll gcd(ll a, ll b) {
  71. while (b != 0) {
  72. ll temp = b;
  73. b = a % b;
  74. a = temp;
  75. }
  76. return a;
  77. }
  78.  
  79. ll factorial(ll n) {
  80. ll f=1;
  81. while (n>0) {
  82. f=f*n;
  83. n--;
  84. }
  85. return f;
  86. }
  87. //const int mod=1e9+7;
  88. double root(double x, double n) {
  89. return pow(x, 1.0 / n);
  90. }
  91. void manar()
  92. {
  93. ios_base::sync_with_stdio(false);
  94. cin.tie(NULL);
  95. cout.tie(NULL);
  96. }
  97. bool is_even(int n) {
  98. if((n&1)==0) {
  99. return 1;
  100. }
  101. else {
  102. return 0;
  103. }
  104. }
  105. bool get_bit(ll n,int k) {
  106. int msk=1LL<<k; //value
  107. return (n&msk)? 1 : 0; //if value not =0 return true
  108. }
  109. int set_bit(ll n,int k) { // set k bit to 1
  110. int msk=1LL<<k;
  111. return n|msk;
  112. }
  113. int flip_bit(ll n,int i) {
  114. int msk=1LL<<i;
  115. return n^msk;
  116. }
  117. const int MOD=1e9;
  118. ll fast_pow(long long n, long long k) {
  119. long long result = 1;
  120. while (k > 0) {
  121. if (k & 1) {
  122. result = (result * n) % MOD;
  123. }
  124. n = (n * n) % MOD;
  125. k >>= 1;
  126. }
  127. return result;
  128. }
  129. ll count_ones(ll n) {
  130. int cnt=0;
  131. while (n) {
  132. n=n&(n-1);
  133. cnt++;
  134. }
  135. return cnt;
  136. }
  137. bool is_power_of_two(int n) {
  138. if(n&&((n&n-1))==0) {
  139. return 1;
  140. }
  141. else {
  142. return 0;
  143. }
  144. }
  145. vector<ll>sums;
  146. vector<vector<ll>> gen_sub(ll n, vector<ll> arr) {
  147. vector<vector<ll>> ans;
  148. for (int i = 0; i < (1 << n); i++) {
  149. vector<ll> tmp;
  150. ll sum = 0;
  151. for (int j = 0; j < n; j++) {
  152. if (isON(i, j)) {
  153. tmp.push_back(arr[j]);
  154. sum += arr[j];
  155. }
  156. }
  157. sums.push_back(sum);
  158. ans.push_back(tmp);
  159. }
  160. return ans;
  161. }
  162.  
  163. vector<string>sub(string s) {
  164. vector<string> ans;
  165. int n = s.size();
  166. ans.push_back("");
  167. for (int i = 1; i < (1 << n); ++i) {
  168. string tmp = "";
  169. for (int j = 0; j < n; ++j) {
  170. if (i & (1 << j)) {
  171. tmp += s[j];
  172. }
  173. }
  174. ans.push_back(tmp);
  175. }
  176.  
  177. return ans;
  178. }
  179. string get_binary(ll x)
  180. {
  181. string ret = "";
  182. bool tmp = false;
  183. for(int i = 63; i > -1; i--)
  184. {
  185. if(isON(x, i))
  186. tmp = true;
  187. if(tmp)
  188. ret += to_string(isON(x, i));
  189. }
  190. return ret;
  191. }
  192. long long lowbit(long long x) {
  193. return x & -x;
  194. }
  195. bool is_palindrome(string s) {
  196. int l = 0, r = s.size() - 1;
  197. while (l < r) {
  198. if (s[l] !=s[r]) {
  199. return false;
  200. }
  201. l++;
  202. r--;
  203. }
  204. return true;
  205. }
  206. const int mod=1e9+7;
  207. ll powmod(ll x, ll y)
  208. {
  209. ll res = 1;
  210. x = x % mod;
  211. if (x == 0) return 0;
  212. while (y > 0)
  213. {
  214. if (y & 1)
  215. res = (res*x) % mod;
  216. y = y>>1;
  217. x = (x*x) % mod;
  218. }
  219. return res;
  220. }
  221. ll add(ll a,ll b)
  222. {
  223. return ((a%mod)+(b%mod))%mod;
  224. }
  225. ll mul(ll a,ll b)
  226. {
  227. return ((a%mod)*(b%mod))%mod;
  228. }
  229. ll sub(ll a,ll b)
  230. {
  231. return ((((a%mod)-(b%mod))%mod)+mod)%mod;
  232. }
  233. ll divide(ll a,ll b)
  234. {
  235. return mul(a,powmod(b,mod-2));
  236. }
  237. /*const int n = 1e6 + 1;
  238. int divcnt[n + 1];
  239. void cntDiv()
  240. {
  241.   for(int i = 1; i <= n; i++)
  242.   {
  243.   for(int j = i; j <= n; j+= i)
  244.   divcnt[j]++;
  245.   }
  246. }
  247. */
  248. const int N=1e7+10;
  249. vector<bool> isPrime(N,true);
  250. vector<int>v;
  251. void sieve() {
  252. isPrime[0] = false;
  253. isPrime[1] = false;
  254.  
  255. for(ll i=2;i*i<N;i++)
  256. {
  257. if(isPrime[i])
  258. {
  259. for(ll j=i*i;j<N;j+=i)
  260. {
  261. isPrime[j] = false;
  262. }
  263. }
  264. }
  265. for (int i = 2; i < N; i++) {
  266. if (isPrime[i]) {
  267. v.push_back(i);
  268. }
  269. }
  270. }
  271. const int MAX_N=4e5+4;
  272. vector<int> adj[MAX_N]; // Adjust MAX_N to match problem constraints
  273. vector<int> dist(MAX_N);
  274. vector<bool> vis(MAX_N);
  275. int bfs(int start) {
  276. int mx = 0;
  277. queue<int> q;
  278.  
  279. fill(dist.begin(), dist.end(), 0);
  280. fill(vis.begin(), vis.end(), false);
  281.  
  282. q.push(start);
  283. dist[start] = 0;
  284. vis[start] = true;
  285.  
  286. while(!q.empty()) {
  287. int u = q.front();
  288. q.pop();
  289.  
  290. for(auto it : adj[u]) {
  291. if(!vis[it]) {
  292. q.push(it);
  293. vis[it] = true;
  294. dist[it] = dist[u] + 1;
  295. mx = max(mx, dist[it]);
  296. }
  297. }
  298. }
  299. return mx;
  300. }
  301.  
  302. void manora() {
  303. ll n;
  304. cin >> n;
  305. vector<char> sk;
  306. for (ll i = 0; i < n; ++i) {
  307. char c;
  308. cin >> c;
  309. bool alive = true;
  310. while (alive && !sk.empty()) {
  311. char top = sk.back();
  312. if (top == c) {
  313. sk.pop_back();
  314. alive = false;
  315. }
  316. else if (top == 'L' && c == 'Z') {
  317. alive = false;
  318. }
  319. else if (top == 'Z' && c == 'L') {
  320. sk.pop_back();
  321. }
  322. else if (top == 'Z' && c == 'F') {
  323. alive = false;
  324. }
  325. else if (top == 'F' && c == 'Z') {
  326. sk.pop_back();
  327. }
  328. else {
  329. break;
  330. }
  331. }
  332. if (alive) {
  333. sk.push_back(c);
  334. }
  335. }
  336. if (sk.empty()) {
  337. cout << "NO animals" << endl;
  338. } else {
  339. cout << sk.back() << endl;
  340. }
  341. }
  342. int main() {
  343. manar();
  344. manora();
  345. /*int t;cin>>t;
  346.   while (t--) {
  347.   manora();
  348.   }
  349.   */
  350. return 0;
  351. }
Success #stdin #stdout 0.01s 15668KB
stdin
Standard input is empty
stdout
NO animals