Problem:
Repeated Spell
After discovering and investigating the ancient nation of Iwashiro, our researchers finally found a temple in the center of Iwashiro. The temple housed a stone tablet dedicated to the god of Iwashiro. On the tablet, there are two strings of text, one sentence and one spell.
In Iashiro, The number of times a spell appears in a sentence has an important meaning. However, even if the spell appears sporadically in the sentence, it is considered to appear once. For example, if the sentence is "abab" and the spell is "ab", then "ab" appears three times in "abab", including non-consecutive occurrences (three patterns:
ab
ab, ab
ab
,
a
ba
b
.)
Given a sentence and a spell, make a program to output the number of times the spell appears in the sentence.
Input
The input is given in the following format.
t
b
In the first line, the string t represents the text written on the tablet is given. In the second line, the string b represents the spell written on the tablet is given. Both strings are made up of only lowercase letters and are between 1 and 1000 characters long.
Output
Output the number of times the spell appears in a sentence in a line. However, the value can be very large, so output the remainder divided by 1,000,000,007 instead.
Sample Input 1
abab
ab
Sample Output 1
3
Sample Input 2
aaaabaaaabaaaabaaaab
aaaaa
Sample Output 2
4368
Sample Input 3
data
structure
Sample Output 3
0

Submitted solutions:

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

#define int long long

int mod=1000000007;

int dp[1009][1009];

