prithivMLmods/Coder-Stat huggingface dataset:
Problem p02571 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
  string S, T;
  cin >> S >> T;
  ll nS = S.size();
  ll nT = T.size();
  ll sameTS = 0;

  rep(i, i <= nS - nT) {
    ll j = 0;
    while (S[i + j] == T[j] && j < nT)
      j++;
    if (sameTS < j)
      sameTS = j;
  }

  cout << nT - sameTS;

  cin >> S;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
  string S, T;
  cin >> S >> T;
  ll nS = S.size();
  ll nT = T.size();
  ll sameTS = 0;

  for (ll i = 0; i <= nS - nT; i++) {
    ll sam = 0;
    for (ll j = 0; j < nT; j++) {
      if (S[i + j] == T[j])
        sam++;
    }
    if (sameTS < sam)
      sameTS = sam;
  }

  cout << nT - sameTS;

  cin >> S;

  return 0;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string t, s;
  cin >> t >> s;

  int ans = t.size();

  for (int start = 0; start <= s.size() - t.size(); start++) {
    int diff = 0;
    for (int i = 0; i < t.size(); i++) {
      if (t[i] != s[start + i]) {
        diff++;
      }
    }
    ans = min(ans, diff);
  }

  cout << ans << endl;
  return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;

  int ans = t.size();

  for (int start = 0; start <= s.size() - t.size(); start++) {
    int diff = 0;
    for (int i = 0; i < t.size(); i++) {
      if (t[i] != s[start + i]) {
        diff++;
      }
    }
    ans = min(ans, diff);
  }

  cout << ans << endl;
  return 0;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define PI acos(-1)
#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
ll mod = 1e9 + 7;

int main() {
  fast_io

      string s,
      t;
  cin >> s >> t;
  int ans = 0;
  vector<int> vec;
  rep(i, s.size() - t.size()) {
    int cnt = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == t[j])
        cnt++;
    }
    vec.push_back(cnt);
  }
  sort(vec.begin(), vec.end());
  cout << t.size() - vec[vec.size() - 1] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define PI acos(-1)
#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
ll mod = 1e9 + 7;

int main() {
  fast_io

      string s,
      t;
  cin >> s >> t;
  int ans = 0;
  vector<int> vec;
  rep(i, s.size() - t.size() + 1) {
    int cnt = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == t[j])
        cnt++;
    }
    vec.push_back(cnt);
  }
  sort(vec.begin(), vec.end());
  cout << t.size() - vec[vec.size() - 1] << endl;
  return 0;
}
Problem p02571 (Python)

Buggy submission (status: Time Limit Exceeded):
S = input()
T = input()

min_dist = 10**10
for i in range(len(S) - len(T) + 1):
    for k in range(len(T)):
        dist = sum(s != t for s, t in zip(S[i : i + len(T)], T))
        min_dist = min(dist, min_dist)
        if min_dist == 0:
            print(0)
            exit()

print(min_dist)


Fixed submission:
S = input()
T = input()

min_dist = 10**10
for i in range(len(S) - len(T) + 1):
    for k in range(len(T)):
        dist = 0
        for s, t in zip(S[i : i + len(T)], T):
            if s != t:
                dist += 1
            if dist >= min_dist:
                break

        min_dist = min(dist, min_dist)
        if min_dist == 0:
            print(0)
            exit()

print(min_dist)
Problem p02571 (Python)

Buggy submission (status: Runtime Error):
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

s = input()
t = input()

a = []
for i in range(len(s) - len(t)):
    cnt = 0
    for j in range(len(t)):
        if t[j] == s[i + j]:
            cnt += 1
    a.append(cnt)
print(len(t) - max(a))


Fixed submission:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

s = input()
t = input()

a = []
for i in range(len(s) - len(t) + 1):
    cnt = 0
    for j in range(len(t)):
        if t[j] == s[i + j]:
            cnt += 1
    a.append(cnt)
print(len(t) - max(a))
Problem p02571 (Python)

Buggy submission (status: Runtime Error):
s = input().strip()
t = input().strip()

if t in s:
    print(0)
