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

// template {{{  0
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,K;
    char S[322];
    Scs(S);
    N = strlen(S);
    Scd(K);

    if( K >= N/2 ) {
        printf ("%d\n", N);
        return 0;
    }

    static int dp[301][301][302] = {};

    Rep(ni,N) Rep(mi,N) {
        int mir = N-1-mi;
        bool same = S[ni] == S[mir];
        RRep(ki,K+1){
            // 無変換
            dp[ni+1][mi+1][ki] = max( dp[ni][mi+1][ki], dp[ni+1][mi+1][ki] );
            dp[ni+1][mi+1][ki] = max( dp[ni+1][mi][ki], dp[ni+1][mi+1][ki] );
            dp[ni+1][mi+1][ki] = max( dp[ni][mi][ki]+same, dp[ni+1][mi+1][ki] );
            // 変換
            dp[ni+1][mi+1][ki+1] = max( dp[ni][mi][ki]+1, dp[ni+1][mi+1][ki+1] );
        }
    }

    // Rep(ki,K+1){
    //     Rep(ni,N+1) Rep(mi,N+1){
    //         printf ("%d%s", dp[ni][mi][ki], mi!=N?",":"\n" );
    //     }
    //     printf ("---\n");
    // }

    int ans = 0;
    Rep(ni,N+1) Rep(mi,N+1){
        if( ni + mi > N ) break;
        Rep(ki,K+1){
            ans = max( dp[ni][mi][ki]*2+(ni+mi<N), ans );
        }
    }
    printf ("%d\n", ans );

    return 0;
}

/**
atcodergrandcontest
atcoder
g
atsetnocdn
 *
 */

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
int dp[301][301][301] = {};
string S;

int calc(ll i, ll j, ll k){
    int &res = dp[i][j][k];
    if(~res) return res;
    if(j - i == 0){
        return res = 0;
    }else if(j - i == 1){
        return res = 1;
    }
    res = 0;
    if(S[i] == S[j-1]){
        res = 2 + calc(i+1, j-1, k);
    }else{
        if(k > 0){
            res = 2 + calc(i+1, j-1, k-1);
        }
    }
    res = max(res, calc(i, j-1, k));
    res = max(res, calc(i+1, j, k));
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> S;
    ll K;
    cin >> K;
    memset(dp, -1, sizeof(dp));
    ll N = S.size();
    ll ans = calc(0,N,K);
    print(ans);

}


#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a , b;
    cin >> a >> b;
    cout << max( a + b , max( a - b , a * b ) );
}

#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
typedef long long ll;
const ll maxn = 1e6+10;
const ll inf = 1e16;

int N,K;
int main(){
//    freopen("in.txt", "r", stdin);
    cin>>N>>K;
    cout<<N-K+1<<endl;

    return 0;
}


#include <bits/stdc++.h>
//#include "atcoder/all"
typedef long long int ll;
using namespace std;
// using namespace atcoder;
#define MAXN 300001
#define mod 1000000007
ll a[MAXN];
int main() {
    int n;
    cin >> n;
    ll co[60];
    for (int i = 0; i < 60; i++) co[i] = 0;
    for (int i = 1; i <= n; i++) {
        ll a;
        cin >> a;
        int count = 0;
        while (a) {
            co[count]+= a % 2;
            a /= 2;
            count++;
        }
    }
    ll ret = 0;
    int now = 1;
    for (int i = 0; i < 60; i++) {
        ret = (ret + (now * co[i] % mod)  * (n - co[i])) % mod;
        now = now * 2 % mod;
    }
    cout << ret << endl;
    return 0;
}

#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

const int N = 5050;
const ll INF = 0x3f3f3f3f;

ll dp[N][N];
int n, w[N], h[N], a[N], ans;

bool cmp(int A,int B){
    return w[A] + h[A] < w[B] + h[B];
}

int main(){
    scanf("%d", &n);
    for(int i = 0;i<n;i++){
        scanf("%d%d", h + i, w + i);a[i] = i;
    }
    sort(a, a + n, cmp);
    for(int i = 0;i<=n;i++){
        dp[0][i] = INF * INF;
        dp[i][0] = 0;
    }
    dp[0][1] = w[a[0]];
    for(int i = 1;i<n;i++){
        for(int j = 1;j<=n;j++){
            dp[i][j] = dp[i - 1][j];
            if(h[a[i]] >= dp[i - 1][j - 1])
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + w[a[i]]);
        }
    }
    ans = n;
    while(dp[n - 1][ans] == INF * INF) ans--;
    printf("%d\n", ans);
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool compare(P a,P b){
    if(a.first == b.first) return a.second < b.second;
    return a.first < b.first;
}

