alexjercan/bugnet huggingface dataset:
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < n; i++)
#define inf 1e9 + 7
using namespace std;
typedef long long ll;
const double pi = acos(-1);

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  vector<ll> cum(n);
  cum[n - 1] = A[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    cum[i] = cum[i + 1] + A[i];
  }
  ll ans = 0;
  ll mod = inf;
  for (int i = 0; i < n - 1; i++) {
    ans += A[i] * (cum[i + 1] % mod);
    ans %= mod;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < n; i++)
#define inf 1e9 + 7
using namespace std;
typedef long long ll;
const double pi = acos(-1);

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  for (int i = 0; i < n; i++)
    cin >> A[i];
  ll mod = inf;
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += (A[i] * A[j]) % mod;
    }
  }
  ans %= mod;
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repa(i, s, n) for (int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i, a, b) for (int i = a; i >= b; i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  ll n;
  cin >> n;
  vector<ll> a(n), suma(n + 1);
  rep(i, n) cin >> a[i];
  rep(i, n) suma[i + 1] = suma[i] + a[i];

  ll ans = 0;
  rep(i, n - 1) {
    ll x = suma[n] - suma[i + 1];
    x %= MOD;
    /* cout << a[i] << " * " << x << endl; */
    ans += (a[i] * x);
    ans %= MOD;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repa(i, s, n) for (int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i, a, b) for (int i = a; i >= b; i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += (a[i] * a[j]) % MOD;
    }
  }
  cout << ans % MOD << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h> // header file includes every Standard library
using namespace std;
#define mod 1000000007

long long power(long long x, unsigned int y) {
  long long res = 1; // Initialize result

  x = x % mod; // Update x if it is more than or
               // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % mod;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % mod;
  }
  return res;
}
int main() {

  int n;
  cin >> n;
  long long ans = 0;
  long long temp;
  vector<long long> t;
  while (n--) {
    cin >> temp;
    t.push_back(temp);
  }
  long long sum[t.size()] = {0};
  for (int i = t.size() - 2; i >= 0; i--) {
    sum[i] = (sum[i] + sum[i + 1] + t[i + 1]) % mod;
  }
  for (int i = 0; i < t.size(); i++) {

    ans = (ans + (t[i] % mod * sum[i] % mod) % mod) % mod;
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h> // header file includes every Standard library
using namespace std;
#define mod 1000000007

long long power(long long x, unsigned int y) {
  long long res = 1; // Initialize result

  x = x % mod; // Update x if it is more than or
               // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % mod;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % mod;
  }
  return res;
}
int main() {

  int n;
  cin >> n;
  long long ans = 0;
  long long temp;
  vector<long long> t;
  while (n--) {
    cin >> temp;
    t.push_back(temp);
  }
  for (int i = 0; i < t.size(); i++) {

    for (int j = i + 1; j < t.size(); j++) {
      ans = (ans + (t[i] % mod * t[j] % mod) % mod) % mod;
    }
  }
  cout << ans;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    sum -= a[i];
    ans = (ans + (sum % mod) * (a[i] % mod)) % mod;
  }
  cout << ans << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = (ans + a[i] * a[j]) % mod;
    }
  }
  cout << ans << "\\n";
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;

  std::vector<std::uint64_t> as(n);
  std::vector<std::uint64_t> asum(n);

  for (std::uint64_t i = 0; i < n; i++) {
    std::cin >> as[i];
    if (i == 0) {
      asum[i] = as[i];
    } else {
      asum[i] = asum[i - 1] + as[i];
    }
  }

  constexpr std::uint64_t MOD = 1000000007;

  std::uint64_t ans = 0;
  for (std::uint64_t i = 0; i < as.size() - 1; ++i) {
    auto mul = (*asum.rbegin() - asum[i]) % MOD;
    ans += (as[i] * mul) % MOD;
    ans %= MOD;
  }

  std::cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;

  std::vector<std::uint64_t> as(n);

  for (auto &val : as) {
    std::cin >> val;
  }

  constexpr std::uint64_t MOD = 1000000007;

  std::uint64_t ans = 0;
  for (std::uint64_t i = 0; i < as.size() - 1; ++i) {
    for (std::uint64_t j = i + 1; j < as.size(); ++j) {
      ans += (as[i] * as[j]) % MOD;
      ans %= MOD;
    }
  }

  std::cout << ans;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define fastIO                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(NULL);
