problemscpp
A collection of my answers to algorithm problems in c++.
pat.cpp
浏览该文件的文档.
1#include "pat.h"
2#include "templates.h"
3#include <algorithm>
4#include <cmath>
5#include <cstring>
6#include <deque>
7#include <iomanip>
8#include <map>
9#include <numeric>
10#include <queue>
11#include <set>
12#include <sstream>
13#include <stack>
14#include <tuple>
15#include <unordered_map>
16#include <unordered_set>
17#include <utility>
18#include <vector>
19
20using namespace std;
21
22namespace pat {
23 namespace b {
24 namespace b1001 {
25 int main(istream &cin, ostream &cout) {
26 int n;
27 cin >> n;
28 int ans = 0;
29 while(n != 1) {
30 if(n % 2 == 0) {
31 n /= 2;
32 } else {
33 n = (3 * n + 1) / 2;
34 }
35 ans++;
36 }
37 cout << ans;
38 return 0;
39 }
40 }// namespace b1001
41
42 namespace b1002 {
43 int main(istream &cin, ostream &cout) {
44 unsigned int sum = 0;
45 char ch;
46 while(cin >> ch) {
47 sum += ch - '0';
48 }
49 stringstream ss;
50 ss << sum;
51 string str;
52 ss >> str;
53 for(int i = 0; i < str.length(); i++) {
54 ch = str[i];
55 switch(ch) {
56 case '0':
57 cout << "ling";
58 break;
59 case '1':
60 cout << "yi";
61 break;
62 case '2':
63 cout << "er";
64 break;
65 case '3':
66 cout << "san";
67 break;
68 case '4':
69 cout << "si";
70 break;
71 case '5':
72 cout << "wu";
73 break;
74 case '6':
75 cout << "liu";
76 break;
77 case '7':
78 cout << "qi";
79 break;
80 case '8':
81 cout << "ba";
82 break;
83 case '9':
84 cout << "jiu";
85 break;
86 }
87 if(i != str.length() - 1) {
88 cout << ' ';
89 }
90 }
91 return 0;
92 }
93 }// namespace b1002
94
95 namespace b1003 {
96 int main(istream &cin, ostream &cout) {
97 int n;
98 cin >> n;
99 for(int _ = 0; _ < n; _++) {
100 string str;
101 cin >> str;
102 int p = -1;
103 int t = -1;
104 int pref_a = 0;
105 int mid_a = 0;
106 int suf_a = 0;
107 for(int i = 0; i < str.length(); i++) {
108 const char ch = str[i];
109 switch(ch) {
110 case 'P':
111 if(p != -1 || t != -1) {
112 goto NO;
113 }
114 p = i;
115 break;
116 case 'A':
117 if(p == -1 && t == -1) {
118 pref_a++;
119 } else if(p != -1 && t == -1) {
120 mid_a++;
121 } else if(p != -1 && t != -1) {
122 suf_a++;
123 } else {
124 goto NO;
125 }
126 break;
127 case 'T':
128 if(p == -1 || t != -1) {
129 goto NO;
130 }
131 t = i;
132 break;
133 default: goto NO;
134 }
135 }
136 if(p == -1 || t == -1) {
137 goto NO;
138 }
139 if(mid_a < 1) {
140 goto NO;
141 }
142 if(suf_a != mid_a * pref_a) {
143 goto NO;
144 }
145 cout << "YES" << endl;
146 continue;
147 NO:
148 cout << "NO" << endl;
149 }
150 return 0;
151 }
152 }// namespace b1003
153
154 namespace b1004 {
155 int main(istream &cin, ostream &cout) {
156 int n;
157 cin >> n;
158 vector<tuple<string, string, unsigned short>> vec(n);
159 for(int i = 0; i < n; i++) {
160 string name;
161 string id;
162 int grade;
163 cin >> name >> id >> grade;
164 vec[i] = make_tuple(name, id, grade);
165 }
166 sort(vec.begin(), vec.end(), [](const tuple<string, string, unsigned short> &a, const tuple<string, string, unsigned short> &b) -> bool {
167 const auto &[a_name, a_id, a_grade] = a;
168 const auto &[b_name, b_id, b_grade] = b;
169 return a_grade < b_grade;
170 });
171 auto [highest_name, highest_id, highest_grade] = vec.back();
172 auto [lowest_name, lowest_id, lowest_grade] = vec.front();
173 cout << highest_name << ' ' << highest_id << endl
174 << lowest_name << ' ' << lowest_id;
175 return 0;
176 }
177 }// namespace b1004
178
179 namespace b1005 {
180 int main(istream &cin, ostream &cout) {
181 int n;
182 cin >> n;
183 unordered_map<int, int> in(n);
184 for(int i = 0; i < n; i++) {
185 int num;
186 cin >> num;
187 in[num] = 0;
188 }
189 for(auto [num, deg]: in) {
190 int cpy = num;
191 if(deg == 0) {
192 while(cpy != 1) {
193 if(cpy % 2 == 0) {
194 cpy /= 2;
195 } else {
196 cpy = (cpy * 3 + 1) / 2;
197 }
198 if(in.contains(cpy)) {
199 in[cpy]++;
200 }
201 }
202 }
203 }
204 vector<int> ans;
205 for(auto [num, deg]: in) {
206 if(deg == 0) {
207 ans.push_back(num);
208 }
209 }
210 sort(ans.rbegin(), ans.rend());
211 for(int i = 0; i < ans.size(); i++) {
212 cout << ans[i];
213 if(i != ans.size() - 1) {
214 cout << ' ';
215 }
216 }
217 return 0;
218 }
219 }// namespace b1005
220
221 namespace b1006 {
222 int main(istream &cin, ostream &cout) {
223 int n;
224 cin >> n;
225 const int b = n / 100;
226 for(int i = 0; i < b; i++) {
227 cout << 'B';
228 }
229 n %= 100;
230 const int s = n / 10;
231 for(int i = 0; i < s; i++) {
232 cout << 'S';
233 }
234 n %= 10;
235 for(int i = 1; i <= n; i++) {
236 cout << i;
237 }
238 return 0;
239 }
240 }// namespace b1006
241
242 namespace b1007 {
243 int main(istream &cin, ostream &cout) {
244 int n;
245 cin >> n;
246 auto *is_prime = new bool[n + 1];
247 memset(is_prime, 1, (n + 1) * sizeof(bool));
248 for(int i = 2; i <= n / 2; i++) {
249 for(int j = 2; i * j <= n; j++) {
250 is_prime[i * j] = false;
251 }
252 }
253 int ans = 0;
254 for(int i = 2; i + 2 <= n; i++) {
255 if(is_prime[i] && is_prime[i + 2]) {
256 ans++;
257 }
258 }
259 cout << ans;
260 delete[] is_prime;
261 return 0;
262 }
263 }// namespace b1007
264
265 namespace b1008 {
266 int main(istream &cin, ostream &cout) {
267 int n;
268 int m;
269 cin >> n >> m;
270 vector<int> vec(n);
271 for(int i = 0; i < n; i++) {
272 cin >> vec[(i + m) % n];
273 }
274 for(int i = 0; i < n; i++) {
275 cout << vec[i];
276 if(i != n - 1) {
277 cout << ' ';
278 }
279 }
280 return 0;
281 }
282 }// namespace b1008
283
284 namespace b1009 {
285 int main(istream &cin, ostream &cout) {
286 string str;
287 vector<string> strs;
288 while(cin >> str) {
289 strs.push_back(str);
290 }
291 for(int i = strs.size() - 1; i > 0; i--) {
292 cout << strs[i] << ' ';
293 }
294 cout << strs[0];
295 return 0;
296 }
297 }// namespace b1009
298
299 namespace b1010 {
300 int main(istream &cin, ostream &cout) {
301 int num;
302 vector<int> vec;
303 ostringstream oss;
304 while(cin >> num) {
305 vec.push_back(num);
306 }
307 for(int i = 0; i + 1 < vec.size(); i += 2) {
308 const int a = vec[i] * vec[i + 1];
309 const int b = vec[i + 1] - 1;
310 if(vec[i + 1] != 0) {
311 oss << a << ' ' << b << ' ';
312 }
313 }
314 if(vec.size() == 2 && vec[1] == 0) {
315 oss << "0 0 ";
316 }
317 string ans = oss.str();
318 ans = ans.substr(0, ans.length() - 1);
319 cout << ans;
320 return 0;
321 }
322 }// namespace b1010
323
324 namespace b1011 {
325 int main(istream &cin, ostream &cout) {
326 long long a;
327 long long b;
328 long long c;
329 int n;
330 cin >> n;
331 for(int i = 1; i <= n; i++) {
332 cin >> a >> b >> c;
333 cout << "Case #" << i << ": " << (a + b > c ? "true" : "false") << endl;
334 }
335 return 0;
336 }
337 }// namespace b1011
338
339 namespace b1012 {
340 int main(istream &cin, ostream &cout) {
341 int n;
342 cin >> n;
343 int a1 = 0;
344 int a2 = 0;
345 bool a2_flag = true;
346 int a2_count = 0;
347 int a3 = 0;
348 int a4_sum = 0;
349 int a4_count = 0;
350 int a5 = 0;
351 for(int i = 0; i < n; i++) {
352 int num;
353 cin >> num;
354 const int remainder = num % 5;
355 switch(remainder) {
356 case 0:
357 if(num % 2 == 0) {
358 a1 += num;
359 }
360 break;
361 case 1:
362 if(a2_flag) {
363 a2 += num;
364 } else {
365 a2 -= num;
366 }
367 a2_flag = !a2_flag;
368 a2_count++;
369 break;
370 case 2:
371 a3++;
372 break;
373 case 3:
374 a4_sum += num;
375 a4_count++;
376 break;
377 case 4:
378 a5 = max(a5, num);
379 break;
380 }
381 }
382 const double a4 = static_cast<double>(a4_sum) / a4_count;
383 if(a1 == 0) {
384 cout << 'N';
385 } else {
386 cout << a1;
387 }
388 cout << ' ';
389 if(a2_count == 0) {
390 cout << 'N';
391 } else {
392 cout << a2;
393 }
394 cout << ' ';
395 if(a3 == 0) {
396 cout << 'N';
397 } else {
398 cout << a3;
399 }
400 cout << ' ';
401 if(a4_count == 0) {
402 cout << 'N';
403 } else {
404 cout << fixed << setprecision(1) << a4;
405 }
406 cout << ' ';
407 if(a5 == 0) {
408 cout << 'N';
409 } else {
410 cout << a5;
411 }
412 return 0;
413 }
414 }// namespace b1012
415
416 namespace b1013 {
417 int main(istream &cin, ostream &cout) {
418 int m;
419 int n;
420 cin >> m >> n;
421 int count = 0;
422 vector<int> primes = {};
423 for(int i = 2; count <= n; i++) {
424 bool is_prime = true;
425 for(int factor = 2; factor <= sqrt(i); factor++) {
426 if(i % factor == 0) {
427 is_prime = false;
428 break;
429 }
430 }
431 if(is_prime) {
432 primes.push_back(i);
433 count++;
434 }
435 }
436 count = 0;
437 for(int i = m - 1; i < n; i++) {
438 cout << primes[i];
439 count++;
440 if(count == 10) {
441 count = 0;
442 cout << endl;
443 } else if(i != n - 1) {
444 cout << ' ';
445 }
446 }
447 return 0;
448 }
449 }// namespace b1013
450
451 namespace b1014 {
452 int main(istream &cin, ostream &cout) {
453 string str1;
454 string str2;
455 cin >> str1 >> str2;
456 string day;
457 const vector<string> days = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
458 int hh;
459 int mm;
460 for(int i = 0; i < str1.length() && i < str2.length(); i++) {
461 if(str1[i] == str2[i]) {
462 if(day.empty()) {
463 if(isupper(str1[i]) != 0) {
464 day = days[str1[i] - 'A'];
465 }
466 } else if(isdigit(str1[i]) != 0 || 'A' <= str1[i] && str1[i] <= 'N') {
467 if(isdigit(str1[i]) != 0) {
468 hh = str1[i] - '0';
469 } else {
470 hh = 10 + str1[i] - 'A';
471 }
472 break;
473 }
474 }
475 }
476 cin >> str1 >> str2;
477 for(int i = 0; i < str1.length() && i < str2.length(); i++) {
478 if(str1[i] == str2[i] && isalpha(str1[i]) != 0) {
479 mm = i;
480 break;
481 }
482 }
483 cout << day << ' ' << setw(2) << right << setfill('0') << hh << ':' << setw(2) << right << setfill('0') << mm;
484 return 0;
485 }
486 }// namespace b1014
487
488 namespace b1015 {
489 int main(istream &cin, ostream &cout) {
490 unsigned int n;
491 unsigned int l;
492 unsigned int h;
493 cin >> n >> l >> h;
494 vector<student> sector[4] = {vector<student>(), vector<student>(), vector<student>(), vector<student>()};
495 int sum = 0;
496 for(int i = 0; i < n; i++) {
497 auto stu = student();
498 cin >> stu.id >> stu.morality >> stu.ability;
499 if(stu.morality >= l && stu.ability >= l) {
500 sum++;
501 if(stu.morality >= h && stu.ability >= h) {
502 sector[0].push_back(stu);
503 } else if(stu.morality >= h) {
504 sector[1].push_back(stu);
505 } else if(stu.morality < h && stu.ability < h && stu.morality >= stu.ability) {
506 sector[2].push_back(stu);
507 } else {
508 sector[3].push_back(stu);
509 }
510 }
511 }
512 cout << sum << endl;
513 for(int i = 0; i < 4; i++) {
514 sort(sector[i].begin(), sector[i].end());
515 for(auto it = sector[i].begin(); it != sector[i].end(); ++it) {
516 auto stu = *it;
517 cout << stu.id << ' ' << stu.morality << ' ' << stu.ability << endl;
518 }
519 }
520 return 0;
521 }
522
523 bool student::operator<(const student &stu) const {
524 if(this->ability + this->morality == stu.ability + stu.morality) {
525 if(this->morality == stu.morality) {
526 return this->id < stu.id;
527 }
528 return this->morality > stu.morality;
529 }
530 return this->ability + this->morality > stu.ability + stu.morality;
531 }
532 }// namespace b1015
533
534 namespace b1016 {
535 int main(istream &cin, ostream &cout) {
536 string a;
537 string b;
538 int da;
539 int db;
540 cin >> a >> da >> b >> db;
541 stringstream ssa;
542 stringstream ssb;
543 int count_a = 0;
544 int count_b = 0;
545 for(const char ch: a) {
546 if(ch - '0' == da) {
547 count_a++;
548 ssa << ch;
549 }
550 }
551 for(const char ch: b) {
552 if(ch - '0' == db) {
553 count_b++;
554 ssb << ch;
555 }
556 }
557 int pa = 0;
558 int pb = 0;
559 if(count_a != 0) {
560 ssa >> pa;
561 }
562 if(count_b != 0) {
563 ssb >> pb;
564 }
565 cout << pa + pb;
566 return 0;
567 }
568 }// namespace b1016
569
570 namespace b1018 {
571 int main(istream &cin, ostream &cout) {
572 int n;
573 cin >> n;
574 int a_win = 0;
575 int b_win = 0;
576 int a_win_count[3] = {};
577 int b_win_count[3] = {};
578 int tie = 0;
579 for(int i = 0; i < n; i++) {
580 char a;
581 char b;
582 cin >> a >> b;
583 if(a == b) {
584 tie++;
585 } else if(a == 'C' && b == 'J' || a == 'J' && b == 'B' || a == 'B' && b == 'C') {
586 a_win++;
587 switch(a) {
588 case 'B':
589 a_win_count[0]++;
590 break;
591 case 'C':
592 a_win_count[1]++;
593 break;
594 case 'J':
595 a_win_count[2]++;
596 break;
597 }
598 } else {
599 b_win++;
600 switch(b) {
601 case 'B':
602 b_win_count[0]++;
603 break;
604 case 'C':
605 b_win_count[1]++;
606 break;
607 case 'J':
608 b_win_count[2]++;
609 break;
610 }
611 }
612 }
613 cout << a_win << ' ' << tie << ' ' << b_win << endl
614 << b_win << ' ' << tie << ' ' << a_win << endl;
615 int a_win_max = 0;
616 int b_win_max = 0;
617 for(int i = 0; i < 3; i++) {
618 a_win_max = max(a_win_max, a_win_count[i]);
619 b_win_max = max(b_win_max, b_win_count[i]);
620 }
621 for(int i = 0; i < 3; i++) {
622 if(a_win_count[i] == a_win_max) {
623 switch(i) {
624 case 0:
625 cout << 'B';
626 break;
627 case 1:
628 cout << 'C';
629 break;
630 case 2:
631 cout << 'J';
632 break;
633 }
634 cout << ' ';
635 break;
636 }
637 }
638 for(int i = 0; i < 3; i++) {
639 if(b_win_count[i] == b_win_max) {
640 switch(i) {
641 case 0:
642 cout << 'B';
643 break;
644 case 1:
645 cout << 'C';
646 break;
647 case 2:
648 cout << 'J';
649 break;
650 }
651 break;
652 }
653 }
654 return 0;
655 }
656 }// namespace b1018
657
658 namespace b1019 {
659 int main(istream &cin, ostream &cout) {
660 string num;
661 cin >> num;
662 int a = 0;
663 int b = 0;
664 while(num.length() < 4) {
665 num = num + '0';
666 }
667 if(num == "0000") {
668 cout << "0000 - 0000 = 0000";
669 return 0;
670 }
671 while(num != "0000" && a - b != 6174) {
672 stringstream ssa;
673 stringstream ssb;
674 stringstream ss;
675 sort(num.rbegin(), num.rend());
676 ssa << num;
677 ssa >> a;
678 sort(num.begin(), num.end());
679 ssb << num;
680 ssb >> b;
681 ss << setw(4) << right << setfill('0') << a - b;
682 num = "";
683 ss >> num;
684 cout << setw(4) << right << setfill('0') << a << " - " << setw(4) << right << setfill('0') << b << " = " << setw(4) << right << setfill('0') << a - b << endl;
685 }
686 return 0;
687 }
688 }// namespace b1019
689
690 namespace b1020 {
691 int main(istream &cin, ostream &cout) {
692 int n;
693 int d;
694 cin >> n >> d;
695 vector<long double> storage(n);
696 vector<long double> sales(n);
697 vector<pair<long double, int>> unit_price(n);
698 for(int i = 0; i < n; i++) {
699 cin >> storage[i];
700 }
701 for(int i = 0; i < n; i++) {
702 cin >> sales[i];
703 }
704 for(int i = 0; i < n; i++) {
705 unit_price[i] = make_pair(sales[i] / storage[i], i);
706 }
707 sort(unit_price.begin(), unit_price.end(), [](const pair<long double, int> &a, const pair<long double, int> &b) { return a.first > b.first; });
708 int current_amount = 0;
709 long double ans = 0;
710 for(int i = 0; i < n && current_amount < d; i++) {
711 int amount = 0;
712 if(current_amount + storage[unit_price[i].second] > d) {
713 amount = d - current_amount;
714 current_amount = d;
715 ans += amount * sales[unit_price[i].second] / storage[unit_price[i].second];
716 } else {
717 amount = storage[unit_price[i].second];
718 ans += sales[unit_price[i].second];
719 current_amount += storage[unit_price[i].second];
720 }
721 }
722 cout << fixed << setprecision(2) << ans;
723 return 0;
724 }
725 }// namespace b1020
726
727 namespace b1021 {
728 int main(istream &cin, ostream &cout) {
729 map<char, int> dm;
730 char ch;
731 while(cin >> ch) {
732 if(isdigit(ch) != 0) {
733 dm[ch]++;
734 }
735 }
736 for(auto [d, m]: dm) {
737 cout << d << ':' << m << endl;
738 }
739 return 0;
740 }
741 }// namespace b1021
742
743 namespace b1022 {
744 int main(istream &cin, ostream &cout) {
745 int a;
746 int b;
747 int d;
748 cin >> a >> b >> d;
749 int sum = a + b;
750 if(sum == 0) {
751 cout << 0;
752 return 0;
753 }
754 vector<unsigned short> vec;
755 while(sum != 0) {
756 vec.push_back(sum % d);
757 sum /= d;
758 }
759 for(auto it = vec.rbegin(); it != vec.rend(); ++it) {
760 cout << *it;
761 }
762 return 0;
763 }
764 }// namespace b1022
765
766 namespace b1023 {
767 int main(istream &cin, ostream &cout) {
768 vector<int> vec(10);
769 for(int i = 0; i < 10; i++) {
770 cin >> vec[i];
771 }
772 for(int i = 1; i < 10; i++) {
773 if(vec[i] > 0) {
774 cout << i;
775 vec[i]--;
776 break;
777 }
778 }
779 for(int i = 0; i < 10; i++) {
780 while(vec[i] > 0) {
781 cout << i;
782 vec[i]--;
783 }
784 }
785 return 0;
786 }
787 }// namespace b1023
788
789 namespace b1024 {
790 int main(istream &cin, ostream &cout) {
791 string str;
792 cin >> str;
793 const char op = str[0];
794 const char num1 = str[1];
795 const auto pos_e = str.find('E');
796 const string num2 = str.substr(3, pos_e - 3);
797 const string num3_str = str.substr(pos_e + 1);
798 stringstream ss;
799 ss << num3_str;
800 int num3;
801 ss >> num3;
802 if(op == '-') {
803 cout << op;
804 }
805 if(num3 < 0) {
806 cout << 0 << '.';
807 for(int i = 1; i < abs(num3); i++) {
808 cout << 0;
809 }
810 cout << num1 << num2;
811 } else {
812 cout << num1;
813 int i = 0;
814 for(; i < num3 && i < num2.length(); i++) {
815 cout << num2[i];
816 }
817 if(i < num2.length()) {
818 cout << '.';
819 for(; i < num2.length(); i++) {
820 cout << num2[i];
821 }
822 }
823 if(i < num3) {
824 for(; i < num3; i++) {
825 cout << 0;
826 }
827 }
828 }
829 return 0;
830 }
831 }// namespace b1024
832
833 namespace b1025 {
834 int main(istream &cin, ostream &cout) {
835 string address0;
836 int n;
837 int k;
838 cin >> address0 >> n >> k;
839 unordered_map<string, pair<int, string>> nodes;
840 for(int i = 0; i < n; i++) {
841 string address;
842 string next;
843 int data;
844 cin >> address >> data >> next;
845 nodes.insert(make_pair(address, make_pair(data, next)));
846 }
847 vector<pair<string, int>> vec;
848 string current_addr = address0;
849 while(current_addr != "-1") {
850 auto [data, next] = nodes[current_addr];
851 vec.emplace_back(current_addr, data);
852 current_addr = next;
853 }
854 n = vec.size();
855 for(int i = 0; i < n - n % k; i += k) {
856 reverse(vec.begin() + i, vec.begin() + i + k);
857 }
858 for(int i = 0; i < n; i++) {
859 cout << vec[i].first << ' ' << vec[i].second << ' ' << (i + 1 < n ? vec[i + 1].first : "-1") << endl;
860 }
861 return 0;
862 }
863 }// namespace b1025
864
865 namespace b1026 {
866 int main(istream &cin, ostream &cout) {
867 unsigned int c1;
868 unsigned int c2;
869 cin >> c1 >> c2;
870 unsigned int d = (c2 + 50 - c1) / 100;
871 const unsigned int h = d / 3600;
872 d %= 3600;
873 const unsigned int m = d / 60;
874 d %= 60;
875 const unsigned s = d;
876 cout << setw(2) << right << setfill('0') << h << ':' << setw(2) << right << setfill('0') << m << ':' << setw(2) << right << setfill('0') << s;
877 return 0;
878 }
879 }// namespace b1026
880
881 namespace b1027 {
882 int main(istream &cin, ostream &cout) {
883 unsigned int n;
884 char ch;
885 cin >> n >> ch;
886 int i = 1;
887 while((i + 1) * (i + 1) / 2 - 1 <= n) {
888 i += 2;
889 }
890 i -= 2;
891 for(int j = 0; j < (i + 1) / 2; ++j) {
892 for(int k = 0; k < j; k++) {
893 cout << ' ';
894 }
895 for(int k = 0; k < i - 2 * j; k++) {
896 cout << ch;
897 }
898 cout << endl;
899 }
900 for(int j = (i + 1) / 2 - 2; j >= 0; --j) {
901 for(int k = 0; k < j; k++) {
902 cout << ' ';
903 }
904 for(int k = 0; k < i - 2 * j; k++) {
905 cout << ch;
906 }
907 cout << endl;
908 }
909 cout << n - ((i + 1) * (i + 1) / 2 - 1);
910 return 0;
911 }
912 }// namespace b1027
913
914 namespace b1028 {
915 bool is_valid(int year, int month, int day) {
916 if(year > 2014) {
917 return false;
918 }
919 if(year == 2014 && month > 9) {
920 return false;
921 }
922 if(year == 2014 && month == 9 && day > 6) {
923 return false;
924 }
925 if(year < 1814) {
926 return false;
927 }
928 if(year == 1814 && month < 9) {
929 return false;
930 }
931 if(year == 1814 && month == 9 && day < 6) {
932 return false;
933 }
934 return true;
935 }
936
937 int main(istream &cin, ostream &cout) {
938 int n;
939 int count = 0;
940 cin >> n;
941 auto oldest = Person(2014, 9, 6);
942 auto youngest = Person(1814, 9, 6);
943 for(int i = 0; i < n; i++) {
944 Person p;
945 cin >> p.name >> p.year;
946 cin.get();
947 cin >> p.month;
948 cin.get();
949 cin >> p.day;
950 if(is_valid(p.year, p.month, p.day)) {
951 count++;
952 if(p < oldest) {
953 oldest = p;
954 }
955 if(youngest < p) {
956 youngest = p;
957 }
958 }
959 }
960 if(count > 0) {
961 cout << count << ' ' << oldest.name << ' ' << youngest.name;
962 } else {
963 cout << 0;
964 }
965 return 0;
966 }
967
968 bool Person::operator<(const Person &p) const {
969 if(this->year < p.year) {
970 return true;
971 }
972 if(this->year == p.year && this->month < p.month) {
973 return true;
974 }
975 if(this->year == p.year && this->month == p.month && this->day < p.day) {
976 return true;
977 }
978 return false;
979 }
980 }// namespace b1028
981
982 namespace b1029 {
983 int main(istream &cin, ostream &cout) {
984 unordered_set<char> bad;
985 unordered_set<char> s;
986 string good_str;
987 string bad_str;
988 cin >> good_str;
989 cin >> bad_str;
990 for(char ch: bad_str) {
991 ch = toupper(ch);
992 bad.insert(ch);
993 }
994 for(char ch: good_str) {
995 ch = toupper(ch);
996 if(!bad.contains(ch) && !s.contains(ch)) {
997 cout << ch;
998 s.insert(ch);
999 }
1000 }
1001 return 0;
1002 }
1003 }// namespace b1029
1004
1005 namespace b1030 {
1006 int main(istream &cin, ostream &cout) {
1007 unsigned int n;
1008 unsigned int p;
1009 cin >> n >> p;
1010 vector<unsigned int> vec(n);
1011 for(unsigned int i = 0; i < n; i++) {
1012 cin >> vec[i];
1013 }
1014 sort(vec.begin(), vec.end());
1015 unsigned int ans = 0;
1016 for(unsigned i = 0; i < vec.size(); i++) {
1017 unsigned diff = upper_bound(vec.begin(), vec.end(), vec[i] * p) - (vec.begin() + i);
1018 ans = max(ans, diff);
1019 }
1020 cout << ans;
1021 return 0;
1022 }
1023 }// namespace b1030
1024
1025 namespace b1031 {
1026 int main(istream &cin, ostream &cout) {
1027 int n;
1028 cin >> n;
1029 const char captcha[11] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
1030 const int weight[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
1031 bool flag = true;
1032 for(int i = 0; i < n; i++) {
1033 string str;
1034 cin >> str;
1035 int sum = 0;
1036 for(int j = 0; j < 17; j++) {
1037 sum += weight[j] * (str[j] - '0');
1038 }
1039 sum %= 11;
1040 if(str[17] != captcha[sum]) {
1041 cout << str << endl;
1042 flag = false;
1043 }
1044 }
1045 if(flag) {
1046 cout << "All passed";
1047 }
1048 return 0;
1049 }
1050 }// namespace b1031
1051
1052 namespace b1032 {
1053 int main(istream &cin, ostream &cout) {
1054 int n;
1055 cin >> n;
1056 unordered_map<int, unsigned long long> um;
1057 unsigned long long maximum_score = 0;
1058 int maximum_id;
1059 for(int i = 0; i < n; i++) {
1060 int id;
1061 int score;
1062 cin >> id >> score;
1063 um[id] += score;
1064 if(um[id] >= maximum_score) {
1065 maximum_score = um[id];
1066 maximum_id = id;
1067 }
1068 }
1069 cout << maximum_id << ' ' << maximum_score;
1070 return 0;
1071 }
1072 }// namespace b1032
1073
1074 namespace b1033 {
1075 int main(istream &cin, ostream &cout) {
1076 unordered_set<char> broken;
1077 string str1;
1078 string str2;
1079 cin >> str1 >> str2;
1080 if(str2.empty()) {
1081 cout << str1;
1082 return 0;
1083 }
1084 bool shift = true;
1085 for(char ch: str1) {
1086 broken.insert(ch);
1087 if(ch == '+') {
1088 shift = false;
1089 }
1090 }
1091 for(const char ch: str2) {
1092 if(!(broken.contains(toupper(ch)) || !shift && isupper(ch) != 0)) {
1093 cout << ch;
1094 }
1095 }
1096 return 0;
1097 }
1098 }// namespace b1033
1099
1100 namespace b1034 {
1101 int main(istream &cin, ostream &cout) {
1102 long long numerator1;
1103 long long numerator2;
1104 long long denominator1;
1105 long long denominator2;
1106 char ch;
1107 cin >> numerator1 >> ch >> denominator1 >> numerator2 >> ch >> denominator2;
1108 const Fraction frac1(true, numerator1, denominator1);
1109 const Fraction frac2(true, numerator2, denominator2);
1110 cout << frac1 << " + " << frac2 << " = " << frac1 + frac2 << endl
1111 << frac1 << " - " << frac2 << " = " << frac1 - frac2 << endl
1112 << frac1 << " * " << frac2 << " = " << frac1 * frac2 << endl
1113 << frac1 << " / " << frac2 << " = " << frac1 / frac2;
1114 return 0;
1115 }
1116 }// namespace b1034
1117
1118 namespace b1035 {
1119 int main(istream &cin, ostream &cout) {
1120 int n;
1121 cin >> n;
1122 vector<int> vec1(n);
1123 vector<int> vec2(n);
1124 for(int i = 0; i < n; i++) {
1125 cin >> vec1[i];
1126 }
1127 for(int i = 0; i < n; i++) {
1128 cin >> vec2[i];
1129 }
1130 int i = n - 1;
1131 for(; i >= 0 && vec1[i] == vec2[i]; --i) {}
1132 vector<int> sorted_vec = vec1;
1133 sort(sorted_vec.begin(), sorted_vec.begin() + i + 1);
1134 bool insertion = true;
1135 for(int j = 0; j <= i; j++) {
1136 if(sorted_vec[j] != vec2[j]) {
1137 insertion = false;
1138 break;
1139 }
1140 }
1141 if(insertion) {
1142 //插入排序
1143 cout << "Insertion Sort" << endl;
1144 int j = n - 1;
1145 for(; j >= 0; --j) {
1146 vector vec1_cpy = vec1;
1147 sort(vec1_cpy.begin(), vec1_cpy.begin() + j);
1148 if(vec1_cpy == vec2) {
1149 break;
1150 }
1151 }
1152 sort(vec1.begin(), vec1.begin() + j + 1);
1153 for(int k = 0; k < n; k++) {
1154 cout << vec1[k];
1155 if(k != n - 1) {
1156 cout << ' ';
1157 }
1158 }
1159 return 0;
1160 }
1161 //归并排序
1162 cout << "Merge Sort" << endl;
1163 int factor = 1;
1164 bool flag = false;
1165 while(true) {
1166 factor *= 2;
1167 int j = 0;
1168 for(; (j + 1) * factor <= n; j++) {
1169 sort(vec1.begin() + j * factor, vec1.begin() + (j + 1) * factor);
1170 }
1171 if(j * factor < n) {
1172 sort(vec1.begin() + j * factor, vec1.end());
1173 }
1174 if(flag) {
1175 for(int k = 0; k < n; k++) {
1176 cout << vec1[k];
1177 if(k != n - 1) {
1178 cout << ' ';
1179 }
1180 }
1181 return 0;
1182 }
1183 if(vec1 == vec2) {
1184 flag = true;
1185 }
1186 }
1187 }
1188 }// namespace b1035
1189
1190 namespace b1036 {
1191 int main(istream &cin, ostream &cout) {
1192 int n;
1193 char c;
1194 cin >> n >> c;
1195 for(int i = 0; i < n; i++) {
1196 cout << c;
1197 }
1198 cout << endl;
1199 for(int i = 0; i < (n + 1) / 2 - 2; i++) {
1200 cout << c;
1201 for(int j = 0; j < n - 2; j++) {
1202 cout << ' ';
1203 }
1204 cout << c << endl;
1205 }
1206 for(int i = 0; i < n; i++) {
1207 cout << c;
1208 }
1209 return 0;
1210 }
1211 }// namespace b1036
1212
1213 namespace b1037 {
1214 int main(istream &cin, ostream &cout) {
1215 unsigned long long galleon;
1216 unsigned long long sickle;
1217 unsigned long long knut;
1218 char ch;
1219 unsigned long long sum[2];
1220 for(int i = 0; i < 2; i++) {
1221 cin >> galleon >> ch >> sickle >> ch >> knut;
1222 sum[i] = galleon * 17 * 29 + sickle * 29 + knut;
1223 }
1224 const bool positive = sum[0] <= sum[1];
1225 unsigned long long diff;
1226 if(positive) {
1227 diff = sum[1] - sum[0];
1228 } else {
1229 diff = sum[0] - sum[1];
1230 }
1231 galleon = diff / (17 * 29);
1232 diff %= 17 * 29;
1233 sickle = diff / 29;
1234 diff %= 29;
1235 knut = diff;
1236 if(!positive) {
1237 cout << '-';
1238 }
1239 cout << galleon << '.' << sickle << '.' << knut;
1240 return 0;
1241 }
1242 }// namespace b1037
1243
1244 namespace b1038 {
1245 int main(istream &cin, ostream &cout) {
1246 unordered_map<int, int> um;
1247 int n;
1248 cin >> n;
1249 int score;
1250 for(int i = 0; i < n; i++) {
1251 cin >> score;
1252 um[score]++;
1253 }
1254 cin >> n;
1255 for(int i = 0; i < n; i++) {
1256 cin >> score;
1257 cout << um[score];
1258 if(i != n - 1) {
1259 cout << ' ';
1260 }
1261 }
1262 return 0;
1263 }
1264 }// namespace b1038
1265
1266 namespace b1039 {
1267 int main(istream &cin, ostream &cout) {
1268 string str1;
1269 string str2;
1270 cin >> str1 >> str2;
1271 unordered_map<char, int> um;
1272 for(char ch: str1) {
1273 um[ch]++;
1274 }
1275 bool yes = true;
1276 for(char ch: str2) {
1277 um[ch]--;
1278 if(um[ch] < 0) {
1279 yes = false;
1280 }
1281 }
1282 int sum = 0;
1283 for(auto [ch, count]: um) {
1284 if(yes && count > 0) {
1285 sum += count;
1286 } else if(!yes && count < 0) {
1287 sum -= count;
1288 }
1289 }
1290 cout << (yes ? "Yes " : "No ") << sum;
1291 return 0;
1292 }
1293 }// namespace b1039
1294
1295 namespace b1040 {
1296 int main(istream &cin, ostream &cout) {
1297 string str;
1298 cin >> str;
1299 vector<unsigned long long> p(str.length(), 0);
1300 vector<unsigned long long> t(str.length(), 0);
1301 unsigned long long current_p = 0;
1302 for(int i = 0; i < p.size(); ++i) {
1303 p[i] = current_p;
1304 if(str[i] == 'P') {
1305 current_p++;
1306 }
1307 }
1308 unsigned long long current_t = 0;
1309 for(int i = t.size() - 1; i >= 0; --i) {
1310 t[i] = current_t;
1311 if(str[i] == 'T') {
1312 current_t++;
1313 }
1314 }
1315 unsigned long long ans = 0;
1316 for(int i = 0; i < p.size(); i++) {
1317 if(str[i] == 'A') {
1318 ans += p[i] * t[i] % 1000000007;
1319 ans %= 1000000007;
1320 }
1321 }
1322 cout << ans;
1323 return 0;
1324 }
1325 }// namespace b1040
1326
1327 namespace b1041 {
1328 int main(istream &cin, ostream &cout) {
1329 int n;
1330 cin >> n;
1331 unordered_map<int, student> um;
1332 for(int i = 0; i < n; i++) {
1333 student stu;
1334 cin >> stu.id >> stu.seat1 >> stu.seat2;
1335 um[stu.seat1] = stu;
1336 }
1337 cin >> n;
1338 int seat1;
1339 for(int i = 0; i < n; i++) {
1340 cin >> seat1;
1341 student stu = um[seat1];
1342 cout << stu.id << ' ' << stu.seat2 << endl;
1343 }
1344 return 0;
1345 }
1346 }// namespace b1041
1347
1348 namespace b1042 {
1349 int main(istream &cin, ostream &cout) {
1350 auto *str = new char[1001];
1351 cin.getline(str, 1001);
1352 map<char, int> m;
1353 int maximum = 0;
1354 for(int i = 0; i < strlen(str); ++i) {
1355 char ch = tolower(str[i]);
1356 if(isalpha(ch) != 0) {
1357 m[ch]++;
1358 maximum = max(maximum, m[ch]);
1359 }
1360 }
1361 for(auto [ch, cnt]: m) {
1362 if(cnt == maximum) {
1363 cout << ch << ' ' << cnt;
1364 break;
1365 }
1366 }
1367 delete[] str;
1368 return 0;
1369 }
1370 }// namespace b1042
1371
1372 namespace b1043 {
1373 int main(istream &cin, ostream &cout) {
1374 unordered_map<char, unsigned> um;
1375 const char patest[6] = {'P', 'A', 'T', 'e', 's', 't'};
1376 um['P'] = 0;
1377 um['A'] = 0;
1378 um['T'] = 0;
1379 um['e'] = 0;
1380 um['s'] = 0;
1381 um['t'] = 0;
1382 string str;
1383 cin >> str;
1384 for(char ch: str) {
1385 if(um.contains(ch)) {
1386 um[ch]++;
1387 }
1388 }
1389 unsigned minimum = 10000;
1390 for(const auto &[ch, count]: um) {
1391 minimum = min(minimum, count);
1392 }
1393 for(auto &[ch, count]: um) {
1394 count -= minimum;
1395 }
1396 for(unsigned i = 0; i < minimum; i++) {
1397 cout << "PATest";
1398 }
1399 bool flag = true;
1400 while(flag) {
1401 flag = false;
1402 for(unsigned i = 0; i < 6; i++) {
1403 if(um[patest[i]] > 0) {
1404 cout << patest[i];
1405 um[patest[i]]--;
1406 flag = true;
1407 }
1408 }
1409 }
1410 return 0;
1411 }
1412 }// namespace b1043
1413
1414 namespace b1044 {
1415 int main(istream &cin, ostream &cout) {
1416 string abc[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
1417 string abc2[13] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
1418 unordered_map<string, int> um;
1419 unordered_set<string> us2;
1420 for(int i = 0; i < 13; i++) {
1421 us2.insert(abc2[i]);
1422 um[abc[i]] = i;
1423 um[abc2[i]] = i;
1424 }
1425 int n;
1426 cin >> n;
1427 char cccc[16];
1428 cin.getline(cccc, 16);
1429 while(n-- != 0) {
1430 auto *cstr = new char[1024];
1431 cin.getline(cstr, 1024);
1432 stringstream ss;
1433 ss << cstr;
1434 if(isdigit(ss.peek()) != 0) {
1435 // 地球数字
1436 unsigned long long num;
1437 ss >> num;
1438 vector<string> output;
1439 bool flag = true;
1440 if(num == 0) {
1441 cout << "tret";
1442 } else {
1443 while(num != 0) {
1444 if(flag) {
1445 if(num % 13 != 0) {
1446 output.push_back(abc[num % 13]);
1447 }
1448 flag = false;
1449 } else {
1450 output.push_back(abc2[num % 13]);
1451 }
1452 num /= 13;
1453 }
1454 for(auto it = output.rbegin(); it != output.rend(); ++it) {
1455 cout << *it;
1456 if(it + 1 != output.rend()) {
1457 cout << ' ';
1458 }
1459 }
1460 }
1461 } else {
1462 // 火星数字
1463 int b = 0;
1464 for(int i = 0; cstr[i] != '\0'; i++) {
1465 if(cstr[i] == ' ') {
1466 b++;
1467 }
1468 }
1469 b++;
1470 string str;
1471 unsigned long long num = 0;
1472 while(b != 0) {
1473 ss >> str;
1474 num += um[str] * pow(13, --b);
1475 }
1476 if(us2.contains(str)) {
1477 num *= 13;
1478 }
1479 cout << num;
1480 }
1481 delete[] cstr;
1482 if(n != 0) {
1483 cout << endl;
1484 }
1485 }
1486 return 0;
1487 }
1488 }// namespace b1044
1489
1490 namespace b1045 {
1491 int main(istream &cin, ostream &cout) {
1492 unsigned n;
1493 cin >> n;
1494 vector<unsigned> vec(n);
1495 vector<unsigned> l_max(n);
1496 vector<unsigned> r_min(n);
1497 unsigned current = 0;
1498 for(unsigned i = 0; i < n; ++i) {
1499 cin >> vec[i];
1500 l_max[i] = current;
1501 current = max(current, vec[i]);
1502 }
1503 current = 1000000001;
1504 for(int i = n - 1; i >= 0; --i) {
1505 r_min[i] = current;
1506 current = min(current, vec[i]);
1507 }
1508 vector<unsigned> ans;
1509 for(unsigned i = 0; i < n; ++i) {
1510 if(vec[i] > l_max[i] && vec[i] < r_min[i]) {
1511 ans.push_back(vec[i]);
1512 }
1513 }
1514 cout << ans.size() << endl;
1515 for(int i = 0; i < ans.size(); i++) {
1516 cout << ans[i];
1517 if(i != ans.size() - 1) {
1518 cout << ' ';
1519 }
1520 }
1521 cout << endl;
1522 return 0;
1523 }
1524 }// namespace b1045
1525
1526 namespace b1046 {
1527 int main(istream &cin, ostream &cout) {
1528 int n;
1529 cin >> n;
1530 int ans1 = 0;
1531 int ans2 = 0;
1532 while(n-- != 0) {
1533 int a1;
1534 int a2;
1535 int b1;
1536 int b2;
1537 cin >> a1 >> a2 >> b1 >> b2;
1538 const int sum = a1 + b1;
1539 if(sum == a2 && sum != b2) {
1540 ans2++;
1541 } else if(sum == b2 && sum != a2) {
1542 ans1++;
1543 }
1544 }
1545 cout << ans1 << ' ' << ans2;
1546 return 0;
1547 }
1548 }// namespace b1046
1549
1550 namespace b1047 {
1551 int main(istream &cin, ostream &cout) {
1552 int n;
1553 cin >> n;
1554 unordered_map<int, int> um;
1555 int maximum = 0;
1556 while(n-- != 0) {
1557 int a;
1558 cin >> a;
1559 cin.get();
1560 int b;
1561 cin >> b >> b;
1562 um[a] += b;
1563 }
1564 for(const auto &[team, score]: um) {
1565 maximum = max(score, maximum);
1566 }
1567 for(const auto &[team, score]: um) {
1568 if(score == maximum) {
1569 cout << team << ' ' << score;
1570 return 0;
1571 }
1572 }
1573 return 1;
1574 }
1575 }// namespace b1047
1576
1577 namespace b1048 {
1578 int main(istream &cin, ostream &cout) {
1579 string a;
1580 string b;
1581 cin >> a >> b;
1582 vector<char> ans;
1583 int i = 1;
1584 for(; i <= max(b.length(), a.length()); ++i) {
1585 const int bi = b.length() >= i ? b[b.length() - i] - '0' : 0;
1586 const int ai = a.length() >= i ? a[a.length() - i] - '0' : 0;
1587 if(i % 2 != 0) {
1588 char ret = (ai + bi) % 13;
1589 switch(ret) {
1590 case 10:
1591 ret = 'J';
1592 break;
1593 case 11:
1594 ret = 'Q';
1595 break;
1596 case 12:
1597 ret = 'K';
1598 break;
1599 default:
1600 ret += '0';
1601 break;
1602 }
1603 ans.push_back(ret);
1604 } else {
1605 int ret = bi - ai;
1606 if(ret < 0) {
1607 ret += 10;
1608 }
1609 ans.push_back(ret + '0');
1610 }
1611 }
1612 for(auto it = ans.rbegin(); it != ans.rend(); ++it) {
1613 cout << *it;
1614 }
1615 return 0;
1616 }
1617 }// namespace b1048
1618
1619 namespace b1049 {
1620 int main(istream &cin, ostream &cout) {
1621 int n;
1622 cin >> n;
1623 long double num;
1624 long double ans = 0;
1625 for(int i = 0; i < n; ++i) {
1626 cin >> num;
1627 ans += num * (n - i) * (i + 1);
1628 }
1629 cout << fixed << setprecision(2) << ans;
1630 return 0;
1631 }
1632 }// namespace b1049
1633
1634 namespace b1050 {
1635 int main(istream &cin, ostream &cout) {
1636 int N;
1637 cin >> N;
1638 int m = N;
1639 int n = 1;
1640 for(int i = 1; i * i <= N; ++i) {
1641 if(N % i == 0) {
1642 n = i;
1643 m = N / i;
1644 }
1645 }
1646 vector matrix(m, vector(n, 0));
1647 vector<int> vec(N);
1648 for(int i = 0; i < N; i++) {
1649 cin >> vec[i];
1650 }
1651 sort(vec.rbegin(), vec.rend());
1652 int direction = 0;//0 右 1 下 2 左 3 上
1653 int x = 0;
1654 int y = 0;
1655 int current = 0;
1656 matrix[0][0] = vec[current];
1657 --N;
1658 while(N != 0) {
1659 int next_x = x;
1660 int next_y = y;
1661 switch(direction) {
1662 case 0:
1663 next_y += 1;
1664 break;
1665 case 1:
1666 next_x += 1;
1667 break;
1668 case 2:
1669 next_y -= 1;
1670 break;
1671 case 3:
1672 next_x -= 1;
1673 break;
1674 }
1675 if(next_x < 0 || next_x >= m || next_y < 0 || next_y >= n || matrix[next_x][next_y] != 0) {
1676 direction += 1;
1677 direction %= 4;
1678 } else {
1679 matrix[next_x][next_y] = vec[++current];
1680 x = next_x;
1681 y = next_y;
1682 N--;
1683 }
1684 }
1685 for(int i = 0; i < m; i++) {
1686 for(int j = 0; j < n; j++) {
1687 cout << matrix[i][j];
1688 if(j != n - 1) {
1689 cout << ' ';
1690 }
1691 }
1692 if(i != m - 1) {
1693 cout << endl;
1694 }
1695 }
1696 return 0;
1697 }
1698 }// namespace b1050
1699
1700 namespace b1051 {
1701 int main(istream &cin, ostream &cout) {
1702 long double r1;
1703 long double p1;
1704 long double r2;
1705 long double p2;
1706 cin >> r1 >> p1 >> r2 >> p2;
1707 const long double a1 = r1 * cos(p1);
1708 const long double a2 = r2 * cos(p2);
1709 const long double b1 = r1 * sin(p1);
1710 const long double b2 = r2 * sin(p2);
1711 long double a = a1 * a2 - b1 * b2;
1712 long double b = a1 * b2 + a2 * b1;
1713 if(a < 0 && a + 0.005 >= 0) {
1714 a += 0.005;
1715 }
1716 if(b < 0 && b + 0.005 >= 0) {
1717 b += 0.005;
1718 }
1719 cout << fixed << setprecision(2) << a << fixed << setprecision(2) << showpos << b << 'i';
1720 return 0;
1721 }
1722 }// namespace b1051
1723
1724 namespace b1052 {
1725 int main(istream &cin, ostream &cout) {
1726 vector<string> vec[3];
1727 char line[1024];
1728 for(int a = 0; a < 3; a++) {
1729 cin.getline(line, sizeof line);
1730 int i = 0;
1731 int j = 0;
1732 while(i < strlen(line) && j < strlen(line)) {
1733 while(line[i] != '[' && i < strlen(line)) {
1734 ++i;
1735 }
1736 while(line[j] != ']' && j < strlen(line)) {
1737 ++j;
1738 }
1739 if(i < strlen(line) && j < strlen(line)) {
1740 ostringstream oss;
1741 for(int m = i + 1; m < j; ++m) {
1742 oss << line[m];
1743 }
1744 vec[a].push_back(oss.str());
1745 ++i;
1746 ++j;
1747 }
1748 }
1749 }
1750 int k;
1751 cin >> k;
1752 while(k-- != 0) {
1753 ostringstream oss;
1754 int a;
1755 int b;
1756 int c;
1757 int d;
1758 int e;
1759 cin >> a >> b >> c >> d >> e;
1760 --a;
1761 --b;
1762 --c;
1763 --d;
1764 --e;
1765 if(a < vec[0].size()) {
1766 oss << vec[0][a];
1767 } else {
1768 goto END;
1769 }
1770 oss << '(';
1771 if(b < vec[1].size()) {
1772 oss << vec[1][b];
1773 } else {
1774 goto END;
1775 }
1776 if(c < vec[2].size()) {
1777 oss << vec[2][c];
1778 } else {
1779 goto END;
1780 }
1781 if(d < vec[1].size()) {
1782 oss << vec[1][d];
1783 } else {
1784 goto END;
1785 }
1786 oss << ')';
1787 if(e < vec[0].size()) {
1788 oss << vec[0][e];
1789 } else {
1790 goto END;
1791 }
1792 cout << oss.str() << endl;
1793 continue;
1794 END:;
1795 cout << "Are you kidding me? @\\/@" << endl;
1796 }
1797 return 0;
1798 }
1799 }// namespace b1052
1800
1801 namespace b1053 {
1802 int main(istream &cin, ostream &cout) {
1803 int n;
1804 double e;
1805 int d;
1806 int cnt1 = 0;
1807 int cnt2 = 0;
1808 cin >> n >> e >> d;
1809 for(int i = 0; i < n; ++i) {
1810 int k;
1811 cin >> k;
1812 int cnt = 0;
1813 for(int j = 0; j < k; ++j) {
1814 double E;
1815 cin >> E;
1816 if(E < e) {
1817 cnt++;
1818 }
1819 }
1820 if(2 * cnt > k) {
1821 if(k > d) {
1822 cnt2++;
1823 } else {
1824 cnt1++;
1825 }
1826 }
1827 }
1828 const double ans1 = static_cast<double>(cnt1) / n * 100;
1829 const double ans2 = static_cast<double>(cnt2) / n * 100;
1830 cout << fixed << setprecision(1) << ans1 << "% " << fixed << setprecision(1) << ans2 << '%';
1831 return 0;
1832 }
1833 }// namespace b1053
1834
1835 namespace b1054 {
1836 int main(istream &cin, ostream &cout) {
1837 int n;
1838 cin >> n;
1839 string x;
1840 long double sum = 0;
1841 int k = 0;
1842 while(n-- != 0) {
1843 cin >> x;
1844 bool flag = true;
1845 int start = 0;
1846 if(x[0] == '-') {
1847 if(x.length() > 1) {
1848 start = 1;
1849 } else {
1850 goto ERROR;
1851 }
1852 }
1853 if(x.length() > 8) {
1854 goto ERROR;
1855 }
1856 if(isdigit(x[start]) != 0) {
1857 int pos = -1;
1858 for(int i = start + 1; i < x.length(); ++i) {
1859 if(x[i] == '.') {
1860 if(flag) {
1861 flag = false;
1862 pos = i;
1863 } else {
1864 goto ERROR;
1865 }
1866 } else if(isdigit(x[i]) == 0) {
1867 goto ERROR;
1868 }
1869 }
1870 if(!flag) {
1871 if(pos + 3 < x.length()) {
1872 goto ERROR;
1873 }
1874 }
1875 stringstream ss;
1876 ss << x;
1877 if(flag) {
1878 int num;
1879 ss >> num;
1880 if(num >= -1000 && num <= 1000) {
1881 sum += num;
1882 k++;
1883 } else {
1884 goto ERROR;
1885 }
1886 } else {
1887 long double num;
1888 ss >> num;
1889 if(num >= -1000 && num <= 1000) {
1890 sum += num;
1891 k++;
1892 } else {
1893 goto ERROR;
1894 }
1895 }
1896 } else {
1897 ERROR:
1898 cout << "ERROR: " << x << " is not a legal number" << endl;
1899 }
1900 }
1901 if(k == 0) {
1902 cout << "The average of 0 numbers is Undefined" << endl;
1903 } else {
1904 const long double y = sum / k;
1905 cout << "The average of " << k << " number" << (k == 1 ? "" : "s") << " is " << fixed << setprecision(2) << y << endl;
1906 }
1907 return 0;
1908 }
1909 }// namespace b1054
1910
1911 namespace b1055 {
1912 int main(istream &cin, ostream &cout) {
1913 int n;
1914 int k;
1915 cin >> n >> k;
1916 vector<Person> vec(n);
1917 for(int i = 0; i < n; i++) {
1918 string name;
1919 int height;
1920 cin >> name >> height;
1921 const auto p = Person{name, height};
1922 vec[i] = p;
1923 }
1924 sort(vec.begin(), vec.end());
1925 vector<deque<Person>> deq(k);
1926 for(int i = 0; i < n / k + n % k; i++) {
1927 if(i % 2 == 1) {
1928 deq[k - 1].push_front(vec.back());
1929 } else {
1930 deq[k - 1].push_back(vec.back());
1931 }
1932 vec.pop_back();
1933 }
1934 for(int i = k - 2; i >= 0; i--) {
1935 for(int j = 0; j < n / k; j++) {
1936 if(j % 2 == 1) {
1937 deq[i].push_front(vec.back());
1938 } else {
1939 deq[i].push_back(vec.back());
1940 }
1941 vec.pop_back();
1942 }
1943 }
1944 for(int i = k - 1; i >= 0; i--) {
1945 for(int j = 0; j < deq[i].size(); j++) {
1946 cout << deq[i][j].name;
1947 if(j != deq[i].size() - 1) {
1948 cout << ' ';
1949 }
1950 }
1951 if(i != 0) {
1952 cout << endl;
1953 }
1954 }
1955 return 0;
1956 }
1957
1958 bool Person::operator<(const Person &p) const {
1959 if(this->height < p.height) {
1960 return true;
1961 }
1962 if(this->height > p.height) {
1963 return false;
1964 }
1965 return this->name > p.name;
1966 }
1967 }// namespace b1055
1968
1969 namespace b1056 {
1970 int main(istream &cin, ostream &cout) {
1971 int n;
1972 cin >> n;
1973 unsigned short num;
1974 int ans = 0;
1975 for(int i = 0; i < n; i++) {
1976 cin >> num;
1977 ans += num * (n - 1) * 11;
1978 }
1979 cout << ans;
1980 return 0;
1981 }
1982 }// namespace b1056
1983
1984 namespace b1057 {
1985 int main(istream &cin, ostream &cout) {
1986 char str[100010];
1987 cin.getline(str, 100010);
1988 unsigned n = 0;
1989 for(int i = 0; str[i] != '\0'; i++) {
1990 if(isupper(str[i]) != 0) {
1991 n += str[i] - 'A' + 1;
1992 } else if(islower(str[i]) != 0) {
1993 n += str[i] - 'a' + 1;
1994 }
1995 }
1996 int one = 0;
1997 int zero = 0;
1998 while(n != 0) {
1999 if((n & 1) == 1) {
2000 one++;
2001 } else {
2002 zero++;
2003 }
2004 n >>= 1;
2005 }
2006 cout << zero << ' ' << one;
2007 return 0;
2008 }
2009 }// namespace b1057
2010
2011 namespace b1058 {
2012 int main(istream &cin, ostream &cout) {
2013 int n;
2014 int m;
2015 cin >> n >> m;
2016 int max_error = 0;
2017 vector<Problem> problems(m);
2018 for(int i = 0; i < m; i++) {
2019 Problem p;
2020 cin >> p.score;
2021 cin >> p.num;
2022 cin >> p.correct_num;
2023 p.correct_choices = unordered_set<char>();
2024 for(int j = 0; j < p.correct_num; j++) {
2025 char choice;
2026 cin >> choice;
2027 p.correct_choices.insert(choice);
2028 }
2029 p.error_count = 0;
2030 problems[i] = p;
2031 }
2032 for(int i = 0; i < n; i++) {
2033 int score = 0;
2034 for(int j = 0; j < m; j++) {
2035 char ch;
2036 cin >> ch;
2037 int num;
2038 cin >> num;
2039 unordered_set<char> answer;
2040 for(int k = 0; k < num; k++) {
2041 char choice;
2042 cin >> choice;
2043 answer.insert(choice);
2044 }
2045 if(answer == problems[j].correct_choices) {
2046 score += problems[j].score;
2047 } else {
2048 problems[j].error_count++;
2049 max_error = max(max_error, problems[j].error_count);
2050 }
2051 cin >> ch;
2052 }
2053 cout << score << endl;
2054 }
2055 if(max_error == 0) {
2056 cout << "Too simple";
2057 } else {
2058 vector<int> max_problems;
2059 cout << max_error << ' ';
2060 for(int i = 0; i < m; i++) {
2061 if(problems[i].error_count == max_error) {
2062 max_problems.push_back(i + 1);
2063 }
2064 }
2065 for(int i = 0; i < max_problems.size(); i++) {
2066 cout << max_problems[i];
2067 if(i != max_problems.size() - 1) {
2068 cout << ' ';
2069 }
2070 }
2071 }
2072 return 0;
2073 }
2074 }// namespace b1058
2075
2076 namespace b1059 {
2077 bool is_prime(int n) {
2078 for(int i = 2; i <= sqrt(n); i++) {
2079 if(n % i == 0) {
2080 return false;
2081 }
2082 }
2083 return true;
2084 }
2085
2086 int main(istream &cin, ostream &cout) {
2087 int n;
2088 cin >> n;
2089 unordered_map<string, string> um;
2090 for(int rank = 1; rank <= n; rank++) {
2091 string id;
2092 cin >> id;
2093 if(rank == 1) {
2094 um[id] = "Mystery Award";
2095 } else if(is_prime(rank)) {
2096 um[id] = "Minion";
2097 } else {
2098 um[id] = "Chocolate";
2099 }
2100 }
2101 int k;
2102 cin >> k;
2103 while(k-- != 0) {
2104 string id;
2105 cin >> id;
2106 if(static_cast<unsigned int>(um.contains(id)) == 0U) {
2107 cout << id << ": Are you kidding?" << endl;
2108 } else {
2109 cout << id << ": " << um[id] << endl;
2110 um[id] = "Checked";
2111 }
2112 }
2113 return 0;
2114 }
2115 }// namespace b1059
2116
2117 namespace b1060 {
2118 int main(istream &cin, ostream &cout) {
2119 int n;
2120 cin >> n;
2121 vector<int> vec(n + 1);
2122 for(int i = 1; i <= n; i++) {
2123 cin >> vec[i];
2124 }
2125 sort(vec.begin(), vec.end());
2126 int e = 1;
2127 int i = n;
2128 while(e <= n && vec[i] > e) {
2129 e++;
2130 i--;
2131 }
2132 cout << e - 1;
2133 return 0;
2134 }
2135 }// namespace b1060
2136
2137 namespace b1061 {
2138 int main(istream &cin, ostream &cout) {
2139 int n;
2140 int m;
2141 cin >> n >> m;
2142 vector<int> scores(m);
2143 for(int i = 0; i < m; i++) {
2144 cin >> scores[i];
2145 }
2146 vector<int> correct_answer(m);
2147 for(int i = 0; i < m; i++) {
2148 cin >> correct_answer[i];
2149 }
2150 for(int i = 0; i < n; i++) {
2151 int score = 0;
2152 for(int j = 0; j < m; j++) {
2153 int answer;
2154 cin >> answer;
2155 if(answer == correct_answer[j]) {
2156 score += scores[j];
2157 }
2158 }
2159 cout << score << endl;
2160 }
2161 return 0;
2162 }
2163 }// namespace b1061
2164
2165 namespace b1062 {
2166 int main(istream &cin, ostream &cout) {
2167 char ch;
2168 double n1;
2169 double n2;
2170 int m1;
2171 int m2;
2172 int k;
2173 cin >> n1 >> ch >> m1 >> n2 >> ch >> m2 >> k;
2174 n1 *= k;
2175 n1 /= m1;
2176 n2 *= k;
2177 n2 /= m2;
2178 if(n1 > n2) {
2179 swap(n1, n2);
2180 }
2181 bool flag = true;
2182 for(int i = ceil(n1) == n1 ? n1 + 1 : ceil(n1); i < n2; i++) {
2183 const int f = gcd(i, k);
2184 if(f == 1) {
2185 if(flag) {
2186 cout << i / f << '/' << k;
2187 flag = false;
2188 } else {
2189 cout << ' ' << i / f << '/' << k;
2190 }
2191 }
2192 }
2193 return 0;
2194 }
2195 }// namespace b1062
2196
2197 namespace b1063 {
2198 int main(istream &cin, ostream &cout) {
2199 int n;
2200 cin >> n;
2201 double ans = 0;
2202 while(n-- != 0) {
2203 int a;
2204 int b;
2205 cin >> a >> b;
2206 ans = max(ans, sqrt(a * a + b * b));
2207 }
2208 cout << fixed << setprecision(2) << ans;
2209 return 0;
2210 }
2211 }// namespace b1063
2212
2213 namespace b1064 {
2214 int main(istream &cin, ostream &cout) {
2215 int n;
2216 cin >> n;
2217 set<int> s;
2218 while(n-- != 0) {
2219 string str;
2220 cin >> str;
2221 int sum = 0;
2222 for(const char ch: str) {
2223 sum += ch - '0';
2224 }
2225 s.insert(sum);
2226 }
2227 cout << s.size() << endl;
2228 for(auto i = s.begin(); i != s.end(); ++i) {
2229 cout << *i;
2230 if(*i != *s.rbegin()) {
2231 cout << ' ';
2232 }
2233 }
2234 return 0;
2235 }
2236 }// namespace b1064
2237
2238 namespace b1066 {
2239 int main(istream &cin, ostream &cout) {
2240 int m;
2241 int n;
2242 int a;
2243 int b;
2244 int g;
2245 cin >> m >> n >> a >> b >> g;
2246 for(int i = 0; i < m; i++) {
2247 for(int j = 0; j < n; j++) {
2248 int v;
2249 cin >> v;
2250 if(a <= v && v <= b) {
2251 cout << setw(3) << right << setfill('0') << g;
2252 } else {
2253 cout << setw(3) << right << setfill('0') << v;
2254 }
2255 if(j != n - 1) {
2256 cout << ' ';
2257 }
2258 }
2259 if(i != m - 1) {
2260 cout << endl;
2261 }
2262 }
2263 return 0;
2264 }
2265 }// namespace b1066
2266
2267 namespace b1065 {
2268 int main(istream &cin, ostream &cout) {
2269 int n;
2270 cin >> n;
2271 unordered_map<string, string> um;
2272 set<string> s;
2273 for(int i = 0; i < n; i++) {
2274 string id1;
2275 string id2;
2276 cin >> id1 >> id2;
2277 um[id1] = id2;
2278 um[id2] = id1;
2279 }
2280 int m;
2281 cin >> m;
2282 for(int i = 0; i < m; i++) {
2283 string id;
2284 cin >> id;
2285 if(um.contains(id)) {
2286 s.erase(um[id]);
2287 } else {
2288 s.insert(id);
2289 }
2290 }
2291 cout << s.size() << endl;
2292 for(auto it = s.begin(); it != s.end(); ++it) {
2293 cout << *it;
2294 if(*it != *s.rbegin()) {
2295 cout << ' ';
2296 }
2297 }
2298 return 0;
2299 }
2300 }// namespace b1065
2301
2302 namespace b1067 {
2303 int main(istream &cin, ostream &cout) {
2304 string pwd;
2305 int n;
2306 cin >> pwd >> n;
2307 int cnt = 0;
2308 char s[1024];
2309 cin.getline(s, 1024);
2310 while(true) {
2311 cin.getline(s, 1024);
2312 auto str = string(s);
2313 if(str == "#") {
2314 return 0;
2315 }
2316 if(cnt == n) {
2317 cout << "Account locked";
2318 return 0;
2319 }
2320 if(str != pwd) {
2321 cout << "Wrong password: " << str << endl;
2322 cnt++;
2323 if(cnt == n) {
2324 cout << "Account locked";
2325 return 0;
2326 }
2327 } else {
2328 cout << "Welcome in";
2329 return 0;
2330 }
2331 }
2332 }
2333 }// namespace b1067
2334
2335 namespace b1068 {
2336 int main(istream &cin, ostream &cout) {
2337 long m;
2338 long n;
2339 long tol;
2340 cin >> m >> n >> tol;
2341 vector grid(n, vector<long>(m));
2342 unordered_map<long, unsigned long> um_cnt;
2343 unordered_map<long, long> um_x;
2344 unordered_map<long, long> um_y;
2345 for(int i = 0; i < n; i++) {
2346 for(int j = 0; j < m; j++) {
2347 cin >> grid[i][j];
2348 um_cnt[grid[i][j]]++;
2349 um_x[grid[i][j]] = i;
2350 um_y[grid[i][j]] = j;
2351 }
2352 }
2353 long ans_x;
2354 long ans_y;
2355 long ans_v;
2356 bool has_ans = false;
2357 for(auto [v, cnt]: um_cnt) {
2358 if(cnt == 1) {
2359 long x = um_x[v];
2360 long y = um_y[v];
2361 pair<long, long> surroundings[8] = {make_pair(x - 1, y - 1), make_pair(x - 1, y), make_pair(x - 1, y + 1),
2362 make_pair(x, y - 1), make_pair(x, y + 1),
2363 make_pair(x + 1, y - 1), make_pair(x + 1, y), make_pair(x + 1, y + 1)};
2364 bool flag = true;
2365 for(auto [s_x, s_y]: surroundings) {
2366 if(s_x >= 0 && s_x < n && s_y >= 0 && s_y < m) {
2367 const long dist = abs(v - grid[s_x][s_y]);
2368 if(dist <= tol) {
2369 flag = false;
2370 break;
2371 }
2372 }
2373 }
2374 if(flag) {
2375 if(!has_ans) {
2376 ans_x = x + 1;
2377 ans_y = y + 1;
2378 ans_v = v;
2379 has_ans = true;
2380 } else {
2381 cout << "Not Unique";
2382 return 0;
2383 }
2384 }
2385 }
2386 }
2387 if(has_ans) {
2388 cout << '(' << ans_y << ", " << ans_x << "): " << ans_v;
2389 } else {
2390 cout << "Not Exist";
2391 }
2392 return 0;
2393 }
2394 }// namespace b1068
2395
2396 namespace b1069 {
2397 int main(istream &cin, ostream &cout) {
2398 int m;
2399 int n;
2400 int s;
2401 cin >> m >> n >> s;
2402 string name;
2403 unordered_set<string> names;
2404 vector<string> list(m);
2405 int cnt = 0;
2406 for(int i = 0; i < m; i++) {
2407 cin >> list[i];
2408 }
2409 for(int i = s - 1; i < m;) {
2410 if(names.contains(list[i])) {
2411 i++;
2412 continue;
2413 }
2414 names.insert(list[i]);
2415 cout << list[i] << endl;
2416 cnt++;
2417 i += n;
2418 }
2419 if(cnt == 0) {
2420 cout << "Keep going...";
2421 }
2422 return 0;
2423 }
2424 }// namespace b1069
2425
2426 namespace b1070 {
2427 int main(istream &cin, ostream &cout) {
2428 int n;
2429 cin >> n;
2430 vector<int> vec(n);
2431 for(int i = 0; i < n; i++) {
2432 cin >> vec[i];
2433 }
2434 sort(vec.begin(), vec.end());
2435 int current = vec[0];
2436 for(int i = 1; i < n; i++) {
2437 current = (current + vec[i]) / 2;
2438 }
2439 cout << current;
2440 return 0;
2441 }
2442 }// namespace b1070
2443
2444 namespace b1071 {
2445 int main(istream &cin, ostream &cout) {
2446 int t;
2447 int k;
2448 cin >> t >> k;
2449 while(k-- != 0) {
2450 int n1;
2451 int b;
2452 int tt;
2453 int n2;
2454 cin >> n1 >> b >> tt >> n2;
2455 if(tt > t) {
2456 cout << "Not enough tokens. Total = " << t << '.' << endl;
2457 continue;
2458 }
2459 if(static_cast<int>(n2 > n1) == b) {
2460 t += tt;
2461 cout << "Win " << tt << "! Total = " << t << '.' << endl;
2462 } else {
2463 t -= tt;
2464 cout << "Lose " << tt << ". Total = " << t << '.' << endl;
2465 }
2466 if(t == 0) {
2467 cout << "Game Over.";
2468 return 0;
2469 }
2470 }
2471 return 0;
2472 }
2473 }// namespace b1071
2474
2475 namespace b1072 {
2476 int main(istream &cin, ostream &cout) {
2477 int n;
2478 int m;
2479 cin >> n >> m;
2480 unordered_set<string> items;
2481 int stu_cnt = 0;
2482 int item_cnt = 0;
2483 while(m-- != 0) {
2484 string item;
2485 cin >> item;
2486 items.insert(item);
2487 }
2488 for(int i = 0; i < n; i++) {
2489 string name;
2490 int k;
2491 cin >> name >> k;
2492 vector<string> vec;
2493 for(int j = 0; j < k; j++) {
2494 string item;
2495 cin >> item;
2496 if(items.contains(item)) {
2497 vec.push_back(item);
2498 }
2499 }
2500 item_cnt += vec.size();
2501 if(!vec.empty()) {
2502 stu_cnt++;
2503 cout << name << ':';
2504 for(const auto &item: vec) {
2505 cout << ' ' << item;
2506 }
2507 cout << endl;
2508 }
2509 }
2510 cout << stu_cnt << ' ' << item_cnt;
2511 return 0;
2512 }
2513 }// namespace b1072
2514
2515 namespace b1073 {
2516 int main(istream &cin, ostream &cout) {
2517 int n;
2518 int m;
2519 cin >> n >> m;
2520 vector<problem> problems(m);
2521 map<pair<int, char>, int> noe;
2522 int max_cnt = 0;
2523 for(int i = 0; i < m; i++) {
2524 problem p;
2525 p.id = i + 1;
2526 cin >> p.score >> p.noa >> p.noca;
2527 p.ca = unordered_set<char>();
2528 for(int j = 0; j < p.noca; j++) {
2529 char ca;
2530 cin >> ca;
2531 p.ca.insert(ca);
2532 }
2533 problems[i] = p;
2534 }
2535 char ch;
2536 for(int i = 0; i < n; i++) {
2537 double score = 0;
2538 for(int j = 0; j < m; j++) {
2539 unordered_set<char> as;
2540 cin >> ch;
2541 int noa;
2542 cin >> noa;
2543 bool flag = true;
2544 for(int k = 0; k < noa; k++) {
2545 char a;
2546 cin >> a;
2547 as.insert(a);
2548 if(!problems[j].ca.contains(a)) {
2549 noe[make_pair(problems[j].id, a)]++;
2550 max_cnt = max(max_cnt, noe[make_pair(problems[j].id, a)]);
2551 flag = false;
2552 }
2553 }
2554 cin >> ch;
2555 for(auto a: problems[j].ca) {
2556 if(!as.contains(a)) {
2557 noe[make_pair(problems[j].id, a)]++;
2558 max_cnt = max(max_cnt, noe[make_pair(problems[j].id, a)]);
2559 }
2560 }
2561 if(!flag) {
2562 continue;
2563 }
2564 if(noa == problems[j].noca) {
2565 score += problems[j].score;
2566 } else {
2567 score += static_cast<double>(problems[j].score) / 2;
2568 }
2569 }
2570 cout << fixed << setprecision(1) << score << endl;
2571 }
2572 if(noe.empty()) {
2573 cout << "Too simple";
2574 } else {
2575 for(const auto &[k, cnt]: noe) {
2576 if(cnt == max_cnt) {
2577 const auto &[id, a] = k;
2578 cout << cnt << ' ' << id << '-' << a << endl;
2579 }
2580 }
2581 }
2582 return 0;
2583 }
2584 }// namespace b1073
2585
2586 namespace b1074 {
2587 int main(istream &cin, ostream &cout) {
2588 string str_n;
2589 string str_a;
2590 string str_b;
2591 cin >> str_n >> str_a >> str_b;
2592 vector<int> n;
2593 vector<int> a;
2594 vector<int> b;
2595 vector<int> ans;
2596 for(int i = str_n.length() - 1; i >= 0; i--) {
2597 if(str_n[i] == '0') {
2598 n.push_back(10);
2599 } else {
2600 n.push_back(str_n[i] - '0');
2601 }
2602 }
2603 for(int i = str_a.length() - 1; i >= 0; i--) {
2604 a.push_back(str_a[i] - '0');
2605 }
2606 for(int i = str_b.length() - 1; i >= 0; i--) {
2607 b.push_back(str_b[i] - '0');
2608 }
2609 int carry = 0;
2610 for(int i = 0; i < max(a.size(), b.size()) || carry != 0; i++) {
2611 const int radix = i < n.size() ? n[i] : 10;
2612 const int num_a = i < a.size() ? a[i] : 0;
2613 const int num_b = i < b.size() ? b[i] : 0;
2614 const int sum = num_a + num_b + carry;
2615 ans.push_back(sum % radix);
2616 carry = sum / radix;
2617 }
2618 int i = ans.size() - 1;
2619 while(ans[i] == 0 && i > 0) {
2620 i--;
2621 }
2622 for(; i >= 0; i--) {
2623 cout << ans[i];
2624 }
2625 return 0;
2626 }
2627 }// namespace b1074
2628
2629 namespace b1075 {
2630 int main(istream &cin, ostream &cout) {
2631 string current;
2632 int n;
2633 int k;
2634 cin >> current >> n >> k;
2635 unordered_map<string, Node> um;
2636 for(int i = 0; i < n; i++) {
2637 Node node;
2638 cin >> node.addr;
2639 cin >> node.data;
2640 cin >> node.next;
2641 um[node.addr] = node;
2642 }
2643 vector<Node> vec1;
2644 vector<Node> vec2;
2645 vector<Node> vec3;
2646 while(current != "-1") {
2647 Node node = um[current];
2648 if(node.data < 0) {
2649 vec1.push_back(node);
2650 } else if(node.data <= k) {
2651 vec2.push_back(node);
2652 } else {
2653 vec3.push_back(node);
2654 }
2655 current = node.next;
2656 }
2657 vector<Node> vec;
2658 vec.insert(vec.end(), vec1.begin(), vec1.end());
2659 vec.insert(vec.end(), vec2.begin(), vec2.end());
2660 vec.insert(vec.end(), vec3.begin(), vec3.end());
2661 for(int i = 0; i < vec.size(); i++) {
2662 Node node = vec[i];
2663 cout << node.addr << ' ' << node.data << ' ' << (i + 1 < vec.size() ? vec[i + 1].addr : "-1") << endl;
2664 }
2665 return 0;
2666 }
2667 }// namespace b1075
2668
2669 namespace b1076 {
2670 int main(istream &cin, ostream &cout) {
2671 int n;
2672 cin >> n;
2673 stringstream ss;
2674 for(int i = 0; i < n; i++) {
2675 for(int j = 0; j < 4; j++) {
2676 char a;
2677 char b;
2678 char c;
2679 cin >> a >> b >> c;
2680 if(c == 'T') {
2681 ss << a - 'A' + 1;
2682 }
2683 }
2684 }
2685 cout << ss.str();
2686 return 0;
2687 }
2688 }// namespace b1076
2689
2690 namespace b1078 {
2691 int main(istream &cin, ostream &cout) {
2692 char op;
2693 cin >> op;
2694 char str[1024];
2695 cin.getline(str, 1024);
2696 cin.getline(str, 1024);
2697 if(op == 'C') {
2698 for(int i = 0; i < strlen(str); i++) {
2699 int n = 1;
2700 while(i + 1 < strlen(str) && str[i] == str[i + 1]) {
2701 n++;
2702 i++;
2703 }
2704 if(n > 1) {
2705 cout << n;
2706 }
2707 cout << str[i];
2708 }
2709 } else {
2710 //op=='D'
2711 for(int i = 0; i < strlen(str); i++) {
2712 if(isdigit(str[i]) != 0) {
2713 stringstream ss;
2714 for(; i < strlen(str); i++) {
2715 if(isdigit(str[i]) != 0) {
2716 ss << str[i];
2717 } else {
2718 break;
2719 }
2720 }
2721 int n;
2722 ss >> n;
2723 for(int j = 0; j < n; j++) {
2724 cout << str[i];
2725 }
2726 } else {
2727 cout << str[i];
2728 }
2729 }
2730 }
2731 return 0;
2732 }
2733 }// namespace b1078
2734
2735 namespace b1077 {
2736 int main(istream &cin, ostream &cout) {
2737 int n;
2738 int m;
2739 cin >> n >> m;
2740 for(int i = 0; i < n; i++) {
2741 int s_teacher;
2742 cin >> s_teacher;
2743 vector<int> scores;
2744 for(int j = 1; j < n; j++) {
2745 int score;
2746 cin >> score;
2747 if(0 <= score && score <= m) {
2748 scores.push_back(score);
2749 }
2750 }
2751 sort(scores.begin(), scores.end());
2752 scores.erase(scores.begin());
2753 scores.erase(--scores.end());
2754 int sum = 0;
2755 for(int j = 0; j < scores.size(); j++) {
2756 sum += scores[j];
2757 }
2758 const double avg = static_cast<double>(sum) / scores.size();
2759 const int final = static_cast<int>((avg + s_teacher) / 2 + 0.5);
2760 cout << final << endl;
2761 }
2762 return 0;
2763 }
2764 }// namespace b1077
2765
2766 namespace b1079 {
2767 bool is_palindromic(string str) {
2768 for(int i = 0; i < str.length() / 2; i++) {
2769 if(str[i] != str[str.length() - 1 - i]) {
2770 return false;
2771 }
2772 }
2773 return true;
2774 }
2775
2776 int main(istream &cin, ostream &cout) {
2777 string str;
2778 cin >> str;
2779 BigInt bi(str);
2780 for(int i = 0; i < 10; i++) {
2781 stringstream ss;
2782 ss << bi;
2783 str = ss.str();
2784 if(is_palindromic(str)) {
2785 cout << bi << " is a palindromic number.";
2786 return 0;
2787 }
2788 auto str_b = string(str.rbegin(), str.rend());
2789 BigInt bi_b(str_b);
2790 BigInt c = bi + bi_b;
2791 cout << str << " + " << str_b << " = " << c << endl;
2792 bi = c;
2793 }
2794 cout << "Not found in 10 iterations.";
2795 return 0;
2796 }
2797 }// namespace b1079
2798
2799 namespace b1080 {
2800 int main(istream &cin, ostream &cout) {
2801 int p;
2802 int m;
2803 int n;
2804 cin >> p >> m >> n;
2805 unordered_map<string, student> um;
2806 for(int i = 0; i < p; i++) {
2807 string id;
2808 cin >> id >> um[id].p;
2809 }
2810 for(int i = 0; i < m; i++) {
2811 string id;
2812 cin >> id >> um[id].mid_term;
2813 }
2814 for(int i = 0; i < n; i++) {
2815 string id;
2816 cin >> id >> um[id].final;
2817 }
2818 vector<student> vec;
2819 for(auto &[id, stu]: um) {
2820 stu.id = id;
2821 stu.score = stu.get_score();
2822 if(stu.p >= 200 && stu.score >= 60) {
2823 vec.push_back(stu);
2824 }
2825 }
2826 sort(vec.begin(), vec.end());
2827 for(const auto &stu: vec) {
2828 cout << stu.id << ' ' << stu.p << ' ' << stu.mid_term << ' ' << stu.final << ' ' << stu.score << endl;
2829 }
2830 return 0;
2831 }
2832
2834 const int mt = mid_term == -1 ? 0 : mid_term;
2835 const int f = final == -1 ? 0 : final;
2836 if(mt > f) {
2837 return static_cast<int>(mt * 0.4 + f * 0.6 + 0.5);
2838 }
2839 return f;
2840 }
2841
2842 bool student::operator<(const student &stu) const {
2843 if(this->score != stu.score) {
2844 return this->score > stu.score;
2845 }
2846 return this->id < stu.id;
2847 }
2848 }// namespace b1080
2849
2850 namespace b1081 {
2851 int main(istream &cin, ostream &cout) {
2852 int n;
2853 cin >> n;
2854 char str[1024];
2855 cin.getline(str, 1024);
2856 while(n-- != 0) {
2857 cin.getline(str, 1024);
2858 auto password = string(str);
2859 bool alpha = false;
2860 bool digit = false;
2861 bool ok = true;
2862 if(password.length() < 6) {
2863 cout << "Your password is tai duan le." << endl;
2864 } else {
2865 for(const char ch: password) {
2866 if(isdigit(ch) != 0) {
2867 digit = true;
2868 } else if(isalpha(ch) != 0) {
2869 alpha = true;
2870 } else if(ch != '.') {
2871 ok = false;
2872 cout << "Your password is tai luan le." << endl;
2873 break;
2874 }
2875 }
2876 if(!ok) {
2877 continue;
2878 }
2879 if(alpha && !digit) {
2880 cout << "Your password needs shu zi." << endl;
2881 } else if(!alpha && digit) {
2882 cout << "Your password needs zi mu." << endl;
2883 } else if(alpha && digit) {
2884 cout << "Your password is wan mei." << endl;
2885 } else {
2886 return 1;
2887 }
2888 }
2889 }
2890 return 0;
2891 }
2892 }// namespace b1081
2893
2894 namespace b1082 {
2895 int main(istream &cin, ostream &cout) {
2896 int n;
2897 cin >> n;
2898 vector<player> vec(n);
2899 for(int i = 0; i < n; i++) {
2900 cin >> vec[i].id >> vec[i].x >> vec[i].y;
2901 }
2902 sort(vec.begin(), vec.end());
2903 cout << (*vec.begin()).id << ' ' << (*vec.rbegin()).id;
2904 return 0;
2905 }
2906
2907 int player::get_dist() const { return x * x + y * y; }
2908
2909 bool player::operator<(const player &p) const { return this->get_dist() < p.get_dist(); }
2910 }// namespace b1082
2911
2912 namespace b1083 {
2913 int main(istream &cin, ostream &cout) {
2914 int n;
2915 cin >> n;
2916 map<int, int, greater<>> m;
2917 for(int i = 1; i <= n; i++) {
2918 int val;
2919 cin >> val;
2920 m[abs(i - val)]++;
2921 }
2922 for(auto [k, v]: m) {
2923 if(v > 1) {
2924 cout << k << ' ' << v << endl;
2925 }
2926 }
2927 return 0;
2928 }
2929 }// namespace b1083
2930
2931 namespace b1084 {
2932 int main(istream &cin, ostream &cout) {
2933 string str;
2934 int n;
2935 cin >> str >> n;
2936 for(int i = 1; i < n; i++) {
2937 char ch = str[0];
2938 ostringstream oss;
2939 int count = 1;
2940 for(int j = 1; j < str.length(); j++) {
2941 if(str[j] == ch) {
2942 count++;
2943 } else {
2944 oss << ch << count;
2945 count = 1;
2946 ch = str[j];
2947 }
2948 }
2949 oss << ch << count;
2950 str = oss.str();
2951 }
2952 cout << str;
2953 return 0;
2954 }
2955 }// namespace b1084
2956
2957 namespace b1085 {
2958 int main(istream &cin, ostream &cout) {
2959 int n;
2960 cin >> n;
2961 unordered_map<string, school> schools;
2962 for(int i = 0; i < n; i++) {
2963 string id;
2964 string sc;
2965 int score;
2966 cin >> id >> score >> sc;
2967 stringstream ss;
2968 for(char ch: sc) {
2969 ss << static_cast<char>(tolower(ch));
2970 }
2971 sc = ss.str();
2972 if(!schools.contains(sc)) {
2973 schools[sc] = school(sc);
2974 }
2975 schools[sc].count++;
2976 switch(id[0]) {
2977 case 'A':
2978 schools[sc].a_sum += score;
2979 break;
2980 case 'B':
2981 schools[sc].b_sum += score;
2982 break;
2983 case 'T':
2984 schools[sc].t_sum += score;
2985 break;
2986 default: return 1;
2987 }
2988 }
2989 vector<school> vec;
2990 vec.reserve(schools.size());
2991 for(const auto &[id, sc]: schools) {
2992 vec.push_back(sc);
2993 }
2994 sort(vec.rbegin(), vec.rend());
2995 unordered_map<int, int> score_rank;
2996 for(int i = vec.size() - 1; i >= 0; i--) {
2997 score_rank[vec[i].get_score()] = i + 1;
2998 }
2999 cout << vec.size() << endl;
3000 for(int i = 0; i < vec.size(); i++) {
3001 const auto &sc = vec[i];
3002 cout << score_rank[sc.get_score()] << ' ' << sc.id << ' ' << sc.get_score() << ' ' << sc.count << endl;
3003 }
3004 return 0;
3005 }
3006
3007 int school::get_score() const { return static_cast<int>(a_sum + b_sum / 1.5 + t_sum * 1.5); }
3008
3009 bool school::operator<(const school &sc) const {
3010 const int score1 = this->get_score();
3011 const int score2 = sc.get_score();
3012 if(score1 != score2) {
3013 return score1 < score2;
3014 }
3015 if(count != sc.count) {
3016 return count > sc.count;
3017 }
3018 return id > sc.id;
3019 }
3020 }// namespace b1085
3021
3022 namespace b1086 {
3023 int main(istream &cin, ostream &cout) {
3024 unsigned a;
3025 unsigned b;
3026 cin >> a >> b;
3027 ostringstream oss;
3028 oss << a * b;
3029 string str = oss.str();
3030 stringstream ss;
3031 for(auto it = str.rbegin(); it != str.rend(); ++it) {
3032 ss << *it;
3033 }
3034 unsigned ans;
3035 ss >> ans;
3036 cout << ans;
3037 return 0;
3038 }
3039 }// namespace b1086
3040
3041 namespace b1087 {
3042 int main(istream &cin, ostream &cout) {
3043 int n;
3044 cin >> n;
3045 cout << n / 2 + n / 3 + n / 5 - n / 6 - n / 10 - n / 15 + n / 30 + 1;
3046 return 0;
3047 }
3048 }// namespace b1087
3049
3050 namespace b1088 {
3051 int main(istream &cin, ostream &cout) {
3052 int m;
3053 int x;
3054 int y;
3055 cin >> m >> x >> y;
3056 int a;
3057 int b;
3058 int a_f;
3059 int b_f;
3060 double c_f;
3061 bool no_solution = true;
3062 for(int a = 10; a <= 99; a++) {
3063 ostringstream oss;
3064 oss << a;
3065 string str_a = oss.str();
3066 stringstream ss;
3067 for(auto it = str_a.rbegin(); it != str_a.rend(); ++it) {
3068 ss << *it;
3069 }
3070 ss >> b;
3071 const double c = static_cast<double>(b) / y;
3072 if(c * x == abs(a - b)) {
3073 no_solution = false;
3074 a_f = a;
3075 b_f = b;
3076 c_f = c;
3077 }
3078 }
3079 if(no_solution) {
3080 cout << "No Solution";
3081 return 0;
3082 }
3083 cout << a_f << ' ';
3084 if(a_f < m) {
3085 cout << "Gai ";
3086 } else if(a_f == m) {
3087 cout << "Ping ";
3088 } else {
3089 cout << "Cong ";
3090 }
3091 if(b_f < m) {
3092 cout << "Gai ";
3093 } else if(b_f == m) {
3094 cout << "Ping ";
3095 } else {
3096 cout << "Cong ";
3097 }
3098 if(c_f < m) {
3099 cout << "Gai";
3100 } else if(c_f == m) {
3101 cout << "Ping";
3102 } else {
3103 cout << "Cong";
3104 }
3105 return 0;
3106 }
3107 }// namespace b1088
3108
3109 namespace b1089 {
3110 int main(istream &cin, ostream &cout) {
3111 int n;
3112 cin >> n;
3113 vector<int> vec(n);
3114 for(int i = 0; i < n; i++) {
3115 cin >> vec[i];
3116 }
3117 for(int i = 0; i + 1 < n; i++) {
3118 for(int j = i + 1; j < n; j++) {
3119 if(is_true(vec, i, j)) {
3120 cout << i + 1 << ' ' << j + 1;
3121 return 0;
3122 }
3123 }
3124 }
3125 cout << "No Solution";
3126 return 0;
3127 }
3128
3129 bool is_true(const vector<int> &vec, int wolf1, int wolf2) {
3130 int lie_count = 0;
3131 bool wolf_lie = false;
3132 for(int i = 0; i < vec.size(); i++) {
3133 const bool is_wolf = vec[i] < 0;
3134 const int target = abs(vec[i]) - 1;
3135 if(is_wolf && !(target == wolf1 || target == wolf2) || !is_wolf && (target == wolf1 || target == wolf2)) {
3136 lie_count++;
3137 if(i == wolf1 || i == wolf2) {
3138 if(wolf_lie) {
3139 return false;
3140 }
3141 wolf_lie = true;
3142 }
3143 }
3144 if(lie_count > 2) {
3145 return false;
3146 }
3147 }
3148 return wolf_lie;
3149 }
3150 }// namespace b1089
3151
3152 namespace b1090 {
3153 int main(istream &cin, ostream &cout) {
3154 int n;
3155 int m;
3156 cin >> n >> m;
3157 unordered_map<string, unordered_set<string>> um;
3158 for(int i = 0; i < n; i++) {
3159 string a;
3160 string b;
3161 cin >> a >> b;
3162 um[a].insert(b);
3163 um[b].insert(a);
3164 }
3165 for(int i = 0; i < m; i++) {
3166 int k;
3167 cin >> k;
3168 bool ok = true;
3169 unordered_set<string> us;
3170 for(int j = 0; j < k; j++) {
3171 string g;
3172 cin >> g;
3173 us.insert(g);
3174 }
3175 for(const auto &g: us) {
3176 for(const auto &nc: um[g]) {
3177 if(static_cast<unsigned int>(us.contains(nc)) != 0U) {
3178 ok = false;
3179 break;
3180 }
3181 }
3182 if(!ok) {
3183 break;
3184 }
3185 }
3186 if(ok) {
3187 cout << "Yes" << endl;
3188 } else {
3189 cout << "No" << endl;
3190 }
3191 }
3192 return 0;
3193 }
3194 }// namespace b1090
3195
3196 namespace b1091 {
3197 int main(istream &cin, ostream &cout) {
3198 int m;
3199 cin >> m;
3200 while(m-- != 0) {
3201 unsigned k;
3202 cin >> k;
3203 const unsigned k2 = k * k;
3204 unsigned q = 1;
3205 while(k / q != 0) {
3206 q *= 10;
3207 }
3208 bool ok = false;
3209 for(unsigned n = 1; n < 10; n++) {
3210 const unsigned nk2 = n * k2;
3211 if(nk2 % q == k) {
3212 ok = true;
3213 cout << n << ' ' << nk2 << endl;
3214 break;
3215 }
3216 }
3217 if(!ok) {
3218 cout << "No" << endl;
3219 }
3220 }
3221 return 0;
3222 }
3223 }// namespace b1091
3224
3225 namespace b1092 {
3226 int main(istream &cin, ostream &cout) {
3227 int n;
3228 int m;
3229 cin >> n >> m;
3230 vector sales(n, 0);
3231 for(int j = 0; j < m; j++) {
3232 for(int i = 0; i < n; i++) {
3233 unsigned sale;
3234 cin >> sale;
3235 sales[i] += sale;
3236 }
3237 }
3238 int maximum = 0;
3239 for(auto sale: sales) {
3240 maximum = max(maximum, sale);
3241 }
3242 cout << maximum << endl;
3243 int i = 0;
3244 for(i = 0; i < n; i++) {
3245 if(sales[i] == maximum) {
3246 cout << i + 1;
3247 break;
3248 }
3249 }
3250 i++;
3251 for(; i < n; i++) {
3252 if(sales[i] == maximum) {
3253 cout << ' ' << i + 1;
3254 }
3255 }
3256 return 0;
3257 }
3258 }// namespace b1092
3259
3260 namespace b1093 {
3261 int main(istream &cin, ostream &cout) {
3262 char a[1000010];
3263 char b[1000010];
3264 cin.getline(a, 1000010);
3265 cin.getline(b, 1000010);
3266 bool has[127];
3267 unordered_set<char> us;
3268 for(int i = 0; i < strlen(a); i++) {
3269 const char ch = a[i];
3270 if(!has[ch]) {
3271 cout << ch;
3272 has[ch] = true;
3273 }
3274 }
3275 for(int i = 0; i < strlen(b); i++) {
3276 const char ch = b[i];
3277 if(!has[ch]) {
3278 cout << ch;
3279 has[ch] = true;
3280 }
3281 }
3282 return 0;
3283 }
3284 }// namespace b1093
3285
3286 namespace b1094 {
3287 int main(istream &cin, ostream &cout) {
3288 int l;
3289 int k;
3290 cin >> l >> k;
3291 vector<char> n(l);
3292 for(int i = 0; i < l; i++) {
3293 cin >> n[i];
3294 n[i] -= '0';
3295 }
3296 for(int i = 0, j = k - 1; j < l; i++, j++) {
3297 unsigned int ans = 0;
3298 for(int m = i; m <= j; m++) {
3299 ans *= 10;
3300 ans += n[m];
3301 }
3302 if(is_prime(ans)) {
3303 for(int m = i; m <= j; m++) {
3304 cout << static_cast<char>(n[m] + '0');
3305 }
3306 return 0;
3307 }
3308 }
3309 cout << 404;
3310 return 0;
3311 }
3312
3313 bool is_prime(unsigned int n) {
3314 if(n < 2) {
3315 return false;
3316 }
3317 for(int i = 2; i <= sqrt(n); i++) {
3318 if(n % i == 0) {
3319 return false;
3320 }
3321 }
3322 return true;
3323 }
3324 }// namespace b1094
3325
3326 namespace b1095 {
3327 int main(istream &cin, ostream &cout) {
3328 int n;
3329 int m;
3330 cin >> n >> m;
3331 unordered_map<string, room> rooms;
3332 unordered_map<char, unordered_set<student *>> levels;
3333 unordered_map<string, unordered_map<string, int>> dates;
3334 for(int i = 0; i < n; i++) {
3335 auto *stu = new student();
3336 cin >> stu->id >> stu->grade;
3337 stu->level = stu->id[0];
3338 stu->room = stu->id.substr(1, 3);
3339 stu->date = stu->id.substr(4, 6);
3340 rooms[stu->room].sum += stu->grade;
3341 rooms[stu->room].count++;
3342 levels[stu->level].insert(stu);
3343 dates[stu->date][stu->room]++;
3344 }
3345 for(int i = 0; i < m; i++) {
3346 int typ;
3347 cin >> typ;
3348 cout << "Case " << i + 1 << ": " << typ << ' ';
3349 if(typ == 1) {
3350 char l;
3351 cin >> l;
3352 cout << l << endl;
3353 if(static_cast<unsigned int>(levels.contains(l)) != 0U) {
3354 vector<student *> vec;
3355 for(auto *const pstu: levels[l]) {
3356 vec.emplace_back(pstu);
3357 }
3358 sort(vec.begin(), vec.end(), p_stu_comp());
3359 for(auto *stu: vec) {
3360 cout << stu->id << ' ' << stu->grade << endl;
3361 }
3362 } else {
3363 cout << "NA" << endl;
3364 }
3365 } else if(typ == 2) {
3366 string room_id;
3367 cin >> room_id;
3368 cout << room_id << endl;
3369 if(static_cast<unsigned int>(rooms.contains(room_id)) != 0U) {
3370 cout << rooms[room_id].count << ' ' << rooms[room_id].sum << endl;
3371 } else {
3372 cout << "NA" << endl;
3373 }
3374 } else if(typ == 3) {
3375 string date;
3376 cin >> date;
3377 cout << date << endl;
3378 if(dates[date].empty()) {
3379 cout << "NA" << endl;
3380 continue;
3381 }
3382 vector<pair<string, int>> vec;
3383 for(const auto &room_cnt: dates[date]) {
3384 vec.emplace_back(room_cnt);
3385 }
3386 sort(vec.begin(), vec.end(), room_cnt_comp());
3387 for(const auto &[id, cnt]: vec) {
3388 cout << id << ' ' << cnt << endl;
3389 }
3390 } else {
3391 string op;
3392 cout << op << endl;
3393 cout << "NA" << endl;
3394 }
3395 }
3396 return 0;
3397 }
3398
3399 bool p_stu_comp::operator()(const student *stu1, const student *stu2) const {
3400 if(stu1->grade != stu2->grade) {
3401 return stu1->grade > stu2->grade;
3402 }
3403 return stu1->id < stu2->id;
3404 }
3405
3406 bool room_cnt_comp::operator()(const pair<string, int> &p1, const pair<string, int> &p2) const {
3407 if(p1.second != p2.second) {
3408 return p1.second > p2.second;
3409 }
3410 return p1.first < p2.first;
3411 }
3412 }// namespace b1095
3413
3414 namespace b1096 {
3415 int main(istream &cin, ostream &cout) {
3416 int k;
3417 cin >> k;
3418 for(int i = 0; i < k; i++) {
3419 unsigned num;
3420 cin >> num;
3421 unordered_set<unsigned> fs;
3422 for(unsigned f = 1; f <= num; f++) {
3423 if(num % f == 0) {
3424 fs.insert(f);
3425 }
3426 }
3427 vector<unsigned> vec(fs.size());
3428 int fi = 0;
3429 for(const auto f: fs) {
3430 vec[fi++] = f;
3431 }
3432 if(vec.size() < 4) {
3433 cout << "No" << endl;
3434 continue;
3435 }
3436 bool ok = false;
3437 for(auto i1 = 0; i1 + 3 < vec.size(); i1++) {
3438 for(auto i2 = i1 + 1; i2 + 2 < vec.size(); i2++) {
3439 for(auto i3 = i2 + 1; i3 + 1 < vec.size(); i3++) {
3440 for(auto i4 = i3 + 1; i4 < vec.size(); i4++) {
3441 if((vec[i1] + vec[i2] + vec[i3] + vec[i4]) % num == 0) {
3442 ok = true;
3443 goto LOOP_END;
3444 }
3445 }
3446 }
3447 }
3448 }
3449 LOOP_END:
3450 if(ok) {
3451 cout << "Yes" << endl;
3452 } else {
3453 cout << "No" << endl;
3454 }
3455 }
3456 return 0;
3457 }
3458 }// namespace b1096
3459
3460 namespace b1097 {
3461 int main(istream &cin, ostream &cout) {
3462 int n;
3463 int k;
3464 int x;
3465 cin >> n >> k >> x;
3466 vector grid(n, vector<int>(n));
3467 for(int i = 0; i < n; i++) {
3468 for(int j = 0; j < n; j++) {
3469 cin >> grid[i][j];
3470 }
3471 }
3472 int indent = 1;
3473 for(int i = 0; i < n; i += 2) {
3474 for(int j = n - 1; j >= 0; j--) {
3475 grid[i][j] = j - indent >= 0 ? grid[i][j - indent] : x;
3476 }
3477 indent++;
3478 if(indent == k + 1) {
3479 indent = 1;
3480 }
3481 }
3482 for(int j = 0; j < n; j++) {
3483 int sum = 0;
3484 for(int i = 0; i < n; i++) {
3485 sum += grid[i][j];
3486 }
3487 cout << sum;
3488 if(j != n - 1) {
3489 cout << ' ';
3490 }
3491 }
3492 return 0;
3493 }
3494 }// namespace b1097
3495
3496 namespace b1098 {
3497 int main(istream &cin, ostream &cout) {
3498 int n;
3499 cin >> n;
3500 int top = 1000;
3501 int bottom = 0;
3502 for(int i = 0; i < n; i++) {
3503 int v;
3504 cin >> v;
3505 top = min(top, v);
3506 }
3507 for(int i = 0; i < n; i++) {
3508 int v;
3509 cin >> v;
3510 bottom = max(bottom, v);
3511 }
3512 if(top <= bottom) {
3513 cout << "No " << bottom - top + 1;
3514 } else {
3515 cout << "Yes " << top - bottom;
3516 }
3517 return 0;
3518 }
3519 }// namespace b1098
3520
3521 namespace b1099 {
3522 int main(istream &cin, ostream &cout) {
3523 unsigned int n;
3524 cin >> n;
3525 if(is_prime(n)) {
3526 if(n > 7 && is_prime(n - 6)) {
3527 cout << "Yes" << endl
3528 << n - 6;
3529 return 0;
3530 }
3531 if(is_prime(n + 6)) {
3532 cout << "Yes" << endl
3533 << n + 6;
3534 return 0;
3535 }
3536 }
3537 for(unsigned int i = n + 1;; i++) {
3538 if(is_prime(i)) {
3539 if(i > 7 && is_prime(i - 6)) {
3540 cout << "No" << endl
3541 << i;
3542 return 0;
3543 }
3544 if(is_prime(i + 6)) {
3545 cout << "No" << endl
3546 << i;
3547 return 0;
3548 }
3549 if(is_prime(i + 6)) {
3550 cout << "No" << endl
3551 << i;
3552 return 0;
3553 }
3554 }
3555 }
3556 }
3557
3558 bool is_prime(unsigned int n) {
3559 if(n == 1) {
3560 return false;
3561 }
3562 for(unsigned int i = 2; i <= sqrt(n); i++) {
3563 if(n % i == 0) {
3564 return false;
3565 }
3566 }
3567 return true;
3568 }
3569 }// namespace b1099
3570
3571 namespace b1100 {
3572 int main(istream &cin, ostream &cout) {
3573 int n;
3574 cin >> n;
3575 unordered_set<string> alumnuses;
3576 for(int i = 0; i < n; i++) {
3577 string id;
3578 cin >> id;
3579 alumnuses.insert(id);
3580 }
3581 int m;
3582 cin >> m;
3583 unsigned cnt = 0;
3584 unordered_set<string> guests;
3585 for(int i = 0; i < m; i++) {
3586 string id;
3587 cin >> id;
3588 cnt += alumnuses.count(id);
3589 guests.insert(id);
3590 }
3591 cout << cnt << endl;
3592 vector<string> vec;
3593 if(cnt > 0) {
3594 for(const auto &id: guests) {
3595 if(alumnuses.contains(id)) {
3596 vec.emplace_back(id);
3597 }
3598 }
3599 } else {
3600 vec = vector(guests.begin(), guests.end());
3601 }
3602 sort(vec.begin(), vec.end(), comp());
3603 cout << *vec.begin();
3604 return 0;
3605 }
3606
3607 bool comp::operator()(const string &s1, const string &s2) const { return s1.substr(6, 8) < s2.substr(6, 8); }
3608 }// namespace b1100
3609
3610 namespace b1101 {
3611 int main(istream &cin, ostream &cout) {
3612 string a;
3613 int d;
3614 cin >> a >> d;
3615 stringstream ss;
3616 ss << a.substr(a.length() - d, d) << a.substr(0, a.length() - d);
3617 double b;
3618 ss >> b;
3619 cout << fixed << setprecision(2) << b / stoi(a);
3620 return 0;
3621 }
3622 }// namespace b1101
3623
3624 namespace b1102 {
3625 int main(istream &cin, ostream &cout) {
3626 int n;
3627 cin >> n;
3628 vector<paper> vec(n);
3629 for(int i = 0; i < n; i++) {
3630 cin >> vec[i].id;
3631 cin >> vec[i].price;
3632 cin >> vec[i].sale;
3633 }
3634 sort(vec.rbegin(), vec.rend(), comp_sale());
3635 cout << vec.begin()->id << ' ' << vec.begin()->sale << endl;
3636 sort(vec.rbegin(), vec.rend(), comp_total());
3637 cout << vec.begin()->id << ' ' << vec.begin()->price * vec.begin()->sale;
3638 return 0;
3639 }
3640
3641 bool comp_sale::operator()(const paper &p1, const paper &p2) const { return p1.sale < p2.sale; }
3642
3643 bool comp_total::operator()(const paper &p1, const paper &p2) const { return p1.sale * p1.price < p2.sale * p2.price; }
3644 }// namespace b1102
3645
3646 namespace b1103 {
3647 int main(istream &cin, ostream &cout) {
3648 unsigned m;
3649 unsigned n;
3650 cin >> m >> n;
3651 unordered_map<unsigned, unsigned> c2a;
3652 unsigned max_c2 = 0;
3653 for(unsigned a = m; a <= n; a++) {
3654 unsigned c2 = 3 * a * (a - 1) + 1;
3655 max_c2 = c2;
3656 c2a[c2] = a;
3657 }
3658 bool ok = false;
3659 unsigned c2 = 0;
3660 for(unsigned b = 1; c2 <= max_c2; b++) {
3661 c2 = (b * b + (b - 1) * (b - 1)) * (b * b + (b - 1) * (b - 1));
3662 if(c2a.contains(c2)) {
3663 ok = true;
3664 cout << c2a[c2] << ' ' << b << endl;
3665 }
3666 }
3667 if(!ok) {
3668 cout << "No Solution";
3669 }
3670 return 0;
3671 }
3672 }// namespace b1103
3673
3674 namespace b1104 {
3675 int main(istream &cin, ostream &cout) {
3676 int N;
3677 cin >> N;
3678 vector<int> diff(10);
3679 for(int i = 0; i < 10; i++) {
3680 diff[i] = 1 - i * 9;
3681 }
3682 for(int i = 1; i <= N; i++) {
3683 bool ok = false;
3684 int k;
3685 int m;
3686 cin >> k >> m;
3687 cout << "Case " << i << endl;
3688 for(int j = k; j >= 1; j--) {
3689 const int n = m + diff[j];
3690 const int g = gcd(m, n);
3691 if(n > 0 && g > 2 && is_prime(gcd(m, n))) {
3692 vector<string> ans;
3693 dfs("", 1, m, k, 0, j, ans);
3694 if(!ans.empty()) {
3695 ok = true;
3696 for(const auto &str: ans) {
3697 cout << m + diff[j] << ' ' << str << endl;
3698 }
3699 }
3700 }
3701 }
3702 if(!ok) {
3703 cout << "No Solution" << endl;
3704 }
3705 }
3706 return 0;
3707 }
3708
3709 bool is_prime(int n) {
3710 if(n == 1) {
3711 return false;
3712 }
3713 for(int i = 2; i <= sqrt(n); i++) {
3714 if(n % i == 0) {
3715 return false;
3716 }
3717 }
3718 return true;
3719 }
3720
3721 void dfs(string str, const int current_i, const int m, const int k, const int current_sum, const int cnt9, vector<string> &ans) {
3722 if(current_i + cnt9 == k) {
3723 if(const int r = m - current_sum - cnt9 * 9; (current_i > 1 && r >= 0 || current_i == 1 && r > 0) && r < 9) {
3724 str += static_cast<char>(r + '0');
3725 } else {
3726 return;
3727 }
3728 for(int i = 0; i < cnt9; i++) {
3729 str += '9';
3730 }
3731 ans.emplace_back(str);
3732 return;
3733 }
3734 for(int i = current_i == 1 ? 1 : 0; i <= 9; i++) {
3735 if(!(current_sum + i + cnt9 * 9 > m || current_sum + i + (k - current_i) * 9 - 1 < m)) {
3736 dfs(str + static_cast<char>(i + '0'), current_i + 1, m, k, current_sum + i, cnt9, ans);
3737 }
3738 }
3739 }
3740 }// namespace b1104
3741
3742 namespace b1105 {
3743 int main(istream &cin, ostream &cout) {
3744 string h1;
3745 string h2;
3746 int n;
3747 cin >> h1 >> h2 >> n;
3748 unordered_map<string, node> um;
3749 for(int i = 0; i < n; i++) {
3750 string address;
3751 cin >> address;
3752 um[address].address = address;
3753 cin >> um[address].data >> um[address].next;
3754 }
3755 vector<node> l1;
3756 vector<node> l2;
3757 for(string addr = h1; addr != "-1"; addr = um[addr].next) {
3758 l1.push_back(um[addr]);
3759 }
3760 for(string addr = h2; addr != "-1"; addr = um[addr].next) {
3761 l2.push_back(um[addr]);
3762 }
3763 if(l1.size() < l2.size()) {
3764 swap(l1, l2);
3765 }
3766 l2 = vector(l2.rbegin(), l2.rend());
3767 vector<node> ans;
3768 for(int cnt = 0, i1 = 0, i2 = 0; i1 < l1.size() || i2 < l2.size(); cnt++, cnt %= 3) {
3769 if(cnt <= 1) {
3770 if(i1 < l1.size()) {
3771 ans.push_back(l1[i1++]);
3772 }
3773 } else {
3774 if(i2 < l2.size()) {
3775 ans.push_back(l2[i2++]);
3776 }
3777 }
3778 }
3779 for(int i = 0; i < ans.size(); i++) {
3780 cout << ans[i].address << ' ' << ans[i].data << ' ' << (i + 1 < ans.size() ? ans[i + 1].address : "-1") << endl;
3781 }
3782 return 0;
3783 }
3784 }// namespace b1105
3785
3786 namespace b1106 {
3787 int main(istream &cin, ostream &cout) {
3788 int n;
3789 cin >> n;
3790 vector<unsigned> vec(n);
3791 vec[0] = 2;
3792 vec[1] = 0;
3793 vec[2] = 1;
3794 vec[3] = 9;
3795 unsigned current = 2 + 0 + 1 + 9;
3796 for(int i = 4; i < n; i++) {
3797 vec[i] = current % 10;
3798 current -= vec[i - 4];
3799 current += vec[i];
3800 }
3801 for(const auto num: vec) {
3802 cout << num;
3803 }
3804 return 0;
3805 }
3806 }// namespace b1106
3807
3808 namespace b1107 {
3809 int main(istream &cin, ostream &cout) {
3810 int n;
3811 int m;
3812 cin >> n >> m;
3813 int champion = 0;
3814 for(int i = 0; i < n; i++) {
3815 int maximum = 0;
3816 for(int j = 0; j < m; j++) {
3817 int weight;
3818 cin >> weight;
3819 maximum = max(maximum, weight);
3820 }
3821 cout << maximum;
3822 if(i != n - 1) {
3823 cout << ' ';
3824 }
3825 champion = max(champion, maximum);
3826 }
3827 cout << endl
3828 << champion;
3829 return 0;
3830 }
3831 }// namespace b1107
3832
3833 namespace b1108 {
3834 int main(istream &cin, ostream &cout) {
3835 unordered_map<char, int> um;
3836 char ch;
3837 while(cin >> ch) {
3838 um[ch]++;
3839 }
3840 const char word[6] = {'S', 't', 'r', 'i', 'n', 'g'};
3841 int cnt = 0;
3842 for(int i = 0; cnt < 6; i++, i %= 6) {
3843 if(um[word[i]] > 0) {
3844 cout << word[i];
3845 um[word[i]]--;
3846 cnt = 0;
3847 } else {
3848 cnt++;
3849 }
3850 }
3851 return 0;
3852 }
3853 }// namespace b1108
3854
3855 namespace b1109 {
3856 int main(istream &cin, ostream &cout) {
3857 char matrix[26][7][5];
3858 for(int i = 0; i < 26; i++) {
3859 for(int j = 0; j < 7; j++) {
3860 for(int k = 0; k < 5; k++) {
3861 cin >> matrix[i][j][k];
3862 }
3863 }
3864 }
3865 vector<string> vec;
3866 ostringstream oss;
3867 char ch;
3868 cin >> noskipws;
3869 while(cin >> ch) {
3870 if(isupper(ch) != 0) {
3871 oss << ch;
3872 } else {
3873 if(!oss.str().empty()) {
3874 vec.emplace_back(oss.str());
3875 }
3876 oss = ostringstream();
3877 }
3878 }
3879 if(!oss.str().empty()) {
3880 vec.emplace_back(oss.str());
3881 }
3882 int cnt = 0;
3883 for(const auto &str: vec) {
3884 const int w = str.length() * 6 - 1;
3885 vector output(7, vector(w, ' '));
3886 for(int i = 0; i < str.length(); i++) {
3887 const char c = str[i];
3888 for(int j = 0; j < 7; j++) {
3889 for(int k = 0; k < 5; k++) {
3890 output[j][i * 6 + k] = matrix[c - 'A'][j][k];
3891 }
3892 }
3893 }
3894 for(int i = 0; i < 7; i++) {
3895 for(int j = 0; j < w; j++) {
3896 cout << output[i][j];
3897 }
3898 if(i != 6) {
3899 cout << endl;
3900 }
3901 }
3902 if(cnt++ != vec.size() - 1) {
3903 cout << endl
3904 << endl;
3905 }
3906 }
3907 return 0;
3908 }
3909 }// namespace b1109
3910
3911 namespace b1110 {
3912 int main(istream &cin, ostream &cout) {
3913 string head;
3914 int n;
3915 int k;
3916 cin >> head >> n >> k;
3917 unordered_map<string, node> um;
3918 for(int i = 0; i < n; i++) {
3919 string address;
3920 cin >> address;
3921 um[address].address = address;
3922 cin >> um[address].data >> um[address].next;
3923 }
3924 deque<vector<node>> deq;
3925 vector<node> block;
3926 string current = head;
3927 while(current != "-1") {
3928 block.emplace_back(um[current]);
3929 if(block.size() == k) {
3930 deq.emplace_front(block);
3931 block.clear();
3932 }
3933 current = um[current].next;
3934 }
3935 if(!block.empty()) {
3936 deq.emplace_front(block);
3937 }
3938 block.clear();
3939 for(const auto &blk: deq) {
3940 for(const auto &nd: blk) {
3941 block.emplace_back(nd);
3942 }
3943 }
3944 for(int i = 0; i < block.size(); i++) {
3945 cout << block[i].address << " " << block[i].data << " " << (i + 1 < block.size() ? block[i + 1].address : "-1") << endl;
3946 }
3947 return 0;
3948 }
3949 }// namespace b1110
3950 }// namespace b
3951
3952 namespace a {
3953 namespace a1003 {
3954 int main(istream &cin, ostream &cout) {
3955 int N;
3956 int M;
3957 int C1;
3958 int C2;
3959 cin >> N >> M >> C1 >> C2;
3960 int max_d = 0;
3961 vector<int> rescue(N);
3962 vector grid(N, vector(N, 0));
3963 for(int i = 0; i < N; i++) {
3964 cin >> rescue[i];
3965 }
3966 for(int i = 0; i < M; i++) {
3967 int c1;
3968 int c2;
3969 int L;
3970 cin >> c1 >> c2 >> L;
3971 grid[c1][c2] = L;
3972 grid[c2][c1] = L;
3973 max_d += L;
3974 }
3975 vector shortest_cnt(N, 0);
3976 vector shortest(N, max_d + 1);
3977 vector max_rescue(N, 0);
3978 priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, comp> pq;
3979 pq.push(make_tuple(C1, 0, rescue[C1]));
3980 while(!pq.empty()) {
3981 auto [c, d, s] = pq.top();
3982 pq.pop();
3983 if(d < shortest[c]) {
3984 shortest[c] = d;
3985 shortest_cnt[c] = 1;
3986 max_rescue[c] = s;
3987 } else if(d == shortest[c]) {
3988 shortest_cnt[c]++;
3989 } else {
3990 continue;
3991 }
3992 if(s > max_rescue[c]) {
3993 max_rescue[c] = s;
3994 }
3995 for(int i = 0; i < N; i++) {
3996 if(grid[c][i] > 0 && d + grid[c][i] <= shortest[i]) {
3997 pq.push(make_tuple(i, d + grid[c][i], s + rescue[i]));
3998 }
3999 }
4000 }
4001 cout << shortest_cnt[C2] << ' ' << max_rescue[C2];
4002 return 0;
4003 }
4004
4005 bool comp::operator()(const tuple<int, int, int> &a, const tuple<int, int, int> &b) const {
4006 auto [a1, a2, a3] = a;
4007 auto [b1, b2, b3] = b;
4008 if(a2 != b2) {
4009 return a2 > b2;
4010 }
4011 return a3 < b3;
4012 }
4013 }// namespace a1003
4014
4015 namespace a1004 {
4016 int main(istream &cin, ostream &cout) {
4017 int n;
4018 int m;
4019 cin >> n >> m;
4020 if(n == 0) {
4021 return 0;
4022 }
4023 unordered_map<string, node *> um;
4024 for(int i = 0; i < m; i++) {
4025 string id;
4026 int k;
4027 cin >> id >> k;
4028 if(!um.contains(id)) {
4029 um[id] = new node(id);
4030 }
4031 auto *const nd = um[id];
4032 for(int j = 0; j < k; j++) {
4033 string cid;
4034 cin >> cid;
4035 if(!um.contains(cid)) {
4036 um[cid] = new node(cid);
4037 }
4038 nd->children.insert(um[cid]);
4039 }
4040 }
4041 queue<pair<node *, int>> q;
4042 q.push(make_pair(um["01"], 0));
4043 if(um["01"] == nullptr) {
4044 cout << 1;
4045 return 0;
4046 }
4047 int current_level = 0;
4048 int leaf_cnt = 0;
4049 while(!q.empty()) {
4050 auto [nd, level] = q.front();
4051 q.pop();
4052 if(level != current_level) {
4053 if(current_level != 0) {
4054 cout << ' ';
4055 }
4056 current_level = level;
4057 cout << leaf_cnt;
4058 leaf_cnt = 0;
4059 }
4060 if(nd->children.empty()) {
4061 leaf_cnt++;
4062 }
4063 for(auto *c: nd->children) {
4064 q.push(make_pair(c, level + 1));
4065 }
4066 }
4067 cout << ' ' << leaf_cnt;
4068 return 0;
4069 }
4070 }// namespace a1004
4071
4072 namespace a1005 {
4073 int main(istream &cin, ostream &cout) {
4074 unsigned long n = 0;
4075 string s;
4076 cin >> s;
4077 for(const char ch: s) {
4078 n += ch - '0';
4079 }
4080 auto oss = ostringstream();
4081 oss << n;
4082 s = oss.str();
4083 bool first = true;
4084 for(const char ch: s) {
4085 if(!first) {
4086 cout << ' ';
4087 }
4088 first = false;
4089 switch(ch) {
4090 case '0':
4091 cout << "zero";
4092 break;
4093 case '1':
4094 cout << "one";
4095 break;
4096 case '2':
4097 cout << "two";
4098 break;
4099 case '3':
4100 cout << "three";
4101 break;
4102 case '4':
4103 cout << "four";
4104 break;
4105 case '5':
4106 cout << "five";
4107 break;
4108 case '6':
4109 cout << "six";
4110 break;
4111 case '7':
4112 cout << "seven";
4113 break;
4114 case '8':
4115 cout << "eight";
4116 break;
4117 case '9':
4118 cout << "nine";
4119 break;
4120 default: return -1;
4121 }
4122 }
4123 return 0;
4124 }
4125 }// namespace a1005
4126
4127 namespace a1006 {
4128 int main(istream &cin, ostream &cout) {
4129 int m;
4130 cin >> m;
4131 vector<tuple<string, string, string>> vec(m);
4132 vector<string> seq;
4133 for(int i = 0; i < m; i++) {
4134 string id;
4135 string sign_in_time;
4136 string sign_out_time;
4137 cin >> id >> sign_in_time >> sign_out_time;
4138 vec[i] = make_tuple(id, sign_in_time, sign_out_time);
4139 seq.push_back(sign_in_time);
4140 seq.push_back(sign_out_time);
4141 }
4142 sort(seq.begin(), seq.end());
4143 for(auto &[id, in, out]: vec) {
4144 if(in == seq[0]) {
4145 cout << id << ' ';
4146 break;
4147 }
4148 }
4149 for(auto &[id, in, out]: vec) {
4150 if(out == seq.back()) {
4151 cout << id;
4152 break;
4153 }
4154 }
4155 return 0;
4156 }
4157 }// namespace a1006
4158
4159 namespace a1007 {
4160 int main(istream &cin, ostream &cout) {
4161 int k;
4162 cin >> k;
4163 vector<int> vec(k);
4164 bool flag = false;
4165 for(int i = 0; i < k; i++) {
4166 cin >> vec[i];
4167 if(vec[i] >= 0) {
4168 flag = true;
4169 }
4170 }
4171 if(!flag) {
4172 cout << "0 " << vec[0] << ' ' << vec[k - 1];
4173 return 0;
4174 }
4175 vector<int> pref_sum(k);
4176 pref_sum[0] = vec[0];
4177 for(int i = 1; i < k; i++) {
4178 pref_sum[i] = pref_sum[i - 1] + vec[i];
4179 }
4180 int max_sum = pref_sum[k - 1];
4181 int max_start = 0;
4182 int max_end = k - 1;
4183 for(int i = 0; i < k; i++) {
4184 for(int j = i; j < k; j++) {
4185 const int sum = pref_sum[j] - pref_sum[i] + vec[i];
4186 if(sum > max_sum) {
4187 max_sum = sum;
4188 max_start = i;
4189 max_end = j;
4190 }
4191 }
4192 }
4193 cout << max_sum << ' ' << vec[max_start] << ' ' << vec[max_end];
4194 return 0;
4195 }
4196 }// namespace a1007
4197
4198 namespace a1008 {
4199 int main(istream &cin, ostream &cout) {
4200 int n;
4201 cin >> n;
4202 vector<int> vec(n);
4203 for(int i = 0; i < n; i++) {
4204 cin >> vec[i];
4205 }
4206 int level = 0;
4207 int sum = 0;
4208 for(const auto &v: vec) {
4209 if(v > level) {
4210 sum += (v - level) * 6;
4211 } else {
4212 sum += (level - v) * 4;
4213 }
4214 sum += 5;
4215 level = v;
4216 }
4217 cout << sum;
4218 return 0;
4219 }
4220 }// namespace a1008
4221
4222 namespace a1009 {
4223 int main(istream &cin, ostream &cout) {
4224 map<int, double> A;
4225 map<int, double> B;
4226 int n;
4227 cin >> n;
4228 for(int i = 0; i < n; i++) {
4229 int exponent;
4230 double coefficient;
4231 cin >> exponent >> coefficient;
4232 A[exponent] = coefficient;
4233 }
4234 cin >> n;
4235 for(int i = 0; i < n; i++) {
4236 int exponent;
4237 double coefficient;
4238 cin >> exponent >> coefficient;
4239 B[exponent] = coefficient;
4240 }
4241 map<int, double> C;
4242 for(auto &[exponent, coefficient]: A) {
4243 for(auto &[exponent2, coefficient2]: B) {
4244 C[exponent + exponent2] += coefficient * coefficient2;
4245 }
4246 }
4247 int cnt = 0;
4248 for(auto &[exponent, coefficient]: C) {
4249 if(coefficient != 0) {
4250 cnt++;
4251 }
4252 }
4253 cout << cnt;
4254 for(auto it = C.rbegin(); it != C.rend(); ++it) {
4255 if(it->second != 0) {
4256 cout << ' ' << it->first << ' ' << fixed << setprecision(1) << it->second;
4257 }
4258 }
4259 return 0;
4260 }
4261 }// namespace a1009
4262
4263 namespace a1013 {
4264 int main(istream &cin, ostream &cout) {
4265 int n, m, k;
4266 cin >> n >> m >> k;
4267 unordered_map<int, int> ans;
4268 vector<unordered_set<int>> g(n + 1);
4269 for(int i = 0; i < m; i++) {
4270 int a, b;
4271 cin >> a >> b;
4272 g[a].insert(b);
4273 g[b].insert(a);
4274 }
4275 for(int i = 0; i < k; i++) {
4276 int a;
4277 cin >> a;
4278 if(ans.contains(a)) {
4279 cout << ans[a] << endl;
4280 continue;
4281 }
4282 unordered_set<int> marked;
4283 int cnt = 0;
4284 for(int j = 1; j <= n; j++) {
4285 if(j != a && !marked.contains(j)) {
4286 cnt++;
4287 dfs(j, g, a, marked);
4288 }
4289 }
4290 cout << cnt - 1 << endl;
4291 ans[a] = cnt - 1;
4292 }
4293 return 0;
4294 }
4295
4296 void dfs(int i, const vector<unordered_set<int>> &g, int occupied, unordered_set<int> &marked) {
4297 marked.insert(i);
4298 for(auto nxt: g[i]) {
4299 if(!marked.contains(nxt) && nxt != occupied) {
4300 dfs(nxt, g, occupied, marked);
4301 }
4302 }
4303 }
4304 }// namespace a1013
4305
4306 namespace a1014 {
4307 int main(istream &cin, ostream &cout) {
4308 int n, m, k, q;
4309 cin >> n >> m >> k >> q;
4310 vector<int> t(k + 1);
4311 vector end_time(k + 1, -1);
4312 vector rest(n, -1);
4313 for(int i = 1; i <= k; i++) {
4314 cin >> t[i];
4315 }
4316 vector<queue<int>> qs(n);
4317 int next = 1;
4318 for(int i = 0; i < n && i < k; i++) {
4319 rest[i] = t[i + 1];
4320 }
4321 for(int i = 0; i < n * m && i < k; i++, next++) {
4322 qs[i % n].push(i + 1);
4323 }
4324 int current_time = 0;
4325 while(next <= k && current_time < 540) {
4326 int minimum = -1;
4327 for(int i = 0; i < n; i++) {
4328 if(rest[i] != -1) {
4329 if(minimum == -1) {
4330 minimum = rest[i];
4331 } else {
4332 minimum = min(minimum, rest[i]);
4333 }
4334 }
4335 }
4336 if(minimum != -1) {
4337 if(current_time + minimum >= 540) {
4338 break;
4339 }
4340 current_time += minimum;
4341 for(int i = 0; i < n; i++) {
4342 if(rest[i] != -1) {
4343 rest[i] -= minimum;
4344 }
4345 if(rest[i] == 0) {
4346 end_time[qs[i].front()] = current_time;
4347 qs[i].pop();
4348 rest[i] = qs[i].empty() ? -1 : t[qs[i].front()];
4349 }
4350 }
4351 }
4352 minimum = m;
4353 for(int i = 0; i < n; i++) {
4354 minimum = min(minimum, static_cast<int>(qs[i].size()));
4355 }
4356 for(int i = 0; i < n && next <= k; i++) {
4357 if(qs[i].size() == minimum) {
4358 if(qs[i].empty()) {
4359 rest[i] = t[next];
4360 }
4361 qs[i].push(next);
4362 next++;
4363 }
4364 }
4365 }
4366 for(int i = 0; i < n; i++) {
4367 int queue_time = current_time;
4368 while(!qs[i].empty() && queue_time < 540) {
4369 if(rest[i] != -1) {
4370 queue_time += rest[i];
4371 rest[i] = -1;
4372 } else {
4373 queue_time += t[qs[i].front()];
4374 }
4375 end_time[qs[i].front()] = queue_time;
4376 qs[i].pop();
4377 }
4378 }
4379 for(int i = 0; i < q; i++) {
4380 int query;
4381 cin >> query;
4382 const int time = end_time[query];
4383 if(time == -1) {
4384 cout << "Sorry" << endl;
4385 } else {
4386 const int h = time / 60;
4387 const int m = time % 60;
4388 cout << setw(2) << right << setfill('0') << h + 8
4389 << ':'
4390 << setw(2) << right << setfill('0') << m
4391 << endl;
4392 }
4393 }
4394 return 0;
4395 }
4396 }// namespace a1014
4397
4398 namespace a1015 {
4399 int main(istream &cin, ostream &cout) {
4400 unsigned n;
4401 unsigned d;
4402 while(cin >> n && cin >> d) {
4403 if(is_prime(n) && is_prime(reverse(n, d))) {
4404 cout << "Yes";
4405 } else {
4406 cout << "No";
4407 }
4408 cout << endl;
4409 }
4410 return 0;
4411 }
4412
4413 unsigned get_num(const string &n, unsigned int d) {
4414 unsigned ans = 0;
4415 for(const char ch: n) {
4416 ans *= d;
4417 ans += ch - '0';
4418 }
4419 return ans;
4420 }
4421
4422 bool is_prime(unsigned int n) {
4423 if(n < 2) {
4424 return false;
4425 }
4426 for(unsigned i = 2; i <= sqrt(n); i++) {
4427 if(n % i == 0) {
4428 return false;
4429 }
4430 }
4431 return true;
4432 }
4433
4434 unsigned reverse(unsigned int n, unsigned int d) {
4435 ostringstream oss;
4436 while(n != 0) {
4437 oss << n % d;
4438 n /= d;
4439 }
4440 return get_num(oss.str(), d);
4441 }
4442 }// namespace a1015
4443
4444 namespace a1016 {
4445 int main(istream &cin, ostream &cout) {
4446 map<string, customer> um;
4447 double sum[M] = {};
4448 array<unsigned, 24> cost{};
4449 for(int i = 0; i < cost.size(); i++) {
4450 cin >> cost[i];
4451 }
4452 for(unsigned i = 1; i < M; i++) {
4453 sum[i] = sum[i - 1] + cost[(i - 1) % 1440 / 60] / 100.0;
4454 }
4455 unsigned int n;
4456 cin >> n;
4457 for(unsigned i = 0; i < n; i++) {
4458 string name;
4459 string time;
4460 string online;
4461 cin >> name >> time >> online;
4462 auto r = record(name, time, online);
4463 if(!um.contains(name)) {
4464 um[name] = customer(name);
4465 }
4466 um[name].records.emplace_back(r);
4467 }
4468 for(auto &[name, c]: um) {
4469 sort(c.records.begin(), c.records.end());
4470 for(auto it = c.records.begin(); it != c.records.end();) {
4471 if((*it).online && (it + 1 == c.records.end() || (*(it + 1)).online)) {
4472 it = c.records.erase(it);
4473 } else {
4474 ++it;
4475 }
4476 }
4477 vector<record> new_vec;
4478 bool looking_for_online = true;
4479 for(const auto &record: c.records) {
4480 if(looking_for_online == record.online) {
4481 new_vec.emplace_back(record);
4482 looking_for_online = !looking_for_online;
4483 }
4484 }
4485 c.records = new_vec;
4486 if(!c.records.empty()) {
4487 cout << name << ' ' << setw(2) << setfill('0') << right << c.records[0].month << endl;
4488 double total = 0;
4489 for(int i = 0; i < c.records.size(); i += 2) {
4490 const unsigned t2 = c.records[i + 1].get_minutes();
4491 const unsigned t1 = c.records[i].get_minutes();
4492 const double price = sum[t2] - sum[t1];
4493 total += price;
4494 cout << c.records[i].time.substr(3) << ' ' << c.records[i + 1].time.substr(3) << ' ' << t2 - t1 << " $" << fixed << setprecision(2) << price << endl;
4495 }
4496 cout << "Total amount: $" << fixed << setprecision(2) << total << endl;
4497 }
4498 }
4499 return 0;
4500 }
4501
4502
4503 record::record(string name, const string &time, const string &online)
4504 : name(std::move(std::move(name))), time(time), online(online == "on-line") {
4505 month = stoi(time.substr(0, 2));
4506 day = stoi(time.substr(3, 2));
4507 hour = stoi(time.substr(6, 2));
4508 minute = stoi(time.substr(9, 2));
4509 }
4510
4511 bool record::operator<(const record &r) const { return this->time < r.time; }
4512
4513 unsigned record::get_minutes() const { return this->day * 24 * 60 + this->hour * 60 + this->minute; }
4514 }// namespace a1016
4515
4516 namespace a1017 {
4517 int main(istream &cin, ostream &cout) {
4518 unsigned n;
4519 unsigned k;
4520 cin >> n >> k;
4521 unsigned next = 0;
4522 unsigned current = 0;
4523 priority_queue<unsigned, vector<unsigned>, greater<unsigned>> pq;
4524 vector<customer> customers(n);
4525 for(unsigned i = 0; i < n; i++) {
4526 string time;
4527 unsigned p;
4528 cin >> time >> p;
4529 customers[i] = customer(i, time, min(60U, p) * 60);
4530 }
4531 sort(customers.begin(), customers.end());
4532 for(unsigned i = 0; i < k; i++) {
4533 pq.push(8 * 60 * 60);
4534 }
4535 unsigned total = 0;
4536 unsigned cnt = 0;
4537 for(auto &c: customers) {
4538 unsigned t = pq.top();
4539 pq.pop();
4540 if(c.arrive_time > 17 * 60 * 60) {
4541 break;
4542 }
4543 const unsigned start_time = max(c.arrive_time, t);
4544 total += start_time - c.arrive_time;
4545 cnt++;
4546 pq.push(start_time + c.p);
4547 }
4548 cout << fixed
4549 << setprecision(1) << static_cast<double>(total) / cnt / 60;
4550 return 0;
4551 }
4552
4553 bool customer::operator<(const customer &b) const { return this->arrive_time_str < b.arrive_time_str; }
4554
4555 customer::customer(unsigned id, const string &arrive_time_str, unsigned p)
4556 : id(id), arrive_time_str(arrive_time_str), p(p) {
4557 const int h = stoi(arrive_time_str.substr(0, 2));
4558 const int m = stoi(arrive_time_str.substr(3, 2));
4559 const int s = stoi(arrive_time_str.substr(6, 2));
4560 this->arrive_time = h * 60 * 60 + m * 60 + s;
4561 }
4562
4563 bool customer_comp_p::operator()(const customer &c1, const customer &c2) const { return c1.p > c2.p; }
4564 }// namespace a1017
4565
4566 namespace a1026 {
4567 string timefmt(unsigned t) {
4568 ostringstream oss;
4569 const unsigned s = t % 60;
4570 t /= 60;
4571 const unsigned m = t % 60;
4572 t /= 60;
4573 const unsigned h = t;
4574 oss << setw(2) << setfill('0') << right << h << ':'
4575 << setw(2) << setfill('0') << right << m << ':'
4576 << setw(2) << setfill('0') << right << s;
4577 return oss.str();
4578 }
4579
4580 void assign(priority_queue<player, vector<player>, greater<player>> &players, priority_queue<table, vector<table>, greater<table>> &tables, vector<player> &vec, vector<unsigned> &table_cnt) {
4581 auto p = players.top();
4582 players.pop();
4583 const auto t = tables.top();
4584 tables.pop();
4585 p.waiting_time = round((t.end_time - p.arrival_time) / 60.0);
4586 p.start_time = t.end_time;
4587 table_cnt[t.id]++;
4588 vec.push_back(p);
4589 tables.push({t.id, t.end_time + p.p});
4590 }
4591
4592 int main(istream &cin, ostream &cout) {
4593 unsigned n;
4594 cin >> n;
4595 priority_queue<player, vector<player>, greater<player>> normal_players;
4596 priority_queue<player, vector<player>, greater<player>> vip_players;
4597 player nop;
4598 nop.arrival_time = INF;
4599 normal_players.push(nop);
4600 vip_players.push(nop);
4601 for(unsigned i = 0; i < n; i++) {
4602 string arrival_time_str;
4603 unsigned p;
4604 unsigned tag;
4605 cin >> arrival_time_str >> p >> tag;
4606 auto ply = player(arrival_time_str, p, tag);
4607 if(ply.vip) {
4608 vip_players.push(ply);
4609 } else {
4610 normal_players.push(ply);
4611 }
4612 }
4613 unsigned k;
4614 unsigned m;
4615 cin >> k >> m;
4616 vector<unsigned> table_cnt(k + 1, 0);
4617 priority_queue<table, vector<table>, greater<table>> normal_tables;
4618 priority_queue<table, vector<table>, greater<table>> vip_tables;
4619 normal_tables.push({0, INF});
4620 vip_tables.push({0, INF});
4621 unordered_set<unsigned> vipid;
4622 for(unsigned i = 0; i < m; i++) {
4623 unsigned id;
4624 cin >> id;
4625 vipid.insert(id);
4626 }
4627 for(unsigned i = 1; i <= k; i++) {
4628 if(static_cast<unsigned int>(vipid.contains(i)) != 0U) {
4629 vip_tables.push({i, 8 * 60 * 60});
4630 } else {
4631 normal_tables.push({i, 8 * 60 * 60});
4632 }
4633 }
4634 vector<player> players;
4635 while(normal_players.size() > 1 || vip_players.size() > 1) {
4636 auto np = normal_players.top();
4637 auto vp = vip_players.top();
4638 unsigned arrive_time = min(np.arrival_time, vp.arrival_time);
4639 while(normal_tables.top().end_time < arrive_time) {
4640 auto t = normal_tables.top();
4641 normal_tables.pop();
4642 t.end_time = arrive_time;
4643 normal_tables.push(t);
4644 }
4645 while(vip_tables.top().end_time < arrive_time) {
4646 auto t = vip_tables.top();
4647 vip_tables.pop();
4648 t.end_time = arrive_time;
4649 vip_tables.push(t);
4650 }
4651 auto nt = normal_tables.top();
4652 auto vt = vip_tables.top();
4653 unsigned end_time = min(nt.end_time, vt.end_time);
4654
4655 if(end_time >= 21 * 60 * 60) {
4656 break;
4657 }
4658
4659 if(vp.arrival_time <= end_time && vt.end_time == end_time) {
4660 assign(vip_players, vip_tables, players, table_cnt);
4661 } else if(np.arrival_time < vp.arrival_time) {
4662 if(nt > vt) {
4663 assign(normal_players, vip_tables, players, table_cnt);
4664 } else {
4665 assign(normal_players, normal_tables, players, table_cnt);
4666 }
4667 } else {
4668 if(nt > vt) {
4669 assign(vip_players, vip_tables, players, table_cnt);
4670 } else {
4671 assign(vip_players, normal_tables, players, table_cnt);
4672 }
4673 }
4674 }
4675 sort(players.begin(), players.end());
4676 for(auto &player: players) {
4677 cout << timefmt(player.arrival_time) << ' ' << timefmt(player.start_time) << ' ' << player.waiting_time << endl;
4678 }
4679 cout << table_cnt[1];
4680 for(unsigned i = 2; i <= k; i++) {
4681 cout << ' ' << table_cnt[i];
4682 }
4683 return 0;
4684 }
4685
4686 player::player(const string &arrival_time_str, unsigned p, unsigned tag)
4687 : arrival_time_str(arrival_time_str), p(min(120U, p) * 60), vip(tag == 1) {
4688 const int h = stoi(arrival_time_str.substr(0, 2));
4689 const int m = stoi(arrival_time_str.substr(3, 2));
4690 const int s = stoi(arrival_time_str.substr(6, 2));
4691 arrival_time = h * 60 * 60 + m * 60 + s;
4692 }
4693
4694 bool player::operator<(const player &ply) const {
4695 if(start_time != ply.start_time) {
4696 return start_time < ply.start_time;
4697 }
4698 return arrival_time < ply.arrival_time;
4699 }
4700
4701 bool player::operator>(const player &ply) const { return arrival_time > ply.arrival_time; }
4702
4703 bool table::operator>(const table &t) const {
4704 if(end_time != t.end_time) {
4705 return end_time > t.end_time;
4706 }
4707 return id > t.id;
4708 }
4709 }// namespace a1026
4710
4711 namespace a1018 {
4712 int main(istream &cin, ostream &cout) {
4713 unsigned cmax;
4714 unsigned n;
4715 unsigned sp;
4716 unsigned m;
4717 auto fc = frame_cmp();
4718 cin >> cmax >> n >> sp >> m;
4719 vector c(n + 1, 0);
4720 for(unsigned i = 1; i <= n; i++) {
4721 int ci;
4722 cin >> ci;
4723 c[i] = ci - static_cast<int>(cmax / 2);
4724 }
4725 vector<unordered_map<unsigned, unsigned>> g(n + 1);
4726 for(unsigned i = 0; i < m; i++) {
4727 unsigned si, sj, tij;
4728 cin >> si >> sj >> tij;
4729 g[si][sj] = tij;
4730 g[sj][si] = tij;
4731 }
4732 vector shortest(n + 1, -1);
4733 vector min_go(n + 1, -1);
4734 vector min_back(n + 1, -1);
4735 priority_queue<frame, vector<frame>, frame_cmp> pq;
4736 shortest[0] = 0;
4737 min_go[0] = 0;
4738 min_back[0] = 0;
4739 pq.push(frame(vector<unsigned>(1, 0), 0u, 0, 0u, 0u));
4740 while(!pq.empty()) {
4741 frame f = pq.top();
4742 pq.pop();
4743 if(f.node == sp) {
4744 cout << f.get_go() << ' ' << f.path[0];
4745 for(int i = 1; i < f.path.size(); i++) {
4746 cout << "->" << f.path[i];
4747 }
4748 cout << ' ' << f.get_back();
4749 return 0;
4750 }
4751 for(auto &[node, d]: g[f.node]) {
4752 if(find(f.path.begin(), f.path.end(), node) == f.path.end()) {
4753 //if(shortest[node] == -1 || min_go[node] == -1 || min_back[node] == -1 || fc(frame(vector<unsigned>(), node, min_back[node], shortest[node], min_go[node]), frame(vector<unsigned>(), node, f.bikes + c[node], f.len + d, f.start))) {
4754 vector<unsigned> path = f.path;
4755 path.emplace_back(node);
4756 auto next_f = frame(path, node, f.bikes + c[node], f.len + d, f.start);
4757 pq.push(next_f);
4758 //shortest[node] = next_f.len;
4759 //min_go[node] = next_f.get_go();
4760 //min_back[node] = next_f.get_back();
4761 }
4762 }
4763 }
4764 return 0;
4765 }
4766
4767 bool frame_cmp::operator()(const frame &f1, const frame &f2) const {
4768 if(f1.len != f2.len) {
4769 return f1.len > f2.len;
4770 }
4771 if(f1.get_go() != f2.get_go()) {
4772 return f1.get_go() > f2.get_go();
4773 }
4774 return f1.get_back() > f2.get_back();
4775 }
4776
4777 unsigned frame::get_go() const { return start; }
4778
4779 unsigned frame::get_back() const { return bikes; }
4780
4781 frame::frame(vector<unsigned> path, unsigned node, int bikes, unsigned len, unsigned start)
4782 : path(std::move(path)), node(node), bikes(bikes), len(len), start(start) {
4783 if(bikes < 0) {
4784 this->start += -bikes;
4785 this->bikes = 0;
4786 }
4787 }
4788 }// namespace a1018
4789
4790 namespace a1019 {
4791 int main(istream &cin, ostream &cout) {
4792 unsigned long long n, b;
4793 cin >> n >> b;
4794 vector<unsigned long long> vec;
4795 while(n != 0) {
4796 vec.emplace_back(n % b);
4797 n /= b;
4798 }
4799 bool ok = true;
4800 for(int i = 0; i < vec.size() / 2; i++) {
4801 if(vec[i] != vec[vec.size() - 1 - i]) {
4802 ok = false;
4803 break;
4804 }
4805 }
4806 if(ok) {
4807 cout << "Yes" << endl;
4808 } else {
4809 cout << "No" << endl;
4810 }
4811 cout << vec.back();
4812 for(int i = vec.size() - 2; i >= 0; i--) {
4813 cout << ' ' << vec[i];
4814 }
4815 return 0;
4816 }
4817 }// namespace a1019
4818
4819 namespace a1020 {
4820 int main(istream &cin, ostream &cout) {
4821 unsigned n;
4822 cin >> n;
4823 vector<unsigned> post_order(n);
4824 vector<unsigned> in_order(n);
4825 for(unsigned i = 0; i < n; i++) {
4826 cin >> post_order[i];
4827 }
4828 for(unsigned i = 0; i < n; i++) {
4829 cin >> in_order[i];
4830 }
4831 TreeNode *root = parse(post_order, in_order);
4832 queue<TreeNode *> q;
4833 q.push(root);
4834 bool flag = true;
4835 while(!q.empty()) {
4836 const auto node = q.front();
4837 q.pop();
4838 if(flag) {
4839 flag = false;
4840 cout << node->key;
4841 } else {
4842 cout << ' ' << node->key;
4843 }
4844 if(node->left != nullptr) {
4845 q.push(node->left);
4846 }
4847 if(node->right != nullptr) {
4848 q.push(node->right);
4849 }
4850 }
4851 return 0;
4852 }
4853
4854 TreeNode *parse(vector<unsigned int> post_order, const vector<unsigned int> &in_order) {
4855 const auto root = new TreeNode(post_order.back());
4856 bool in_left = true;
4857 unordered_set<unsigned> left, right;
4858 vector<unsigned> left_post, right_post, left_in, right_in;
4859 for(auto node: in_order) {
4860 if(in_left) {
4861 if(node == root->key) {
4862 in_left = false;
4863 } else {
4864 left.insert(node);
4865 left_in.emplace_back(node);
4866 }
4867 } else {
4868 right.insert(node);
4869 right_in.emplace_back(node);
4870 }
4871 }
4872 for(auto node: post_order) {
4873 if(node == root->key) {
4874 continue;
4875 }
4876 if(left.contains(node)) {
4877 left_post.emplace_back(node);
4878 } else {
4879 right_post.emplace_back(node);
4880 }
4881 }
4882 if(!left.empty()) {
4883 root->left = parse(left_post, left_in);
4884 }
4885 if(!right.empty()) {
4886 root->right = parse(right_post, right_in);
4887 }
4888 return root;
4889 }
4890 }// namespace a1020
4891
4892 namespace a1023 {
4893 int main(istream &cin, ostream &cout) {
4894 string n;
4895 cin >> n;
4896 unordered_map<unsigned short, unsigned short> us1;
4897 unordered_map<unsigned short, unsigned short> us2;
4898 vector<unsigned short> vec;
4899 unsigned short c = 0;
4900 for(int i = n.length() - 1; i >= 0; i--) {
4901 unsigned short ch = static_cast<unsigned short>(n[i]) - '0';
4902 us1[ch]++;
4903 ch *= 2;
4904 ch += c;
4905 c = ch / 10;
4906 ch %= 10;
4907 vec.emplace_back(ch);
4908 }
4909 if(c > 0) {
4910 vec.emplace_back(c);
4911 }
4912 ostringstream oss;
4913 for(auto it = vec.rbegin(); it != vec.rend(); ++it) {
4914 unsigned num = *it;
4915 oss << num;
4916 us2[num]++;
4917 }
4918
4919 cout << (us1 == us2 ? "Yes" : "No") << endl
4920 << oss.str();
4921 return 0;
4922 }
4923 }// namespace a1023
4924
4925 namespace a1024 {
4926 int main(istream &cin, ostream &cout) {
4927 string n;
4928 unsigned int k;
4929 cin >> n >> k;
4930 bi bn(n);
4931 unsigned step = 0;
4932 while(step <= k) {
4933 if(bn.is_palindromic()) {
4934 cout << bn << endl
4935 << step;
4936 return 0;
4937 }
4938 if(step == k) {
4939 break;
4940 }
4941 bi bn2 = bn;
4942 bn2.reverse();
4943 bn = bn + bn2;
4944 step++;
4945 }
4946 cout << bn << endl
4947 << step;
4948 return 0;
4949 }
4950
4951 ostream &operator<<(ostream &os, bi &b) {
4952 for(auto it = b.vec.rbegin(); it != b.vec.rend(); ++it) {
4953 os << *it;
4954 }
4955 return os;
4956 }
4957
4958 void bi::reverse() { vec = vector(vec.rbegin(), vec.rend()); }
4959
4960 bool bi::is_palindromic() const {
4961 for(int i = 0; i < vec.size() / 2; i++) {
4962 if(vec[i] != vec[vec.size() - i - 1]) {
4963 return false;
4964 }
4965 }
4966 return true;
4967 }
4968
4969 bi bi::operator+(const bi &n2) const {
4970 vector<unsigned short> v;
4971 unsigned short c = 0;
4972 for(int i = 0; i < vec.size(); i++) {
4973 unsigned short n = vec[i] + n2.vec[i];
4974 n += c;
4975 c = n / 10;
4976 n %= 10;
4977 v.emplace_back(n);
4978 }
4979 if(c > 0) {
4980 v.emplace_back(c);
4981 }
4982 bi ans;
4983 ans.vec = v;
4984 return ans;
4985 }
4986
4987 bi::bi(const string &str) {
4988 for(int i = str.length() - 1; i >= 0; i--) {
4989 vec.emplace_back(str[i] - '0');
4990 }
4991 }
4992 }// namespace a1024
4993
4994 namespace a1027 {
4995 int main(istream &cin, ostream &cout) {
4996 const char num[13] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'};
4997 unsigned input[3];
4998 cin >> input[0] >> input[1] >> input[2];
4999 stack<char> stk;
5000 ostringstream oss;
5001 oss << '#';
5002 for(int i = 0; i < 3; i++) {
5003 unsigned color = input[i];
5004 while(color != 0) {
5005 stk.push(num[color % 13]);
5006 color /= 13;
5007 }
5008 while(stk.size() < 2) {
5009 stk.push('0');
5010 }
5011 while(!stk.empty()) {
5012 oss << stk.top();
5013 stk.pop();
5014 }
5015 }
5016 cout << oss.str();
5017 return 0;
5018 }
5019 }// namespace a1027
5020
5021 namespace a1021 {
5022 int dfs(const vector<unordered_set<int>> &g, int father, int nd) {
5023 int maximum = 0;
5024 for(const auto child: g[nd]) {
5025 if(child != father) {
5026 maximum = max(maximum, dfs(g, nd, child));
5027 }
5028 }
5029 return maximum + 1;
5030 }
5031
5032 int main(istream &cin, ostream &cout) {
5033 int n;
5034 cin >> n;
5035 auto g = vector<unordered_set<int>>(n + 1);
5036 vector deep(n + 1, 0);
5037 UnionFind uf(n + 1);
5038 for(int i = 1; i < n; i++) {
5039 int a, b;
5040 cin >> a >> b;
5041 uf.unite(a, b);
5042 g[a].insert(b);
5043 g[b].insert(a);
5044 }
5045 unordered_set<int> us;
5046 for(int i = 1; i <= n; i++) {
5047 us.insert(uf.find(i));
5048 }
5049 if(us.size() != 1) {
5050 cout << "Error: " << us.size() << " components";
5051 return 0;
5052 }
5053 int maximum = 0;
5054 for(int i = 1; i <= n; i++) {
5055 deep[i] = dfs(g, 0, i);
5056 maximum = max(maximum, deep[i]);
5057 }
5058 for(int i = 1; i <= n; i++) {
5059 if(deep[i] == maximum) {
5060 cout << i << endl;
5061 }
5062 }
5063 return 0;
5064 }
5065 }// namespace a1021
5066
5067 namespace a7_1 {
5068 int main(istream &cin, ostream &cout) {
5069 int n;
5070 int h;
5071 cin >> n >> h;
5072 vector<int> balloons(n);
5073 unordered_map<int, int> pos;
5074 for(int i = 0; i < n; i++) {
5075 cin >> balloons[i];
5076 pos[balloons[i]] = i;
5077 }
5078 int maximum = 0;
5079 int cnt = 0;
5080 for(int i = 0; i < n; i++) {
5081 auto it = lower_bound(balloons.begin(), balloons.end(), balloons[i] - h);
5082 const int v = it - balloons.begin();
5083 const int t = i - v + 1;
5084 if(cnt < t) {
5085 cnt = t;
5086 maximum = balloons[i] - h;
5087 }
5088 }
5089 cout << maximum << ' ' << cnt;
5090 return 0;
5091 }
5092 }// namespace a7_1
5093
5094 namespace a7_2 {
5095 int vec[100010];
5096 int lmax[100010];
5097 int rmin[100010];
5098 int lmax2[100010];
5099 int rmin2[100010];
5100
5101 bool isFirstRun(int start, int end) {
5102 if(start >= end) {
5103 return true;
5104 }
5105 lmax2[start] = vec[start];
5106 rmin2[end] = vec[end];
5107 for(int i = start + 1; i <= end; i++) {
5108 lmax2[i] = max(vec[i], lmax2[i - 1]);
5109 }
5110 for(int i = end - 1; i >= start; i--) {
5111 rmin2[i] = min(vec[i], rmin2[i + 1]);
5112 }
5113 for(int i = start; i <= end; i++) {
5114 if(vec[i] >= lmax2[i] && vec[i] <= rmin2[i]) {
5115 return true;
5116 }
5117 }
5118 return false;
5119 }
5120
5121 int main(istream &cin, ostream &cout) {
5122 int k;
5123 cin >> k;
5124 while(k-- != 0) {
5125 int n;
5126 cin >> n;
5127 for(int i = 0; i < n; i++) {
5128 cin >> vec[i];
5129 }
5130 bool ok = false;
5131 lmax[0] = vec[0];
5132 rmin[n - 1] = vec[n - 1];
5133 for(int i = 1; i < n; i++) {
5134 lmax[i] = max(vec[i], lmax[i - 1]);
5135 }
5136 for(int i = n - 2; i >= 0; i--) {
5137 rmin[i] = min(vec[i], rmin[i + 1]);
5138 }
5139 for(int i = 0; i < n; i++) {
5140 if(vec[i] >= lmax[i] && vec[i] <= rmin[i]) {
5141 if(isFirstRun(0, i - 1) && isFirstRun(i + 1, n - 1)) {
5142 ok = true;
5143 break;
5144 }
5145 }
5146 }
5147 if(ok) {
5148 cout << "Yes" << endl;
5149 } else {
5150 cout << "No" << endl;
5151 }
5152 }
5153 return 0;
5154 }
5155 }// namespace a7_2
5156
5157 namespace a7_3 {
5158 int main(istream &cin, ostream &cout) {
5159 int n;
5160 int t;
5161 cin >> n >> t;
5162 vector out(n + 1, 0);
5163 vector in(n + 1, 0);
5164 vector<unordered_set<int>> following(n + 1);
5165 unordered_map<int, int> kols;
5166 for(int i = 1; i <= n; i++) {
5167 int m;
5168 cin >> m;
5169 out[i] += m;
5170 while(m-- != 0) {
5171 int u;
5172 cin >> u;
5173 in[u]++;
5174 following[i].insert(u);
5175 }
5176 }
5177 for(int i = 1; i <= n; i++) {
5178 if(out[i] == 0 || in[i] / following[i].size() >= t) {
5179 if(!kols.contains(i)) {
5180 kols[i] = 0;
5181 }
5182 }
5183 }
5184 for(const auto &kol: kols) {
5185 for(const auto &fo: following[kol.first]) {
5186 if(kols.contains(fo)) {
5187 kols[fo]++;
5188 }
5189 }
5190 }
5191 int maximum = 0;
5192 for(auto &kv: kols) {
5193 maximum = max(maximum, kv.second);
5194 }
5195 vector<int> ans;
5196 for(auto &kv: kols) {
5197 if(kv.second == maximum) {
5198 ans.emplace_back(kv.first);
5199 }
5200 }
5201 sort(ans.begin(), ans.end());
5202 for(int i = 0; i < ans.size(); i++) {
5203 cout << ans[i];
5204 if(i != ans.size() - 1) {
5205 cout << ' ';
5206 }
5207 }
5208 return 0;
5209 }
5210 }// namespace a7_3
5211
5212 namespace a7_4 {
5213 Node *genTree(const vector<int> &preorder, const vector<int> &inorder, int pStart, int pEnd, int iStart,
5214 int iEnd) {
5215 if(pStart > pEnd || iStart > iEnd) {
5216 return nullptr;
5217 }
5218 const int root = preorder[pStart];
5219 auto *node = new Node(root);
5220 unordered_set<int> lefts;
5221 int iLeftEnd = iStart;
5222 while(inorder[iLeftEnd] != root) {
5223 lefts.insert(inorder[iLeftEnd++]);
5224 }
5225 iLeftEnd--;
5226 const int iRightStart = iLeftEnd + 2;
5227 int pLeftEnd = pStart + 1;
5228 while(pLeftEnd < preorder.size() && lefts.contains(preorder[pLeftEnd])) {
5229 pLeftEnd++;
5230 }
5231 node->left = genTree(preorder, inorder, pStart + 1, pLeftEnd - 1, iStart, iLeftEnd);
5232 node->right = genTree(preorder, inorder, pLeftEnd, pEnd, iRightStart, iEnd);
5233 return node;
5234 }
5235
5236 void postOrder(Node *node, vector<int> &vec) {
5237 if(node->left != nullptr) {
5238 postOrder(node->left, vec);
5239 }
5240 if(node->right != nullptr) {
5241 postOrder(node->right, vec);
5242 }
5243 vec.emplace_back(node->val);
5244 }
5245
5246 int judge(Node *node) {
5247 map<int, int> m;
5248 vector<vector<Node *>> lvs;
5249 queue<pair<int, Node *>> q;
5250 q.push({0, node});
5251 while(!q.empty()) {
5252 const auto p = q.front();
5253 q.pop();
5254 const int level = p.first;
5255 m[level]++;
5256 while(lvs.size() < level + 1) {
5257 vector<Node *> topush;
5258 lvs.push_back(topush);
5259 }
5260 Node *n = p.second;
5261 lvs[level].push_back(n);
5262 if(n->left != nullptr) {
5263 q.push({level + 1, n->left});
5264 }
5265 if(n->right != nullptr) {
5266 q.push({level + 1, n->right});
5267 }
5268 }
5269 for(const auto kv: m) {
5270 const int k = kv.first;
5271 const int v = kv.second;
5272 if(k != m.rbegin()->first) {
5273 if(v != pow(2, k)) {
5274 return 0;
5275 }
5276 } else {
5277 if(v == pow(2, k)) {
5278 return 1;
5279 }
5280 if(lvs.size() >= 2) {
5281 bool haveEmpty = false;
5282 for(const auto &nd: lvs[lvs.size() - 2]) {
5283 if(nd->left == nullptr) {
5284 haveEmpty = true;
5285 } else {
5286 if(haveEmpty) {
5287 return 3;
5288 }
5289 }
5290 if(nd->right == nullptr) {
5291 haveEmpty = true;
5292 } else {
5293 if(haveEmpty) {
5294 return 3;
5295 }
5296 }
5297 }
5298 }
5299 return 2;
5300 }
5301 }
5302 return -1;
5303 }
5304
5305 int main(istream &cin, ostream &cout) {
5306 int n;
5307 cin >> n;
5308 vector<int> inorder(n);
5309 vector<int> preorder(n);
5310 for(int i = 0; i < n; i++) {
5311 cin >> inorder[i];
5312 }
5313 for(int i = 0; i < n; i++) {
5314 cin >> preorder[i];
5315 }
5316 Node *root = genTree(preorder, inorder, 0, n - 1, 0, n - 1);
5317 vector<int> vec;
5318 cout << judge(root) << endl;
5319 postOrder(root, vec);
5320 for(int i = 0; i < vec.size(); i++) {
5321 cout << vec[i];
5322 if(i != vec.size() - 1) {
5323 cout << ' ';
5324 }
5325 }
5326 return 0;
5327 }
5328 }// namespace a7_4
5329 }// namespace a
5330
5331 namespace top {}
5332}// namespace pat
const int N
Definition: acwing.h:146
void qs(vector< int > &vec, int l, int r)
Definition: acwing.cpp:6299
bool find(vector< unordered_set< int > > &g, int x, vector< bool > &st, vector< int > &match)
Definition: acwing.cpp:7522
struct acwing::acwing3378::student student
vector< int > root
Definition: acwing408.cpp:349
计算机程序设计能力考试
Definition: pat.cpp:22
int main(istream &cin, ostream &cout)
Definition: pat.cpp:25
int main(istream &cin, ostream &cout)
Definition: pat.cpp:43
int main(istream &cin, ostream &cout)
Definition: pat.cpp:96
int main(istream &cin, ostream &cout)
Definition: pat.cpp:155
int main(istream &cin, ostream &cout)
Definition: pat.cpp:180
int main(istream &cin, ostream &cout)
Definition: pat.cpp:222
int main(istream &cin, ostream &cout)
Definition: pat.cpp:243
int main(istream &cin, ostream &cout)
Definition: pat.cpp:266
int main(istream &cin, ostream &cout)
Definition: pat.cpp:285
int main(istream &cin, ostream &cout)
Definition: pat.cpp:300
int main(istream &cin, ostream &cout)
Definition: pat.cpp:325
int main(istream &cin, ostream &cout)
Definition: pat.cpp:340
int main(istream &cin, ostream &cout)
Definition: pat.cpp:417
int main(istream &cin, ostream &cout)
Definition: pat.cpp:452
int main(istream &cin, ostream &cout)
Definition: pat.cpp:489
int main(istream &cin, ostream &cout)
Definition: pat.cpp:535
int main(istream &cin, ostream &cout)
Definition: pat.cpp:571
int main(istream &cin, ostream &cout)
Definition: pat.cpp:659
int main(istream &cin, ostream &cout)
Definition: pat.cpp:691
int main(istream &cin, ostream &cout)
Definition: pat.cpp:728
int main(istream &cin, ostream &cout)
Definition: pat.cpp:744
int main(istream &cin, ostream &cout)
Definition: pat.cpp:767
int main(istream &cin, ostream &cout)
Definition: pat.cpp:790
int main(istream &cin, ostream &cout)
Definition: pat.cpp:834
int main(istream &cin, ostream &cout)
Definition: pat.cpp:866
int main(istream &cin, ostream &cout)
Definition: pat.cpp:882
int main(istream &cin, ostream &cout)
Definition: pat.cpp:937
bool is_valid(int year, int month, int day)
Definition: pat.cpp:915
int main(istream &cin, ostream &cout)
Definition: pat.cpp:983
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1006
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1026
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1053
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1075
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1101
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1119
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1191
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1214
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1245
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1267
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1296
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1328
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1349
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1373
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1415
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1491
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1527
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1551
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1578
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1620
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1635
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1701
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1725
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1802
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1836
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1912
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1970
int main(istream &cin, ostream &cout)
Definition: pat.cpp:1985
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2012
bool is_prime(int n)
Definition: pat.cpp:2077
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2086
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2118
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2138
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2166
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2198
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2214
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2239
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2268
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2303
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2336
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2397
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2427
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2445
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2476
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2516
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2587
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2630
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2670
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2691
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2736
bool is_palindromic(string str)
Definition: pat.cpp:2767
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2776
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2800
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2851
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2895
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2913
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2932
int main(istream &cin, ostream &cout)
Definition: pat.cpp:2958
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3023
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3042
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3051
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3110
bool is_true(const vector< int > &vec, int wolf1, int wolf2)
Definition: pat.cpp:3129
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3153
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3197
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3226
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3261
bool is_prime(unsigned int n)
Definition: pat.cpp:3313
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3287
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3327
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3415
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3461
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3497
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3522
bool is_prime(unsigned int n)
Definition: pat.cpp:3558
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3572
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3611
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3625
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3647
bool is_prime(int n)
Definition: pat.cpp:3709
void dfs(string str, const int current_i, const int m, const int k, const int current_sum, const int cnt9, vector< string > &ans)
Definition: pat.cpp:3721
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3675
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3743
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3787
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3809
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3834
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3856
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3912
int main(istream &cin, ostream &cout)
Definition: pat.cpp:3954
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4016
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4073
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4128
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4160
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4199
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4223
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4264
void dfs(int i, const vector< unordered_set< int > > &g, int occupied, unordered_set< int > &marked)
Definition: pat.cpp:4296
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4307
unsigned reverse(unsigned int n, unsigned int d)
Definition: pat.cpp:4434
unsigned get_num(const string &n, unsigned int d)
Definition: pat.cpp:4413
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4399
bool is_prime(unsigned int n)
Definition: pat.cpp:4422
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4445
const unsigned M
Definition: pat.h:807
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4517
void assign(priority_queue< player, vector< player >, greater< player > > &players, priority_queue< table, vector< table >, greater< table > > &tables, vector< player > &vec, vector< unsigned > &table_cnt)
Definition: pat.cpp:4580
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4592
string timefmt(unsigned t)
Definition: pat.cpp:4567
const unsigned INF
Definition: pat.h:862
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4712
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4791
TreeNode * parse(vector< unsigned int > post_order, const vector< unsigned int > &in_order)
Definition: pat.cpp:4854
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4820
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4893
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4926
ostream & operator<<(ostream &os, bi &b)
Definition: pat.cpp:4951
int main(istream &cin, ostream &cout)
Definition: pat.cpp:4995
int dfs(const vector< unordered_set< int > > &g, int father, int nd)
Definition: pat.cpp:5022
int main(istream &cin, ostream &cout)
Definition: pat.cpp:5032
int main(istream &cin, ostream &cout)
Definition: pat.cpp:5068
int rmin2[100010]
Definition: pat.cpp:5099
int rmin[100010]
Definition: pat.cpp:5097
int lmax[100010]
Definition: pat.cpp:5096
bool isFirstRun(int start, int end)
Definition: pat.cpp:5101
int vec[100010]
Definition: pat.cpp:5095
int lmax2[100010]
Definition: pat.cpp:5098
int main(istream &cin, ostream &cout)
Definition: pat.cpp:5121
int main(istream &cin, ostream &cout)
Definition: pat.cpp:5158
int main(istream &cin, ostream &cout)
Definition: pat.cpp:5305
void postOrder(Node *node, vector< int > &vec)
Definition: pat.cpp:5236
int judge(Node *node)
Definition: pat.cpp:5246
Node * genTree(const vector< int > &preorder, const vector< int > &inorder, int pStart, int pEnd, int iStart, int iEnd)
Definition: pat.cpp:5213
bool operator<(const student &stu) const
Definition: pat.cpp:523
bool operator<(const Person &p) const
Definition: pat.cpp:968
bool operator<(const Person &p) const
Definition: pat.cpp:1958
unordered_set< char > correct_choices
Definition: pat.h:359
多选题
Definition: pat.h:440
int score
满分值
Definition: pat.h:442
unordered_set< char > ca
正确选项
Definition: pat.h:445
int id
编号
Definition: pat.h:441
int noa
选项个数
Definition: pat.h:443
int noca
正确选项个数
Definition: pat.h:444
string addr
Definition: pat.h:459
string next
Definition: pat.h:461
int get_score() const
Definition: pat.cpp:2833
bool operator<(const student &) const
Definition: pat.cpp:2842
bool operator<(const player &) const
Definition: pat.cpp:2909
int get_dist() const
Definition: pat.cpp:2907
int get_score() const
Definition: pat.cpp:3007
bool operator<(const school &) const
Definition: pat.cpp:3009
bool operator()(const student *stu1, const student *stu2) const
Definition: pat.cpp:3399
bool operator()(const pair< string, int > &p1, const pair< string, int > &p2) const
Definition: pat.cpp:3406
bool operator()(const string &s1, const string &s2) const
Definition: pat.cpp:3607
bool operator()(const paper &p1, const paper &p2) const
Definition: pat.cpp:3641
bool operator()(const paper &p1, const paper &p2) const
Definition: pat.cpp:3643
bool operator()(const tuple< int, int, int > &a, const tuple< int, int, int > &b) const
Definition: pat.cpp:4005
unsigned get_minutes() const
Definition: pat.cpp:4513
unsigned day
Definition: pat.h:814
unsigned minute
Definition: pat.h:816
record(string name, const string &time, const string &online)
Definition: pat.cpp:4503
unsigned hour
Definition: pat.h:815
bool operator<(const record &r) const
Definition: pat.cpp:4511
unsigned month
Definition: pat.h:813
bool operator<(const customer &b) const
Definition: pat.cpp:4553
string arrive_time_str
客户的到达时间,用 HH:MM:SS 表示
Definition: pat.h:842
unsigned arrive_time
Definition: pat.h:843
unsigned p
客户的业务办理时间 P(单位:分钟)
Definition: pat.h:844
bool operator()(const customer &c1, const customer &c2) const
Definition: pat.cpp:4563
bool operator>(const player &p) const
Definition: pat.cpp:4701
unsigned waiting_time
Definition: pat.h:868
string arrival_time_str
Definition: pat.h:865
unsigned start_time
Definition: pat.h:869
unsigned arrival_time
Definition: pat.h:866
bool operator<(const player &p) const
Definition: pat.cpp:4694
unsigned id
Definition: pat.h:879
bool operator>(const table &p) const
Definition: pat.cpp:4703
unsigned end_time
Definition: pat.h:880
unsigned start
Definition: pat.h:899
unsigned get_go() const
Definition: pat.cpp:4777
vector< unsigned > path
Definition: pat.h:895
unsigned get_back() const
Definition: pat.cpp:4779
unsigned len
Definition: pat.h:898
unsigned node
Definition: pat.h:896
bool operator()(const frame &f1, const frame &f2) const
Definition: pat.cpp:4767
bool is_palindromic() const
Definition: pat.cpp:4960
void reverse()
Definition: pat.cpp:4958
vector< unsigned short > vec
Definition: pat.h:948
bi operator+(const bi &n2) const
Definition: pat.cpp:4969
Node * right
Definition: pat.h:992
Node * left
Definition: pat.h:991
高精度整数
Definition: templates.h:23
分数
Definition: templates.h:71
并查集
Definition: templates.h:91
void unite(int x, int y)
Definition: templates.cpp:496
int find(int x)
Definition: templates.cpp:489