int main(){
    //cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);

    int n;cin>>n;
    vector<int> perm(8);
    REP(i,8){
        perm[i] = i;
    }
    vector<P> xy(n);
    REP(i,n){
        int x,y; cin >> x >> y;
        xy[i] = P(x,y);
    }
    sort(ALL(xy),compare);
    do{
        vector<P> permutation(8);
        REP(i,8){
            permutation[i] = P(i,perm[i]);
        }
        bool flag1 = true;
        REP(i,n){
            if(!binary_search(ALL(permutation),xy[i], compare)) {
                flag1 = false; break;
            }
        }
        if(!flag1) continue;

        bool flag = true;
        REP(i,7){
            FOR(k,i+1,8){
                if(abs(k-i) == abs(perm[k]-perm[i])){
                    flag = false; break;
                }
            }
            if(!flag) break;
        }
        if(flag == true){
            REP(i,8){
                REP(k,8){
                    if(binary_search(ALL(permutation),P(i,k),compare)){
                        cout<<'Q';
                    }
                    else cout<<'.';
                }
                cout<<endl;
            }
            return 0;
        }

    }while(next_permutation(ALL(perm)));
}

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#define ll long long
using namespace std;
inline ll read(){
	ll re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll d,len,ans=0,mi[20],me[20],cur[20];
void dfs(ll n,ll val,ll tmp){
//	cout<<"dfs "<<n<<' '<<val<<' '<<tmp<<' '<<d<<' '<<mi[len-n-1]<<' '<<mi[n-1]<<'\n';
	if(n>(len/2-1)){

		if(len%2) tmp*=10;
		if(val==d) ans+=tmp;
		return;
	}
	ll i=-9;
	while(i<=9&&i*(mi[len-n-1]-mi[n])+val<=d) i++;
	i--;cur[n]=i;
	dfs(n+1,val+i*(mi[len-n-1]-mi[n]),tmp*(me[i+10]-(n==0&&i>=0)));
	if(i==9) return;
	i++;cur[n]=i;
	dfs(n+1,val+i*(mi[len-n-1]-mi[n]),tmp*(me[i+10]-(n==0&&i>=0)));
}
int main(){
	d=read();ll i,j;
	mi[0]=1;
	for(i=1;i<=18;i++) mi[i]=mi[i-1]*10;
	for(i=0;i<=9;i++) for(j=0;j<=9;j++) me[i-j+10]++;
	for(len=0;len<=19;len++) dfs(0,0,1);
	printf("%lld\n",ans);
//	system("pause");
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define endl "\n"

ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
ll timer;
vll pre, par, low, seen;
vvll graph;

void init(ll N){
  pre.resize(N); par.resize(N);
  low.resize(N); seen.resize(N,0);
  graph.resize(N,vll());
  timer = 1;
}
void dfs(ll cur, ll pas){

  pre[cur] = low[cur] = timer;
  timer++;

  seen[cur] = 1;

  for(ll i=0;i<graph[cur].size();i++){
    ll next = graph[cur][i];
    if(!seen[next]){
      par[next] =  cur;

      dfs(next, cur);
      low[cur] = min(low[cur], low[next]);
    }
    else if(next != pas){
      low[cur] = min(low[cur], pre[next]);
    }
  }
}

void art_point(ll N, set<ll> &arp){
  seen.resize(N,0);
  timer = 1;
  dfs(0,-1);

  ll np = 0;
  for(ll i=1;i<N;i++){
    ll p = par[i];
    if(p == 0) np++;
    else if(pre[p] <= low[i]) arp.insert(p);
  }
  if(np > 1) arp.insert(0);

}
//-----------------------------------------

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll v, e;
  cin >> v >> e;
  init(v);
  REP(i,e){
    ll a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  set<ll> st;
  art_point(v,st);
  IREP(i,st) cout << (*i) <<endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;

struct LowLink{
    vector<vector<int>>& edges;
    // 関節点
    vector<int> art;
    vector<pair<int,int>> bridge;

    vector<int> used, ord, low;
    int k;

    void dfs(int idx, int par){
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_art = false;
        int cnt = 0;
        for(auto& to : edges[idx]){
            if(ord[to] == -1){
                ++cnt;
                dfs(to, idx);
                low[idx] = min(low[idx], low[to]);
                is_art |= par != -1 && low[to] >= ord[idx];
                if(ord[idx] < low[to])
                    bridge.emplace_back(idx, to);
            }else if(to != par)
                low[idx] = min(low[idx], ord[to]);
        }
        is_art |= (par == -1 && cnt > 1);
        if(is_art)
            art.emplace_back(idx);
    }

    LowLink(vector<vector<int>>& edges) :
        edges(edges),
        ord(edges.size(), -1),
        low(edges.size(), 0),
        k(0)
    {
        for(int i = 0; i < edges.size(); ++i)
            if(ord[i] == -1)
                dfs(i, -1);
        for(auto& b : bridge)
            b = make_pair(min(b.first, b.second), max(b.first, b.second));
        sort(art.begin(), art.end());
        sort(bridge.begin(), bridge.end());
    }
};

signed main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v(m);
    vector<vector<int>> edges(n);
    for(int i = 0; i < m; ++i){
        vector<int> l(2);
        for(auto& x : l)
            cin >> x;
        sort(l.begin(), l.end());
        v[i] = make_pair(l.front(), l.back());
        edges[l[0]].emplace_back(l[1]);
        edges[l[1]].emplace_back(l[0]);
    }
    LowLink ll(edges);
    for(auto& x : ll.art)
        cout << x << endl;
}


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

constexpr ll MOD = 1000000007;

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

  vector<ll> one(60);
  rep(i, 0, n) {
    cin >> a;
    rep(j, 0, 60) if (a >> j & 1) one[j]++;
  }

  ll ans = 0;
  rep(i, 0, 60) ans =
    (ans + (1ll << i) % MOD * one[i] % MOD * (n - one[i]) % MOD) % MOD;

  cout << ans << endl;
  return 0;
}

#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
#include <cassert>
#include <bit>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;n>>=1;}return res;}//x^n%mod
int main(){
    ll n;
    ll a[MAX*3];
    cin>>n;
    rep(i,n)cin>>a[i];
    ll sum=0;
    ll two_factors=1;
    rep(d,60){
        ll p=0,q=0;
        rep(i,n){
            if(a[i] & (1LL<<d))p++;
            else q++;
        }
        sum=(sum+(p*q)%MOD*two_factors%MOD)%MOD;
        two_factors=two_factors*2%MOD;
    }
    cout<<sum<<endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

int N, M;
const int OFFSET = 2000;

LL dp[6001][8001];

LL memo(int total, int dif) {
	if (dif < 0)
		return 0LL;
	if (!total)
		return dif >= OFFSET;

	LL &ret = dp[total][dif];
	if (ret != -1)
		return ret;

	ret = 0LL;

	if (total >= 3)
		ret += (total - 1LL) * (total - 2LL) * memo(total - 3, dif);
	if (total >= 2)
		ret += (total - 1LL) * memo(total - 2, dif - 1);
	ret += memo(total - 1, dif + 1);

	ret %= M;
	return ret;
}

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

	cin >> N >> M;

	SET(dp, 255);

	cout << memo(3 * N, OFFSET) << endl;

	return 0;
}

#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<cstdio>
#include<queue>
#include<cmath>
#include<vector>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
    int f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f*x;
}
#define MAXN 12000
#define INF 0x3f3f3f3f
int Mod;
int Pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1) ret=1ll*ret*x%Mod;
		x=1ll*x*x%Mod,y>>=1;
	}
	return ret;
}
int f[MAXN+5][MAXN+5],inv[MAXN+5];
int main(){
	int n=read(),O=3*n;
	Mod=read();
	for(int i=1;i<=3*n;i++)
		inv[i]=Pow(i,Mod-2);
	f[0][O]=1;
	for(int i=1;i<=3*n;i++)
		for(int j=0;j<=6*n;j++){
			f[i][j]+=f[i-1][j-1];
			if(f[i][j]>=Mod) f[i][j]-=Mod;
			if(i>=2)
				f[i][j]+=f[i-2][j+1];
			if(f[i][j]>=Mod) f[i][j]-=Mod;
			if(i>=3)
				f[i][j]+=f[i-3][j];
			if(f[i][j]>=Mod) f[i][j]-=Mod;
			f[i][j]=1ll*f[i][j]*inv[i]%Mod;
		}
	int ans=0,n3=1;
	for(int i=1;i<=3*n;i++)
		n3=1ll*n3*i%Mod;
	for(int i=O;i<=6*n;i++)
		ans=(ans+1ll*n3*f[3*n][i]%Mod)%Mod;
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    string s;cin>>s;
    s[3]='8';
    cout<<s<<endl;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    double result{0};
    double n; cin >> n;
    //lol k; cin >> k;
    /*
    vector<lol> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */
    result = 2*n*PI;

    cout << result << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define pb push_back
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 507;
const int MX = 1e9 + 7;
const LL INF = 1e18 + 9LL;

int n;
LL tab[N][N];
vector <int> primes;

LL nwd(LL a, LL b){
	if(b == 0)
		return a;
	return nwd(b, a%b);
}

LL get(LL a, LL b, LL c, LL d){
	LL ret = a / nwd(a, b) * b;
	ret = ret / nwd(ret, c) * c;
	ret = ret / nwd(ret, d) * d;
	return ret;
}

bool ok(int a){
	for(int i = 2; i * i <= a; ++i)
		if(a%i == 0)
			return false;
	return true;
}

int main(){
	scanf("%d", &n);
	if(n == 2){
		puts("2 3\n5 4");
		return 0;
	}

	for(int i = 2; primes.size() < n + n; ++i)
		if(ok(i))
			primes.push_back(i);

	for(int i = 0; i <= n + 1; ++i)
		for(int j = 0; j <= n + 1; ++j)
			tab[i][j] = 1;

	int sx = n - 1 + (n & 1), sy = 1;
	for(int i = 1; i <= n - 1 + (n & 1); ++i){
		int cx = sx, cy = sy;
		while(cx <= n && cy <= n){
			tab[cx][cy] *= primes.back();
			++cx, ++cy;
		}

		if(sx > 2)
			sx -= 2;
		else{
			if(sy == 1 && sx == 2)
				sx = 1, sy++;
			else
				sy += 2;
		}

		primes.pop_back();
	}

	sx = 1, sy = 1;
	for(int i = 1; i <= n; ++i){
		int cx = sx, cy = sy;
		while(cx <= n && cy >= 1){
			tab[cx][cy] *= primes.back();
			++cx, --cy;
		}

		if(sy + 1 < n)
			sy += 2;
		else{
			if(sx == 1 && sy + 1 == n)
				sy = n, ++sx;
			else
				sx += 2;
		}

		primes.pop_back();
	}

	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j){
			if((i + j) & 1)
				tab[i][j] = get(tab[i - 1][j], tab[i][j - 1], tab[i + 1][j], tab[i][j + 1]) + 1;
			printf("%lld ", tab[i][j]);
		}

		puts("");
	}

	return 0;
}

#include "bits/stdc++.h"

using namespace std;

#define int long long int
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> matrix;

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x;}
inline int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x;}
inline int mul(int x, int y) { return ((x % mod) * (y % mod)) % mod;}
inline int power(int a, int b) {
	int x = 1;
	while (b) {
		if (b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a) { return power(a, mod - 2);}

const int N = 5005;
int n, dp[N][N];
pii a[N];

bool cmp(pii one, pii two) {
	return (one.fi + one.se < two.fi + two.se);
}

#undef int
int main() {
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	clock_t start = clock();

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].fi >> a[i].se;
	}
	sort(a + 1, a + n + 1, cmp);

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i][j] = inf;
		}
	}

	dp[1][1] = a[1].se;
	int ans = 1;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			if (dp[i - 1][j - 1] > a[i].fi) dp[i][j] = dp[i - 1][j];
			else {
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + a[i].se);
				ans = max(ans, j);
			}
		}
	}

	cout << ans << endl;

	clock_t end = clock();
	cerr << "Time: " << (double)(end - start) / CLOCKS_PER_SEC << " seconds" << endl;

	return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define MAX_N 100000

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

  cout << 50 << endl;

  ll b = n / 50;
  int a = n % 50;
  ll flag = 0;
  REP(i,50){
    if(i<a){
      flag = 1;
    }else{
      flag = 0;
    }
    cout << i + (b + flag) * 51 - n << ' ';
  }
  cout << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
const ll MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;

struct pair_hash {
	template <class T1, class T2>
	std::size_t operator () (const std::pair<T1,T2> &p) const {
		auto h1 = std::hash<T1>{}(p.first);
		auto h2 = std::hash<T2>{}(p.second);

		return h1 ^ h2;
	}
};

ll pw(ll te, ll tee) {
	if (tee == 0)	return 1;
	ll res = pw(te, tee / 2);
	return (tee % 2 ? te * res * res : res * res);
}
ll k, a[60];

void Read_input() {
	cin >> k;
	if (k == 0) {
		cout << 4 << endl;
		cout << 3 << " " << 3 << " " << 3 << " " << 3;
		exit(0);
	}
}