typedef long long ll;
using namespace std;

ll mod = 1000000007;

int main() {
  fastIO

      int n;
  cin >> n;

  int a[n];

  ll sum = 0;

  for (int i = 0; i < n; i++) {

    cin >> a[i];

    sum += a[i];

    sum %= mod;
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {

    sum -= a[i];

    if (sum < 0)
      sum += mod;

    ans += (a[i] * sum);

    ans %= mod;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fastIO                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(NULL);
typedef long long ll;
using namespace std;

ll mod = 1000000000 + 7;

int main() {
  fastIO int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ll p = (a[i] * a[j]) % mod;
      sum = (sum + p) % mod;
    }
  }
  cout << sum;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
int main() {
  int n;

  int64_t c = 0, d = 0;
  cin >> n;
  int64_t a[n], k[n];
  rep(i, n) {
    cin >> a[i];
    k[i] = a[i] % 1000000007;
    d += k[i];
  }
  rep(i, n - 1) {
    d = d - k[i];
    int64_t e = d % 1000000007;
    int64_t b = k[i] * e;
    c += b;
    c = c % 1000000007;
  }
  cout << c << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
int main() {
  int n;
  int64_t c = 0;
  cin >> n;
  int64_t a[n];
  rep(i, n) cin >> a[i];
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      c += (a[i] * a[j]) % 1000000007;
      c = c % 1000000007;
      // cout << c << endl;
    }
  }
  cout << c << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

long long MOD = 1e9 + 7;
int MAX_INT = 1e9;

long long H, W;
vector<vector<long long>> cost_map(1000 + 1, vector<long long>(1000 + 1, 0));

// 最大公約数
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long N;
  cin >> N;
  vector<long long> A(N), sum_A(N + 1, 0);
  long long a;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  reverse(A.begin(), A.end());
  for (int i = 0; i < N; ++i) {
    sum_A[i + 1] = sum_A[i] + A[i];
  }

  long long sum = 0;
  for (int i = 0; i < A.size() - 1; ++i) {
    sum += (A[i + 1] % MOD) * (sum_A[i + 1] % MOD) % MOD;
    sum %= MOD;
  }

  cout << sum << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

long long MOD = 1e9 + 7;
int MAX_INT = 1e9;

long long H, W;
vector<vector<long long>> cost_map(1000 + 1, vector<long long>(1000 + 1, 0));

// 最大公約数
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long N;
  cin >> N;
  vector<long long> A, sum_A(N, 0);
  long long a;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    A.push_back(a);
    if (i != 0) {
      for (int j = 0; j < A.size(); ++j) {
        sum_A[j] += a;
      }
    }
  }

  long long sum = 0;
  for (int i = 0; i < A.size() - 1; ++i) {
    sum += (A[i] % MOD) * (sum_A[i + 1] % MOD) % MOD;
    sum %= MOD;
  }

  cout << sum << endl;

  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#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() {
  long long N;
  cin >> N;

  vector<long long> A(N);
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<long long> S(N + 1, 0);
  for (long long i = 0; i < N; ++i) {
    S[i + 1] = S[i] + A[i];
  }

  long long ans = 0;
  for (long long i = 0; i < N; ++i) {
    long long llbuff = (S[N] - S[i + 1]) % (long long)1000000007;
    ans += (A[i] * llbuff) % (long long)1000000007;
  }

  cout << ans % (long long)1000000007 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#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() {
  ll N;
  cin >> N;

  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }

  ll ans = 0;
  for (ll i = 0; i < N - 1; ++i) {
    for (ll j = i + 1; j < N; ++j) {
      ans += A.at(i) * A.at(j);
      ans %= 1000000007ll;
    }
  }

  cout << ans % 1000000007ll << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: 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];
  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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define fi fisrt
