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

//
//  main.cpp
//  B
//
//  Created by Yoshinao Itakura on 2020/08/22.
//  Copyright © 2020 Yoshinao Itakura. All rights reserved.
//

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <typeinfo>
#include <vector>
using namespace std;

int main(int argc, const char *argv[]) {
  string S;
  cin >> S;
  int sum = 0;

  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == '0')
      sum += 0;
    else if (S[i] == '1')
      sum = sum + 1;
    else if (S[i] == '2')
      sum += 2;
    else if (S[i] == '3')
      sum += 3;
    else if (S[i] == '4')
      sum += 4;
    else if (S[i] == '5')
      sum += 5;
    else if (S[i] == '6')
      sum += 6;
    else if (S[i] == '7')
      sum += 7;
    else if (S[i] == '8')
      sum += 8;
    else if (S[i] == '9')
      sum += 9;
  }

  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Error: TLE

Fixed submission:

//
//  main.cpp
//  B
//
//  Created by Yoshinao Itakura on 2020/08/22.
//  Copyright © 2020 Yoshinao Itakura. All rights reserved.
//

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main(int argc, const char *argv[]) {
  long long N;
  cin >> N;
  int answer = 0;
  while (N >= 0) {
    answer += N % 10;
    N = N / 10;
  }
  if (answer % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define PI 3.141592653589
using namespace std;
using ll = long long;

template <typename T_char> T_char ToUpper(T_char cX) { return toupper(cX); }

int func(int n) {
  int tmp = 0;
  while (n > 0) {
    tmp += n % 10;
    n = n / 10;
  }
  return tmp;
}
int main() {
  string n;
  cin >> n;
  int last = n.size();
  int sum = 0;
  for (int i = 0; i < last; ++i) {
    int num = n[i] - '0';
    sum += func(num);
  }

  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define PI 3.141592653589
using namespace std;
using ll = long long;

template <typename T_char> T_char ToUpper(T_char cX) { return toupper(cX); }

int func(int n) {
  int tmp = 0;
  while (n > 0) {
    tmp += n % 10;
    n = n / 10;
  }
  return tmp;
}
int main() {
  string n;
  cin >> n;
  int last = n.size();

  string nn = n.substr(last - 3);

  int num = stoi(nn);
  int res = func(num);

  if (res % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02577 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

namespace adaptor = boost::adaptors;
namespace mp = boost::multiprecision;

mp::cpp_int digit_sum(mp::cpp_int n) {
  if (n < 10)
    return n;
  return digit_sum(n / 10) + n % 10;
}

void solve() {
  std::string N;
  std::cin >> N;
  int64_t size = N.size();
  int64_t digit_sum = 0;
  for (int64_t i = 0; i < size; i++) {
    digit_sum += N[i] - '0';
  }

  std::string ans = digit_sum % 9 == 0 ? "Yes" : "No";
  std::cout << ans << std::endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  solve();
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>

namespace adaptor = boost::adaptors;
namespace mp = boost::multiprecision;

mp::cpp_int digit_sum(mp::cpp_int n) {
  if (n < 10)
    return n;
  return digit_sum(n / 10) + n % 10;
}

void solve() {
  mp::cpp_int N;
  std::cin >> N;
  std::string ans = digit_sum(N) % 9 == 0 ? "Yes" : "No";
  std::cout << ans << std::endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  solve();
}
Problem p02577 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int check(string n) {
  // Compute sum of digits
  int l = n.length();
  int digitSum = 0;
  for (int i = 0; i < l; i++)
    digitSum += (n[i] - '0');

  // Check if sum of digits is divisible by 9.
  return (digitSum % 9 == 0);
}
int main() {
  string n;
  cin >> n;
  check(n) ? cout << "Yes" : cout << "No";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string n;
  cin >> n;
  int sum = 0;
  int l = n.length();
  for (int i = 0; i < l; l++) {
    sum += n[i];
  }
  if (sum % 9 == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  char N[200010];
  cin >> N;
  int n = strlen(N);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += N[i] - '0';
  }
  sum %= 9;
  if (sum == 0)
    cout << "Yes" << endl;
  if (sum != 0)
    cout << "No" << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 9) >= this->size() (which is 9)


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  string n = to_string(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (n.at(i) == '0')
      sum += 0;
    if (n.at(i) == '1')
      sum += 1;
    if (n.at(i) == '2')
      sum += 2;
    if (n.at(i) == '3')
      sum += 3;
    if (n.at(i) == '4')
      sum += 4;
    if (n.at(i) == '5')
      sum += 5;
    if (n.at(i) == '6')
      sum += 6;
    if (n.at(i) == '7')
      sum += 7;
    if (n.at(i) == '8')
      sum += 8;
    if (n.at(i) == '9')
      sum += 9;
  }
  sum %= 9;
  if (sum == 0)
    cout << "Yes" << endl;
  if (sum != 0)
    cout << "No" << endl;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  string number;
  int c = 0;
  cin >> number;
  for (char n : number) {
    c += (n - '0');
  }
  if (c % 9 == 0) {
    cout << "Yes" << endl;
  }
  if (c % 9 != 0) {
    cout << "No" << endl;
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 9) >= this->size() (which is 9)


Fixed submission:

#include <iostream>

using namespace std;

int main() {
  string num;
  int kakuinokazu[200001];
  int ketasu;
  int sum = 0;
  string a;
  cin >> num;
  ketasu = num.size();
  int i;
  for (i = 1; i <= ketasu; i++) {
    a = num.at(i);
    kakuinokazu[i] = stoi(a);
  }
  for (int j = 1; j <= ketasu; j++) {
    sum = sum + kakuinokazu[j];
  }
  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string n;
  cin >> n;
  if (n == "0") {
    cout << "Yes" << endl;
    return 0;
  }
  int cnt = 0;
  for (int i = 0; i < n.size(); i++) {
    cnt += n[i] - '0';
  }
  if (cnt % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  string n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n.size(); i++) {
    cnt += n[i];
  }
  if (cnt % 9 == 0 || stoi(n) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n.length(); i++) {
    sum += (n[i] - '0');
  }
  if (sum % 9 == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  char c[200005];
  int sum = 1;
  while (cin >> c[sum])
    sum++;
  int ans = 0;
  for (int i = 1; i <= sum; i++) {
    int num = (int)(c[i] - '0');
    sum += num;
  }
  if (sum % 9 == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  string t;
  int k, s = 0, i;
  cin >> t;
  for (i = 0; i < t.length(); i++) {
    s = s + t[i] - 48;
  }

  if (s == 0) {
    cout << "Yes" << endl;
  } else if (s % 9 == 0) {

    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    sum = sum + n;
    sum = sum % 9;
  }
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

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

#include <bits/stdc++.h>
#define INF 1000000007
#define inf 10000000
#define mod 1000000007
using namespace std;
template <typename T> T Max(T X, T Y) { return X > Y ? X : Y; }
template <typename T> T Min(T X, T Y) { return X < Y ? X : Y; }
int sum = 0;
string s;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    int num = s[i] - '0';
    sum += num;
  }
  if (sum % 9 == 0) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INF 1000000007
#define inf 10000000
#define mod 1000000007
using namespace std;
template <typename T> T Max(T X, T Y) { return X > Y ? X : Y; }
template <typename T> T Min(T X, T Y) { return X < Y ? X : Y; }
int sum = 0;
char c[200005];
int main() {
  scanf("%s", c);
  for (int i = 0; i < strlen(c); i++) {
    int num = c[i] - '0';
    sum += num;
  }
  if (sum % 9 == 0) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  int judge;
  for (int i = 0; i < s.size(); i++) {
    judge += s[i] - '0';
    judge = judge % 9;
  }
  if (judge % 9 == 0) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int sum = 0;
  int tmp = a[0];
  for (int i = 0; i < N; i++) {
    if (a[i] < tmp) {
      sum += tmp - a[i];
    } else
      tmp = a[i];
  }
  cout << sum << endl;
}
Problem p02577 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int i, result = 0, n;
  for (i = 0; i < str.size(); i++) {
    n = str[i] - 48;
    result = result + n;
  }
  if (result % 9 == 0) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, sum = 0;
  cin >> n;
  for (i = 0; i < n; ++i) {
    sum = sum + n;
    sum = sum % 9;
  }
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define nl endl
#define in cin
#define out cout
#define ll long long
#define charToInt(c) (c - '0')
int main() {
  ll a, b, c = 0, d, i, j;
  string s;
  in >> s;
  for (i = 0; s[i]; i++) {
    s[i] = s[i] - 48;
    c += s[i];
  }
  if (c % 9 == 0) {
    cout << "Yes" << nl;
  } else {
    cout << "No" << nl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define nl endl
#define in cin
#define out cout
#define ll long long
#define charToInt(c) (c - '0')
int main() {
  ll a, b, c = 0, d, i, j;
  char s[1000];
  in >> s;
  for (i = 0; s[i]; i++) {
    s[i] = s[i] - 48;
    c += s[i];
  }
  if (c % 9 == 0) {
    cout << "Yes" << nl;
  } else {
    cout << "No" << nl;
  }
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

//| #######################|
//|  ADARSH SINGH KUSHWAHA |
//| ###################### |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Bahut_tej ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define frb(i, a, b) for (ll i = a - 1; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define mp map<ll, ll>
#define v vector<ll>
#define srt(v) sort(v.begin(), v.end())
#define mod 1000000007
#define max 1000001
bool prime[max];
void seive() {
  memset(prime, true, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i * i <= max; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= max; j += i) {
        prime[j] = false;
      }
    }
  }
}
void solve() {
  string s;
  cin >> s;
  ll n = s.size();
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    sum += (s[i] - '0');
  }
  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
int main() {
  Bahut_tej;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // int t;
  // cin>>t;
  // while(t--){
  solve();
  //}
  return 0;
}


Error: WA

Fixed submission:

//| #######################|
//|  ADARSH SINGH KUSHWAHA |
//| ###################### |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Bahut_tej ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define frb(i, a, b) for (ll i = a - 1; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define mp map<ll, ll>
#define v vector<ll>
#define srt(v) sort(v.begin(), v.end())
#define mod 1000000007
#define max 1000001
bool prime[max];
void seive() {
  memset(prime, true, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i * i <= max; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= max; j += i) {
        prime[j] = false;
      }
    }
  }
}
void solve() {
  string s;
  cin >> s;
  ll n = s.size();
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    sum += (s[i - '0']);
  }
  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
int main() {
  Bahut_tej;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // int t;
  // cin>>t;
  // while(t--){
  solve();
  //}
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (register int i = a; i <= b; i++)

int n;
char s[200010];
int ans;
inline void solve(int T) {
  cin >> s;
  n = strlen(s);
  rep(i, 0, n - 1) ans += s[i] - '0';
  puts(ans % 9 ? "No" : "Yes");
}

int main() {
  // ios_base::sync_with_stdio(0);
  // cin.tie(0);
  // cout.tie(0);

  int T = 1;
  // cin >> T;
  rep(i, 1, T) solve(i);

  // system("pause");
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (register int i = a; i <= b; i++)

char s[200010];
int ans;
inline void solve(int T) {
  cin >> s;
  rep(i, 0, strlen(s) - 1) ans += s[i] - '0';
  puts(ans % 9 ? "No" : "Yes");
}

int main() {
  // ios_base::sync_with_stdio(0);
  // cin.tie(0);
  // cout.tie(0);

  int T = 1;
  // cin >> T;
  rep(i, 1, T) solve(i);

  // system("pause");
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

int main(void) {
  using namespace std;
  long long i;
  long long sum = 0;
  string s;
  // const char* cs = s.c_str();

  cin >> s;
  // cout << s.length();
  // cout << s << endl;
  /*
  for(int i = 0; i < (int)s.size(); ++i){
    cout << s[i];
    sum = sum + (int)s[i]-48;
  }
  */

  for (int i = 0; i < s.length(); i++) {
    // cout << s[i] << endl;
    sum = sum + ((int)s[i] - 48);
  }
  // cout << sum <<endl;
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>

int main(void) {
  using namespace std;
  long long i;
  long long sum = 0;

  string s;
  const char *cs = s.c_str();
  cin >> s;

  for (int i = 0; i < s.length(); i++) {
    // cout << (int)cs[i] << "\\t" << sum << endl;
    sum = sum + ((int)cs[i] - 48);
  }
  // cout << sum <<endl;
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char a[1000005];
int main() {
  scanf("%s", a + 1);
  int s = 0;
  for (int i = 1; i <= strlen(a + 1); i++) {
    s += a[i] - '0';
  }
  if (s % 9 == 0)
    printf("Yes");
  else
    printf("No");
  return 0;
}

Error: WA

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char a[10005];
int main() {
  scanf("%s", a + 1);
  int s = 0;
  for (int i = 1; i <= strlen(a); i++) {
    s += a[i] - '0';
  }
  if (s % 9 == 0)
    printf("Yes");
  else
    printf("No");
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string n;
  cin >> n;
  int a[n.length()];
  int p[n.length()];
  int sum = 0;
  for (int i = 0; i < n.length(); ++i) {
    a[i] = n.at(i);
    p[i] = a[i] - '0';
    sum += p[i];
  }
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 9) >= this->size() (which is 9)


Fixed submission:

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

int main() {
  string n;
  cin >> n;
  int a[10 ^ 200000];
  int b[10 ^ 200000];
  long long s = 0;
  int j = 0;
  for (int i = 0; i < (10 ^ 200000); ++i) {
    if (n.at(j) == 0) {
      a[j] = 0;
    }
    if (n.at(j) == 1) {
      a[j] = 1;
    }
    if (n.at(j) == 2) {
      a[j] = 2;
    }
    if (n.at(j) == 3) {
      a[j] = 3;
    }
    if (n.at(j) == 4) {
      a[j] = 4;
    }
    if (n.at(j) == 5) {
      a[j] = 5;
    }
    if (n.at(j) == 6) {
      a[j] = 6;
    }
    if (n.at(j) == 7) {
      a[j] = 8;
    }
    if (n.at(j) == 8) {
      a[j] = 8;
    }
    if (n.at(j) == 9) {
      a[j] = 9;
    }
    j += 1;
    b[j] = a[j] % 9;
  }
  j = 0;
  for (int i = 0; i < (10 ^ 200000); ++i) {
    s += b[j];
    j += 1;
  }
  int c;
  c = s % 9;
  if (c != 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
  string str;
  int cnt = 0;
  cin >> str;
  for (int i = 0; i < str.length(); i++) {
    cnt += (int)(str[i] - '0');
  }
  if (cnt % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
  char buff[256];
  int cnt = 0;
  cin >> buff;
  for (int i = 0; i < strlen(buff); i++) {
    cnt += (int)(buff[i] - '0');
  }
  if (cnt != 0 && cnt % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>

using namespace std;

int main() {
  char N[1000000];

  cin >> N;

  int sum = 0;
  int len = strlen(N);

  for (int i = 0; i < len; i++)
    sum += N[i] - '0';

  if ((sum % 9) == 0)
    cout << "Yes";
  else
    cout << "No";
}


Error: WA

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;

int main() {
  char N[1000];

  cin >> N;

  int sum = 0;
  int len = strlen(N);

  for (int i = 0; i < len; i++)
    sum += N[i] - '0';

  if ((sum % 9) == 0)
    cout << "Yes";
  else
    cout << "No";

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

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
int Sum;
char S[300000];
char c;
int main() {
  for (;;) {
    scanf("%c", &c);
    if (c == '\\n')
      break;
    else
      Sum += c - '0';
  }
  printf("%s", Sum % 9 == 0 ? "Yes" : "No");
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
int Sum;
char S[300000];
int main() {
  scanf("%s", S);
  for (int I = 0; I < strlen(S); I++) {
    Sum += S[I] - '0';
  }
  printf("%s", Sum % 9 == 0 ? "Yes" : "No");
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string.h>
using namespace std;

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

  string s;
  int sum = 0;

  getline(cin, s);
  int d = s.size();

  for (int i = 0; i < d; i++) {
    sum += (s[i] - '0');
  }

  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, sum = 0;
  cin >> n;
  for (i = 0; i < n; ++i) {
    sum = sum + n;
    sum = sum % 9;
  }
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 1; i <= (n); i++)
#define drep(i, n) for (int i = (n)-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define rng(a) a.begin(), a.end()
using ll = long long;

using namespace std;

int main() {
  string n;
  cin >> n;
  ll sum = 0;
  rep(i, n.length()) { sum += (int)(n[i] - '0'); }

  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 1; i <= (n); i++)
#define drep(i, n) for (int i = (n)-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define rng(a) a.begin(), a.end()
using ll = long long;

using namespace std;

int main() {
  string n;
  cin >> n;
  reverse(rng(n));
  ll sum = 0;
  while (n.size() > 0) {
    sum += (int)(n[0] - '0');
    reverse(rng(n));
    n.pop_back();
    reverse(rng(n));
  }
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

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

#include <bits/stdc++.h>
using namespace std;
string word;
long long sum, i;

int main() {
  // freopen("test.in", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> word;
  sum = 0;

  for (i = 0; i < word.size(); i++) {
    sum += (word[i] - '0');
    sum %= 9;
  }

  if (sum % 9 == 0) {
    printf("Yes\\n");
  } else {
    printf("No\\n");
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
char word[200005];
long long sum, i;

int main() {
  // freopen("test.in", "r", stdin);
  scanf("%s", word);
  sum = 0;

  for (i = 0; i < strlen(word); i++) {
    sum += (word[i] - '0');
    sum %= 9;
  }

  if (sum % 9 == 0) {
    printf("Yes\\n");
  } else {
    printf("No\\n");
  }

  return 0;
}