void Solve() {
	for (ll i = 1; i <= 50; i++)	a[i] = i - 1;
	ll t = (k - 1) / 50;
	k %= 50;
	for (ll i = 1; i <= 50; i++)	a[i] += t;
	if (k == 0)
		for (ll i = 1; i <= 50; i++)	a[i]++;
	else {
		for (ll i = 1; i <= k; i++) {
			sort(a + 1, a + 51);
			a[1] += 50;
			for (ll j = 2; j <= 50; j++)	a[j]--;
		}
	}
	cout << 50 << endl;
	cout << a[1];
	for (ll i = 2; i <= 50; i++)	cout << " " << a[i];
}

int main() {

	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	//freopen("input.txt", "r", stdin),	freopen("output.txt", "w", stdout);

	Read_input(),	Solve();
	return 0;
}


#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())

void Add(ll &a, ll b){
    a=(a+b)%mod;
    return;
}

void Pro(ll &a, ll b){
    a=(a*b)%mod;
    return;
}

ll H,W;
vector<P> d;

vec ans;
void init(){
    cin>>H>>W;
    rep(i,H){
        ll x,y; cin>>x>>y;
        x--; y--;
        d.pb(mp(x,y));
        ans.pb(-1);
    }
}

void Solve(){
    set<P> x;
    multiset<ll> y;
    rep(i,W) {
        P f=mp(i,i);
        x.insert(f);
        y.insert(0);
    }
    rep(i,H){
        ll Biggest=-INF;
        for(auto itr=x.lower_bound(mp(d[i].first,-INF));itr!=x.end();){
            ll R=(*itr).first, L=(*itr).second;
           // cout<<i<<':'<<R<<' '<<L<<endl;
            if(R>d[i].second+1) break;
            Biggest=max(Biggest,L);
            auto itr1=y.lower_bound(R-L);
            y.erase(itr1);
            itr=x.erase(itr);
        }
        if(Biggest!=-INF) if(d[i].second!=W-1) {x.insert(mp(d[i].second+1,Biggest)); y.insert(d[i].second+1-Biggest);}
        if(y.size()) ans[i]=*(y.begin());
        else break;
    }
    rep(i,H) if(ans[i]>=0) ans[i]+=(i+1);

}

int main(){
    init();
    Solve();
    rep(i,H) cout<<ans[i]<<endl;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

vector<vector<ll>> G(100007, vector<ll>(0));

void dfs(ll x,vl &d,ll dist){
    d[x]=dist;
    for(auto p: G[x]){
        if(d[p]==INF)dfs(p,d,dist+1);
    }
}

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll u;
    cin >> u;u--;
    ll v;
    cin >> v;v--;
    vector<ll> A(N-1,0);
    vector<ll> B(N-1,0);
    for(ll i=0;i<N-1;++i){
        cin>>A[i]>>B[i];
        A[i]--;B[i]--;
        G[A[i]].emplace_back(B[i]);
        G[B[i]].emplace_back(A[i]);
    }
    vector<ll> du(N,INF);
    vector<ll> dv(N,INF);
    dfs(u,du,0);
    dfs(v,dv,0);
    ll mark;
    ll ou=-INF;
    for(ll i=0;i<N;++i){
        if(du[i]<dv[i]&&chmax(ou,dv[i]))mark=i;
    }
    ll nige=du[mark];
    ll ans=nige;
    ll S=ou-nige;//Sは1以上
    if(S==1)ans+=0;
    else if(S==2)ans++;
    else {
        ans+=((S-2)/2)*2;
        S-=((S-2)/2)*2;
        if(S==3)ans+=2;
        else ans++;
    }
    prt(ans)

    return 0;
}


#include <iostream>

int main(void)
{
    int n;
    std::cin >> n;
    for(int i = 1; i <= n; i++) {
        int x = i;
        if(x % 3 == 0) {
            std::cout << " " << i;
            continue;
        }
        do {
            if(x % 10 == 3) {
                std::cout << " " << i;
                break;
            } else {
                x /= 10;
            }
        }while(x);
    }
    std::cout << std::endl;
    return 0;
}

#include <iostream>
using namespace std;

void check_num(int *i, int *x, int *n, int *flag);
void include3(int *i, int *x, int *n, int *flag);
void end_check_num(int *i, int *x, int *n, int *flag);

void call(int n){
	int i = 1;
	int x = 0;
	int END_FLAG = 0;
	check_num(&i, &x, &n, &END_FLAG);
}

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

	return 0;
}
void check_num(int *i, int *x, int *n, int *flag){
	*x = *i;
	if( *x % 3 == 0 ){
		cout << " " << *i;
		end_check_num(i, x, n, flag);
	}
	else include3(i, x, n, flag);
}
void include3(int *i, int *x, int *n, int *flag){
	if( *flag == 0 ){
		if( *x % 10 == 3 ){
			cout << " " << *i;
			end_check_num(i, x, n, flag);
		}
		else{
			(*x) /= 10;
			if(*x) include3(i, x, n, flag);
			else end_check_num(i, x, n, flag);
		}
	}
}
void end_check_num(int *i, int *x, int *n, int *flag){
	if( ++(*i) <= *n ) check_num(i, x, n, flag);
	else{
		cout << endl;
		*flag = 1;
	}
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d ;
  int L=a+b,R=c+d;
  if (L==R){
    cout << "Balanced" << endl;
  }else
    cout << (L<R ? "Right" :"Left") << endl;
}

#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, n);
    IN(ll, m);
    IN(ll, d);
    double ans = (1.0 + (d != 0)) * (m - 1) * (n - d) / (n * n);
    FOUT(ans);
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int x, y;
    cin >> x >> y;

    int f = 300000;
    int s = 200000;
    int t = 100000;

    int ans = 0;

    if (x == 1) ans += f;
    else if (x == 2) ans += s;
    else if (x == 3) ans += t;

    if (y == 1) ans += f;
    else if (y == 2) ans += s;
    else if (y == 3) ans += t;

    if (x == 1 && y == 1) ans += 400000;

    cout << ans << '\n';
    return 0;
}

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

long long ans, n;

int main() {
    string s;
    cin >> n >> s;
    for (int i = 0; i < (1 << n); i++) {
        string lr, lb;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j))
                lr += s[j];
            else
                lb += s[j];
        }
 	//cerr << lr << " " << lb << "\n";
        long long dp[40][20];
        memset(dp, 0, sizeof dp);
        dp[n * 2][0] = 1;
        for (int j = n * 2 - 1; j >= n; j--) {
            for (int k = 0; k <= (int)lr.size(); k++) {
                dp[j][k] += (k > 0) * dp[j + 1][k - 1] * (s[j] == lr[k - 1]);
                dp[j][k] += dp[j + 1][k] * (s[j] == lb[(n * 2 - j) - k - 1]);
            }
        }
		ans += dp[n][(int)lr.size()];
    }
    cout << ans;
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
template<typename Itr>
auto partition2(const Itr first, const Itr last){
  auto i=first;
  for(auto j=first; j!=last; ++j){
    if(*j<=*last){
      iter_swap(i, j);
      ++i;
    }
  }
  iter_swap(i, last);
  return i;
}
int32_t main(){
  size_t n; cin>>n;
  vector<uint32_t> a(n); for(auto&& e:a) cin>>e;
  const auto last=--end(a);
  auto mid=partition2(begin(a), last);
  for(auto i=begin(a); i!=mid; ++i) cout<<*i<<' ';
  cout<<'['<<*mid<<"] ";
  for(auto i=next(mid); i!=last; ++i) cout<<*i<<' ';
  cout<<*last<<'\n';
}

#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int Partition(int a[], int p, int r) {
	int x = a[r];
	int i = p-1;
	for(int j = p; j < r; j++) {
		if(a[j] <= x) {
			i++;
			int temp = a[i];
			a[i] = a[j];
			a[j] = temp;
		}
	}
	int temp = a[i+1];
	a[i+1] = x;
	a[r] = temp;
    return i+1;
}

int main() {
	int n;
	cin >> n;
	int a[n];
	for( int i = 0; i < n; i++) cin >> a[i];
	int b = Partition(a, 0, n-1);
	for( int i = 0; i < n; i++) {
		if(i == b) {
			if( i ) cout << " [" <<a[i] << "]";
			else cout << "[" << a[i] << "]";
		} else if( i ) cout << " " <<a[i];
		else cout << a[i];
	}
	cout << endl;
	return 0;
}


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

int H, W;
int A[82][82], B[82][82];
bool dp[82][82][25610];

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> A[i][j];
    rep(i, H) rep(j, W) cin >> B[i][j];
    dp[0][0][A[0][0]-B[0][0]+ofs] = true;
    dp[0][0][B[0][0]-A[0][0]+ofs] = true;

    rep(i, H) rep(j, W) {
        if (i>0) rep(k, 25610) {
            if (!dp[i-1][j][k]) continue;
            int nk = k+A[i][j]-B[i][j];
            if (0<=nk && nk<25610) dp[i][j][nk] = true;
            nk = k+B[i][j]-A[i][j];
            if (0<=nk && nk<25610) dp[i][j][nk] = true;
        }
        if (j>0) rep(k, 25610) {
            if (!dp[i][j-1][k]) continue;
            int nk = k+A[i][j]-B[i][j];
            if (0<=nk && nk<25610) dp[i][j][nk] = true;
            nk = k+B[i][j]-A[i][j];
            if (0<=nk && nk<25610) dp[i][j][nk] = true;
        }
    }

    int ans = 1000000;
    rep(i, 25610) if (dp[H-1][W-1][i]) ans = min(ans, abs(i-ofs));
    cout << ans << endl;
}