#define se second

using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f;

vector<int> vec[N];

int n, m, k, ans, sum;
int ji;
int a[N];
int num[N];
string s, t;
int lens, lent;
signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    sum += a[i];
  sum %= mod;
  for (int i = 1; i <= n; i++)
    ans += (a[i] * (sum - a[i]) % mod + mod) % mod;
  if (ans % 2 == 1)
    ans += mod;
  ans /= 2;
  ans %= mod;
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define fi fisrt
#define se second

using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f;

vector<int> vec[N];

int n, m, k, ans, sum;
int a[N];
int num[N];
string s, t;
int lens, lent;
int ksm(int xx, int yy, int zz) {
  int ret;
  while (yy) {
    if (yy & 1)
      ret = (ret * xx) % zz;
    xx = (xx * xx) % zz;
    yy >>= 1;
  }
  return ret;
}

signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    sum += a[i];
  sum %= mod;
  for (int i = 1; i <= n; i++)
    ans += a[i] * (sum - a[i]);
  ans /= 2;
  ans %= mod;
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  long long ans = 0;
  int mod = 1000000007;

  vector<long long> b(n, 0);
  b[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    b[i] = a[i] + b[i + 1];
    b[i] %= mod;
  }

  for (int i = 0; i < n - 1; i++) {
    ans += a[i] * b[i + 1];
    ans %= mod;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  long long ans = 0;
  int mod = 1000000007;

  for (int i = 0; i < n - 1; i++) {
    for (int j = 1; j < n - i; j++) {
      ans += a[i] * a[i + j];
      ans %= mod;
    }
  }

  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)      // iをaからn
#define per(i, a, n) for (int i = a - 1; i >= n; i--) // iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y)                                                              \\
  cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y                 \\
       << ")\\n"; // デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 // 10^12:∞
#define MOD 1000000007    // 10^9+7:合同式の法

