#pragma GCC optimize "-O3"
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define NumberOfOnes __builtin_popcount
#define LSOne(S) (S & (-S))
#define ll long long
#define two pair<int,int>
#define twoll pair<ll,ll>
#define four pair<two,two>
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define y1 y1922
#define INF 1000000000000000000
#define P 1000000007
#define lmax 1000000000
#define nn 1000003
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define vtwo vector<two>
#define ALL(container) (container).begin(), (container).end()
#define sz(container) (int)(container.size())
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mid(a,b) (a+b>>1)
#define minN 0
#define maxN 10000000
#define na(x) ((x)<P?(x):(x)-P)
#define ab(a) (-(a)<(a)?(a):-(a))
#define FAST std::ios::sync_with_stdio(false)
#define xRand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rnd rng
#define IT iterator
typedef
tree<
  int,// aq pair<int,int> shegidzlia
  null_type,
  less/*_equal*/<int>,// aqac
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
// '_equal' mashin ginda roca multiset gchirdeba
template<class key, class value,class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
ordered_map<int, int> my_map;
inline int rin(){
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
inline int bin(){
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x;
}
int k,n,f[308][308][308];
string s;
int main(){FAST;xRand;
cin>>s;
cin>>k;
n=sz(s);
for(int i=n-1;i>=0;i--){
	for(int j=i;j<n;j++){
		for(int p=0;p<=k;p++){
			if(i==j){
				f[i][j][p]=1;
				continue;
			}
			if(i+1==j){
				f[i][j][p]=(s[i]==s[j]||p>0)?2:1;
				continue;
			}
			f[i][j][p]=max(f[i+1][j][p],f[i][j-1][p]);
			if(s[i]==s[j]){
				f[i][j][p]=max(f[i][j][p],f[i+1][j-1][p]+2);
			}
			if(p>0){
				f[i][j][p]=max(f[i][j][p],f[i+1][j-1][p-1]+2);
			}
		}
	}
}
cout<<f[0][n-1][k]<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
                 *   *   * *   *
                  *   *   *   *
                   *   * *   *
                     *  *   *
					   *  *

*/

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int N,K; vector<int> pl,mi;
void input()
{
    cin >> N >> K;
    for(int i=0; i<N; ++i){
        int x; cin >> x;
        if(x > 0) pl.emplace_back(x);
        else if(x < 0) mi.emplace_back(-x);
    }
    reverse(mi.begin(),mi.end());
}

void solve()
{
    if(N != pl.size() + mi.size()) --K;
    int ans, left, right;
    if(pl.empty() && mi.empty()) ans = 0;
    else if(pl.empty()) ans = mi[K-1];
    else if(mi.empty()) ans = pl[K-1];
    else {
        int mi_size = mi.size();
        int pl_size = pl.size();
        if(pl_size >= K)  {
            left = -1; right = K-1;
            ans = pl[right];
        }
        else {
            left = K - pl_size - 1; right = pl_size - 1;
            if(pl[right] > mi[left]) ans = pl[right] + 2 * mi[left];
            else ans = 2 * pl[right] + mi[left];
            // cout << mi[left] << " " << pl[right] << endl;
        }

        while(1){
            ++left; --right;
            if(left < mi_size){
                if(right >= 0){
                    if(pl[right] > mi[left]) ans = min(ans, pl[right] + 2 * mi[left]);
                    else ans = min(ans, 2 * pl[right] + mi[left]);
                    // cout << mi[left] << " " << pl[right] << endl;
                }
                else if(right == -1) ans = min(ans, mi[left]);
            }
            else break;
        }
    }

    cout << ans << endl;
}

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


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int a, b, ans; cin >> a >> b;
    ans = 0;

    repp(i, a, b+1){
        string s = to_string(i); int l = s.length();
        bool f = true;
        rep(j, l){
            if(s[j] != s[l-1-j]) f = false;
        }
        if(f) ans++;
    }

    out(ans);
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<
    pair<int, int>,
    null_type,
    less_equal<pair<int, int>>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define lb(v, z) lower_bound(all(v), z)
#define ub(v, z) upper_bound(all(v), z)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rdp(i, a, b) for (int i = (a); i >= (b); i--)
#define rlt(i, a, b) for (int i = (a); i < (b); i++)
#define cns(z) cout << (z) << ' '
#define cnl(z) cout << (z) << '\n'
#define M1 1000000007
#define M2 998244353
#define MAXN 300005
#define INF (1ll << 60)
#define endl "\n"
#define garr(ip)       \
    for (auto &x : ip) \
        cin >> x;
#define parr(ip)          \
    for (auto &x : ip)    \
        cout << x << " "; \
    cout << endl;
#define nl cout << endl
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vp;

void solve(int testCaseNumber = 1)
{
    int n;
    cin >> n;
    string ans;
    while (n > 0)
    {
        n--;
        ans += 'a' + n % 26;
        n /= 26;
    }
    reverse(all(ans));
    cnl(ans);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}


#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

inline void reset(int cnt[], int& state) {
	REP(i, 3) cnt[i] = 0;
	state = 0;
}

int main() {
	int ans = 0, cnt[3], state;
	char JOI[] = {'J', 'O', 'I'};

	reset(cnt, state);
	while (1) {
		int c = getchar();

		if (c == JOI[state]) {
			cnt[state]++;
		} else {
			if (state == 2) {
				if (cnt[1] <= min(cnt[0], cnt[2]))
					ans = max(ans, cnt[1]);
				reset(cnt, state);
			} else if (c == JOI[state + 1]) {
				state++;
			} else
				reset(cnt, state);

			if (c == JOI[state]) cnt[state]++;
		}

		if (c == '\n') break;
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n=s.size()-2;

    int ans = inf;
    rep(i,n){
        int x=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        ans = min(ans,abs(x-753));
    }
    cout << ans << endl;

        return 0;
    }


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

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	while (cin >> n) {
		long long stool = 0;
		int prev = 0;
		for (int i = 0; i < n; ++i) {
			int aux;
			cin >> aux;
			if (aux <= prev) {
				stool += (prev - aux);
			} else {
				prev = aux;
			}
		}
		cout << stool << endl;
	}
	return 0;
}

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

long long a[200000],l[200000];

signed main()
{
	ios::sync_with_stdio(0);

	long long n,i;
	long long ans=0;

	cin >> n;

	for(i=1; i<=n; i++)
		cin >> a[i];

	for(i=1; i<=n; i++)
		l[i]=max(a[i],l[i-1]);

	for(i=1; i<=n; i++)
		ans+=l[i]-a[i];

	cout << ans << endl;

	return 0;
}


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

int main(){

string s;
  cin >> s;
bool c=true;
for(int i=97;i<=122;i++){
        c=true;
for(int j=0;s[j]!='\0';j++){
        if(char(i)==s[j]){
        c=false;
        continue;
        }
}
        if(c==true){
            cout<<char(i);
            break;
        }
}
if(c==false)
        cout<<"None";
 return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    char a[20], b[20], c[20];
    scanf("%s %s %s", &a, &b, &c);
    int al, bl;
    al = strlen(a)-1;
    bl = strlen(b)-1;
    if(a[al]==b[0] && b[bl]==c[0])
    printf("YES");
    else printf("NO");
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

int main(){
  ll N;
  cin >> N;
  char a[28];
  string s = "";
  for(char i='a'; i<='z';i++){
	a[int(i) - int('a')] = i;
  }
  while(N){
	N--;
	s += a[N%26];
	N /= 26;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}

#include <iostream>
#include <string>

typedef long long ll;

std::string alphabet = "abcdefghijklmnopqrstuvwxyz";
ll N;

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

  std::cin >> N;
  std::string ans = "";
  while (N) {
    N--;
    ans = alphabet[N % 26] + ans;
    N /= 26;
  }

  std::cout << ans << "\n";

  return 0;
}


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

int main(){
	string angou;

	while (getline(cin, angou)){
		int a = angou.size();

		for (int i = 0; i < 26; i++)
		{
			for (int q = 0; q < a; q++){
				if (angou[q] == ' ' || angou[q] == '.') continue;

				if (angou[q] == 'z') angou[q] = 'a';
				else angou[q]++;
			}

			bool theExists = angou.find("the") != string::npos;
			bool thisExists = angou.find("this") != string::npos;
			bool thatExists = angou.find("that") != string::npos;
			if (theExists || thisExists || thatExists)
			{
				cout << angou << endl;
				continue;
			}
		}
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int l=s.length(),j,k;
  vector<int> v(26,-1);
  for(j=0;j<l;j++){
    k=s[j]-'a';
    if(v[k]==-1||j-v[k]>2) v[k]=j;
    else{
      cout<<v[k]+1<<' '<<j+1<<endl;
      return 0;
    }
  }
  cout<<"-1 -1"<<endl;
}


#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;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int dp[3010][10000];
int main()
{
	int n, t;
	cin >> n >> t;
	vector<P> p(n);
	rep(i,n) cin >> p[i].first >> p[i].second; // 時間、美味しさ。
	SORT(p);
	int ans = 0;
	rep(i,n){
		rep(j,t){
			chmax(dp[i+1][j], dp[i][j]);
			int nj = j + p[i].first;
			if(nj < t)
			chmax(dp[i+1][nj], dp[i][j] + p[i].second);
		}
		int now = dp[i][t-1]+p[i].second; //
		chmax(ans,now);
	}
	cout << ans << endl;

}


#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    int l, i=0, a[10];
    while(2 > i){
        cin >> a[i];
        i++;
    }
    if (a[0] > 8 || a[1] > 8) {
        cout << ":(" << "\n";
    } else {
        cout << "Yay!" << "\n";
    }
}

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

int main(){
    int a, b;
    cin >> a >> b;
    cout << (((a <= 8) && (b <= 8)) ? "Yay!" : ":(") << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct Node{
  int key;
  Node *right,*left,*parent;
};
Node *root,*NIL;

Node * tmin(Node *x){
  while(x->left!=NIL)x=x->left;
  return x;
}
Node * treeSuccessor(Node *x){
  if(x->right!=NIL)return tmin(x->right);
  Node *y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void tdel(Node *z){
  Node *y;
  Node *x;

  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
  if(y->left!=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent = y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }
  else{
    if(y==y->parent->left){
      y->parent->left=x;
    }
    else{
      y->parent->right=x;
    }
  }
  if(y!=z){
    z->key = y->key;
  }
  free(y);
}

Node * find(Node *u,int k){
  while(u != NIL && k!=u->key){
    if(k<u->key)u=u->left;
    else u = u -> right;
  }
  return u;
}
void insert(int k){
    Node *y = NIL;
  Node *x = root;
  Node *z;
  z=(Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent = y;
  if(y==NIL){
    root = z;
  }else{
    if(z->key < y->key){
      y->left = z;
    }else{
      y->right = z;
    }
  }
}
void inorder(Node *u){
  if(u==NIL)return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL)return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}
int main(){
  int n,m;
  string func;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> func;
    if(func=="find"){
      cin >> m;
      Node *t=find(root,m);
      if(t!=NIL)cout << "yes" << endl;
      else cout << "no" << endl;
    }
    else if(func=="insert"){
      cin >> m;
      insert(m);
    }
    else if(func=="print"){
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
    else if(func=="delete"){
      cin >> m;
      tdel(find(root,m));
    }
  }
  return 0;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, a[maxn];

bool bad()
{
	for (int i = 0; i < n; i++)
		if (a[i] != 1)
			return false;
	return true;
}

void solve(int turn = 0)
{
	if (bad())
	{
		cout << ((1 - turn) ? "Second" : "First") << endl;
		return;
	}
	int parity = 0;
	bool check = false;
	for (int i = 0; i < n; i++)
		parity ^= (a[i] & 1), check |= (a[i] == 1);
	if (check)
	{
		if (parity ^ (n & 1))
			cout << (turn ? "Second" : "First") << endl;
		else
			cout << ((1 - turn) ? "Second" : "First") << endl;
		return;
	}
	if (n & 1)
	{
		if (!parity)
		{
			cout << (turn ? "Second" : "First") << endl;
			return;
		}
		else
		{
			int cnt = 0;
			for (int i = 0; i < n; i++)
				cnt += (a[i] & 1);
			if (cnt > 1)
			{
				cout << ((1 - turn) ? "Second" : "First") << endl;
				return;
			}
			else
			{
				for (int i = 0; i < n; i++)
					if (a[i] & 1)
						a[i]--;
				int GCD = a[0];
				for (int i = 1; i < n; i++)
					GCD = __gcd(a[i], GCD);
				for (int i = 0; i < n; i++)
					a[i] /= GCD;
				solve(1 - turn);
			}
		}
	}
	else
	{
		if (!parity)
			cout << ((1 - turn) ? "Second" : "First") << endl;
		else
			cout << (turn ? "Second" : "First") << endl;
	}
}

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

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	solve();
}


#include<stdio.h>
int main(){
	int n, r, t;
	scanf("%d %d", &n, &r);
	t = 100 * (10 - n);
	if(n<10){
		printf("%d\n", r+t);
	}
	else{
		printf("%d\n", r);
	}
	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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int n, k;
    cin >> n >> k;
    if (n%k != 0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

signed main() {
  int H, W, K;
  cin >> H >> W >> K;

  vector<vector<int>> dp(H+1, vector<int>(W, 0));
  dp[0][0] = 1;

  REP(i, H) REP(j, W) REP(k, (1<<(W-1))){
    bool ok = true;
    REP(l, W-2){
      if(((k >> l)&1) && ((k >> (l+1))&1)) ok = false;
    }
    if(ok){
      if(j >= 1 && ((k >> (j-1))&1)){
        dp[i+1][j-1] += dp[i][j];
        dp[i+1][j-1] %= MOD;
      }else if(j <= W-2 && ((k >> j)&1)){
        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;

  return 0;
}

#include<bits/stdc++.h>

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double llf;
typedef std::pair<int,int> pii;

#define xx first
#define yy second

template<typename T> inline T max(T a,T b){return a>b?a:b;}
template<typename T> inline T min(T a,T b){return a<b?a:b;}
template<typename T> inline T abs(T a){return a>0?a:-a;}
template<typename T> inline bool repr(T &a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool repl(T &a,T b){return a>b?a=b,1:0;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
template<typename T> inline T sqr(T x){return x*x;}
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
#define I inline
#define mset(a,b) memset(a,b,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))

#define fo0(i,n) for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define fd0(i,n) for(int i=(n)-1;~i;i--)
#define fd1(i,n) for(int i=n;i;i--)
#define fd(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define foe(i,x)for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)

struct Cg{I char operator()(){return getchar();}};
struct Cp{I void operator()(char x){putchar(x);}};
#define OP operator
#define RT return *this;
#define RX x=0;char t=P();while((t<'0'||t>'9')&&t!='-')t=P();bool f=0;\
if(t=='-')t=P(),f=1;x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define RL if(t=='.'){lf u=0.1;for(t=P();t>='0'&&t<='9';t=P(),u*=0.1)x+=u*(t-'0');}if(f)x=-x
#define RU x=0;char t=P();while(t<'0'||t>'9')t=P();x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define TR *this,x;return x;
I bool IS(char x){return x==10||x==13||x==' ';}template<typename T>struct Fr{T P;I Fr&OP,(int&x)
{RX;if(f)x=-x;RT}I OP int(){int x;TR}I Fr&OP,(ll &x){RX;if(f)x=-x;RT}I OP ll(){ll x;TR}I Fr&OP,(char&x)
{for(x=P();IS(x);x=P());RT}I OP char(){char x;TR}I Fr&OP,(char*x){char t=P();for(;IS(t);t=P());if(~t){for(;!IS
(t)&&~t;t=P())*x++=t;}*x++=0;RT}I Fr&OP,(lf&x){RX;RL;RT}I OP lf(){lf x;TR}I Fr&OP,(llf&x){RX;RL;RT}I OP llf()
{llf x;TR}I Fr&OP,(uint&x){RU;RT}I OP uint(){uint x;TR}I Fr&OP,(ull&x){RU;RT}I OP ull(){ull x;TR}};Fr<Cg>in;
#define WI(S) if(x){if(x<0)P('-'),x=-x;char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
#define WL if(y){lf t=0.5;for(int i=y;i--;)t*=0.1;if(x>=0)x+=t;else x-=t,P('-');*this,(ll)(abs(x));P('.');if(x<0)\
x=-x;while(y--){x*=10;x-=floor(x*0.1)*10;P(((int)x)%10+'0');}}else if(x>=0)*this,(ll)(x+0.5);else *this,(ll)(x-0.5);
#define WU(S) if(x){char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
template<typename T>struct Fw{T P;I Fw&OP,(int x){WI(10);RT}I Fw&OP()(int x){WI(10);RT}I Fw&OP,(uint x){WU(10);RT}
I Fw&OP()(uint x){WU(10);RT}I Fw&OP,(ll x){WI(19);RT}I Fw&OP()(ll x){WI(19);RT}I Fw&OP,(ull x){WU(20);RT}I Fw&OP()
(ull x){WU(20);RT}I Fw&OP,(char x){P(x);RT}I Fw&OP()(char x){P(x);RT}I Fw&OP,(const char*x){while(*x)P(*x++);RT}
I Fw&OP()(const char*x){while(*x)P(*x++);RT}I Fw&OP()(lf x,int y){WL;RT}I Fw&OP()(llf x,int y){WL;RT}};Fw<Cp>out;

const int N=100007;

int n,t[N][3],s[N];

int main()
{
	in,n;
	fo0(l,3)fo1(i,n)in,t[i][l];
	fo1(i,n)
	{
		int p=(t[i][0]-1)/3;
		//out,p,'\n';
		bool f1=1,f2=1;
		fo0(j,3)f1&=t[i][j]==p*3+j+1;
		fo0(j,3)f2&=t[i][j]==p*3+3-j;
		if((!f1&&!f2)||(~(i^p)&1))return puts("No"),0;
		s[i]=f1?p+1:-p-1;
	}
	//fo1(i,n)out,s[i],' ';out,'\n';
	int a[2]={0,0},b[2]={0,0};
	fo1(i,n)a[i&1]^=s[i]<0;
	fo1(i,n)while(abs(s[i])!=i)std::swap(s[i],s[abs(s[i])]),b[i&1]^=1;
	out,a[0]==b[1]&&a[1]==b[0]?"Yes":"No",'\n';
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

class Fruit {
public:
    int time;
    int gain;
    string name;
    Fruit(string name) {
	time = 0;
	gain = 0;
	this->name = name;
    }
    bool operator< (const Fruit &a) const {
	if (gain * a.time == a.gain * time) return name < a.name;
	return gain * a.time > a.gain * time;
    }
};

signed main() {
    int N;

    while (cin >> N) {
	if (!N) break;

	vector<Fruit> fruits;
	rep(i, N) {
	    string L;
	    int P, A, B, C, D, E, F, S, M;
	    cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;

	    Fruit fruit = Fruit(L);
	    fruit.time = A + B + C;
	    fruit.time += (D + E) * M;
	    fruit.gain = S * F * M - P;
	    fruits.push_back(fruit);
	}
	sort(all(fruits));
	rep(i, N) {
	    cout << fruits[i].name << endl;
	}
	cout << "#" << endl;
    }

    return 0;
}


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

int main(){
  string s;
  cin>>s;
  if(s.size()!=26){
    map<char,int> mp;
    rep(i,s.size()){
      mp[s[i]]=1;
    }
    rep(i,26){
      if(mp['a'+i]!=1){
        s+=('a'+i);
        break;
      }
    }
    cout<<s<<endl;
  }else{
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
      cout<<-1<<endl;
      return 0;
    }
    vector<char> tmp;
    tmp.push_back(s[25]);
    for(int i=24; i>=0; i--){
      char ch='{';
      for(auto x : tmp){
        if(x > s[i]){
          ch=min(ch,x);
        }
      }
      if(ch!='{'){
        s = s.substr(0,i);
        s+=ch;
        break;
      }
      tmp.push_back(s[i]);
    }
    cout<<s<<endl;
  }
}

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

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

const int N_prime = 15000;

class prime
{
		public:
			prime();
			vector<int> primeList;
			bool used[N_prime];
};

prime::prime()
{
	memset(used, true, sizeof(used));

	//一千万までの素数
	for(int i = 2; i < sqrt( N_prime ); i++)
	{
		if(used[i] == false)
		{
			continue;
		}

		for(int j = i*2; j < N_prime; j += i)
		{
			used[j] = false;
		}
	}

	for(int i = 2; i < N_prime; i++)
	{
		if(used[i] == true)
		{
			primeList.push_back(i);
		}
	}
}
int main()
{
	prime twin;
	int limit;
	while(cin >> limit, limit)
	{
		for(int i = 0; i < 10001; i++)
		{
			if(twin.primeList[i] > limit)
			{
				limit = i-1;
				break;
			}
			else if(twin.primeList[i] == limit)
			{
				limit = i;
				break;
			}
		}
		for(int i = limit; i > 0; i--)
		{
			if(twin.primeList[i-1] == twin.primeList[i]-2)
			{
				printf("%d %d\n",twin.primeList[i-1] ,twin.primeList[i]);
				break;
			}
		}
	}
}


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

int main(){
  int n; cin >> n;
  int x = 100;
  int f = n/x;
  int q = n%10;
  n /= 10;
  int y = n%10;
  if(y > f)cout << f + 1 << f + 1 << f + 1 << '\n';
  else if(y == f && q > f) cout << f + 1 << f + 1 << f + 1 << '\n';
  else cout << f << f << f << '\n';
}

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

int main() {
  string s;
  cin >> s;
  if (3 == (int)s.size()) {
    reverse(s.begin(), s.end());
    cout << s << endl;
  }
  else {
    cout << s << endl;
  }
}


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

int main(){
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	for (int i=0; i<h; i++){
		for (int j=0; j<w; j++){
			if ((i<b && j<a) || (i>=b && j>=a)) cout << "1";
			else cout << "0";
		}
		cout << "\n";
	}
}

#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    string zo = string(a, '0') + string(w-a, '1');
    string oz = string(a, '1') + string(w-a, '0');
    rep(i, h) cout << (i<b ? zo : oz) << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i=0; i<2*n; i++){
    if((i + (s[i] == 'W')) % 2 == 0){
      s[i] = 'L';
    }
    else{
      s[i] = 'R';
    }
  }
  if(count(s.begin(), s.end(), 'L') != n) cout << 0 << endl;
  else{
    ll ans = 1;
    int left = 0;
    for(int i=0; i<2*n; i++){
      if(s[i] == 'L') left++;
      else{
        ans *= left;
        left--;
        ans %= MOD;
      }
    }
    for(int i=1; i<n+1; i++){
      ans *= i;
      ans %= MOD;
    }
    cout << ans << endl;
  }
}

#include <cstdio>
using namespace std;
#define MOD 1000000007
char s[200007];
int main(){
	register int n, n2, i, ans, cnt, pre, now;
	scanf("%d", &n);
	n2 = n * 2;
	scanf("%s", s + 1);
	if (s[1] == 'W' || s[n2] == 'W') {
		puts("0");
		return 0;
	}
	ans = cnt = 1, pre = 0;
	for (i = 2; i < n2; ++i) {
		if (s[i - 1] != s[i]) now = pre;
		else now = pre ^ 1;
		//now: 0 = [, 1 = ]
		if (now) {
			ans = 1ll * ans * cnt % MOD;
			--cnt;
		}
		else ++cnt;
		pre = now;
	}
	if (cnt > 1) {
		puts("0");
		return 0;
	}
	for (i = 2; i <= n; ++i) ans = 1ll * ans * i % MOD;
	printf("%d\n", cnt == 1 ? ans : 0);
	return 0;
}


// D - Factorization

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;

const int MOD = 1000000007;

vector<pair<ll, ll>> prime_factorize(ll n) {
	vector<pair<ll, ll> > result;
	for (ll p=2; p*p<=n; p++) {
		if (n % p != 0) continue;
		ll num = 0;
		while (n % p == 0) {
			num++;
			n /= p;
		}
		result.push_back(make_pair(p, num));
    }
    if (n != 1) {
    	result.push_back(make_pair(n, 1));
    }
    return result;
}

vector<ll> prime_factorize_straight(ll n) {
	vector<ll> result;
	vector<pair<ll, ll>> pair_result = prime_factorize(n);
	for (auto pair : pair_result) {
		for (ll i=0; i<pair.second; i++) {
			result.push_back(pair.first);
		}
	}

	return result;
}

// mod p （pは素数）の下でのべき乗を求める
ll mod_pow(ll a, ll n, ll p) {
		ll result = 1;
		while (n > 0) {
			if (n & 1) result = result * a % p;
			a = a * a % p;
			n >>= 1;
		}
		return result;
	};

// mod p（pは素数）の下での逆元を求める（フェルマーの小定理を利用）
ll mod_inverse(ll a, ll p) {
	return mod_pow(a, p-2, p);
}

// mod p （pは素数）の下での除算 (a / b)
ll mod_devide(ll a, ll b, ll p) {
	return a * mod_inverse(b, p) % p;
}

ll mod_comb(ll n, ll k, ll p) {
	ll numerator = 1;
	for (int i=n; i>n-k; i--) {
		numerator *= i;
		numerator %= p;
	}

	ll denominator = 1;
	for (int i=k; i>0; i--) {
		denominator *= i;
		denominator %= p;
	}

	return mod_devide(numerator, denominator, p);
}

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

	vector<pair<ll, ll>> pf = prime_factorize(M);

	ll ans = 1;

	for (auto p : pf) {
		int k = p.second;
		ans = (ans * mod_comb(k+N-1, N-1, MOD)) % MOD;
	}

	cout << ans << endl;

	return 0;
}

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

ll N, M;
const int MAX = 5.0e5 + 100;
const int MOD = 1.0e9 + 7;
ll fac[MAX], finv[MAX], inv[MAX];

vector<ll> primeFactorization(ll n) {
    vector<ll> ret;
    ll a = 2;
    while (n >= a * a) {
        if (n % a == 0) {
            ret.push_back(a);
            n /= a;
        }
        else a++;
    }
    ret.push_back(n);
    return ret;
}

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

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

int main() {
    COMinit();

    cin >> N >> M;

    if (M == 1) {
        cout << 1 << endl;
    }
    else {
        vector<ll> pf = primeFactorization(M);
        map<ll, ll> mp;
        for (int i = 0; i < pf.size(); i++) {
            mp[pf[i]]++;
        }

        ll ans = 1;
        for (auto itr = mp.begin(); itr != mp.end(); itr++) {
            ll val = itr->second;
            ans = (ans * COM(N+val-1, val)) % MOD;
        }

        cout << ans << endl;
    }

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define maz(a,b) a=max(a,b);
typedef long long ll;

using namespace std;
#define N 310
ll d[N][N][N],n,x;
string s;
int main(){
    cin>>s>>x; n=s.size();
    lol(k,x+1)lol(i,n)d[0][i][k]=0,d[1][i][k]=1;
    for(ll t=2;t<=n;t++){
	for(ll i=0;i+t-1<n;i++)lol(k,x+1){
	    ll l=i,r=i+t-1;
	    ll res=max(d[t-1][i][k],d[t-1][i+1][k]);
	    if(s[l]==s[r]){
		maz(res,d[t-2][i+1][k]+2);
	    }
	    else if(k){
		maz(res,d[t-2][i+1][k-1]+2);
	    }
	    d[t][i][k]=res;
	}
    }
    cout<<d[n][0][x]<<endl;
    return 0;
}

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n;
string s;
bool b[200010];
signed main() {
	cin >> n >> s;
	if (s[0] == 'W' || s.back() == 'W') {
		cout << 0 << endl;
		return 0;
	}
	REP(i, 2 * n - 1) {
		if (s[i - 1] == s[i] && !b[i - 1])b[i] = true;
		if (s[i - 1] != s[i] && b[i - 1])b[i] = true;
	}
	if (!b[2 * n - 1]) {
		cout << 0 << endl;
		return 0;
	}
	int ans = 1, cnt = 0;
	rep(i, 2 * n) {
		if (b[i]) {
			ans *= cnt;
			ans %= mod;
			cnt--;
		}
		else cnt++;
	}
	if (cnt) {
		cout << 0 << endl;
		return 0;
	}
	REP(i, n) {
		ans *= i;
		ans %= mod;
	}
	cout << ans << endl;
}


//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//
//#include <immintrin.h>
//#include <emmintrin.h>

#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
#define vi vector<int>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define all2(x,n) (x+1), (x+1+n)
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define mt make_tuple
#define eb emplace_back
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define contain(S,X) (((S)&o(X))!=0)
#define containL(S,X) (((S)&oL(X))!=0)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=998244353;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;
inline int getplc(int x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}
LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}
// Smax
//int Smax() { return -INF; }
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
// Smin
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
template <typename T>
// erro
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); }

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}
void Solve();
int main() {
#ifndef ONLINE_JUDGE
//	freopen("in.txt","r",stdin);
//    freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}

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

int l[N],r[N],id[N];
int n;
int a[N],s[N],pre[N],ans[N];
void add(int x,int y){
  for(;x<=n;x+=x&-x)s[x]+=y;
}
int ask(int x){
  int res=0;
  for(;x;x-=x&-x)res+=s[x];
  return res;
}
void Solve(){
  int q;
  cin>>n>>q;
  rep(i,1,n){
    cin>>a[i];
  }
  rep(i,1,q){
    cin>>l[i]>>r[i];
    id[i]=i;
  }
  sort(id+1,id+1+q,[&](int a,int b){
    return r[a]<r[b];
  });
  int r=1;
  rep(i,1,n){
    if(pre[a[i]])add(pre[a[i]],-1);
    add(i,1);
    pre[a[i]]=i;
//    error(i);
//    rep(j,1,n)error(j,ask(j));
    while(r<=q&&::r[id[r]]<=i){
//      error(i,l[id[r]],::r[id[r]]);
      ans[id[r]]=ask(i)-ask(l[id[r]]-1);
      r++;
    }
  }
  rep(i,1,q){
    cout<<ans[i]<<'\n';
  }

}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    a--, b--;
    mat<char> grid = mmat<char>(100, 100);
    rep (i, 50)
        rep (j, 100)
            grid[i][j] = '.';
    rep (i, 50)
        rep (j, 100)
            grid[i + 50][j] = '#';

    rep (i, a) {
        int row = i / 50 * 2 + 51;
        int col = (i % 50) * 2;
        grid[row][col] = '.';
    }
    rep (i, b) {
        int row = i / 50 * 2;
        int col = (i % 50) * 2;
        grid[row][col] = '#';
    }

    print(100, 100);
    rep (i, 100) {
        rep (j, 100)
            cout << grid[i][j];
        cout << endl;
    }

    return 0;
}


//int a = s - '0'; 文字から数字
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;

//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main() {
	ll N, M;cin >> N >> M;
	vector<ll> L(M), R(M);
	rep(i,M) cin >> L[i] >> R[i];

	sort(ALL(L));
	sort(ALL(R));

	if(R[0] - L[M-1] + 1 < 0) cout << 0 << endl;
	else cout << R[0] - L[M-1] + 1 << endl;
}

#include <iostream>
#define SIZE 100000
using namespace std;

void copy(int *res, int *ori, int n){
    for(int i=0;i<n;i++){
        *(res+i) = *(ori+i);
    }
}

void mult(int *res, int *a, int n){
    for(int i=0;i<n;i++){
        *(res+i) = *(a + *(res+i));
    }
}

void pow(int *res, int *a, long long b, int n){
    int base[SIZE], tmp[SIZE];
    for(int i=0;i<n;i++){
        *(base+i) = *(a+i);
        *(res+i) = i;
    }
    while(b > 0){
        if(b%2 == 0){
            copy(tmp, base, n);
            mult(tmp, base, n);
            copy(base, tmp, n);
            b /= 2;
        }else{
            mult(res, base, n);
            b--;
        }
    }
}

int main(void){
    int n, m, p[SIZE], q[SIZE];
    long long k;
    long long x[SIZE], y[SIZE];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x[i];
        p[i] = i;
        if(i>0){
            y[i-1] = x[i] - x[i-1];
        }
    }
    cin >> m >> k;
    for(int i=0;i<m;i++){
        int a, t;
        cin >> a;
        a--;
        t = p[a];
        p[a] = p[a-1];
        p[a-1] = t;
    }
    pow(q, p, k, n-1);

    for(int i=0;i<n;i++){
        if(i > 0){
            x[i] = x[i-1] + y[q[i-1]];
        }
        cout << x[i] << endl;
    }/*
    for(int i=0;i<n;i++){
        cout << i << " : " << q[i] << endl;
        cout << i << "y : " << y[i] << endl;
    }*/
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//素数判定
//#include <cmath>
bool is_prime(long long n) {
	if (n == 1) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (long long i = 3; i <= sqrt(n); i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

//二項係数 mod p
//#include <vector>
long long modinv(long long n, long long p) {
	long long a = p, u = 1, v = 0;
	while (a) {
		long long t = n / a;
		n -= t * a;
		std::swap(n, a);
		u -= t * v;
		std::swap(u, v);
	}
	u %= p;
	if (u < 0) u += p;
	return u;
}

std::vector<long long> factorial;
std::vector<long long> factorial_inv;
void make_table(long long n, long long p) {
	factorial.resize(n, 1);
	factorial_inv.resize(n, 1);
	for (long long i = 2; i <= n; i++) {
		factorial[i] = factorial[i - 1] * i % p;
	}
	factorial_inv[n] = modinv(factorial[n], p);
	for (long long i = n - 1; i >= 2; i--) {
		factorial_inv[i] = factorial_inv[i + 1] * (i + 1) % p;
	}
}

long long combination(long long n, long long r, long long p) {
	r = std::min(r, n - r);
	long long ret = factorial[n] * factorial_inv[r] % p;
	ret *= factorial_inv[n - r];
	ret %= p;
	return ret;
}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	const ll p = 1e9 + 7;
	//const ll p = 998244353;

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

	map<ll, ll> mp;
	ll x = m;
	for (ll i = 2; i <= x; i++) {
		if (is_prime(x)) {
			mp[x]++;
			break;
		}
		if (!is_prime(i)) continue;
		ll cnt = 0;
		while (x % i == 0) {
			x /= i;
			cnt++;
		}
		mp[i] += cnt;
	}

	make_table(1e7, p);
	ll ans = 1;
	for (auto i = mp.begin(); i != mp.end(); i++) {
		ll a = (i -> first), b = (i -> second);
		ans *= combination(b + n - 1, n - 1, p);
		ans %= p;
	}
	cout << ans << endl;
}

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

using Weight = long long;
using Vertex = int;
struct Edge {Vertex from, to; Weight weight;};
using Graph = std::vector<std::vector<Edge>>;

std::vector<std::vector<Vertex>> connected_component(const Graph& G) {
  std::vector<std::vector<Vertex>> cc;
  std::vector<bool> used(G.size());
  std::function<void(int)> dfs = [&](int v) {
    cc.back().push_back(v);
    used[v] = true;
    for(const auto& e: G[v]) if(!used[e.to]) dfs(e.to);
  };
  for(Vertex v = 0; v < G.size(); ++v) if(!used[v]) {
    cc.push_back(std::vector<Vertex>());
    dfs(v);
  }
  return cc;
}

using I = long long;

I com2(I n) {return n * (n - 1) / 2;}

bool check(const auto& G, auto s) {
  vector<int> color(G.size(), -1);
  function<bool(Vertex, int)> dfs = [&](auto v, auto c) {
    if(color[v] != -1) return color[v] == c;
    color[v] = c;
    c ^= 1;
    for(const auto& e: G[v]) if(!dfs(e.to, c)) return false;
    return true;
  };
  return dfs(s, 0);
}

int main() {
  I N, M;
  cin >> N >> M;
  Graph G(N);
  for(auto i=0; i<M; ++i) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    G[u].push_back({u, v});
    G[v].push_back({v, u});
  }

  auto cc = connected_component(G);
  auto V = N - count_if(begin(cc), end(cc), [](const auto& v) {return v.size() == 1;});
  auto ans = N * N - V * V;
  I twocol = 0, obscure = 0;
  for(auto c: cc) if(c.size() != 1) {
    if(check(G, *begin(c))) ++twocol;
    else                    ++obscure;
  }
  ans += 2 * twocol + obscure;
  ans += 4 * com2(twocol) + 2 * com2(obscure);
  ans += 2 * twocol * obscure;
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2005;
int n,m,q,ans;
int a[maxn][maxn],s[maxn][maxn],up[maxn][maxn],lf[maxn][maxn];
inline int read()
{
	int ret=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-f;ch=getchar();}
	while(ch>=48&&ch<=57){ret=ret*10+ch-48;ch=getchar();}
	return ret*f;
}
char fstchar()
{
	char ch=getchar();
	while(ch!='0'&&ch!='1') ch=getchar();
	return ch;
}
int main()
{
	n=read();m=read();q=read();
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=fstchar()-'0',s[i][j]=a[i][j]+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
		up[i][j]=up[i][j-1]+up[i-1][j]-up[i-1][j-1];
		lf[i][j]=lf[i-1][j]+lf[i][j-1]-lf[i-1][j-1];
		if(a[i][j]&&a[i-1][j]) up[i][j]++;
		if(a[i][j]&&a[i][j-1]) lf[i][j]++;
	}
	while(q--)
	{
		int x=read(),y=read(),xx=read(),yy=read();
		ans=s[xx][yy]-s[x-1][yy]-s[xx][y-1]+s[x-1][y-1];
		ans-=up[xx][yy]-up[x][yy]-up[xx][y-1]+up[x][y-1];
		ans-=lf[xx][yy]-lf[xx][y]-lf[x-1][yy]+lf[x-1][y];
		printf("%d\n",ans);
	}
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define mod 998244353
#define inv2 499122177
#define M 1000020
using namespace std;
namespace IO{
	int Top=0; char SS[20];
	void write(int x){
		if(!x){putchar('0');return;} if(x<0) x=-x,putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}using namespace IO;
int mul(int x,int y){return (LL)x*(LL)y%mod;}
int add(int x,int y){return (x+y>=mod)?x+y-mod:x+y;}
int mus(int x,int y){return (x-y<0)?x-y+mod:x-y;}
int qpow(int x,int sq){
	int res=1;
	for(;sq;sq>>=1,x=mul(x,x)) if(sq&1) res=mul(res,x);
	return res;
}
int n,m,fac[M],ifac[M],ans;
int C(int tot,int tk){return mul(fac[tot],mul(ifac[tot-tk],ifac[tk]));}
int main(){
	n=read(),m=read(),fac[0]=1; if(n>m) swap(n,m);
	for(int i=1;i<=n+m;i++) fac[i]=mul(fac[i-1],i); ifac[n+m]=qpow(fac[n+m],mod-2);
	for(int i=n+m;i;i--) ifac[i-1]=mul(ifac[i],i);
	for(int i=1;i<=n;i++) ans=add(ans,mul(C(i<<1,i),C(n+m-(i<<1),n-i)));
	write(add(mul(ans,mul(inv2,qpow(C(n+m,m),mod-2))),m)),putchar('\n'); return 0;
}

#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db double

using namespace std;
const int N=5e5+10,mod=998244353;
int rd()
{
	int x=0,w=1;char ch=0;
	while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*w;
};
void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;}
int fpow(int a,int b){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;} return an;}
int ginv(int a){return fpow(a,mod-2);}
int n,m,fac[N<<1],iac[N<<1];
int C(int a,int b){return b<0||a<b?0:1ll*fac[a]*iac[b]%mod*iac[a-b]%mod;}

int main()
{
	fac[0]=1;
	for(int i=1;i<=1000000;++i) fac[i]=1ll*fac[i-1]*i%mod;
	iac[1000000]=ginv(fac[1000000]);
	for(int i=1000000;i;--i) iac[i-1]=1ll*iac[i]*i%mod;
	n=rd(),m=rd();
	if(n<m) swap(n,m);
	int ans=0;
	for(int i=1;i<=n;++i) ad(ans,1ll*C(i+i,i)*C(n+m-i-i,n-i)%mod);
	ans=1ll*ans*ginv(C(n+m,n))%mod*ginv(2)%mod;
	ad(ans,n);
	printf("%d\n",ans);
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }

template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}// 改行付き出力

double dp[330][330][330];
bool flag[330][330][330];
int n;

double recurse(int i, int j, int k)
{
    if (abs(dp[i][j][k] + 1) > 1e-9)
        return dp[i][j][k];

    double ret = 0;
    ret += (double)n / (double)(i + j + k);

    if (i > 0)
        ret += (double)i / (double)(i + j + k) * recurse(i - 1, j, k);
    if (j > 0)
        ret += (double)j / (double)(i + j + k) * recurse(i + 1, j - 1, k);
    if (k > 0)
        ret += (double)k / (double)(i + j + k) * recurse(i, j + 1, k - 1);
    dp[i][j][k] = ret;

    return ret;
}
// TODO: write
int main() {
  cin>>n;
  int c[4] = {0};
  rep(i,n){
    int a;cin>>a;
    c[a]++;
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = 0;
  print(recurse(c[1],c[2],c[3]));
  return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<math.h>
#include<set>
using namespace std;

void itsvgg()
{
    ios::sync_with_stdio(0);cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

double rolls[301][301][301];

void initialization()
{
		for(int i=0;i<=300;i++)
		for(int j=0;j<=300;j++)
			for(int k=0;k<=300;k++)
				rolls[i][j][k]=0.0;
}

double prob(int n, int x,int y, int z)
{
	double p1=double(x)/double(n),p2=double(y)/double(n),p3=double(z)/double(n);
	double p0=1-p1-p2-p3;
	double k=1;
	if(x>0)
	{
		if(rolls[x-1][y][z]==0)
			k+=p1*prob(n,x-1,y,z);
		else
			k+=p1*rolls[x-1][y][z];
	}
	if(y>0)
	{
		if(rolls[x+1][y-1][z]==0)
			k+=p2*prob(n,x+1,y-1,z);
		else
			k+=p2*rolls[x+1][y-1][z];
	}
	if(z>0)
	{
		if(rolls[x][y+1][z-1]==0)
			k+=p3*prob(n,x,y+1,z-1);
		else
			k+=p3*rolls[x][y+1][z-1];
	}
	//cout<<x<<" "<<1-p0<<endl;

	if(x!=0 || y!=0 || z!=0)
		rolls[x][y][z]=k/(1-p0);
	else
		rolls[x][y][z]=0;
	return rolls[x][y][z];

}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    itsvgg();
	initialization();
	int n;
	cin>>n;
	int ones=0,twos=0,threes=0;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		if(x==1)
		{
			ones++;
		}
		else if (x==2)
			twos++;
		else
			threes++;
	}
	//cout<<ones<<twos<<threes<<endl;

	//cout<<expected[0][0][0];
	//cout<<ones<<twos<<threes<<endl;
	cout.precision(10);
	cout<<prob(n,ones,twos,threes);
}


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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

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

const int N = 2e5 + 5;

int A[N];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];
	if (A[0] != 0) die(-1);
	for (int i = 1; i < n; i++) if (A[i] - A[i - 1] > 1) die(-1);
	ll res = 0;
	for (int i = 1; i < n; i++) if (A[i] == A[i - 1] + 1) res++; else res += A[i];
	cout << res << endl;

	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    int N;
    cin >> N;
    map<int, int> A;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        A[a]++;
    }
    int ans = 0;
    for (auto x : A) {
        if (x.second % 2 != 0) ans++;
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long int
#define s(x)	cin>>x
#define p(x)	cout<<x<<"\n"
#define goog(x, y)  cout<<"Case #"<<x<<": "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 100000000000
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpi;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
typedef long double ld;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
int gcd(int a, int b) ;

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve() {
  int d,t,s;cin>>d>>t>>s;
  int k=d/s;
  if(k<t)
  p("Yes");
  else if(k==t)
  { if(d%s==0)
    p("Yes");
    else p("No");
  }
  else p("No");
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

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

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    //u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

#include<bits/stdc++.h>
using namespace std;
#define rg register
#define rep(i,a,b) for (rg int i=(a);i<=(b);i++)
#define per(i,a,b) for (rg int i=(b);i>=(a);i--)
#define pb push_back
#define lowbit(x) (x&(-x))
#define replow(i,a,b) for(rg int i = (a);i<=(b);i+=lowbit(i))
#define perlow(i,a,b) for(rg int i = (b);i>=(a);i-=lowbit(i))
#define mk make_pair
#define VI vector<int>
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define fi first
#define se second
#define il inline
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define inf 0x3f3f3f3f
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
char buf[1<<15],*p1 = buf,*p2 = buf;
inline ll read(){
    #define num ch-'0'
    char ch;bool flag=0;ll res;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=res*10ll+num);
    (flag)&&(res=-res);
    #undef num
    return res;
}
inline void write(ll x){
	if (x < 0) x = ~x + 1ll, putchar('-');
	if (x > 9) write(x / 10ll);
	putchar(x % 10ll + '0');
}
#define mid ((l + r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
#undef mid
#undef ls
#undef rs
multiset<int> s;
void solve()
{
	int n = read();
	int mn = 1e9 + 10;
	int cnt = 0;
	rep(i,1,n)
	{
		int x = read();
		if(s.empty())
		{
			s.insert(x);
		}
		else
		{
			auto it = s.lower_bound(x);
			if(it == s.begin())
			{
				s.insert(x);
			}
			else
			{
				it--;
				s.erase(it);
				s.insert(x);
			}
		}
	}
	printf("%d",s.size());
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
//	int T = read();
//	while(T--)
	solve();
}


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

char getResult(map<char, string> &s){
  char turn, next;
  for(turn = 'a'; s[turn].size() > 0; turn = next){
    next = s[turn][0];
    s[turn] = s[turn].erase(0,1);
  }
  return toupper(turn);
}

int main(){
  map<char, string> s;
  for(char c = 'a'; c <= 'c'; c++){
    cin >> s[c];
  }

  char result = getResult(s);
  cout << result << endl;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    string a, b, c;
    cin >> a >> b >> c;
    if(a.back() == b.front()){
        if(b.back() == c.front()) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> c(20, vector<int>(20));
    vector<pair<int, int>> a;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        ll x = 0;
        bool found = false;
        for (int i = 0; i < (int)s.size(); i++) {
            if (s[i] != '.') (x *= 10) += s[i] - '0';
            else found = true;
        }
        if (!found)  x *= (ll)1e9;
        else {
            int cur = 0;
            while (s.back() != '.')
                ++cur,s.pop_back();
            for (int it = 0; it < 9 - cur; it++) x *= 10;
        }
        int c2=0,c5=0;
        ll y = x;
        while (y % 2 == 0)
            ++c2,y /= 2;
        y = x;
        while (y % 5 == 0)
            ++c5,y /= 5;
        ++c[min(18, c2)][min(18, c5)];
        a.emplace_back(min(18, c2), min(18, c5));
    }
    for (int i = 18; i >= 0; i--)
        for (int j = 18; j >= 0; j--)
            c[i][j] += c[i + 1][j] + c[i][j + 1] - c[i + 1][j + 1];
    ll w = 0;
    for (auto x : a)
        w += c[18 - x.first][18 - x.second] - (x.first >= 9 && x.second >= 9);
    w /= 2;
    cout << w;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
int main(){
    int N;
    cin>>N;
    vector<P> Bracketfirst(0);
    vector<P> Bracketsecond(0);
    //A (
    //B )
    for(int i=0;i<N;i++){
        int A=0,B=0;
        string S;
        cin>>S;
        for(int j=0;j<(int)S.size();j++){
            if(S.at(j)=='('){
                A++;
            }
            else{
                if(A>0){
                    A--;
                }
                else{
                    B++;
                }
            }
        }
        if(A>=B){
            Bracketfirst.push_back(make_pair(B,A));
        }
        else{
            Bracketsecond.push_back(make_pair(A,B));
        }
    }
    sort(Bracketfirst.begin(),Bracketfirst.end());
    sort(Bracketsecond.begin(),Bracketsecond.end());
    reverse(Bracketsecond.begin(),Bracketsecond.end());
    string answer="";
    for(int i=0;i<(int)Bracketfirst.size();i++){
        //cout<<Bracket.at(i).first<<" "<<Bracket.at(i).second<<endl;
        for(int j=0;j<Bracketfirst.at(i).first;j++){
            answer+=")";
        }
        for(int j=0;j<Bracketfirst.at(i).second;j++){
            answer+="(";
        }
    }
    for(int i=0;i<(int)Bracketsecond.size();i++){
        //cout<<Bracket.at(i).first<<" "<<Bracket.at(i).second<<endl;
        for(int j=0;j<Bracketsecond.at(i).second;j++){
            answer+=")";
        }
        for(int j=0;j<Bracketsecond.at(i).first;j++){
            answer+="(";
        }
    }
    //cout<<answer<<endl;
    int a=0,b=0;
    for(int i=0;i<(int)answer.size();i++){
        if(answer.at(i)=='('){
            a++;
        }
        if(answer.at(i)==')'){
            b++;
        }
        if(a<b){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(a==b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
map<int,int>t;
int N,B[200005],bit[200005];

int sum(int i)
{
	int s=0;
	while(i>0)
	{
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}

void add(int i,int x)
{
	while(i<=N)
	{
		bit[i]+=x;
		i+=i&-i;
	}
}
int main()
{
	long long ans=0;
	scanf("%d",&N);

	for(int i=0;i<N;i++)
	{
		scanf("%d",B+i);
		t[B[i]]=1;
	}
	int i=1;
	for(map<int,int>::iterator it=t.begin();it!=t.end();it++,i++)
		it->second=i;
	for(int i=0;i<N;i++)
		B[i]=t[B[i]];
	for(int j=0;j<N;j++)
	{
		ans+=j-sum(B[j]);
		add(B[j],1);
	}
	printf("%lld\n",ans);
}

#include <stdio.h>
#define MAX 200000
#define INFTY 2000000000
double cnt=0;
void bubble(int *,int,int,int);
void bubbleSort(int *,int,int);

void bubble(int *A,int left,int mid,int right){
  int i,j,k;
  int x1,x2;
  int L[MAX],R[MAX];

  x1=mid-left;
  x2=right-mid;

  for(i=0;i<x1;i++){
    L[i]=A[left+i];
  }

  for(i=0;i<x2;i++){
    R[i]=A[mid+i];
  }

  L[x1]=INFTY;
  R[x2]=INFTY;

  i=0;
  j=0;

  for(k=left;k<right;k++){
    if(L[i]<R[j]){
      A[k]=L[i];
      i++;
    }else{
      A[k]=R[j];
      cnt=cnt+(x1-i);
      j++;
    }
  }

}

void bubbleSort(int *A,int left,int right){
  int middle;

  if(left+1<right){
    middle=(left+right+1)/2;
    bubbleSort(A,left,middle);
    bubbleSort(A,middle,right);
    bubble(A,left,middle,right);
  }
}

int main()
{
  int i,n,A[MAX];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  bubbleSort(A,0,n);

  printf("%.0f\n",cnt);

  return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
const double PI = acos(-1);

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b)
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }

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

//素因数分解
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
//const auto &pf = prime_factorize(i);
//for (auto p : pf) cout << p.first << " " << p.second;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main()
{
    int n, m; cin >> n >> m;
    vector<int> x(n+1), y(m+1);
    cin >> x[0] >> y[0];
    for (int i = 1; i<= n; i++)
        cin >> x[i];
    for (int i = 1; i<= m; i++)
        cin >> y[i];
    sort(ALL(x));
    sort(ALL(y));
    if (x[n] < y[0])
        cout << "No War" << endl;
    else
        cout <<"War" << endl;
    return 0;
}

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

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int max_x;
    cin >> max_x;
    rep(i, N - 1){
        int x;
        cin >> x;
        max_x = max(max_x, x);
    }
    int min_y;
    cin >> min_y;
    rep(i, N - 1){
        int y;
        cin >> y;
        min_y = min(min_y, y);
    }
    for (int i = X + 1; i <= Y; i++){
        if (max_x < i && i <= min_y){
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
}


/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;

int main() {
int sx,sy,tx,ty;
cin>>sx>>sy>>tx>>ty;
string S="";
rep(i,ty-sy){
  S+='U';
}
rep(i,tx-sx){
  S+='R';
}
rep(i,ty-sy){
  S+='D';
}
rep(i,tx-sx){
  S+='L';
}
S+='L';
rep(i,ty-sy+1){
  S+='U';
}
rep(i,tx-sx+1){
  S+='R';
}
S+='D';
S+='R';
rep(i,ty-sy+1){
  S+='D';
}
rep(i,tx-sx+1){
  S+='L';
}
S+='U';
cout<<S<<endl;
return 0;
}

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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int x = tx-sx, y = ty-sy;
    rep(i,x) cout << 'R';
    rep(i,y) cout << 'U';
    rep(i,x) cout << 'L';
    rep(i,y) cout << 'D';
    cout << 'D';
    rep(i,x+1) cout << 'R';
    rep(i,y+1) cout << 'U';
    cout << 'L';
    cout << 'U';
    rep(i,x+1) cout << 'L';
    rep(i,y+1) cout << 'D';
    cout << 'R';
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;

char map[13][13];
int d[13][13];
int dy[4]={-1,0,1,0};
int dx[4]={0,-1,0,1};

void bfs(int y,int x);
int main(){
    char a[12];
    string str;
    while(1){
    int co=0;
    for(int i=0;i<12;i++){
        cin>>map[i];
    }
    if(cin.eof())break;
    for(int i=0;i<12;i++){
        for(int j=0;j<12;j++){
            d[i][j]=0;
        }
    }
    for(int i=0;i<12;i++){
        for(int j=0;j<12;j++){
          if(map[i][j]=='1' && d[i][j]==0){
	    co++;
            bfs(i,j);
          }
        }
    }
    cout<<co<<endl;
    }
}
void bfs(int y,int x){
    d[y][x]=1;
    for(int p=0;p<4;p++){
        int ny=y+dy[p];
        int nx=x+dx[p];
        if(ny>=0 && ny<12 && nx>=0  && nx<12  && d[ny][nx]==0 && map[ny][nx]=='1' ){
            bfs(ny,nx);
        }
    }
   return;
}

#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

int a[144];

void flip(int x, int y)
{
  if(x>11||y>11||x<0||y<0) return;
  if(a[x+y*12])
  {
    a[x+y*12] = 0;
    flip(x+1,y);
    flip(x-1,y);
    flip(x,y+1);
    flip(x,y-1);
  }
}

void solve()
{
  int cnt = 0;
  REP(i,144) if(a[i])
  {
    cnt++;
    flip(i%12,i/12);
  }
  cout << cnt << endl;
}

int main()
{
  string s;
  int i = 0;
  while(cin >> s)
  {
    REP(j,12) a[i*12+j] = s[j]-'0';
    i=(++i)%12;
    if(i==0) solve();
  }
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
vector<P> edge[100005];
vl seen(100005,INFL);
void dfs(int n,ll c,int m){
    for(auto x:edge[n]){
        if(x.first==m)continue;
        seen[x.first]=min(seen[x.first],c+x.second);
        dfs(x.first,seen[x.first],n);
    }
}
int main(){
	int n;cin>>n;
    rep(i,n-1){
        int a,b;cin>>a>>b;
        a--;b--;
        int c;cin>>c;
        edge[a].push_back({b,c});
        edge[b].push_back({a,c});
    }
    int q,k;cin>>q>>k;
    k--;
    dfs(k,0,-1);
    rep(i,q){
        int a,b;
        cin>>a>>b;
        a--;b--;
        cout<<seen[a]+seen[b]<<endl;
    }
}

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

std::vector<int> bipartite(std::vector<std::pair<int,int>> edge){
    int M = edge.size();
    if(M==0)return {};
    int N = 0;
    for(int i=0;i<M;i++){
        N=std::max(N,edge[i].first+1);
        N=std::max(N,edge[i].second+1);
    }
    std::vector<int> R(N,-1);
    std::vector<int> S(0);
    std::vector<std::vector<int>> es(N,std::vector<int>(0));
    for(int i=0;i<M;i++){
        es[edge[i].first].push_back(edge[i].second);
        es[edge[i].second].push_back(edge[i].first);
    }
    std::queue<int> Q;
    std::vector<bool> visited(N,false);
    for(int j=0;j<N;j++){
        if(visited[j])continue;
        Q.push(j);
        R[j]=0;
        visited[j]=true;
        while(!Q.empty()){
            int q=Q.front();
            Q.pop();
            visited[q]=true;
            for(int i=0;i<es[q].size();i++){
                if(R[es[q][i]]==R[q]){
                    return S;
                }
                if(visited[es[q][i]])continue;
                Q.push(es[q][i]);
                R[es[q][i]]=1-R[q];
            }

        }
    }
    return R;
}

signed main(void){
    long long N,M;
    int a,b;
    vector<int> A,B;
    cin >> N >> M;
    REP(i,M){
        cin >> a >> b;
        a--;b--;
        A.push_back(a);
        B.push_back(b);
    }
    vector<pair<int,int>> AB;
    REP(i,M){
        AB.push_back({A[i],B[i]});
        //cout << A[i] MM B[i] << endl;
    }

    vector<int> d=bipartite(AB);
    //vector<int> d(N,1);
    if(d.size()==0){
        cout << N*(N-1)/2 - M << endl;
        return 0;
    }
    //REP(i,N){cout << d[i] << " ";}cout << endl;
    long long x=0,y=0;
    REP(i,N){
        if(d[i]){
            x++;
        }else{
            y++;
        }
    }
    cout << x*y - M << endl;
    return 0;
}


#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector<s>
#define vvec(s) vector<vector<s>>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " "
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli a, b;
    cin>>a>>b;
    lli ans=0;
    rep(i,2){
        if(a>b){
            ans+=a;
            a--;
        }
        else{
            ans+=b;
            b--;
        }
    }
    out(ans);
}

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

signed main(){
	int A, B;
	scanf("%d%d", &A, &B);
	printf("%d\n", (A == B) ? (A + B) : (2 * max(A, B) - 1));
	return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

vpll adj[MAXN];ll visit[MAXN]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m;
string s,t;
vll a;
// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	for(ll i=0;i<n;i++) {
		cin>>m;
		for(ll j=0;j<m;j++) {
			cin>>x>>y;
			x--;
			adj[i].pb({x,y});
		}
	}

	ll maxi = 0;
	for(ll k=1;k<pow(2,n);k++) {
		bool mark = true;
		for(ll i=0;i<n;i++) {
			if((k & (1<<i))) {
				for(ll j=0;j<adj[i].size();j++) {
					if(adj[i][j].s == 1) {
						if((k & (1<<adj[i][j].f)) == 0)
							mark = false;
					}
					else {
						if((k & (1<<adj[i][j].f)))
							mark = false;
					}

					if(mark == false) break;
				}
			}
			if(mark == false) break;
		}
		if(mark) {
			maxi = max(maxi,(ll) __builtin_popcount(k));
		}
	}
	cout<<maxi;newl;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}

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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)

int main(){
    int mod=1000000007;
    int n,a,ans=0;
    sc1(n);
    int w[15][14][2];
    rep(i,15) rep(j,14) rep(k,2) w[i][j][k]=0;
    rep(i,n) {
        sc1(a);
        rep(j,a) sc2(w[i][j][0],w[i][j][1]);
    }
    rep(i,pow(2,n)) {
        if (i==0) continue;
        int x=i;
        int l[15]={0};
        rep(j,n) {
            if (x&1) l[j]=1;
            x=x>>1;
        }
        int f=1;
        rep(j,n) {
            if (l[j]) {
                rep(k,14) if (w[j][k][0]>0 && l[w[j][k][0]-1]!=w[j][k][1]) f=0;
            }
        }
        int cnt=0;
        if (f) {
            rep(j,n) cnt+=l[j];
            ans=max(ans,cnt);
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

#define INF 1e+9
#define MAX_V 2505

struct edge {
  int to;
  int cost;
};

using P = pair<int, int>;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d+V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while ( !que.empty() ) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) { continue; }

    for ( int i = 0; i < G[v].size(); i++ ) {
      edge e = G[v][i];
      if ( d[e.to] > d[v] + e.cost ) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int h, w;
int pos(int i, int j) { return i*w + j; }

int main() {
  cin >> h >> w;
  V = h * w;
  string table[h];
  for ( int i = 0; i < h; i++ ) { cin >> table[i]; }

  int black = 0;
  for ( int i = 0; i < h; i++ ) {
    for ( int j = 0; j < w; j++ ) {
      if ( table[i][j] == '#' ) { black++; continue; }
      if ( i+1 < h )  { G[pos(i,j)].push_back({pos(i+1,j), 1}); }
      if ( i-1 >= 0 ) { G[pos(i,j)].push_back({pos(i-1,j), 1}); }
      if ( j+1 < w )  { G[pos(i,j)].push_back({pos(i,j+1), 1}); }
      if ( j-1 >= 0 ) { G[pos(i,j)].push_back({pos(i,j-1), 1}); }
    }
  }

  dijkstra(pos(0,0));
  int ans = -1;
  if ( d[pos(h-1,w-1)] != INF ) {
    ans = h*w - d[pos(h-1,w-1)] - black - 1;
  }

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


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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

VI n(5, 0);

bool isStraight(){
    int s = 0;
    REP(i, 5) s+=n[i]-n[0]-i;
    if(s == 0) return true;
    else {
        if(n[0] == 1) n[0]+=13;
        SORT(n);

        s = 0;
        REP(i, 5) s+=n[i]-n[0]-i;
        if(s == 0) return true;
        else false;
    }
    return false;
}

int main(){
    while(scanf("%d,%d,%d,%d,%d", &n[0], &n[1], &n[2], &n[3], &n[4])!=EOF){
        int m = 0;
        SORT(n);
        REP(i, 4) FOR(j, i+1, 5) if(n[i]==n[j]) m++;
        switch(m){
            case 1:
                cout << "one pair" << endl;
                break;
            case 2:
                cout << "two pair" << endl;
                break;
            case 3:
                cout << "three card" << endl;
                break;
            case 4:
                cout << "full house" << endl;
                break;
            case 6:
                cout << "four card" << endl;
                break;
            default:
                if(isStraight()) cout << "straight" << endl;
                else cout << "null" << endl;
        }
    }
}

#include <cstdio>
#include <algorithm>
using namespace std;

const char *solve(){
	int c[20] = {};
	int a;
	for(int i = 0; i < 5; ++i){
		if(scanf("%d,", &a) == EOF){ return 0; }
		++c[a];
	}
	c[14] = c[1];

	int mc = 0, ms = 0, p = 0;
	for(int i = 1; i < 14; ++i){
		mc = max(mc, c[i]);
		if(c[i] > 1){ ++p; }
		int s = 0;
		for(int j = 0; j < 5 && c[i + j]; ++j){
			++s;
		}
		ms = max(ms, s);
	}

	if(mc == 4){ return "four card"; }
	if(p > 1 && mc > 2){ return "full house"; }
	if(ms > 4){ return "straight"; }
	if(mc > 2){ return "three card"; }
	if(p > 1){ return "two pair"; }
	if(p){ return "one pair"; }
	return "null";
}

int main(){
	const char *ans;
	while(ans = solve()){
		puts(ans);
	}
}


#define NguyenDangQuan the_author

#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define mset(x, i) memset(x,i,sizeof(x))
#define elif else if
#define heap priority_queue
#define fi first
#define se second
#define pb push_back
#define ld long double
#define ll long long
#define ull unsigned long long
#define task "codejam"
using namespace std;

int typetest;
template<class T>
void read(T &x){
    register int c;
    T neg = 1;
    x = (T)0;
    while ((c = getchar()) <= 47 || c >= 58)
		if(c == '-') neg = -1;
    for (; (c > 47 && c < 58); c = getchar()){
        x = (x << 3) + (x << 1) + (T)(c - 48);
    }
	x *= neg;
}
inline void fastIOfileinput(){
	ios:: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(task".INP", "r", stdin);
//	freopen(task".OUT", "w", stdout);
//	freopen(task".in", "r", stdin);
//	freopen(task".out", "w", stdout);
	typetest = 0;
}

const int N = 2e5 + 2;
int m, n, k;
vector<int> ker[N], kel[N];
int ltr[N], ltl[N];

void Enter(){
	read(n); read(m); read(k);
	while(m--){
		int a, b;
		read(a); read(b);
		ker[a].pb(b);
		ker[b].pb(a);
	}
	while(k--){
		int a, b;
		read(a); read(b);
		kel[a].pb(b);
		kel[b].pb(a);
	}
}

void BFS(int i, int lt[], vector<int> ke[]){
	++m;
	lt[i] = m;
	queue<int> open;
	open.push(i);
	while(open.size()){
		int c = open.front();
		open.pop();
		for(auto i : ke[c]){
			if((!lt[i]))
				open.push(i), lt[i] = m;
		}
	}
}

void solve(){
	m = 0;
	for(int i = 1; i <= n; ++i)
		if(ltr[i] == 0)
			BFS(i, ltr, ker);
	m = 0;
	for(int i = 1; i <= n; ++i)
		if(ltl[i] == 0)
			BFS(i, ltl, kel);
	map<int, map<int, int> > s;
	for(int i = 1; i <= n; ++i){
		++s[ltr[i]][ltl[i]];
//		cerr << ltr[i] << " " << ltl[i] << "\n";
	}
	for(int i = 1; i <= n; ++i){
		int& v = s[ltr[i]][ltl[i]];
		cout << v << " ";
	}
}

signed main(){
	fastIOfileinput();
	if(typetest){
		int t;
		cin >> t;
		int v = t;
		while(t--){
			Enter();
			cout << "Case #" << v - t << ": ";
			solve();
		}
	}
	else{
		Enter();
		solve();
	}
}

#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
struct node{int to,nxt;}sq[400200];
int all=0,head[200100],ans[200100];
int n,m1,m2,cnt=0;
pii col[200100];
bool vis[200100];
map<pii,int> mp;

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

void add(int u,int v)
{
	all++;sq[all].to=v;sq[all].nxt=head[u];head[u]=all;
}

void dfs(int u,int op)
{
	if (op==0) col[u].fir=cnt;else col[u].sec=cnt;
	vis[u]=1;
	go(u,i)
	{
		int v=sq[i].to;
		if (!vis[v]) dfs(v,op);
	}
}

void init(int m,int op)
{
	all=cnt=0;
	memset(head,0,sizeof(head));
	memset(vis,0,sizeof(vis));
	rep(i,1,m)
	{
		int u=read(),v=read();
		add(u,v);add(v,u);
	}
	rep(i,1,n)
		if (!vis[i]) {cnt++;dfs(i,op);}
}

int main()
{
	n=read();m1=read();m2=read();
	init(m1,0);init(m2,1);
	rep(i,1,n) mp[col[i]]++;
	rep(i,1,n) ans[i]=mp[col[i]];
	rep(i,1,n) printf("%d ",ans[i]);
	return 0;
}


#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

using s64 = int64_t;

constexpr s64 INF = 1'010'000'000'000'000'000LL;

template<typename T, typename U>
bool chmin(T& xmin, const U& x)
{
    if(x < xmin) {
        xmin = x;
        return true;
    }
    else {
        return false;
    }
}

#define FOR(i, start, end) for(s64 i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

s64 N;
s64 M;
vector<vector<s64>> G;

void print_g() {
    REP(i, N) {
        REP(j, N) {
            s64 c = G[i][j];
            if(c == INF)
                cout << "INF";
            else
                cout << c;
            cout << (j==N-1 ? '\n' : ' ');
        }
    }
}

void floyd() {
    REP(k, N) {
        REP(i, N) {
            if(G[i][k] == INF) continue;
            REP(j, N) {
                if(G[k][j] == INF) continue;
                chmin(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
}

void solve() {
    floyd();

    REP(i, N) {
        if(G[i][i] < 0) {
            cout << "NEGATIVE CYCLE\n";
            return;
        }
    }

    print_g();
}

int main() {
    cin >> N;
    G.assign(N, vector<s64>(N, INF));
    REP(i, N) { G[i][i] = 0; }

    cin >> M;
    REP(_, M) {
        s64 a, b, c; cin >> a >> b >> c;
        G[a][b] = c;
    }

    solve();

    return 0;
}

/**
 * All Pairs Shortest Paths (全点間最短パス)
 *
 * O(|E||V| + |V|^2 log|V|)
 */

/**
 * Feasible Potential
 *
 * O(|E||V|)
 */

#include <vector>
#include <algorithm>
using namespace std;

using Int = long long;
struct edge{
    int to;
    Int cost;
};

vector<Int> Potential(const vector<vector<edge>>& G){
    vector<Int> dist(G.size(),0);
    for(int i = 1;i < G.size();i++){
        for(int v = 0;v < G.size();v++){
            for(auto & e : G[v]){
                dist[e.to] = min(dist[e.to],dist[v] + e.cost);
            }
        }
    }
    for (int v = 0; v < G.size(); v++) {
      for (auto &e : G[v]) {
          if(dist[e.to] > dist[v] + e.cost){
              return vector<Int>();
          }
      }
    }
    return dist;
}

/**
 * Potential Dijkstra
 *
 * O(|E| + |V|log|V|)
 */

#include <functional>
#include <queue>
#include <set>
#include <vector>
using namespace std;

Int INF = 1LL << 40;
using Pii = pair<Int, int>;

vector<Int> Potential_Dijkstra(const vector<vector<edge>> &G, const vector<Int> &pot,int s) {
  vector<Int> dist(G.size(), INF);
  dist[s] = 0;
  priority_queue<Pii, vector<Pii>, greater<Pii>> que;
  que.emplace(dist[s], s);
  while (!que.empty()) {
    auto d = que.top().first;
    auto v = que.top().second;
    que.pop();
    if (dist[v] < d)
      continue;
    for (auto &e : G[v]) {
      Int co = e.cost + pot[v] - pot[e.to];
      if (dist[e.to] > d + co) {
        dist[e.to] = d + co;
        que.emplace(dist[e.to], e.to);
      }
    }
  }
  return dist;
}

vector<vector<Int>> AllPairsShortestPaths(const vector<vector<edge>> &G){
    vector<vector<Int>> res(G.size());
    auto pot = Potential(G);
    if(pot.empty()) return vector<vector<Int>>();
    for(int s = 0;s < G.size();s++){
        res[s] = Potential_Dijkstra(G,pot,s);
        for(int t = 0;t < G.size();t++){
          if(res[s][t] == INF) continue;
          res[s][t] += pot[t] - pot[s];
        }
    }
    return res;
}

#include <iostream>

int main(){
  int v,e;
  cin >> v >> e;
  vector<vector<edge>> G(v);

  for(int i = 0;i < e;i++){
    int s,t;
    Int d;
    cin >> s >> t >> d;
    G[s].push_back({t,d});
  }

  auto res = AllPairsShortestPaths(G);

  if(res.empty()){
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }

  for(auto & d : res){
    for(int i = 0;i < G.size();i++){
      if(d[i] == INF) cout << "INF";
      else cout << d[i];
      cout << " \n"[i + 1 == G.size()];
    }
  }
}