#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;
bool dp[6410][20000];
int abs(int x,int y){
    if(x>=y) return x-y;
    else return y-x;
}
int main(){
    int h,w;
    cin >> h >> w;
    vector<int> a(h*w), b(h*w);
    rp(i,h*w) cin >> a[i];
    rp(i,h*w) cin >> b[i];
    rp(i,6410){
        rp(j,20000) dp[i][j]=false;
    }
    int m=0;
    rp(i,h*w) m=max(m,abs(a[i],b[i]));
    dp[0][abs(a[0],b[0])]=true;
    for(int i=1; i<h*w; i++){
        int dif=abs(a[i],b[i]);
        if(i%w){
            for(int k=0; k<=(h+w)*m;k++){
                if(dp[i-1][k]){
                    dp[i][abs(k,dif)]=true;
                    if(k+dif<=(h+w)*m*2) dp[i][k+dif]=true;
                }
            }
        }
        if(i>=w){
            for(int k=0; k<=(h+w)*m;k++){
                if(dp[i-w][k]){
                    dp[i][abs(k,dif)]=true;
                    if(k+dif<=(h+w)*m*2) dp[i][k+dif]=true;
                }
            }
        }
    }
    int ans;
    int c=0;
    while(1){
        if(dp[h*w-1][c]){
            ans=c;
            break;
        }
        c++;
    }
    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;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h, vector<char>(w));
    rep(i,h) rep(j, w) cin >> s[i][j];
    rep(i,h)rep(j,w){
        if(s[i][j] == '#' && i != 0 && j != 0 && i != h-1 && j != w-1){
            if(s[i+1][j] != '#' && s[i-1][j] != '#' && s[i][j-1] != '#' && s[i][j+1] != '#'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,K,mx=0,gc=0;
  cin>>N>>K;
  vector<int> A(N);
  for(int &i:A){
    cin>>i;
    mx=max(mx,i),gc=__gcd(gc,i);
  }
  if(K<=mx && K%gc==0)puts("POSSIBLE");
  else puts("IMPOSSIBLE");
}


#include <bits/stdc++.h>
#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 repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << endl
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N, T;
  cin >> N >> T;

  ll T_MAX = 6003;
  vll dp(T_MAX);

  vector<P> food(N);
  rep(i, N) cin >> food[i].first >> food[i].second;

  SORT(food);

  rep(i, N) {
    ll a = food[i].first;
    ll b = food[i].second;
    vll t = dp;
    rep(j, T) {
      ll nj = j + a;
      t[nj] = max(t[nj], dp[j] + b);
    }
    dp = t;
  }

  ll ans = 0;
  rep(j, T_MAX) {
    ans = max(ans, dp[j]);
  }
  COUT(ans);
  return 0;
}

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

#define ll long long
#define ld long double
#define ar array

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
	cin >> x;
}
void read(double& d) {
	string t;
	read(t);
	d=stod(t);
}
void read(long double& d) {
	string t;
	read(t);
	d=stold(t);
}
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, size_t S> void read(array<A, S>& x) {
	EACH(a, x)
		read(a);
}

string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b?"true":"false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vt<bool> v) {
	string res;
	FOR(sz(v))
		res+=char('0'+v[i]);
	return res;
}

template<size_t S> string to_string(bitset<S> b) {
	string res;
	FOR(S)
		res+=char('0'+b[i]);
	return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
		if(!f)
			res+=' ';
		f=0;
		res+=to_string(x);
	}
    return res;
}

template<class A> void write(A x) {
	cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
	write(h);
	write(t...);
}
void print() {
	write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
	write(h);
	if(sizeof...(t))
		write(' ');
	print(t...);
}

void DBG() {
	cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

template<class T> void offset(ll o, T& x) {
	x+=o;
}
template<class T> void offset(ll o, vt<T>& x) {
	EACH(a, x)
		offset(o, a);
}
template<class T, size_t S> void offset(ll o, ar<T, S>& x) {
	EACH(a, x)
		offset(o, a);
}

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
	return uniform_int_distribution<ll>(a, b)(mt_rng);
}
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
ll mod=1e9+7;
const int N=1e6+5;
const ld PI=2*acos(0.0);

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

#define lcm(a,b) ((a)*(b))/(__gcd(a,b))

bool compare(array<int,2> a,array<int,2> b){
return a[0]<b[0];
}
void solve() {
int n,t; read(n,t);
vt<array<int,2> > td(n+1);
FOR(i,1,n+1) read(td[i][0],td[i][1]);
sort(++td.begin(),td.end(),compare);
int siz=(*--td.end())[0]+t+5;
vt<int> dp(siz,0);
vt<int> pre(siz,0);
FOR(i,1,n+1){
FOR(j,1,siz){
if(j-td[i][0]<0||j-td[i][0]>=t) { dp[j]=pre[j];}
else{ dp[j]=max(pre[j],pre[j-td[i][0]]+td[i][1]);}
}
FOR(j,1,siz){ pre[j]=dp[j]; dp[j]=0; }
//dbg(i,pre);
}
print(*max_element(all(pre)));
}

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


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if((a-b == 0)+(a-c == 0)+(b-c == 0)==1){
   cout<<"Yes"<<endl;
  }else{
   cout<<"No"<<endl;
  }
}

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define MOD 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define M 1e6+9
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}

ll n,k,a,b,c,d,x,y,z,m,l;
ll ans;
vecl arr(N);
ll dp[509][509];
ll pre[N];

void test_case() {

    set<int> st;
    rep(i,3) {
        int x;
        cin>>x;
        st.insert(x);
    }

    if(st.size() == 2) {
        yes;
    } else {
        no;
    }

}

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        test_case();
    }
}


#include<bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く */
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
const int MAX_INT = 1000000;
int dp[31];
int n;
int solve(int a);
int main(){
  while(1){
    memset(dp,-1,sizeof(dp));
    cin >> n;
    if(n==0)break;
    cout << (solve(n)/10-1)/365+1 << endl;
  }
}
int solve(int a){
  if(dp[a] != -1)return dp[a];
  else{
    if(a == 0)return 1;
    else if(a < 0)return 0;
    else return dp[a] = solve(a-1)+solve(a-2)+solve(a-3);
  }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int n;
    while (cin >> n, n) {
        V a(n);
        rep(i, n) cin >> a[i];

        int ans = -1e9;
        rep(i, n) {
            int t = 0;
            rep2(j, i, n) {
                t += a[j];
                ans = max(ans, t);
            }
        }

        cout << ans << endl;
    }
}


/*
    @uthor: Varun Mishra
    "varun21999" ->  Codechef, Codeforce, Hackerrank, Hackerearth;
*/
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int            long long int
#define ull            unsigned int
#define ld             long double
#define pb             push_back
#define pa             pair<int,int>
#define ppa            pair<pair<int,int>,int>
#define pap            pair<int,pair<int,int>>
#define v1d            vector<int>
#define v2d            vector<vector<int> >
#define vpa            vector<pair<int,int>>
#define M              1000000007
#define MN             LLONG_MIN
#define MX             LLONG_MAX
#define ff             first
#define ss             second
#define endl           "\n"
#define v1s            vector<string>
#define all(v)         v.begin(),v.end()
#define S(v)           sort(v.begin(),v.end())
#define RS(v)          sort(v.rbegin(),v.rend())
#define R(v)           reverse(v.begin(),v.end())
#define mxpq(T)        priority_queue <T>
#define mnpq(T)        priority_queue<T,vector<T>,greater<T>>
#define T              int tc;cin>>tc;while(tc--)
#define p2d(v)         for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)         for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)         for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define forIloop(i,n)  for(auto i=0;i<n;i++);
#define forDloop(i,n)  for(auto i=n-1;i>=0;i--);
#define qqq 400005
#define isEven(n)  (!n & 1);
const int MOD = 1e9 + 7;
// bool isEven(int n){
//     return (!(n & 1));
// }
// int popcount(int num){
//     num = num - ((num >> 1) & 0x55555555);
//     num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
//     return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
// }
// int powerOfTwo(int n){
//     return 1 << n;
// }

// int arr[1000001];
// bool temet = false;

void codeforce2(){
    int a[3]; cin>>a[0]>>a[1]>>a[2];
    swap(a[0], a[1]);
    swap(a[0], a[2]);
    cout << a[0] << " " << a[1] << " " << a[2] << endl;

    return;
}

