#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
using C = complex<double>;

int main() {
	int n, k;
	cin >> n >> k;
	vector<vector<int>> a(n, vector<int>(n));
	rep(i, n)rep(j, n) cin >> a.at(i).at(j);
	int L = k * k / 2 + 1;

	int wa = -1, ac = 1001001001;
	while (wa + 1 < ac) {
		int wj = (wa + ac) / 2;
		bool ok = false;
		{
			vector<vector<int>> s(n + 1, vector<int>(n+1));
			rep(i, n)rep(j, n) s.at(i + 1).at(j + 1) = a.at(i).at(j)>wj?1:0;
			rep(i, n + 1)rep(j, n) s.at(i).at(j + 1) += s.at(i).at(j);
			rep(i, n)rep(j, n + 1) s.at(i + 1).at(j) += s.at(i).at(j);
			rep(i, n - k + 1)rep(j, n - k + 1) {
				int now = s.at(i + k).at(j + k);
				now -= s.at(i).at(j + k);
				now -= s.at(i + k).at(j);
				now += s.at(i).at(j);
				if (now < L) ok = true;
			}
		}

		if (ok) ac = wj; else wa = wj;
	}
	cout << ac << endl;
}

#include "bits/stdc++.h"

using namespace std;

#define ll long long

#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()

#define            pb                push_back
#define          sz(a)               (int)a.size()
#define         fastio               ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define      GR(a,n,m)               vector<vector<int>> a(n, vector<int>(m, 0));

#define int long long

const int N = 1000;
int c[N][N];
int a[N][N];
int s[N][N];

int query(int i1,int j1,int i2,int j2){
    int ans = s[i2][j2];
    if(i1)ans -= s[i1-1][j2];
    if(j1)ans -= s[i2][j1-1];
    if(i1&&j1)ans += s[i1-1][j1-1];
    return ans;
}
void solve()
{
    int n, k;
    cin >> n >> k;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            cin >> c[i][j];
        }
    }
    int l = 0,r = 1e9;
    int ans = r;

    int pos = (k * k - 1) / 2 + 1;
    while(l <= r)
    {
        int mid = l + (r - l) / 2;

        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(c[i][j] <=  mid){
                    a[i][j] = 1;
                }else{
                    a[i][j] = 0;
                }
            }
        }

        for(int i = 0;i < n;i++){
            s[i][0] = a[i][0];
            if(i)s[i][0] += s[i-1][0];
            s[0][i] = a[0][i];
            if(i)s[0][i]+=s[0][i-1];
        }
        for(int i = 1;i < n;i++){
            for(int j = 1;j < n;j++){
                s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
            }
        }
        bool ok=false;
        for(int i = 0;i + k - 1 < n;i++){
            for(int j = 0;j + k - 1 < n;j++){
                int sum = query(i,j,i+k-1,j+k-1);
                if(sum >= pos)ok=1;
            }
        }
        if(ok){
            ans=mid;
            r=mid-1;
        }else l=mid+1;
    }
    cout<<ans;
}

int32_t main()
{
    fastio;
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
}


#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int>a(n + 1);
	rep(i, n + 1) { cin >> a[i]; }
	int k = INF;
	rep(i, n) { k = min(k, abs(a[i] - a[i + 1])); }
	cout << k << endl;
	rep(i, k) {
		rep(j, n + 1) {
			cout << (a[j] + i) / k << " ";
		}
		cout << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; string S; cin >> N >> S;
    vector<int> B(N + 1);
    for (auto &b : B) cin >> b;

    int k = 0;
    REP(i, 1, 1e4 + 1) {
        bool ok = true;
        REP(j, 0, N) {
            if (S[j] == '<') {
                int d = B[j + 1] / i - B[j] / i;
                if (d < 1 || (d == 1 && B[j] % i > B[j + 1] % i)) {
                    ok = false;
                }
            } else {
                int d = B[j] / i - B[j + 1] / i;
                if (d < 1 || (d == 1 && B[j] % i < B[j + 1] % i)) {
                    ok = false;
                }
            }
        }
        if (!ok) break;
        k = i;
    }

    cout << k << endl;
    REP(i, 0, k) {
        REP(j, 0, N + 1) {
            cout << B[j] / k + (i < B[j] % k) << " ";
        }
        cout << endl;
    }
    return 0;
}


//you can do anything  //  be strong :|
#include <bits/stdc++.h>
#define ll long long
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pk push_back
#define f first
#define s second
using namespace std;
int const maxn = 1e6+9 ;

ll pric[maxn] ;
bool vis[maxn] ;
vector<vector<ll>>adj;
ll dp[maxn] ;

void dfs(int cur )
{

	if(dp[cur]!=-1) return ;

	dp[cur] = pric[cur] ;
	vis[cur] =1 ;

	for(int i=0 ;i<adj[cur].size() ;i++)
	{
		if(!vis[ adj[cur][i] ])
			dfs(adj[cur][i]) ;

		dp[cur] = max( dp[adj[cur][i]] , dp[cur] );
	}
}

void solve()
{
		ll n ,m ;
		cin>>n>>m ;
		for(int i=0 ;i<n ;i++) cin>>pric[i];
		adj.resize(n);
		ll x ,y ;
		for(int i=0 ;i<m ;i++)
		{
			cin>>x>>y;
			x-- ; y-- ;
			adj[x].pk(y);
		}

		ll sum =INT_MIN ;
		memset(vis ,false ,sizeof(vis));
		memset(dp ,-1 ,sizeof(dp));
		for(int i=0 ;i<n ;i++)
		{
			if(!vis[i])
					dfs(i);
			for(auto j : adj[i])
			sum=max(sum ,  dp[j]- pric[i]);
		}

		cout<<sum;
}

int main()
{
	ll t=1;
//	scanf("%lld" ,&t);
	while(t--) solve();
}

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define ma 1e18
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double
#define PI  3.14159265358979
#define pri  priority_queue<lli>
#define prim  priority_queue<lli,vector<lli>,greater<lli>>
#define prip  priority_queue<pr>
#define primp  priority_queue<pr,vector<pr>,greater<pr>>
#define flush  cout<<flush
vector<lli>v[200001];
lli a[200001];
lli dis[200001];
lli vis[200001];

void dfs(lli x){
    vis[x] = 1;
    for(auto itr  : v[x]){
        if(!vis[itr]){
            dfs(itr);
        }
            dis[x] = max(dis[x] , max(dis[itr] , a[itr]));

    }
}

int main(){
    lli n,m,x,y;
    cin>>n>>m;
    loop(i,1,n+1){
        cin>>a[i];
        dis[i] = -1;
        vis[i] = 0;

    }

    loop(i,0,m){
        cin>>x>>y;
        v[x].pb(y);
    }

    loop(i,1,n+1){
        if(!vis[i]){
            dfs(i);
        }
    }

    lli ans = -1e16;
    loop(i,1,n+1){
        if(dis[i]!=-1){
            ans = max(ans ,  dis[i] - a[i]);
        }
        }
        cout<<ans<<"\n";
}


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

const int N=2000+5;

inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
	    if(c=='-')
	        f=-1;
	    c=getchar();
	}
	while(c>='0'&&c<='9')
	{
	    x=x*10+c-'0';
	    c=getchar();
	}
	return x*f;
}

int n;
int a[N];

inline int exgcd(int x,int y)
{
	if(!y) return x;
	return exgcd(y,x%y);
}

map<int,int> re;
map<int,int>::iterator it;

int main()
{
	n=read();
	int minn=0x3f3f3f3f;
	for(int i=1;i<=n;i++) a[i]=read(), minn=min(minn,a[i]);
	for(int i=1;i<=n;i++)
	{
		int t=sqrt(a[i]);
		for(int j=1;j<=t;j++)
		{
			if(a[i]%j!=0) continue;
			if(j<=minn) re[j]=exgcd(re[j],a[i]);
			if(a[i]/j<=minn) re[a[i]/j]=exgcd(re[a[i]/j],a[i]);
		}
	}
	int ans=0;
	for(it=re.begin();it!=re.end();it++)
		if((*it).first==(*it).second)
			ans++;
	printf("%d\n",ans);
	return 0;
}

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

typedef long long LL;
#define int LL
typedef pair<int, int> PII;
typedef pair<int, LL> PIL;
const int N = 5e5 + 10, M = 3e5 + 10;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
#define x first
#define y second
const int mod = 1e9 + 7;
#define gcd __gcd

map<int, int> cnt;
int a[N];
int b[N];

void solve() {
	int n;
	scanf("%lld", &n);
	cnt[0] = 1;
	LL res = 0, sum = 0;
	for(int i = 1; i <= n; i++) {
		int x;
		scanf("%lld", &x);
		if(i & 1) x = -x;
		sum += x;
		if(cnt.count(sum)) res += cnt[sum];
		cnt[sum]++;
	}
	printf("%lld\n", res);
}

signed main() {
	// freopen("in.txt", "r", stdin);
    // int t; cin >> t; while(t--)
    solve();
    return 0;
}


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

const string YES = "Yes";
const string NO = "No";

using ll = long long;

bool is_kaibun(string s){
    for(int i = 0;i < s.size();i++){
        if(s[i] != s[int(s.size()) - i - 1]){
            return false;
        }
    }
    return true;
}

