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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> void debug(T begin, T end) {
  for (T i = begin; i != end; ++i)
    cout << *i << " ";
  cout << endl;
}

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main() {
  string s;
  while (cin >> s && s != "0") {
    int dp[80001][11] = {};
    int N = s.size();
    int ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 11; j++) {
        dp[i + 1][(j * 10 + s[i] - '0') % 11] += dp[i][j];
      }
      if (s[i] != '0')
        dp[i + 1][s[i] - '0'] += 1;
      ans += dp[i + 1][0];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> void debug(T begin, T end) {
  for (T i = begin; i != end; ++i)
    cout << *i << " ";
  cout << endl;
}

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main() {
  string s;
  while (cin >> s && s != "0") {
    reverse(s.begin(), s.end());
    int N = s.size();
    int ans = 0;
    for (int i = 0; i < N; i++) {
      int sum = 0;
      int mul = 1;
      for (int j = i; j < N; j++) {
        sum += (s[j] - '0') * mul;
        sum %= 11;
        if (sum == 0 && s[j] != '0') {
          ans++;
          // cout<<s.substr(i, j - i + 1)<<endl;
        }
        mul = (mul * 10) % 11;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01300 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int solve() {
  int res = 0, memo[12][12];
  vector<int> a, b, imemo[12][12];
  memset(memo, -1, sizeof(memo));
  a.push_back(n[0] - '0'), a.push_back(n[0] - '0'), b.push_back(0);
  for (int i = 2; i < n.size(); i += 2)
    a.push_back((a.back() + n[i] - '0') % 11), a.push_back(a.back());
  for (int i = 1; i < n.size(); i += 2)
    b.push_back((b.back() + n[i] - '0') % 11), b.push_back(b.back());
  if (n.size() % 2 == 0)
    b.erase(--b.end());
  else
    a.erase(--a.end());

  for (int i = 0, A = 0, B = 0; i < n.size() - 1; i++) {
    if (n[i] == '0')
      continue;

    if (memo[A][B] == -1) {
      memo[A][B] = 0;
      for (int j = i + 1; j < n.size(); j++)
        if (((a[j] + A) - (b[j] + B)) % 11 == 0)
          memo[A][B]++, imemo[A][B].push_back(j);
      reverse(imemo[A][B].begin(), imemo[A][B].end());
    }

    while (imemo[A][B].size() && imemo[A][B].back() < i)
      memo[A][B]--, imemo[A][B].erase(--imemo[A][B].end());
    res += memo[A][B];
    if (i % 2 == 0)
      A = 11 - a[i] % 11;
    else
      B = 11 - b[i] % 11;
  }
  return res;
}

int main() {
  while (1) {
    cin >> n;
    if (n == "0")
      break;
    cout << solve() << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int solve() {
  int res = 0, memo[12][12];
  vector<int> a, b, imemo[12][12];
  memset(memo, -1, sizeof(memo));
  a.push_back(n[0] - '0'), a.push_back(n[0] - '0'), b.push_back(0);
  for (int i = 2; i < n.size(); i += 2)
    a.push_back((a.back() + n[i] - '0') % 11), a.push_back(a.back());
  for (int i = 1; i < n.size(); i += 2)
    b.push_back((b.back() + n[i] - '0') % 11), b.push_back(b.back());
  if (n.size() % 2 == 0)
    b.erase(--b.end());
  else
    a.erase(--a.end());

  for (int i = 0, A = 0, B = 0; i < n.size() - 1; i++) {
    if (n[i] == '0')
      continue;

    if (memo[A][B] == -1) {
      memo[A][B] = 0;
      for (int j = i + 1; j < n.size(); j++)
        if (((a[j] + A) - (b[j] + B)) % 11 == 0)
          memo[A][B]++, imemo[A][B].push_back(j);
    }

    while (imemo[A][B].size() && imemo[A][B][0] < i)
      memo[A][B]--, imemo[A][B].erase(imemo[A][B].begin());
    res += memo[A][B];
    if (i % 2 == 0)
      A = 11 - a[i] % 11;
    else
      B = 11 - b[i] % 11;
  }
  return res;
}

int main() {
  while (1) {
    cin >> n;
    if (n == "0")
      break;
    cout << solve() << endl;
  }
  return 0;
}
Problem p01300 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))

typedef complex<double> P;
typedef long long ll;

void PrintCase(int number) { printf("Case #%d: ", number); }

int main() {
  string str;
  while (cin >> str && str != "0") {
    int cnt = 0;
    // ツつアツつアツづ慊づづづ個青板篠堋つェツ可スツ嘉アツ出ツ個サツつオツづつ「ツづゥツつゥ
    int ap[2][11];
    for (int i = 0; i < 2; i++)
      fill(ap[i], ap[i] + 11, 0);
    ap[(str.size() - 1) % 2][str[str.size() - 1] - '0']++;
    for (int i = str.size() - 2; i >= 0; i--) {
      int sum = 0;
      if (str[i] == '0') {
        for (int j = 0; j <= 10; j++)
          ap[(i) % 2][j] = ap[(i + 1) % 2][j];
        ap[i % 2][0]++;
        continue;
      }
      int ad = str[i] - '0';
      if ((str.size() - 1 - i) % 2 != 0) {
        ad *= 10;
      }
      // jツづ個青板篠堋づ可督楪達ツづつォツづゥツ青板篠堋つェツつ「ツつュツづつ堕カツ催敖つキツづゥツつゥ
      for (int j = 0; j <= 10; j++)
        ap[(i) % 2][j] = ap[(i + 1) % 2][(j - ad + 110) % 11];
      ap[i % 2][ad % 11]++;
      cnt += ap[i % 2][0];
      // for(int j = i; j >= 0; j--){
      //     if(str[j]=='0')
      //         continue;
      //     if((i-j)%2==0)
      //         sum+=str[j]-'0';
      //     else
      //         sum+=(str[j]-'0')*10;
      //     if(sum!=0&&sum%11==0)
      //         cnt++;
      // }
    }
    cout << cnt << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))

typedef complex<double> P;
typedef long long ll;

void PrintCase(int number) { printf("Case #%d: ", number); }

int main() {

  // for(int i = 1; i < 1000; i++){
  //     cout<<11*i<<endl;
  // }
  string str;
  while (cin >> str && str != "0") {
    int cnt = 0;
    for (int i = str.size() - 1; i >= 0; i--) {
      int sum = 0;
      for (int j = i; j >= 0; j--) {
        if (str[j] == '0')
          continue;
        if ((i - j) % 2 == 0)
          sum += str[j] - '0';
        else
          sum += (str[j] - '0') * 10;
        if (sum != 0 && sum % 11 == 0) {
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }

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

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

int main() {
  string chars;
  int inp;
  while (cin >> chars && chars != "0") {
    // inp=atoi(chars.c_str());
    int keta = chars.size();
    int ans = 0;
    int amari[keta][11];
    int t;
    int s;
    for (int i = 0; i < keta; i++) {
      t = (int)chars[i] - (int)'0';

      if (i == 0) {
        for (int j = 0; j < 11; j++) {
          amari[i][j] = 0;
        }
      } else {

        for (int j = 0; j < 11; j++) {
          s = ((10 - j) + t + 1) % 11;
          amari[i][j] = amari[i - 1][s];
        }
      }
      if (t != 0) {
        amari[i][t]++;
      }

      ans += amari[i][0];
    }

    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  string chars;
  int inp;
  while (cin >> chars && chars != "0") {
    inp = atoi(chars.c_str());
    int keta = 0;
    while ((int)pow(10, keta) <= inp) {
      keta++;
    }
    int ans = 0;
    int amari[keta][11];
    int t;
    int s;
    for (int i = 0; i < keta; i++) {
      t = inp / (int)pow(10, keta - i - 1) % 10;

      if (i == 0) {
        for (int j = 0; j < 11; j++) {
          amari[i][j] = 0;
        }
      } else {

        for (int j = 0; j < 11; j++) {
          s = ((10 - j) + t + 1) % 11;
          amari[i][j] = amari[i - 1][s];
        }
      }
      if (t != 0) {
        amari[i][t]++;
      }

      ans += amari[i][0];
    }

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

#include <bits/stdc++.h>
/*
 */

using namespace std;

int main() {
  string S;
  while (cin >> S) {
    if (S == "0") {
      break;
    }
    long long int ans = 0;
    vector<vector<long long int>> dp(S.length(), vector<long long int>(2));
    for (size_t i = 0; i < S.length(); i++) {
      if (i) {
        dp[i] = dp[i - 1];
      }
      if (i % 2) {
        dp[i][0] += S[i] - '0';
      } else {
        dp[i][1] -= S[i] - '0';
      }
    }
    for (size_t i = 0; i < S.length(); i++) {
      dp[i][0] += dp[i][1];
      while (dp[i][0] < 0) {
        dp[i][0] += 11;
      }
      dp[i][0] %= 11;
    }
    map<long long int, long long int> X;
    X[0]++;
    for (size_t i = 0; i < S.length(); i++) {
      ans += X[dp[i][0]];
      if (!(i < S.length() - 1 && S[i + 1] == '0')) {
        X[dp[i][0]]++;
      }
    }

    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
/*
 */

using namespace std;

int main() {
  string S;
  while (cin >> S) {
    if (S == "0") {
      break;
    }
    long long int ans = 0;
    for (size_t i = 0; i < S.length(); i++) {
      if (S[i] == '0') {
        continue;
      }
      long long int num = 0;
      for (size_t j = i; j < S.length(); j++) {
        num *= 10;
        num += S[j] - '0';
        num %= 11;
        if (num == 0) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p01300 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

int main() {
  for (string s; cin >> s && s != "0";) {
    int ans = 0;
    int e[11] = {}, o = 0;
    REP(i, s.size()) {
      int d = s[i] - '0';
      if (d != 0)
        e[o]++;
      o = (o + (i & 1 ? 11 - d : d)) % 11;
      ans += e[o];
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

int main() {
  for (string s; getline(cin, s) && s != "0";) {
    int ans = 0;
    int ps[80002] = {};
    REP(i, s.size())
    ps[i + 2] = ps[i] + s[i] - '0';
    REP(i, s.size()) if (s[i] != '0') FOR(j, i + 1, s.size()) {
      int m = (i ^ j) & 1;
      if ((ps[j + 2 - m] - ps[i]) % 11 == (ps[j + 1 + m] - ps[i + 1]) % 11)
        ans++;
    }
    printf("%d\\n", ans);
  }

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

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

string S;
int dp[80000][11];

int rec(int idx, int mod) {
  if (idx == S.size())
    return (mod == 0);
  if (~dp[idx][mod])
    return (dp[idx][mod]);
  return (dp[idx][mod] =
              rec(idx + 1, (mod * 10 + S[idx] - '0') % 11) + (mod == 0));
}

int main() {
  while (cin >> S, S != "0") {
    memset(dp, -1, sizeof(dp));
    int ret = 0;
    for (int i = 0; i < S.size(); i++) {
      if (S[i] != '0')
        ret += rec(i + 1, S[i] - '0');
    }
    cout << ret << endl;
  }
}

Error: TLE

Fixed submission:

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

string S;
int dp[80000][11];

int rec(int idx, int mod) {
  if (idx == S.size())
    return (mod == 0);
  if (~dp[idx][mod])
    return (dp[idx][mod]);
  return (rec(idx + 1, (mod * 10 + S[idx] - '0') % 11) + (mod == 0));
}

int main() {
  while (cin >> S, S != "0") {
    memset(dp, -1, sizeof(dp));
    int ret = 0;
    for (int i = 0; i < S.size(); i++) {
      if (S[i] != '0')
        ret += rec(i + 1, S[i] - '0');
    }
    cout << ret << endl;
  }
}
Problem p01300 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int main() {
  string s;
  while (cin >> s, s != "0") {
    if (s.size() < 2) {
      cout << 0 << endl;
      continue;
    }
    ll d[80005][11] = {{}};
    ll w[80005] = {};
    ll i, j, k, ans = 0;
    for (i = 0; i < s.size(); i++) {
      w[i + 2] = (w[i] + s[i] - '0') % 11;
    }
    for (i = 0; i + 1 < s.size(); i += 2) {
      k = (11 + s[i] - s[i + 1]) % 11;
      for (j = 0; j < 11; j++) {
        d[i + 2][(j + k) % 11] = d[i][j];
      }
      if (s[i] != '0')
        d[i + 2][k]++;
      // for(j=0;j<11;j++) cout << d[i+2][j] << " ";
      // cout << endl;
      ans += d[i + 2][0];
      // cout << ans << "/";
      if (i + 2 < s.size()) {
        k = s[i + 2] - '0';
        ans += d[i + 2][(11 - k) % 11];
      }
      // cout << ans << " ";
    }
    // cout << endl;
    for (i = 1; i + 1 < s.size(); i += 2) {
      k = (11 + s[i] - s[i + 1]) % 11;
      for (j = 0; j < 11; j++) {
        d[i + 2][(j + k) % 11] = d[i][j];
      }
      if (s[i] != '0')
        d[i + 2][k]++;
      // for(j=0;j<11;j++) cout << d[i+2][j] << " ";
      // cout << endl;
      ans += d[i + 2][0];
      // cout << ans << "/";
      if (i + 2 < s.size()) {
        k = s[i + 2] - '0';
        ans += d[i + 2][(11 - k) % 11];
      }
      // cout << ans << " ";
    }
    // cout << endl;
    cout << ans << endl;
    // cout <<endl;
    s = "";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int main() {
  string s;
  while (cin >> s, s != "0") {
    if (s.size() == 1) {
      cout << 0 << endl;
      s = "";
      continue;
    }
    ll d[80005] = {};
    ll i, j, k, ans = 0;
    for (i = 0; i < s.size(); i++) {
      d[i + 2] = d[i] + s[i] - '0';
    }
    for (i = 0; i < s.size(); i++) {
      if (s[i] == '0')
        continue;
      for (j = i + 1; j < s.size(); j++) {
        if ((j - i) % 2 == 0) {
          if (((d[j + 2] - d[i]) - (d[j + 1] - d[i + 1])) % 11 == 0)
            ans++;
        } else {
          if (((d[j + 1] - d[i]) - (d[j + 2] - d[i + 1])) % 11 == 0)
            ans++;
        }
      }
    }
    cout << ans << endl;
    s = "";
  }
  return 0;
}
Problem p01300 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  string s;
  while (cin >> s, s != "0") {
    int ans = 0, c[2][11] = {0}, d;
    rep(i, s.size()) {
      d = (i & 1 ? 10 : 1) * (s[i] - '0');
      rep(j, 11) c[i & 1][(j + d) % 11] = c[i & 1 ^ 1][j];
      if (s[i] != '0')
        c[i & 1][d % 11]++;
      ans += c[i & 1][0];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string n;
  while (cin >> n, n != "0") {
    int ans = 0, i, j, k, s = n.size();
    for (i = 0; i < s; i++)
      if (n[i] != '0')
        for (j = i; j < s; j++) {
          int e = 0, o = 0;
          for (k = i; k <= j; k++)
            k & 1 ? (e += n[k] - '0') : (o += n[k] - '0');
          ans += (e - o) % 11 == 0;
        }
    cout << ans << endl;
  }
  return 0;
}
Problem p01300 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define inf (1 << 28)
#define MAX 90000

using namespace std;

string line;

void compute() {
  int dp[2][11];
  rep(i, 2) rep(j, 11) dp[i][j] = 0;
  int N = line.size();
  int ans = 0;
  dp[1][line[0] - '0'] = 1;
  REP(i, 1, N) {
    rep(j, 11) dp[(i + 1) & 1][j] = 0;
    rep(j, 11) dp[(i + 1) & 1][((j * 10) % 11 + line[i] - '0') % 11] +=
        dp[i & 1][j];
    if (line[i] != '0')
      dp[(i + 1) & 1][line[i] - '0']++;
    // rep(j,11)cout << dp[(i+1)&1][j] << " ";
    // cout << endl;
    ans += dp[(i + 1) & 1][0];
  }

  cout << ans << endl;
}

int main() {
  while (cin >> line, line != "0")
    compute();
  return 0;
}

/*
string line;
int sum[4][MAX];

void compute()
{
  reverse(line.begin(),line.end());
  int N = line.size();
  rep(i,4)rep(j,N+5)sum[i][j] = 0;
  rep(i,N)sum[i&1][i] = line[i]-'0';
  REP(i,1,N)sum[!(i&1)+2][i] = line[i]-'0';
  rep(i,4)rep(j,N)sum[i][j] += (j-1>=0?sum[i][j-1]:0);

  //set<string> ans;
  int cnt = 0;
  rep(s,N)
    {
      REP(t,s+1,N)
        {
          if(line[t] == '0')continue;
          int base = (s%2?2:0);
          int cost = (sum[base][t]-(s-1>=0?sum[base][s-1]:0)) -
(sum[base+1][t]-(s-1>=0?sum[base+1][s-1]:0)); if(!cost || cost%11 == 0)cnt++;
        }
    }

  cout << cnt << endl;
  //for(set<string>::iterator it = ans.begin(); it != ans.end();it++)cout << *it
<< endl;
  //cout << ans.size() << endl;

}

int main()
{
  while(cin >> line,line != "0")compute();
  return 0;
}
*/

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define inf (1 << 28)
#define MAX 90000
using namespace std;

string line;
int sum[4][MAX];

void compute() {
  reverse(line.begin(), line.end());
  int N = line.size();
  rep(i, 4) rep(j, N + 5) sum[i][j] = 0;
  rep(i, N) sum[i & 1][i] = line[i] - '0';
  REP(i, 1, N) sum[!(i & 1) + 2][i] = line[i] - '0';
  rep(i, 4) rep(j, N) sum[i][j] += (j - 1 >= 0 ? sum[i][j - 1] : 0);
  /*
  rep(i,4)
    {
      cout << i << "-th" << endl;
      rep(j,N)cout << sum[i][j] << " ";
      cout << endl;
    }
  */
  // set<string> ans;
  int cnt = 0;
  rep(s, N) {
    REP(t, s + 1, N) {
      if (line[t] == '0')
        continue;
      int base = (s % 2 ? 2 : 0);
      int cost = (sum[base][t] - (s - 1 >= 0 ? sum[base][s - 1] : 0)) -
                 (sum[base + 1][t] - (s - 1 >= 0 ? sum[base + 1][s - 1] : 0));
      if (!cost || cost % 11 == 0)
        cnt++;
    }
  }

  cout << cnt << endl;
  // for(set<string>::iterator it = ans.begin(); it != ans.end();it++)cout <<
  // *it << endl; cout << ans.size() << endl;
}

int main() {
  while (cin >> line, line != "0")
    compute();
  return 0;
}
Problem p01300 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int solve(string s) {
  int res = 0;
  vector<vector<int>> dp(2, vector<int>(11, 0));
  for (int i = 0; i < (int)s.size(); ++i) {
    int k = s[i] - '0';
    dp[i & 1].assign(11, 0);
    for (int j = 0; j < 11; ++j)
      dp[i & 1][(10 * j + k) % 11] += dp[~i & 1][j];
    if (k)
      dp[i & 1][k]++;
    res += dp[i & 1][0];
  }
  return res;
}

int main() {
  for (string in; cin >> in, in != "0";)
    cout << solve(in) << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

string in;

bool calc(string x) {
  return (int)x.size() <= 16
             ? stoll(x) % 11 == 0
             : calc(to_string(stoll(x.substr(0, 16)) % 11) + x.substr(16));
}

int solve() {
  int res = 0;
  for (int i = 2; i <= (int)in.size(); ++i) {
    for (int j = 0; i + j <= (int)in.size(); ++j) {
      string x = in.substr(j, i);
      if (x[0] == '0')
        continue;
      res += calc(x);
    }
  }
  return res;
}

int main() {
  while (cin >> in, in != "0")
    cout << solve() << '\\n';
  return 0;
}
Problem p01300 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;

string str;
int cnt[11];

void solve() {
  rep(i, 11) cnt[i] = 0;
  int t = 0;
  int ans = 0;
  rep(i, str.size()) {
    int x = str[i] - '0';
    if (i % 2 == 0)
      t = (t + x) % 11;
    else
      t = (t + 11 - x) % 11;
    cnt[t]++;
  }
  if (str[0] != '0')
    ans += cnt[0];
  t = 0;
  rep(i, str.size() - 1) {
    int x = str[i] - '0';
    if (i % 2 == 0)
      t = (t + x) % 11;
    else
      t = (t + 11 - x) % 11;
    cnt[t]--;
    if (str[i + 1] - '0' == 0)
      continue;
    ans += cnt[t];
  }
  cout << ans << endl;
}

int main() {
  while (true) {
    cin >> str;
    if (str == "0")
      break;
    solve();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;

string str;

void solve() {
  int ans = 0;
  rep(i, str.size()) {
    int cnt = str[i] - '0';
    if (cnt == 0)
      continue;
    int x = 0;
    for (int j = i + 1; j < str.size(); j++) {
      x = x ^ 1;
      if (x)
        cnt -= str[j] - '0';
      else
        cnt += str[j] - '0';
      ans += (cnt % 11 == 0);
    }
  }
  cout << ans << endl;
}

int main() {
  while (true) {
    cin >> str;
    if (str == "0")
      break;
    solve();
  }
}