int32_t main(){

    cout<<fixed<<setprecision(16);
    cin.sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    /*#ifndef _DEBUG
     freopen("input.txt",  "r",  stdin);
     freopen("output.txt", "w", stdout);
    #endif*/
    //auto start = high_resolution_clock::now();

    // Lucario();
    //codeforceContest();
    //hackerEarth();
    //codeChef();

    // T{
    //     codeforce2();
    // }
    codeforce2();

   /* auto stop = high_resolution_clock::now();
    auto duration = duration_cast<seconds>(stop - start);
    cout << "Time: "<<duration.count()<<endl;*/
    return 0;
}

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

int main() {
  long long n,m,d;
  cin>>n>>m>>d;
  cout << fixed << setprecision(8);
  double ans=1.000000*(n-d)/n*(m-1)/n;
  if(d!=0)ans*=2;
  cout<<ans<<endl;
}


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n; cin >> n;
  int mi = n;
  for (int i = 1; i <= 5; i++) {
    int t; cin >> t;
    mi = min(mi, t);
  }
  cout << (n + mi - 1) / mi + 4 << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

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

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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;
    }
}

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

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }

    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }

  int main(){
     lint n,a,b,c,d,e;
     cin>>n>>a>>b>>c>>d>>e;
     lint x=min({a,b,c,d,e});
     lint ans=(n+x-1)/x;
     ans+=4;
     cout<<ans<<endl;

  }


#include <stdio.h>

int main(){

  int l, r, ll, rr, minn;

  scanf("%d%d", &l, &r);

  ll = l % 2019;
  rr = r % 2019;

  minn = 2019;
  if(r - l > 2019) rr += 2019;

  for (int i=ll;i<rr;i++){
      for (int j=ll+i-ll+1;j<rr+1;j++){
          if(minn > i * j % 2019){
              minn = i * j % 2019;
          }
      }
  }
  printf("%d\n", minn);
  return 0;
}

#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

