#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
using ll = int_fast64_t;
#define ld long double
#define int long long
#define runtime clock_t start = clock();su;cout << clock - start;
#define file(name) if (fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
#define su cout << '\n';
#define PI 3.1415926535897932384626433832795
#define pb push_back
#define eb emplace_back
//const int dx[4] = {-1, 1, -1, 1};
//const int dy[4] = {-1, 1, 1, -1};
const ll mer = 2147483647;
const ll MAXN = 1e7 + 5;
const ll MOD = 1e9 + 7;
const ll INFLL = 1e18;
ll count_mod(ll l, ll rr, int r) {
ll first = l + ((r - l) % 5 + 5) % 5;
if (first > rr) return 0;
return 1 + (rr - first) / 5;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
const int coef[5] = {1, 4, 5, 5, 4};
vector<ll> left(n), right(n);
for (int i = 0; i < n; ++i) cin >> left[i] >> right[i];
ll dp[5] = {1, 0, 0, 0, 0}, next[5];
for (int i = 0; i < n; ++i) {
ll cnt[5];
for (int r = 0; r < 5; ++r)
cnt[r] = count_mod(left[i], right[i], r);
fill(begin(next), end(next), 0LL);
for (int p = 0; p < 5; ++p)
if (dp[p])
for (int r = 0; r < 5; ++r)
if (cnt[r])
next[(p + r) % 5] += dp[p] * cnt[r];
memcpy(dp, next, sizeof(dp));
}
ll ans = 0;
for (int s = 0; s < 5; ++s) ans += dp[s] * coef[s];
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |