Problem p02555 (C++)

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

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
/*
struct UnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> size;

    //こいつがいわゆるコンストラクタ
    //初期化している
    UnionFind(int N) : par(N),rank(N),size(N){
        for(int i=0;i<N;i++){
            par[i]=i;
            size[i]=1;
            rank[i]=0;
        }
    }

    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }


    void unite(int x, int y){
        int rx,ry;
        rx = find(x);
        ry = find(y);
        if(rx == ry){
            return;
        }
        else{
            if(rank[rx]<rank[ry]){
                par[rx]=ry;
                size[ry]+=size[rx];
            }
            else{
                par[ry]=rx;
                size[rx]+=size[ry];
                if(rank[rx]==rank[ry]){
                    rank[rx]++;
                }
            }
        }
    }


    bool same(int x,int y){
        return find(x) == find(y);
    }
};
*/
ll inf = 1000000000 + 7;
int main() {
  ll S;
  cin >> S;
  vector<ll> A(S, 0);
  vector<ll> B(S, 0);
  A.at(2) = 1;
  B.at(2) = 1;
  for (ll i = 3; i < S; i++) {
    A.at(i) = B.at(i - 3) + 1;
    B.at(i) = A.at(i) + B.at(i - 1);
    A.at(i) = A.at(i) % inf;
    B.at(i) = B.at(i) % inf;
  }
  cout << A.at(S - 1) << endl;
}

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

/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/
/*
struct UnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> size;

    //こいつがいわゆるコンストラクタ
    //初期化している
    UnionFind(int N) : par(N),rank(N),size(N){
        for(int i=0;i<N;i++){
            par[i]=i;
            size[i]=1;
            rank[i]=0;
        }
    }

    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }


    void unite(int x, int y){
        int rx,ry;
        rx = find(x);
        ry = find(y);
        if(rx == ry){
            return;
        }
        else{
            if(rank[rx]<rank[ry]){
                par[rx]=ry;
                size[ry]+=size[rx];
            }
            else{
                par[ry]=rx;
                size[rx]+=size[ry];
                if(rank[rx]==rank[ry]){
                    rank[rx]++;
                }
            }
        }
    }


    bool same(int x,int y){
        return find(x) == find(y);
    }
};
*/
ll inf = 1000000000 + 7;
int main() {
  ll S;
  cin >> S;
  vector<ll> A(S, 0);
  vector<ll> B(S, 0);
  if (S > 2) {
    A.at(2) = 1;
    B.at(2) = 1;
  }
  if (S > 3) {
    for (ll i = 3; i < S; i++) {
      A.at(i) = B.at(i - 3) + 1;
      B.at(i) = A.at(i) + B.at(i - 1);
      A.at(i) = A.at(i) % inf;
      B.at(i) = B.at(i) % inf;
    }
  }
  cout << A.at(S - 1) << endl;
}