void solve(long long _N){
    string N = to_string(_N);
    reverse(N.begin(), N.end());

    for(int i = 0;i < 60;i++){
        if(is_kaibun(N)){
            cout<<"Yes"<<endl;
            return;
        }
        N.push_back('0');
    }
    cout<<"No"<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
typedef unsigned long long ull;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define f(i,a,b) for(ll i=a;i<=b;i++)
// #define testcases ll t;cin>>t;while(t--)
#define dec(x) greater<x>()

/*** Define fues ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 100005
const char nl = '\n';

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, fue) memset(name, fue, sizeof(name))

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a, pll b) { if (a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "

/*** Functions
ll BigMod(ll base, ll pow, ll modfue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modfue);ll total = ((ans % modfue) * (ans % modfue)) % modfue;  if(pow % 2 == 0) return total; else{ return (total * (base % modfue) ) % modfue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }
ll sumofdigit(ll n){ll sum=0;while(n){sum=sum+n%10;n=n/10;}return sum;}
ll countDigit(ll n) { if (n == 0) return 0; return 1 + countDigit(n / 10); }
ll countDigit(ll n) { return floor(log10(n) + 1); } //only positive
 ***/

template <class T> inline T gcd(T a, T b) {if (b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b, T p) {ll ans = 1; while (p--) ans *= b; return ans;}

void solve()
{
	string s;
	cin>>s;
	ll n=s.size(),c=0;
	for(ll i=n-1;i>=0;i--)
	{
		if(s[i]=='0')c++;
		else break;
	}
	ll a=0;
	loop(i,0,n)
	{
		if(s[i]=='0')a++;
		else break;
	}
	// cout<<a<<" "<<c<<nl;
	for(ll i=a;i<(n-c)/2;i++)
	{
		if(s[i]!=s[n-i-1-c])
		{
			cout<<"No";
			return;
		}
	}

	cout<<"Yes";
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll t = 1;
	// cin>>t;
	while (t--)
	{
		solve();
	}
}


#include <iostream>
using namespace std;
int main(void){
    int n,s,d;
    cin >> n >> s >> d;
    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        if(x<s){
            if(d<y){
                cout << "Yes" << endl;
                break;
            }
            else{
                if(i+1==n){
                    cout << "No" << endl;
                }
                else{
                    continue;
                }
            }
        }

        else{
                if(i+1==n){
                    cout << "No" << endl;
                }
                else{
                    continue;
                }
            }

        }
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define FIO                ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)         for(int i=a;i<b;i++)
#define repe(i,a,b)        for(int i=a;i<=b;i++)
#define rrep(i,a,b)        for(int i=b;i>=a;i--)
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define sz(s)              (int)s.size()
#define fi                 first
#define se                 second
#define lb                 lower_bound
#define ub                 upper_bound
#define pb                 push_back
#define ppb                pop_back
#define pf                 push_front
#define ppf                pop_front
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main()
{
    FIO;
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif

    int n,s,d;
    cin>>n>>s>>d;
    string ans = "No";
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        if(x>=s || y<=d) continue;
        if(x<s && y > d ) ans = "Yes";
    }
    cout<<ans<<endl;

    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(998244353);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int multipf(vector<string>& s){
    cout << s[0];
    rep1(i, s.size() - 1)cout << " " << s[i];
    cout << endl;
    return 0;
}

int multipf(vector<ll>& n){
    cout << n[0];
    rep1(i, n.size() - 1)cout << " " << n[i];
    cout << endl;
    return 0;
}

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        ans %= mod;
        a = a * a;
        a %= mod;
        b >>= 1;
    }
    return ans % mod;
}

struct UnionFind {
    vector<ll> par;
    vector<ll> rank;
    vector<ll> Size;
    UnionFind(ll n) {
        init(n);
    }

    void init(ll n) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        rep0(i, n + 1){
            par[i] = i;
            rank[i] = 0;
            Size[i] = 1;
        }
    }

    ll root(ll x) {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(ll x){
        return Size[root(x)];
    }
};

//modの値の確認をすること
int main(){
    ll n;
    string s;
    cin >> n >> s;
    vector<tuple<ll,ll,ll,ll> > a(n + 1,make_tuple(0,0,0,0));
    rep1(i, n){
        if(s[i - 1] == 'A')get<0>(a[i])++;
        else if(s[i - 1] == 'T')get<1>(a[i])++;
        else if(s[i - 1] == 'C')get<2>(a[i])++;
        else get<3>(a[i])++;
    }
    rep1(i, n){
        get<0>(a[i]) += get<0>(a[i - 1]);
        get<1>(a[i]) += get<1>(a[i - 1]);
        get<2>(a[i]) += get<2>(a[i - 1]);
        get<3>(a[i]) += get<3>(a[i - 1]);
    }
    ll ans = 0;
    rep0(i, n)nfor(j, i + 1, n + 1)if(get<0>(a[j]) - get<0>(a[i]) == get<1>(a[j]) - get<1>(a[i]) && get<2>(a[j]) - get<2>(a[i]) == get<3>(a[j]) - get<3>(a[i]))ans++;
    pf(ans);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

  int count = 0;
  for (int i = 0; i < n; i++) {
    int c1 = 0, c2 = 0;
    for (int j = i; j < n; j++) {
      switch (s[j]) {
        case 'A':
          c1++;
          break;
        case 'T':
          c1--;
          break;
        case 'C':
          c2++;
          break;
        case 'G':
          c2--;
          break;
      }
      if (c1 == 0 && c2 == 0) {
        count++;
      }
    }
  }
  cout << count;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using p = pair<int, int>;

int main() {
    //vector<vector<int>>data(h,vector<int>(w));

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    int am = 100000, bm = 100000, ai = 0, bi = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] < am) {
            am = a[i];
            ai = i;
        }
        if (b[i] < bm) {
            bm = b[i];
            bi = i;
        }
    }
    int counta = 0, countb = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == am) {
            counta++;
        }
        if (b[i] == bm) {
            countb++;
        }
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int c = min(a[1], b[1]);

    if (ai != bi) {
        cout << max(am, bm) << endl;
        return 0;
    } else if (ai == bi && (counta > 1 || countb > 1)) {
        cout << max(am, bm) << endl;
        return 0;
    } else {
        cout << min(c, am + bm) << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N], b[N];
int n, m;
int main(){
	scanf("%d",&n);
	int ans = 2e9;
	for(int i=0; i<n; ++i){
		scanf("%d%d",a+i,&b[i]);
	}
	for(int i=0; i<n; ++i){
		for(int j=0; j<n; ++j){
			if(i==j){
				ans = min(ans, a[i]+b[i]);
			}
			else{
				ans = min(ans, max(a[i], b[j]));
			}
		}
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//const int MOD =  998244353;

const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int A, B; cin >> A >> B;
    int X = (A+B)/2;
    int Y = A - X;

    cout << X << " " << Y << endl;
}

/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/

// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <vector>
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>

#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;

int dp[1 << 20];

signed main()
{
    tezz

    vector<int> primes;
    for(int i=2; i<72; i++){
        bool flag = true;
        for(int j=2; j<i; j++){
            if(i % j == 0) flag = false;
        }

        if(flag) primes.emplace_back(i);
    }

    int A, B;
    cin>>A>>B;

    //now convert every number into masks.. with respect to prime divisors

    vector<int> v(B - A + 1);

    for(int i=A; i<=B; i++){
        int mask = 0;

        for(int j=0; j<20; j++){
            if(i % primes[j] == 0){
                mask |= (1 << j);
            }
        }

        v[i - A] = mask;
    }

    //now using dp to form every possible states
    dp[0] = 1;

    for(int x: v){
        for(int mask=0; mask<(1 << 20); mask++){
            if(dp[mask]){
                int temp = mask & x;
                if(temp == 0) dp[mask | x] += dp[mask];
            }
        }
    }

    int ans = 0;
    for(int i=0; i<(1 << 20); i++) ans += dp[i];

    cout<<ans;
}


#include<bits/stdc++.h>
#define rg register
#define fp( i , x , y ) for( rg int i=(x); i<=(y); ++i )
#define fq( i , x , y ) for( rg int i=(y); i>=(x); --i )
#define dou double
using namespace std ;
void upd( int &x , int y ) {
  if( x == -1 ) x = y ;
  else x = min( x , y ) ;
}
signed main( ) {
  ios::sync_with_stdio(false) ;
  cin.tie(0) ;
  int n , ans = -1 , a , b , c ;
  cin >> n ;
  fp( i , 1 , n ) {
    cin >> a >> b >> c ;
	if( a < c ) upd( ans , b ) ;
  }
  cout << ans << '\n' ;
  return 0 ;
}

#include<bits/stdc++.h>
using namespace std;
#define en      '\n'
#define endl    '\n'
#define ll      long long signed
#define pb      push_back
#define append  push_back
#define all(v)  (v).begin(),(v).end()
#define FOR(i,a,b,k) for(int i=a; k>0?i<b:i>b; i+=k)
#define fori(a) for(int i=0; i<a; i++)
#define forj(a) for(int j=0; j<a; j++)
#define fork(a) for(int k=0; k<a; k++)
#define MOD     1000000007
#define MAX     1000010
#define mset(a,s,k) memset(a,k,s*sizeof(a[0]))
#define ff      first
#define ss      second
#define __      <<" "<<
#define _       <<en

ll pow_(ll a,ll e,ll m=MOD){ll r=1;while(e){if(e&1)r=r*a%m;a=a*a%m;e>>=1;}return r;}
int inv(ll a) {return int(pow_(a,MOD-2,MOD));}int add(ll a, ll b){return (a+b+MOD)%MOD;} int mul(ll a, ll b)
{return (MOD+a*b%MOD)%MOD;}int di(ll a, ll b){return mul(a,inv(b));}ll  ceil(ll a,ll b){return a/b+(a%b!=0);}
template<typename T1,typename T2>ostream&operator<<(ostream&O,pair<T1,T2>a){O<<"( ";O<<a.ff<<", "<<a.ss;O<<" )";return O;}
template<typename T>ostream&operator<<(ostream&O,vector<T>V){O<<"[ ";fori(V.size())O<<V[i]<<(i==V.size()-1?"":", ");O<<" ]";return O;}
template<typename T>ostream&operator<<(ostream&O,set<T>S){O<<"{ ";for(T i:S)O<<i<<", ";O<<" }";return O;}
template<typename T1,typename T2>ostream&operator<<(ostream&O,map<T1,T2>S){O<<"{ ";for(auto i:S)O<<i<<", ";O<<" }";return O;}
template<typename T=int>class print{public:vector<T>V;print(vector<T>v){V=v;cout<<" <"<<V<<"> ";}
print(T*x,int n){fori(n)V.push_back(x[i]);cout<<" <"<<V<<"> ";}friend ostream&operator<<(ostream&O,print p){return O;}};

#define vi vector<int>
#define tp pair<int,int>
#define ar array<int,4>

ar arr[MAX]; int N;
void reset();

int solve(){
    cin>>N;
    reset();
    fori(N){
        int a,b,c; cin>>a>>b>>c;
        arr[i]={b,a,c};
    }
    sort(arr,arr+N);
    bool f=1;
    fori(N){
        if(arr[i][1]<arr[i][2]){
            cout<<arr[i][0];
            f=false;
            break;
        }
    }
    if(f) cout<<-1;
    cout<<endl;
    // fori(N){ cin>>arr[i];}
    // print<int>(arr,N);
    return 0;
}

void reset(){

    // Clear Vectors, maps, sets
    // Set default values of arr
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    while(t--){
        solve();
        // cout<<solve()<<en;
        // cout<<(solve()?"Yes":"No")<<endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <iomanip>

signed main(){
    int N;
    std::cin >> N;
    std::vector<std::string> S(N);
    for(auto &si:S) std::cin >> si;
    std::vector<std::vector<int>> A(N,std::vector<int> (N));
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            A[i][j]=S[i][j]-'0';
        }
        A[i][i]=1;
    }
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(A[i][k]+A[k][j]==2) A[i][j]=1;
            }
        }
    }
    double answer=0;
    for(int i=0;i<N;i++){
        double go=0;
        for(int j=0;j<N;j++){
            if(A[j][i]==1) go++;
        }
        answer+=1/go;
    }
    std::cout << std::fixed << std::setprecision(10) << answer << '\n';
}

