fork download
  1. #include<unordered_map>
  2. #include<unordered_set>
  3. #include<functional>
  4. #include<algorithm>
  5. #include<iostream>
  6. #include<hash_map>
  7. #include<iterator>
  8. #include<iomanip>
  9. #include<numeric>
  10. #include<cstring>
  11. #include<vector>
  12. #include<bitset>
  13. #include<string>
  14. #include<deque>
  15. #include<stack>
  16. #include<queue>
  17. #include<array>
  18. #include<cmath>
  19. #include<list>
  20. #include<map>
  21. #include<set>
  22. #include <ext/pb_ds/assoc_container.hpp>
  23. #include <ext/pb_ds/tree_policy.hpp>
  24.  
  25. using namespace __gnu_pbds;
  26. using namespace std;
  27.  
  28. typedef long long ll;
  29. typedef unsigned long long ull;
  30. typedef double db;
  31. typedef long double ldb;
  32.  
  33. #define ordered_set tree<ll, null_type,less_equal<ll>, \
  34. rb_tree_tag,tree_order_statistics_node_update>
  35. #define pii pair<int,int>
  36. #define pll pair<ll,ll>
  37. #define inf INT32_MAX
  38. #define linf INT64_MAX
  39. #define pf push_front
  40. #define pb push_back
  41. #define ppb pop_back
  42. #define ppf pop_front
  43. #define ff first
  44. #define ss second
  45.  
  46. const int mod=998244353,N=2e5+5;
  47. /*ECPC 2021 ISA-*/
  48. ll Pow(ll b,ll p){
  49. if(!p)return 1;
  50. if(p==1)return b;
  51. ll tmp=Pow(b,p/2);
  52. tmp=(tmp*tmp);
  53. if(p&1)tmp=(tmp*b);
  54. return tmp;
  55. }
  56. bool slv(){
  57. ll n,ans=0;
  58. cin>>n;
  59.  
  60. vector<ll>a(n),b(n);
  61. for(auto &i:a)cin>>i;
  62. for(auto &i:b)cin>>i;
  63.  
  64. for(int i=0;i<n;++i){
  65. a[i]=a[i]*(i+1)*(n-i);
  66. }
  67.  
  68. sort(b.begin(),b.end());
  69. sort(a.rbegin(),a.rend());
  70.  
  71. for(int i=0;i<n;++i){
  72. ll temp=((a[i]%mod)*(b[i]%mod))%mod;
  73. ans=(ans+temp)%mod;
  74. }
  75. cout<<ans;
  76. }
  77. int main(){
  78. ios_base::sync_with_stdio(false);
  79. cin.tie(nullptr);
  80. int t=1;
  81. //cin>>t;
  82. while(t--){
  83. slv();
  84. }
  85. }
Runtime error #stdin #stdout 0s 5644KB
stdin
Standard input is empty
stdout
Standard output is empty