fork download
  1. /*/ Author: _Math.man /*/
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. /*/---------------------------Defines-----------------------------------------/*/
  7.  
  8. #pragma GCC optimize("Ofast")
  9. #define int long long
  10. #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
  11. #define pb push_back
  12. #define eb emplace_back
  13. #define fn for(int i =0 ;i <n;i++)
  14. #define fn1 for( int i =1;i<=n; i++)
  15. #define fm for(int j =0 ;j <m;j++)
  16. #define fm1 for(int j =1;j<=m;j++)
  17. #define fi first
  18. #define se second
  19. #define endl '\n'
  20. #define PI 3.14159265358979323846
  21. #define MOD 1000000007
  22. #define all(a) a.begin(),a.end()
  23. #define rall(a) a.rbegin(),a.rend()
  24. const int N = 2e6+5;
  25. const int INF = 1e18L;
  26. //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  27. /*/-----------------------------Debug begins----------------------------------/*/
  28. vector<string> split(const string& s, char c) {
  29. vector<string> v; stringstream ss(s); string x;
  30. while (getline(ss, x, c)) v.emplace_back(x); return move(v);
  31. }
  32. template<typename T, typename... Args>
  33. inline string arrStr(T arr, int n) {
  34. stringstream s; s << "[";
  35. for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
  36. if(n>0)
  37. s << arr[n - 1] ;
  38. s<< "]";
  39. return s.str();
  40. }
  41. #define trace(args...) {__trace_begin(__LINE__); __trace(split(#args, ',').begin(), args);}
  42. inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
  43. template<typename T> inline void __trace_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
  44. template<typename T> inline void __trace_out_var(T* val) { cerr << arrStr(val, 10); }
  45. template<typename T> inline void __trace_out_var(T val) { cerr << val; }
  46. inline void __trace(vector<string>::iterator it) { cerr << endl; }
  47.  
  48. template<typename T, typename... Args>
  49. inline void __trace(vector<string>::iterator it, T a, Args... args) {
  50. cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  51. __trace_out_var(a);
  52. cerr << "; ";
  53. __trace(++it, args...);
  54. }
  55. /*/-----------------------------Code begins----------------------------------/*/
  56. int ar[N];
  57. int dp[N];
  58. void go(string s,map<int,set<int>>&b,map<int,set<int>>&a){
  59. int cur =1;
  60. for(int i =0 ;i<s.size();i++){
  61. int no =0 ;
  62. while(i<s.size()){
  63. if(s[i]=='&'){
  64. b[cur].insert(no);
  65. a[no].insert(cur);
  66. no =0 ;
  67. i++;
  68. }else if(s[i]==','){
  69. if(no>0){
  70. b[cur].insert(no);
  71. a[no].insert(cur);
  72. no =0 ;
  73. }
  74. break;
  75. }
  76. no*=10;
  77. no+=s[i]-'0';
  78. i++;
  79. }
  80. ++cur;
  81. }
  82. }
  83. signed main(){
  84. // #ifndef ONLINE_JUDGE
  85. // freopen("input.txt","r",stdin);
  86. // freopen("output.txt","w",stdout);
  87. // #endif
  88. IOS;
  89. int T=1;
  90. // cin >> T;
  91. while(T--){
  92. int n,m;
  93. cin >> n ;
  94. string s;
  95. cin.ignore();
  96. getline(cin,s);
  97. cin>>m;
  98. cin.ignore();
  99. string t;
  100. cin>>t;
  101. t+=',';
  102. s+=',';
  103. map<int,set<int>>bank,part;
  104. go(s,bank,part);
  105. go(t,part,bank);
  106. int ans=0;
  107. for(auto i : bank){
  108. ans=max(ans,(int)i.se.size());
  109. }
  110. for(auto i : part){
  111. ans=max(ans,(int)i.se.size());
  112. }
  113. cout << ans <<'\n';
  114.  
  115. }
  116. return 0;
  117. }
Success #stdin #stdout 0s 4556KB
stdin
Standard input is empty
stdout
0