#include <bits/stdc++.h>
using namespace std;
typedef long double LD;
typedef long long ll;
#define int ll
#define ff(i,a,b) for (int i = a; i < b; i++)
#define bf(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define one cout<<"-1"<<endl
#define pi 3.141592653589793238
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
#define intmx INT_MAX
#define intmi INT_MIN
const int MOD=1e9+7;
int test=1;
void solve(){
    int n,m;
    cin>>n>>m;
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    string s[n];
    ff(i,0,n)
    cin>>s[i];
    int cnt=0;
    int i=x,j=y;
    i++;
    while(i<n&&s[i][j]=='.'){
        cnt++;
        i++;
    }
    i=x-1;
    while(i>=0&&s[i][j]=='.'){
        cnt++;
        i--;
    }
    i=x;j=y+1;
    while(j<m&&s[i][j]=='.'){
        cnt++;
        j++;
    }
    j=y-1;
    while(j>=0&&s[i][j]=='.'){
        cnt++;
        j--;
    }
    if(s[x][y]=='.')
    cnt++;
    cout<<cnt<<endl;
}

signed main() {
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


#include <bits/stdc++.h>
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
#define maxn 3e5+10
#define inf32 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int,int>pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

ll lowbit(int x) {return x&(-x);}
vector<ll>sum(maxn,0);

void update(int i,int x){
    while(i<sum.size()){
        sum[i] += x;
        i += lowbit(i);
    }
}
//记得index要从1开始
ll query(int i){
    ll ans = 0;
    while(i>0){
       ans += sum[i];
       i -= lowbit(i);
    }
    return ans;
}

void solve(){
    int h,w,m;cin >> h >> w >> m;
    vector<ll>x(m),y(m),sc(w+1,h+1),rc(h+1,w+1);
    for(int i = 0;i<m;i++){
        cin >> x[i] >> y[i];
        rc[x[i]] = min(rc[x[i]],y[i]);
        sc[y[i]] = min(sc[y[i]],x[i]);
    }
    ll ans = 0;
    vector<pll>a(m);
    for(int i = 0;i<m;i++) a[i].first = x[i],a[i].second = y[i];
    sort(a.begin(),a.end());
    ll lim = w+1;
    vector<bool>b(w+1,0);
    int j = 0;
    for(int i = 1;i<=h;i++){
        ll tp = rc[i]-1;
        if(tp==0) break;
        ans += tp;
        update(1,1);
        update(rc[i],-1);
        while(j<m&&a[j].first==i){
            if(a[j].first==1) lim = min(lim,a[j].second);
            if(a[j].second<lim){
                    if(b[a[j].second]==0){
                        b[a[j].second] = 1;
                        ans += a[j].first-1-query(a[j].second);//watch(a[j].first-1-query(a[j].first));
                    }
            }
            j++;
        }
    }
        for(int i = 1;i<lim;i++){
            if(!b[i]){
                ans += sc[i]-1-query(i);
            }
        }
        cout << ans;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  solve();
  return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;
/* using namespace atcoder; */

using ll = long long;
using P = pair<int, int>;

const ll INF = 1 << 30;

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

struct Data {
  int to;
  ll cost;
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> dist(n, INF);
//  vector<vector<ll>> G2(n, vector<ll>(n, INF));
  vector<vector<Data>> G(n, vector<Data>());
  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    if (a == b) {
      chmin(dist.at(a), c);
    } else {
//      chmin(G2.at(a).at(b), c);
      Data d = {b, c};
      G.at(a).push_back(d);
    }
  }
//  vector<vector<Data>> G(n, vector<Data>());
//  rep(i, n) {
//    rep(j, n) {
//      if (i == j) continue;
//      Data d = {j, G2.at(i).at(j)};
//      G.at(i).push_back(d);
//    }
//  }

  vector<vector<ll>> dist2(n, vector<ll>(n, INF));
  rep(i, n) {
    vector<ll> dist3(n, INF);
    dist3.at(i) = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>,
        greater<pair<ll, int>>> que;
    que.push(make_pair(dist3.at(i), i));
    while (!que.empty()) {
      int v = que.top().second;
      ll d = que.top().first;
      que.pop();
      if (d > dist3.at(v)) continue;
      for (auto e : G.at(v)) {
        if (e.to == i) {
          continue;
        }
        if (chmin(dist3.at(e.to), dist3.at(v) + e.cost)) {
          que.push(make_pair(dist3.at(e.to), e.to));
        }
      }
    }
    rep(j, n) {
//      cerr << dist3.at(j) << " ";
      dist2.at(i).at(j) = dist3.at(j);
    }
//    cerr << endl;
  }
  rep(i, n) {
    rep(j, n) {
      if (i == j) continue;
      dist.at(i) = min(dist.at(i), dist2.at(i).at(j) + dist2.at(j).at(i));
    }
  }
  rep(i, n) {
    cout << ((dist.at(i) == INF) ? -1 : dist.at(i)) << endl;
  }
  return 0;
}


#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string S; cin >> S;
  int l = 0, r = S.size() - 1;
  bool is_zero = true;
  while (l < r) {
    if (S[l] == S[r]) {
      ++l, --r;
      if (S[l] != '0') is_zero = false;
    } else {
      if (is_zero && S[r] == '0') {
        --r;
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define FORL(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define FORR(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define INF 1000000000000000003
#define MOD 1000000007
#define F first
#define S second
#define PB push_back
#define POB pop_back
#define MP make_pair
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi>vp;
typedef vector<ll> vl;

int intToBinary (int n) {
    string s = bitset< 32 >( n ).to_string();
    return stoi(s);
}

vector<bool> primeSeive(ll n){
    vector<bool> v(n,true);
    v[0]=false;
    v[1]=false;
    for(ll i=2;i<=sqrt(n);i++){
        for(ll j=i*2;j<=n;j+=i){
            v[j]=false;
        }
    }
    return v;
}

vector<ll> cumSum(vector<ll> arr, int n){
    vector<ll> sumArr;
    sumArr.PB(0);
    ll sum = 0;
    FOR(i,n){
        sum+=arr[i];
        sumArr.PB(sum);
    }
    return sumArr;
}

bool checkPrime(ll num){
    for(int i = 2;i<=sqrt(num);i++){
        if(num%i == 0) return false;
    }
    return true;
}

ll totalSum(vl v){
    ll total = 0;
    FOR(i,v.size()) total += v[i];
    return total;
}

vector<ll> countDivisors(ll n) {
    vector<ll> v(n+1, 1);
    v[0]= 0;

    for(ll i= 2; i <= n; i++) {
        for(ll j= i; j <=n; j+=i) {
            v[j]++;
        }
    }
    return v;
}

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;

    if(s[0] == s[1] && s[1] == s[2] ) cout << "Won";
    else cout << "Lost";

	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

// 約数列挙
vector<int> get(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

class FGCDOrMIN {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> A(N);
        REP(i, N) cin >> A[i];

        int mina = INF;
        map<int, int> m;
        REP(i, N) {
            for (auto n : get(A[i])) {
                if (m.count(n) == 0) {
                    m[n] = A[i];
                } else {
                    m[n] = gcd(m[n], A[i]);
                }
            }
            mina = min(mina, A[i]);
        }
        int res = 0;
        for (auto kv : m) {
            if (kv.second <= mina && kv.first == kv.second) {
                res++;
            }
        }
        cout << res << endl;
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    FGCDOrMIN solver;
    solver.solve(in, out);
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int T; cin >> T;
    rep(i,T) {
        int N; cin >> N;
        int A[N];
        rep(i,N) cin >> A[i];
        if(N%2) {
            cout << "Second" << endl;
            continue;
        }
        else {
            sort(A,A+N);
            bool can=true;
            rep(i,N/2) {
                if(A[i*2]!=A[i*2+1]) can=false;
            }
            if(can) {
                cout << "Second" << endl;
            } else {
                cout << "First" << endl;
            }
        }
    }

}


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

using ll = long long;
constexpr int INF = (int)1e9;
constexpr long long LINF = (long long)1e18;
constexpr long long MOD = 1e9 + 7;
//constexpr long long MOD = 998244353;
constexpr double pi = 3.141592653589793238;

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

    vector<ll> a(n);
    vector<vector<ll>> dp(n, vector<ll>(3));
    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            dp.at(0).at(0) = 1;
            dp.at(0).at(1) = 0;
            dp.at(0).at(2) = 1;
        }
        else {
            dp.at(i).at(0) = (dp.at(i - 1).at(0) + dp.at(i - 1).at(1)) % MOD;
            dp.at(i).at(1) = dp.at(i - 1).at(0);
            dp.at(i).at(2) = (dp.at(i).at(0) + dp.at(i).at(1)) % MOD;
        }

        ll ai;
        cin >> ai;
        a.at(i) = ai;
    }

    ll ans = 0;
    ans += (dp.at(n - 1).at(2) * a.at(0)) % MOD;
    if (n <= 2) {
        cout << ans << endl;
        return 0;
    }
    ans = (ans + dp.at(n - 2).at(2) * a.at(1)) % MOD;
    ans = ans - dp.at(n - 3).at(2) * a.at(1);
    if (ans < 0) ans += MOD;

    ans += dp.at(n - 2).at(2) * a.at(n - 1) % MOD;
    ans %= MOD;
    ans -= dp.at(n - 3).at(2) * a.at(n - 1) % MOD;
    if (ans < 0) ans += MOD;

    for (int i = 2; i < n - 1; ++i) {
        ans += dp.at(i - 1).at(2) * dp.at(n - 1 - i).at(2) % MOD * a.at(i) % MOD;
        ans %= MOD;
        ans -= dp.at(i - 2).at(2) * dp.at(n - 2 - i).at(2) % MOD * a.at(i) % MOD;
        if (ans < 0) ans += MOD;
    }

    cout << ans << endl;

    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

ll read() {
    ll K = 0;
    string S; cin >> S;
    int cnt = 0;
    bool found = false;
    bool neg = false;
    trav(a, S) {
        if (a == '.') {
            found = true; continue;
        } else if (a == '-') {
            neg = true; continue;
        }
        if (found) cnt++;

        K *= 10; K += a - '0';
    }
    FOR(i, cnt, 4) K *= 10;
    if (neg) K *= -1;
    return K;
}

void solve() {

    ll X = read(), Y = read(), R = read();
    R *= R;
    ll ans = 0;
    for (ll x = -2000000000; x <= 2000000000; x += 10000) {
        ll lo = Y, hi = 2000000000;
        assert(lo < hi);
        ll G = (X-x)*(X-x);
        if (G > R) continue;
        while (lo < hi) {
            ll mid = lo + (hi-lo+1)/2;
            if ((Y-mid)*(Y-mid) <= R-G) {
                lo = mid;
            } else {
                hi = mid-1;
            }
        }
        ll upB = lo;
        lo = -2000000000;
        hi = Y;
        assert(lo < hi);
        while (lo < hi) {
            ll mid = lo + (hi-lo)/2;
            if ((Y-mid)*(Y-mid) <= R-G) {
                hi = mid;
            } else {
                lo = mid+1;
            }
        }
        ll loB = lo;
        loB += 1e12; upB += 1e12;
        assert(loB >= 0); assert(upB >= 0);
        loB = (loB + 9999) / 10000;
        upB = upB / 10000;
        assert(upB - loB + 1 >=0);
        ans += upB - loB + 1;
    }
    cout << ans << nl;

}

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

    int T = 1;
//    cin >> T;
    while(T--) {
        solve();
    }

	return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	auto count_pairs = [&](int x) {
		if (x <= 1 || x > 2 * n) return 0LL;
		return (long long) (x - 1) / 2 * 2 + (x - 1) % 2 - max(0, (x - n - 1) * 2);
	};
	long long ans = 0;
	for (int x = 2; x <= 2 * n; ++x)
		ans += (long long) count_pairs(x) * count_pairs(x - k);
	cout << ans << '\n';
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()

int n, m;
vector<pair<int, int>> edge[100000];
bool vis[100000];
int ans[1000000];

void dfs(int u, int pe, bool pf) {
	vis[u] = true;
	if (pf) {
		ans[u] = (pe + 1) % n;
	}
	else {
		ans[u] = pe;
	}

	for (auto e : edge[u]) {
		int v = e.first;
		if (vis[v])continue;

		dfs(v, e.second, e.second == ans[u]);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	rep(_, m) {
		int u, v, c;
		cin >> u >> v >> c;
		u--; v--; c--;
		edge[u].emplace_back(v, c);
		edge[v].emplace_back(u, c);
	}

	dfs(0, 0, false);

	rep(i, n) {
		cout << ans[i] + 1 << endl;
	}

	return 0;
}

#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

ll inf = 1LL << 60;

struct edge {
    ll to, cost, time;
};

void djikstra(vector<ll> &d, vector<ll> &f, vector<vector<edge>> &g, ll start) {
    // p : (cost, position)
    using p = pair<ll, ll>;
    ll inf = 1LL << 60;
    fill(d.begin(), d.end(), inf);
    d[start] = 0;

    priority_queue<p, vector<p>, greater<p>> q;
    q.push(p(0, start));

    for (int i = 0; i < f.size(); i++) {
        f[i] = -1;
    }
    while (!q.empty()) {
        p now = q.top();
        q.pop();
        ll now_cost = now.first, now_position = now.second;
        if (d[now_position] < now_cost)
            continue;
        for (edge e : g[now_position]) {
            ll t = e.time;
            ll d_temp = ((d[now_position] + t - 1) / t) * t;
            if (d[e.to] > d_temp + e.cost) {
                d[e.to] = d_temp + e.cost;
                f[e.to] = now_position;
                q.push(p(d[e.to], e.to));
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, x, y;
    cin >> n >> m >> x >> y;
    x--;
    y--;
    vector<ll> a(m), b(m), t(m), k(m);
    vector<vector<edge>> g(n);
    rep(i, m) {
        cin >> a[i] >> b[i] >> t[i] >> k[i];
        a[i]--;
        b[i]--;
        g[a[i]].push_back({b[i], t[i], k[i]});
        g[b[i]].push_back({a[i], t[i], k[i]});
    }

    vector<ll> d(n, inf), f(n);
    d[x] = 0;
    ll start = x;

    djikstra(d, f, g, start);

    if (d[y] == inf) {
        d[y] = -1;
    }
    cout << d[y] << endl;
    return 0;
}


//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rrep(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define srep(i, s, n) for (long long i = (s); i <= (long long)(n); i++)
#define drep(i,n) for(long long i = (n)-1; i >= 0; --i)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using pll = pair<long long, long long>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------
struct Edge {
    ll to;
    ll w;
    Edge(ll to, ll w) : to(to), w(w) {}
};
using Graph = vector<vector<Edge>>;
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

	ll n,m;
	cin>>n>>m;

	map<ll , vll> mp;
	rep(i,m){
		ll x,y;
		cin>>x>>y;
		mp[x].push_back(y);
	}

	//sort(all(mp));はしなくてもよい。昇順で入っている。多分。
	set<ll> ans;
	set<ll> s; //任意のxについて黒ポーンのあるy座標を格納する。
	s.insert(n);

	for(auto p : mp){

		vector<ll> add;//次にいる場所

		for(auto y : p.second){

			//一つ前の段階でどの座標にいるか調べる。
			if(s.count(y+1)) {
				add.push_back(y);
			}else if(s.count(y-1)){
				add.push_back(y);
			}

			//白の場合はそのまま降ってくるので処理は不要。

		}

		for(auto i : p.second) s.erase(i);
		for(auto i : add) s.insert(i);
	}

	cout<<s.size()<<endl;
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define maxn 200010
// #define mod
using namespace std;
// template<class T>T ABS(T x) {return x<0?-x:x;}
//int ksm(int x,int y) {int r=1;while(y) y&1?r=1ll*r*x%mod:0,x=1ll*x*x%mod,y>>=1;return r;}
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
// struct Edge{int to,next;}a[maxn];
// int h[maxn],cnt;
// void add(int x,int y) {a[++cnt]=(Edge){y,h[x]},h[x]=cnt,a[++cnt]=(Edge){x,h[y]},h[y]=cnt;}
char S[maxn],X[maxn];
int T[10],B[10],pw[maxn],n;
signed main()
{
	n=read();
	scanf("%s%s",S+1,X+1);
	B[0]=1;
	pw[0]=1;for(int i=1;i<n;i++) pw[i]=pw[i-1]*10%7;
	for(int i=n;i;i--)
		if(X[i]=='A')
		{
			for(int j=0;j<7;j++) T[j]=B[j];
			for(int j=0;j<7;j++) B[j]=T[j]&T[((j+(S[i]-'0')*pw[n-i])%7+7)%7];
		}
		else
		{
			for(int j=0;j<7;j++) T[j]=B[j];
			for(int j=0;j<7;j++) B[j]=T[j]|T[((j+(S[i]-'0')*pw[n-i])%7+7)%7];
		}
	cout<<(B[0]?"Takahashi":"Aoki")<<'\n';
	return 0;
}


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

int main(){
  int n;
  string s;
  cin>>n>>s;
  n++;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  int l=0,r=10001,mid;
  bool h;
  while(l<r){
    mid=(l+r)/2;
    vector<vector<int>> A(n,vector<int>(mid));
    h=true;
    for(int i=0;i<n;i++){
      for(int j=0;j<mid;j++){
        A[i][j]=a[i]/mid+(j<a[i]%mid);
      }
    }
    for(int j=0;j<mid;j++){
      for(int i=0;i<n-1;i++){
        if(s[i]=='>'&&A[i][j]<=A[i+1][j])h=false;
        if(s[i]=='<'&&A[i][j]>=A[i+1][j])h=false;
        if(!h)break;
      }
      if(!h)break;
    }
    if(h)l=mid+1;
    else r=mid;
  }
  l--;
  cout<<l<<endl;
  for(int j=0;j<l;j++){
    for(int i=0;i<n;i++){
      if(i)cout<<" ";
      cout<<a[i]/l+(j<a[i]%l);
    }
    cout<<endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
ostream& operator<<(ostream&o,const pair<auto,auto>&p){return o<<"<"<<p.first<<", "<<p.second<<">";}
ostream& operator<<(ostream&o,const vector<auto>&v){o<<'[';int f=0;for(auto&x:v)(f?o<<", ":o)<<x,f=1;return o<<']';}
#ifdef BIZON
    #define rr(...) [](const auto&...x){ char c='='; cerr << boolalpha << "\e[1;38;5;68m" << #__VA_ARGS__ << " "; ((cerr<<"\e[0;38;5;61m"<<exchange(c,',')<<"\e[0m "<<x),...); cerr<<endl; }(__VA_ARGS__);
#else
    #define rr(...) 0;
    #define endl '\n'
#endif
#define ALL(c) begin(c), end(c)
#define II(...) __VA_ARGS__; [](auto&...x){(cin>>...>>x);}(__VA_ARGS__);
#define ii(...) int II(__VA_ARGS__)
inline bool umin(auto&x, const auto&y){ return y<x && (x=y, 1); }
inline bool umax(auto&x, const auto&y){ return y>x && (x=y, 1); }
using ll = long long;

int main(){
    if(auto f="in.txt"; fopen(f,"r") && freopen(f,"r",stdin));
    ios::sync_with_stdio(0);cin.tie(0);

    ii(n)
    vector<int> a(n);
    for(auto &_ : a) cin>>_;

    vector<ll> s(n+1);
    vector<map<ll,int>> m(2);
    m[n%2][0] = 1;
    ll ans = 0;
    for(int i=n-1;i>=0;--i){
        s[i] = a[i] - s[i+1];

        ans+= m[i%2][s[i]];
        ans+= m[1-i%2][-s[i]];

        ++m[i%2][s[i]];
    }

    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long

vector<int> parent;
int root(int i){
  if(parent[i]==i) return i;
  parent[i] = root(parent[i]);
  return parent[i];
}

int main(){

  int n,q;
  cin >> n >> q;

  vector<int> c(n);
  for(auto& i : c) cin >> i;

  vector<map<int,int>> cla(n);
  parent.resize(n);
  //vector<int> len(n,1);

  for(int i=0; i<n; ++i) {
    cla[i][c[i]]++;
    parent[i] = i;
  }

  for(int i=0; i<q; ++i) {
    int t,a,b;
    cin >> t >> a >> b;

    //cout << t << ' ' << a << ' ' << b << endl;

    if(t==1){

      int ra = root(a-1), rb = root(b-1);
      if(ra == rb) continue;

      if(cla[ra].size()>cla[rb].size()){
	for(auto j : cla[rb])
	  cla[ra][j.first] += j.second;
	//cla[rb].clear();
	parent[rb] = ra;
	//len[a-1] += len[b-1];
	//len[b-1] = 0;
      }else{
	for(auto j : cla[ra])
	  cla[rb][j.first] += j.second;
	//cla[ra].clear();
	parent[ra] = rb;
	//len[b-1] += len[a-1];
	//len[a-1] = 0;

      }
    }
    else{
      cout << cla[root(a-1)][b] << endl;
    }
  }

}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#define nl "\n"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;
#define mt make_tuple
#define vec vector
#define ld long double
#define eps 1e-9

#define int long long

const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;

typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 2e5 + 5;
vii g[N] ;
int a[N], b[N], A, B;
bool vis[N] ;

void dfs(int node) {
	if(vis[node]) return ;
	vis[node] = 1 ;

	A += a[node], B += b[node];

	for(auto i : g[node]) {
		if(not vis[i]) {
			dfs(i) ;
		}
	}
}

void solve() {

	int n, m; cin >> n >> m ;

	rep(i,1,n+1) cin >> a[i] ;
	rep(i,1,n+1) cin >> b[i] ;

	rep(i,0,m) {
		int u,v; cin >> u >> v;
		g[u].eb(v) ;
		g[v].eb(u) ;
	}

	rep(i,1,n+1) {
		if(not vis[i]) {
			A = 0 , B = 0 ;
			dfs(i) ;
			if(A != B) {
				cout << "No"; return ;
			}
		}
	}

	cout << "Yes" ;
}

int32_t main() {

#ifdef LOCAL
    freopen("error.txt", "w", stderr);
#endif

    fast;

	// int t; cin >> t; while(t--)
		solve() ;

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}


#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main(){
    vector<long>viOrd(10,0);
    for(int i = 1; i < 10; i++){
        viOrd[i] = viOrd[i-1] * 10 + 9;
    }
    long n,k;
    cin >> n >> k;
    long nTmp = n;
    for(int i = 0; i < k; i++){
        vector<long> viTmp;
        long nThis = nTmp;
        while(nThis > 0){
            viTmp.push_back(nThis%10);
            nThis /= 10;
        }
        sort(viTmp.begin(), viTmp.end());
        long iSize = long(viTmp.size());
        nTmp = 0;
        for(long i = 0; i < iSize/2; i++){
            nTmp += (viTmp[iSize-i-1]-viTmp[i]) * (viOrd[iSize-i-1]-viOrd[i]);
        }
    }
    cout << nTmp << endl;

    return 0;
}

#include<bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<endl
#define rep(i,a,b) for(ll i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(ll i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(ll i=hd[a],y;(y=to[i]);i=nxt[i])
typedef long long ll;
//57200710018

using namespace std;
char IO;
inline ll rd() {
	ll res=0,f=1;
	while(IO=getchar(),IO<48||IO>57)if(IO=='-')f=0;
	do res=(res<<3)+(res<<1)+(IO^48);
	while(IO=getchar(),IO>=48&&IO<=57);
	if(f)return res;
	return -res;
}
inline void Max(ll &a,ll b) {
	((a<b)&&(a=b));
}
inline void Min(ll &a,ll b) {
	((a>b)&&(a=b));
}
bool let;
const ll M=2005,P=1e9+7;
ll mp[M][M],s1[M][M],s2[M][M];
char s[M];
bool vis[M][M];
bool vio;
ll Pow(ll a,ll b) {
	ll res=1;
	for(; b; b>>=1,a=a*a%P)
		if(b&1)res=res*a%P;
	return res;
}
int main() {
//	printf("%.3f",(&vio-&let)/1024.0/1024);
	ll n=rd(),m=rd(),tot=0,ans=0;
	rep(i,1,n) {
		scanf("%s",s+1);
		rep(j,1,m)if(s[j]=='.')mp[i][j]=1,tot++;
	}
//	rep(i,1,n){rep(j,1,m)printf("%d",mp[i][j]);puts("");}
	rep(i,1,n) {
		rep(j,1,m) {
			if(!vis[i][j]&&mp[i][j]) {
				ll t=j;
				while(mp[i][t])t++;
				rep(k,j,t-1) {
					s1[i][k]=t-j;
					vis[i][k]=1;
				}
			}
		}
	}
	memset(vis,0,sizeof vis);
	rep(i,1,n) {
		rep(j,1,m) {
			if(!vis[i][j]&&mp[i][j]) {
				ll t=i;
				while(mp[t][j])t++;
				rep(k,i,t-1) {
					s2[k][j]=t-i;
					vis[k][j]=1;
				}
			}
		}
	}
	rep(i,1,n)rep(j,1,m)if(mp[i][j]) {
		ll t=s1[i][j]+s2[i][j]-1;
		ans=(ans+(Pow(2,t)-1)*Pow(2,tot-t)%P)%P;
	}
	printf("%lld",ans);
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
long long a;
long long n, m;
long long s=0;
vector <int> dd;
void xy(long long r, vector <vector <int>> &qw, vector <vector <int>> &as, long long e, long long d, vector <int> &dd)
{
    if (r!=n+1)
    {
        for (int i=0; i<qw[e].size(); ++i)
        {
            dd[r-1]=e;
            xy(r+1, qw, as, qw[e][i], d+as[e][i], dd);
        }
    }
    else if (e==0 && d==m)
    {
        int y=0;
        vector <int> ff(n);
        for (int i=0; i<n; ++i)
        {
            ff[i]=dd[i];
        }
        sort(ff.begin(), ff.end());
        for (int i=1; i<n; ++i)
            if (ff[i]==ff[i-1])
                y=1;
        if (y==0)
            s+=1;
    }
}
signed main ()
{
    cin >> n >> m;
    vector <vector <int>> qw (n);
    vector <vector <int>> as (n);
    for (int i=0; i<n; ++i)
    {
        for (int ii=0; ii<n; ++ii)
        {
            int f;
            cin >> f;
            qw[i].push_back(ii);
            as[i].push_back(f);
        }
    }
    for (int i=0; i<n; ++i)
        dd.push_back(0);
    a=n;
    xy(1, qw, as, 0, 0, dd);
    cout << s << endl;
}

#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int cost[n + 1][n + 1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			cin >> cost[i][j];
	vector <int> vec;
	for (int i = 1; i <= n; ++i)
		vec.pb(i);
	vec.pb(1);
	int cnt = 0;
	do {
		int tot = 0;
		for (int i = 0; i < n; ++i)
			tot += cost[vec[i]][vec[i + 1]];
		if (tot == k)
			++cnt;
	} while (next_permutation(vec.begin() + 1, vec.begin() + n));
	cout << cnt << endl;
}


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

#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
#define uwu ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize("Ofast")

const int INF = 1e9 + 7;
const long long INF2 = 1e17;

int main(void) {
	uwu

	int n, m; cin >> n >> m;
	vector <string> v(n);
	ffor(n) cin >> v[i];

	const int mod = 998244353;
	long long ans = 1;

	for(int i = 0, j = 0; i != n - 1 || j != m - 1; ) {
		set <char> colours;
		for(int x = i, y = j; 0 <= x && x < n && 0 <= y && y < m; x++, y--) {
			if (v[x][y] != '.') colours.insert(v[x][y]);
		}
		if ((int)colours.size() == 0) {
			ans *= 2;
			ans %= mod;
		}
		else if ((int)colours.size() == 1) {
		}
		else if ((int)colours.size() == 2) {
			cout << 0 << '\n';
			return 0;
		}

		if (j == m - 1) i++;
		else j++;
	}
	if (v[n - 1][m - 1] == '.') ans *= 2;
	ans %= mod;
	cout << ans << '\n';
}

/*
C:\Users\kenne\OneDrive\Desktop\competitive_programming\main.cpp
*/


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
#define INF 1000000001

int main() {
    int N,M; cin>>N>>M;
    vi H(N), W(M);
    for (int i = 0; i < N; i++)cin>>H[i];
    for (int i = 0; i < M; i++)cin>>W[i];

    sort(H.begin(),H.end());
    sort(W.begin(),W.end());
    vi pair_sum((N-1)/2+1, 0);
    for (int i = 1; i <= (N-1)/2; i++){
        pair_sum[i]=pair_sum[i-1]+H[N-1-2*(i-1)]-H[N-2-2*(i-1)];
    }
    priority_queue<int, vi, greater<int>> p;
    for (int i = 1; i < N; i++)p.push(H[i]);
    int waited_partner=H[0];
    int made_pair=0;
    int made_pair_num=0;
    int next=INF;
    int ans=INF;
    for (int i = 0; i < M; i++){
        int join=W[i];
        if(p.empty()){
            ans=min(ans, made_pair+abs(join-waited_partner));
            continue;
        }
        next=p.top();
        while(join>next){
            made_pair+=next-waited_partner; p.pop();
            made_pair_num++;
            waited_partner=p.top(); p.pop();
            if(!p.empty())next=p.top();
            else next=INF;
        }
        ans=min(ans, made_pair+abs(join-waited_partner)+pair_sum[(N+1)/2-1-made_pair_num]);
    }

    cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=2e18;
ll MOD=1000000007;
ll mod=998244353;

int main() {
    int n,l;
    cin >> n >> l;
    vector<int> a(n+2),b(n+2);
    rep(i,n) cin >> a[i+1];
    rep(i,n) cin >> b[i+1];
    a[0]=0;
    a[n+1]=l+1;
    b[0]=0;
    b[n+1]=l+1;
    ll ans=0;
    for (int i=1;i<=n;i++){
        int l=-1,r=n+1;
        while(r-l>1){
            int mid=(r+l)/2;
            if (mid<=i) {
                l=mid;
                continue;
            }
            if (a[mid]-(mid-i)>=b[i]) r=mid;
            else l=mid;
        }
        if (a[r]-(r-i)==b[i] && a[i]!=b[i]){
            rep(j,r-i){
                a[r-j-1]=a[r]-j-1;
                ans++;
            }
        }
    }
    for (int i=n;i>=1;i--){
        int l=0,r=n+2;
        while(r-l>1){
            int mid=(r+l)/2;
            if (mid>=i) {
                r=mid;
                continue;
            }
            if (a[mid]+(i-mid)<=b[i]) l=mid;
            else r=mid;
        }
        if (a[l]+(i-l)==b[i] && a[i]!=b[i]){
            rep(j,i-l){
                a[l+j+1]=a[l]+j+1;
                ans++;
            }
        }
    }
    bool w=true;
    rep(i,n){
        if (a[i+1]!=b[i+1]) w=false;
    }
    if (w) cout << ans << endl;
    else cout << -1 << endl;
}


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

int main(){
  int n;
  cin>>n;
  vector <int> a(n),b(n);
  for(int i=0;i<n;i++){
   cin>>a[i];
  }
for(int i=0;i<n;i++){
cin>>b[i];
}
  int ans=0;
  for(int l=1;l<=1000;l++){
    for(int r=l;r<=1000;r++){
      bool ok=true;
      for(int i=0;i<n;i++){
        if(l>=a[i] and r<=b[i]){

        }
        else{
          ok=false;
        }
      }
      if(ok){
        ans=max(ans,r-l+1);
      }
    }
  }
  cout<<ans<<"\n";
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    vector<int> a, b;
    int n;

    cin >> n;
    a.reserve(n);
    b.reserve(n);

    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }

    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        b.push_back(temp);
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if (a[n - 1] > b[0])
        cout << 0 << endl;

    else
        cout << b[0] - a[n - 1] + 1 << endl;

    return 0;

}


#if 1
#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

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

#define all(x) begin(x), end(x)
typedef pair<int, int> pii;
typedef vector<int> vi;
#endif

int cnt[210000];
int sm[420000];

const int mod = 998244353;
const int inv2 = (998244354/2);

long long calc(long long x) {
    return ((x * (x+1)) % mod) * inv2 % mod;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a,b,c;
    cin >> a >> b >> c;

    long long t = calc(a) * calc(b) % mod;
    t = (t * calc(c)) % mod;

    cout << t << endl;
}

#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

const int MAX = 510000;
const ll MOD = 998244353;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll mod) {
    return modpow(a, mod - 2, mod);
}

ll mod(ll val, ll m) {
    ll res = val % m;
    if (res < 0) res += m;
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    vll A(N);
    rep(i, N) cin >> A[i];

    unordered_map<int, ll> SK;
    REP(x, 0, K + 1) {
        rep(i, N) {
            SK[x] += (modpow(A[i], abs(x), MOD));
            SK[x] %= MOD;
        }
    }
    COMinit();
    REP(X, 1, K + 1) {
        ll ans = 0;
        rep(k, X + 1) {
            ll sk = (SK[X - k] * SK[k]) % MOD;
            //sk = (sk * modinv(2, MOD)) % MOD;
            ll t = (COM(X, k) * sk) % MOD;
            //t = (t * modinv(2, MOD)) % MOD;
            ans += t;
            ans %= MOD;
        }
        ll sub = modpow(2, X, MOD) * SK[X] % MOD;
        ans = mod(ans - sub, MOD);
        ans = ans* modinv(2, MOD) % MOD;
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, d, h;cin>>n>>d>>h;
    cout<<fixed<<setprecision(20);
    vector<pair<int, int>>v;
    int a[n], b[n];for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        v.push_back({b[i], a[i]});
    }

    double ans=0.0;

    for(int i=0;i<n;i++){
        int dd=v[i].second,hh= v[i].first;
    double x=((h-hh)*(1.0)*d)/(d-dd);
    ans=max(ans, h-x);
    }

    cout<<ans;
}

#define _DEBUG
#include "bits/stdc++.h"
//#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define PI acosl(-1)
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define puba emplace_back
#define pubamp(a,b) emplace_back(mp(a,b))
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N,D,H;
	int d[101],h[101];
	ld ymax=0;
	scan(N>>D>>H);
	rep(i,N){
		scan(d[i]>>h[i]);
		chmax(ymax,(ld)H-(ld)D*(H-h[i])/(D-d[i]));
	}
	prind(ymax);
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
// Please write the recurances once :(
void pre(){}
void solve(){
    ll n;cin>>n;
    ll count = 0;
    while(n%2==0){
        count++;
        n/=2;
    }
    if(count==0){
        cout<<"Odd"<<"\n";
    }else if(count==1){
        cout<<"Same"<<"\n";
    }else{
        cout<<"Even"<<"\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    rep(i,n) {
        ll a;
        cin >> a;
        string ans;
        if(a%2==1) ans="Odd";
        else {
            if((a/2)%2==1) ans="Same";
            else ans="Even";
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
  int a[4];
  int ans = 100;
  rep(i,4) {
    cin >> a[i];
    ans = min(ans,a[i]);
  }
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a1,a2,a3,a4;
int main(){
	cin>>a1>>a2>>a3>>a4;
	cout<<min(a1,min(a2,min(a3,a4)));
	return 0;
}


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

double A, B;

int main() {
	scanf("%lf%lf", &A, &B);
	printf("%lf\n", 100.0 - B / A * 100);
	return 0;
}

//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

typedef long long ll;
using vint = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vbool = vector<bool>;
template <class T> using arr = vector<vector<T>>;

//マクロ
// forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
// FORAは範囲for文(使いにくかったら消す)
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; i >= ll(a); i--)
#define FORA(i, I) for (const auto &i : I)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000 // 10^12:∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange

// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

template <class T> void pl(T x) { cout << x << " "; }

template <class T> void pr(T x) { cout << x << endl; }

template <class T> void prvec(const vector<T> &a) {
  REP(i, a.size() - 1) { cout << a[i] << " "; }
  pr(a[a.size() - 1]);
}

template <class T> void prarr(const arr<T> &a) {
  REP(i, a.size())
  if (a[i].empty())
    pr("");
  else
    prvec(a[i]);
}

using P = pair<ll, ll>;
void prp(const P &p) { cout << p.first << " " << p.second << endl; }

struct Constants {
  ll N;
  Constants() { cin >> N; }
} C;

struct Args {
  vector<P> a;
  ll s1, s2;
  Args() : a(C.N) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    REP(i, C.N) {
      ll x, y;
      cin >> x >> y;
      a.at(i).first = x;
      a.at(i).second = y;
      s1 += x;
      s2 += y;
    }
    sort(ALL(a), [](P &l, P &r) {
      return (2 *l.first + l.second) > (2 * r.first + r.second);
    });

  }
} args;

struct Solver {
  ll ans;
  Solver() : ans() {}
  //
  void solve() {
    ll s1 = args.s1;
    ll s2 = 0;
    FORA(p, args.a) {
      if (s1 < s2) {
        return;
      }
      ++ans;
      s1 -= p.first;
      s2 += p.first + p.second;
    }
  }

  void output() { pr(ans); }
} s;

int main() {
  s.solve();
  s.output();
  return 0;
}


#include <bits/stdc++.h>
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
typedef double DB;
typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
// head
const LL MOD=1e9+7;
const int N=2e5+5;
int k,d[N];
LL dp[N][17];
string s;
int get(char c) {
    if(isdigit(c)) return c-'0';
    else return c-'A'+10;
}
LL dfs(int x,int st,bool a,bool b) {
    if(x==SZ(s)) return !a&&d[st]==k;
    if(!a&&!b&&dp[x][d[st]]!=-1) return dp[x][d[st]];
    int mx=b?get(s[x]):15;
    LL ret=0;
    for(int i=0;i<=mx;i++) {
        if(a&!i&&d[st|(1<<i)]>k) continue;
        ret=(ret+dfs(x+1,(a&!i)?0:st|(1<<i),a&!i,b&(i==mx)))%MOD;
    }
    if(!a&&!b) dp[x][d[st]]=ret;
    return ret;
}
int main() {
    cin>>s>>k;
    for(int i=0;i<1<<16;i++) d[i]=__builtin_popcount(i);
    memset(dp,-1,sizeof dp);
    cout<<dfs(0,0,true,true)<<'\n';
    return 0;
}

/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Digits Paradise in Hexadecimal
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_N + 4];
int dp[MAX_N + 1][17];
bool used[16];

/* subroutines */

inline int hex2dec(char c) {
  return (c >= '0' && c <= '9') ? (c - '0') : (c - 'A' + 10);
}

inline void addmod(int &a, int b) { a = (a + b) % MOD; }
inline int pmod(int a, int b) { return (int)((ll)a * b % MOD); }

/* main */

int main() {
  int k;
  scanf("%s%d", s, &k);
  int n = strlen(s);

  int s0 = hex2dec(s[0]);
  dp[1][1] = s0 - 1;
  used[s0] = true;
  int c = 1;

  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= 16; j++)
      if (dp[i][j] > 0) {
	addmod(dp[i + 1][j], pmod(dp[i][j], j));
	if (j < 16)
	  addmod(dp[i + 1][j + 1], pmod(dp[i][j], 16 - j));
      }

    int si = hex2dec(s[i]), e0 = 0, e1 = 0;
    for (int j = 0; j < si; j++) {
      if (used[j]) e0++;
      else e1++;
    }
    addmod(dp[i + 1][c], e0);
    if (c < 16) addmod(dp[i + 1][c + 1], e1);

    addmod(dp[i + 1][1], 15);

    if (! used[si])
      used[si] = true, c++;
  }

  addmod(dp[n][c], 1);

  printf("%d\n", dp[n][k]);
  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;

#define LL long long
#define DB double
#define MAXN 100
#define Pr pair<int,int>
#define X first
#define Y second
#define INF 1000000001
#define mem(x,v) memset(x,v,sizeof(x))

LL read(){
    LL x=0,F=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*F;
}

int MOD;
int add(int a,int b){return (a+b>=MOD)?a+b-MOD:a+b;}
int dec(int a,int b){return (a-b<0)?a-b+MOD:a-b;}
int mul(int a,int b){return (1LL*a*b)%MOD;}
int fst_pow(int a,int b){
	int res=1;
	while(b){
		if(b&1)res=mul(res,a);
		a=mul(a,a),b>>=1;
	}return res;
}
inline void upd(int &x,int y){
	x=(x+y)%MOD;
	if(x<0)x+=MOD;
}

int n,k,lim,res,dp[105][1000005];

int main(){
	n=read(),k=read(),MOD=read();
	lim=k*n*(n-1)/2;
	dp[0][0]=1;
	for(int i=1;i<n;i++){
		for(int j=0;j<=lim;j++){
			upd(dp[i][j],dp[i-1][j]);
			if(j>=i)upd(dp[i][j],dp[i][j-i]);
		}
		for(int j=lim;j>=i*(k+1);j--){
			upd(dp[i][j],dec(0,dp[i][j-i*(k+1)]));
		}
	}
	for(int i=1;i<=n;i++){
		res=0;
		for(int j=0;j<=lim;j++)
		res=add(res,mul(dp[i-1][j],dp[n-i][j]));
		printf("%d\n",dec(mul(res,k+1),1));
	}
}

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

ll f(string s) {
  vector<ll> c(10);
  ll res = 0;
  rep(i, 5) c[s[i] - '0']++;
  for (int i = 1; i < 10; ++i) {
    ll t = i;
    while (c[i]--) t *= 10;
    res += t;
  }
  return res;
}

int main() {
  ll k;
  string s, t;
  cin >> k >> s >> t;

  vector<ll> card(10, k);

  rep(i, 4) card[s[i] - '0']--;
  rep(i, 4) card[t[i] - '0']--;
  ll res = 9 * k - 8;
  ll tot = res * (res - 1);
  ll cnt = 0;
  for (int i = 1; i < 10; ++i) {
    for (int j = 1; j < 10; ++j) {
      s[4] = '0' + i;
      t[4] = '0' + j;
      if (f(s) > f(t)) {
        if (i == j)
          cnt += card[i] * (card[i] - 1);
        else
          cnt += card[i] * card[j];
      }
    }
  }

  long double z = (long double)cnt / tot;

  cout << setprecision(15) << z << endl;
  return 0;
}


#include <iostream>
#include <iomanip>

double ans[112][112][112];

int main(){
	for(int i = 99; i >= 0; --i){
		for(int j = 99; j >= 0; --j){
			for(int k = 99; k >= 0; --k){
				int sum = i + j + k;
				ans[i][j][k] += ans[i + 1][j][k] * i;
				ans[i][j][k] += ans[i][j + 1][k] * j;
				ans[i][j][k] += ans[i][j][k + 1] * k;
				ans[i][j][k] /= sum;
				ans[i][j][k] += 1;
			}
		}
	}
	int a, b, c;
	std::cin >> a >> b >> c;
	std::cout << std::setprecision(100) << ans[a][b][c] << std::endl;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f;
#define sz(x) (int)x.size()
#define af(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x);
#define fil(x, y) fill(af(x), y);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define lc i << 1
#define rc i << 1 | 1
const int mod = 1e9 + 7;
ll fpow(ll a, ll b){ll ret=1;while(b){if(b&1)ret=ret*a%mod;a=a*a%mod,b>>=1;}return ret;}
ll inv(ll x){return x ? fpow(x, mod - 2) : 1;}
void madd(int &a, int b){a+=b;if(a>=mod)a-=mod;}
void msub(int &a, int b){a+=mod-b;if(a>=mod)a-=mod;}
const int MM = 2e5 + 5;
void solve(){
	int a, b, c;
	cin >> a >> b >> c;
	vector<vector<vector<double>>> dp(101, vector<vector<double>>(101, vector<double>(101)));
	function<double(int,int,int)> rec = [&](int x, int y, int z){
		if (x == 100 || y == 100 || z == 100) return 0.0;
		if (dp[x][y][z] != 0.0) return dp[x][y][z];
		int t = x + y + z;
		return dp[x][y][z] = 1.0*x/t*(1.0+rec(x+1,y,z)) + 1.0*y/t*(1.0+rec(x,y+1,z)) + 1.0*z/t*(1.0+rec(x,y,z+1));
	};
	cout << fixed << setprecision(10) << rec(a, b, c) << '\n';
}

int main(){
	cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i,n)for(ll i=0;i<(n);i++)
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
typedef long long ll;   typedef long double ld; typedef pair<ll,ll>pint;
using vll=vector<ll>;   using vs=vector<string>;
#define p2a(v, p) v[p.first][p.second]

void arrdot(vector<vector<ll>>& v1,vector<vector<ll>>& v2) {
    vector<vector<ll>> buf(3, vll(3,0));
    rep(i,3) rep(j,3) rep(k,3) {
        buf[i][j] += v1[i][k]*v2[k][j];
    }
    v1=buf;
}

void rotXY(pint& p, vector<vll>& rot) {
    ll x=rot[0][0]*p.first+rot[0][1]*p.second+rot[0][2];
    ll y=rot[1][0]*p.first+rot[1][1]*p.second+rot[1][2];
    p = {x,y};
}

int main() {
    ll n; cin >> n;
    vector<pint> point(n);
    rep(i,n) {
        ll x,y; cin >> x>>y;
        point[i]={x,y};
    }

    ll m; cin >> m;
    vector<vector<vector<ll>>> rot={{{1,0,0},{0,1,0},{0,0,1}}};
    vector<vector<vll>> rot_op={
        {{0,1,0},{-1,0,0},{0,0,1}},
        {{0,-1,0},{1,0,0},{0,0,1}},
        {{-1,0,2},{0,1,0},{0,0,1}},
        {{1,0,0},{0,-1,2},{0,0,1}},
    };
    rep(i,m) {
        int cmd; cin>>cmd; cmd--;
        vector<vector<ll>> buf=rot_op[cmd];

        if(cmd==2) {
            int p; cin>>p;
            buf[0][2]*=p;
        }
        if(cmd==3) {
            int p; cin>>p;
            buf[1][2]*=p;
        }
        arrdot(buf, rot.back());
        rot.push_back(buf);
    }

    // read query
    ll qn; cin >> qn;
    rep(i,qn) {
        ll x,y; cin >> x >> y; y--;
        vector<vector<ll>> rot_i=rot[x];
        pint p = point[y];
        rotXY(p,rot_i);
        cout << p.first << " ";
        cout << p.second << endl;
    }
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using db = double; using str = string;
using pi = pair<int,int>;
using vi = vector<int>; using vs = vector<str>;
using vl = vector<ll>; using vd = vector<double>;
using vvi = vector<vector<int>>;
using vvs = vector<vector<string>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using pqi = priority_queue<int>;
using rpqi = priority_queue<int, vi, greater<int>>;
using umi = unordered_map<int, int>;
using usi = unordered_set<int>;

#define PB push_back
#define PF push_front
#define PK pop_back()
#define PT pop_front()
#define EB emplace_back
#define LB lower_bound
#define UB upper_bound
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define VT vector
#define se second
#define fi first
#define rt return
#define ln "\n"
#define ctu continue
#define F1(e) for(int i=0;i<(e);++i)
#define F2(i,e) for(int i=0;i<(e);++i)
#define F3(i,b,e) for(int i=(b);i<(e);++i)
#define F4(i,b,e,s) for(int i=(b); (s)>0?i<(e):i>(e); i+=(s))
#define Sum(a) accumulate((a).begin(), (a).end() , 0ll);
#define Min(a) *std::min_element((a).begin(), (a).end())
#define Max(a) *std::max_element((a).begin(), (a).end())
#define Sort(c) sort((c).begin(), (c).end())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define each(x,a) for(auto& x : a)
#define all(c) (c).begin(), (c).end()
#define rall(a) rbegin(a),rend(a)
#define mst(a,x) memset(a, x, sizeof(a))
#define to_unique(a) a.erase(unique(begin(a), end(a)), end(a))
#define bct(x) (__builtin_popcountll(x))
#define in(x, a) a.find((x)) != a.end()
#define sz(x) ((int)(x).size())
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define isok(x, y) (x >= 0 && x < n && y >= 0 && y < m && !vis[x][y])

const ll mod = 1e9 + 7;
const double PI=acos(-1.0);
const int fx[4] = {1, 0, -1, 0}, fy[4] = {0, 1, 0, -1};
const int dx[8]={-1, -1, 0, 1, 1, 1, 0, -1}, dy[8]={0, 1, 1, 1, 0, -1, -1, -1};

template<class A> void read(VT<A>& v);
template<class T> void read(T& x) { cin >> x; }
template<class H, class... T> void read(H& h, T&... t) {
	read(h); read(t...);
}
template<class A> void read(VT<A>& x) {
	each(a, x) read(a);
}

template<class A> void wte(A x) {cout << x;}
template<class H, class... T> void wte(const H& h, const T&... t) {
	wte(h); cout<<' '; wte(t...);
}
template<class A> void wte(VT<A>& x) {
    bool f=1;
	each(a, x){
	    if(f==1) {
	        wte(a); f=0;
	    } else wte(' '),wte(a);
	}
	cout<<'\n';
}
const int N = 1e5 + 10;
int n,m,k;
int a[N];
int main() {
    IOS;
    int x,y;
    read(x,y);
    cout<<x/100.0*y<<ln;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <sstream>
#define INF 1000000009
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main() {

    ll k,n,m;

    cin >> k >> n >> m;
    ll x = m;
    vector<ll> ans(k);
    vector<p> pa(k);
    rep(i,k){
      ll a;
      cin >> a;
      ans[i] = (a*m)/n;
      x -= ans[i];
      ll sa = (a*m) % n;
      pa[i] = {sa,i};
    }
    if(x == 0){
      rep(i,k) cout << ans[i] << " ";
      cout << endl;
      return 0;
    }
    sort(pa.begin(), pa.end(), greater<p>() );
    rep(i,x){
      ans[pa[i].second]++;
    }
    rep(i,k) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

#ifdef DEBUG_BUILD
# define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#ifdef DEBUG_BUILD
# include "debugger.hpp"
#else
# define debug(...)
# define debugdo(...)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using pll = std::pair<ll, ll>;
template <class T> using vec = std::vector<T>;
template <class T> using vec2 = std::vector<vec<T>>;
template <class T> using vec3 = std::vector<vec2<T>>;
#define rep(i, N) for (ll i = 0; i < (N); i++)
#define rrep(i, N) for (ll i = (N) - 1; i >= 0; i--)
#define range(i, A, B) for (ll i = (A); i < (B); i++)
constexpr int MOD = 1000000007;
constexpr ll INFL = std::numeric_limits<ll>::max();
template <class T> bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; }

void Main() {
    ll N;
    ll D, H;
    cin >> N >> D >> H;
    ld ret = 0;
    rep(i, N) {
        ll d, h;
        cin >> d >> h;
        ld b = (ld)(h * (D - d) - (H - h) * d) / (D - d) ;
        chmax(ret, b);
    }
    cout << ret << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    Main();
    std::cout << std::flush;
    std::cerr << "--end--" << std::flush;
    return 0;
}


#include <algorithm>
#include <iostream>
#include <deque>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <list>
#include <vector>

// #include <atcoder/convolution>

using namespace std;
using ll = long long;
#define len(s) static_cast<ll>(s.size())
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(c) c.begin(), c.end()

template<typename T, const char* fmt>
struct INPUT {
    T value;
    INPUT() { scanf(fmt, &value); }
    operator T() { return value; }
};
const char IC_FMT[] = "%c";
const char ILL_FMT[] = "%lld";
using IC = INPUT<char, IC_FMT>;
using ILL = INPUT<ll, ILL_FMT>;

template <typename T>
void print(T t) {
    cout << t << endl;
}

template <typename T, typename S, typename... Args>
void print(T t, S s, Args... args) {
    cout << t << ' ';
    print(s, args...);
}

template<typename... Args>
void debug(Args... args) {
    #ifdef DEBUG
    print(args...);
    #endif
}

struct Cargo {
    ll weight;
    ll value;
};

bool operator<(const Cargo& a, const Cargo& b) noexcept {
    return a.value < b.value;
}

struct Box {
    ll number;
    ll capacity;
};

bool operator<(const Box& a, const Box& b) noexcept {
    return a.capacity < b.capacity;
}

struct Query {
    ll l, r;
};

int main() {
    ILL N, M, Q;
    vector<Cargo> cargos;
    rep(i, N) {
        ILL W, V;
        cargos.push_back({W, V});
    }
    vector<Box> boxes;
    ll number = 1;
    rep(i, M) {
        ILL B;
        boxes.push_back({number, B});
        number++;
    }

    sort(all(cargos));
    reverse(all(cargos));
    sort(all(boxes));

    set<ll> used;
    rep(i, Q) {
        used.clear();
        ILL L, R;
        ll value = 0;
        for (auto c : cargos) {
            // debug(L, R);
            // Find box
            for (auto b : boxes) {
                if (used.count(b.number)) continue;
                if (L <= b.number && b.number <= R) continue;
                if (c.weight > b.capacity) continue;
                used.insert(b.number);
                value += c.value;
                break;
            }
        }
        print(value);
    }

    return 0;
}

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>

using ll = long long;

ll pow2(int x) {
    ll i=1;
    if (x == 0) return i;
    for (int k=0; k<x; k++) {
        i *= 2;
    }
    return i;
}

int main() {
    std::vector<ll> a;
    int n;

    std::cin >> n;
    a.reserve(pow2(n));
    for (ll i=1; i<=pow2(n); i++) {
        ll t;
        std::cin >> t;
        a.push_back(t);
    }

    ll m1v = 0;
    size_t m1;
    for (ll i=0; i<pow2(n-1); i++) {
        if (a.at(i) > m1v) {
            m1v = a.at(i);
            m1 = i+1;
        }
    }

    ll m2v = 0;
    size_t m2;
    for (ll i=pow2(n-1); i<pow2(n); i++) {
        if (a.at(i) > m2v) {
            m2v = a.at(i);
            m2 = i+1;
        }
    }

    std::cout << (m1v > m2v ? m2 : m1) << std::endl;

    return 0;
}


#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_ll.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=998244353;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<ll>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc ll t; cin >> t; while(t--)

// using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}
void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }

const ll N1=1e6+1;
vector<ll> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(ll j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}

struct dsu {
    vector<ll> par, rank;
    dsu(ll n): par(n+1), rank(n+1) {
        for (ll i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    ll root(ll a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(ll a, ll b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<ll> parent(ll n){
        set<ll> s;
        for(ll i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};
void solve(){
  // ll n,k;
  // cin>>n>>k;
  // vector<vector<ll>> dp(n+1,vector<ll>(k+1,0));
  // rep(i,1,n+1) dp[i][1]=1;
  // rep(i,2,n+1){
  //   rep(k1,1,k+1){
  //     ll lim=i;
  //     if(k1==2) lim=(i%2==0?i/2:i/2);
  //     rep(j,1,lim+1){
  //       if(i-j>=0 ) dp[i][k1]=(dp[i][k1]+(dp[j][k1-1]*dp[i-j][1]))%mod;
  //     }
  //   }
  // }
  // cout<<dp[n][k]<<endl;
  // int mod=998244353;
  // int n,k,f[3010][3010];
  // scanf("%d %d",&n,&k);
  // f[0][k]=1;
	// for(int i=0;i<n;i++)
	// 	for(int j=1;j<=n;j++) if(f[i][j])
	// 	{
	// 		if(2*j<=n) (f[i][2*j]+=f[i][j])%=mod;
	// 		(f[i+1][j-1]+=f[i][j])%=mod;
	// 	}
	// printf("%d",f[n][0]);

  ll n,kl;
  cin>>n>>kl;
  vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
  dp[1][1]=1;
  rep(i,2,n+1){
    rrep(k,n+1,1){
      dp[i][k]=(dp[i][k]+dp[i-1][k-1]+(2*k<=i?dp[i][2*k]:0))%mod;
    }
  }
  cout<<dp[n][kl]<<endl;
}

int32_t main(){
    optimizeIO();
    {solve();}
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
  if ((x += a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator-=(const mint a) {
  if ((x += mod-a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
  if (!t) return 1;
  mint a = pow(t>>1);
  a *= a;
  if (t&1) a *= *this;
  return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<vector<mint>> dp(N+2, vector<mint>(N+2, 0));
    dp.at(0).at(0) = 1;
    rep(i, N+1){
      for(ll j = N; j >= 0; j--){
        dp.at(i+1).at(j+1) += dp.at(i).at(j);
        if(j % 2 == 0 && j > 0){
          dp.at(i).at(j/2) += dp.at(i).at(j);
        }
      }
    }
    cout << dp.at(N).at(K) << endl;
}