problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02572 | C++ | Time Limit Exceeded | #include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string>
#include <vector>
#define PI 3.14159265358979
#define MOD 1000000007
// fixed << setprecision(15) <<
using namespace std;
int main(void) {
long long int n, m, max;
int i, j;
int e[200000];
cin >> n;
for (i = 0; i < n; i++) {
cin >> e[i];
}
max = 0;
for (i = 0; i < n - 1; i++) {
m = 0;
for (j = i + 1; j < n; j++) {
m += e[j];
}
max += e[i] * (m % MOD);
max %= MOD;
}
cout << max << endl;
return 0;
} | #include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string>
#include <vector>
#define PI 3.14159265358979
#define MOD 1000000007
// fixed << setprecision(15) <<
using namespace std;
int main(void) {
long long int n, m, max;
int i, j;
int e[200000];
cin >> n;
for (i = 0; i < n; i++) {
cin >> e[i];
}
max = 0;
m = 0;
for (i = n - 1; i > 0; i--) {
m += e[i];
m %= MOD;
max += e[i - 1] * m;
max %= MOD;
}
cout << max << endl;
return 0;
} | replace | 26 | 32 | 26 | 31 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
int a[n];
int sum = 0;
rep(i, n) {
cin >> a[i];
sum += a[i];
sum %= MOD;
}
int ans = 0;
rep(i, n) {
sum -= a[i];
while (sum < 0)
ans += MOD;
ans += a[i] * (sum);
ans %= MOD;
while (ans < 0)
ans += MOD;
}
if (ans < 0)
ans += MOD;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
int a[n];
int sum = 0;
rep(i, n) {
cin >> a[i];
sum += a[i];
sum %= MOD;
}
int ans = 0;
rep(i, n) {
sum -= a[i];
while (sum < 0)
sum += MOD;
ans += a[i] * (sum);
ans %= MOD;
while (ans < 0)
ans += MOD;
}
if (ans < 0)
ans += MOD;
cout << ans << endl;
}
| replace | 26 | 27 | 26 | 27 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define lint long long
const lint mod = 1e9 + 7;
const lint inf = 2.19e15 + 1;
const long double eps = 1e-10;
template <class T, class U> bool chmin(T &a, U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class U> bool chmax(T &a, U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
signed main() {
int n;
lint sum = 0;
cin >> n;
vector<lint> a(n);
REP(i, n) cin >> a[i];
REP(i, n - 1) {
for (int j = i + 1; j < n; j += 1) {
sum += a[i] * a[j] % mod;
sum %= mod;
}
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define lint long long
const lint mod = 1e9 + 7;
const lint inf = 2.19e15 + 1;
const long double eps = 1e-10;
template <class T, class U> bool chmin(T &a, U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class U> bool chmax(T &a, U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
signed main() {
int n;
lint sum = 0;
cin >> n;
vector<lint> a(n);
REP(i, n) cin >> a[i];
vector<lint> acm(n + 1);
acm[0] = 0;
REP(i, n) { acm[i + 1] = (acm[i] + a[i]) % mod; }
REP(i, n) {
sum += acm[i] * a[i] % mod;
sum %= mod;
}
cout << sum << endl;
}
| replace | 28 | 33 | 28 | 34 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const lint N = 1e5 + 5, mod = 1e9 + 7;
lint n, a[N];
int main() {
#ifdef LOCAL
freopen("input", "r", stdin);
#endif
scanf("%lld", &n);
for (int i = 0; i < n; i++)
scanf("%lld", &a[i]);
lint sum = a[n - 1], ans = 0;
for (int i = n - 2; i >= 0; i--) {
int add = (a[i] * sum) % mod;
ans = (ans + add) % mod;
sum = (sum + a[i]) % mod;
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const lint N = 2e5 + 5, mod = 1e9 + 7;
lint n, a[N];
int main() {
#ifdef LOCAL
freopen("input", "r", stdin);
#endif
scanf("%lld", &n);
for (int i = 0; i < n; i++)
scanf("%lld", &a[i]);
lint sum = a[n - 1], ans = 0;
for (int i = n - 2; i >= 0; i--) {
int add = (a[i] * sum) % mod;
ans = (ans + add) % mod;
sum = (sum + a[i]) % mod;
}
printf("%lld\n", ans);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02572 | C++ | Time Limit Exceeded | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define ll long long
#define fast \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define N 101
#define mod 1000000007
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i < n; i++)
#define in(i, arr) \
for (auto &i : arr) \
cin >> i;
#define all(x) \
(x).begin(), (x).end() // sort(all(v)) instead sort(v.begin(),v.end())
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define vi vector<int>
#define vl vector<int>
#define pb push_back
#define eb empalce_back
int pow(int base, int to) {
int ans = 1;
while (to > 0) {
if (to & 1)
ans *= base, to--;
else
base *= base, to /= 2;
}
return ans;
}
int main() {
fast;
// string s,t;
// cin>>s>>t;
// int count=0;
// int ma=0;
// int temp;
// for(int i=0;i<t.size();i++)
// { temp=i;
// for(int j=i;j<s.size()-(t.size()-i);j++)
// {
// if(s[j]==t[i])
// i++,count++,ma=max(ma,count);
// else {i=temp;count=0;}
// }
// i=temp+1;
// }
////for(int k=0;k<s.size();k++){
////for (int i=k,j=0;i<s.size(),j<t.size();i++)
////{
//// if(s[i]==t[j])
//// j++,count++;
//// else ma=max(ma,count),j++,count=0;
////
////}}
// cout<<t.size()-ma;
int n;
cin >> n;
ll arr[n];
in(i, arr);
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
ans = (ans % mod + (arr[i] % mod * arr[j] % mod) % mod) % mod;
}
}
cout << ans;
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define ll long long
#define fast \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define N 101
#define mod 1000000007
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i < n; i++)
#define in(i, arr) \
for (auto &i : arr) \
cin >> i;
#define all(x) \
(x).begin(), (x).end() // sort(all(v)) instead sort(v.begin(),v.end())
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define vi vector<int>
#define vl vector<int>
#define pb push_back
#define eb empalce_back
int pow(int base, int to) {
int ans = 1;
while (to > 0) {
if (to & 1)
ans *= base, to--;
else
base *= base, to /= 2;
}
return ans;
}
int main() {
fast;
// string s,t;
// cin>>s>>t;
// int count=0;
// int ma=0;
// int temp;
// for(int i=0;i<t.size();i++)
// { temp=i;
// for(int j=i;j<s.size()-(t.size()-i);j++)
// {
// if(s[j]==t[i])
// i++,count++,ma=max(ma,count);
// else {i=temp;count=0;}
// }
// i=temp+1;
// }
////for(int k=0;k<s.size();k++){
////for (int i=k,j=0;i<s.size(),j<t.size();i++)
////{
//// if(s[i]==t[j])
//// j++,count++;
//// else ma=max(ma,count),j++,count=0;
////
////}}
// cout<<t.size()-ma;
int n;
cin >> n;
ll arr[n];
in(i, arr);
ll ans = 0;
ll arr1[n];
arr1[n - 1] = arr[n - 1];
for (int i = n - 2; i >= 0; i--) {
arr1[i] = (arr1[i + 1] % mod + arr[i] % mod) % mod;
}
for (int i = 0; i < n - 1; i++) {
ans = (ans % mod + ((arr[i] % mod) * (arr1[i + 1] % mod)) % mod) % mod;
}
cout << ans;
}
| replace | 65 | 70 | 65 | 72 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int64_t> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int64_t ans = 0;
for (int i = 0; i < N - 1; i++) {
for (int j = 1; j < N - i; j++) {
ans += (vec.at(i) * vec.at(i + j)) % (1000000007);
ans %= 1000000007;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int64_t> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int64_t sum = 0;
int64_t SUM = 0;
for (int i = 0; i < N; i++) {
sum += (vec.at(i) % 1000000007);
sum %= 1000000007;
}
for (int i = 0; i < N; i++) {
SUM += ((vec.at(i) % 1000000007) * (vec.at(i) % 1000000007)) % 1000000007;
SUM %= 1000000007;
}
int64_t ans;
if ((sum * sum - SUM) % 2 == 1) {
ans = ((1000000007 + sum * sum - SUM) / 2) % 1000000007;
} else if (sum * sum - SUM < 0) {
ans = ((2000000014 + sum * sum - SUM) / 2) % 1000000007;
} else {
ans = ((sum * sum - SUM) / 2) % 1000000007;
}
cout << ans << endl;
} | replace | 10 | 16 | 10 | 27 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x) \
if (dbg) { \
cerr << #x << " = " << (x) << endl; \
}
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
void Yes(bool flag = true) {
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void No(bool flag = true) { Yes(!flag); }
void YES(bool flag = true) {
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void NO(bool flag = true) { YES(!flag); }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
bool dbg = false;
} // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
// #define P pair<int, int>
// #define V vector<int>
// #define S set<int>
#define asn ans
template <uint MD> struct ModInt {
using M = ModInt;
const static M G;
uint v;
ModInt(ll _v = 0) { set_v(_v % MD + MD); }
M &set_v(uint _v) {
v = (_v < MD) ? _v : _v - MD;
return *this;
}
explicit operator bool() const { return v != 0; }
M operator-() const { return M() - *this; }
M operator+(const M &r) const { return M().set_v(v + r.v); }
M operator-(const M &r) const { return M().set_v(v + MD - r.v); }
M operator*(const M &r) const { return M().set_v(ull(v) * r.v % MD); }
M operator/(const M &r) const { return *this * r.inv(); }
M &operator+=(const M &r) { return *this = *this + r; }
M &operator-=(const M &r) { return *this = *this - r; }
M &operator*=(const M &r) { return *this = *this * r; }
M &operator/=(const M &r) { return *this = *this / r; }
bool operator==(const M &r) const { return v == r.v; }
M pow(ll n) const {
M x = *this, r = 1;
while (n) {
if (n & 1)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
M inv() const { return pow(MD - 2); }
/*
M inv() const {
long long b = MD, u = 1, v = 0;
long long a = (*this).v;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= MD;
if (u < 0)
u += MD;
return M{u};
}
*/
friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; }
friend istream &operator>>(istream &is, M &r) { return is >> r.v; }
};
using Mint = ModInt<MOD>;
int N;
Mint A[101010];
Mint SUM = 0;
void solve() {}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
SUM += A[i];
}
Mint ans = SUM * SUM;
for (int i = 0; i < N; i++) {
ans -= A[i] * A[i];
}
ans /= 2;
cout << ans << endl;
solve();
return 0;
}
| #include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x) \
if (dbg) { \
cerr << #x << " = " << (x) << endl; \
}
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
void Yes(bool flag = true) {
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void No(bool flag = true) { Yes(!flag); }
void YES(bool flag = true) {
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void NO(bool flag = true) { YES(!flag); }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
bool dbg = false;
} // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
// #define P pair<int, int>
// #define V vector<int>
// #define S set<int>
#define asn ans
template <uint MD> struct ModInt {
using M = ModInt;
const static M G;
uint v;
ModInt(ll _v = 0) { set_v(_v % MD + MD); }
M &set_v(uint _v) {
v = (_v < MD) ? _v : _v - MD;
return *this;
}
explicit operator bool() const { return v != 0; }
M operator-() const { return M() - *this; }
M operator+(const M &r) const { return M().set_v(v + r.v); }
M operator-(const M &r) const { return M().set_v(v + MD - r.v); }
M operator*(const M &r) const { return M().set_v(ull(v) * r.v % MD); }
M operator/(const M &r) const { return *this * r.inv(); }
M &operator+=(const M &r) { return *this = *this + r; }
M &operator-=(const M &r) { return *this = *this - r; }
M &operator*=(const M &r) { return *this = *this * r; }
M &operator/=(const M &r) { return *this = *this / r; }
bool operator==(const M &r) const { return v == r.v; }
M pow(ll n) const {
M x = *this, r = 1;
while (n) {
if (n & 1)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
M inv() const { return pow(MD - 2); }
/*
M inv() const {
long long b = MD, u = 1, v = 0;
long long a = (*this).v;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= MD;
if (u < 0)
u += MD;
return M{u};
}
*/
friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; }
friend istream &operator>>(istream &is, M &r) { return is >> r.v; }
};
using Mint = ModInt<MOD>;
int N;
Mint A[201011];
Mint SUM = 0;
void solve() {}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
SUM += A[i];
}
Mint ans = SUM * SUM;
for (int i = 0; i < N; i++) {
ans -= A[i] * A[i];
}
ans /= 2;
cout << ans << endl;
solve();
return 0;
}
| replace | 126 | 127 | 126 | 127 | 0 | |
p02572 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n;
long a[20020];
long mod = 1000000007;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
long long x = 0;
for (int i = 0; i < n; i++) {
ans = (ans + a[i] * x) % mod;
x = (x + a[i]) % mod;
}
cout << ans << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int n;
long a[200020];
long mod = 1000000007;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
long long x = 0;
for (int i = 0; i < n; i++) {
ans = (ans + a[i] * x) % mod;
x = (x + a[i]) % mod;
}
cout << ans << endl;
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for (auto &i : mp)
const int INF = 1001001001;
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
ll ans = 0;
for (int i = 0; i < a.size() - 1; i++) {
for (int j = i + 1; j < a.size(); j++) {
ans += a[i] * a[j];
ans %= MOD;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for (auto &i : mp)
const int INF = 1001001001;
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
ll ans = 0;
// for (int i = 0; i < a.size() - 1; i++) {
// for (int j = i + 1; j < a.size(); j++) {
// ans += a[i] * a[j];
// ans %= MOD;
// }
// }
// vector <int> s(n + 1, 0); // s[0] = 0 になる
// string s[n + 1];
// for (int i = 0; i < n; ++i) { s[i + 1] = atoi(s[i].c_str()) + atoi(a[i]);
// }
// // reverse(s.begin(), s.end());
// for (int i = 0; i < a.size() - 1; i++) {
// ans += a[i] * (stoi(s[n]) - stoi(s[i + 1]));
// ans %= MOD;
// }
vector<ll> s(n + 1, 0); // s[0] = 0 になる
vector<ll> tmp(n);
rep(i, n) tmp[i] = a[i];
reverse(tmp.begin(), tmp.end());
for (int i = 0; i < n; ++i) {
s[i + 1] = (s[i] + (tmp[i] % MOD)) % MOD;
}
// for (int i = 0; i < n; ++i) { s[i + 1] = (s[i] + (a[i] % MOD)) % MOD; }
for (int i = 0; i < n - 1; i++) {
// ans += (a[i] % MOD) * (s[n] - s[i + 1]);
ans += (a[i] % MOD) * (s[n - (i + 1)]);
ans %= MOD;
}
cout << ans << endl;
return 0;
}
| replace | 18 | 23 | 18 | 46 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l + r) / 2)
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define drep(i, a, b) for (int i = (a); i >= (b); --i)
#define file(a) freopen(#a ".in", "r", stdin), freopen(#a ".out", "w", stdout);
const int maxn = 1e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;
int n, m, Q, K, T;
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
int a[maxn];
int dsum[maxn];
signed main() {
// file(a);
n = read();
rep(i, 1, n) a[i] = read();
dsum[n] = a[n];
drep(i, n - 1, 1) dsum[i] = (dsum[i + 1] + a[i]) % mod;
int ans = 0;
rep(i, 1, n - 1) { ans = (ans + 1ll * a[i] * dsum[i + 1] % mod) % mod; }
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l + r) / 2)
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define drep(i, a, b) for (int i = (a); i >= (b); --i)
#define file(a) freopen(#a ".in", "r", stdin), freopen(#a ".out", "w", stdout);
const int maxn = 2e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;
int n, m, Q, K, T;
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
int a[maxn];
int dsum[maxn];
signed main() {
// file(a);
n = read();
rep(i, 1, n) a[i] = read();
dsum[n] = a[n];
drep(i, n - 1, 1) dsum[i] = (dsum[i + 1] + a[i]) % mod;
int ans = 0;
rep(i, 1, n - 1) { ans = (ans + 1ll * a[i] * dsum[i + 1] % mod) % mod; }
printf("%lld\n", ans);
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
bool operator==(const mint a) const { return x == a.x; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int n;
mint a[111111];
int main() {
while (cin >> n) {
mint sum = 0, x = 0;
for (int i = 0; i < n; ++i) {
ll t;
cin >> t;
a[i] = t;
sum += a[i];
}
for (int i = 0; i < n; ++i) {
x += a[i] * (sum - a[i]);
}
cout << x / 2 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
bool operator==(const mint a) const { return x == a.x; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int n;
mint a[222222];
int main() {
while (cin >> n) {
mint sum = 0, x = 0;
for (int i = 0; i < n; ++i) {
ll t;
cin >> t;
a[i] = t;
sum += a[i];
}
for (int i = 0; i < n; ++i) {
x += a[i] * (sum - a[i]);
}
cout << x / 2 << endl;
}
} | replace | 44 | 45 | 44 | 45 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n + 1); ++(i))
#define REPR(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = (m)-1; i >= (n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>());
#define BIT(n) (1LL << (n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x, y) __gcd(x, y)
#define LCM(x, y) x / __gcd(x, y) * y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<pair<int, int>>>;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(tail) != 0)
cout << " ";
print(forward<Tail>(tail)...);
}
template <class T> void print(vector<T> &vec) {
for (auto &a : vec) {
cout << a;
if (&a != &vec.back())
cout << " ";
}
cout << endl;
}
template <class T> void print(vector<vector<T>> &df) {
for (auto &vec : df) {
print(vec);
}
}
struct mint {
int x;
mint(int x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(int t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << fixed << setprecision(10);
mint ans = 0;
int N;
cin >> N;
vector<int> A(N);
REP(i, N) { cin >> A[i]; }
REP(i, N - 1) FOR(j, i + 1, N) {
mint tmp = A[i] * A[j];
ans += tmp;
}
cout << ans << endl;
return 0;
}
/*
cd ~/Desktop/Programming/AtCoder/contest/abc177/abc177_c && sh
shellscripts/test_cpp.sh cd
~/Desktop/Programming/AtCoder/contest/abc177/abc177_c && sh
shellscripts/etest_cpp.sh cd
~/Desktop/Programming/AtCoder/contest/abc177/abc177_c && sh
shellscripts/submit_cpp.sh
*/
| #include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n + 1); ++(i))
#define REPR(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = (m)-1; i >= (n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>());
#define BIT(n) (1LL << (n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x, y) __gcd(x, y)
#define LCM(x, y) x / __gcd(x, y) * y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<pair<int, int>>>;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(tail) != 0)
cout << " ";
print(forward<Tail>(tail)...);
}
template <class T> void print(vector<T> &vec) {
for (auto &a : vec) {
cout << a;
if (&a != &vec.back())
cout << " ";
}
cout << endl;
}
template <class T> void print(vector<vector<T>> &df) {
for (auto &vec : df) {
print(vec);
}
}
struct mint {
int x;
mint(int x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(int t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << fixed << setprecision(10);
mint ans = 0;
int N;
cin >> N;
vector<int> A(N);
VI B(N + 1, 0);
REP(i, N) {
cin >> A[i];
B[i + 1] = B[i] + A[i];
B[i + 1] %= MOD;
}
REP(i, N) {
mint tmp = B[N] - B[i + 1];
tmp *= A[i];
ans += tmp;
}
cout << ans << endl;
return 0;
}
/*
cd ~/Desktop/Programming/AtCoder/contest/abc177/abc177_c && sh
shellscripts/test_cpp.sh cd
~/Desktop/Programming/AtCoder/contest/abc177/abc177_c && sh
shellscripts/etest_cpp.sh cd
~/Desktop/Programming/AtCoder/contest/abc177/abc177_c && sh
shellscripts/submit_cpp.sh
*/
| replace | 102 | 105 | 102 | 111 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, a, b, c) for (ll i = a; i < b; i += c)
#define r(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define mod 1000000007
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll n;
cin >> n;
ll ar[n];
ll sum = 0;
f(i, 0, n, 1) { cin >> ar[i]; }
f(i, 0, n - 1, 1) {
f(j, i + 1, n, 1) {
sum += (ar[i] * ar[j]);
sum %= mod;
}
}
cout << sum;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, a, b, c) for (ll i = a; i < b; i += c)
#define r(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define mod 1000000007
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll n;
cin >> n;
ll ar[n];
ll sum = 0;
f(i, 0, n, 1) { cin >> ar[i]; }
ll in = ar[n - 1];
r(i, n - 1, 1, 1) {
// cout << in << "\n";
sum += (ar[i - 1] * in);
in += ar[i - 1];
sum %= mod;
in %= mod;
// cout << ar[i-1] << " " << sum << " " << in << "\n";
}
cout << sum;
return 0;
} | replace | 13 | 18 | 13 | 21 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int M = (int)1e5;
const int N = (int)5e5;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)1e9 + 7;
const double eps = 1e-6;
int n, a[M + 5];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d", &n);
ll sum = 0, ans = 0;
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]), sum = (sum + a[i]) % mod;
for (int i = 1; i <= n; ++i) {
sum = (sum - a[i]) % mod;
ans = (ans + sum * a[i] % mod) % mod;
}
ans = (ans % mod + mod) % mod;
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int M = (int)2e5;
const int N = (int)5e5;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)1e9 + 7;
const double eps = 1e-6;
int n, a[M + 5];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d", &n);
ll sum = 0, ans = 0;
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]), sum = (sum + a[i]) % mod;
for (int i = 1; i <= n; ++i) {
sum = (sum - a[i]) % mod;
ans = (ans + sum * a[i] % mod) % mod;
}
ans = (ans % mod + mod) % mod;
printf("%lld\n", ans);
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <functional>
#include <iostream> // cout, endl, cin
#include <map> // map
#include <math.h>
#include <numeric>
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void) {
int N;
cin >> N;
vector<ll> vec(N);
for (int i = 0; i < N; i++)
cin >> vec.at(i);
ll ans = 0;
ll mod = 1e9 + 7;
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
ans += vec.at(i) * vec.at(j);
ans %= mod;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <functional>
#include <iostream> // cout, endl, cin
#include <map> // map
#include <math.h>
#include <numeric>
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void) {
int N;
cin >> N;
vector<ll> vec(N);
for (int i = 0; i < N; i++)
cin >> vec.at(i);
ll ans = 0;
ll mod = (ll)1e9 + 7;
ll tmp = 0;
for (int i = 1; i < N; i++) {
tmp += vec.at(i - 1);
tmp %= mod;
ans += vec.at(i) * tmp;
ans %= mod;
}
cout << ans << endl;
return 0;
} | replace | 32 | 38 | 32 | 39 | TLE | |
p02572 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#define mod 1000000007
using namespace std;
unsigned long long a[100005], cnt, sum;
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum = sum + a[i];
}
for (int i = 1; i <= n; i++) {
sum = sum - a[i];
cnt = (cnt + (sum % mod * a[i]) % mod) % mod;
}
cout << cnt << endl;
return 0;
}
/* 1 2 3 4 5
2 3 4 5 6 8 10 12 15 20
*/ | #include <cstdio>
#include <iostream>
#define mod 1000000007
using namespace std;
unsigned long long a[1000005], cnt, sum;
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum = sum + a[i];
}
for (int i = 1; i <= n; i++) {
sum = sum - a[i];
cnt = (cnt + (sum % mod * a[i]) % mod) % mod;
}
cout << cnt << endl;
return 0;
}
/* 1 2 3 4 5
2 3 4 5 6 8 10 12 15 20
*/ | replace | 4 | 5 | 4 | 5 | 0 | |
p02572 | C++ | Time Limit Exceeded | /*----------------------------------------------------*
* लेखक --> अमित सिंह
* संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
*-----------------------------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define fo(i, n) for (int i = 0; i < n; i++)
#define endl "\n"
#define MOD 1000000007
void Tez() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
Tez();
int n;
cin >> n;
ll a[n];
fo(i, n) cin >> a[i];
ll ans = 0;
fo(i, n - 1) {
for (int j = i + 1; j < n; j++) {
ans = (ans + (a[i] * a[j]) % MOD) % MOD;
}
}
cout << ans;
return 0;
}
| /*----------------------------------------------------*
* लेखक --> अमित सिंह
* संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
*-----------------------------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define fo(i, n) for (int i = 0; i < n; i++)
#define endl "\n"
#define MOD 1000000007
void Tez() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
Tez();
int n;
cin >> n;
ll a[n];
fo(i, n) cin >> a[i];
ll ans = 0;
ll arr[n - 1];
ll sum = 0;
for (int i = 0; i < n; i++)
sum = (sum + a[i]) % MOD;
for (int i = 0; i < n - 1; i++) {
arr[i] = ((sum - a[i]) % MOD + MOD) % MOD;
// arr[i]=sum-a[i];
sum = arr[i];
}
for (int i = 0; i < n - 1; i++) {
ans = (ans + a[i] * arr[i]) % MOD;
}
cout << ans;
return 0;
}
| replace | 26 | 30 | 26 | 37 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define IN(type, n) \
type n; \
cin >> n
int main() {
IN(ll, N);
vector<ll> A(N);
ll mod = 1000000007;
REP(i, N) {
IN(ll, tmp);
tmp %= mod;
A.at(i) = tmp;
}
ll ans = 0;
REP(i, N - 1) {
for (int j = i + 1; j < N; ++j) {
ans += A.at(i) * A.at(j);
ans %= mod;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define IN(type, n) \
type n; \
cin >> n
int main() {
IN(ll, N);
vector<ll> A(N);
ll mod = 1000000007;
REP(i, N) {
IN(ll, tmp);
tmp %= mod;
A.at(i) = tmp;
}
ll ans = 0;
ll sum = A.at(N - 1);
for (int i = N - 2; i >= 0; --i) {
ans += sum * A.at(i);
ans %= mod;
sum += A.at(i);
sum %= mod;
}
cout << ans << endl;
return 0;
}
| replace | 19 | 24 | 19 | 25 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int P = 1000000007;
int n, i, a[100005];
i64 tot, ans;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (i = n; i > 0; --i) {
ans = (ans + tot * a[i]) % P;
tot = (tot + a[i]) % P;
}
printf("%lld", ans);
} | #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int P = 1000000007;
int n, i, a[200005];
i64 tot, ans;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (i = n; i > 0; --i) {
ans = (ans + tot * a[i]) % P;
tot = (tot + a[i]) % P;
}
printf("%lld", ans);
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n;
long long a[100005];
const long long MOD = (long long)(1e9) + 7;
void solve() {
long long subsum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
subsum = (subsum + a[i]) % MOD;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
subsum = (subsum - a[i] + MOD) % MOD;
ans = (ans + (a[i]) * subsum % MOD) % MOD;
}
cout << ans << '\n';
}
int main() {
// int t; cin >> t;
// while(t--)
solve();
} | #include <bits/stdc++.h>
using namespace std;
int n;
long long a[200005];
const long long MOD = (long long)(1e9) + 7;
void solve() {
long long subsum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
subsum = (subsum + a[i]) % MOD;
}
long long ans = 0;
for (int i = 0; i < n; i++) {
subsum = (subsum - a[i] + MOD) % MOD;
ans = (ans + (a[i]) * subsum % MOD) % MOD;
}
cout << ans << '\n';
}
int main() {
// int t; cin >> t;
// while(t--)
solve();
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template <class T> inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
void execute();
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false); // cin と scanfの併用禁止
cout << fixed << setprecision(15);
execute();
return 0;
}
void execute() {
int N;
ll A[200000];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll s = 0;
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
s += A[i] * A[j];
s %= (1000000007);
}
}
cout << s << endl;
}
| #include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template <class T> inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
void execute();
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false); // cin と scanfの併用禁止
cout << fixed << setprecision(15);
execute();
return 0;
}
void execute() {
int N;
ll A[200000];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll s = 0;
ll v = 0;
for (int i = N - 1; 0 < i; i--) {
v += A[i];
v %= (1000000007);
s += A[i - 1] * v;
s %= (1000000007);
}
cout << s << endl;
}
| replace | 41 | 46 | 41 | 47 | TLE | |
p02572 | C++ | Runtime Error | #include <iostream>
using namespace std;
using ll = long long;
#define MOD 1000000007;
int main() {
ll N;
ll A[N + 1];
cin >> N;
ll sum = 0;
ll res = 0;
for (ll i = 1; i <= N; i++) {
cin >> A[i];
sum += A[i];
sum %= MOD;
}
for (ll i = 1; i < N; i++) {
sum -= A[i];
if (sum < 0) {
sum += MOD;
}
res += (A[i] * sum) % MOD;
res %= MOD;
}
cout << res << endl;
return 0;
} | #include <iostream>
using namespace std;
using ll = long long;
#define MOD 1000000007;
int main() {
ll N;
ll A[200002];
cin >> N;
ll sum = 0;
ll res = 0;
for (ll i = 1; i <= N; i++) {
cin >> A[i];
sum += A[i];
sum %= MOD;
}
for (ll i = 1; i < N; i++) {
sum -= A[i];
if (sum < 0) {
sum += MOD;
}
res += (A[i] * sum) % MOD;
res %= MOD;
}
cout << res << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | -11 | |
p02572 | C++ | Time Limit Exceeded | // インクルード(アルファベット順)
#include <algorithm> //sort,二分探索,など
#include <bitset> //固定長bit集合
#include <cmath> //pow,logなど
#include <complex> //複素数
#include <deque> //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip> //setprecision(浮動小数点の出力の誤差)
#include <iostream> //入出力
#include <iterator> //集合演算(積集合,和集合,差集合など)
#include <map> //map(辞書)
#include <numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include <queue> //キュー
#include <set> //集合
#include <stack> //スタック
#include <string> //文字列
// #include<unordered_map>//イテレータあるけど順序保持しないmap
// #include<unordered_set>//イテレータあるけど順序保持しないset
#include <utility> //pair
#include <valarray> //なんとなく追加
#include <vector> //可変長配列
// メモ:表示桁数を大きくする cout << fixed << setprecision(20) << cm <<
// endl;
using namespace std;
typedef long long ll;
// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) // 最大値を求める
#define MIN(x) *min_element(ALL(x)) // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first // pairの一つ目の要素
#define S second // pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout << ans << endl;
#define input(N) cin >> N;
signed main() {
ll N, ans = 0;
cin >> N;
vector<ll> A(N), SUMa(N, 0);
REP(i, N) { cin >> A[i]; }
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
SUMa[i] = (SUMa[i] + A[j]) % MOD;
}
}
for (int i = 0; i < N; i++) {
ans = (ans + A[i] * SUMa[i] % MOD) % MOD;
}
answer(ans);
system("pause");
return 0;
} | // インクルード(アルファベット順)
#include <algorithm> //sort,二分探索,など
#include <bitset> //固定長bit集合
#include <cmath> //pow,logなど
#include <complex> //複素数
#include <deque> //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip> //setprecision(浮動小数点の出力の誤差)
#include <iostream> //入出力
#include <iterator> //集合演算(積集合,和集合,差集合など)
#include <map> //map(辞書)
#include <numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include <queue> //キュー
#include <set> //集合
#include <stack> //スタック
#include <string> //文字列
// #include<unordered_map>//イテレータあるけど順序保持しないmap
// #include<unordered_set>//イテレータあるけど順序保持しないset
#include <utility> //pair
#include <valarray> //なんとなく追加
#include <vector> //可変長配列
// メモ:表示桁数を大きくする cout << fixed << setprecision(20) << cm <<
// endl;
using namespace std;
typedef long long ll;
// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) // 最大値を求める
#define MIN(x) *min_element(ALL(x)) // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first // pairの一つ目の要素
#define S second // pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout << ans << endl;
#define input(N) cin >> N;
signed main() {
ll N, ans = 0;
cin >> N;
vector<ll> A(N), SUMa(N, 0);
REP(i, N) { cin >> A[i]; }
for (int i = N - 2; i >= 0; i--) {
SUMa[i] = (SUMa[i + 1] + A[i + 1]) % MOD;
}
for (int i = 0; i < N; i++) {
ans = (ans + A[i] * SUMa[i] % MOD) % MOD;
}
answer(ans);
system("pause");
return 0;
} | replace | 57 | 61 | 57 | 59 | TLE | |
p02572 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define str string
#define deb_arr(arr, n) \
for (ll i = 0; i < (n); i++) { \
cout << (arr)[i] << " "; \
}
#define in_arr0(arr, n) \
for (ll i = 0; i < (n); i++) { \
cin >> (arr)[i]; \
}
#define in_arr1(arr, n) \
for (ll i = 1; i <= (n); i++) { \
cin >> (arr)[i]; \
}
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
#define vll vector<ll>
#define fr(n) for (i = 0; i < (n); i++)
#define fr1(n) for (i = 1; i <= (n); i++)
#define pll pair<ll, ll>
#define f first
#define s second
#define vpll vector<pll>
#define ump unordered_map
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define debb(x) cout << (x) << endl
#define IN(a, b) ((a).find(b) != (a).end())
#define pb push_back
#define mkp make_pair
#define PI M_PI
#define INF 1e18
#define deb(x) \
if (ON) \
cout << #x << " : " << x << endl
#define fast ios_base::sync_with_stdio(false)
#define io cin.tie(NULL), cout.tie(NULL)
#define ON !false
ll dx[] = {0, -1, 0, 1};
ll dy[] = {1, 0, -1, 0};
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return ((a % mod) + (b % mod) + mod) % mod; }
inline ll mul(ll a, ll b) { return ((a % mod) * (b % mod) + mod) % mod; }
void pause(ll id) {
cout << "Waiting " << id << endl;
cin >> id;
}
const int mxn = 1e5 + 10;
ll arr[mxn];
ll pre[mxn];
void init() { return; }
signed main() {
fast;
io;
if (!true) {
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
init();
ll i, j;
// iota(itf,its) ;
// n=unique(a+1,a+1+n,n)-(a+1);
ll n;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> arr[i];
}
for (i = n; i >= 1; i--) {
pre[i] = arr[i];
pre[i] = add(pre[i], pre[i + 1]);
pre[i] %= mod;
}
ll ans = 0;
for (i = 1; i <= n; i++) {
ll temp = 0;
temp = mul(arr[i], pre[i + 1]);
ans = add(ans, temp);
}
debb(ans);
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define str string
#define deb_arr(arr, n) \
for (ll i = 0; i < (n); i++) { \
cout << (arr)[i] << " "; \
}
#define in_arr0(arr, n) \
for (ll i = 0; i < (n); i++) { \
cin >> (arr)[i]; \
}
#define in_arr1(arr, n) \
for (ll i = 1; i <= (n); i++) { \
cin >> (arr)[i]; \
}
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
#define vll vector<ll>
#define fr(n) for (i = 0; i < (n); i++)
#define fr1(n) for (i = 1; i <= (n); i++)
#define pll pair<ll, ll>
#define f first
#define s second
#define vpll vector<pll>
#define ump unordered_map
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define debb(x) cout << (x) << endl
#define IN(a, b) ((a).find(b) != (a).end())
#define pb push_back
#define mkp make_pair
#define PI M_PI
#define INF 1e18
#define deb(x) \
if (ON) \
cout << #x << " : " << x << endl
#define fast ios_base::sync_with_stdio(false)
#define io cin.tie(NULL), cout.tie(NULL)
#define ON !false
ll dx[] = {0, -1, 0, 1};
ll dy[] = {1, 0, -1, 0};
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return ((a % mod) + (b % mod) + mod) % mod; }
inline ll mul(ll a, ll b) { return ((a % mod) * (b % mod) + mod) % mod; }
void pause(ll id) {
cout << "Waiting " << id << endl;
cin >> id;
}
const int mxn = 2e5 + 10;
ll arr[mxn];
ll pre[mxn];
void init() { return; }
signed main() {
fast;
io;
if (!true) {
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
init();
ll i, j;
// iota(itf,its) ;
// n=unique(a+1,a+1+n,n)-(a+1);
ll n;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> arr[i];
}
for (i = n; i >= 1; i--) {
pre[i] = arr[i];
pre[i] = add(pre[i], pre[i + 1]);
pre[i] %= mod;
}
ll ans = 0;
for (i = 1; i <= n; i++) {
ll temp = 0;
temp = mul(arr[i], pre[i + 1]);
ans = add(ans, temp);
}
debb(ans);
return 0;
}
| replace | 62 | 63 | 62 | 63 | 0 | |
p02572 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
long long a[100000];
long long mod = 1000000007;
int main() {
int n;
cin >> n;
long long sum = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum = sum + a[i];
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
sum = sum - a[i];
ans = ans % mod + (sum % mod) * (a[i] % mod) % mod;
ans = ans % mod;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
long long a[1000000];
long long mod = 1000000007;
int main() {
int n;
cin >> n;
long long sum = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum = sum + a[i];
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
sum = sum - a[i];
ans = ans % mod + (sum % mod) * (a[i] % mod) % mod;
ans = ans % mod;
}
cout << ans << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000007
class Graph {
int V;
vector<list<int>> edges;
public:
Graph(int nodes) {
V = nodes;
edges.resize(nodes + 1);
}
void addEdge(int from, int to) { edges[from].push_back(to); }
int min_dist(int &fin, int i, map<int, bool> &special, vector<bool> &check) {
check[i] = true;
multiset<int> ms;
int k;
for (auto it = edges[i].begin(); it != edges[i].end(); it++) {
if (check[*it] == true)
continue;
k = min_dist(fin, *it, special, check);
if (k != 0)
ms.insert(k);
}
for (auto it = ms.begin(); it != ms.end(); it++) {
fin += (*it);
// cout << *it << " ";
}
// cout << endl;
if (ms.size() % 2 == 0) {
if (special[i])
return 1;
return 0;
} else {
if (special[i])
return 0;
auto it = ms.begin();
fin -= (*it);
return (*it) + 1;
}
}
};
int main() {
int t = 1;
// cin >> t;
while (t--) {
int n;
cin >> n;
vector<ll> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
ll sum = 0;
for (int i = 0; i < n; i++) {
ll temp = 0;
for (int j = i + 1; j < n; j++) {
temp = (temp + arr[j]) % INF;
}
sum = (sum + ((temp % INF) * (arr[i] % INF))) % INF;
}
cout << sum % INF << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000007
class Graph {
int V;
vector<list<int>> edges;
public:
Graph(int nodes) {
V = nodes;
edges.resize(nodes + 1);
}
void addEdge(int from, int to) { edges[from].push_back(to); }
int min_dist(int &fin, int i, map<int, bool> &special, vector<bool> &check) {
check[i] = true;
multiset<int> ms;
int k;
for (auto it = edges[i].begin(); it != edges[i].end(); it++) {
if (check[*it] == true)
continue;
k = min_dist(fin, *it, special, check);
if (k != 0)
ms.insert(k);
}
for (auto it = ms.begin(); it != ms.end(); it++) {
fin += (*it);
// cout << *it << " ";
}
// cout << endl;
if (ms.size() % 2 == 0) {
if (special[i])
return 1;
return 0;
} else {
if (special[i])
return 0;
auto it = ms.begin();
fin -= (*it);
return (*it) + 1;
}
}
};
int main() {
int t = 1;
// cin >> t;
while (t--) {
int n;
cin >> n;
vector<ll> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
ll sum = 0;
ll temp = arr[n - 1];
for (int i = n - 2; i >= 0; i--) {
sum = (sum + (arr[i] % INF) * (temp % INF)) % INF;
temp = (temp + arr[i]) % INF;
}
cout << sum % INF << endl;
}
return 0;
}
| replace | 56 | 62 | 56 | 60 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int mn = 1e5 + 7, mod = 1e9 + 7;
long long a[mn], sum[mn], ans;
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", a + i);
sum[i] = (sum[i - 1] + a[i]) % mod;
}
for (int i = 1; i <= n; ++i)
ans = (ans + a[i] * (sum[n] - sum[i] + mod) % mod) % mod;
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
const int mn = 2e5 + 7, mod = 1e9 + 7;
long long a[mn], sum[mn], ans;
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", a + i);
sum[i] = (sum[i - 1] + a[i]) % mod;
}
for (int i = 1; i <= n; ++i)
ans = (ans + a[i] * (sum[n] - sum[i] + mod) % mod) % mod;
cout << ans;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long int ull;
#define base 31
#define MOD 1000000007
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORs(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define __FOR(i, a, b, k) for (int i = a; i <= b; i += k)
#define __REP(i, a, b, k) for (int i = a; i < b; i += k)
#define pb push_back
#define _io \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N 100005
ull n, a[N], sum[N];
ull res;
int main() {
_io;
cin >> n;
FOR(i, 1, n) cin >> a[i];
sum[1] = a[1];
FOR(i, 2, n) sum[i] = sum[i - 1] + a[i];
// FOR(i,1,n) cout<<sum[i]<<" ";
res = 0;
ull mod = 1000000007;
FOR(i, 1, n) {
ull x = ((a[i] % mod) * ((sum[n] - sum[i]) % mod)) % mod;
res += (x % (mod));
}
cout << res % mod;
}
| #include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long int ull;
#define base 31
#define MOD 1000000007
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORs(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define __FOR(i, a, b, k) for (int i = a; i <= b; i += k)
#define __REP(i, a, b, k) for (int i = a; i < b; i += k)
#define pb push_back
#define _io \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N 200005
ull n, a[N], sum[N];
ull res;
int main() {
_io;
cin >> n;
FOR(i, 1, n) cin >> a[i];
sum[1] = a[1];
FOR(i, 2, n) sum[i] = sum[i - 1] + a[i];
// FOR(i,1,n) cout<<sum[i]<<" ";
res = 0;
ull mod = 1000000007;
FOR(i, 1, n) {
ull x = ((a[i] % mod) * ((sum[n] - sum[i]) % mod)) % mod;
res += (x % (mod));
}
cout << res % mod;
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
long long sum = 0;
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
sum = (sum + a[i] * a[j]) % 1000000007;
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
long long sum = 0, cnt = 0;
for (int i = 1; i < n; ++i)
sum += a[i];
cnt += a[0] % 1000000007 * (sum % 1000000007);
for (int i = 1; i < n; ++i) {
sum -= a[i];
cnt += a[i] % 1000000007 * (sum % 1000000007);
cnt %= 1000000007;
}
cnt %= 1000000007;
cout << cnt << endl;
return 0;
} | replace | 8 | 13 | 8 | 19 | TLE | |
p02572 | C++ | Runtime Error | #include <cmath>
#include <iostream>
#include <vector>
int main() {
int num;
std::cin >> num;
long A[num];
std::vector<long long> B(num, 0);
for (int i = 0; i < num; i++) {
std::cin >> A[i];
B[i + 1] = B[i] + A[i];
}
int mod = 1000000007;
long ans = 0;
for (int i = 0; i < num; i++) {
long long sum = (B[num] - B[i + 1]) % mod;
// std::cout << sum_all << std::endl;
ans += sum * A[i];
ans %= mod;
}
// std::cout << (long)141421356*17320508 << std::endl;
std::cout << ans << std::endl;
return 0;
} | #include <cmath>
#include <iostream>
#include <vector>
int main() {
int num;
std::cin >> num;
long A[num];
std::vector<long long> B(num + 1, 0);
for (int i = 0; i < num; i++) {
std::cin >> A[i];
B[i + 1] = B[i] + A[i];
}
int mod = 1000000007;
long ans = 0;
for (int i = 0; i < num; i++) {
long long sum = (B[num] - B[i + 1]) % mod;
// std::cout << sum_all << std::endl;
ans += sum * A[i];
ans %= mod;
}
// std::cout << (long)141421356*17320508 << std::endl;
std::cout << ans << std::endl;
return 0;
} | replace | 8 | 9 | 8 | 9 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
#define N 100005
#define mod 1000000007
using namespace std;
template <typename T> inline void in(T &x) {
x = 0;
char c = getchar();
bool fu = 0;
while (c < '0' || c > '9') {
if (c == '-')
fu = 1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
int n, a[N], sum[N], ans;
int main() {
in(n);
for (int i = 0; i < n; ++i)
in(a[i]);
sum[n - 1] = a[n - 1];
for (int i = n - 2; i >= 0; --i)
sum[i] = (a[i] + sum[i + 1]) % mod;
for (int i = 0; i < n - 1; ++i)
ans = (ans + (1LL * a[i] * sum[i + 1] % mod)) % mod;
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
#define N 200005
#define mod 1000000007
using namespace std;
template <typename T> inline void in(T &x) {
x = 0;
char c = getchar();
bool fu = 0;
while (c < '0' || c > '9') {
if (c == '-')
fu = 1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
int n, a[N], sum[N], ans;
int main() {
in(n);
for (int i = 0; i < n; ++i)
in(a[i]);
sum[n - 1] = a[n - 1];
for (int i = n - 2; i >= 0; --i)
sum[i] = (a[i] + sum[i + 1]) % mod;
for (int i = 0; i < n - 1; ++i)
ans = (ans + (1LL * a[i] * sum[i + 1] % mod)) % mod;
printf("%d\n", ans);
return 0;
} | replace | 1 | 2 | 1 | 2 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define MOD 1000000007
#define MAX 100010
#define aout(a) \
REP(i, sizeof(a)) cout << a[i] << " "; \
cout << endl;
#define vout(v) \
REP(i, v, size()) cout << v[i] << " "; \
cout << endl;
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int main() {
int N;
cin >> N;
vector<ll> A(N);
REP(i, N) cin >> A[i];
ll ans = 0;
FOR(i, 0, N - 1) {
FOR(j, i + 1, N) { ans = (ans + ((A[i] * A[j]) % MOD)) % MOD; }
}
cout << ans;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define MOD 1000000007
#define MAX 100010
#define aout(a) \
REP(i, sizeof(a)) cout << a[i] << " "; \
cout << endl;
#define vout(v) \
REP(i, v, size()) cout << v[i] << " "; \
cout << endl;
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int main() {
int N;
cin >> N;
vector<ll> A(N);
REP(i, N) cin >> A[i];
ll ans = 0;
vector<ll> sum(N - 1);
sum[0] = A[0];
FOR(i, 1, N - 1) { sum[i] = (sum[i - 1] + A[i]) % MOD; }
REP(i, N - 1) {
int tmp = (A[i + 1] * sum[i]) % MOD;
ans = (ans + tmp) % MOD;
}
cout << ans;
} | replace | 22 | 25 | 22 | 28 | TLE | |
p02572 | C++ | Runtime Error | #include <cstdio>
// #include<iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxv = 100005;
const int inf = 1e9 + 7;
int ar[maxv];
int main() {
int n;
ll sum = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &ar[i]);
sum += ar[i];
sum %= inf;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
sum -= ar[i];
if (sum < 0)
sum += inf;
ans += ar[i] * sum;
ans %= inf;
}
printf("%lld\n", ans);
return 0;
}
| #include <cstdio>
// #include<iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxv = 200005;
const int inf = 1e9 + 7;
int ar[maxv];
int main() {
int n;
ll sum = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &ar[i]);
sum += ar[i];
sum %= inf;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
sum -= ar[i];
if (sum < 0)
sum += inf;
ans += ar[i] * sum;
ans %= inf;
}
printf("%lld\n", ans);
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define endl '\n'
#define eps 0.000000001
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#define IO \
ios::sync_with_stdio(false); \
cin.tie(0);
using namespace std;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int n;
ll a[maxn], pre[maxn];
int main() {
int n;
cin >> n;
pre[0] = pre[1] = 0;
rep(i, 1, n) cin >> a[i], pre[i + 1] = (pre[i] + a[i]) % mod;
ll sum = 0;
rep(i, 1, n) {
ll cur = (pre[i] * a[i]) % mod;
sum = (sum + cur) % mod;
}
cout << sum << endl;
}
| #include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define endl '\n'
#define eps 0.000000001
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#define IO \
ios::sync_with_stdio(false); \
cin.tie(0);
using namespace std;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
int n;
ll a[maxn], pre[maxn];
int main() {
int n;
cin >> n;
pre[0] = pre[1] = 0;
rep(i, 1, n) cin >> a[i], pre[i + 1] = (pre[i] + a[i]) % mod;
ll sum = 0;
rep(i, 1, n) {
ll cur = (pre[i] * a[i]) % mod;
sum = (sum + cur) % mod;
}
cout << sum << endl;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 10009;
const int P = 1000000007;
int n;
int a[maxn];
long long sum[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
sum[i] = (sum[i - 1] + a[i]) % P;
}
long long ans = 0;
for (int i = 2; i <= n; ++i) {
ans = (ans + a[i] * sum[i - 1]) % P;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 200009;
const int P = 1000000007;
int n;
int a[maxn];
long long sum[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
sum[i] = (sum[i - 1] + a[i]) % P;
}
long long ans = 0;
for (int i = 2; i <= n; ++i) {
ans = (ans + a[i] * sum[i - 1]) % P;
}
cout << ans << endl;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long a[100005];
int main() {
int n;
scanf("%d", &n);
long long tot1 = 0, tot2 = 0;
for (int i = 1; i <= n; ++i)
scanf("%lld", &a[i]), tot1 += a[i], tot2 += a[i] * a[i] % mod;
tot1 %= mod;
tot2 %= mod;
long long ans = tot1 * tot1 % mod;
ans = (ans - tot2) % mod + mod;
printf("%lld\n", ans * 500000004 % mod);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long a[200005];
int main() {
int n;
scanf("%d", &n);
long long tot1 = 0, tot2 = 0;
for (int i = 1; i <= n; ++i)
scanf("%lld", &a[i]), tot1 += a[i], tot2 += a[i] * a[i] % mod;
tot1 %= mod;
tot2 %= mod;
long long ans = tot1 * tot1 % mod;
ans = (ans - tot2) % mod + mod;
printf("%lld\n", ans * 500000004 % mod);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
/*
cout<<"\ndebugging\n";
*/
int main() {
ios_base::sync_with_stdio(false); // Fast I/O
cin.tie(NULL);
ll t, n, i, j;
cin >> n;
vector<ll> a;
ll x;
for (i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
ll sum = 0;
for (int i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
sum = (sum % mod + (a[i] * a[j]) % mod) % mod;
}
}
cout << sum;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
/*
cout<<"\ndebugging\n";
*/
int main() {
ios_base::sync_with_stdio(false); // Fast I/O
cin.tie(NULL);
ll t, n, i, j;
cin >> n;
vector<ll> a;
ll x;
for (i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
ll sum = 0, sumall = 0;
for (i = n - 2; i >= 0; i--) {
sumall = (sumall + a[i + 1]) % mod;
sum = (sum + (a[i] * sumall) % mod) % mod;
}
cout << sum;
return 0;
}
| replace | 22 | 27 | 22 | 26 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
using P = pair<int, int>;
int main() {
ll N;
cin >> N;
vector<ll> A(N);
rep(i, N) cin >> A[i];
ll ans = 0;
for (int i = 0; i < (N - 1); i++) {
for (int j = i + 1; j < N; j++) {
ans += A[i] * A[j];
if (ans > 1'000'000'007LL)
ans %= 1'000'000'007LL;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
using P = pair<int, int>;
int main() {
ll N;
cin >> N;
vector<ll> A(N);
rep(i, N) cin >> A[i];
ll ans = 0;
vector<ll> SS(N);
ll s = 0;
for (int i = N - 1; i >= 1; i--) {
s += A[i];
SS[i] = s % 1'000'000'007LL;
}
for (int i = 0; i < N - 1; i++) {
ans += A[i] * SS[i + 1];
ans %= 1'000'000'007LL;
}
cout << ans << endl;
return 0;
} | replace | 16 | 22 | 16 | 28 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, t, a[100005];
vector<ll> adj[100005];
#define ari \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define ginp \
for (int i = 0; i < m; i++) { \
int u, v; \
cin >> u >> v; \
adj[u].push_back(v); \
adj[v].push_back(u); \
}
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first
#define mp make_pair
ll mod = 1e9 + 7;
void printar(vector<ll> ar, ll l, ll r) {
for (int i = l; i < r; i++)
cout << ar[i] << " ";
cout << endl;
}
ll fast() {
ll temp = 1, exp = 1e9 + 5, pow = 2;
while (exp > 0) {
if (exp % 2)
temp = (temp * pow) % mod;
exp /= 2;
pow = (pow * pow) % mod;
}
return temp;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
ari;
ll sum = 0, sq = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
sum %= mod;
sq += (a[i] * a[i]) % mod;
sq %= mod;
}
ll ans = (((sum * sum) % mod - sq) + mod) % mod;
ans = (ans * fast()) % mod;
cout << ans << endl;
return (0);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, t, a[200005];
vector<ll> adj[100005];
#define ari \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define ginp \
for (int i = 0; i < m; i++) { \
int u, v; \
cin >> u >> v; \
adj[u].push_back(v); \
adj[v].push_back(u); \
}
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first
#define mp make_pair
ll mod = 1e9 + 7;
void printar(vector<ll> ar, ll l, ll r) {
for (int i = l; i < r; i++)
cout << ar[i] << " ";
cout << endl;
}
ll fast() {
ll temp = 1, exp = 1e9 + 5, pow = 2;
while (exp > 0) {
if (exp % 2)
temp = (temp * pow) % mod;
exp /= 2;
pow = (pow * pow) % mod;
}
return temp;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
ari;
ll sum = 0, sq = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
sum %= mod;
sq += (a[i] * a[i]) % mod;
sq %= mod;
}
ll ans = (((sum * sum) % mod - sq) + mod) % mod;
ans = (ans * fast()) % mod;
cout << ans << endl;
return (0);
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02572 | C++ | Time Limit Exceeded | #pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<double, double>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define tcT template <class T
#define tcTUU tcT, class... U
#define tcTU tcT, class U
#define tcTU3 tcTU, class C
#define tcTU4 tcTU3, class D
tcT > using V = vector<T>;
tcT, size_t SZ > using AR = array<T, SZ>;
tcT > using mpq = priority_queue<T, vector<T>, greater<T>>;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
tcT> using oset = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>; #define fbo find_by_order #define ook
order_of_key tcTU> using ht = gp_hash_table<T,U,chash>;*/
struct chash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
tcTU > using um = unordered_map<T, U, chash>;
#define cbit(n, b) (((n) >> (b)) & 1)
#define sbit(n, b) ((n) | (1ULL << (b)))
#define rbit(n, b) ((n) & ~(1ULL << (b)))
#define fbit(n, b) ((n) ^ (1ULL << (b)))
#define ts to_string
#define fe first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(v) ((int)(v).size())
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto &a : x)
tcTU > T fstTrue(T lo, T hi, U f) {
while (lo < hi) {
T mid = (lo + hi) / 2;
f(mid) ? hi = mid : lo = mid + 1;
}
return lo;
}
tcTU > T lstTrue(T lo, T hi, U f) {
while (lo < hi) {
T mid = (lo + hi + 1) / 2;
f(mid) ? lo = mid : hi = mid - 1;
}
return lo;
}
const int di[4] = {-1, 0, 1, 0}, dj[4] = {0, 1, 0, -1};
const int di8[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
dj8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MOD = 1e9 + 7; // const int MOD =998244353;
const ld PI = acos((ld)-1);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(rng); }
bool pow2(int i) { return i && (i & -i) == i; }
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
tcT > bool chmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
tcT > bool chmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
tcT > void remDup(vector<T> &v) {
sort(all(v));
v.erase(unique(all(v)), end(v));
}
tcTU > void remAll(vector<T> &v, U a) { v.erase(remove(all(v), a), v.end()); }
// TO_STRING
tcTU3 > string ts(tuple<T, U, C> p);
tcTU4 > string ts(tuple<T, U, C, D> p);
string ts(char c) { return string(1, c); }
string ts(bool b) {
#ifdef __APPLE__
return b ? "true" : "false";
#else
return ts((int)b);
#endif
}
string ts(const char *s) { return (string)s; }
string ts(string s) { return s; }
tcT > string ts(complex<T> c) {
stringstream ss;
ss << c;
return ss.str();
}
string ts(vb v) {
string res = "{";
F0R(i, sz(v)) res += char('0' + v[i]);
res += "}";
return res;
}
template <size_t SZ> string ts(bitset<SZ> b) {
string res = "";
F0R(i, sz(b)) res += char('0' + b[i]);
return res;
}
tcTU > string ts(pair<T, U> p);
tcT > string ts(T v) { // containers with begin(), end()
#ifdef __APPLE__
bool fst = 1;
string res = "{";
for (const auto &x : v) {
if (!fst)
res += ", ";
fst = 0;
res += ts(x);
}
res += "}";
return res;
#else
bool fst = 1;
string res = "";
for (const auto &x : v) {
if (!fst)
res += " ";
fst = 0;
res += ts(x);
}
return res;
#endif
}
tcTU > string ts(pair<T, U> p) {
#ifdef __APPLE__
return "(" + ts(p.fe) + ", " + ts(p.se) + ")";
#else
return ts(p.fe) + " " + ts(p.se);
#endif
}
tcTU3 > string ts(tuple<T, U, C> p) {
#ifdef __APPLE__
return "(" + ts(get<0>(p)) + "," + ts(get<1>(p)) + "," + ts(get<2>(p)) + ")";
#else
return ts(get<0>(p)) + " " + ts(get<1>(p)) + " " + ts(get<2>(p));
#endif
}
tcTU4 > string ts(tuple<T, U, C, D> p) {
#ifdef __APPLE__
return "(" + ts(get<0>(p)) + "," + ts(get<1>(p)) + "," + ts(get<2>(p)) + "," +
ts(get<3>(p)) + ")";
#else
return ts(get<0>(p)) + " " + ts(get<1>(p)) + " " + ts(get<2>(p)) + " " +
ts(get<3>(p));
#endif
}
// INPUT void re(string& d){getline(cin,d) ;getline(cin,d); }
tcTU3 > void re(tuple<T, U, C> &p);
tcTU4 > void re(tuple<T, U, C, D> &p);
tcT > void re(complex<T> &c);
tcTU > void re(pair<T, U> &p);
tcT > void re(vector<T> &v);
tcT, size_t SZ > void re(AR<T, SZ> &a);
tcT > void re(T &x) { cin >> x; }
void re(double &d) {
string t;
re(t);
d = stod(t);
}
void re(ld &d) {
string t;
re(t);
d = stold(t);
}
tcTUU > void re(T &t, U &...u) {
re(t);
re(u...);
}
tcT > void re(complex<T> &c) {
T a, b;
re(a, b);
c = {a, b};
}
tcTU > void re(pair<T, U> &p) { re(p.fe, p.se); }
tcT > void re(vector<T> &x) { trav(a, x) re(a); }
tcT, size_t SZ > void re(array<T, SZ> &x) { trav(a, x) re(a); }
tcTU3 > void re(tuple<T, U, C> &p) { re(get<0>(p), get<1>(p), get<2>(p)); }
tcTU4 > void re(tuple<T, U, C, D> &p) {
re(get<0>(p), get<1>(p), get<2>(p), get<3>(p));
}
// OUTPUT
tcT > void pr(T x) { cout << ts(x); }
tcTUU > void pr(const T &t, const U &...u) {
pr(t);
pr(u...);
}
void ps() { pr("\n"); } // print w/ spaces
tcTUU > void ps(const T &t, const U &...u) {
pr(t);
if (sizeof...(u))
pr(" ");
ps(u...);
}
// DEBUG
void DBG() { cerr << "]" << endl; }
tcTUU > void DBG(const T &t, const U &...u) {
cerr << ts(t);
if (sizeof...(u))
cerr << ", ";
DBG(u...);
}
#ifdef __APPLE__ // chk -> fake assert
#define dbg(...) \
cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \
DBG(__VA_ARGS__)
#define chk(...) \
if (!(__VA_ARGS__)) \
cerr << "Line(" << __LINE__ << ") -> function(" << __FUNCTION__ \
<< ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" \
<< "\n", \
exit(0);
#else
#define dbg(...) 0
#define chk(...) 0
#endif
template <int MOD, int RT> struct mint {
static const int mod = MOD;
static constexpr mint rt() { return RT; } // primitive root for FFT
int v;
explicit operator int() const {
return v;
} // explicit -> don't silently convert to int
mint() { v = 0; }
mint(ll _v) {
v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
if (v < 0)
v += MOD;
}
friend bool operator==(const mint &a, const mint &b) { return a.v == b.v; }
friend bool operator!=(const mint &a, const mint &b) { return !(a == b); }
friend bool operator<(const mint &a, const mint &b) { return a.v < b.v; }
friend void re(mint &a) {
ll x;
re(x);
a = mint(x);
}
friend string ts(mint a) { return ts(a.v); }
mint &operator+=(const mint &m) {
if ((v += m.v) >= MOD)
v -= MOD;
return *this;
}
mint &operator-=(const mint &m) {
if ((v -= m.v) < 0)
v += MOD;
return *this;
}
mint &operator*=(const mint &m) {
v = (ll)v * m.v % MOD;
return *this;
}
mint &operator/=(const mint &m) { return (*this) *= inv(m); }
friend mint pow(mint a, ll p) {
mint ans = 1;
assert(p >= 0);
for (; p; p /= 2, a *= a)
if (p & 1)
ans *= a;
return ans;
}
friend mint inv(const mint &a) {
assert(a.v != 0);
return pow(a, MOD - 2);
}
mint operator-() const { return mint(-v); }
mint &operator++() { return *this += 1; }
mint &operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint &b) { return a += b; }
friend mint operator-(mint a, const mint &b) { return a -= b; }
friend mint operator*(mint a, const mint &b) { return a *= b; }
friend mint operator/(mint a, const mint &b) { return a /= b; }
};
typedef mint<MOD, 5> mi; // 5 is primitive root for both common mods
typedef vector<mi> vmi;
typedef pair<mi, mi> pmi;
typedef vector<pmi> vpmi;
vector<vmi> scmb; // small combinations
void genComb(int SZ) {
scmb.assign(SZ, vmi(SZ));
scmb[0][0] = 1;
FOR(i, 1, SZ)
F0R(j, i + 1) scmb[i][j] = scmb[i - 1][j] + (j ? scmb[i - 1][j - 1] : 0);
}
vi invs, fac, ifac;
void genFac(int SZ) { // pre-compute factorial mod inverses
invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ);
invs[1] = fac[0] = ifac[0] = 1;
FOR(i, 2, SZ) invs[i] = MOD - (ll)MOD / i * invs[MOD % i] % MOD;
FOR(i, 1, SZ) {
fac[i] = (ll)fac[i - 1] * i % MOD;
ifac[i] = (ll)ifac[i - 1] * invs[i] % MOD;
}
}
ll comb(int a, int b) {
if (a < b || b < 0)
return 0;
return (ll)fac[a] * ifac[b] % MOD * ifac[a - b] % MOD;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void IOS(int n = 10, string s = "") {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.precision(n);
cerr.precision(n);
cerr << fixed;
cout << fixed;
if (sz(s)) {
setIn(s + ".in"), setOut(s + ".out");
}
}
const int mxN = 1e5;
void solve() {
int n;
re(n);
vmi a(n);
re(a);
mi ans = 0;
F0R(i, n) {
FOR(j, i + 1, n) { ans += (a[i] * a[j]); }
}
ps(ans);
}
int main() {
IOS();
int t = 1; // re(t);
F0R(i, t) {
// pr("Case #",i+1,": ");
solve();
}
#ifdef __APPLE__
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
| #pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<double, double>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define tcT template <class T
#define tcTUU tcT, class... U
#define tcTU tcT, class U
#define tcTU3 tcTU, class C
#define tcTU4 tcTU3, class D
tcT > using V = vector<T>;
tcT, size_t SZ > using AR = array<T, SZ>;
tcT > using mpq = priority_queue<T, vector<T>, greater<T>>;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
tcT> using oset = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>; #define fbo find_by_order #define ook
order_of_key tcTU> using ht = gp_hash_table<T,U,chash>;*/
struct chash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
tcTU > using um = unordered_map<T, U, chash>;
#define cbit(n, b) (((n) >> (b)) & 1)
#define sbit(n, b) ((n) | (1ULL << (b)))
#define rbit(n, b) ((n) & ~(1ULL << (b)))
#define fbit(n, b) ((n) ^ (1ULL << (b)))
#define ts to_string
#define fe first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(v) ((int)(v).size())
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define trav(a, x) for (auto &a : x)
tcTU > T fstTrue(T lo, T hi, U f) {
while (lo < hi) {
T mid = (lo + hi) / 2;
f(mid) ? hi = mid : lo = mid + 1;
}
return lo;
}
tcTU > T lstTrue(T lo, T hi, U f) {
while (lo < hi) {
T mid = (lo + hi + 1) / 2;
f(mid) ? lo = mid : hi = mid - 1;
}
return lo;
}
const int di[4] = {-1, 0, 1, 0}, dj[4] = {0, 1, 0, -1};
const int di8[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
dj8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MOD = 1e9 + 7; // const int MOD =998244353;
const ld PI = acos((ld)-1);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(rng); }
bool pow2(int i) { return i && (i & -i) == i; }
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
tcT > bool chmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
tcT > bool chmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
tcT > void remDup(vector<T> &v) {
sort(all(v));
v.erase(unique(all(v)), end(v));
}
tcTU > void remAll(vector<T> &v, U a) { v.erase(remove(all(v), a), v.end()); }
// TO_STRING
tcTU3 > string ts(tuple<T, U, C> p);
tcTU4 > string ts(tuple<T, U, C, D> p);
string ts(char c) { return string(1, c); }
string ts(bool b) {
#ifdef __APPLE__
return b ? "true" : "false";
#else
return ts((int)b);
#endif
}
string ts(const char *s) { return (string)s; }
string ts(string s) { return s; }
tcT > string ts(complex<T> c) {
stringstream ss;
ss << c;
return ss.str();
}
string ts(vb v) {
string res = "{";
F0R(i, sz(v)) res += char('0' + v[i]);
res += "}";
return res;
}
template <size_t SZ> string ts(bitset<SZ> b) {
string res = "";
F0R(i, sz(b)) res += char('0' + b[i]);
return res;
}
tcTU > string ts(pair<T, U> p);
tcT > string ts(T v) { // containers with begin(), end()
#ifdef __APPLE__
bool fst = 1;
string res = "{";
for (const auto &x : v) {
if (!fst)
res += ", ";
fst = 0;
res += ts(x);
}
res += "}";
return res;
#else
bool fst = 1;
string res = "";
for (const auto &x : v) {
if (!fst)
res += " ";
fst = 0;
res += ts(x);
}
return res;
#endif
}
tcTU > string ts(pair<T, U> p) {
#ifdef __APPLE__
return "(" + ts(p.fe) + ", " + ts(p.se) + ")";
#else
return ts(p.fe) + " " + ts(p.se);
#endif
}
tcTU3 > string ts(tuple<T, U, C> p) {
#ifdef __APPLE__
return "(" + ts(get<0>(p)) + "," + ts(get<1>(p)) + "," + ts(get<2>(p)) + ")";
#else
return ts(get<0>(p)) + " " + ts(get<1>(p)) + " " + ts(get<2>(p));
#endif
}
tcTU4 > string ts(tuple<T, U, C, D> p) {
#ifdef __APPLE__
return "(" + ts(get<0>(p)) + "," + ts(get<1>(p)) + "," + ts(get<2>(p)) + "," +
ts(get<3>(p)) + ")";
#else
return ts(get<0>(p)) + " " + ts(get<1>(p)) + " " + ts(get<2>(p)) + " " +
ts(get<3>(p));
#endif
}
// INPUT void re(string& d){getline(cin,d) ;getline(cin,d); }
tcTU3 > void re(tuple<T, U, C> &p);
tcTU4 > void re(tuple<T, U, C, D> &p);
tcT > void re(complex<T> &c);
tcTU > void re(pair<T, U> &p);
tcT > void re(vector<T> &v);
tcT, size_t SZ > void re(AR<T, SZ> &a);
tcT > void re(T &x) { cin >> x; }
void re(double &d) {
string t;
re(t);
d = stod(t);
}
void re(ld &d) {
string t;
re(t);
d = stold(t);
}
tcTUU > void re(T &t, U &...u) {
re(t);
re(u...);
}
tcT > void re(complex<T> &c) {
T a, b;
re(a, b);
c = {a, b};
}
tcTU > void re(pair<T, U> &p) { re(p.fe, p.se); }
tcT > void re(vector<T> &x) { trav(a, x) re(a); }
tcT, size_t SZ > void re(array<T, SZ> &x) { trav(a, x) re(a); }
tcTU3 > void re(tuple<T, U, C> &p) { re(get<0>(p), get<1>(p), get<2>(p)); }
tcTU4 > void re(tuple<T, U, C, D> &p) {
re(get<0>(p), get<1>(p), get<2>(p), get<3>(p));
}
// OUTPUT
tcT > void pr(T x) { cout << ts(x); }
tcTUU > void pr(const T &t, const U &...u) {
pr(t);
pr(u...);
}
void ps() { pr("\n"); } // print w/ spaces
tcTUU > void ps(const T &t, const U &...u) {
pr(t);
if (sizeof...(u))
pr(" ");
ps(u...);
}
// DEBUG
void DBG() { cerr << "]" << endl; }
tcTUU > void DBG(const T &t, const U &...u) {
cerr << ts(t);
if (sizeof...(u))
cerr << ", ";
DBG(u...);
}
#ifdef __APPLE__ // chk -> fake assert
#define dbg(...) \
cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \
DBG(__VA_ARGS__)
#define chk(...) \
if (!(__VA_ARGS__)) \
cerr << "Line(" << __LINE__ << ") -> function(" << __FUNCTION__ \
<< ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" \
<< "\n", \
exit(0);
#else
#define dbg(...) 0
#define chk(...) 0
#endif
template <int MOD, int RT> struct mint {
static const int mod = MOD;
static constexpr mint rt() { return RT; } // primitive root for FFT
int v;
explicit operator int() const {
return v;
} // explicit -> don't silently convert to int
mint() { v = 0; }
mint(ll _v) {
v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
if (v < 0)
v += MOD;
}
friend bool operator==(const mint &a, const mint &b) { return a.v == b.v; }
friend bool operator!=(const mint &a, const mint &b) { return !(a == b); }
friend bool operator<(const mint &a, const mint &b) { return a.v < b.v; }
friend void re(mint &a) {
ll x;
re(x);
a = mint(x);
}
friend string ts(mint a) { return ts(a.v); }
mint &operator+=(const mint &m) {
if ((v += m.v) >= MOD)
v -= MOD;
return *this;
}
mint &operator-=(const mint &m) {
if ((v -= m.v) < 0)
v += MOD;
return *this;
}
mint &operator*=(const mint &m) {
v = (ll)v * m.v % MOD;
return *this;
}
mint &operator/=(const mint &m) { return (*this) *= inv(m); }
friend mint pow(mint a, ll p) {
mint ans = 1;
assert(p >= 0);
for (; p; p /= 2, a *= a)
if (p & 1)
ans *= a;
return ans;
}
friend mint inv(const mint &a) {
assert(a.v != 0);
return pow(a, MOD - 2);
}
mint operator-() const { return mint(-v); }
mint &operator++() { return *this += 1; }
mint &operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint &b) { return a += b; }
friend mint operator-(mint a, const mint &b) { return a -= b; }
friend mint operator*(mint a, const mint &b) { return a *= b; }
friend mint operator/(mint a, const mint &b) { return a /= b; }
};
typedef mint<MOD, 5> mi; // 5 is primitive root for both common mods
typedef vector<mi> vmi;
typedef pair<mi, mi> pmi;
typedef vector<pmi> vpmi;
vector<vmi> scmb; // small combinations
void genComb(int SZ) {
scmb.assign(SZ, vmi(SZ));
scmb[0][0] = 1;
FOR(i, 1, SZ)
F0R(j, i + 1) scmb[i][j] = scmb[i - 1][j] + (j ? scmb[i - 1][j - 1] : 0);
}
vi invs, fac, ifac;
void genFac(int SZ) { // pre-compute factorial mod inverses
invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ);
invs[1] = fac[0] = ifac[0] = 1;
FOR(i, 2, SZ) invs[i] = MOD - (ll)MOD / i * invs[MOD % i] % MOD;
FOR(i, 1, SZ) {
fac[i] = (ll)fac[i - 1] * i % MOD;
ifac[i] = (ll)ifac[i - 1] * invs[i] % MOD;
}
}
ll comb(int a, int b) {
if (a < b || b < 0)
return 0;
return (ll)fac[a] * ifac[b] % MOD * ifac[a - b] % MOD;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void IOS(int n = 10, string s = "") {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.precision(n);
cerr.precision(n);
cerr << fixed;
cout << fixed;
if (sz(s)) {
setIn(s + ".in"), setOut(s + ".out");
}
}
const int mxN = 1e5;
void solve() {
int n;
re(n);
vmi a(n);
re(a);
mi ans = 0, s = 0;
trav(i, a) s += i;
trav(i, a) {
s -= i;
ans += i * s;
}
ps(ans);
}
int main() {
IOS();
int t = 1; // re(t);
F0R(i, t) {
// pr("Case #",i+1,": ");
solve();
}
#ifdef __APPLE__
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
| replace | 381 | 384 | 381 | 386 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
inline long long qr() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline long long mul(long long x, long long y) {
int ans = 0;
while (y) {
if (y & 1)
ans = (ans + x) % mod;
y >>= 1;
x = (x + x) % mod;
}
}
int n;
const int maxn = 2e5 + 10;
long long a[maxn];
long long b[maxn];
long long ans;
int main() {
n = qr();
for (register int i = 1; i <= n; i++) {
a[i] = qr();
b[i] = (b[i] + b[i - 1] + a[i]);
}
for (register int i = 1; i < n; i++) {
ans = (ans + mul(a[i], b[n] - b[i]) % mod) % mod;
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
inline long long qr() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline long long mul(long long x, long long y) {
int ans = 0;
while (y) {
if (y & 1)
ans = (ans + x) % mod;
y >>= 1;
x = (x + x) % mod;
}
return ans;
}
int n;
const int maxn = 2e5 + 10;
long long a[maxn];
long long b[maxn];
long long ans;
int main() {
n = qr();
for (register int i = 1; i <= n; i++) {
a[i] = qr();
b[i] = (b[i] + b[i - 1] + a[i]);
}
for (register int i = 1; i < n; i++) {
ans = (ans + mul(a[i], b[n] - b[i]) % mod) % mod;
}
cout << ans;
return 0;
}
| insert | 25 | 25 | 25 | 26 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define GO \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long int
const int maxr = 1e5 + 5;
int arr[maxr], prefix[maxr];
const int M = 1e9 + 7;
int32_t main() {
GO;
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
prefix[0] = arr[0];
for (int i = 1; i < n; i++) {
prefix[i] = arr[i] + prefix[i - 1];
prefix[i] %= M;
}
int ans = 0;
for (int i = n - 2; i >= 0; i--) {
ans += (prefix[i] * arr[i + 1]);
ans %= M;
}
cout << ans << endl;
return 0;
}
//! | #include <bits/stdc++.h>
using namespace std;
#define GO \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long int
const int maxr = 2e5 + 5;
int arr[maxr], prefix[maxr];
const int M = 1e9 + 7;
int32_t main() {
GO;
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
prefix[0] = arr[0];
for (int i = 1; i < n; i++) {
prefix[i] = arr[i] + prefix[i - 1];
prefix[i] %= M;
}
int ans = 0;
for (int i = n - 2; i >= 0; i--) {
ans += (prefix[i] * arr[i + 1]);
ans %= M;
}
cout << ans << endl;
return 0;
}
//! | replace | 9 | 10 | 9 | 10 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int64_t> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int64_t sum = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
sum += (vec.at(i) * vec.at(j)) % 1000000007;
sum = sum % 1000000007;
}
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int64_t> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int64_t sum = 0;
int64_t ksum = 0;
for (int i = 1; i < N; i++) {
ksum += vec.at(i);
ksum = ksum % 1000000007;
}
for (int i = 0; i < N - 1; i++) {
sum += (vec.at(i) * ksum) % 1000000007;
sum = sum % 1000000007;
ksum -= vec.at(i + 1);
if (ksum < 0)
ksum += 1000000007;
}
cout << sum << endl;
} | replace | 11 | 16 | 11 | 23 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
using ll = long long;
int addm(int a, int b) { return ((ll)a + b) % MOD; }
int mulm(int a, int b) { return ((ll)a * b) % MOD; }
int main() {
int n;
vector<int> arr(n), pref(n);
for (auto &x : arr)
cin >> x;
pref[0] = arr[0];
for (int i = 1; i < n; i++) {
pref[i] = addm(pref[i - 1], arr[i]);
}
int sum = 0;
for (int i = 1; i < n; i++) {
sum = addm(sum, mulm(pref[i - 1], arr[i]));
}
cout << sum;
} | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
using ll = long long;
int addm(int a, int b) { return ((ll)a + b) % MOD; }
int mulm(int a, int b) { return ((ll)a * b) % MOD; }
int main() {
int n;
cin >> n;
vector<int> arr(n), pref(n);
for (auto &x : arr)
cin >> x;
pref[0] = arr[0];
for (int i = 1; i < n; i++) {
pref[i] = addm(pref[i - 1], arr[i]);
}
int sum = 0;
for (int i = 1; i < n; i++) {
sum = addm(sum, mulm(pref[i - 1], arr[i]));
}
cout << sum;
}
| insert | 14 | 14 | 14 | 15 | -11 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int n, a[100005], bc[100005], ans = 0;
signed main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = n; i >= 1; i--)
bc[i] = a[i] + bc[i + 1], bc[i] %= mod;
for (int i = 1; i <= n; i++) {
ans += (a[i] * bc[i + 1]);
ans %= mod;
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int n, a[200005], bc[200005], ans = 0;
signed main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = n; i >= 1; i--)
bc[i] = a[i] + bc[i + 1], bc[i] %= mod;
for (int i = 1; i <= n; i++) {
ans += (a[i] * bc[i + 1]);
ans %= mod;
}
cout << ans;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
// long long
using ll = long long;
// pair<int, int>
using PII = pair<int, int>;
// 最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
// 出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(20) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
// 配列入力
vector<long long> vecin(ll n) {
vector<long long> res(n);
for (int i = 0; i < n; i++)
cin >> res[i];
return res;
}
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
// a = max(a, b), a = min(a, b)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// num ^ pow(mod取る)
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1)
prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 重みつきUnionFInd
template <class Abel> struct GUnionFind {
vector<int> par;
vector<int> rank;
vector<Abel> diff_weight;
GUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }
void init(int n = 1, Abel SUM_UNITY = 0) {
par.resize(n);
rank.resize(n);
diff_weight.resize(n);
for (int i = 0; i < n; ++i)
par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
Abel weight(int x) {
root(x);
return diff_weight[x];
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y, Abel w) {
w += weight(x);
w -= weight(y);
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y), w = -w;
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
diff_weight[y] = w;
return true;
}
Abel diff(int x, int y) { return weight(y) - weight(x); }
};
// UnionFind
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n + 1);
rank.resize(n + 1);
Size.resize(n + 1);
for (int i = 0; i <= n; ++i)
par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x) { return Size[root(x)]; }
};
// modint構造体
struct Mint {
int val;
Mint inv() const {
int tmp, a = val, b = mod, x = 1, y = 0;
while (b)
tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
return Mint(x);
}
public:
Mint() : val(0) {}
Mint(ll x) {
if ((val = x % mod) < 0)
val += mod;
}
Mint pow(ll t) {
Mint res = 1, b = *this;
while (t) {
if (t & 1)
res *= b;
b *= b;
t >>= 1;
}
return res;
}
Mint &operator+=(const Mint &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator-=(const Mint &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator*=(const Mint &x) {
val = (ll)val * x.val % mod;
return *this;
}
Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
bool operator==(const Mint &x) const { return val == x.val; }
bool operator!=(const Mint &x) const { return val != x.val; }
bool operator<(const Mint &x) const { return val < x.val; }
bool operator<=(const Mint &x) const { return val <= x.val; }
bool operator>(const Mint &x) const { return val > x.val; }
bool operator>=(const Mint &x) const { return val >= x.val; }
Mint operator+(const Mint &x) const { return Mint(*this) += x; }
Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
vector<Mint> Fact, Finv;
public:
// factorial fact(10000010);
// fact.nCr(a, b)
// 「fact」の部分は自由に名前変更可能
factorial(int maxx) {
Fact.resize(maxx + 1), Finv.resize(maxx + 1);
Fact[0] = Mint(1);
rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
Finv[maxx] = Mint(1) / Fact[maxx];
rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
}
Mint fact(int n, bool inv = 0) {
if (inv)
return Finv[n];
else
return Fact[n];
}
Mint nPr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[n - r];
}
Mint nCr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[r] * Finv[n - r];
}
};
// 1 * 2 * 3 .... * n (mod)
ll modfact(ll n) {
if (n <= 1)
return 1;
return (n * modfact(n - 1)) % MOD;
}
// kが角度だった場合:cos(k * (PI / 180));
// const double PI = acos(-1);のまま使うと円周率(M_PIもあるよ)
const double PI = acos(-1);
// 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5);
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
// 素因数分解
vector<pair<long long, int>> factorize(long long n) {
vector<pair<long long, int>> res;
for (long long i = 2; i * i <= n; ++i) {
if (n % i)
continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.emplace_back(n, 1);
return res;
}
// 素数判定
bool primejudge(long long a) {
if (a <= 1)
return false;
for (long long i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
// 累積和
// vector<long long>sums(vector<int>n){
// vector<long long>res(n.size() + 1, 0);
// for(int i = 0; i < n.size(); i++) res[i + 1] = n[i] + res[i];
// return res;
// }
int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
vector<vector<int>> graph;
int main() {
int n;
cin >> n;
vector<ll> a(n);
REP(i, n) cin >> a[i];
Mint ans = 0;
REP(i, n) {
REP(j, i) { ans += a[i] * a[j]; }
}
print(ans.val);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// long long
using ll = long long;
// pair<int, int>
using PII = pair<int, int>;
// 最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
// 出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(20) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
// 配列入力
vector<long long> vecin(ll n) {
vector<long long> res(n);
for (int i = 0; i < n; i++)
cin >> res[i];
return res;
}
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
// a = max(a, b), a = min(a, b)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// num ^ pow(mod取る)
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1)
prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 重みつきUnionFInd
template <class Abel> struct GUnionFind {
vector<int> par;
vector<int> rank;
vector<Abel> diff_weight;
GUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }
void init(int n = 1, Abel SUM_UNITY = 0) {
par.resize(n);
rank.resize(n);
diff_weight.resize(n);
for (int i = 0; i < n; ++i)
par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
Abel weight(int x) {
root(x);
return diff_weight[x];
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y, Abel w) {
w += weight(x);
w -= weight(y);
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y), w = -w;
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
diff_weight[y] = w;
return true;
}
Abel diff(int x, int y) { return weight(y) - weight(x); }
};
// UnionFind
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n + 1);
rank.resize(n + 1);
Size.resize(n + 1);
for (int i = 0; i <= n; ++i)
par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x) { return Size[root(x)]; }
};
// modint構造体
struct Mint {
int val;
Mint inv() const {
int tmp, a = val, b = mod, x = 1, y = 0;
while (b)
tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
return Mint(x);
}
public:
Mint() : val(0) {}
Mint(ll x) {
if ((val = x % mod) < 0)
val += mod;
}
Mint pow(ll t) {
Mint res = 1, b = *this;
while (t) {
if (t & 1)
res *= b;
b *= b;
t >>= 1;
}
return res;
}
Mint &operator+=(const Mint &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator-=(const Mint &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator*=(const Mint &x) {
val = (ll)val * x.val % mod;
return *this;
}
Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
bool operator==(const Mint &x) const { return val == x.val; }
bool operator!=(const Mint &x) const { return val != x.val; }
bool operator<(const Mint &x) const { return val < x.val; }
bool operator<=(const Mint &x) const { return val <= x.val; }
bool operator>(const Mint &x) const { return val > x.val; }
bool operator>=(const Mint &x) const { return val >= x.val; }
Mint operator+(const Mint &x) const { return Mint(*this) += x; }
Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
vector<Mint> Fact, Finv;
public:
// factorial fact(10000010);
// fact.nCr(a, b)
// 「fact」の部分は自由に名前変更可能
factorial(int maxx) {
Fact.resize(maxx + 1), Finv.resize(maxx + 1);
Fact[0] = Mint(1);
rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
Finv[maxx] = Mint(1) / Fact[maxx];
rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
}
Mint fact(int n, bool inv = 0) {
if (inv)
return Finv[n];
else
return Fact[n];
}
Mint nPr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[n - r];
}
Mint nCr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[r] * Finv[n - r];
}
};
// 1 * 2 * 3 .... * n (mod)
ll modfact(ll n) {
if (n <= 1)
return 1;
return (n * modfact(n - 1)) % MOD;
}
// kが角度だった場合:cos(k * (PI / 180));
// const double PI = acos(-1);のまま使うと円周率(M_PIもあるよ)
const double PI = acos(-1);
// 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5);
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
// 素因数分解
vector<pair<long long, int>> factorize(long long n) {
vector<pair<long long, int>> res;
for (long long i = 2; i * i <= n; ++i) {
if (n % i)
continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.emplace_back(n, 1);
return res;
}
// 素数判定
bool primejudge(long long a) {
if (a <= 1)
return false;
for (long long i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
// 累積和
// vector<long long>sums(vector<int>n){
// vector<long long>res(n.size() + 1, 0);
// for(int i = 0; i < n.size(); i++) res[i + 1] = n[i] + res[i];
// return res;
// }
int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
vector<vector<int>> graph;
int main() {
int n;
cin >> n;
ll sum = 0;
ll ans = 0;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
ans += x * sum % MOD;
ans %= MOD;
sum += x;
sum %= MOD;
}
cout << ans << endl;
return 0;
}
| replace | 342 | 349 | 342 | 353 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);
void Main() {
ll N;
cin >> N;
vll A(N);
rep(i, N) cin >> A[i];
ll MOD = 1e9 + 7;
ll sum = 0;
rep(i, N) rep(j, i) {
sum += (A[i] * A[j]) % MOD;
sum %= MOD;
}
cout << sum << endl;
}
int main(int argc, char const *argv[]) {
Main();
return 0;
}
void yesno(bool state) {
if (state)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);
void Main() {
ll N;
cin >> N;
vll A(N);
rep(i, N) cin >> A[i];
ll MOD = 1e9 + 7;
ll sum = 0;
ll memo = 0;
rep(i, N - 1) {
memo += A[i];
memo %= MOD;
sum += (memo * A[i + 1]) % MOD;
sum %= MOD;
}
cout << sum << endl;
}
int main(int argc, char const *argv[]) {
Main();
return 0;
}
void yesno(bool state) {
if (state)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | replace | 20 | 22 | 20 | 25 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = (1e9 + 7) * 2;
ll a[100005];
int main(int argc, char *argv[]) {
int n;
ll sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans += ((sum - a[i]) % mod) * a[i];
ans %= mod;
}
cout << ans / 2 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = (1e9 + 7) * 2;
ll a[200005];
int main(int argc, char *argv[]) {
int n;
ll sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans += ((sum - a[i]) % mod) * a[i];
ans %= mod;
}
cout << ans / 2 << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define nl '\n'
using namespace std;
typedef long long ll;
void solve() {
int N;
cin >> N;
int A[N];
for (int &i : A)
cin >> i;
ll ans = 0;
const int mod = 1e9 + 7;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
ans += (1ll * A[i] * A[j]) % mod;
if (ans >= mod)
ans -= mod;
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// int t;
// cin >> t;
// while (t--) {
solve();
// cout << nl;
// }
return 0;
} | #include <bits/stdc++.h>
#define nl '\n'
using namespace std;
typedef long long ll;
void solve() {
int N;
cin >> N;
int A[N];
for (int &i : A)
cin >> i;
ll ans = 0;
const int mod = 1e9 + 7;
int suff[N] = {0};
suff[N - 1] = A[N - 1];
for (int i = N - 2; i >= 0; i--)
suff[i] = (A[i] + suff[i + 1]) % mod;
for (int i = 0; i < N - 1; i++)
ans = (ans + (1ll * A[i] * suff[i + 1]) % mod) % mod;
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// int t;
// cin >> t;
// while (t--) {
solve();
// cout << nl;
// }
return 0;
} | replace | 17 | 24 | 17 | 23 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <string>
using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1e18;
#define PI 3.141592653589793
#define REP(i, n) for (long long i = 0; i < n; i++)
int main() {
long long N;
long long A[100000];
long long sum = 0;
long long ans = 0;
cin >> N;
REP(i, N) {
cin >> A[i];
sum += A[i];
}
// cout<<ans<<endl;
for (int i = 0; i < N; i++) {
sum -= A[i];
ans = (A[i] * (sum % mod) + ans) % mod;
// cout<<ans<<endl;
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
#include <string>
using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1e18;
#define PI 3.141592653589793
#define REP(i, n) for (long long i = 0; i < n; i++)
int main() {
long long N;
int A[300000];
long long sum = 0;
long long ans = 0;
cin >> N;
REP(i, N) {
cin >> A[i];
sum += A[i];
}
// cout<<ans<<endl;
for (int i = 0; i < N; i++) {
sum -= A[i];
ans = (A[i] * (sum % mod) + ans) % mod;
// cout<<ans<<endl;
}
cout << ans;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02572 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl
const int MOD = 1000000007;
int n;
int main() {
cin >> n;
vector<ll> a(n), b(n + 1, 0);
rep(i, 0, n) cin >> a[i];
rep(i, 0, n + 1) b[i + 1] = b[i] + a[i];
ll ans = 0;
rep(i, 0, n) {
ll t = b[n] - b[i + 1];
t %= MOD;
ans += a[i] * t;
ans %= MOD;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl
const int MOD = 1000000007;
int n;
int main() {
cin >> n;
vector<ll> a(n), b(n + 1, 0);
rep(i, 0, n) cin >> a[i];
rep(i, 0, n) b[i + 1] = b[i] + a[i];
ll ans = 0;
rep(i, 0, n) {
ll t = b[n] - b[i + 1];
t %= MOD;
ans += a[i] * t;
ans %= MOD;
}
cout << ans << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p02572 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
#define N 100010
#define M 1010
using namespace std;
const int mod = 1e9 + 7;
int sum[N], a[N], n;
int read() {
int s = 0, f = 0;
char ch = getchar();
while (!isdigit(ch))
f |= (ch == '-'), ch = getchar();
while (isdigit(ch))
s = s * 10 + (ch ^ 48), ch = getchar();
return f ? -s : s;
}
signed main() {
n = read();
for (int i = 1; i <= n; i++)
a[i] = read(), sum[i] = (sum[i - 1] + a[i]) % mod;
int ans = 0;
for (int i = 1; i <= n - 1; i++) {
int xx = (sum[n] - sum[i] + mod) % mod;
ans = (ans + (a[i] * xx) % mod) % mod;
}
cout << ans << "\n";
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
#define N 200010
#define M 1010
using namespace std;
const int mod = 1e9 + 7;
int sum[N], a[N], n;
int read() {
int s = 0, f = 0;
char ch = getchar();
while (!isdigit(ch))
f |= (ch == '-'), ch = getchar();
while (isdigit(ch))
s = s * 10 + (ch ^ 48), ch = getchar();
return f ? -s : s;
}
signed main() {
n = read();
for (int i = 1; i <= n; i++)
a[i] = read(), sum[i] = (sum[i - 1] + a[i]) % mod;
int ans = 0;
for (int i = 1; i <= n - 1; i++) {
int xx = (sum[n] - sum[i] + mod) % mod;
ans = (ans + (a[i] * xx) % mod) % mod;
}
cout << ans << "\n";
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int a[maxn];
int sum[maxn];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
sum[n + 1] = 0;
for (int i = n; i >= 2; i--) {
sum[i] = (sum[i + 1] + a[i]) % mod;
}
int ans = 0;
for (int i = 1; i <= n - 1; i++) {
// cout<<sum[i+1]<<endl;
ans = (ans + a[i] * sum[i + 1]) % mod;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int a[maxn];
int sum[maxn];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
sum[n + 1] = 0;
for (int i = n; i >= 2; i--) {
sum[i] = (sum[i + 1] + a[i]) % mod;
}
int ans = 0;
for (int i = 1; i <= n - 1; i++) {
// cout<<sum[i+1]<<endl;
ans = (ans + a[i] * sum[i + 1]) % mod;
}
cout << ans << endl;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define _for(i, j, N) for (int i = (j); i < (N); i++)
#define _rep(i, j, N) for (int i = (j); i <= (N); i++)
#define _dec(i, N, j) for (int i = (N - 1); i >= (j); i--)
#define _rec(i, N, j) for (int i = (N); i >= (j); i--)
#define ALL(x) x.begin(), x.end()
#define MEM(a, n) memset(a, n, sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
int get_int() {
int x;
scanf("%d", &x);
return x;
}
LL get_ll() {
LL x;
scanf("%lld", &x);
return x;
}
double get_db() {
double x;
scanf("%lf", &x);
return x;
}
template <typename T> int chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <typename T> int chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
_for(i, 0, v.size()) os << v[i] << " ";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (auto a : v)
os << a << " ";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v) {
os << v.fst << " " << v.scd << " ";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &v) {
for (auto a : v)
cout << a << endl;
return os;
}
static const int dx[8] = {-1, 0, 1, 0, 1, -1, 1, -1};
static const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
const double pi = acos(-1.0);
const double eps = 1e-8;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
template <int mod> struct mint {
int x;
constexpr mint() : x(0) {}
constexpr mint(LL y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
constexpr mint &operator+=(const mint &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
constexpr mint &operator-=(const mint &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
constexpr mint &operator*=(const mint &p) noexcept {
x = (int)(1LL * x * p.x % mod);
return *this;
}
constexpr mint &operator/=(const mint &p) noexcept {
*this *= p.inv();
return *this;
}
constexpr mint operator-() const { return mint(-x); }
constexpr mint operator+(const mint &p) const { return mint(*this) += p; }
constexpr mint operator-(const mint &p) const { return mint(*this) -= p; }
constexpr mint operator*(const mint &p) const { return mint(*this) *= p; }
constexpr mint operator/(const mint &p) const { return mint(*this) /= p; }
constexpr bool operator==(const mint &p) const { return x == p.x; }
constexpr bool operator!=(const mint &p) const { return x != p.x; }
constexpr bool operator<(const mint &p) const { return x < p.x; }
constexpr bool operator>(const mint &p) const { return x > p.x; }
constexpr mint inv() const { return this->power(mod - 2); }
constexpr mint operator^(LL n) const { return mint(this->power(n)); }
constexpr mint &operator^=(LL n) { return *this = *this ^ n; }
constexpr int get_mod() { return mod; }
constexpr mint power(LL n) const {
mint res(1), mul(x);
while (n) {
if (n & 1)
res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
inline mint fac() const {
static std::vector<mint> facs;
int l0 = facs.size();
if (l0 > this->x)
return facs[this->x];
facs.resize(this->x + 1);
for (int i = l0; i <= this->x; i++)
facs[i] = (i == 0 ? mint(1) : facs[i - 1] * mint(i));
return facs[this->x];
}
mint nCr(const mint &r) const {
if (this->x < r.x)
return mint(0);
return this->fac() / ((*this - r).fac() * r.fac());
}
friend constexpr ostream &operator<<(ostream &os, const mint &p) {
return os << p.x;
}
friend constexpr istream &operator>>(istream &is, mint &a) {
LL t = 0;
is >> t;
a = mint<mod>(t);
return (is);
}
};
constexpr LL MOD = 1e9 + 7;
using mi = mint<MOD>;
const int maxn = 1e5 + 5;
mi A[maxn];
int main() {
LL N;
cin >> N;
mi res(0);
mi sum(0);
_for(i, 0, N) {
cin >> A[i];
sum = sum + A[i];
}
_for(i, 0, N) { res = res + (sum - A[i]) * A[i]; }
res = res / 2;
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define _for(i, j, N) for (int i = (j); i < (N); i++)
#define _rep(i, j, N) for (int i = (j); i <= (N); i++)
#define _dec(i, N, j) for (int i = (N - 1); i >= (j); i--)
#define _rec(i, N, j) for (int i = (N); i >= (j); i--)
#define ALL(x) x.begin(), x.end()
#define MEM(a, n) memset(a, n, sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
int get_int() {
int x;
scanf("%d", &x);
return x;
}
LL get_ll() {
LL x;
scanf("%lld", &x);
return x;
}
double get_db() {
double x;
scanf("%lf", &x);
return x;
}
template <typename T> int chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <typename T> int chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
_for(i, 0, v.size()) os << v[i] << " ";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (auto a : v)
os << a << " ";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v) {
os << v.fst << " " << v.scd << " ";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &v) {
for (auto a : v)
cout << a << endl;
return os;
}
static const int dx[8] = {-1, 0, 1, 0, 1, -1, 1, -1};
static const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
const double pi = acos(-1.0);
const double eps = 1e-8;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
template <int mod> struct mint {
int x;
constexpr mint() : x(0) {}
constexpr mint(LL y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
constexpr mint &operator+=(const mint &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
constexpr mint &operator-=(const mint &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
constexpr mint &operator*=(const mint &p) noexcept {
x = (int)(1LL * x * p.x % mod);
return *this;
}
constexpr mint &operator/=(const mint &p) noexcept {
*this *= p.inv();
return *this;
}
constexpr mint operator-() const { return mint(-x); }
constexpr mint operator+(const mint &p) const { return mint(*this) += p; }
constexpr mint operator-(const mint &p) const { return mint(*this) -= p; }
constexpr mint operator*(const mint &p) const { return mint(*this) *= p; }
constexpr mint operator/(const mint &p) const { return mint(*this) /= p; }
constexpr bool operator==(const mint &p) const { return x == p.x; }
constexpr bool operator!=(const mint &p) const { return x != p.x; }
constexpr bool operator<(const mint &p) const { return x < p.x; }
constexpr bool operator>(const mint &p) const { return x > p.x; }
constexpr mint inv() const { return this->power(mod - 2); }
constexpr mint operator^(LL n) const { return mint(this->power(n)); }
constexpr mint &operator^=(LL n) { return *this = *this ^ n; }
constexpr int get_mod() { return mod; }
constexpr mint power(LL n) const {
mint res(1), mul(x);
while (n) {
if (n & 1)
res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
inline mint fac() const {
static std::vector<mint> facs;
int l0 = facs.size();
if (l0 > this->x)
return facs[this->x];
facs.resize(this->x + 1);
for (int i = l0; i <= this->x; i++)
facs[i] = (i == 0 ? mint(1) : facs[i - 1] * mint(i));
return facs[this->x];
}
mint nCr(const mint &r) const {
if (this->x < r.x)
return mint(0);
return this->fac() / ((*this - r).fac() * r.fac());
}
friend constexpr ostream &operator<<(ostream &os, const mint &p) {
return os << p.x;
}
friend constexpr istream &operator>>(istream &is, mint &a) {
LL t = 0;
is >> t;
a = mint<mod>(t);
return (is);
}
};
constexpr LL MOD = 1e9 + 7;
using mi = mint<MOD>;
const int maxn = 2e5 + 5;
mi A[maxn];
int main() {
LL N;
cin >> N;
mi res(0);
mi sum(0);
_for(i, 0, N) {
cin >> A[i];
sum = sum + A[i];
}
_for(i, 0, N) { res = res + (sum - A[i]) * A[i]; }
res = res / 2;
cout << res << endl;
return 0;
}
| replace | 149 | 150 | 149 | 150 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// using namespace __gnu_pbds;
#define fastio() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define fill(a, val) memset(a, val, sizeof(a))
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define endl "\n"
#define int long long
#define printclock \
cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>
const ll mod = 1000 * 1000 * 1000 + 7;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const ll MOD2 = 998244353;
const ll N = 1000 * 1000 + 10;
const ll N2 = 70;
const ld PI = 3.141592653589793;
// template<class T>using onset=tree <T, null_type, less<T>, rb_tree_tag,
// tree_order_statistics_node_update>;
ll gcd(ll a, ll b) {
if (!b)
return a;
return gcd(b, a % b);
}
ll power(ll x, ll y, ll p = LLONG_MAX) {
ll res = 1;
x %= p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
void solve() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
signed main() {
fastio();
// cout<<fixed<<setprecision(20);
ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
ll ans = 0;
for (ll i = 1; i < n; i++) {
for (ll j = 0; j < n; j++) {
if ((j + i) >= n) {
break;
}
// cout<<j<<" "<<(j+i)<<endl;
ans += (a[j] % mod * a[(j + i)] % mod) % mod;
ans %= mod;
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// using namespace __gnu_pbds;
#define fastio() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define fill(a, val) memset(a, val, sizeof(a))
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define endl "\n"
#define int long long
#define printclock \
cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>
const ll mod = 1000 * 1000 * 1000 + 7;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const ll MOD2 = 998244353;
const ll N = 1000 * 1000 + 10;
const ll N2 = 70;
const ld PI = 3.141592653589793;
// template<class T>using onset=tree <T, null_type, less<T>, rb_tree_tag,
// tree_order_statistics_node_update>;
ll gcd(ll a, ll b) {
if (!b)
return a;
return gcd(b, a % b);
}
ll power(ll x, ll y, ll p = LLONG_MAX) {
ll res = 1;
x %= p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
void solve() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
signed main() {
fastio();
// cout<<fixed<<setprecision(20);
ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
ll ans = 0, sum = 0;
for (ll i = 0; i < n; i++) {
sum += a[i];
}
for (ll i = 0; i < n; i++) {
sum -= a[i];
ans = ans % mod + (sum % mod * a[i] % mod) % mod;
}
cout << ans;
return 0;
} | replace | 68 | 78 | 68 | 75 | TLE | |
p02572 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// #include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep2(i, x) for (ll i = 1; i <= x; i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
/*bool IsPrime(ll num) {
if (num < 2) return false;
else if (num == 2) return true;
else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) { // 素数ではない
return false;
}
}
// 素数である
return true;
}*/
/*ll gcd(ll a, ll b) {
if (a < b)swap(a, b);
if (a % b == 0)return b;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}*/
/*ll keta(ll n) {
ll res = 0;
while (n >= 1) {
res += n % 10; n /= 10;
}
return res;
}*/
/*ll modpow(ll x, ll y, ll mod) {
ll res = 1;
while (y) {
if (y % 2) { res *= x; res %= mod; }
x = x * x % mod; y /= 2;
}
return res;
}*/
/*ll nCk(ll n, ll k) {
ll a = 1, b = 1;
for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
return a * modpow(b, mod - 2) % mod;
}*/
// printf("%.10f\n", n);
ll test[123456], rui[123456];
signed main() {
string s, t;
ll n, m, k, a, b, c, cnt = 0, ans = 0;
cin >> n;
rep(i, n) { cin >> test[i]; }
for (int h = n - 1; h >= 0; h--) {
rui[h] = (rui[h + 1] + test[h]) % mod;
}
rep(i, n) {
ans += (rui[i + 1] * test[i]) % mod;
ans %= mod;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// #include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep2(i, x) for (ll i = 1; i <= x; i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
/*bool IsPrime(ll num) {
if (num < 2) return false;
else if (num == 2) return true;
else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) { // 素数ではない
return false;
}
}
// 素数である
return true;
}*/
/*ll gcd(ll a, ll b) {
if (a < b)swap(a, b);
if (a % b == 0)return b;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}*/
/*ll keta(ll n) {
ll res = 0;
while (n >= 1) {
res += n % 10; n /= 10;
}
return res;
}*/
/*ll modpow(ll x, ll y, ll mod) {
ll res = 1;
while (y) {
if (y % 2) { res *= x; res %= mod; }
x = x * x % mod; y /= 2;
}
return res;
}*/
/*ll nCk(ll n, ll k) {
ll a = 1, b = 1;
for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
return a * modpow(b, mod - 2) % mod;
}*/
// printf("%.10f\n", n);
ll test[223456], rui[223456];
signed main() {
string s, t;
ll n, m, k, a, b, c, cnt = 0, ans = 0;
cin >> n;
rep(i, n) { cin >> test[i]; }
for (int h = n - 1; h >= 0; h--) {
rui[h] = (rui[h + 1] + test[h]) % mod;
}
rep(i, n) {
ans += (rui[i + 1] * test[i]) % mod;
ans %= mod;
}
cout << ans << endl;
return 0;
} | replace | 72 | 73 | 72 | 73 | 0 | |
p02572 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define BOUND 27182818284
#define MAT 2
typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;
ll MOD = 1000000007;
const ll INF = (1ll << 60);
const int INFint = (1 << 30);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
template <class T> bool umax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool umin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
// gcd
template <typename T> T gcd(T a, T b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll findGCD(vector<ll> arr) {
ll result = arr[0];
for (auto a : arr) {
result = gcd(a, result);
}
return result;
}
template <typename T> T getlcm(T m, T n) {
// 引数に0がある場合は0を返す
if ((0 == m) || (0 == n))
return 0;
return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
fill((T *)array, (T *)(array + N), val);
}
// v.front() = -BOUND;
// v.back() = BOUND;
// struct edge{
// int cost, to;
//
// edge(int in_cost, int in_to){
// cost=in_cost;
// to=in_to;
// }
// bool operator<(const edge &a) const
// {
// return cost > a.cost;
// }
// };
ll euler_phi(ll n) {
ll ret = n;
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret -= ret / i;
while (n % i == 0)
n /= i;
}
}
if (n > 1)
ret -= ret / n;
return ret;
}
class Combination {
long long powmod(long long a, long long p) {
long long ans = 1LL;
long long mul = a;
while (p > 0) {
if ((p & 1) == 1) {
ans = (ans * mul) % mod;
}
mul = (mul * mul) % mod;
p >>= 1;
}
return ans;
}
public:
int N;
long long mod;
vector<long long> fact;
vector<long long> revfact;
Combination(int n, long long m) : N(n), mod(m), fact(n + 1), revfact(n + 1) {
fact[0] = 1;
for (int i = 1; i <= N; i++) {
fact[i] = fact[i - 1] * i;
fact[i] %= mod;
}
revfact[N] = powmod(fact[N], mod - 2);
for (int i = N - 1; i >= 0; i--) {
revfact[i] = revfact[i + 1] * (i + 1) % mod;
}
}
long long getCombination(int a, int b) {
if (a < 0 || b < 0)
return 0;
if (b > a)
return 0;
return (fact[a] * revfact[b]) % mod * revfact[a - b] % mod;
}
};
struct mint {
const int mod = 1000000007;
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
struct UnionFind {
int n, cnt;
vector<int> par, rank, sz;
UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) {
iota(par.begin(), par.end(), 0);
}
int find(int x) {
if (x == par[x])
return x;
return par[x] = find(par[x]);
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) { return sz[find(x)]; }
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[x] = y;
sz[y] += sz[x];
} else {
par[y] = x;
sz[x] += sz[y];
if (rank[x] == rank[y]) {
rank[x]++;
}
}
cnt--;
}
};
const string Yes = "Yes";
const string YES = "YES";
const string No = "No";
const string NO = "NO";
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
template <typename Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while (a < sz) {
Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C> int find_first(int a, const C &check) {
Monoid L = M1;
if (a <= 0) {
if (check(f(L, seg[1])))
return find_subtree(1, check, L, false);
return -1;
}
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) {
Monoid nxt = f(L, seg[a]);
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C> int find_last(int b, const C &check) {
Monoid R = M1;
if (b >= sz) {
if (check(f(seg[1], R)))
return find_subtree(1, check, R, true);
return -1;
}
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1) {
if (b & 1) {
Monoid nxt = f(seg[--b], R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
template <typename T> vector<T> DIVISOR(T n) {
vector<T> v;
for (T i = 1; i * i <= n; ++i) {
if (n % i == 0) {
v.push_back(i);
if (i != n / i) {
v.push_back(n / i);
}
}
}
sort(v.begin(), v.end());
return v;
}
ll permutation(ll n) {
ll ans = 1LL;
if (n <= 0) {
return ans;
}
for (ll i = 1; i <= n; i++) {
ans *= i;
}
return ans;
}
template <typename T> struct PrimeFact {
vector<T> spf;
PrimeFact(T N) { init(N); }
void init(T N) { // 前処理。spf を求める
spf.assign(N + 1, 0);
for (T i = 0; i <= N; i++)
spf[i] = i;
for (T i = 2; i * i <= N; i++) {
if (spf[i] == i) {
for (T j = i * i; j <= N; j += i) {
if (spf[j] == j) {
spf[j] = i;
}
}
}
}
}
map<T, T> get(T n) { // nの素因数分解を求める
map<T, T> m;
while (n != 1) {
m[spf[n]]++;
n /= spf[n];
}
return m;
}
};
vector<int> eratosthenes(const int N) {
std::vector<bool> is_prime(N + 1, true);
std::vector<int> prime_vec;
for (int i = 2; i <= N; i++) {
if (!is_prime[i]) {
continue;
}
// jは素数が確定しているのでその倍数をふるいおとす
for (int j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
prime_vec.emplace_back(i);
}
return prime_vec;
}
vector<int> get_prime_divisor(const int N) {
std::vector<bool> is_prime(N + 1, true);
std::vector<int> prime_divisor_vec;
for (int i = 2; i <= N; i++) {
if (!is_prime[i]) {
continue;
}
// jは素数が確定しているのでその倍数をふるいおとす
for (int j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
if (N % i == 0) {
prime_divisor_vec.emplace_back(i);
}
}
return prime_divisor_vec;
}
int main() {
int N;
cin >> N;
vector<lli> A(N);
rep(i, N) { cin >> A[i]; }
vector<lli> sumA(N, 0LL);
lli sum = 0;
for (int i = N; i > 0; i--) {
sumA[i] = (sum + A[i]) % MOD;
sum = (sum + A[i]) % MOD;
}
lli ans = 0;
for (int i = 0; i < N - 1; i++) {
ans = ans + (A[i] * sumA[i + 1]) % MOD;
ans %= MOD;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define BOUND 27182818284
#define MAT 2
typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;
ll MOD = 1000000007;
const ll INF = (1ll << 60);
const int INFint = (1 << 30);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
template <class T> bool umax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool umin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
// gcd
template <typename T> T gcd(T a, T b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll findGCD(vector<ll> arr) {
ll result = arr[0];
for (auto a : arr) {
result = gcd(a, result);
}
return result;
}
template <typename T> T getlcm(T m, T n) {
// 引数に0がある場合は0を返す
if ((0 == m) || (0 == n))
return 0;
return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
fill((T *)array, (T *)(array + N), val);
}
// v.front() = -BOUND;
// v.back() = BOUND;
// struct edge{
// int cost, to;
//
// edge(int in_cost, int in_to){
// cost=in_cost;
// to=in_to;
// }
// bool operator<(const edge &a) const
// {
// return cost > a.cost;
// }
// };
ll euler_phi(ll n) {
ll ret = n;
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret -= ret / i;
while (n % i == 0)
n /= i;
}
}
if (n > 1)
ret -= ret / n;
return ret;
}
class Combination {
long long powmod(long long a, long long p) {
long long ans = 1LL;
long long mul = a;
while (p > 0) {
if ((p & 1) == 1) {
ans = (ans * mul) % mod;
}
mul = (mul * mul) % mod;
p >>= 1;
}
return ans;
}
public:
int N;
long long mod;
vector<long long> fact;
vector<long long> revfact;
Combination(int n, long long m) : N(n), mod(m), fact(n + 1), revfact(n + 1) {
fact[0] = 1;
for (int i = 1; i <= N; i++) {
fact[i] = fact[i - 1] * i;
fact[i] %= mod;
}
revfact[N] = powmod(fact[N], mod - 2);
for (int i = N - 1; i >= 0; i--) {
revfact[i] = revfact[i + 1] * (i + 1) % mod;
}
}
long long getCombination(int a, int b) {
if (a < 0 || b < 0)
return 0;
if (b > a)
return 0;
return (fact[a] * revfact[b]) % mod * revfact[a - b] % mod;
}
};
struct mint {
const int mod = 1000000007;
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
struct UnionFind {
int n, cnt;
vector<int> par, rank, sz;
UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) {
iota(par.begin(), par.end(), 0);
}
int find(int x) {
if (x == par[x])
return x;
return par[x] = find(par[x]);
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) { return sz[find(x)]; }
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[x] = y;
sz[y] += sz[x];
} else {
par[y] = x;
sz[x] += sz[y];
if (rank[x] == rank[y]) {
rank[x]++;
}
}
cnt--;
}
};
const string Yes = "Yes";
const string YES = "YES";
const string No = "No";
const string NO = "NO";
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
template <typename Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while (a < sz) {
Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C> int find_first(int a, const C &check) {
Monoid L = M1;
if (a <= 0) {
if (check(f(L, seg[1])))
return find_subtree(1, check, L, false);
return -1;
}
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) {
Monoid nxt = f(L, seg[a]);
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C> int find_last(int b, const C &check) {
Monoid R = M1;
if (b >= sz) {
if (check(f(seg[1], R)))
return find_subtree(1, check, R, true);
return -1;
}
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1) {
if (b & 1) {
Monoid nxt = f(seg[--b], R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
template <typename T> vector<T> DIVISOR(T n) {
vector<T> v;
for (T i = 1; i * i <= n; ++i) {
if (n % i == 0) {
v.push_back(i);
if (i != n / i) {
v.push_back(n / i);
}
}
}
sort(v.begin(), v.end());
return v;
}
ll permutation(ll n) {
ll ans = 1LL;
if (n <= 0) {
return ans;
}
for (ll i = 1; i <= n; i++) {
ans *= i;
}
return ans;
}
template <typename T> struct PrimeFact {
vector<T> spf;
PrimeFact(T N) { init(N); }
void init(T N) { // 前処理。spf を求める
spf.assign(N + 1, 0);
for (T i = 0; i <= N; i++)
spf[i] = i;
for (T i = 2; i * i <= N; i++) {
if (spf[i] == i) {
for (T j = i * i; j <= N; j += i) {
if (spf[j] == j) {
spf[j] = i;
}
}
}
}
}
map<T, T> get(T n) { // nの素因数分解を求める
map<T, T> m;
while (n != 1) {
m[spf[n]]++;
n /= spf[n];
}
return m;
}
};
vector<int> eratosthenes(const int N) {
std::vector<bool> is_prime(N + 1, true);
std::vector<int> prime_vec;
for (int i = 2; i <= N; i++) {
if (!is_prime[i]) {
continue;
}
// jは素数が確定しているのでその倍数をふるいおとす
for (int j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
prime_vec.emplace_back(i);
}
return prime_vec;
}
vector<int> get_prime_divisor(const int N) {
std::vector<bool> is_prime(N + 1, true);
std::vector<int> prime_divisor_vec;
for (int i = 2; i <= N; i++) {
if (!is_prime[i]) {
continue;
}
// jは素数が確定しているのでその倍数をふるいおとす
for (int j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
if (N % i == 0) {
prime_divisor_vec.emplace_back(i);
}
}
return prime_divisor_vec;
}
int main() {
int N;
cin >> N;
vector<lli> A(N);
rep(i, N) { cin >> A[i]; }
vector<lli> sumA(N, 0LL);
lli sum = 0;
for (int i = N - 1; i > 0; i--) {
sumA[i] = (sum + A[i]) % MOD;
sum = (sum + A[i]) % MOD;
}
lli ans = 0;
for (int i = 0; i < N - 1; i++) {
ans = ans + (A[i] * sumA[i + 1]) % MOD;
ans %= MOD;
}
cout << ans << endl;
return 0;
}
| replace | 447 | 448 | 447 | 448 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02572 | Python | Time Limit Exceeded | # -*- coding: utf-8 -*-
n = int(input())
nums = list(map(int, input().split()))
x = 10**9 + 7
ans = 0
for i in range(1, n):
ans += (sum(nums[:i]) % x) * nums[i]
ans = ans % x
print(ans)
| # -*- coding: utf-8 -*-
n = int(input())
nums = list(map(int, input().split()))
x = 10**9 + 7
ans = 0
sums = [0] * (n - 1)
for j in range(n - 1):
if j == 0:
sums[0] = nums[0] % x
else:
sums[j] = (sums[j - 1] + nums[j]) % x
for i in range(1, len(nums)):
ans += sums[i - 1] * nums[i]
ans = ans % x
print(ans)
| replace | 8 | 10 | 8 | 18 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ull = unsigned long long int;
using ll = long long int;
constexpr ull mod = 1000000007;
int main() {
int n;
cin >> n;
vector<ull> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
ull sum = 0;
for (int i = 0; i < n - 1; i++) {
ull t = 0;
for (int j = i + 1; j < n; j++) {
t += A[j];
}
t = t % mod;
sum += A[i] * t;
sum = sum % mod;
}
cout << sum << endl;
return 0;
} | #include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ull = unsigned long long int;
using ll = long long int;
constexpr ull mod = 1000000007;
int main() {
int n;
cin >> n;
vector<ull> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
ull sum = 0;
ull state = 0;
for (int i = n - 2; i >= 0; i--) {
state += A[i + 1];
state = state % mod;
sum += state * A[i];
sum = sum % mod;
}
cout << sum << endl;
return 0;
} | replace | 21 | 28 | 21 | 26 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define vite \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define tst \
lli T; \
cin >> T; \
while (T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define lli long long int
#define vt vector
#define pb push_back
int main() {
vite;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
lli n;
cin >> n;
lli a[n];
for (lli i = 0; i < n; i++)
cin >> a[i];
lli sum = 0;
for (lli i = 0; i < n; i++)
for (lli j = i + 1; j < n; j++)
sum = (sum + (a[i] * a[j]) % mod) % mod;
cout << sum;
cout << endl;
// cout<< fixed << setprecision(6) << 1.0 * clock() / CLOCKS_PER_SEC;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define vite \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define tst \
lli T; \
cin >> T; \
while (T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define lli long long int
#define vt vector
#define pb push_back
int main() {
vite;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
lli n;
cin >> n;
lli a[n];
for (lli i = 0; i < n; i++)
cin >> a[i];
lli sum = 0, p[n + 1] = {0};
for (lli i = n - 1; i >= 0; i--)
p[i] = (p[i + 1] + a[i]) % mod;
for (lli i = 0; i < n; i++) {
sum += a[i] * p[i + 1];
sum %= mod;
}
cout << sum;
cout << endl;
// cout<< fixed << setprecision(6) << 1.0 * clock() / CLOCKS_PER_SEC;
return 0;
} | replace | 27 | 32 | 27 | 34 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[100005];
// ------------------------------------
// 1 is true
// 0 is false
// ------------------------------------
ll binexp(ll x, ll n, ll m) {
x %= m;
ll res = 1;
while (n > 0) {
if (n & 1) {
res = res * x % m;
}
x = x * x % m;
n >>= 1;
}
return res;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
const ll k = 1000000007;
ll sumai = 0, sumaisq = 0, minvtwo = binexp(2, (k - 2), k);
for (int i = 0; i < n; i++) {
sumai += a[i] % k;
sumaisq += ((a[i] % k) * (a[i] % k)) % k;
sumai = sumai % k;
sumaisq = sumaisq % k;
}
cout << (minvtwo * ((sumai * sumai - sumaisq) % k)) % k << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[200005];
// ------------------------------------
// 1 is true
// 0 is false
// ------------------------------------
ll binexp(ll x, ll n, ll m) {
x %= m;
ll res = 1;
while (n > 0) {
if (n & 1) {
res = res * x % m;
}
x = x * x % m;
n >>= 1;
}
return res;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
const ll k = 1000000007;
ll sumai = 0, sumaisq = 0, minvtwo = binexp(2, (k - 2), k);
for (int i = 0; i < n; i++) {
sumai += a[i] % k;
sumaisq += ((a[i] % k) * (a[i] % k)) % k;
sumai = sumai % k;
sumaisq = sumaisq % k;
}
cout << (minvtwo * ((sumai * sumai - sumaisq) % k)) % k << endl;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02572 | C++ | Runtime Error | #include "algorithm"
#include "cmath"
#include "cstdio"
#include "cstring"
#include "iostream"
#include "queue"
#include "stack"
using namespace std;
#define read(x) scanf("%d", &x)
#define readl(x) scanf("%lld", &x)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
int n;
ll a[100005];
ll sum[100005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (int i = n; i >= 1; i--) {
sum[i] = (sum[i + 1] + a[i]) % MOD;
}
for (int i = 1; i < n; i++) {
sum[0] = (sum[0] + a[i] * sum[i + 1]) % MOD;
}
printf("%lld\n", sum[0] % MOD);
return 0;
} | #include "algorithm"
#include "cmath"
#include "cstdio"
#include "cstring"
#include "iostream"
#include "queue"
#include "stack"
using namespace std;
#define read(x) scanf("%d", &x)
#define readl(x) scanf("%lld", &x)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
int n;
ll a[200005];
ll sum[200005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (int i = n; i >= 1; i--) {
sum[i] = (sum[i + 1] + a[i]) % MOD;
}
for (int i = 1; i < n; i++) {
sum[0] = (sum[0] + a[i] * sum[i + 1]) % MOD;
}
printf("%lld\n", sum[0] % MOD);
return 0;
} | replace | 16 | 18 | 16 | 18 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define P 1000000007
int main() {
// input
int64_t N;
cin >> N;
vector<int64_t> A(N);
rep(i, N) { cin >> A.at(i); }
// calc
int64_t ans = 0;
rep(i, N - 1) {
for (int64_t j = i + 1; j < N; j++) {
ans += A.at(i) * A.at(j);
ans %= P;
}
}
// output
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define P 1000000007
int main() {
// input
int64_t N;
cin >> N;
vector<int64_t> A(N);
rep(i, N) { cin >> A.at(i); }
// calc
int64_t ans = 0;
int64_t S = 0;
for (int i = N - 2; i >= 0; i--) {
S += A.at(i + 1);
S %= P;
ans += A.at(i) * S;
ans %= P;
}
// output
cout << ans << endl;
} | replace | 13 | 18 | 13 | 19 | TLE | |
p02572 | C++ | Runtime Error | #include <algorithm>
#include <stdio.h>
#include <string.h>
#define mod 1000000007
using namespace std;
long long a[100100];
long long h, n;
int main() {
scanf("%lld", &n);
for (int i = 0; i < n; i++) {
scanf("%lld", a + i);
h += a[i];
}
long long ans = 0;
for (int i = 0; i < n; i++) {
h -= a[i];
ans = (ans + ((h) % mod * a[i]) % mod) % mod;
}
printf("%lld\n", ans);
} | #include <algorithm>
#include <stdio.h>
#include <string.h>
#define mod 1000000007
using namespace std;
long long a[10010000];
long long h, n;
int main() {
scanf("%lld", &n);
for (int i = 0; i < n; i++) {
scanf("%lld", a + i);
h += a[i];
}
long long ans = 0;
for (int i = 0; i < n; i++) {
h -= a[i];
ans = (ans + ((h) % mod * a[i]) % mod) % mod;
}
printf("%lld\n", ans);
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'
const ll MOD = 1000000007;
int main() {
int n;
scanf("%d", &n);
vector<ll> a(n);
for (ll &i : a)
scanf("%lld", &i);
ll ans = 0;
for (ll i : a) {
ans += i;
ans = ans % MOD;
}
ans *= ans;
ans = ans % MOD;
for (ll i : a) {
ans -= i * i;
while (ans < 0)
ans += MOD;
ans = ans % MOD;
}
ans *= 500000004;
ans = ans % MOD;
printf("%lld", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'
const ll MOD = 1000000007;
int main() {
int n;
scanf("%d", &n);
vector<ll> a(n);
for (ll &i : a)
scanf("%lld", &i);
ll ans = 0;
for (ll i : a) {
ans += i;
ans = ans % MOD;
}
ans *= ans;
ans = ans % MOD;
for (ll i : a) {
ans -= i * i;
if (ans < 0) {
ll temp = (-ans + MOD - 1) / MOD;
ans += temp * MOD;
}
ans = ans % MOD;
}
ans *= 500000004;
ans = ans % MOD;
printf("%lld", ans);
return 0;
} | replace | 35 | 37 | 35 | 39 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
int main() {
ll n, sum = 0, summ = 0, a[300005];
cin >> n;
rep(i, n) { cin >> a[i]; }
rep(i, n - 1) {
summ = 0;
for (int j = i + 1; j < n; j++) {
summ += a[j];
summ %= mod;
}
sum += (a[i] * summ) % mod;
sum %= mod;
}
cout << sum;
} | #include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
int main() {
ll n, sum = 0, summ = 0, a[300005];
cin >> n;
rep(i, n) { cin >> a[i]; }
rep(i, n - 1) {
summ += a[n - 1 - i];
summ %= mod;
sum += (a[n - 2 - i] * summ) % mod;
sum %= mod;
}
cout << sum;
} | replace | 12 | 18 | 12 | 15 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long a[100005], pref[100005], res = 0;
int main() {
int n, mod = 1000000007;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pref[i] = a[i] + pref[i - 1];
}
for (int i = 1; i <= n; i++) {
res += ((pref[i - 1] % mod) * (a[i] % mod)) % mod;
}
cout << res % mod;
} | #include <bits/stdc++.h>
using namespace std;
long long a[200005], pref[200005], res = 0;
int main() {
int n, mod = 1000000007;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pref[i] = a[i] + pref[i - 1];
}
for (int i = 1; i <= n; i++) {
res += ((pref[i - 1] % mod) * (a[i] % mod)) % mod;
}
cout << res % mod;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long int ans = 0;
for (int i = 0; i < n - 1; i++) {
long long int sum = 0;
for (int j = i + 1; j < n; j++) {
sum += a[j];
sum %= MOD;
}
ans += (a[i] * sum) % MOD;
ans %= MOD;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long int ans = 0;
long long int sum = 0;
for (int i = n - 1; i > 0; i--) {
sum += a[i];
sum %= MOD;
ans += a[i - 1] * sum % MOD;
ans %= MOD;
}
cout << ans << endl;
return 0;
}
| replace | 14 | 22 | 14 | 19 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a.at(i);
long long sum = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
sum += (long long)a.at(i) * a.at(j);
sum = sum % 1000000007;
}
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a.at(i);
long long sum = 0;
long long u = 0;
for (int i = n - 1; i > 0; i--) {
u += a.at(i);
u = u % 1000000007;
sum += u * a.at(i - 1);
sum = sum % 1000000007;
}
cout << sum << endl;
return 0;
} | replace | 11 | 16 | 11 | 17 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
const int N = 1e5 + 1;
const int INF = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int A[n];
for (int i = 0; i < n; i++) {
cin >> A[i];
}
int ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
ans += (A[i] * A[j]);
ans = ans % INF;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
const int N = 1e5 + 1;
const int INF = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int A[n];
for (int i = 0; i < n; i++) {
cin >> A[i];
}
int ans = 0;
int x = 1;
int p[n];
p[0] = A[0];
for (int i = 1; i < n; i++) {
p[i] = (A[i] + p[i - 1]) % INF;
}
for (int i = 1; i < n; i++) {
ans += (A[i] * p[i - 1]);
ans %= INF;
}
cout << ans << endl;
}
| replace | 20 | 25 | 20 | 29 | TLE | |
p02572 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define int long long
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define vi vector<int>
#define ff first
#define ss second
#define vp vector<pair<int, int>>
#define vpp vector<pair<int, pair<int, int>>>
#define seti set<int>
#define setbit(x) __builtin_popcountll(x)
#define sov(v) accumulate(all(v), 0)
#define fs(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pqmax priority_queue<int, vector<int>>
#define pqmin priority_queue<int, vector<int>, greater<int>>
#define dq deque<int>
#define umi unordered_map<int, int>
#define ums unordered_map<string, int>
#define ps(x, y) fixed << setprecision(y) << x
#define all(x) x.begin(), x.end()
#define f(x, y, z) for (x = y; x < z; x++)
#define si size()
#define ps(x, y) fixed << setprecision(y) << x
#define countdigit(x) floor(log10(x) + 1)
#define M 1000000007
#define PI 3.1415926535
// Use (k%M+m)%m always where k is any no
#define ee "\n"
#define re return
// Author Rahul Sannigrahi
vector<int> take(int n) {
int i, j;
vi v;
f(i, 0, n) {
cin >> j;
v.pb(j);
}
return v;
}
void show(vector<int> v) {
int i;
for (i = 0; i < v.si; i++) {
cout << v[i] << " ";
}
cout << ee;
}
int decode() {
int i, j, k, l, n, m;
cin >> n;
vi v = take(n);
vi pes(n);
pes[v.si - 1] = v[v.si - 1];
for (i = v.si - 2; i >= 0; i--) {
pes[i] = pes[i + 1] + v[i];
}
// show(pes);
l = 0;
f(i, 0, v.si - 1) l = (l % M + ((v[i] % M) * (pes[i + 1] % M) + M)) % M;
cout << l << ee;
re 0;
}
int32_t main() {
IOS
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
int t = 1;
cin >> t;
while (t--)
decode();
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define int long long
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define vi vector<int>
#define ff first
#define ss second
#define vp vector<pair<int, int>>
#define vpp vector<pair<int, pair<int, int>>>
#define seti set<int>
#define setbit(x) __builtin_popcountll(x)
#define sov(v) accumulate(all(v), 0)
#define fs(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pqmax priority_queue<int, vector<int>>
#define pqmin priority_queue<int, vector<int>, greater<int>>
#define dq deque<int>
#define umi unordered_map<int, int>
#define ums unordered_map<string, int>
#define ps(x, y) fixed << setprecision(y) << x
#define all(x) x.begin(), x.end()
#define f(x, y, z) for (x = y; x < z; x++)
#define si size()
#define ps(x, y) fixed << setprecision(y) << x
#define countdigit(x) floor(log10(x) + 1)
#define M 1000000007
#define PI 3.1415926535
// Use (k%M+m)%m always where k is any no
#define ee "\n"
#define re return
// Author Rahul Sannigrahi
vector<int> take(int n) {
int i, j;
vi v;
f(i, 0, n) {
cin >> j;
v.pb(j);
}
return v;
}
void show(vector<int> v) {
int i;
for (i = 0; i < v.si; i++) {
cout << v[i] << " ";
}
cout << ee;
}
int decode() {
int i, j, k, l, n, m;
cin >> n;
vi v = take(n);
vi pes(n);
pes[v.si - 1] = v[v.si - 1];
for (i = v.si - 2; i >= 0; i--) {
pes[i] = pes[i + 1] + v[i];
}
// show(pes);
l = 0;
f(i, 0, v.si - 1) l = (l % M + ((v[i] % M) * (pes[i + 1] % M) + M)) % M;
cout << l << ee;
re 0;
}
int32_t main() {
IOS
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
int t = 1;
// cin>>t;
while (t--)
decode();
return 0;
}
| replace | 80 | 81 | 80 | 81 | 0 | |
p02572 | Python | Time Limit Exceeded | n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(n):
for j in range(i + 1, n):
s += a[i] * a[j]
s %= 1000000007
print(s % 1000000007)
| n = int(input())
a = list(map(int, input().split()))
s1 = sum(a)
s2 = 0
ans = 0
for i in range(n - 1):
s2 += a[i]
ans += a[i] * (s1 - s2)
print(ans % 1000000007)
| replace | 2 | 8 | 2 | 9 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll inf = 1000000007;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
ll a[100005], sum[100005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
sum[i] = sum[i - 1] + a[i];
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans = (ans + a[i] * ((sum[n] - sum[i]) % inf) % inf) % inf;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll inf = 1000000007;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
ll a[200005], sum[200005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
sum[i] = sum[i - 1] + a[i];
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans = (ans + a[i] * ((sum[n] - sum[i]) % inf) % inf) % inf;
}
cout << ans << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
const int mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<ll> a(n);
ll ans = 0;
rep(i, n) cin >> a[i];
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
(ans += (a[i] * a[j])) %= mod;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
const int mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<ll> a(n);
ll ans = 0;
rep(i, n) cin >> a[i];
ll sum = 0;
for (int i = n - 1; i >= 1; i--) {
sum += a[i];
sum %= mod;
ans += (a[i - 1] * sum) % mod;
ans %= mod;
}
cout << ans << endl;
} | replace | 17 | 21 | 17 | 23 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define ll long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define pci pair < char, int
#define mii map<int, int>
#define mll map<long long int, long long int>
#define mci map<char, int>
#define umii unordered_map<int, int>
#define umll unordered_map<long long int, long long int>
#define umci unordered_map<char, int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
// ll visit[100001]={0};
// vector<ll> adj[1000001];
int main() {
IOS;
int t;
t = 1; // cin>>t;
while (t--) {
ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++)
cin >> a[i];
ll ans = 0;
for (ll i = 0; i < n; i++) {
for (ll j = i + 1; j < n; j++) {
ans = (ans + (a[i] * a[j]) % mod) % mod;
}
}
cout << ans;
}
return 0;
}
| #include <bits/stdc++.h>
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define ll long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define pci pair < char, int
#define mii map<int, int>
#define mll map<long long int, long long int>
#define mci map<char, int>
#define umii unordered_map<int, int>
#define umll unordered_map<long long int, long long int>
#define umci unordered_map<char, int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
// ll visit[100001]={0};
// vector<ll> adj[1000001];
int main() {
IOS;
int t;
t = 1; // cin>>t;
while (t--) {
ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++)
cin >> a[i];
ll ans = 0;
ll suf[n];
suf[n - 1] = a[n - 1];
for (ll j = n - 2; j >= 0; j--) {
suf[j] = (a[j] + suf[j + 1]) % mod;
}
for (ll i = 0; i < n - 1; i++) {
ans = (ans + (a[i] * suf[i + 1]) % mod) % mod;
}
cout << ans;
}
return 0;
}
| replace | 35 | 39 | 35 | 42 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<int, pii> viii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vector<vl>> vvvl;
ll mod = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll i, j, n, sum = 0;
cin >> n;
vl a;
for (i = 0; i < n; i++) {
cin >> a[i];
sum = (sum + a[i]) % mod;
}
ll ans = 0, curr = 0;
for (i = 0; i < n; i++) {
curr = (curr + a[i]) % mod;
ans = (ans + (((sum - curr + mod) % mod) * a[i]) % mod) % mod;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<int, pii> viii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vector<vl>> vvvl;
ll mod = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll i, j, n, sum = 0;
cin >> n;
vl a(n);
for (i = 0; i < n; i++) {
cin >> a[i];
sum = (sum + a[i]) % mod;
}
ll ans = 0, curr = 0;
for (i = 0; i < n; i++) {
curr = (curr + a[i]) % mod;
ans = (ans + (((sum - curr + mod) % mod) * a[i]) % mod) % mod;
}
cout << ans << endl;
return 0;
}
| replace | 25 | 26 | 25 | 26 | -11 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int ll
#define FOR(i, s, e) for (ll i = s; i <= (ll)e; ++i)
#define DEC(i, s, e) for (ll i = s; i >= (ll)e; --i)
#define IAMSPEED \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a, b, c) \
cerr << #a << "=" << a << "," << #b << "=" << b << "," << #c << "=" << c \
<< "\n"
#define dbv(v) \
cerr << #v << ":"; \
for (auto ite : v) \
cerr << ite << ' '; \
cerr << "\n"
#define dbvp(v) \
cerr << #v << ":"; \
for (auto ite : v) \
cerr << "{" << ite.f << ',' << ite.s << "} "; \
cerr << "\n"
#define dba(a, ss, ee) \
cerr << #a << ":"; \
FOR(ite, ss, ee) cerr << a[ite] << ' '; \
cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair<ll, ll> pi;
typedef tuple<ll, ll, ll> ti3;
string cts(char x) {
string t(1, x);
return t;
}
ll rand(ll a, ll b) { return a + rng() % (b - a + 1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
const int MAXN = 100005;
#ifndef LOCAL
#define cerr \
if (0) \
cout
#endif
int A[MAXN];
int sum[MAXN];
int n;
int32_t main() {
IAMSPEED
cin >> n;
FOR(i, 1, n) cin >> A[i];
FOR(i, 1, n) sum[i] = sum[i - 1] + A[i], sum[i] %= MOD;
int ans = 0;
FOR(i, 1, n) {
int cur = A[i] * sum[i - 1];
cur %= MOD;
ans += cur;
ans %= MOD;
}
cout << ans;
}
| #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int ll
#define FOR(i, s, e) for (ll i = s; i <= (ll)e; ++i)
#define DEC(i, s, e) for (ll i = s; i >= (ll)e; --i)
#define IAMSPEED \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a, b, c) \
cerr << #a << "=" << a << "," << #b << "=" << b << "," << #c << "=" << c \
<< "\n"
#define dbv(v) \
cerr << #v << ":"; \
for (auto ite : v) \
cerr << ite << ' '; \
cerr << "\n"
#define dbvp(v) \
cerr << #v << ":"; \
for (auto ite : v) \
cerr << "{" << ite.f << ',' << ite.s << "} "; \
cerr << "\n"
#define dba(a, ss, ee) \
cerr << #a << ":"; \
FOR(ite, ss, ee) cerr << a[ite] << ' '; \
cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair<ll, ll> pi;
typedef tuple<ll, ll, ll> ti3;
string cts(char x) {
string t(1, x);
return t;
}
ll rand(ll a, ll b) { return a + rng() % (b - a + 1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
const int MAXN = 200005;
#ifndef LOCAL
#define cerr \
if (0) \
cout
#endif
int A[MAXN];
int sum[MAXN];
int n;
int32_t main() {
IAMSPEED
cin >> n;
FOR(i, 1, n) cin >> A[i];
FOR(i, 1, n) sum[i] = sum[i - 1] + A[i], sum[i] %= MOD;
int ans = 0;
FOR(i, 1, n) {
int cur = A[i] * sum[i - 1];
cur %= MOD;
ans += cur;
ans %= MOD;
}
cout << ans;
}
| replace | 48 | 49 | 48 | 49 | 0 | |
p02572 | C++ | Runtime Error | #include <cstring>
#include <fstream>
#include <iostream>
#define rep(a) for (int i = 0; i < a; i++)
#define E << endl;
#define Mode 1000000007
#define F freopen("in.txt", "r", stdin);
using namespace std;
int main() {
// F;
int ar[20005];
int tem[20005];
int n;
cin >> n;
rep(n) cin >> ar[i];
long long sum = 0;
rep(n) {
sum += ar[i];
tem[i] = sum;
}
long long ans = 0;
rep(n - 1) {
long long tempsum = tem[n - 1] - tem[i];
tempsum %= Mode;
// cout<<"just adition "<<tempsum<<endl;
tempsum *= ar[i];
tempsum %= Mode;
ans += tempsum;
ans %= Mode;
}
cout << ans << endl;
return 0;
} | #include <cstring>
#include <fstream>
#include <iostream>
#define rep(a) for (int i = 0; i < a; i++)
#define E << endl;
#define Mode 1000000007
#define F freopen("in.txt", "r", stdin);
using namespace std;
int main() {
// F;
int ar[200005];
long long tem[200005];
int n;
cin >> n;
rep(n) cin >> ar[i];
long long sum = 0;
rep(n) {
sum += ar[i];
tem[i] = sum;
}
long long ans = 0;
rep(n - 1) {
long long tempsum = tem[n - 1] - tem[i];
tempsum %= Mode;
// cout<<"just adition "<<tempsum<<endl;
tempsum *= ar[i];
tempsum %= Mode;
ans += tempsum;
ans %= Mode;
}
cout << ans << endl;
return 0;
} | replace | 12 | 14 | 12 | 14 | 0 | |
p02572 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;
ll A[100010];
int main() {
int N;
cin >> N;
ll sum = 0;
for (int i = 0; i < N; i++)
cin >> A[i];
ll ans = 0;
for (int i = 0; i < N; i++) {
ans = (ans + (sum % mod) * A[i]) % mod;
sum += A[i];
}
cout << ans << endl;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;
ll A[200010];
int main() {
int N;
cin >> N;
ll sum = 0;
for (int i = 0; i < N; i++)
cin >> A[i];
ll ans = 0;
for (int i = 0; i < N; i++) {
ans = (ans + (sum % mod) * A[i]) % mod;
sum += A[i];
}
cout << ans << endl;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
long long ans = 0;
int n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
ans += a[i] * a[j];
ans = ans % (1000000007);
}
}
cout << ans << endl;
} | #include <iostream>
using namespace std;
int main() {
long long ans = 0;
int n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long b[n + 1] = {};
for (int i = n - 1; i >= 0; i--) {
b[i] = b[i + 1] + a[i];
b[i] = b[i] % 1000000007;
}
for (int i = 0; i < n; i++) {
ans += b[i + 1] * a[i];
ans = ans % 1000000007;
}
cout << ans << endl;
} | replace | 13 | 18 | 13 | 22 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
using ll = long long;
int main() {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
ll ans = 0;
ll temp;
for (int i = 0; i < N - 1; i++) {
temp = 0;
for (int j = i + 1; j < N; j++) {
temp += A.at(j);
}
temp %= MOD;
ans += A.at(i) * temp % MOD;
}
ans %= MOD;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
using ll = long long;
int main() {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
ll ans = 0;
ll temp;
for (int i = 1; i < N; i++) {
temp += A.at(i - 1);
temp %= MOD;
ans += A.at(i) * temp % MOD;
}
ans %= MOD;
cout << ans << endl;
} | replace | 18 | 23 | 18 | 20 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <queue>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define readVarll(nam) \
ll nam; \
cin >> nam
#define DEV_VAL 1000000007
ll mulbig(ll a, ll b) { return (a * b) % DEV_VAL; }
ll addbig(ll a, ll b) { return (a + b) % DEV_VAL; }
int main() {
ll n;
cin >> n;
ll mydata[n];
rep(i, n) cin >> mydata[i];
ll ans = 0;
rep(i, n) {
reps(j, i + 1, n) {
ll tmp = mulbig(mydata[i], mydata[j]);
ans = addbig(ans, tmp);
}
}
cout << fixed << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#include <queue>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define readVarll(nam) \
ll nam; \
cin >> nam
#define DEV_VAL 1000000007
ll mulbig(ll a, ll b) { return (a * b) % DEV_VAL; }
ll addbig(ll a, ll b) { return (a + b) % DEV_VAL; }
int main() {
ll n;
cin >> n;
ll mydata[n];
rep(i, n) cin >> mydata[i];
ll ans = 0;
ll tmpadd = mydata[0];
reps(i, 1, n) {
ans = addbig(ans, mulbig(tmpadd, mydata[i]));
tmpadd = addbig(tmpadd, mydata[i]);
}
cout << fixed << ans << endl;
return 0;
} | replace | 29 | 34 | 29 | 33 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n;
ll r = 1e9 + 7;
cin >> n;
ll arr[n];
ll sum = 0;
for (ll i = 0; i < n; i++) {
cin >> arr[i];
for (ll j = 0; j < i; j++) {
sum += (arr[i] * arr[j]) % r;
}
}
cout << sum % r;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n;
ll r = 1e9 + 7;
cin >> n;
ll arr[n];
ll sum = 0;
for (int i = 0; i < n; i++) {
ll temp;
cin >> temp;
if (i == 0)
arr[i] = temp;
else {
sum += (temp * arr[i - 1]) % r;
arr[i] = (arr[i - 1] % r + temp % r) % r;
}
}
cout << sum % r;
return 0;
}
| replace | 10 | 14 | 10 | 18 | TLE | |
p02572 | C++ | Runtime Error | #pragma GCC optimize(2)
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5005;
const int MAXM = 20500;
const ll MOD = 1e9 + 7;
#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
template <typename T> inline T min(T a, T b, T c, T d) {
return min(min(a, b), min(c, d));
}
template <typename T, typename T1> inline T qpower(T x, T p, T1 mod) {
T re = 1;
x %= mod;
while (p) {
if (p & 1)
re = (re * x) % mod;
x = (x * x) % mod;
p >>= 1;
}
return re;
}
#define mst(X, Y) memset(X, Y, sizeof(X))
#define rep(i, a, n) for (int i = (a); i <= (n); i++)
#define per(i, a, n) for (int i = (a); i >= (n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
// int solve(int l,int r)
// {
// }
ll a[MAXN];
ll sum[MAXN];
int main() { // closeSync;
#ifdef DEBUG
// freopen("C:/Users/86159/Desktop/input.txt", "r", stdin);
// freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
// clock_t c1 = clock();
int n;
cin >> n;
rep(i, 1, n) cin >> a[i];
rep(i, 1, n) sum[i] = (sum[i - 1] + a[i]) % MOD;
ll ans = 0;
rep(i, 1, n - 1) { // i + 1 -> n
ans = (ans + a[i] * (sum[n] - sum[i] + MOD) % MOD) % MOD;
}
cout << ans << endl;
// cerr << "Time:" << clock() - c1 << "ms" <<endl;
return 0;
} | #pragma GCC optimize(2)
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 200005;
const int MAXM = 20500;
const ll MOD = 1e9 + 7;
#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
template <typename T> inline T min(T a, T b, T c, T d) {
return min(min(a, b), min(c, d));
}
template <typename T, typename T1> inline T qpower(T x, T p, T1 mod) {
T re = 1;
x %= mod;
while (p) {
if (p & 1)
re = (re * x) % mod;
x = (x * x) % mod;
p >>= 1;
}
return re;
}
#define mst(X, Y) memset(X, Y, sizeof(X))
#define rep(i, a, n) for (int i = (a); i <= (n); i++)
#define per(i, a, n) for (int i = (a); i >= (n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
// int solve(int l,int r)
// {
// }
ll a[MAXN];
ll sum[MAXN];
int main() { // closeSync;
#ifdef DEBUG
// freopen("C:/Users/86159/Desktop/input.txt", "r", stdin);
// freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
// clock_t c1 = clock();
int n;
cin >> n;
rep(i, 1, n) cin >> a[i];
rep(i, 1, n) sum[i] = (sum[i - 1] + a[i]) % MOD;
ll ans = 0;
rep(i, 1, n - 1) { // i + 1 -> n
ans = (ans + a[i] * (sum[n] - sum[i] + MOD) % MOD) % MOD;
}
cout << ans << endl;
// cerr << "Time:" << clock() - c1 << "ms" <<endl;
return 0;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
const ll m = 1e9 + 7;
using namespace std;
ll add(ll i, ll j) { return ((i % m) + (j % m)) % m; }
ll mod(ll i, ll j) { return ((i % m) * (j % m)) % m; }
int main() {
int n;
cin >> n;
vector<ll> v(n);
vector<ll> presum(n);
v[n] = 0;
presum[n] = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
v[i] = v[i] % m;
}
for (int i = n - 1; i >= 0; i--) {
presum[i] = add(presum[i + 1], v[i + 1]);
}
ll ans = 0;
for (int i = n - 1; i >= 0; i--) {
ans += mod(presum[i], v[i]);
ans %= m;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define ll long long
const ll m = 1e9 + 7;
using namespace std;
ll add(ll i, ll j) { return ((i % m) + (j % m)) % m; }
ll mod(ll i, ll j) { return ((i % m) * (j % m)) % m; }
int main() {
int n;
cin >> n;
vector<ll> v(n + 1, 0);
vector<ll> presum(n + 1, 0);
v[n] = 0;
presum[n] = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
v[i] = v[i] % m;
}
for (int i = n - 1; i >= 0; i--) {
presum[i] = add(presum[i + 1], v[i + 1]);
}
ll ans = 0;
for (int i = n - 1; i >= 0; i--) {
ans += mod(presum[i], v[i]);
ans %= m;
}
cout << ans << endl;
} | replace | 9 | 11 | 9 | 11 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i);
}
const ll p = 1000000007;
ll ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
ans += (a.at(i) % p) * (a.at(j) % p);
ans %= p;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i);
}
const ll p = 1000000007;
ll ans = 0;
ll b = a.at(0) % p;
for (int i = 1; i < n; i++) {
ans += (a.at(i) % p) * (b % p);
ans %= p;
b += a.at(i) % p;
b %= p;
}
cout << ans << endl;
return 0;
} | replace | 13 | 18 | 13 | 19 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, b, n) for (int i = (b); i < (n); i++)
using namespace std;
using ll = long long;
const ll M = 1000000007;
int main() {
ll n, ans = 0;
cin >> n;
vector<ll> a(n + 10);
rep(i, n) cin >> a[i];
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++) {
ans += (a[i] * a[j]) % M;
ans %= M;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, b, n) for (int i = (b); i < (n); i++)
using namespace std;
using ll = long long;
const ll M = 1000000007;
int main() {
ll n, ans = 0;
cin >> n;
vector<ll> a(n + 10);
vector<ll> s(n + 10);
rep(i, n) {
cin >> a[i];
s[i + 1] += s[i] + a[i];
s[i + 1] %= M;
}
rep(i, n - 1) {
if (s[n] - s[i + 1] < 0)
ans += a[i] * (s[n] - s[i + 1] + M);
else
ans += a[i] * (s[n] - s[i + 1]);
ans %= M;
}
cout << ans << endl;
} | replace | 14 | 20 | 14 | 27 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fast \
ios::sync_with_stdio(false); \
cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
const ll Mod = (1e9 + 7) * 2;
int n;
ll a[100010];
ll sum, ans;
int main() {
fast;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
sum %= Mod;
ans += Mod - a[i] * a[i] % Mod;
ans %= Mod;
}
ans += sum * sum % Mod;
ans %= Mod;
cout << ans / 2;
} | #include <bits/stdc++.h>
using namespace std;
#define fast \
ios::sync_with_stdio(false); \
cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
const ll Mod = (1e9 + 7) * 2;
int n;
ll a[200010];
ll sum, ans;
int main() {
fast;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
sum %= Mod;
ans += Mod - a[i] * a[i] % Mod;
ans %= Mod;
}
ans += sum * sum % Mod;
ans %= Mod;
cout << ans / 2;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using namespace std;
using ll = long long;
int main() {
ll mod = 7 + 1e9;
ll n, ans = 0;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
rep(i, n) rep(j, i) {
ans += (a[i] * a[j]) % mod;
ans %= mod;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using namespace std;
using ll = long long;
int main() {
ll mod = 7 + 1e9;
ll n, ans = 0;
cin >> n;
vector<ll> a(n), b(n);
rep(i, n) {
cin >> a[i];
if (i != 0)
b[i] += b[i - 1] + a[i];
}
rep(i, n) {
ll k = a[i] * ((b[n - 1] - b[i]) % mod) % mod;
ans += k;
ans %= mod;
}
cout << ans << endl;
return 0;
}
| replace | 10 | 14 | 10 | 19 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
using namespace std;
int main() {
long long n;
cin >> n;
vector<long long> av(n);
long long suma = 0;
for (auto &a : av) {
cin >> a;
suma += a;
}
long long ret = 0;
for (long long i = 0; i < n - 1; ++i) {
suma -= av[i];
if (1000000007 < suma) {
long long tempa = suma;
while (1000000007 < tempa) {
ret += av[i] * 1000000007;
ret %= 1000000007;
tempa -= 1000000007;
}
ret += av[i] * tempa;
ret %= 1000000007;
} else {
ret += av[i] * suma;
ret %= 1000000007;
}
}
cout << ret << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
long long n;
cin >> n;
vector<long long> av(n);
long long suma = 0;
for (auto &a : av) {
cin >> a;
suma += a;
}
long long ret = 0;
for (long long i = 0; i < n - 1; ++i) {
suma -= av[i];
long long tempa = suma % 1000000007;
ret += av[i] * tempa;
ret %= 1000000007;
}
cout << ret << endl;
return 0;
} | replace | 17 | 30 | 17 | 20 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
int main() {
LL n, ans = 0;
cin >> n;
vector<LL> a(n);
for (LL i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
ans += (a[i] % MOD) * (a[j] % MOD);
ans %= MOD;
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
int main() {
LL n, ans = 0;
cin >> n;
vector<LL> a(n);
for (LL i = 0; i < n; i++)
cin >> a[i];
LL subSum = 0;
for (int i = 0; i < n - 1; i++) {
subSum += a[i];
subSum %= MOD;
ans += subSum * a[i + 1];
ans %= MOD;
}
cout << ans;
} | replace | 10 | 15 | 10 | 16 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define MOD 1000000007
using namespace std;
int main() {
int n;
cin >> n;
vector<unsigned long long> ans(n, 0);
unsigned long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> ans[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
sum = (sum + (ans[i] * ans[j]) % MOD) % MOD;
}
}
cout << sum;
return 0;
} | #include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define MOD 1000000007
using namespace std;
int main() {
int n;
cin >> n;
vector<unsigned long long> ans(n, 0);
unsigned long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> ans[i];
}
unsigned long long check = 0;
for (int i = 0; i < n; i++) {
sum = (sum + (ans[i] * check) % MOD) % MOD;
check = (check + ans[i]) % MOD;
}
cout << sum;
return 0;
} | replace | 26 | 31 | 26 | 30 | TLE | |
p02572 | Python | Time Limit Exceeded | def main():
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
ans += sum(list(map(lambda x: A[i] * x, A[i + 1 :])))
print(ans % (10**9 + 7))
main()
| def main():
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
ans = 0
all_num = sum(A)
for i in range(N, 1, -1):
all_num -= A[i - 1]
ans += A[i - 1] * all_num
print(ans % (10**9 + 7))
main()
| replace | 9 | 11 | 9 | 13 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MM = 1e9 + 7;
int main() {
ll N;
cin >> N;
vector<ll> A(N);
for (ll &i : A)
cin >> i;
ll count = 0;
for (ll i = 0; i < N - 1; i++)
for (ll j = i + 1; j < N; j++) {
count += (A[i] * A[j]) % MM;
count %= MM;
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MM = 1e9 + 7;
int main() {
ll N;
cin >> N;
vector<ll> A(N);
for (ll &i : A)
cin >> i;
ll sum = 0, count = 0;
vector<ll> B(N);
for (ll j = N - 1; j >= 0; j--) {
// cout << j << endl;
sum += A[j] % MM;
sum %= MM;
B[j] = sum;
}
for (ll i = 0; i < N - 1; i++) {
count += (A[i] * B[i + 1]) % MM;
count %= MM;
}
cout << count << endl;
}
| replace | 12 | 18 | 12 | 27 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
class mint {
long long x;
public:
mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(long long t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
// 階乗を計算する
vector<mint> _factionals = {0, 1};
mint factional(long long n) {
if (_factionals.size() <= n) {
long long i = _factionals.size();
_factionals.resize(n + 1);
for (; i <= n; i++) {
_factionals[i] = _factionals[i - 1] * i;
}
}
return _factionals[n];
}
// 組み合わせ数を計算する。nCr
unordered_map<long long, vector<mint>> _combinations;
mint combination(long long n, long long r) {
if (n < 1 || r < 1 || n < r)
return mint(0);
if (n == r)
return mint(1);
// nが小さい場合は公式を使う
if (n < 51000)
return factional(n) / (factional(r) * factional(n - r));
// nが大きい場合はnC(r) = nC(r - 1) * (n - r + 1) / r
// nCr = nC(n - r)、計算量が少ない方を選ぶ
if (r > n - r)
r = n - r;
// nC0 = 0, nC1 = nで初期化
if (!_combinations.count(n))
_combinations[n] = {0, n};
auto &&vec = _combinations[n];
if (vec.size() <= r) {
long long i = vec.size();
vec.resize(r + 1);
for (; i <= r; i++) {
vec[i] = (vec[i - 1] * (n - i + 1)) / i;
}
}
return vec[r];
}
// 順序のパターン数を計算する。nPr
unordered_map<long long, vector<mint>> _permutations;
mint permutation(long long n, long long r) {
if (n < 1 || r < 1 || n < r)
return mint(0);
// nが小さい場合は公式を使う
if (n < 51000)
return factional(n) / factional(n - r);
// nが大きい場合はnC(r) = nC(r - 1) * (n - r + 1)
// nC0 = 0, nC1 = nで初期化
if (!_permutations.count(n))
_permutations[n] = {0, n};
auto &&vec = _permutations[n];
if (vec.size() <= r) {
long long i = vec.size();
vec.resize(r + 1);
for (; i <= r; i++) {
vec[i] = vec[i - 1] * (n - i + 1);
}
}
return vec[r];
}
int n;
mint result;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << std::setprecision(20);
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
result += a[i] * a[j];
}
}
cout << result;
} | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
class mint {
long long x;
public:
mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(long long t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
// 階乗を計算する
vector<mint> _factionals = {0, 1};
mint factional(long long n) {
if (_factionals.size() <= n) {
long long i = _factionals.size();
_factionals.resize(n + 1);
for (; i <= n; i++) {
_factionals[i] = _factionals[i - 1] * i;
}
}
return _factionals[n];
}
// 組み合わせ数を計算する。nCr
unordered_map<long long, vector<mint>> _combinations;
mint combination(long long n, long long r) {
if (n < 1 || r < 1 || n < r)
return mint(0);
if (n == r)
return mint(1);
// nが小さい場合は公式を使う
if (n < 51000)
return factional(n) / (factional(r) * factional(n - r));
// nが大きい場合はnC(r) = nC(r - 1) * (n - r + 1) / r
// nCr = nC(n - r)、計算量が少ない方を選ぶ
if (r > n - r)
r = n - r;
// nC0 = 0, nC1 = nで初期化
if (!_combinations.count(n))
_combinations[n] = {0, n};
auto &&vec = _combinations[n];
if (vec.size() <= r) {
long long i = vec.size();
vec.resize(r + 1);
for (; i <= r; i++) {
vec[i] = (vec[i - 1] * (n - i + 1)) / i;
}
}
return vec[r];
}
// 順序のパターン数を計算する。nPr
unordered_map<long long, vector<mint>> _permutations;
mint permutation(long long n, long long r) {
if (n < 1 || r < 1 || n < r)
return mint(0);
// nが小さい場合は公式を使う
if (n < 51000)
return factional(n) / factional(n - r);
// nが大きい場合はnC(r) = nC(r - 1) * (n - r + 1)
// nC0 = 0, nC1 = nで初期化
if (!_permutations.count(n))
_permutations[n] = {0, n};
auto &&vec = _permutations[n];
if (vec.size() <= r) {
long long i = vec.size();
vec.resize(r + 1);
for (; i <= r; i++) {
vec[i] = vec[i - 1] * (n - i + 1);
}
}
return vec[r];
}
int n;
mint result;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << std::setprecision(20);
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
mint x(0);
;
for (int i = n - 2; i >= 0; i--) {
x += a[i + 1];
result += mint(a[i]) * x;
}
cout << result;
} | replace | 144 | 148 | 144 | 149 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pi;
typedef pair<lld, lld> pl;
typedef pair<int, lld> pil;
typedef pair<lld, int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a, b) make_pair(a, b)
bool isrange(int y, int x, int n, int m) {
if (0 <= y && y < n && 0 <= x && x < m)
return true;
return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const lld mod = 1e9 + 7;
lld arr[222222];
int main(void) {
int n;
scanf("%lld", &n);
lld tot = 0;
for (int e = 0; e < n; e++) {
scanf("%lld", &arr[e]);
tot = (tot + arr[e]) % mod;
}
lld ans = 0;
for (int e = 0; e < n; e++) {
tot = (tot - arr[e] + mod) % mod;
ans = (ans + arr[e] * tot) % mod;
}
printf("%lld", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pi;
typedef pair<lld, lld> pl;
typedef pair<int, lld> pil;
typedef pair<lld, int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a, b) make_pair(a, b)
bool isrange(int y, int x, int n, int m) {
if (0 <= y && y < n && 0 <= x && x < m)
return true;
return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const lld mod = 1e9 + 7;
lld arr[222222];
int main(void) {
int n;
scanf("%d", &n);
lld tot = 0;
for (int e = 0; e < n; e++) {
scanf("%lld", &arr[e]);
tot = (tot + arr[e]) % mod;
}
lld ans = 0;
for (int e = 0; e < n; e++) {
tot = (tot - arr[e] + mod) % mod;
ans = (ans + arr[e] * tot) % mod;
}
printf("%lld", ans);
return 0;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02572 | Python | Time Limit Exceeded | #!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
for i in range(N - 1):
ans += (A[i] * (sum(A[i + 1 :]) % mod)) % mod
ans = ans % mod
print(ans)
| #!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
s = sum(A) ** 2
a = 0
for i in A:
a += i**2
ans = (s - a) // 2
ans = ans % mod
print(ans)
| replace | 5 | 9 | 5 | 15 | TLE | |
p02572 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int __int128
using namespace std;
const int mod = 1e9 + 7;
int n, sum[100005], a[100005], ans;
inline int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * f;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
signed main() {
n = read();
for (int i = 1; i <= n; i++)
a[i] = read();
for (int i = 1; i <= n; i++)
sum[i] = sum[i - 1] + a[i];
for (int i = 1; i <= n; i++)
ans = (ans + a[i] * (sum[n] - sum[i])) % mod;
write(ans);
return 0;
} | #include <bits/stdc++.h>
#define int __int128
using namespace std;
const int mod = 1e9 + 7;
int n, sum[1000005], a[1000005], ans;
inline int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * f;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
signed main() {
n = read();
for (int i = 1; i <= n; i++)
a[i] = read();
for (int i = 1; i <= n; i++)
sum[i] = sum[i - 1] + a[i];
for (int i = 1; i <= n; i++)
ans = (ans + a[i] * (sum[n] - sum[i])) % mod;
write(ans);
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02572 | Python | Time Limit Exceeded | n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
ans += a[i] * sum(a[i + 1 :])
print(ans % (10**9 + 7))
| n = int(input())
a = list(map(int, input().split()))
ans = 0
r = [0] * (n + 1)
for i, v in enumerate(a, start=1):
r[i] = v + r[i - 1]
for i in range(n - 1):
ans += a[i + 1] * r[i + 1]
print(ans % (10**9 + 7))
| replace | 3 | 5 | 3 | 9 | TLE | |
p02572 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, sum = 0;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (i < j) {
sum += a[i] * a[j];
sum = sum % 1000000007;
}
}
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, sum = 0;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int x = 0;
for (long long int i = 0; i < n; i++) {
// for(long long int j=i+1;j<n;j++)
// {
// if(i<j)
// {
sum = (sum + ((long long int)a[i] * x)) % 1000000007;
x = (x + a[i]) % 1000000007;
// }
//}
}
cout << sum << endl;
return 0;
} | replace | 8 | 15 | 8 | 19 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.