#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x,T a,T b){return a<=x&&x<=b;}
template<class T> void amin(T &a,T v){if(a>v) a=v;}
template<class T> void amax(T &a,T v){if(a<v) a=v;}
int ROUND(double x) { return (int)(x+0.5); }
bool ISINT(double x) { return fabs(ROUND(x)-x)<=EPS; }
bool ISEQUAL(double x,double y) { return fabs(x-y)<=EPS*max(1.0,max(fabs(x),fabs(y))); }
double SQSUM(double x,double y) { return x*x+y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;



#if 0

ll dp[305][305][305];

void addmod(ll& a, ll& b)
{
	const int MOD = 1e9 + 7;
	a += b;
	a %= MOD;
}

int main()
{
	int N;
	cin >> N;

	if (N >= 301) return 0;

	string s;
	cin >> s;

	const int L = SZ(s);

	dp[0][0][0] = 1;


	for (int key=0;key<N;key++)
	{
		for (int len = 0; len <= key; len++)
		{
			for (int atteru = 0; atteru <= len; atteru++)
			{
				if (len == atteru)
				{
					addmod(dp[key + 1][len + 1][atteru + 1], dp[key][len][atteru]);
					addmod(dp[key + 1][len + 1][atteru],     dp[key][len][atteru]);
					addmod(dp[key + 1][max(0,len - 1)][max(0, atteru - 1)], dp[key][len][atteru]);
				}
				else
				{
					addmod(dp[key + 1][len + 1][atteru], dp[key][len][atteru]);
					addmod(dp[key + 1][len + 1][atteru], dp[key][len][atteru]);
					addmod(dp[key + 1][max(0, len - 1)][atteru], dp[key][len][atteru]);
				}
			}
		}
	}

	cout << dp[N][L][L] << endl;

	return 0;
}

#elif 1


ll dp[500][500];
ll mpow[500][500];

int main()
{
	const int MOD = 1e9 + 7;

	int N, C;
	cin >> N >> C;
	vector <int> A(N), B(N), x(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	for (int i = 0; i < N; ++i)
	{
		cin >> B[i];
	}
	



	for (int i = 0; i < N; i++)
	{
		for (int z = A[i]; z <= B[i]; ++z)
		{
			ll x = 1;
			for (int q = 0; q < 500; q++)
			{
				mpow[i][q] += x;
				mpow[i][q] %= MOD;
				x *= z;
				x %= MOD;
			}
		}
	}

	memset(dp, 0, sizeof(dp));

	dp[0][C] = 1; // dp[0-園児番号i][残りキャンディ]

	for (int i = 0; i < N; ++i)
	{
		for (int c = 0; c <= C; ++c)
		{
			for (int a = 0; a <= c; ++a)
			{
				dp[i + 1][c - a] += (dp[i][c] * mpow[i][a]) % MOD;
				dp[i + 1][c - a] %= MOD;
			}
		}
	}

	cout << dp[N][0] << endl;
	return 0;
}


#elif 1

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

	const int N = SZ(s);
	for (char c = 'a'; c <= 'z'; ++c)
	{
		vector <int> sum(N + 1);
		for (int i = 0; i < N; ++i)
		{
			if (c == s[i])
			{
				sum[i + 1] = sum[i] + 1;
			}
			else
			{
				sum[i + 1] = sum[i];
			}
		}

		for (int len = 2; len <= min(100, N); ++len)
		{
			for (int i = 0; i + len <= N; ++i)
			{
				int freq = sum[i + len] - sum[i];
				if (freq > len / 2)
				{
					printf("%d %d\n", i + 1, i + len);
					return 0;
				}
			}
		}
	}
	printf("%d %d\n", -1, -1);
	return 0;
}


#else

int main()
{
	int N;
	cin >> N;
	vector <int> a(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> a[i];
	}

	int bestDist = BIG;

	for (int y=-100;y<=100;++y)
	{
		int dist = 0;
		for (int x : a)
		{
			dist += SQ(x - y);
		}

		amin(bestDist, dist);
	}

	cout << bestDist << endl;

	return 0;
}

#endif

Measured memory_bytes: 3712