int main() {
  int N;
  cin >> N;

  vector<long long int> a(N);
  long long int all = 0;
  rep(i, 0, N) {
    cin >> a.at(i);
    all += a.at(i);
    all %= MOD;
  }

  // sort(all(a));

  long long int ans = 0;

  rep(i, 0, N) {
    all -= a.at(i);
    all = (all + MOD) % MOD;
    ans += (a.at(i) * all) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)      // iをaからn
#define per(i, a, n) for (int i = a - 1; i >= n; i--) // iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y)                                                              \\
  cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y                 \\
       << ")\\n"; // デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 // 10^12:∞
#define MOD 1000000007    // 10^9+7:合同式の法

int main() {
  int N;
  cin >> N;

  vector<long long int> a(N);

  rep(i, 0, N) { cin >> a.at(i); }

  // sort(all(a));

  long long int ans = 0;

  rep(i, 0, N) {
    rep(j, i + 1, N) {
      ans += (a.at(i) * a.at(j)) % MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

const int N = 2e5 + 10;
long long int a[N];
int n;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n;
  long long int sum = 0;

  for (int i = 0; i < n; i++) {
    cin >> a[i];

    sum += a[i];
    sum %= 1000000007;
  }

  long long ans = 0;

  for (int i = 0; i < n; i++) {
    sum -= a[i];
    if (sum < 0)
      sum += 1000000007;

    ans += a[i] * sum;
    ans %= 1000000007;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

const int N = 2e5 + 10;
long long int a[N];
int n;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n;
  long long int sum = 0;

  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < N; j++) {
      sum += (a[i] * a[j]) % (1000000007);
    }
  }

  sum %= 1000000007;

  cout << sum << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define loop(a, b) for (ll i = a; i < b; i++)
#define iloop(a, b) for (int i = a; i < b; i++)
#define it(c) for (auto it = c.begin(); it != c.end(); it++)
#define M 1000000007

using namespace std;

void Thai_Jase() {
  ll n;
  cin >> n;
  ll a[n], sum = 0, ans = 0;
  loop(0, n) {
    cin >> a[i];
    sum += a[i];
  }
  for (ll i = 0; i < n - 1; i++) {
    ll temp = (sum - a[i]) % M;
    ans += (a[i] * temp) % M;
    sum -= a[i];
  }
  cout << ans % M;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int ts = 1;
  while (ts--) {
    Thai_Jase();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define loop(a, b) for (ll i = a; i < b; i++)
#define iloop(a, b) for (int i = a; i < b; i++)
#define it(c) for (auto it = c.begin(); it != c.end(); it++)
#define M 1000000007

using namespace std;

void Thai_Jase() {
  ll n;
  cin >> n;
  ll a[n], sum = 0;
  loop(0, n) cin >> a[i];
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      sum += (a[i] * a[j]) % M;
    }
  }
  cout << sum % M;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int ts = 1;
  while (ts--) {
    Thai_Jase();
  }
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded


/*
ID: Bipin Singh [bipinsingh061]
LANG: C++
TASK: gift1
*/
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << "\\n" << (#x) << " = " << (x) << "\\n"
#define int long long int

void inputoutput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

bool dfs(int src, int c, bool *vis, vector<int> (&v)[2001], int col[]) {
  vis[src] = true;
  col[src] = c;
  // cout<<src<<" ";

  for (auto it : v[src]) {
    if (!vis[it]) {
      if (dfs(it, c * -1, vis, v, col) == false)
        return false;
    } else {
      if (col[src] == col[it])
        return false;
    }
  }
  return true;
}

int mod = 1e9 + 7;

void update(vector<int> &D, int l, int r, int x) {
  D[l] += x;
  D[r + 1] -= x;
}

int32_t main() {
  inputoutput();

  int n;
  cin >> n;
  int ar[n];
  int pref[n + 1];

  for (int i = 0; i < n; ++i) {
    cin >> ar[i];
  }

  int sum = 0;
  for (int i = n - 1; i >= 0; --i) {
    sum = (sum + ar[i]) % mod;
    pref[i] = sum;
  }
  pref[n] = 0;

  int ans = 0;

  for (int i = 0; i < n; ++i) {
    ans = (ans + (ar[i] * pref[i + 1])) % mod;
  }
  cout << (ans + mod) % mod;

  return 0;
}


Error: TLE

Fixed submission:


/*
ID: Bipin Singh [bipinsingh061]
LANG: C++
TASK: gift1
*/
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << "\\n" << (#x) << " = " << (x) << "\\n"
#define int long long int

void inputoutput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

bool dfs(int src, int c, bool *vis, vector<int> (&v)[2001], int col[]) {
  vis[src] = true;
  col[src] = c;
  // cout<<src<<" ";

  for (auto it : v[src]) {
    if (!vis[it]) {
      if (dfs(it, c * -1, vis, v, col) == false)
        return false;
    } else {
      if (col[src] == col[it])
        return false;
    }
  }
  return true;
}

int mod = 1e9 + 7;

void update(vector<int> &D, int l, int r, int x) {
  D[l] += x;
  D[r + 1] -= x;
}

int32_t main() {
  inputoutput();

  int n;
  cin >> n;
  int ar[n];

  for (int i = 0; i < n; ++i) {
    cin >> ar[i];
  }
  int sum = 0;
  for (int i = 0; i < n; ++i) {

    for (int j = i + 1; j < n; ++j) {
      int pr = 1;
      pr = pr * ar[i] % mod;
      pr = pr * ar[j] % mod;
      // cout<<pr<<"\\n";
      sum += pr;
    }
  }
  cout << (sum + mod) % mod;

  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: 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[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;
}


Error: 0

Fixed submission:

#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;
}