signed main(){
	dp[0][0]=1;
	string s,t;cin>>s>>t;
	int a=s.size(),b=t.size();

	for(int i=0;i<a;i++){
		for(int j=0;j<=b;j++){
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			if(j<b&&s[i]==t[j]){
				dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;
			}
		}
	}

	cout<<dp[a][b]<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 11332
final_rank: 9

code_snippet: #include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, b, e) for (intmax_t i = (b), i##_limit = (e); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class Container>
struct reverse_t {
    Container &c;
    reverse_t(Container &c) : c(c) {}
    auto begin() { return c.rbegin(); }
    auto end() { return c.rend(); }
};

template <class Container>
auto reversed(Container &c) {
    return reverse_t<Container>(c);
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    var(string, t, b);

    size_t T = t.size();
    size_t B = b.size();
    auto dp = makeVector<intmax_t>(-1, T, B);

    const intmax_t MOD = intmax_t(1e9) + 7;
    const auto res = makeFixPoint([&](auto rec, size_t i, size_t j) -> intmax_t {
        if (j == B) return 1;
        if (i == T) return 0;
        auto& ret = dp[i][j];
        if (~ret) return ret;
        ret = 0;
        ret += rec(i + 1, j) % MOD;
        if (t[i] == b[j]) ret = (ret + rec(i + 1, j + 1)) % MOD;
        return ret;
    })(0, 0);

    output(res);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 10988
final_rank: 6

code_snippet: #include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, b, e) for (intmax_t i = (b), i##_limit = (e); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class Container>
struct reverse_t {
    Container &c;
    reverse_t(Container &c) : c(c) {}
    auto begin() { return c.rbegin(); }
    auto end() { return c.rend(); }
};

template <class Container>
auto reversed(Container &c) {
    return reverse_t<Container>(c);
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    var(string, t, b);

    const size_t T = t.size();
    const size_t B = b.size();
    auto dp = makeVector<intmax_t>(-1, T, B);

    const intmax_t MOD = intmax_t(1e9) + 7;
    const auto res = makeFixPoint([&](auto rec, size_t i, size_t j) -> intmax_t {
        if (j == b.size()) return 1;
        if (i == t.size()) return 0;
        auto& ret = dp[i][j];
        if (~ret) return ret;
        ret = 0;
        ret += rec(i + 1, j) % MOD;
        if (t[i] == b[j]) ret = (ret + rec(i + 1, j + 1)) % MOD;
        return ret;
    })(0, 0);

    output(res);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 10948
final_rank: 5

code_snippet: #include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const int MOD=(1e9)+7;
const int mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k;
lol sum[1010][1010];
lol rui[1010][1010];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string t,b;
  cin >>t>>b;
  int T=t.size(),B=b.size();
  
  for(int i=1;i<=B;i++){
    for(int j=1;j<=T;j++){
      rui[i][j]=rui[i][j-1];
      if(b[i-1]==t[j-1]) rui[i][j]++;  
      //cout <<rui[i][j]<<' ';
    }
    //cout <<'\n';
  }

  lol ans=0;
  for(int i=0;i<B;i++){
    for(int j=0;j<T;j++){
      if(b[i]==t[j]){
        if(i==0) sum[i+1][j+1]=sum[i+1][j]+1;
        else{
          sum[i+1][j+1]=sum[i+1][j]+sum[i][j];
        }
      }else sum[i+1][j+1]=sum[i+1][j];
      sum[i+1][j+1]%=MOD;
    }
  }
  /*
  for(int i=0;i<=B;i++){
    for(int j=0;j<=T;j++) cout <<' '<<sum[i][j];
    cout <<'\n';
  }*/
  cout <<sum[B][T]<<'\n';
  return (0);
}
accuracy: 1
time_ms: 10
memory_kb: 19008
final_rank: 13

code_snippet: #include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin Headelr {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define all(x) x.begin(), x.end()
#define rep(i, b, e) for (intmax_t i = (b), i##_limit = (e); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

using imax = intmax_t;
using usize = size_t;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class Container>
struct reverse_t {
    Container &c;
    reverse_t(Container &c) : c(c) {}
    auto begin() { return c.rbegin(); }
    auto end() { return c.rend(); }
};

template <class Container>
auto reversed(Container &c) {
    return reverse_t<Container>(c);
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// }}} End Header

constexpr int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

const auto inside = [](int y, int x, int H, int W) -> bool {
    return (y >= 0 && x >= 0 && y < H && x < W);
};

const imax MOD = imax(1e9) + 7;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    var(string, t, b);

    const usize T = t.size(), B = b.size();
    auto dp = makeVector<imax>(0, T + 1, B + 1);

    rep(i, 0, T) {
        dp[i + 1][1] = dp[i][1] + (t[i] == b[0]);
    }

    rep(i, 0, T) rep(j, 1, B) {
        dp[i + 1][j + 1] += dp[i][j + 1];
        if (t[i] == b[j]) {
            dp[i + 1][j + 1] += dp[i][j];
        }
        dp[i + 1][j + 1] %= MOD;
    }

    output(dp.back().back());

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 10716
final_rank: 3

code_snippet: #include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin Headelr {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define all(x) x.begin(), x.end()
#define rep(i, b, e) for (intmax_t i = (b), i##_limit = (e); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

using imax = intmax_t;
using usize = size_t;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class Container>
struct reverse_t {
    Container &c;
    reverse_t(Container &c) : c(c) {}
    auto begin() { return c.rbegin(); }
    auto end() { return c.rend(); }
};

template <class Container>
auto reversed(Container &c) {
    return reverse_t<Container>(c);
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// }}} End Header

constexpr int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

const auto inside = [](int y, int x, int H, int W) -> bool {
    return (y >= 0 && x >= 0 && y < H && x < W);
};

const imax MOD = imax(1e9) + 7;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    var(string, t, b);

    const usize T = t.size(), B = b.size();
    auto dp = makeVector<imax>(0, T + 1, B + 1);
    // dp[i][j] := t の i 番目までのなかに、b の j 番目までの文字列は何個ふくまれるか。
    dp[0][0] = t[0] == b[0];

    rep(i, 0, T) rep(j, 0, B) {
        if (t[i] == b[j]) {
            dp[i + 1][j + 1] += dp[i][j];
            dp[i + 1][j + 1] %= MOD;
        }
        dp[i + 1][j] += dp[i][j];
        dp[i + 1][j] %= MOD;
    }

    imax res = 0;
    reps(i, 0, T) res = (res + dp[i][B]) % MOD;

    output(res);

    return 0;
}
accuracy: 0.7391304347826086
time_ms: 10
memory_kb: 10768
final_rank: 17

code_snippet: //y16-7
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

#define large 1000000007

string t,b;
LL dp[1000][1000];

LL solve(int sekiban, int jumon){
    if(jumon == b.size()) return 1;
    if(sekiban == t.size()) return 0;
    if(dp[sekiban][jumon] != -1) return dp[sekiban][jumon];
    LL re = 0;
    for(int i=sekiban; i<t.size(); i++){
        if(t[i] == b[jumon]) re += solve(i+1, jumon+1);
    }
    re %= large;
    dp[sekiban][jumon] = re;
    return re;
}

int main(){
    cin >> t >> b;
    for(int i=0; i<t.size(); i++){
        for(int j=0; j<b.size(); j++){
            dp[i][j] = -1;
        }
    }
    cout << solve(0,0) << endl;

    return 0;
}
accuracy: 1
time_ms: 560
memory_kb: 11108
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9
ll mod = 1e9+7;

int main(){
	string t,b;
	cin>>t>>b;
	ll n1 = t.size(),n2 = b.size();
	vector<vector<ll > > dp(n1,vector<ll> (n2,0) );
	for(int i=0;i<n1;i++){
		if(t[i]==b[0])	dp[i][0] = 1;
	}
	if(n1 < n2){
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<n2;i++){
		ll sum = 0;
		for(int j=0;j<i;j++) {
			sum+=dp[j][i-1];
			sum%=mod;
		}
		for(int j=i;j<n1;j++){
			if(t[j]==b[i]) {
				dp[j][i] = sum;
			}
			sum+=dp[j][i-1];
			sum%=mod;
		}
	}
	ll res = 0;
	/*for(int i=0;i<n2;i++){
		for(int j=0;j<n1;j++){
			cout<<dp[i][j]<<' ';
		}
		cout<<endl;
	}*/
	for(int i=0;i<n1;i++) {
		res += dp[i][n2-1];
		res %= mod;
	}
	cout<<res<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 10876
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9
ll mod = 1e9+7;

int main(){
	string t,b;
	cin>>t>>b;
	ll n1 = t.size(),n2 = b.size();
	vector<vector<ll > > dp(n1,vector<ll> (n2,0) );
	for(int i=0;i<n1;i++){
		if(t[i]==b[0])	dp[i][0] = 1;
	}
	if(n1 < n2){
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<n2;i++){
		ll sum = 0;
		for(int j=0;j<i;j++) {
			sum+=dp[j][i-1];
			sum%=mod;
		}
		for(int j=i;j<n1;j++){
			if(t[j]==b[i]) {
				dp[j][i] = sum;
			}
			sum+=dp[j][i-1];
			sum%=mod;
		}
	}
	ll res = 0;
	/*for(int i=0;i<n2;i++){
		for(int j=0;j<n1;j++){
			cout<<dp[i][j]<<' ';
		}
		cout<<endl;
	}*/
	for(int i=0;i<n1;i++) {
		res += dp[i][n2-1];
		res %= mod;
	}
	cout<<res<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 10692
final_rank: 2

code_snippet: #include <iostream>
using namespace std;

long long MOD = 1000000007;
long long dp[1010][1010];

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

    for(int i = 0; i <= b.size(); i++){
        dp[0][i] = 0;
    }
    for(int i = 0; i <= t.size(); i++){
        dp[i][0] = 1;
    }

    for(int i = 0; i < t.size(); i++){
        for(int j = 0; j < b.size(); j++){
            if(t[i] == b[j]){
                dp[i+1][j+1] = (dp[i][j+1] + dp[i][j]) % MOD;
            }else{
                dp[i+1][j+1] = dp[i][j+1];
            }
        }
    }

    cout << dp[t.size()][b.size()] << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 11104
final_rank: 8

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

long long mod = 1000000007, dp[1009][1009]; string S, T;

int main() {
	cin >> S >> T;
	dp[0][0] = 1;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j <= T.size(); j++) {
			if (j < T.size() && S[i] == T[j]) { dp[i + 1][j + 1] += dp[i][j]; dp[i + 1][j + 1] %= mod; }
			dp[i + 1][j] += dp[i][j]; dp[i + 1][j] %= mod;
		}
	}
	cout << dp[S.size()][T.size()] << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 11092
final_rank: 7

code_snippet: #include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main(void){
	char a[1001],b[1001];
	int x,y,cnt;
	scanf("%s %s",a,b);
	x=strlen(b);  y=strlen(a);
	int dp[x][y],i,j,k;
	for(i=0;i<x;i++){
		for(j=0;j<y;j++) dp[i][j]=0;
	}
//printf("x=%d y=%d\n",x,y);
	for(i=0;i<y;i++){
		if(b[0]==a[i]) dp[0][i]=1;
//printf(" %d",dp[0][i]);
	}
//printf("\n");
	for(i=1;i<x;i++){
		for(j=i-1;j<y-1;j++){
			if(dp[i-1][j]>0){
//printf("j=%d ",j);	
				for(k=j+1;k<y;k++){
					if(b[i]==a[k])    dp[i][k]=(dp[i][k]+dp[i-1][j])%1000000007;
//printf(" %d",dp[i-1][j]);
				}
//printf("\n");
			}
/*for(k=0;k<y;k++)printf(" %d",dp[i][k]);
printf("\n");*/
		}
	}
/*for(i=0;i<x;i++){
	printf("%d ",i);
	for(j=0;j<y;j++) printf(" %d",dp[i][j]);
	printf("\n");
}*/
	cnt=0;
	for(i=0;i<y;i++) cnt=(cnt+dp[x-1][i])%1000000007;
	printf("%d\n",cnt);
	return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 7120
final_rank: 1

code_snippet: #include<iostream>
#include<string>
using namespace std;
int sht[1000][1000];

int main(){
 string t;//原文
 string b;//呪文
 int i,j,k,ans=0;
 
 for(i=0;i<1000;i++){
 	for(j=0;j<1000;j++){
		sht[i][j]=0;
	}
 }
 
 cin>>t>>b;
 //1行目
 for(i=0;i<t.size();i++){
 	if(b[0]==t[i]){
		sht[i][0]=1;
	}else{
		sht[i][0]=0;
	}
 }
 //2行目以降
 for(i=1;i<b.size();i++){
 	for(j=0;j<t.size();j++){
		if(b[i]==t[j] && j>=i){
			for(k=0;k<j;k++){
				sht[j][i]=(sht[j][i]+sht[k][i-1])%1000000007;
			}
		}
	}
 }
 for(j=0;j<t.size();j++){
 	ans=(ans+sht[j][i-1])%1000000007;
 }
 cout<<ans<<endl;
}
accuracy: 1
time_ms: 910
memory_kb: 7140
final_rank: 14

code_snippet: #include<iostream>
#include<string>
using namespace std;
int sht[1000][1000];

int main(){
 string t;//原文
 string b;//呪文
 long long int i,j,k,ans=0;
 
 for(i=0;i<1000;i++){
 	for(j=0;j<1000;j++){
		sht[i][j]=0;
	}
 }
 
 cin>>t>>b;
 //1行目
 for(i=0;i<t.size();i++){
 	if(b[0]==t[i]){
		sht[i][0]=1;
	}else{
		sht[i][0]=0;
	}
 }
 //2行目以降
 for(i=1;i<b.size();i++){
 	for(j=0;j<t.size();j++){
		if(b[i]==t[j] && j>=i){
			for(k=0;k<j;k++){
				sht[j][i]=(sht[j][i]+sht[k][i-1])%1000000007;
			}
		}
	}
 }
 for(j=0;j<t.size();j++){
 	ans=(ans+sht[j][i-1])%1000000007;
 }
 cout<<ans<<endl;
}
accuracy: 1
time_ms: 900
memory_kb: 7128
final_rank: 12

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

long long int p[1000][1000];

int main(){

string A;
string B;

long long int j=0;
long long int i=0;
long long int c=0;

long long int answer=0;
long long int final=0;

long long int n=0;//上の文の文字数
long long int m=0;//下の文の文字数

cin>>A;
cin>>B;

n=A.size(); //4
m=B.size(); //2

/////p全部に0を代入する///////

for(i=0;i<1000;i++){
for(j=0;j<1000;j++){
	p[j][i]=0;
}
}

//////////////////////////////

////一番上の段だけみる////

for(i=0;i<n;i++){
	if(A[i]==B[0]){
		p[i][0]=1;			
	}
}

///////////////////////




for(j=1;j<m;j++){   //j=1  
for(i=0;i<n;i++){   //i=0,1,2,3

	if(A[i]==B[j]){
		for(c=0;c<i;c++){
			p[i][j]=p[i][j]+p[c][j-1]%1000000007; //
		}
		//cout<<p[i][j]%1000000007;			
	}else{
		//cout<<0;
	}
	
}

//cout<<endl;

}

for(i=0;i<n;i++){
	answer=answer%1000000007+p[i][m-1]%1000000007;
}

final=answer%1000000007;

cout<<final<<endl;

}
accuracy: 1
time_ms: 770
memory_kb: 11056
final_rank: 16

code_snippet: #include<iostream>
#include<string>
using namespace std;
int sht[1000][1000];

int main(){
 string t;//原文
 string b;//呪文
 int i;
 int j;
 int k;
 int ans=0;
 
 for(i=0;i<1000;i++){
 	for(j=0;j<1000;j++){
		sht[i][j]=0;
	}
 }
 
 cin>>t>>b;
 //1行目
 for(i=0;i<t.size();i++){
 	if(b[0]==t[i]){
		sht[i][0]=1;
	}else{
		sht[i][0]=0;
	}
 }
 //2行目以降
 for(i=1;i<b.size();i++){
 	for(j=0;j<t.size();j++){
		if(b[i]==t[j] && j>=i){
			for(k=0;k<j;k++){
				sht[j][i]=sht[j][i]+sht[k][i-1];
			}
		}
	}
 }
 for(j=0;j<t.size();j++){
 	ans=(ans+sht[j][i-1])%1000000007;
 }
 cout<<ans<<endl;
}
accuracy: 0.43478260869565216
time_ms: 80
memory_kb: 7076
final_rank: 18

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

long long int p[1000][1000];

int main(){

string A;
string B;

long long int j=0;
long long int i=0;
long long int c=0;

long long int answer=0;
long long int final=0;

long long int n=0;//上の文の文字数
long long int m=0;//下の文の文字数

cin>>A;
cin>>B;

n=A.size(); //4
m=B.size(); //2

/////p全部に0を代入する///////

for(i=0;i<1000;i++){
for(j=0;j<1000;j++){
	p[j][i]=0;
}
}

//////////////////////////////

////一番上の段だけみる////

for(i=0;i<n;i++){
	if(A[i]==B[0]){
		p[i][0]=1;			
	}
}

///////////////////////




for(j=1;j<m;j++){   //j=1  
for(i=0;i<n;i++){   //i=0,1,2,3

	if(A[i]==B[j]){
		for(c=0;c<i;c++){
			p[i][j]=p[i][j]+p[c][j-1]; //
		}
		//cout<<p[i][j];			
	}else{
		//cout<<0;
	}
	
}

//cout<<endl;

}

for(i=0;i<n;i++){
	answer=answer%1000000007+p[i][m-1]%1000000007;
}

final=answer%1000000007;

cout<<final<<endl;

}
accuracy: 0.43478260869565216
time_ms: 90
memory_kb: 11056
final_rank: 20

code_snippet: #include<bits/stdc++.h>
#define NN 1000000007
using namespace std;
int dp[1001][1001];
int main(void)
{
	char a[1001],b[1001];
	
	int i,j,k;
	
	cin>>a;
	cin>>b;
	
	int x=strlen(a);
	int y=strlen(b);
	
	
	
	for(i=0;i<y;i++){
		for(j=0;j<x;j++){
			dp[i][j]=0;
		}
	}
	
	for(i=0;i<x;i++){
		if(a[i]==b[0]){
			dp[0][i]=1;
		}
	}
	
	
	
	for(i=1;i<y;i++){
		for(j=0;j<x;j++){
			for(k=j+1;k<x;k++){
				//cout<<"a="<<a[i]<<" "<<"k="<<k<<" "<<"b="<<b[k]<<endl;
				if(a[k]==b[i]){
					//cout<<"check"<<endl;
					dp[i][k]=(dp[i][k]+dp[i-1][j])%NN;
				}
			}
		}
	}
	
	/*for(i=0;i<y;i++){
		for(j=0;j<x;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
	
	int sum=0;
	for(i=0;i<x;i++){
		sum=(sum+dp[y-1][i])%NN;
	}
	cout<<sum<<endl;
	return 0;
}
accuracy: 1
time_ms: 720
memory_kb: 7016
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
int i,j,h,k,p;
long long v[1001][1001],M=1000000007;
long long int sum;
double def;
int main(void)
{
	char s[1001],t[1001];
	cin>>s>>t;
	h=strlen(s);
	k=strlen(t);
	for(i=0;i<=h;i++) for(j=0;j<=h;j++) v[i][j]=0;
	for(i=0;i<h;i++) if(s[i]==t[0]) v[0][i]=1;
	for(p=0;p<k;p++){
		for(i=p;i<h;i++){
			if(s[i]==t[p]){
				for(j=i+1;j<h;j++){
					if(s[j]==t[p+1]){
						v[p+1][j]+=v[p][i];
						if(M<v[p+1][j]) v[p+1][j]%=M;
					}
				}
			}
		}
	}/*
	for(i=0;i<k;i++){
		for(j=0;j<h;j++) cout<<v[i][j]<<" ";
		cout<<endl;
	}*/
	sum=0;
	for(i=0;i<h;i++){
		sum+=v[k-1][i];
		if(M<sum) sum=sum%M;
	}
	cout<<sum<<endl;
}
accuracy: 1
time_ms: 680
memory_kb: 10964
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
int i,j,h,k,p;
long long v[1001][1001],sum;
int main(void)
{
	char s[1001],t[1001];
	cin>>s>>t;
	h=strlen(s);
	k=strlen(t);
	for(i=0;i<=h;i++) for(j=0;j<=h;j++) v[i][j]=0;
	for(i=0;i<h;i++) if(s[i]==t[0]) v[0][i]=1;
	for(p=0;p<k;p++){
		for(i=p;i<h;i++){
			if(s[i]==t[p]){
				for(j=i+1;j<h;j++){
					if(s[j]==t[p+1]){
						v[p+1][j]+=v[p][i];
					}
				}
			}
		}
	}/*
	for(i=0;i<k;i++){
		for(j=0;j<h;j++) cout<<v[i][j]<<" ";
		cout<<endl;
	}*/
	sum=0;
	for(i=0;i<h;i++) sum+=v[k-1][i];
	sum=sum%1000000007;
	cout<<sum<<endl;
}
accuracy: 0.43478260869565216
time_ms: 70
memory_kb: 10904
final_rank: 19