fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  5.  
  6. #define int long long
  7. #define pb push_back
  8. #define ff first
  9. #define ss second
  10. #define all(x) (x).begin(), (x).end()
  11. #define rall(x) (x).rbegin(), (x).rend()
  12. #define sz(x) ((int)(x).size())
  13. #define endl '\n'
  14. #define yes cout << "yes\n"
  15. #define no cout << "no\n"
  16.  
  17. #define rep(i,a,b) for(int i=a;i<b;++i)
  18. #define per(i,a,b) for(int i=b-1;i>=a;--i)
  19. #define each(x, a) for (auto& x : a)
  20.  
  21. const int INF = 1e18;
  22. const int MOD = 1e9+7;
  23. const int N = 2e5 + 5;
  24.  
  25. int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
  26. int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
  27. int power(int a, int b, int m = MOD) {
  28. int res = 1;
  29. while (b > 0) {
  30. if (b & 1) res = res * a % m;
  31. a = a * a % m;
  32. b >>= 1;
  33. }
  34. return res;
  35. }
  36. int modinv(int a, int m = MOD) {
  37. return power(a, m - 2, m);
  38. }
  39.  
  40. void solve() {
  41. int n;
  42. cin >> n;
  43. vector<int> a(n), b(n), c(n);
  44. rep(i,0,n) cin>>a[i];
  45. rep(i,0,n) cin>>b[i];
  46. rep(i,0,n) cin>>c[i];
  47.  
  48.  
  49. int count_ab = 0;
  50. rep(i, 0, n) {
  51. bool ok = true;
  52. rep(j, 0, n) {
  53. if (a[j] >= b[(i + j) % n]) {
  54. ok = false;
  55. break;
  56. }
  57. }
  58. if (ok) count_ab++;
  59. }
  60.  
  61. int count_bc = 0;
  62. rep(i, 0, n) {
  63. bool ok = true;
  64. rep(j, 0, n) {
  65. if (b[j] >= c[(i + j) % n]) {
  66. ok = false;
  67. break;
  68. }
  69. }
  70. if (ok) count_bc++;
  71. }
  72.  
  73. cout << n * count_ab * count_bc << endl;
  74. }
  75.  
  76. int32_t main() {
  77. fast_io;
  78. int t;
  79. cin >> t;
  80. while (t--) {
  81. solve();
  82. }
  83. return 0;
  84. }
Success #stdin #stdout 0.01s 5284KB
stdin
4
2
1 2
3 4
5 4
3
1 1 1
2 2 2
3 3 3
4
1 2 1 2
3 3 2 2
5 5 5 5
5
1 4 2 3 5
6 4 5 7 6
7 5 8 10 10
stdout
4
27
0
10