else:
    ans = 1000
    for i in range(len(s) - len(t) - 1):
        count = len(t) - 1
        for j in range(len(t) - 1):
            if s[i + j] == t[i]:
                count -= 1
        ans = min(count, ans)
    print(ans)


Fixed submission:
s = input().strip()
t = input().strip()

if t in s:
    print(0)
else:
    ans = 10001
    for i in range(len(s) - len(t) + 1):
        count = 0
        cnt = i
        for j in range(len(t)):
            if s[cnt] != t[j]:
                count += 1
            cnt += 1
        ans = min(count, ans)
    print(ans)
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
int main() {
  string s, t;
  cin >> s >> t;
  int i = 0;
  vector<int> zure(s.size() - t.size(), 0);
  do {
    rep(j, t.size()) {
      if (s[i + j] != t[j]) {
        zure[i]++;
      }
    }
    i++;
  } while (i < s.size() - t.size());
  sort(zure.begin(), zure.end());
  cout << zure[0] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
int main() {
  string s, t;
  cin >> s >> t;
  int i = 0, sz;
  if (s.size() == t.size()) {
    sz = 1;
  } else {
    sz = s.size() - t.size();
  }
  vector<int> zure(sz, 0);
  do {
    rep(j, t.size()) {
      if (s[i + j] != t[j]) {
        zure[i]++;
      }
    }
    i++;
  } while (i < s.size() - t.size());
  sort(zure.begin(), zure.end());
  cout << zure[0] << endl;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define fast_IO                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define int long long int
#define ll long long
#define ld long double

bool isPrime(ll n) {
  if (n < 2)
    return false;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

ll lcm(ll x, ll y) { return (x * y) / (__gcd(x, y)); }

signed main() {
  fast_IO;
  int t = 1;
  // cin>>t;
  while (t--) {
    string s, t;
    cin >> s >> t;
    int ans = s.size();
    for (int i = 0; i < s.length() - t.length() - 1; i++) {
      int p = 0, cnt = 0;
      for (int j = i; j < i + t.length(); j++) {
        if (s[j] != t[p++])
          cnt++;
      }
      ans = min(ans, cnt);
    }
    cout << ans;
  }
  return 0;
}

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

#define fast_IO                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define int long long int
#define ll long long
#define ld long double

bool isPrime(ll n) {
  if (n < 2)
    return false;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

ll lcm(ll x, ll y) { return (x * y) / (__gcd(x, y)); }

signed main() {
  fast_IO;
  int t = 1;
  // cin>>t;
  while (t--) {
    string s, t;
    cin >> s >> t;
    int ans = t.size();
    for (int i = 0; i + t.length() - 1 < s.length(); i++) {
      int p = 0, cnt = 0;
      for (int j = i; j < i + t.length(); j++) {
        if (s[j] != t[p++])
          cnt++;
      }
      ans = min(ans, cnt);
    }
    cout << ans;
  }
  return 0;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;

  int ans = T.size();

  for (int i = 0; i < S.size() - T.size() + 1; i++) {
    int count = 0;
    for (int j = 0; j < T.size(); j++) {
      if (T.at(i) != S.at(i + j))
        count++;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

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

int main() {
  string S, T;
  cin >> S >> T;

  int ans = T.size();

  for (int i = 0; i < S.size() - T.size() + 1; i++) {
    int count = 0;
    for (int j = 0; j < T.size(); j++) {
      if (T.at(j) != S.at(i + j))
        count++;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 100000 + 5;
// ------------------------------------
vector<int> v;
// ------------------------------------
// 1 is tru

int main() {
  string s, t, subs;
  int a = 0;
  cin >> s >> t;

  for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      if (s[i] == t[j]) {
        if (i - j >= 0 && i - j + t.length() <= s.length()) {
          subs = s.substr(i - j, t.length());
          for (int k = 0; k < t.length(); k++) {
            if (subs[k] != t[k]) {
              a++;
            }
          }
          v.push_back(a);
          a = 0;
        }
      }
    }
  }
  cout << *min_element(v.begin(), v.end()) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 100000 + 5;
// ------------------------------------
vector<int> v;
// ------------------------------------
// 1 is tru

int main() {
  string s, t, subs;
  int a = 0;
  cin >> s >> t;
  v.push_back(t.length());

  for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      if (s[i] == t[j]) {
        if (i - j >= 0 && i - j + t.length() <= s.length()) {
          subs = s.substr(i - j, t.length());
          for (int k = 0; k < t.length(); k++) {
            if (subs[k] != t[k]) {
              a++;
            }
          }
          v.push_back(a);
          a = 0;
        }
      }
    }
  }
  cout << *min_element(v.begin(), v.end()) << endl;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int kekka, kari;
  kekka = 0;
  kari = 0;
  string iti, ni;
  cin >> iti >> ni;
  for (int i = 0; i < iti.size() - ni.size(); i++) {
    for (int s = 0; s <= ni.size(); s++) {
      if (iti.at(i + s) == ni.at(s)) {
        kari++;
      }
    }
    if (kekka < kari) {
      kekka = kari;
    }
    kari = 0;
  }
  cout << ni.size() - kekka << endl;
}

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

int main() {
  int kekka, kari;
  kekka = 0;
  kari = 0;
  string iti, ni;
  cin >> iti >> ni;
  for (int i = 0; i <= iti.size() - ni.size(); i++) {
    for (int s = 0; s < ni.size(); s++) {
      if (iti.at(i + s) == ni.at(s)) {
        kari++;
      }
    }
    if (kekka < kari) {
      kekka = kari;
    }
    kari = 0;
  }
  cout << ni.size() - kekka << endl;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main() {
  string s, t;
  cin >> s >> t;
  int ans = MOD;
  int temp = 0;
  for (int i = 0; i < (s.size() - t.size() - 1); i++) {
    temp = 0;
    for (int k = 0; k < t.size(); k++) {
      if (s.at(i + k) != t.at(k)) {
        temp++;
      }
    }
    ans = min(ans, temp);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main() {
  string s, t;
  cin >> s >> t;
  int ans = MOD;
  int temp = 0;
  if (s.size() == t.size()) {
    for (int i = 0; i < s.size(); i++) {
      if (s.at(i) != t.at(i)) {
        temp++;
      }
    }
    ans = temp;
  }
  for (int i = 0; i < (s.size() - t.size()); i++) {
    temp = 0;
    for (int k = 0; k < t.size(); k++) {
      if (s.at(i + k) != t.at(k)) {
        temp++;
      }
    }
    ans = min(ans, temp);
  }
  cout << ans << endl;
  return 0;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>

using namespace std;

int main() {
  string S, T;
  cin >> S;
  cin >> T;

  const char *cS = S.c_str();
  const char *cT = T.c_str();

  int max_count = 0;
  for (size_t i = 0; i < (S.size() - T.size() - 1); ++i) {
    int count = 0;
    for (size_t j = 0; j < T.size(); ++j) {
      if (cS[i + j] == cT[j]) {
        ++count;
      }
    }

    if (max_count < count) {
      max_count = count;
    }
  }

  cout << (static_cast<int>(T.size()) - max_count) << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {
  string S, T;
  cin >> S;
  cin >> T;

  const char *cS = S.c_str();
  const char *cT = T.c_str();

  int max_count = 0;
  for (size_t i = 0; i < (S.size() - T.size() + 1); ++i) {
    int count = 0;
    for (size_t j = 0; j < T.size(); ++j) {
      if (cS[i + j] == cT[j]) {
        ++count;
      }
    }

    if (max_count < count) {
      max_count = count;
    }
  }

  cout << (static_cast<int>(T.size()) - max_count) << endl;

  return 0;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define LL long long
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

LL gcd(LL C, LL D) {
  if (C < D)
    gcd(D, C);

  if (C % D == 0)
    return D;
  else
    gcd(D, C % D);
}

int main() {
  string s, t;
  int ans = 0;

  cin >> s >> t;
  for (int i = 0; i < s.length() - t.length() + 1; i++) {
    int cnt = 0;
    rep(j, t.length()) {
      if (s[i + j] == t[j]) {
        cnt++;
      }
    }
    ans = max(ans, cnt);
  }

  return t.length() - ans;
}


Fixed submission:
#include <bits/stdc++.h>

#define LL long long
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

LL gcd(LL C, LL D) {
  if (C < D)
    gcd(D, C);

  if (C % D == 0)
    return D;
  else
    gcd(D, C % D);
}

int main() {
  string s, t;
  int ans = 0;

  cin >> s >> t;
  for (int i = 0; i < s.length() - t.length() + 1; i++) {
    int cnt = 0;
    rep(j, t.length()) {
      if (s[i + j] == t[j]) {
        cnt++;
      }
    }
    ans = max(ans, cnt);
  }

  cout << t.length() - ans << endl;
  return 0;
}
Problem p02571 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int e = s.size();
  int b = t.size();
  int c = 0;
  int m = 0;
  for (int i = 0; i <= e - b; i++) {
    for (int j = 0; j < b; i++) {
      if (t[j] == s[j + i]) {
        c++;
      }
    }
    m = max(m, c);
    c = 0;
  }
  cout << b - m;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int e = s.size();
  int b = t.size();
  int c = 0;
  int m = 0;
  for (int i = 0; i <= e - b; i++) {
    for (int j = 0; j < b; j++) {
      if (t[j] == s[j + i]) {
        c++;
      }
    }
    m = max(m, c);
    c = 0;
  }
  cout << b - m;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int minx = 1001;
  for (int i = 0; i < s.size() - t.size() - 1; i++) {
    int x = 0;
    for (int j = 0; j < t.size(); j++) {
      if (t.at(j) != s.at(i + j)) {
        x += 1;
      }
    }
    minx = min(minx, x);
  }
  cout << minx << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int minx = 10000;
  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    int x = 0;
    for (int j = 0; j < t.size(); j++) {
      if (t.at(j) != s.at(i + j)) {
        x += 1;
      }
    }
    minx = min(minx, x);
  }
  cout << minx << endl;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sort(v) sort(v.begin(), v.end())
#define pb push_back
/*
ll ar[1000000+9]={0};
void seiv() {
ll n=1000000,i,j;
ar[1]=1;
for(i=4;i<=n;i+=2)ar[i]=1;
for(i=3;i<=n;i+=2)
{ if(ar[i]==0)
{ for(j=i*i;j<=n;j+=i*2)ar[j]=1; }
 }
}*/
int main() {
  string s, t;
  ll a, b, c, d, i, j, k, l;
  cin >> s >> t;
  l = 11000000000;
  d = 0;
  for (i = 0; i < s.size() - t.size() - 1; i++) {
    d = 0;
    for (j = 0, k = i; j < t.size(); j++, k++) {
      if (s[k] != t[j])
        d++;
    }
    // cout<<k<<endl;
    l = min(l, d);
  }
  cout << l << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sort(v) sort(v.begin(), v.end())
#define pb push_back
/*
ll ar[1000000+9]={0};
void seiv() {
ll n=1000000,i,j;
ar[1]=1;
for(i=4;i<=n;i+=2)ar[i]=1;
for(i=3;i<=n;i+=2)
{ if(ar[i]==0)
{ for(j=i*i;j<=n;j+=i*2)ar[j]=1; }
 }
}*/
int main() {
  string s, t;
  ll a, b, c, d, i, j, k, l;
  cin >> s >> t;
  l = 11000000000;
  d = 0;
  for (i = 0; i <= s.size() - t.size(); i++) {
    d = 0;
    for (j = 0, k = i; j < t.size(); j++, k++) {
      if (s[k] != t[j])
        d++;
    }
    // cout<<k<<endl;
    l = min(l, d);
  }
  cout << l << endl;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES // M_PI等のフラグ

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))

using namespace std;

void solve() {
  string S, T;
  cin >> S >> T;

  int ans = T.size();
  for (int i = 0; i < S.size() - T.size() - 1; i++) {
    int ret = 0;
    for (int j = 0; j < T.size(); j++) {
      if (S.at(i + j) != T.at(j))
        ret++;
    }
    ans = min(ans, ret);
  }

  cout << ans << endl;
}

int main(int argc, char const *argv[]) {
  solve();
  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES // M_PI等のフラグ

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))

using namespace std;

void solve() {
  string S, T;
  cin >> S >> T;

  int ans = T.size();
  for (int i = 0; i <= S.size() - T.size(); i++) {
    int ret = 0;
    for (int j = 0; j < T.size(); j++) {
      if (S.at(i + j) != T.at(j))
        ret++;
    }
    ans = min(ans, ret);
  }

  cout << ans << endl;
}

int main(int argc, char const *argv[]) {
  solve();
  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef map<ll, ll> mp;
typedef pair<int, int> pii;
typedef vector<ll> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;

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);
  int m = 1000000007;
  int n;
  cin >> n;
  vi a(n);
  fo(i, n) cin >> a[i];
  int sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = ((sum) % m + (a[i] * a[j]) % m) % m;
    }
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef map<ll, ll> mp;
typedef pair<int, int> pii;
typedef vector<ll> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;

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);
  int m = 1000000007;
  int n;
  cin >> n;
  vi a(n);
  fo(i, n) cin >> a[i];
  ll sum = 0, sum1 = 0;
  // vi temp;
  for (int i = 0; i < n; i++) {
    sum1 += a[i];
    sum1 %= m;
  }

  for (int i = 0; i < a.size(); i++) {
    sum1 -= a[i];
    if (sum1 < 0)
      sum1 += m;
    sum += a[i] * sum1;
    sum %= m;
  }
  cout << sum << endl;
  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<long long> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
  long long C = 1000000007;
  long long Sum = 0;
  for (int i = 0; i < N; i++) {
    for (int j = (i + 1); j < N; j++) {
      Sum += (V.at(i) * V.at(j)) % C;
    }
  }
  cout << Sum % C << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<long long> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
  long long C = 1000000007;
  long long Sum = 0;
  vector<long long> W(N - 1);
  W.at(0) = V.at(0);
  for (int i = 1; i < N - 1; i++) {
    W.at(i) = W.at(i - 1) + V.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    Sum += ((W.at(i) % C) * V.at(i + 1)) % C;
  }
  cout << Sum % C << endl;
}
Problem p02572 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define rep(X, N) for (ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(), (V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main() {

  int n;
  cin >> n;

  vector<ll> a(n);
  vector<ll> b(1);

  rep(i, n) {
    cin >> a[i];
    b.push_back((b[i] + a[i]) % MODN);
  }

  ll ans = 0;

  rep(i, n) {
    ll sum = b[n] - b[i + 1];
    assert(sum >= 0);

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

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define rep(X, N) for (ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(), (V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main() {

  int n;
  cin >> n;

  vector<ll> a(n);
  vector<ll> b(1);

  rep(i, n) {
    cin >> a[i];
    b.push_back((b[i] + a[i]) % MODN);
  }

  ll ans = 0;

  rep(i, n) {
    ll sum = b[n] - b[i + 1];
    if (sum < 0)
      sum += MODN;

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

  cout << ans << endl;

  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<ll> sum(n, 0);
  sum[0] = 0;
  for (ll i = 0; i < n; ++i) {
    sum[i + 1] = (sum[i] + a[n - 1 - i]) % mod;
  }

  ll res = 0;
  for (ll i = 1; i < n; ++i) {
    res += (sum[i] * a[n - 1 - i]) % mod;
  }
  res %= mod;
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<ll> sum(n, 0);
  sum[0] = 0;
  for (ll i = 0; i < n - 1; ++i) {
    sum[i + 1] = (sum[i] + a[n - 1 - i]) % mod;
  }

  ll res = 0;
  for (ll i = 1; i < n; ++i) {
    res += (sum[i] * a[n - 1 - i]) % mod;
  }
  res %= mod;
  cout << res << endl;
  return 0;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
  }
}

Fixed submission:
#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;
  }
}
Problem p02572 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}

Fixed submission:
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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
*/

Fixed submission:
#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
*/
Problem p02572 (C++)

Buggy submission (status: 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;
}


Fixed submission:
/*----------------------------------------------------*
 * लेखक --> अमित सिंह
 * संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
 *-----------------------------------------------------*/
#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;
}
Problem p02572 (C++)

Buggy submission (status: 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;
}


Fixed submission:
#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;
}