int main(void) {
    int l, r, i, j, ans;

    scanf("%d%d", &l, &r);

    if (r - l >= 2019 || l % 2019 > r % 2019)
    {
        printf("0\n");
        return (0);
    }
    ans = 2019;
    i = l % 2019;
    while (i < r % 2019)
    {
        j = i + 1;
        while (j <= r % 2019)
        {
            if (ans > i * j % 2019)
                ans = i * j % 2019;
            j++;
        }
        i++;
    }

    printf("%d\n", ans);

    return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

int main() {
	vector<long long> num(3);
	long long K;
	for (int i = 0; i < 3; i++) {
		cin >> num.at(i);
	}
	sort(num.begin(), num.end());
	cin >> K;
	for (int i = 0; i < K; i++) {
		num.back() *= 2;
	}
	long long ans;
	ans = num.at(0) + num.at(1) + num.at(2);
	cout << ans << endl;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
const int maxn=500010;
const int N=1<<20;
const int mod=1e9+7;
int n;
int a[maxn],f[maxn];
int flg[maxn];//1-i中异或和不为0的个数
int d1[N];//
int d0[N];//
int pre[N];//上一个异或和为i的数
signed main(){
	cin>>n;
	for(int i=0;i<(1<<20);i++)d0[i]=1;
	for(int i=0;i<n;i++)cin>>a[i],f[i]=(i>0?(f[i-1]^a[i]):a[i]);
	for(int i=0;i<n;i++){
		if(f[i]){
			int b=f[i];//当前的异或和
			d0[b]=(d0[b]+(flg[i]-flg[pre[b]])*d1[b])%mod;
			d1[b]=(d0[b]+d1[b])%mod;
			pre[b]=i;
		}else{
			flg[i]++;
			if(d1[0])d1[0]=(d1[0]*2)%mod;
			else d1[0]++;
		}
		flg[i+1]=flg[i];
	}
	int ans=0;
	if(f[n-1]==0){
		for(int i=0;i<(1<<20);i++)ans=(ans+d1[i])%mod;
	}else{
		ans=d0[f[n-1]];
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

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

	int n, q;
	cin >> n;
	vector<int>S(n);
	for (int i = 0; i < n; ++i)cin >> S[i];
	sort(S.begin(), S.end());
	cin >> q;
	vector<int>T(q);
	for (int i = 0; i < q; ++i)cin >> T[i];
	sort(T.begin(), T.end());
	int ans = 0;
	for (int i = 0; i < q; ++i) {
		if(binary_search(S.begin(), S.end(), T[i]))++ans;
	}cout << ans << endl;
}

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

using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

int main() {
  int N; cin >> N;
  string A, B, C; cin >> A >> B >> C;

  int cnt = 0;
  REP(i, N) {
    if(A[i] == B[i] && B[i] == C[i]) {

    }
    else if(A[i] == B[i]) {
      cnt++;
    }
    else if(A[i] == C[i]) {
      cnt++;
    }
    else if(C[i] == B[i]) {
      cnt++;
    } else {
      cnt = cnt + 2;
    }
  }

  cout << cnt << endl;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;
void func()
{
	double D,T,S;
	cin >> D>>T>>S;

	if(D/S <= T)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}

int main() {
//	while(1)
	func();
	return 0;
}

#include <iostream>
#include <regex>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;
  regex rx(R"([0-9]{)" + to_string(A) + R"(}-[0-9]{)" + to_string(B) + R"(})");
  if (regex_match(S, rx)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}


#include <bits/stdc++.h>
#define mov(x) (1<<(x))

using namespace std;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

int n, m, sum;
int grp[mov(15)];
int w[15][15];
int f[mov(15)][15];

int main()
{
	read(n), read(m);
	memset(w, 0x9f, sizeof(w));
	for(int i=1; i<=m; i++)
	{
		int a, b, c;
		read(a), read(b), read(c);
		w[a-1][b-1] = c;
		w[b-1][a-1] = c;
		sum += c;
	}
	memset(f, 0x9f, sizeof(f));
	for(int s=1; s<mov(n); s++)
		for(int i=0; i<n; i++)
			if(s & mov(i))
				for(int j=i+1; j<n; j++)
					if(s & mov(j))
						if(w[i][j] > 0)
							grp[s] += w[i][j];
	for(int s=1; s<mov(n); s++)
		if(s & 1)
			f[s][0] = grp[s];
	for(int s=1; s<mov(n); s++)
		for(int i=0; i<n; i++)
			if((mov(i)&s) && (s&1))
			{
				int u = ((~s)&(mov(n)-1));
				for(int t=u; t; t=((t-1)&u))
					for(int j=0; j<n; j++)
						if(mov(j) & t)
							if(w[i][j] > 0)
								cmax(f[s|t][j], f[s][i] + w[i][j] + grp[t]);
			}
	printf("%d\n", sum-f[mov(n)-1][n-1]);
	return 0;
}

#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll sum[200010];
int bin_s(int l,int r) {
	ll g=(sum[l]+sum[r])/2;
	int ok=l,ng=r;
	while(ok+1<ng){
		int mid=(ok+ng)/2;
		if (sum[mid]<=g)ok=mid;
		else ng=mid;
	}
	if(g-sum[ok]<sum[ng]-g)return ok;
	else return ng;
}

int main() {
	int N;cin>>N;
	for(int i=0;i<N;++i){
		ll A; cin>>A;
		sum[i+1]=sum[i]+A;
	}
	ll ans=1e15;
	for(int i=2;i+2<=N;++i){
		int form=bin_s(0,i),latt=bin_s(i,N);
		ll mn=min(sum[form],sum[i]-sum[form]),mx=max(sum[form],sum[i]-sum[form]);
		mn=min(mn,min(sum[latt]-sum[i],sum[N]-sum[latt]));
		mx=max(mx,max(sum[latt]-sum[i],sum[N]-sum[latt]));
		ans=min(ans,mx-mn);
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <math.h> // sqrt()
#include <iomanip>
#define rep(i , n) for (int i = 1; i <= (int)(n); i++)
#define repz(i , n) for (int i = 0; i < (int) n; i++)
#define repi(i , r, n) for (int i = r; i <= (int)(n); i++)
#define repd(i , r, n) for (int i = r; i >= (int)(n); i--)

using namespace std;
int main(){
 int n;
  cin >> n;
  int64_t A[n];
  int64_t B[n];
  int64_t C[n];
  repz( i , n) cin >> A[i];
  repz( i , n) cin >> B[i];
  repz( i , n) cin >> C[i];
  sort(A, A + n);
  sort(C, C + n);
    int64_t ans = 0; int64_t a = 0; int64_t c = 0;
    for ( int64_t i : B){
        a = lower_bound(A, A + n, i ) - A ;
        c = upper_bound(C, C + n , i) - C;
        ans += a * (n - c);
    }
    cout << ans << endl;

}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;

int n;
vector<vector<int>> a(3);

ll solve () {
  ll ans = 0;
  rep (j, n) {
    int tmp = a[1][j];
    ll comb = lower_bound(a[0].begin(), a[0].end(), tmp) - a[0].begin();
    comb *= a[2].end() - upper_bound(a[2].begin(), a[2].end(), tmp);
    ans += comb;
  }
  return ans;
}

int main() {
  while (cin >> n) {
    rep (i, 3) {
      a[i].resize(n);
      rep (j, n) cin >> a[i][j];
      sort(a[i].begin(), a[i].end());
    }
    cout << solve() << endl;
  }
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<ll> takahashi(n);
  ll sum = 0;
  for(int i = 0; i < n; i++){
    ll a, b;
    cin >> a >> b;
    takahashi[i] = a+b;
    sum-=b;
  }
  sort(takahashi.begin(), takahashi.end(), greater<long long>());
  for(int i = 0; i < n; i++){
    if(i%2 == 0){
    sum += takahashi[i];
    }
  }
  cout << sum;
}

#include<iostream>
#include<math.h>
#include<algorithm>
#include<tuple>
using namespace std;
#define fr(i,n) for(int i=0;i<n;i++)
typedef double db;
typedef tuple<bool,db> bod;
db Pi = 3.14159265358979;

db st(db t){
  t+=4*Pi;
  while(t>=0) t-=2*Pi;
  t+=2*Pi;
  return t;
}

bod J(db a,db b){
  if(a<=Pi){
    return make_tuple(!(a<=b && b<a+Pi),a+Pi-b);
  }
  else{
    return make_tuple(!(a<=b || b<a-Pi),st(a+Pi-b));
  }
}

int main(){
  int n,q,r;
  bool f;
  db x[100],y[100],m[100][100],M;
  cin >> n;
  if(n==2){
    cout<<0.5<<endl<<0.5<<endl;
    return 0;
  }
  fr(i,n) cin>>x[i]>>y[i];
  fr(i,n){
    fr(j,n){
      if(i != j){
        m[i][j]=st(atan2(x[j]-x[i],y[j]-y[i]));
      }
    }
    fr(j,n){
      if(i==j) continue;
      f=0;
      M=2*Pi;
      fr(k,n){
        if(k==i || k==j) continue;
//        cout<<i<<" "<<j<<" "<<k<<" "<<m[i][j]<<" "<<m[i][k]<<endl;
        bod G=J(m[i][j],m[i][k]);
        if(M>get<1>(G)){
          r=k;
          M=get<1>(G);
        }
        if(get<0>(G)){
          f=1;
          break;
        }
      }
      if(!f){
        q=j;
        break;
      }
    }
    if(f) cout<<0.0<<endl;
    else cout<<M/(2*Pi)<<endl;
  }
}


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

vector<P> tell[15];

int main() {
    int n;
    cin >> n;
    rep(i,n) {
        int a;
        cin >> a;
        rep(j,a) {
            int x, y;
            cin >> x >> y;
            x--;
            tell[i].emplace_back(x,y);
        }
    }
    int ans = 0;
    rep(is,1<<n) {
        int cnt = __builtin_popcount(is);
        bool ok = true;
        rep(i,n) {
            if (!(is>>i&1)) continue;
            for (auto p : tell[i]) {
                int x = p.first, y = p.second;
                if (!(int(is>>x&1) == y)) ok = false;
            }
        }
        if (ok) ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <array>

using namespace std;

class EightQueen
{
public:
  vector<vector<int>> bd;
  EightQueen(){}
  EightQueen( int n ) : bd(n, vector<int>(n)) {}
  int solve();
  bool dfs( int r );
  bool conflict( int r, int c );
};

bool EightQueen::conflict( int r, int c )
{
  for ( auto i = 0; i < 8; ++i )
    for ( auto j = 0; j < 8; ++j )
      {
        if ( bd[i][j] == 0 ) continue;

        if ( i == r ) return false;
        if ( j == c ) return false;
        if ( r - c == i - j ) return false;
        if ( r + c == i + j ) return false;
      }
  return true;
}

bool EightQueen::dfs( int r )
{
  if ( r == 8 ) return true;

  for ( auto c = 0; c < 8; ++c )
    {
      if ( bd[r][c] == 2 )
        {
          if ( dfs( r + 1 ) ) return true;
        }
      else
        {
          if ( conflict( r, c ) )
            {
              bd[r][c] = 1;
              if ( dfs( r + 1 ) ) return true;
              bd[r][c] = 0;
            }
        }
    }

  return false;
}

int EightQueen::solve()
{
  dfs( 0 );

  for ( auto r = 0; r < 8; ++r )
    {
      for ( auto c = 0; c < 8; ++c )
        {
          if ( bd[r][c] )
            cout << "Q";
          else
            cout << ".";
        }
      cout << endl;
    }

  return 0;
}

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

  EightQueen eq( 8 );

  for ( auto i = 0; i < n; ++i )
    {
      int r, c;
      cin >> r >> c;
      eq.bd[r][c] = 2;
    }

  eq.solve();

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, p;
int peb[55];

void solve() {
	int c = 0;
	int p_ = p;

	while (1) {
		if (p_ == 0) {
			p_ += peb[c];
			peb[c] = 0;
			c++;
		} else {
			peb[c]++;
			if (peb[c] == p) break;
			p_--;
			c++;
		}

		c %= n;
	}

	cout << c << endl;
}

int main() {
	while (1) {
		cin >> n >> p; if (n == 0 && p == 0) break;
		memset(peb, 0, sizeof(peb));
		solve();
	}

	return 0;
}

#include <iostream>

int main(void){
  while(1){
int stonNum[51] = {0};
    int p, n;
    std::cin >> n >> p;
    int first = p;
    if(n == 0 && p == 0)  return 0;
    int i=0;
    while(1){
      bool flag = true;
      if(p > 0){
        stonNum[i]++;
        p--;
        if(stonNum[i] == first){
        std::cout << i << std::endl;
        break;
        }
      }else{
        p += stonNum[i];
        stonNum[i] = 0;
      }
      if(i == n-1)  i = 0;
      else i++;
    }
  }
}


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

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

    int n,y;cin>>n>>y;

    int sy=y-n*1000;
    int n1=-1,n5=-1,n10=-1;

    for(int i=0;i<=n;i++)
    {
        int bsy=sy-i*4000;
        if(bsy<0)break;
        if(bsy%9000==0)
        {
            if(bsy/9000+i<=n)
            {
                n10=bsy/9000;
                n5=i;
                n1=n-n10-n5;
                break;
            }
        }
    }

    cout<<n10<<" "<<n5<<" "<<n1<<"\n";

    return 0;
}

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

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

  int a = -1;
  int b = -1;
  int c = -1;

  for(int i = 0; i <= N; i++){
    for(int j = 0; j + i <= N; j++){
      int k = (N - i -j);
      int sum = 10000 * i + 5000 * j + 1000 * k;
      if(sum == Y){
        a = i;
        b = j;
        c = k;
      }
    }
  }
 cout << a << " " << b << " " << c << endl;

}


#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

struct UnionFind {
  vll par;
  vll wcnt;
  vll bcnt;
  ll cnt;
  UnionFind(ll N, vector<string>& mp) : par(N), wcnt(N, 0), bcnt(N, 0), cnt(N) {
    for (ll i = 0; i < N; i++) {
      par[i] = i;
      ll w = (ll)mp[0].size();
      if (mp[i / w][i % w] == '.')
        wcnt[i] = 1;
      else
        bcnt[i] = 1;
    }
  }

  ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

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

  ll get_wcnt(ll x) { return wcnt[find(x)]; }
  ll get_bcnt(ll x) { return bcnt[find(x)]; }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll sizex = wcnt[x] + bcnt[x];
    ll sizey = wcnt[y] + bcnt[y];
    if (sizex < sizey) swap(x, y);
    par[y] = x;
    wcnt[x] += wcnt[y];
    bcnt[x] += bcnt[y];
    cnt--;
  }

  ll count() const { return cnt; }
};

int main() {
  ll x, y;
  cin >> x >> y;
  ll ans = 0;
  if (x == 1)
    ans += 300000;
  else if (x == 2)
    ans += 200000;
  else if (x == 3)
    ans += 100000;

  if (y == 1)
    ans += 300000;
  else if (y == 2)
    ans += 200000;
  else if (y == 3)
    ans += 100000;

  if (x == 1 && y == 1) ans += 400000;

  cout << ans << endl;

  return 0;
}

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

int prim() {
	int d[MAX],
		p[MAX] = { -1 },
		color[MAX] = {};//WHITE
	fill(d, d + MAX, INF);
	d[0] = 0;

	while (true) {
		int u, minv = INF;
		for (int i = 0; i < n; i++) {
			if (color[i] != BLACK&&d[i] < minv) {
				minv = d[i];
				u = i;
			}
		}

		if (minv == INF) { break; }

		color[u] = BLACK;

		for (int v = 0; v < n; v++) {
			if (color[v] != BLACK&&M[u][v] != INF) {
				if (M[u][v] < d[v]) {
					d[v] = M[u][v];
					p[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] != -1)sum += M[i][p[i]];
	}
	return sum;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int a; cin >> a;
			M[i][j] = (a == -1) ? INF : a;
		}
	}

	cout << prim() << endl;

	return 0;
}


#include <stdio.h>
int main(int argc, char const *argv[]) {
  int i, n;

  scanf("%d", &n);

  for (i = 3; i <= n; i++) {
    if (i % 3 == 0) {
      printf(" %d", i);
    } else {
      int temp = i;
      do {
        if (temp % 10 == 3) {
          printf(" %d", i);
          break;
        }
        temp /= 10;
      } while (temp > 0);
    }
  }
  puts("");
  return 0;
}

#include<iostream>
using namespace std;

int i = 1, x, n;

void checknum();
void include3();
void endchecknum();

int main() {
	cin >> n;
	checknum();
	return 0;
}

void checknum() {
	x = i;
	if (x % 3 == 0) {
		cout << " " << i;
		endchecknum();
	} else {
		include3();
	}
}

void include3() {
	if (x % 10 == 3) {
		cout << " " << i;
		endchecknum();
	} else {
		x /= 10;
		if (x) {
			include3();
		} else {
			endchecknum();
		}
	}
}

void endchecknum() {
	if (++i <= n) {
		checknum();
	} else {
		cout << endl;
		return;
	}
}


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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it!= m.end(); it++)

const int MOD = 1e9 + 7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 +5;
const char nl = '\n';

int main(){

  string s; cin >> s;
  int ok1 = 0, ok2 = 0, ok3 = 0;
  if(s[0] == 'A')
    ok1= 1;
  int cnt = 0;
  for(int i =2; i < s.size()-1; i++)
  {
    if(s[i] == 'C')
      cnt++;
  }
  if(cnt == 1)
    ok2 = 1;
  if(s[1] < 'a' || s[1] > 'z')
  {
    cout << "WA" <<nl;
    return 0;
  }
  if(s[s.size() -1] < 'a' || s[s.size()-1] > 'z')
  {
    cout << "WA" <<nl;
    return 0;
  }

  for(int i = 1; i < s.size(); i++)
  {
    if(s[i] >= 'a' && s[i] <= 'z' || s[i] == 'C')
      ok3 = 1;
  }
  if(ok1 && ok2 && ok3)
    cout << "AC" << nl;
  else
    cout << "WA" << nl;

  return 0;
}

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

int main() {
  int N, n;
  cin >> N;
  n = N;
  for (int i = 0; i < 9; i++) {
  int x;
    x += n % 10;
    n /= 10;
    if (i == 8){
  if ( N % x == 0){
    cout << "Yes" << endl;}
  else{
    cout << "No" << endl;}
    }
  }
}


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

const int maxn = 110;
const double PI = acos(-1);
int n;
pair<int, int> p[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d %d", &p[i].first, &p[i].second);
    }
    for (int i = 1; i <= n; i++) {
        vector<double> V;
        for (int j = 1; j <= n; j++) if (i ^ j) {
            V.push_back(atan2(p[j].second - p[i].second, p[j].first - p[i].first));
        }
        sort(V.begin(), V.end());
        double ans = max(0.0, PI - (V.back() - V[0]));
        for (int i = 0; i + 1 < V.size(); i++) {
            ans = max(ans, (V[i + 1] - V[i]) - PI);
        }
        printf("%.10f\n", ans / PI / 2);
    }
    return 0;
}

#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;
typedef pair<double, int> Pdi;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

double pi = 3.141592653589793238;

signed main(){

    int N; cin >> N;
    vector<double> x(N), y(N);

    REP(i, N) cin >> x[i] >> y[i];

    vector<double> ans(N, 0.0);

    int n = 1000000;
    REP(i, n){
        double theta = 2.0 * pi * (double)i / (double)(n);
        double maxv = -1.0 * INF, v;
        int maxi;
        REP(j, N){
            v = x[j] * cos(theta) + y[j] * sin(theta);
            if(v > maxv){
                maxv = v;
                maxi = j;
            }
        }
        ans[maxi] += 1.0 / (double)n;
    }

    REP(i, N) cout << ans[i] << endl;

    return 0;
}

template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int a, b, c; cin >> a >> b >> c;
    if (a > b) swap(a,b);
    if (a < c && c < b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

#include <stdio.h>

int main() {

	int a, b;
	scanf("%d %d", &a, &b);
	char s[a+b+2];
	scanf("%s", s);

	for(int i=0; i<a; i++){
		if(s[i]<48 || s[i]>57){
			printf("No\n");
			return 0;
		}
	}

	if (s[a]!=45){
		printf("No\n");
			return 0;
	}

	for(int i=a+1; i<=(a+b); i++){
		if(s[i]<48 || s[i]>57){
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");

    return 0;
}


#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
const int N = 3e5 + 1;
int n, m, k;
long long int A[N], B[N], cs[N], sum;
int main(){
    ll H , W , N ;
    cin >> H >> W >> N ;
    if(N % max(H , W ) == 0) cout << N / max(H , W ) << endl;
    else cout <<  ( N / max(H , W ) ) + 1 << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

#define MOD 1000000007

int main(){
    ll h, w, k;
    cin >> h >> w >> k;

    ll dp[110][10] = {};
    dp[0][0] = 1;

    rep(i, h)rep(j, w)rep(k,(1<<(w-1))){
        bool isok = true;
        rep(l, w-2)if(k & (1<<l) && k & (1<<(l+1))){
            isok = false;
            break;
        }
        if(isok){
            if(j > 0 && (1<<(j-1) & k)){
                dp[i+1][j-1] += dp[i][j];
                dp[i+1][j-1] %= MOD;
            }
            else if(j < w-1 && (1<<j) & k){
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= MOD;
            }
            else {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
        }
    }

    cout << dp[h][k-1] << endl;

}


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; return(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

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

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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    cin >> s;
    if (s.size() % 2 != 0) {
        END("No")
    }

    REP(i, 0, s.size()) {
        if (i % 2 == 0) {
            if (s.at(i) != 'h') {
                END("No")
            }
        } else {
            if (s.at(i) != 'i') {
                END("No")
            }
        }
    }
    MSG("Yes")
}

#include <iostream>

using namespace std;

int main()
{

	int n;
	cin >> n;

	int sum = 0;

	sum = (n - 2) * 180;

	cout << sum;

	return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int N, K, a[100001], d[100001], c[100001];
vector<int> G[100001];

void dfs(int u) {
    for (int v : G[u]) {
        dfs(v);
        d[u] = max(d[v]+1, d[u]);
        c[u] += c[v];
    }
    if (u > 1 && a[u] > 1 && d[u] == K-1) {
        d[u] = -1;
        ++c[u];
    }
}

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

    cin >> N >> K;
    for (int u = 1; u <= N; ++u) {
        cin >> a[u];
        if (u > 1) G[a[u]].push_back(u);
    }
    dfs(1);
    cout << (a[1] > 1) + c[1];
}

#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
	int a[3], k, b = 0;
	for (int i = 0 ; i < 3 ; i++) cin >> a[i];
	cin >> k;
	sort(a, a + 3);
	b = a[2];
	for (int i = 0 ; i < k ; i++) b *= 2;
	cout << a[0] + a[1] + b;
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

template< typename T >
map<T, int> prime_factorization(T x)
{
    map<T, int> ret;
    for (T i = 2; i * i <= x; ++i)
    {
        while (x % i == 0)
        {
            ++ret[i];
            x /= i;
        }
    }
    if (x != 1) ++ret[x];
    return ret;
}

s64 mypow(s64 x, s64 n)
{
    s64 ret = 1;
    while (n)
    {
        if (n & 1) ret = (ret * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1;
    }
    return ret;
}

const int max_n = 100100;
s64 fac[max_n + 1];
s64 finv[max_n + 1];
void init(int n)
{
    fac[0] = fac[1] = 1;
    for (s64 i = 2; i <= n; ++i)
    {
        fac[i] = fac[i - 1] * i % MOD;
    }
    finv[n] = mypow(fac[n], MOD - 2);
    for (s64 i = n - 1; i >= 0; --i)
    {
        finv[i] = finv[i + 1] * (i + 1) % MOD;
    }
}

s64 comb(int n, int r)
{
    if (n < r || n < 0 || r < 0) return 0;
    return fac[n] * finv[r] % MOD * finv[n - r] % MOD;
}

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

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

    auto pfac = prime_factorization(m);
    init(max_n);

    s64 ans = 1;
    for (auto& item : pfac)
    {
        int num = item.second;
        ans *= comb(n + num - 1, num);
        ans %= MOD;
    }

    cout << ans << "\n";
    return 0;
}

#include <bits/stdc++.h>
#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() {
  int n, y;
  cin >> n >> y;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; i + j <= n; ++j) {
      int k = n - i - j;
      if (10000 * i + 5000 * j + 1000 * k == y) {
        printf("%d %d %d\n", i, j, k);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
  double x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout.precision(9);
  cout.setf(ios::fixed);
  cout  << sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) << endl;
  return 0;
}

#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main() {
	string str;
	while (getline(cin, str)) {
		for (int i = 0; i < 26; i++) {
			for (auto &itr : str) if (isalpha(itr)) itr = (itr - 'a' + 1) % 26 + 'a';
			if (str.find("the") != -1) { cout << str << endl; break; }
			if (str.find("this") != -1) { cout << str << endl; break; }
			if (str.find("that") != -1) { cout << str << endl; break; }
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int64_t N, X;
  cin >> N >> X;
  vector<int64_t> A(N);
  rep(i, N) cin >> A[i];

  int64_t answer = 0;
  for(int i = 1; i < N; ++i) {
    if(X < (A[i-1] + A[i])) {
      int64_t diff = (A[i] + A[i-1]) - X;
      A[i] -= min(A[i], diff);
      answer += diff;
    }
  }
  cout << answer << endl;
  return 0;
}

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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
     return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    if(v.size() >= 200) {
        return "Too big container";
    }

    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#define rep(i,n) for (int i = 0; i < n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
#define reps(i,s,n) for (int i = s; i < n; ++i)
#define all(c) begin(c),end(c)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
typedef pair<int,int> PINT;
typedef pair<ll,ll> PLL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
#define print(a) cout << a << endl;
const int INFI = (1 << 30) - 1;
const long long INFLL = (1LL << 62) - 1;
template<typename T> void printv(vector<T>&v) {
    int n = v.size() - 1;
    rep(i, n) cout << v[i] << " ";
    cout << v.back() << endl;
}
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
double deg2rad(double deg) { return deg * M_PI / 180; }
double rad2deg(double rad) { return rad * 180 / M_PI; }

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

    ll N, X; cin >> N >> X;
    ll ans = 0;
    ll left; cin >> left;

    rep(i, N - 1) {
        ll a; cin >> a;
        ll over = (left + a) - X;
        if(over > 0) {
            ans += over;
            if(over > a) {
                left = 0;
            } else {
                left = a - over;
            }
        } else {
            left = a;
        }
    }

    print(ans);
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll prev = 0;
    vector<ll> A(5);
    ll k;
    rep(i, 5) cin >> A[i];
    cin >> k;
    rep(i, 4) {
        rep2(j, i + 1, 5) {
            if(A[j] - A[i] > k) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

#include <cmath>
#include <iostream>
using namespace std;
int main() {
	int N, L;
	cin >> N >> L;
	int opt = (1 << 30), sum = 0;
	for (int i = 0; i < N; ++i) {
		int p = L + i;
		if (abs(opt) > abs(p)) {
			opt = p;
		}
		sum += p;
	}
	cout << sum - opt << endl;
	return 0;
}


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

int main() {
  int a,b,n,i=0;
  cin >> a >> b;
  n = 1;
  while(b>n){
    n += a - 1;
    i++;
  }

  cout << i << endl;
}

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

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

const int INF=1e9;

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

  vector<int> A(n),B(n);
  rep(i,n){
    if(i==0){
      if(s[0]=='W') A[0]=1;
      else A[0]=0;
    }
    else if(s[i]=='W') A[i]=A[i-1]+1;
    else A[i]=A[i-1];
  }
  for(int i=n-1;i>=0;i--){
    if(i==n-1){
      if(s[n-1]=='E') B[n-1]=1;
      else B[n-1]=0;
    }
    else if(s[i]=='E') B[i]=B[i+1]+1;
    else B[i]=B[i+1];
  }
  int mi=INF;
  rep(i,n){
    mi=min(mi,A[i]+B[i]);
  }
  cout<<mi-1<<endl;

  return 0;
}


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

lli n, m;

int main(void){
	cin >> n >> m;
	vector<bool> ac(n+1);
	vector<lli> wa(n+1);
	rep(i, m){
		int p;
		string s;
		cin >> p >> s;
		if(s == "AC") ac[p] = true;
		else{
			if(!ac[p]) wa[p]++;
		}
	}
	lli sumac = 0, sumwa = 0;
	rep(i, n+1){
		if(ac[i]){
			sumac++;
			sumwa+=wa[i];
		}
	}
	cout << sumac << " " << sumwa << endl;
	return 0;
}

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

inline int gi()
{
	char c = getchar();
	while(c < '0' || c > '9') c = getchar();
	int sum = 0;
	while('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

typedef long long ll;
const int maxn = 100005;

int n, s, x[maxn];
ll ans, p[maxn];

int main()
{
	n = gi(); s = gi();
	for (int i = 1; i <= n; ++i) x[i] = gi(), p[i] = gi();

	int l = 1, r = n, d = p[1] >= p[n];
	while (1) {
		if (x[l] >= s) {ans += x[r] - s; break;}
		if (x[r] <= s) {ans += s - x[l]; break;}
		if (p[l] >= p[r]) {
			if (d != 0) {ans += x[r] - x[l]; d ^= 1;}
			p[l] += p[r--];
		} else {
			if (d != 1) {ans += x[r] - x[l]; d ^= 1;}
			p[r] += p[l++];
		}
	}

	printf("%lld\n", ans);

	return 0;
}


#include <bits/stdc++.h>

template <class T>
T root(std::vector<T>& v, T x) {
    return v[x] - x ? (v[x] = root(v, v[x])) : x;
}

template <class T>
bool same(std::vector<T>& v, T x, T y) { return root(v, x) == root(v, y); }

template <class T>
void unite(std::vector<T>& v, T x, T y) {
    x = root(v, x);
    y = root(v, y);
    if (x != y) v[x] = y;
}

int main() {
    long long n, m;
    std::cin >> n >> m;
    std::vector<int> p(n);
    std::vector<std::deque<int>> g(n);
    for (int i = 0; i < n; i++) p[i] = i;
    for (int i = 0; i < m; i++) {
        int a, b;
        std::cin >> a >> b; a--; b--;
        unite(p, a, b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    std::map<int, std::deque<int>> sub;
    for (int i = 0; i < n; i++) {
        sub[root(p, p[i])].push_back(i);
    }

    long long a = 0, b = 0, c = 0;
    std::vector<bool> done(n, false), color(n);
    for (auto& s : sub) {
        auto v = s.second;
        if (v.size() == 1) {
            b++;
            continue;
        }
        std::deque<int> q;
        q.push_back(v[0]);
        color[v[0]] = true;
        bool odd = false;
        while (!q.empty()) {
            auto curr = q.front();
            done[curr] = true;
            for (auto to : g[curr]) {
                if (done[to] && color[to] == color[curr]) {
                    odd = true;
                    // break;
                } else if (!done[to]) {
                    q.push_back(to);
                    color[to] = !color[curr];
                }
            }
            q.pop_front();
            // if (odd) break;
        }
        if (odd) a++;
        else c++;
    }
    // std::cout << a << " " << b << " " << c << std::endl;

    std::cout << (a * a + 2 * a * c + 2 * c * c + 2 * n * b - b * b) << std::endl;

    return 0;
}

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

const int INF = 1<<30;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    cin >> H >> W;
    vector<int> A(H), B(H);
    for(int i=0; i<H; i++)
    {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    map<int, int> path;
    multiset<int> dist;
    for(int i=0; i<W; i++)
    {
        path[i] = i;
        dist.insert(0);
    }

    for(int i=0; i<H; i++)
    {
        int idx = -1;
        for(auto itr = path.lower_bound(A[i]); itr != path.end() && itr->first <= B[i] + 1; itr = path.erase(itr))
        {
            chmax(idx, itr->second);
            auto ditr = dist.find(itr->first - itr->second);
            dist.erase(ditr);
        }
        if(idx != -1 && B[i] + 1 < W)
        {
            path[B[i] + 1] = idx;
            dist.insert(B[i] + 1 - idx);
        }
        if(dist.size() == 0)
        {
            cout << "-1\n";
        }
        else
        {
            cout << *dist.begin() + i + 1 << '\n';
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<"\t\n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  ll n, m; cin >> n >> m;
  vl a(n), b(m); ina(a,n); ina(b,m);
  sort(all(a)); sort(all(b));
  rep(i,n-1) if (a[i]==a[i+1]) { puts("0"); return 0; }
  rep(i,m-1) if (b[i]==b[i+1]) { puts("0"); return 0; }
  ll ans = 1;
  for (ll now = n*m; now > 0; now--) {
    auto ita = lower_bound(all(a), now);
    auto itb = lower_bound(all(b), now);
    int st = (*ita == now) + (*itb == now);
    if (st == 0) {
      ans *= (a.end() - ita)*(b.end() - itb) - (n*m - now);
    }
    if (st == 1 && *ita == now) {
      ans *= (b.end() - itb);
    }
    if (st == 1 && *itb == now) {
      ans *= (a.end() - ita);
    }
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

int main(){FIN

    ll n,m;cin>>n>>m;
    vll a(n);
    REP(i,n) cin>>a[i];
    vll rui(n+1,0);
    ll sum=0;
    REP(i,n){
        sum += a[i];
        rui[i+1] = sum % m;
    }
    map<ll,ll> mp;
    REP(i,n+1) mp[rui[i]]++;
    ll ans=0;
    for(auto p:mp){
        // cout<<p.second<<endl;
        ans += p.second * (p.second-1) /2;
    }
    cout<<ans<<endl;
    return 0;
}