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

typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef array<int,2> aii;
typedef array<int,3> aiii;
typedef array<int,4> aiiii;
typedef unsigned long long ull;
typedef long long int ll;
typedef array<ll,2> all;
typedef array<ll,3> alll;
typedef array<ll,4> allll;

#define pb push_back
#define ff first
#define ss second
#define MAX 1000005
#define MOD 1000000007
#define INF 1e9+100
vector<int>adj[MAX];
int xMove[] = { 0,1,0,-1,1,1,-1,-1, 2, 2, -2, -2, 1, 1, -1, -1 };
int yMove[] = { 1,0,-1,0,1,-1,1,-1, 1, -1, 1, -1, 2, -2, 2, -2 };

void add_edge(int a, int b, int c, int d, int n)
{
    int u=(a-1)*n+b,v=(c-1)*n+d;
    adj[u].pb(v);
    adj[v].pb(u);
}

int dist[MAX];

void bfs(int s)
{
    memset(dist,-1,sizeof dist);

    queue<int> q;
    q.push(s);
    dist[s]=0;

    while(!q.empty())
    {
        int u=q.front();
        q.pop();

        for(int v: adj[u])
        {
            if(dist[v]==-1)
            {
                dist[v]=dist[u]+1;
                q.push(v);
            }
        }
    }
}

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
    cin.tie(0),cout.tie(0);
    ios_base::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);
    int TC=1;
    int n,m,k,q;
    //cin>>TC;
    for(int t1=1; t1<=TC; t1++)
    {
        cin>>n>>m;
        vector<aiii> edges(m);
        int mp[n*n+1];
        memset(mp,-1,sizeof mp);
        for(auto &[u,v,c]: edges)
        {
            char c1;
            cin>>u>>v>>c1;
            c=c1;
            mp[(u-1)*n+v]=1;
            mp[(v-1)*n+u]=1;
        }

        for(auto [a,b,c1]: edges)
        {
            for(auto [c,d,c2]: edges)
            {
                if(c2==c1)
                {
                    add_edge(a,c,b,d,n);
                    add_edge(c,a,d,b,n);
                    add_edge(a,d,b,c,n);
                    add_edge(d,a,c,b,n);
                }
            }
        }

        bfs(n);
        int mn=INF;
        for(int i=1;i<=n*n;i++)
        {
            if(dist[i]!=-1)
            {
                int r=i%n;
                int d=(i-r)/n;
                if(d+1==r)
                    mn=min(mn,2*dist[i]);
                else if(mp[i]==1)
                    mn=min(mn,2*dist[i]+1);
            }
        }

        cout<<(mn==INF?-1:mn)<<endl;
    }

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

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

const char newl = '\n';

template <typename T>
void dijkstra(int s,vector<vector<pair<int,T>>>& edges,vector<T>& dist) {
    priority_queue<pair<T,int>,vector<pair<T,int>>,greater<pair<T,int>>> que;
    dist[s] = 0;
    que.push(make_pair(0,s));
    while (!que.empty()) {
        pair<ll,int> p = que.top();
        que.pop();
        int v =  p.second;
        if (dist[v] < p.first) continue;
        for (pair<int,T>& e : edges[v]) {
            if (dist[e.first] > dist[v]+e.second) {
                dist[e.first] = dist[v]+e.second;
                que.push(make_pair(dist[e.first],e.first));
            }
        }
    }
}

int main() {
    int n,m;
    cin >> n >> m;
    vector<P> a[26];
    for (int i = 0;i < m;++i) {
        int u,v;char c;
        cin >> u >> v >> c;
        a[c-'a'].push_back(make_pair(u-1,v-1));
    }
    vector<vector<P>> edges(n*n);
    for (int c = 0;c < 26;++c) {
        for (int i = 0;i < a[c].size();++i) for (int j = 0;j < a[c].size();++j) {
            P &p = a[c][i];
            P &q = a[c][j];
            edges[p.first*n+q.first].push_back(make_pair(p.second*n+q.second,1));
            edges[p.second*n+q.second].push_back(make_pair(p.first*n+q.first,1));
            edges[p.second*n+q.first].push_back(make_pair(p.first*n+q.second,1));
            edges[p.first*n+q.second].push_back(make_pair(p.second*n+q.first,1));
        }
    }
    vector<int> dist(n*n,1e9);
    dijkstra<int>(n-1,edges,dist);
    cout << (dist[(n-1)*n] < 1e9 ? dist[(n-1)*n] : -1) << newl;
}


#include<bits/stdc++.h>
#define mxn 100005
#define inf 1e9
using namespace std;
int n, mem[mxn][26];
char str[mxn];
int dp(int pos, int ch)
{
    if(pos==n)return inf;
    if(pos==n-1 && (str[n-1]-'a')!=ch)return 1;
    int &ret= mem[pos][ch];
    if(ret!=-1)return ret;

    ret= dp(pos+1, ch);
    if((str[pos]-'a')!=ch)ret= min(ret, 1+dp(pos+2, str[pos+1]-'a'));
    return ret;
}
int main()
{
    scanf("%d %s", &n, str);
    memset(mem, -1, sizeof mem);
    int res= dp(1, str[0]-'a');
    if(res==inf)res= -1;
    printf("%d\n", res);

    return 0;
}

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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

template<typename T, typename U>
ostream& operator<<(ostream& o, const pair<T,U>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}

template<typename T, typename U>
ostream& operator<<(ostream& o, const map<T,U>& m) {
  o << "{";
  for (const pair<T,U>& p : m)
    o << p.first << ": " << p.second << ",";
  return o << "}";
}

template<typename T>
ostream& operator<<(ostream& o, const set<T>& s) {
  o << "{";
  for (const T& e : s)
    o << s << ",";
  return o << "}";
}

template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (const T& x : v)
    o << x << ",";
  return o << "]";
}

template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T>>& v) {
  o << "[";
  for (const vector<T>& x : v)
    o << x << ",\n";
  return o << "]";
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

    int n;
    string s;
    cin >> n >> s;

    if (s[0] != s[n-1]) {
        cout << "1\n";
        return 0;
    }
    for (int i=1; i<n-2; ++i) {
        if (s[0] != s[i] && s[i+1] != s[n-1]) {
            cout << "2\n";
            return 0;
        }
    }
    cout << "-1\n";
}


#include<iostream>
using namespace std;

int main(){
    int a,b,c,d,l,m,n,o,p;
    cin>>a>>b;
    cin>>c>>d;
    l=a-c;
    m=b-c;
    n=a-d;
    o=b-d;
    int max=l;

    if(m>max){
        max=m;
    }
    if(n>max){
        max=n;
    }
    if(o>max){
        max=o;
    }
    cout<<max;

  return 0;
}

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

/*#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 oset_find(k) find_by_order(k)
#define oset_order(k) order_of_key(k)*/

using ll = long long;
using db = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define ROF(i, a, n) for(int i=(n)-1;i>=(a);--i)

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
constexpr int pct(int x) { return __builtin_popcount(x); }

template<typename T> bool fmin(T& a, const T& b) { return b<a?a=b,1:0; }
template<typename T> bool fmax(T& a, const T& b) { return a<b?a=b,1:0; }

#define ts to_string
string ts(char c) { return '\'' + string(1, c) + '\''; }
string ts(const char* s) { return (string)s; }
string ts(const string& s) { return '"' + s + '"'; }
string ts(bool b) { return (b ? "true" : "false"); }

string ts(vector<bool> v) {
    string res = "{";
    FOR(i, 0, sz(v))
        res += char('0' + v[i]);
    res += "}";
    return res;
}

template <size_t SZ> string ts(bitset<SZ> b) {
    string res = "";
    FOR(i, 0, SZ)
        res+=char('0'+b[i]);
    return res;
}

template <typename A, typename B> string ts(pair<A, B> p);
template <typename A> string ts(A v) {
    bool first = 1; string res = "{";
    for (const auto& x: v) {
        if (!first) res += ", ";
        first = 0; res += ts(x);
    }
    res += "}"; return res;
}

template <typename A, typename B> string ts(pair<A, B> p) {
    return "(" + ts(p.fi) + ", " + ts(p.se) + ")";
}

void dbg_out() { cerr << "]" << endl; }
template <typename H, typename... T> void dbg_out(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    dbg_out(t...);
}
#ifdef LOCAL
    #define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)
#else
    #define dbg(...) 0
#endif

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

//const ll MOD = 1000000007; //998244353;
//const ll INF = LLONG_MAX;
//const db PI = 3.14159265358979323846;

ll n;
ll a[200005];

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << b - c;
}

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

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


#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
using namespace std;

int n,i,j,k,l,tot;
int ans[200001];
int a[200001];
bool bz[200001];

void swap(int &x,int &y) {int z=x;x=y;y=z;}
void Exit()
{
    printf("-1\n");
    exit(0);
}

int main()
{
#ifdef file
    freopen("c.in","r",stdin);
#endif

    scanf("%d",&n);
    fo(i,1,n) scanf("%d",&a[i]);

    l=1;
    fo(i,1,n)
        if (a[i]==l && i>l)
        {
            fd(j,i-1,l)
                if (!bz[j])
                    bz[j]=1,swap(a[j],a[j+1]),ans[++tot]=j;
                else
                    Exit();

            while (l<=n && a[l]==l) ++l;
            if (l>n) break;
        }
    fo(i,1,n-1) if (a[i]>a[i+1]) Exit();

    if (tot<n-1) Exit();
    else
    {
        fo(i,1,n-1)
            printf("%d\n",ans[i]);
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(4e5)+10;
int n,fa[maxn],dis[maxn],dep[maxn];
vector<int> g[maxn];
int lg[maxn];
int mx,son[maxn];
void dfs(int u,int p) {
	dis[u]=dis[p]+1; fa[u]=p;
	for (int v : g[u]) if (v!=p) dfs(v,u);
	if (!mx||dis[u]>dis[mx]) mx=u;
}
int st[maxn][20];
int dfn[maxn],tot,idx,euler[maxn],pos[maxn],ans[maxn];
void dfs2(int u,int p) {
	dfn[++idx]=u;
	for (int v : g[u]) if (v!=p&&v!=son[u]) dfs2(v,u);
	if (son[u]) dfs2(son[u],u);
}
int MN(int x,int y) {
    if (dep[x]<dep[y]) return x;
    return y;
}
int lca(int x,int y) {
    x=pos[x],y=pos[y];
    if (x>y) swap(x,y);
    int j=lg[y-x+1];
    return MN(st[x][j],st[y-(1<<j)+1][j]);
}
int DIS(int x,int y) {
    return dep[x]+dep[y]-2*dep[lca(x,y)];
}
void pre(int u,int p) {
    dep[u]=dep[p]+1;
    euler[++tot]=u; pos[u]=tot;
    for (int v : g[u]) if (v!=p) {
        pre(v,u);
        euler[++tot]=u;
    }
}
int main() {
	//freopen("1.txt","r",stdin);
    for (int i=2;i<maxn;i++) lg[i]=lg[i>>1]+1;
	read(n); int x,y,z;
	for (int i=1;i<n;i++) {
		read(x),read(y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	pre(1,0);
	for (int i=1;i<=tot;i++) st[i][0]=euler[i];
    for (int j=1;j<=19;j++)
    for (int i=1;i+(1<<j)-1<=tot;i++)
        st[i][j]=MN(st[i][j-1],st[i+(1<<(j-1))][j-1]);
	mx=0; dfs(1,0); x=mx;
	mx=0; dfs(x,0); y=mx;
	z=y;
	while (fa[z]) son[fa[z]]=z,z=fa[z];
	dfs2(x,0);
	ans[x]=1;
	for (int i=2;i<=n;i++)
		ans[dfn[i]]=ans[dfn[i-1]]+DIS(dfn[i],dfn[i-1]);
	for (int i=1;i<=n;i++) printf("%d ",ans[i]); puts("");
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?

  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?

  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vvi vector<vector<int>>
#define mi  map<int,int>
#define mii map<pii,int>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(x) (int)x.size()
#define all(v) (v).begin(), (v).end()
#define ret(x) return cout<<x,0;
#define rety return cout<<"Yes",0;
#define retn return cout<<"No",0;
#define fl fflush(stdout)
#define hell 1000000007
#define hell2 998244353
#define pi 3.14159265358979323846
#define piii pair<pii,int>
int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=ans*a%m; b/=2;a=a*a%m;}return ans;}
int inverse(int a, int p){return fexp(a, p-2,p);}

int fac[300005]; //fac[0]=0;fac[1]=1;rep(i,2,300005)fac[i]=(fac[i-1]*i)%hell;

int ncr(int n, int r,int p) {
    if (r==0) return 1;
    return (fac[n]*inverse(fac[r],p)%p*inverse(fac[n-r],p)%p)%p;
}

bool sortby(piii &a,piii &b){
    if(a.ff.ff==b.ff.ff)return (a.ff.ss<b.ff.ss);
    return (a.ff.ff<b.ff.ff);
    if(a.ss==b.ss)return (a.ff<b.ff);
    return (a.ss<b.ss);
}

int solve(){
    int n,m,a;
    cin>>n>>m;
   // if(m==0)ret(1);
    vi v;
    v.pb(0);
    rep(i,0,m){
        cin>>a;
        v.pb(a);
    }
    sort(all(v));
    v.pb(n+1);
    int g=1e18;
    rep(i,1,sz(v)){
        //cout<<v[i]-v[i-1]-1<<" ";
        if(v[i]!=v[i-1]+1)
        g=min(g,v[i]-v[i-1]-1);
    }
    int ans=0;//ret(g);
    rep(i,1,sz(v)){
        ans+=((v[i]-v[i-1]-1+g-1)/g);
    }
    cout<<ans;
    return 0;
}

signed main(){
    auto start = high_resolution_clock::now();
    IOS;
    int t=1;

    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cerr<<"Time taken:"<<duration.count()/1000000.0<<"seconds"<<"\n";
    return 0;
}

/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#pragma GCC optimize(2)
#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

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

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 102;
int n, k, P, ans[N], lim;
int f[N][N*N*N/2], sum[N*N*N/2];
inline void add(int &x, int y) { x += y, x >= P && (x -= P); }
void work(void) {
	f[0][0] = 1;
	for (int i = 1;i <= n; i++) {
		lim += i * k;
		for (int j = 0;j <= lim; j++)
			sum[j] = (f[i-1][j] + (j >= i ? sum[j-i] : 0)) % P;
		for (int j = lim;j >= 0; j--)
			f[i][j] = sum[j], j >= (k + 1) * i && (add(f[i][j], P - sum[j - (k + 1) * i]), 0);
	}
}

int main() {
	read(n), read(k), read(P), work();
	for (int i = 1;i <= n; i++) {
		ll ans = k;
		for (int t = 1;t <= lim; t++)
			ans = (ans + (ll)(k + 1) * f[i-1][t] % P * f[n-i][t]) % P;
		write(ans);
	}
	return 0;
}

/*

100 100 998244353

*/


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int) x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)

using ll = long long;
using ld = long double;
using namespace std;

int n, k, MOD = 998244353;
ll res;

int f(int x) {
	if (2 * n < x) return 0;
	if (x - 1 <= n)	return x - 1;
	return 2 * n - x + 1;
}

int main() {
	scanf("%d%d", &n, &k);
	rep(s, 2, 2 * n) {
		int s2 = s - k;
		if (s2 <= 1) continue;
		res += 1LL * f(s) * f(s2);
	}
	printf("%lld\n", res);
}

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

class BinaryIndexedTree{
private:
    const int N;
    vector<int> a;

public:
    BinaryIndexedTree(const int& N): N(N){
        a.resize(N + 1, 0);
    }

    void add(const int& POS, const int& VAL){
        for(int i = POS; i <= N; i += i - (i & (i - 1))){
            a[i] += VAL;
        }
    }

    int query(const int& POS){
        int sum = 0;
        for(int i = POS; i >= 1; i &= (i - 1)){
            sum += a[i];
        }
        return sum;
    }

    int query(const int& L, const int& R){
        if(L > R){
            return 0;
        }
        return query(R) - query(L - 1);
    }
};

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

    int N;
    cin >> N;

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

    long long inversions = 0;
    BinaryIndexedTree tree(N);
    for(int i = 1; i <= N; ++i){
        inversions += tree.query(a[i] + 1, N);
        tree.add(a[i], 1);
    }

    cout << inversions << "\n";
    for(int i = 1; i <= N - 1; ++i){
        inversions -= (a[i] - 1);
        inversions += (N - a[i]);
        cout << inversions << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 100001
#define INF 1000000000000000000
#define MOD 1000000007

int main(){
  vector<int> A(3);
  for(int i=0;i<3;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  if(A[2]-A[1]==A[1]-A[0]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

/*
	JAI JAGANNATH!
*/
//@Author : zanj0

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

#define int 			long long int

#define ff              first
#define ss              second
#define pb              push_back
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl       		"\n"
#define timetaken cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n"

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void solve() {
	vector <int> v(3);
	for (int i = 0, x; i < 3; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	if (v[0] == v[1]) {
		cout << v.back() << endl;
	} else if (v[1] == v.back()) {
		cout << v[0] << endl;
	} else {
		cout << 0 << endl;
	}

}
int32_t main()
{
	zanj0();
	solve();
	timetaken;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.14159265
ll mod1=1000000007;
// bool comp(pair<ll,ll>a,pair<ll,ll>b)
// {
//    // if(a.second==b.second)
//    //  return a.first<b.first;
//   // else
//     return a.second<b.second;

// }
// sort(a.begin(),a.end(),greater<int>());
// priority_queue<int, vector<int>, greater<int> > Q;
// vector<ll> factorial(1001,1);
// vector<ll> inv_factorial(1001);
// vector<vector<ll> > combi(1001,vector<ll>(1001));
// ll binpow(ll a, ll b)
// {
//     ll res = 1;
//     while (b > 0) {
//         if (b & 1)
//             res = res * a;
//         a = a * a;
//         b >>= 1;
//     }
//     return res;
// }

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

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

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

// bool comp(ll a, ll b)
// {
//     return a>b;
// }

// ll inversemod(ll a, ll mod)
// {
//     return binpow(a,mod-2, mod);
// }
// for(int i=1;i<=1000;i++) factorial[i]=(factorial[i-1]*i)%mod1;

//   for(int i=0;i<=1000;i++) inv_factorial[i]=inversemod(factorial[i],mod1);

//   for(int i=0;i<=1000;i++)
//   {
//     for(int j=0;j<=i;j++)
//     {
//       combi[i][j]=(((factorial[i]*inv_factorial[i-j])%mod1)*inv_factorial[j])%mod1;
//     }
//   }
// ll t[4*20001]
// void build(ll a[], ll v, ll tl, ll tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = t[v*2] ^ t[v*2+1];
//     }
// }
// void dfs(ll i,ll *visited,vector<ll> e[])
// {
//   visited[i]=1;
//   ll n=e[i].size();
//   for(ll j=0;j<n;j++)
//   {
//     if(visited[e[i][j]]==0)
//       dfs(e[i][j],visited,e);
//   }
// }

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   ll test;
   // cin>>test;
   test=1;
   for(ll ftest=0;ftest<test;ftest++)
   {
      ll n,i,j;
      cin>>n;
      ll A[n];
      ll dp[n+1];
      dp[0]=1;
      dp[1]=1;
      for(i=2;i<=n;i++)
         dp[i]=(dp[i-1]+dp[i-2])%mod1;
      ll ans=0;
      for(i=0;i<n;i++)
      {
         cin>>A[i];
         ans=(ans+((((A[i]*dp[i])%mod1)*dp[n-i])%mod1))%mod1;
         if(i!=0)
            ans=(ans-((((A[i]*dp[i-1])%mod1)*dp[n-i-1])%mod1))%mod1;
         ans=(ans%mod1+mod1)%mod1;
         // ans=(ans+x)%mod1;
      }
      cout<<ans<<'\n';
   }
}


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

#define debug(x) cout << #x << " is " << x << endl
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;

int t, n;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> t;
	while (t--) {
		cin >> n;
		vector<int> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i]; a[i]--;
		}
		vector<int> ans;
		for (int i = 0; i < n; ++i) {
			int j = find(a.begin(), a.end(), i) - a.begin();
			if (i == j) continue;
			if (j % 2 == (int)ans.size() % 2) {
				if (j >= i + 2) {
					ans.push_back(j - 2);
					swap(a[j-2], a[j-1]);
				}
				else {
					ans.push_back(i - 1);
					ans.push_back(i);
					ans.push_back(i - 1);
					ans.push_back(i);
					ans.push_back(i - 1);
					swap(a[i], a[j]);
					continue;
				}
			}
			for (int k = j - 1; k >= i; --k) {
				ans.push_back(k);
				swap(a[k], a[k+1]);
			}
		}
		cout << ans.size() << '\n';
		for (int i = 0; i < (int)ans.size(); ++i) {
			cout << ans[i] + 1 << ' ';
		}
		cout << '\n';
	}
    return 0;
}

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

#define pb push_back
#define FOR(i,f,n) for(int i=f;i<n;i++)
#define FORI(i,f,n) for(int i=f;i>=n;i--)
#define sz(a) ((int)(a).size())
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define alli(a) (a).rbegin(),(a).rend()
#define approx(a) fixed<<setprecision(a)
#define trav(a,x) for(auto& a : x)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,bool> pib;
typedef pair<ll,bool> plb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T> void ckmin(T &a, const T &b) { a = min(a, b); }
template <class T> void ckmax(T &a, const T &b) { a = max(a, b); }

template <class T> void read(vector<T> &v);
template <class F, class S> void read(pair<F, S> &p);
template <class T> void read(T &x) {cin>>x;}
template <class R, class... T> void read(R& r, T&... t){read(r); read(t...);};
template <class T> void read(vector<T> &v) {trav(x, v) read(x);}
template <class F, class S> void read(pair<F, S> &p) {read(p.ff, p.ss);}

template <class F, class S> void pr(const pair<F, S> &x);
template <class T> void pr(const T &x) {cout<<x;}
template <class R, class... T> void pr(const R& r, const T&... t) {pr(r); pr(t...);}
template <class F, class S> void pr(const pair<F, S> &x) {pr("{", x.ff, ", ", x.ss, "}");}
void ps() {pr("\n");}
template <class T> void ps(const T &x) {pr(x); ps();}
template <class T> void ps(vector<T> &v) {trav(x, v) pr(x, ' '); ps();}
template <class F, class S> void ps(const pair<F, S> &x) {pr(x.ff, ' ', x.ss); ps();}
template <class R, class... T> void ps(const R& r, const T &...t) {pr(r, ' '); ps(t...);}

const int MXN = 2e5+1;
vi adj[MXN], level[MXN], in(MXN), out(MXN);
int timer = 0;

void dfs(int v, int d){
    in[v] = ++timer;
    level[d].pb(in[v]);
    for(int u : adj[v]){
        dfs(u, d+1);
    }
    out[v] = ++timer;
}

void solve(){
    int n; read(n);
    FOR(i,1,n){
        int x; read(x);
        adj[x].pb(i+1);
    }
    dfs(1, 0);
    int q; read(q);
    FOR(i,0,q){
        int u, d; read(u, d);
        int ans = lower_bound(all(level[d]), out[u]) - lower_bound(all(level[d]), in[u]);
        ps(ans);
    }
}

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


#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define sz(v) (int)v.size();
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b){ll res=1;a=a%mod; while(b){if(b&1)res=(res*a)%mod; a=(a*a)%mod;b/=2;}return res;}
ll invmod(ll a){return power(a,mod-2);}
ll  h,w,a,b;
ll dp[17][17];
int solve(int r,int c,int i,int j){
	if(i<0||j<0) return 0;

	if(c>=w){
		c=0;
		r++;
	}

	if(dp[r][c]) return solve(r,c+1,i,j);

	if(r==h) return 1;
	ll ans = solve(r,c+1,i,j-1);

	dp[r][c]=1;

	if(c+1<w && dp[r][c+1]==0) {
		dp[r][c+1]=1;
		ans += solve(r,c+2,i-1,j);
		dp[r][c+1]=0;
	}
	if(r+1<h && dp[r+1][c]==0){
		dp[r+1][c]=1;
		ans+=solve(r,c+1,i-1,j);
		dp[r+1][c]=0;
	}
	dp[r][c]=0;
	return ans;
}
int main(void)
{
	FIO
	cin>>h>>w>>a>>b;
	cout<<solve(0,0,a,b);
	return 0;
}

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

int main(void){

    long long nCr[61][61]={};//0で初期化

    nCr[0][0]=1;
    for(int i=1;i<=60;i++){
        for(int j=0;j<=i;j++){
            if(j!=0){
                nCr[i][j] += nCr[i-1][j-1];
            }
            if(j!=i){
                nCr[i][j] += nCr[i-1][j];
            }
        }
    }

    long long A,B,K;
    cin >> A >> B >> K;

    string S;
    long long C = A+B;

    for(int i=0;i<C;i++){

        //aがA個、bがB個ある
        //前から(A+B-1)C(A-1)個は先頭がa
        //その範囲に入った場合、a+((A+B-1)C(A-1)個中前からK個目)が答え
        //そうでなければ、b+((A+B-1)C(A)個中前からK-(A+B-1)C(A-1)個目)が答え
        if(A!=0 && K <= nCr[A+B-1][A-1]){
            S.push_back('a');
            A--;
        }else{
            S.push_back('b');
            K -= nCr[A+B-1][A-1];
            B--;
        }
    }

    cout << S << endl;

    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define p_q priority_queue
#define m_p make_pair
#define pb push_back
#define ld long double
#define F first
#define S second
#define ull unsigned long long
#define mod 1000000007
#define md 998244353
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll qpow(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string iots(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int stoi(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int a,b,w;
int main()
{
	ios::sync_with_stdio(0);
	cin>>a>>b>>w;
	w*=1000;
	bool f=0;
	forn(i,1,w)
	{
		if((ld)w/(ld)i<=(ld)b&&(ld)w/(ld)i>=(ld)a)
		{
			f=1;
		}
	}
	if(!f)
	{
		cout<<"UNSATISFIABLE\n";
		return 0;
	}
	cout<<(w+b-1)/b<<" "<<w/a<<endl;
	return 0;
}
//特判判全
//循环边界
//精度足够
//注意初值

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

void solution()
{
  double s, e, w;
  cin >> s >> e >> w;
  w *= 1000;
  int end = floor(w / (double)s);
  int start = ceil(w / (double)e);
  int first = -1, last = -1;
  bool flag = true;
  for(int i = start; i <= end; i++)
  {
    if(w / w * w == w)
    {
      if(flag)
      {
        first = i;
        flag = false;
      }
      last = i;
    }
  }
  if(first < 0)
  {cout << "UNSATISFIABLE" << endl;}
  else
  {cout << first << " " << last << endl;}
  return;
}

int main()
{
  int count, counter = 0;
  count = 1;
  while(counter++ < count)
  {solution();}
  return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  sort(a,a+n);
  int flag = 1;
  for(int i=0;i<n;i++)
  {
    if(a[i] != i+1)
    {
      cout<<"No"<<endl;
      flag = 0;
      break;
    }
  }
  if(flag == 1)
  {
    cout<<"Yes"<<endl;
  }
  return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}

const ll INF=1e18;
const int mx=200005;

//abc181

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n%2==0) out("White");
    else out("Black");
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
dpするときは「配る」、「もらう」の両方を考えて最適な方を選べ
Segtreeで区間最大(max)を使うとき,単位元の設定をしっかり
(デフォルトは-INF,0の方が都合の良い場合は変更)
*/


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

ll dp[1 << 20];

vector<int> pr = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};

int getmask(ll v) {
  int mask = 0;
  for (int i = 0; i < 20; i++) {
    if (v % pr[i] == 0) mask |= (1 << i);
  }
  return mask;
}

void solve() {
  ll a, b; cin >> a >> b;
  dp[0] = 1;
  for (ll v = a; v <= b; v++) {
    int mymask = getmask(v);
    for (int mask = 0; mask < (1 << 20); mask++) {
      if (mask & mymask) continue;
      dp[mask | mymask] += dp[mask];
    }
  }
  cout << accumulate(dp, dp + (1 << 20), 0ll);
}

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}

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

int main() {
    ll n,k;
    std::cin >> n>>k;

    string s;
    std::cin >> s;

    string next = s+s;

    for (int jjjj = 0; jjjj < k; jjjj++) {
        s = next;
        for (int i = 0; i < 2*n; i++) {
            char x;
            if(s[2*i%(2*n)]=='R'){
                if(s[(2*i+1)%(2*n)]=='P'){
                    x= 'P';
                }else{
                    x= 'R';
                }
            }else if(s[2*i%(2*n)]=='P'){
                if(s[(2*i+1)%(2*n)]=='S'){
                    x= 'S';
                }else{
                    x= 'P';
                }
            }else{
                if(s[(2*i+1)%(2*n)]=='R'){
                    x= 'R';
                }else{
                    x= 'S';
                }
            }
            next[i] =x;
        }
    }

    std::cout << next[0] << std::endl;
}


//Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;

//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}

// bool isOK(string X,ll base,ll M) {
//   ll sum = 0;
//   REP(i, X.size()) {
//     if (sum > M / base) {
//       return false;
//     }
//     sum *= base;
//     sum += (X.at(i) - '0');
//   }

//   if (sum <= M) {
//     return true;
//   } else {
//     return false;
//   }
// }

bool isOK(string X, ll key,ll M) {
    ll result=0,d = 1;

    for(ll i=X.size()-1;i >= 0;i--,d*=key){
        if (M/d < (X[i]-'0')) return false;
        if (result > M - (X[i]-'0')*d) return false;
        result += (X[i]-'0')*d;
        if(i >= 1){
            if(M/key < d){
                return false;
            }
        }
    }
    //cout << "result = " << result << "\n";
    if (result <= M) return true;
    else return false;
}

int main(){
    string X;
    ll M;
    ll max;

    cin >> X >> M;

    max = X[0] - '0';
    for (ll i = 1; i < (ll)X.size(); i++) {
        if (max < X[i] - '0') {
            max = X[i] - '0';
        }
    }
    ll left = M+10, right = max;
    ll mid=0;

    if(X.size()==1){
        if (X[0]-'0' <= M) cout << 1 << "\n";
        else cout << 0 << "\n";
        return 0;
    }

    while(left - right > 1){
        mid = (left + right) / 2;
        //cout << "L R = " << left << " " << right << "\n";
        //cout << "mid = " << mid << "\n";
        if(isOK(X,mid,M)) right = mid;
        else left = mid;
    }
    cout << right - max << "\n";
    return 0;
}

#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

void iosetup(void){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int get_d(string& X){
    int ret = 0;
    for (auto d : X)
        ret = max(ret, (int)(d - '0'));
    return ret;
}

constexpr ll INF = (1LL << 61);

ll n_num(string& X, ll n){
    ll ret = 0LL;
    for (auto d : X){
        if (ret > INF / n) return INF;
        ret = ret * n + (ll)(d - '0');
    }
    return ret;
}

ll solve(string& X, ll M){
    int d = get_d(X);
    if (n_num(X, d + 1) > M) return 0;
    ll ok = d + 1, ng = INF;
    while (ng - ok > 1){
        ll mid = (ok + ng) / 2;
        if (n_num(X, mid) > M) ng = mid;
        else ok = mid;
    }
    return (ng - d - 1);
}

int main(void){
    iosetup();
    string X;
    ll M;
    cin >> X >> M;
    if (X == "1") cout << 1 << endl;
    else if (X.length() == 1){
        ll Xi = (ll)(X[0] - '0');
        if (Xi <= M) cout << 1 << endl;
        else cout << 0 << endl;
    }
    else cout << solve(X, M) << endl;
    return 0;
}


#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define _ << ' ' <<
#define _n << '\n';
#define print(arr) for(int i : arr) cout << i << ' '; cout << '\n';

using namespace std;

pair<long long int,long long int> go(int pos, vector<int> &vec){
    if(pos == 0){
        if(vec[0]){
            return {1, 3};
        }
        else{
            return {3, 1};
        }
    }
    pair<long long int,long long int> p = go(pos-1, vec);
    if(vec[pos]){
        return {p.first, powl(2, pos+1) + p.second};
    }
    return {powl(2, pos+1) + p.first, p.second};
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    vector<int> vec;
    for(int i=0;i<n;++i){
        string str; cin >> str;
        if(str == "AND") vec.push_back(1);
        else vec.push_back(0);
    }
    cout << go(n-1, vec).first << '\n';
    return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define int long long
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MAXIN(x) max_element(ALL(x)) - x.begin();
#define MIN(x) *min_element(ALL(x))
#define MININ(x) min_element(ALL(x)) - x.begin();
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000  //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265358979323846

using namespace std;

#include <sstream>

using namespace std;

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim)) {
        if (!item.empty()) {
            elems.push_back(item);
        }
    }
    return elems;
}

signed main() {
    string an;
    cin >> an;
    cout << split(an, '.')[0] << endl;
}

// int M, H;
// cin >> M >> H;

// if(H%M == 0){
//     cout << "Yes" <<endl ;
// }else{
//     cout << "No" <<endl ;
// }


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

int main() {
  int n;
  double x, y;
  complex<double> a, b;

  cin >> n;
  cin >> x >> y;
  a = {x, y};
  cin >> x >> y;
  b = {x, y};

  auto m = (a + b) / 2.0;

  auto res = m + (a - m) * polar(1.0, M_PI * 2.0 / n);

  cout << fixed << setprecision(12) << res.real() << " " << res.imag() << endl;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

const ll INF_L = 1LL << 60;
const int INF_I = 1 << 30;
const int MOD = (int)1e9 + 7;
const double PI = acos(-1);
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int main()
{
    int n;
    cin >> n;
    complex<double> a, b;
    rep(i, 2)
    {
        double x, y;
        cin >> x >> y;
        if (!i)
            a = {x, y};
        else
            b = {x, y};
    }

    auto m = (a + b) / 2.0;
    auto res = m + (a - m) * polar(1.0, 2.0 * PI / n);

    printf("%.10f\n%.10f\n", res.real(), res.imag());
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
long t, N; cin >> t >> N;
long l=1, r=1e15;
while(r-l>1){
  long x=(l+r)/2;
  if(((100+t)*x)/100-x<N){ l=x; }else{ r=x; }
}
cout << ((100+t)*r)/100-1 << "\n";
}

#include <bits/stdc++.h>
using namespace std;
int main() {
	int64_t t, n;
	cin >> t >> n;
	if (100 * n % t == 0) {
		cout << n - 1 + 100 * n / t << endl;
	}
	else { cout << n + 100 * n / t ;}

}


#define ii pair<int , int>

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

const int N = 1e5 + 5;

vector<ii> edge[N];
int label[N];

bool check[N];

void dfs(int u)
{
    for (auto adj : edge[u])
    {
        int v = adj.first;
        int w = adj.second;

        if (label[v] == 0)
        {
            if (label[u] == w)
            {
                if (w == 1) label[v] = 2;
                else label[v] = 1;
            }
            else
            {
                label[v] = w;
            }
            dfs(v);
        }
    }
}

int main()
{
    // freopen(".inp","r",stdin);
    // freopen(".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    while(m--)
    {
        int u , v , w;
        cin >> u >> v >> w;
        edge[u].push_back(ii(v , w));
        edge[v].push_back(ii(u , w));
    }

    label[1] = 1;
    dfs(1);

    for (int i = 1 ; i <= n ; ++i) cout << label[i] << "\n";

}

#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
#include  <cstdio>
#include  <sstream>
#include  <bitset>
#include <fstream>
#include <ctime>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using Vii = vector<vector<int> >;
using Viii = vector<vector<vector <int> > >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll> >;
using Vlll = vector<vector<vector<ll> > >;
using Vdd = vector<vector<double> >;
using Vldd = vector<vector<ld> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Vbb = vector<vector<bool> >;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Pli = pair<ll, int>;
using VPi = vector<Pi>;
using VPl = vector<Pl>;
using VPli = vector<Pli>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;
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; }
const int MOD = static_cast<int>(1e9 + 7);
const ll MOD2 = 998244353;
const int INF = INT_MAX - 1000000;
const ll LINF = LLONG_MAX - 1000000;
const ll OLINF = ll(2) << 60;
const int OINF = 2 << 29;
const int dx[4] = { 0,-1,0,1 };
const int dy[4] = { -1,0,1,0 };
const int ddx[8] = { -1,-1,0,1,1,1,0,-1 };
const int ddy[8] = { 0,1,1,1,0,-1,-1,-1 };
struct edge { int to; ll cost; };
struct kedge { int u, v, cost; };

Vi C;
Vi Ans;
Vb visited;
set<int> S;
int Dep[100005] = { 0 };

void bfs(int u, Vii& G) {
	visited[u] = true;
	//cout << u << " " << C[u] << endl;
	if (S.find(C[u]) == S.end()) Ans.push_back(u);
	S.insert(C[u]);
	Dep[C[u]]++;
	for (int nu : G[u]) {
		if (visited[nu]) continue;
		bfs(nu, G);
	}
	if (Dep[C[u]] > 1) {
		Dep[C[u]]--;
	}
	else {
		S.erase(S.find(C[u]));
		Dep[C[u]] = 0;
	}
}

int main() {
	int n;
	cin >> n;
	C.resize(n);
	rep(i, n) cin >> C[i];

	Vii G(n);
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	visited.resize(n, false);
	bfs(0, G);

	sort(Ans.begin(), Ans.end());
	for (int A : Ans) {
		cout << A + 1 << endl;
	}
}


#include<iostream>
using namespace std;
int main(){
  int n,point,i;
  string str;
  cin>>n>>point>>str;
  for(i=0;i<n;i++){
    if(str[i]=='o') point++;
    else{
      if(point==0) continue;
      else point--;
      }
    }
  cout<<point<<endl;

  return 0;
  }

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll t; cin>>t; while(t--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
const ll MOD=1000000007;
int main(){
    TEZ;
    ll a,b,c;
    cin>>a>>b>>c;
    ll sum=21-(a+b+c);
    cout<<sum;
}


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

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
const int mod = 1e9 + 7;
const ll INF = 3e18;
const double EPSILON = 1e-9;
const int N = 2e5+5;
int dp[N][7]; // dp[i][j] : true if takahashi can get the remainder j on the i'th position
/* if x[i]=='T' takahashi needs only one chance to get the remainder to win, else takashi needs both chances to get the remainder
otherwise aoki will choose the other option to get a different remainder in order to takahashi loose
*/
int main(){
    fastio;
    int n, ten = 1;
    string s,x;
    cin >> n >> s >> x;
    dp[n][0] = 1;
    for(int i = n-1; i >= 0; i--){
        for(int j = 0; j < 7; j++){
            // append zero |& append s[i]
            if(x[i] == 'T'){
                dp[i][j] = dp[i+1][j] | dp[i+1][(j+(ten*(s[i]-'0')))%7];
            }else{
                dp[i][j] = dp[i+1][j] & dp[i+1][(j+(ten*(s[i]-'0')))%7];
            }
        }
        ten = (ten * 10) % 7;
    }
    cout << (dp[0][0]?"Takahashi":"Aoki") << "\n";
    return 0;
}
// DOES IT HAVE OVERFLOW ?
// DOES IT HAVE INVALID MEMO ACESS ?

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

int dp[200200][17][2];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	int t=-1;
	rep(i,n){
		int a,b,c;
		cin>>a>>b>>c;
		if(c-a>=1){
			if(t==-1||t>=b)t=b;
		}
	}
	cout<<t<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define Rep(i,j,n) for (ll i=(ll)(j);i<=(ll)(n);++i)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int mod = 998244353;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

/*
ll ti=clock();
cout<<("Execution Time: %.4lf sec", 1.0 * (clock() - ti) / CLOCKS_PER_SEC)<<endl;
*/

int main(){
  ll n;
  cin>>n;
  string s;
  cin>>s;
  ll q;
  cin>>q;
  ll count_2=0;
  ll m=2*n;
  rep(i,q){
      ll t,a,b;
      cin>>t>>a>>b;
      if(t==1){
          ll A,B;
          A=(a-1+n*(count_2%2))%m;
          B=(b-1+n*(count_2%2))%m;
        //   cout<<A<<" "<<B<<endl;//debug
          char tmp;
          tmp=s[A];
          s[A]=s[B];
          s[B]=tmp;
      }
      else{
          count_2++;
        //   cout<<"t1:"<<t1<<" t2:"<<t2<<endl;//debug
      }
    //   print(s);//debug
  }
  if(count_2%2==1){
      string t;
    t=s.substr(n,n);
    s.erase(n);
    s=t+s;
  }
  print(s);
}

#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
#include<cassert>
#include<stack>
#include <iterator>     // std::back_inserter
const double PI = acos(-1);
using namespace std;
using ll =long long;
#define rep(i,n)for(ll i=0;i<(n);i++)
const int mod = 1000000007;
const ll inf = 1e18 + 1;
//int ctoi(char c) {
//	if (c >= '0' && c <= '9') {
//		return c - '0';
//	}
//	return 0;
//}
//
ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
//ll lcm(ll a, ll b) {
//	return a * b / gcd(a, b);
//};
//fixed << setprecision(2)

///*Union Find*/
//#define MAX_N 200000
//#define MAX_M 200000
//vector<ll>par(MAX_N);
//vector<ll>ran(MAX_N);
//void init(ll N) {
//	rep(i, N) {
//		par[i] = i;
//		ran[i] = 0;
//	}
//}
//ll find(ll x) {
//	if (par[x] == x) {
//		return x;
//	}
//	else {
//		return par[x] = find(par[x]);
//	}
//}
//void unite(ll x,ll y) {
//	x = find(x);
//	y = find(y);
//	if (x == y)return;
//	if (ran[x] < ran[y]) {
//		par[x] = y;
//
//	}
//	else {
//		par[y] = x;
//		if (ran[x] == ran[y])ran[x]++;
//	}
//}
//bool same(ll x, ll y) {
//	return find(x) == find(y);
//}
////UnionFind

//dfs
//if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
//dfs

//桁和を求める
//ll digsum(ll n) {
//	ll res = 0;
//	while (n > 0) {
//		res += n % 10;
//		n /= 10;
//	}
//	return res;
//}
//桁和を求める
//cin,coutを早くする
//ios::sync_with_stdio(false);
//cin coutを早くする。

ll g1(ll s) {
	map<int, int>m;
	ll tmp = s;
	int n=1;
	tmp /= 10;
	while (tmp!=0) {
		tmp /= 10;
		n++;
	}
	//cout << n<<endl;
	rep(i, n) {
		ll b = s / pow(10, i);
		b %= 10;
		m[b]++;
	}
	ll x=0;
	for (int i = 9; i >= 0; i--) {
		while (true) {
			if (m[i] != 0) {
				x += i * pow(10, n-1);
				m[i]--;
				n--;
			}
			else {
				break;
			}
		}
	}
	return x;
}
ll g2(ll s) {
	map<int, int>m;
	ll tmp = s;
	int n = 1;
	tmp /= 10;
	while (tmp != 0) {
		tmp /= 10;
		n++;
	}
//	cout << n << endl;
	rep(i, n) {
		ll b = s / pow(10, i);
		b %= 10;
		m[b]++;
	}
	ll x = 0;
	for (int i = 0; i <= 9; i++) {
		while (true) {
			if (m[i] != 0) {
				x += i * pow(10, n - 1);
				m[i]--;
				n--;
			}
			else {
				break;
			}
		}
	}
	return x;

}
int main() {
	ios::sync_with_stdio(false);
	ll N, K;
	cin >> N >> K;
	ll a = N;
	rep(i, K) {
		a = g1(a) - g2(a);
	}
	cout << a;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<set>
using namespace std;

#define  ll             long long int
#define  ull            unsigned long long int
#define  ld             long double
#define  max3(a,b,c)    max(a,max(b,c))
#define  max4(a,b,c,d)  max(max3(a,b,c),d)
#define  min3(a,b,c)    min(a,min(b,c))
#define  min4(a,b,c,d)  min(min3(a,b,c),d)
vector<ll> v,w;
set<ll>s1;
map<ll,ll>mp;

long long mod = 1000000007;
int main()
{
  ll i,j=0,l,m,n,o,r,t,x,y,k,c=1;
  string s,p,q;
cin>>n;
ll a[n+1]={0};
for(i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
for(i=1;i<=n;i++){
c*=(a[i]-a[i-1]+1);
c%=mod;
}
cout<<c;
}

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
typedef unsigned long long ull;
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void sc(int &x){scanf("%d",&x);}
void sc(int &x,int &y){scanf("%d%d",&x,&y);}
void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void sc(ll &x){scanf("%lld",&x);}
void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);}
void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}
void sc(char *x){scanf("%s",x);}
void sc(char *x,char *y){scanf("%s%s",x,y);}
void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);}
void out(int x){printf("%d\n",x);}
void out(ll x){printf("%lld\n",x);}
void out(int x,int y){printf("%d %d\n",x,y);}
void out(ll x,ll y){printf("%lld %lld\n",x,y);}
void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);}
void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);}
using namespace std;
const int N=3e5+5,mod=1e9+7;
int n,a[N];
int main()
{
    //freopen("1.in","r",stdin);freopen("1.out","w",stdout);
    sc(n);
    rep(i,1,n) sc(a[i]);
    sort(a+1,a+1+n);
    ll ans=a[1]+1;
    rep(i,1,n-1)
        ans=ans*(a[i+1]-a[i]+1)%mod;
    out(ans);
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n, m;
    cin >> n >> m;
    vector <string> qw (n);
    for (int i=0; i<n; ++i)
    {
        cin >> qw[i];
    }
    long long t=0;
    for (int i=0; i<n; ++i)
    {
        for (int ii=0; ii<m; ++ii)
        {
            if (qw[i][ii]=='.')
            {
                if (i!=n-1 && qw[i+1][ii]=='.')
                    t+=1;
                if (ii!=m-1 && qw[i][ii+1]=='.')
                    t+=1;
            }
        }
    }
    cout << t << endl;
}

#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>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define sz(s) int64_t(s.size())
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())

const ll mod = 1e9 + 7;

template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

template<class T, class U>
void chkmax(T &a, U b) {
    a = max(a, (T)b);
    return;
}

template<class T, class U>
void chkmin(T &a, U b) {
    a = min(a, (T)b);
    return;
}

ll ppow (ll x, ll s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    ll b = ppow (x, s / 2);
    return (b * b) % mod;
}

vector<int> zf (string s) {

	int n = sz(s);

	vector<int> z (n);

	for (int i = 1, l = 0, r = 0; i < n; i++) {

		if (i <= r)
			z[i] = min (r - i + 1, z[i - l]);

		while (i + z[i] < n && s[z[i]] == s[i + z[i]])
			z[i]++;

		if (i + z[i] - 1 > r)
			l = i,  r = i + z[i] - 1;

	}

	return z;

}

vector<int> pf(string p) {
    int n = sz(p);
    vector<int> pref_fun(n, 0);

    for (int i = 1;i < n;i++) {
        int j = pref_fun[i - 1];
        while (j > 0 && p[i] != p[j])
            j = pref_fun[j - 1];
        if (p[i] == p[j])
            j++;
        pref_fun[i] = j;
    }
    return pref_fun;
}

vector<vector<int> > mul(vector<vector<int> > &a, vector<vector<int> > &b) {
    int n = sz(a);
    vector<vector<int> > c(n, vector<int> (n, 0));

    for (int i = 0;i < n;i++) {
        for (int j = 0;j < n;j++) {
            for (int k = 0;k < n;k++) {
                ll ga = a[i][k];
                ga *= b[k][j];
                ga %= mod;
                c[i][j] += ga;
                if (c[i][j] >= mod) {
                    c[i][j] -= mod;
                }
            }
        }
    }

    return c;
}

vector<vector<int> > matrix_pow(vector<vector<int> > a, ll y) {
    int n = sz(a);
    vector<vector<int> > res(n, vector<int> (n, 0));
    for (int i = 0;i < n;i++) res[i][i] = 1;
    while (y) {
        if (y%2 == 1) {
            res = mul(res, a);
            y--;
        }else {
            a = mul(a, a);
            y /= 2;
        }
    }
    return res;
}

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

    int a, b;
    cin >> a >> b;
    cout.precision(10);
    cout << fixed << 100 * (1 - (ld)b/a);

    return 0;
}


#include <iostream>
#include <cmath>

int main() {
    int x, y;
    std::cin >> x;
    std::cin >> y;
    std::cout << (std::abs(x-y) < 3 ? "Yes" : "No") << std::endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vp = vector<pii>;
using vvi = vector<vi>;
#define rep(i, a, b) for (int i = a; i < (int) (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (int) (b); i--)
#define fore(i_in, a) for (auto& i_in: a)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pq(T) priority_queue<T, vector<T>, greater<T>>
template<class T> void chmin(T &a, T b) { if (a > b) a = b; }
//template<class T> bool chmin(T& a, T b) {if (a > b) {a = b;return true;} else return false;}
template<class T> void chmax(T &a, T b) { if (a < b) a = b; }
//template<class T> bool chmax(T& a, T b) {if (a < b) {a = b;return true;} else return false;}
template<class T> void print(const T &t) { cout << t << "\n"; }

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

    int h, w; cin>>h>>w;
    if (abs(h-w) < 3) print("Yes");
    else print("No");
}


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

#define stp(var, init, end) for (auto var = init; var < end; ++var)
#define stpe(var, init, end) for (auto var = init; var <= end; ++var)
#define ll long long

int main(void)
{
    int n;
    cin >> n;
    cout << n - 1;
    return 0;
}

#include<iostream>
using namespace std;
long long n;
void solve()
{
    cout<<n-1<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

struct unionfind
{
    vector<long long> d;

    unionfind(long long n) : d(n, -1) {}

    long long root(long long x)
    {
        if (d[x] < 0)
        {
            return x;
        }
        else
        {
            return d[x] = root(d[x]);
        }
    }

    bool unite(long long x, long long y)
    {
        x = root(x);
        y = root(y);

        if (x == y)
        {
            return false;
        }

        if (d[x] > d[y])
        {
            swap(x, y);
        }

        d[x] += d[y];
        d[y] = x;
        return true;
    }

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

    long long size(long long x)
    {
        return -d[root(x)];
    }
};

int main(void)
{
    ll n, m;

    cin >> n >> m;

    vector<ll> a(m), b(m);
    vector<vector<ll>> g(n, vector<ll>());

    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;

        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    ll k;
    cin >> k;

    vector<vector<ll>> g_d(k, vector<ll>(k, INF));
    vector<ll> c(k);

    for (int i = 0; i < k; i++)
    {
        cin >> c[i];
        c[i]--;
    }

    for (int i = 0; i < k; i++)
    {
        queue<ll> q;
        q.push(c[i]);

        vector<ll> dis(n, INF);
        dis[c[i]] = 0;

        while (q.size())
        {
            ll p = q.front();
            q.pop();

            for (auto &&x : g[p])
            {
                if (dis[x] == INF)
                {
                    dis[x] = dis[p] + 1, dis[x];
                    q.push(x);
                }
            }
        }

        for (int j = 0; j < k; j++)
        {
            if (i == j)
            {
                g_d[i][j] = 0;
                g_d[j][i] = 0;
            }

            if (dis[c[j]] == INF)
            {
                cout << -1 << endl;
                return 0;
            }

            ll d;
            d = min(g_d[i][j], dis[c[j]]);

            g_d[i][j] = d;
            g_d[j][i] = d;
        }
    }

    ll maxd = 0;
    bool flag = false;

    for (int i = 0; i < k; i++)
    {
        for (int j = i + 1; j < k; j++)
        {
            maxd = max(maxd, g_d[i][j]);
        }
    }

    // for (int i = 0; i < k; i++)
    // {
    //     for (int j = 0; j < k; j++)
    //     {
    //         printf("%lld ", g_d[i][j]);
    //     }
    //     printf("\n");
    // }

    vector<vector<ll>> dp(1 << k, vector<ll>(k, INF));

    for (int i = 0; i < k; i++)
    {
        dp[1 << i][i] = 1;
    }

    for (int bit = 1; bit < 1 << k; bit++)
    {
        for (int i = 0; i < k; i++)
        {
            for (int j = 0; j < k; j++)
            {
                dp[bit | 1 << j][j] = min(dp[bit | 1 << j][j], dp[bit][i] + g_d[i][j]);
            }
        }
    }

    ll ans = INF;

    for (int i = 0; i < k; i++)
    {
        ans = min(ans, dp[(1 << k) - 1][i]);
    }

    cout << ans << endl;
}

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

int main(){
    int N,K;
    cin>>N>>K;
    vector<vector<int>> A(N,vector<int>(N));
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>A[i][j];
        }
    }
    vector<int> kouho;
    int left=-1,right=1e9+1;
    while(right-left>1){
        int mid=(right-left)/2+left;
        vector<vector<int>> a(N,vector<int>(N)),sum(N,vector<int>(N));
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(A[i][j]>mid) a[i][j]=1;
                else a[i][j]=0;
            }
        }
        sum[0][0]=a[0][0];
        for(int i=1;i<N;i++) sum[i][0]=sum[i-1][0]+a[i][0];
        for(int i=1;i<N;i++) sum[0][i]=sum[0][i-1]+a[0][i];
        for(int i=1;i<N;i++){
            for(int j=1;j<N;j++){
                sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j];
            }
        }
        bool f=false;
        if(sum[K-1][K-1]<=K*K/2) f=true;
        for(int i=1;i<=N-K;i++){
            if(sum[i+K-1][K-1]-sum[i-1][K-1]<=K*K/2) f=true;
        }
        for(int i=1;i<=N-K;i++){
            if(sum[K-1][i+K-1]-sum[K-1][i-1]<=K*K/2) f=true;
        }
        for(int i=1;i<=N-K;i++){
            for(int j=1;j<=N-K;j++){
                if(sum[i+K-1][j+K-1]-sum[i-1][j+K-1]-sum[i+K-1][j-1]+sum[i-1][j-1]<=K*K/2){
                    f=true;
                }
            }
        }
        if(f){
            right=mid;
        }else{
            left=mid;
        }
    }
    cout<<right<<endl;
    return 0;
}


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

#define int long long

signed main(){
	int l,r;
	cin>>l>>r;

	if(l==r){
		cout<<0;return 0;
	}

	if(l==1)l++;

	if(r-l==1){
		cout<<1;return 0;
	}

	vector<int> d(r+1,0);

	for(int i=2;i<=r;i++){
		if(d[i]!=0)continue;
		for(int j=i;j<=r;j+=i){
			d[j]++;
		}
		for(int j=i*i;j<=r;j+=i*i){
			d[j]=-10000000;
		}
	}

	int ncop=0;

	for(int i=2;i<=r;i++){
		if(d[i]<0)continue;
		int x=r/i-(l-1)/i;
		//cout<<i<<' '<<x<<' '<<d[i]<<' ';
		x=x*(x-1)/2;
		ncop+=(d[i]%2)?x:-x;
		//cout<<ncop<<'\n';
	}

	int div=0;

	for(int i=l;i<=r;i++){
		div+=r/i-1;
	}

	cout<<(ncop-div)*2;
	return 0;
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define neinf 0xc0c0c0c0c0c0c0c0ll
#define inf 0x3f3f3f3f3f3f3f3fll
#define uint unsigned int
#define ull unsigned ll
#define HgS 1000000007
#define pr pair<ll,ll>
#define prpr make_pair
#define ll long long
#define opr operator
#define reg register
#define gc getchar
#define pc putchar
#define ret return
#define cst const
#define db double
#define il inline
il ll rd()
{
	reg ll res=0,lab=1;
	reg char ch=gc();
	while((ch<'0'||ch>'9')&&ch!=EOF){if(ch=='-')lab=-lab;ch=gc();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+(ch&15),ch=gc();
	ret res*lab;
}
il void prt(ll x,char t='\n')
{
	static char ch[70];int tp=0;
	if(!x){fputs("0",stdout);if(t)pc(t);ret;}
	if(x<0)pc('-'),x=-x;
	while(x)ch[++tp]=(x%10)^48,x/=10;
	while(tp)pc(ch[tp--]);
	if(t)pc(t);
}
il ll umax(ll a,ll b){return a>b?a:b;}
il ll umin(ll a,ll b){return a<b?a:b;}
il ll uabs(ll x){return x>0?x:-x;}
il ll qpow(ll n,ll e=HgS-2,ll p=HgS)
{
	n%=p;reg ll res=1;
	while(e){if(e&1)res=res*n%p;n=n*n%p;e>>=1;}
	ret res;
}
ll l,r,mu[1000005],sum[1000005];bool vis[1000005];
ll slv(int x,int y)
{
	ll ans=0;
	for(int l=1,r;l<=umin(x,y);l=r+1)
	{
		r=umin(x/(x/l),y/(y/l));
		ans+=1ll*(x/l)*(y/l)*(sum[r]-sum[l-1]);
	}
	return ans;
}
int main()
{
	l=rd(),r=rd();
	for(int i=1;i<=r;++i)mu[i]=1;
	for(int i=2;i<=r;++i)
	{
		if(vis[i])continue;
		for(int j=i;j<=r;j+=i)
		{
			vis[j]=1;
			if(1ll*j%(1ll*i*i)==0)mu[j]=0;
			else mu[j]=-mu[j];
		}
	}
	for(int i=1;i<=r;++i)sum[i]=sum[i-1]+mu[i];
	ll s1=0,s2=slv(r,r)-slv(l-1,r)-slv(r,l-1)+slv(l-1,l-1);
	for(int i=umax(l,2);i<=r;++i){++s1;for(int j=2;j*i<=r;++j)s1+=2;}
	prt(1ll*(r-l+1)*(r-l+1)-s1-s2);
	ret 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;

const int N = 15;

char a[N];
int ans = 0;
int tr[N],cnt;
int st[N];

void dfs(int num)
{
	if(num == 4)
	{
		bool fl = true;
		for(int i = 1;i <= cnt;i++)
			if(st[tr[i]] == 0)
			{
				fl = false;
				break;
			}
		if(fl) ans++;
		return;
	}

	for(int i = 0;i < 10;i++)
	{
		if(a[i] == 'x') continue;
		st[i]++;
		dfs(num + 1);
		st[i]--;
	}

}

int main()
{
	scanf("%s",a);
	for(int i = 0;i < 10;i++)
	    if(a[i] == 'o')
	        tr[++cnt] = i;

	if(cnt > 4)
	{
		printf("0");
		return 0;
	}

	dfs(0);

	printf("%d",ans);

	return 0;
}

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

int main() {
  int n; cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; ++i){
    int judge = 0;
    int i2 = i;
    while (i2){
      if (i2%10 == 7) {
        judge = 1;
        break;
      }
      i2 /= 10;
    }
    i2 = i;
    while (i2){
      if (i2 % 8 == 7) {
        judge = 1;
        break;
      }
      i2 /= 8;
    }
    if (judge == 1) continue;
    ans++;
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1e9+7;

ll exp(ll a,ll n){
    if(n==0)    return 1;
    if(n==1)    return a;
    ll ans=exp(a,n/2);
    ans*=ans;ans%=MOD;
    if(n&1) ans*=a,ans%=MOD;
    return ans;
}

void solve(){
    int n,m;cin>>n>>m;
    string s[n];
    for(int i=0;i<n;i++)    cin>>s[i];

    int top[n][m],bottom[n][m],left[n][m],right[n][m];
    memset(top,0,sizeof(top));
    memset(bottom,0,sizeof(bottom));
    memset(left,0,sizeof(left));
    memset(right,0,sizeof(right));

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')    continue;
            top[i][j]=1;
            if(i)   top[i][j]+=top[i-1][j];
        }
    }
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')    continue;
            bottom[i][j]=1;
            if(i+1<n)   bottom[i][j]+=bottom[i+1][j];
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')    continue;
            left[i][j]=1;
            if(j)   left[i][j]+=left[i][j-1];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=m-1;j>=0;j--){
            if(s[i][j]=='#')    continue;
            right[i][j]=1;
            if(j+1<m)   right[i][j]+=right[i][j+1];
        }
    }

    int nTidy=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='.')    nTidy++;
        }
    }
    ll total=exp(2,nTidy)*nTidy%MOD;
    ll negativeContri=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')    continue;
            int restriction=top[i][j]+bottom[i][j]+left[i][j]+right[i][j]-4+1;
            negativeContri+=exp(2,nTidy-restriction);
            negativeContri%=MOD;
        }
    }
    cout<<(total-negativeContri+MOD)%MOD<<"\n";
}

main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    solve();
}

//x<<y=x*2^y,x>>y=x/2^y
//1e5+3 is prime
// in a matrix, all elements of a primary diagonal have constant diff of coordinates
// and a secondary diagonal has constant sum of coordinates
//use ll() for using an integer in self-built fn
//(x&-x) bitwise and of (x and its 2's complement) returns (last set bit)
//eg if x=1010 then it will return 0010
// careful dont print empty container(run time error)
//v.erase O(n)
//use ("\n") instead of endl as endl flushes the output buffer
//every time so takes more time than \n (TLE)
//stoll() and to_string((less than 1e19))
//INT_MAX is approx 3e10
//For sets use set_name.lower_bound(x)(strictly O(logn))
//NOT lb(all(s),x)(O(logn) for random access (eg vector) but for sets it is O(n));
#include<bits/stdc++.h>
typedef long long int ll;
#define ull unsigned long long int
#define lld long double
#define endl "\n"
#define fi first
#define sec second
#define sp setprecision
#define lb lower_bound
#define ub upper_bound
#define For(i, a, b) for(long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for(long long int i = (a); i >= (b); i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vlld vector<lld>
#define vi vector<int>
#define vch vector<char>
#define sll set<ll>
#define sch set<ch>
#define vpll vector< pair<ll,ll> >
#define vpii vector< pair<int,int> >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mll map<ll, ll>
#define mcll map<char,ll>
#define sz(container) ll((container).size())
#define fill(a,b) memset(a, b, sizeof(a))
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
lld pi=3.1415926535897932;
const ll mod=998244353;
const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1};
const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};
string ds="RLDU";
/***************************************
struct cmp
{
    bool operator() (const pll &a, const pll &b)  const
    {
        ll lena = a.sec - a.fi + 1;
        ll lenb = b.sec - b.fi + 1;
        if (lena == lenb) return a.fi < b.fi;
        return lena > lenb;
    }
};
********************************/

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

ll binpow(ll a, ll b,ll m)
{
    a %= m;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinv(ll n)
{
    return binpow(n, mod - 2,mod);
}

/**************coding*********************/
vector<vll >adj(105);
vll used(105,0);
void dfs(ll v)
{
    used[v]=1;
    for(ll u : adj[v])
    {
        if (!used[u]) dfs(u);
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_io;
    ll T=1;//cin>>T;
    For(i,1,T)
    {
        ll n;cin>>n;
        string s[n];
        For(j,0,n-1) cin>>s[j];
        For(j,0,n-1)
        {
            For(k,0,n-1)
            {
                if(s[j][k]=='1') adj[j].pb(k);
            }
        }
        lld ans=0;
        vll vis(n,0);
        For(j,0,n-1)
        {
            For(k,0,n-1) used[k]=0;
            dfs(j);
            For(k,0,n-1) if(used[k]==1) vis[k]++;
        }
        For(j,0,n-1) ans+=(1/double(vis[j]));
        cout<<sp(20)<<ans;
    }
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long int;

// aの逆元を計算する
ll modinv(ll a, ll mod)
{
    ll b = mod, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= mod;
    if (u < 0)
        u += mod;
    return u;
}

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

    for (int i = 0; i < T; i++)
    {
        ll N, S, K;
        cin >> N >> S >> K;

        if (__gcd(K, N) != 1)
        {
            ll g = __gcd(K, N);

            if (S % g != 0)
            {
                cout << "-1" << endl;
                continue;
            }

            K /= g;
            N /= g;
            S /= g;
        }

        ll K_inv = modinv(K, N);

        cout << ((N - S) * K_inv) % N << endl;
    }

    return 0;
}

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

#define ll long long
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define P pair<ll, ll>

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

    vector<ll> L(T), R(T);
    rep(i, T) cin >> L.at(i) >> R.at(i);
    rep(i, T){
        if(R.at(i)-L.at(i) < L.at(i)){
            cout << 0 << endl;
            continue;
        }
        cout << (R.at(i)-2*L.at(i)+1)*(R.at(i)-L.at(i)+1)
                - (R.at(i)-L.at(i))*(R.at(i)-L.at(i)+1)/2
                + (L.at(i)-1)*L.at(i)/2 << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a+b>=15 && b>=8 ) cout<<1;
	else if(a+b>=10 && b>=3) cout<<2;
	else if(a+b>=3) cout<<3;
	else  cout<<4;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
	x += y;
	if( x >= m )
		x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
	x -= y;
	if( x < 0 )
		x += m;
}

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

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

	a += b;

	if( a >= 15 && b >= 8 )
	{
		cout<<1;
	}
	else if( a >= 10 && b >= 3 )
	{
		cout<<2;
	}
	else if( a >= 3 )
	{
		cout<<3;
	}
	else
	{
		cout<<4;
	}

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Erep(i,n) for(int i = 0; i <= (n); ++i)
#define repS(i,s,n) for(int i = s; i < (n); ++i)
#define ErepS(i,s,n) for(int i = s; i <= (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())
#define Output(a) printf("%lld %s", a, "\n")
#define OutputS(a) printf("%s %s", a, "\n")

typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vst;

const ll INF = 0x1fffffffffffffff;
const ll MOD = 1000000007;

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; }

string s;

void input(){
    cin >> s;
}

void solve(){
    string ans = "";
    rep(i, s.size()){
        if(s[i] == '6'){
            ans.push_back('9');
        }else if(s[i] == '9'){
            ans.push_back('6');
        }else{
            ans.push_back(s[i]);
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

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

    input();
    solve();
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair
#define MOD 1000000007
#define pi 3.1415926536
/* BAAP BAAP HOTA HAI
   AUTHOR- Devansh Nandasana*/
void adde(vector<ll> adj[],ll u,ll v)
{
  adj[u].pb(v);
  adj[v].pb(u);
}
ll modInverse(ll a, ll m)
{
    ll m0=m;
    ll y=0,x=1;
    if(m==1)
      return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m,a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0)
      x+=m0;
    return x;
}
void BFS(vector<ll> adj[],ll bfs[],ll s,ll n)
{
    bool *visited = new bool[n+1];
    for(ll i=0;i<n+1;i++)
        visited[i] = false;
    list<ll> queue;
    visited[s] = true;
    bfs[s]=0;
    queue.push_back(s);
    vector<ll>::iterator i;
    while(!queue.empty())
    {
        s=queue.front();
        queue.pop_front();
        for(i=adj[s].begin();i!=adj[s].end();++i)
        {
            if(!visited[*i])
            {
                visited[*i] = true;
                bfs[*i]=bfs[s]+1;
                queue.push_back(*i);
            }
        }
    }
}
ll nCrModp(ll n,ll r,ll p)
{
    if (r > n - r)
        r = n - r;
    ll C[r + 1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for (ll i = 1; i <= n; i++) {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j - 1]) % p;
    }
    return C[r];
}
ll find_center(ll n,vector<ll> adj[])
{
  queue<ll> q;
  bool vis[n+1];
  ll cnt[n+1];
  for(ll i=1;i<=n;i++)
  {
    vis[i]=false;
    cnt[i]=adj[i].size();
    if(cnt[i]==1)
    q.push(i);
  }
  while(q.size()>1)
  {
    ll cur=q.front();
    vis[cur]=true;
    q.pop();
    for(ll i=0;i<adj[cur].size();i++)
    {
      if(!vis[adj[cur][i]])
      {
        cnt[adj[cur][i]]--;
        if(cnt[adj[cur][i]]==1)
        q.push(adj[cur][i]);
      }
    }
  }
  return q.front();
}
int main()
{
  #ifndef ONLINE_JUDGE
  	freopen("/home/devansh/Desktop/temp/input.txt", "r", stdin);
  	freopen("/home/devansh/Desktop/temp/output.txt", "w", stdout);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin>>s;
  reverse(&s[0],&s[s.length()]);
  for(ll i=0;i<s.length();i++)
  {
    if(s[i]=='6')
      s[i]='9';
    else if(s[i]=='9')
      s[i]='6';
  }
  cout<<s<<"\n";
}


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

int main(){
    char word[1000];
    cin >> word;
    string ans = "Yes";
    for(int i=0;i<strlen(word);i++){
        if(i%2){
            if(word[i]<'A' || 'Z'<word[i]) ans = "No";
        }else{
            if(word[i]<'a' || 'z'<word[i]) ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

	long long int x = 0;
	for (long long int i = 1; i <= n; i++) {
		if (x + i >= n + 1) {
			if (x + i == n + 1) {
				x = i;
			}
			else {
				x = i - 1;
			}
			break;
		}
		x += i;
	}
	cout << (n - x) + 1 << endl;
}


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

int main() {
  int N;
  std::int64_t X;
  std::cin >> N >> X;
  std::vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }
  std::int64_t best = X;
  for (int k = 1; k <= N; ++k) {
    std::vector<std::vector<int>> powers(k + 1, std::vector<int>(k, -1));
    powers[0][0] = 0;
    for (const auto a : A) {
      for (int i = k - 1; i >= 0; --i) {
        for (int j = 0; j < k; ++j) {
          if (powers[i][j] >= 0) {
            const int m = (j + a) % k;
            powers[i + 1][m] = std::max(powers[i + 1][m], powers[i][j] + a);
          }
        }
      }
    }
    for (int j = 0; j < k; ++j) {
      if ((X - j) % k == 0 && powers[k][j] >= 0) {
        best = std::min(best, (X - powers[k][j]) / k);
      }
    }
  }
  std::cout << best << std::endl;
  return 0;
}

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // int64_t
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define REP(i,m,n) for(int i = m; i <= (n); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)

const int INF = 1e9+7;   //10oku7

const int KONS_UFT= 300000;

vector<int> par(KONS_UFT); //par 親
vector<int> depth(KONS_UFT); //depth 木の深さ

//要素を初期化
void init( int n ){
  rep (i , n){
    par[i] = i;
  }

  rep (i , n){
    depth[i] = 0;
  }

  return;
}

//木の根を調べる。
int find( int x ){
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find( par[x]);
  }
}

//xとyの属する集合を合併
void unite( int x, int y){
  x = find( x);
  y = find( y);
  if (x == y) return;

  if (depth [x] < depth [y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (depth[x] == depth [y]) depth[x]++;
  }
  return;
}

//xとyが同じ集合に属するか
bool same( int x, int y){
  return find(x) == find (y);
}

int main() {

  int H , W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H){
    cin >> S.at(i);
  }

  S.at(0).at(0) = '#';
  S.at(0).at(W-1) = '#';
  S.at(H-1).at(0) = '#';
  S.at(H-1).at(W-1) = '#';

  init(H+W);

  rep(i,H){
    rep(j,W){
      if (S.at(i).at(j) == '#') unite(i,j+H);
    }
  }

  set<int> col, row;
  rep(i,H){
    col.insert(find(i));
  }
  rep(j,W){
    row.insert(find(j+H));
  }

  cout << min(col.size() -1 , row.size() -1) << endl;

}


#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint x, y, a, b;
    cin >> x >> y >> a >> b;
    lint ret = 0;
    for (int i = 0; i <= 60; ++i) {
        bool ok   = true;
        lint tot  = i;
        lint curr = x;
        for (int j = 0; j < i; ++j) {
            if (curr >= y / a) {
                ok = false;
                break;
            }
            curr *= a;
        }
        if (curr > y)
            ok = false;
        lint bs = (y - 1 - curr) / b;
        tot += bs;
        if (!ok)
            continue;
        else
            ret = max(ret, tot);
    }
    cout << ret << "\n";
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;

int main()
{
	ld k;
	cin>>k;
	string s,t;
	cin>>s>>t;
	s.erase(s.end()-1);
	t.erase(t.end()-1);
	vll v(9,k),w1(9,0),w2(9,0);
	for(auto i:s)
	{
		ll a=i-'1';
		v[a]--;
		w1[a]++;
	}

	for(auto i:t)
	{
		ll a=i-'1';
		v[a]--;
		w2[a]++;
	}

	ld sum=0;
	for(int i=0;i<9;i++)
	{
		for(int j=0;j<9;j++)
		{
			ll a=0,b=0,temp;
			w1[i]++;
			w2[j]++;

			for(int l=1;l<10;l++)
			{
				a+=l*pow(10,w1[l-1]);
				b+=l*pow(10,w2[l-1]);
			}
			if(a>b)
			{
				temp=v[i];
				v[i]--;
				sum+= temp*v[j];
				v[i]++;
			}
			w1[i]--;
			w2[j]--;
		}
	}

	k=9*k-8;
	ld ans=sum/(k*(k-1));
	cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> P(n, -1);
  vector<vector<int>> G(n);
  REP(i, 1, n) {
    cin >> P[i];
    P[i]--;
    G[P[i]].push_back(i);
  }
  vector<int> in(n), out(n);
  vector<vector<int>> D(n);
  int tmp = 0;
  auto dfs = [&](auto dfs, int cur, int depth) -> void {
    in[cur] = tmp++;
    D[depth].push_back(in[cur]);
    for(int ne: G[cur]) {
      dfs(dfs, ne, depth+1);
    }
    out[cur] = tmp++;
    D[depth].push_back(out[cur]);
  };
  dfs(dfs, 0, 0);
  int q; cin >> q;
  rep(i, q) {
    int u, d; cin >> u >> d;
    u--;
    cout << (upper_bound(all(D[d]), out[u]) - lower_bound(all(D[d]), in[u])) / 2 << endk;
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int b[200005];
int main()
{
	int N,min=0;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		int n;
		scanf("%d",&n);
		b[n]++;

		if(n==min)
		{
			for(int j=n;;j++)
			{
				if(b[j]==0)
				{
					min=j;
					break;
				}
			}
		}
		printf("%d\n",min);
	}

}


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

int main() {
  string N;
  cin >> N;
  int length;
  int count=0;
  length = N.size();
  int x=0;
  for (int i=0;i<length-1;i++) {
    if(N.at(length-1-i)=='0'){
      count++;
    }else{
      break;
    }
  }
  for (int i=0;i<1+(length-count)/2;i++){
    if(N.at(i)!=N.at(length-count-1-i)){
      x++;
      break;
    }
  }
  if(x==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007

void solve()
{
int n;
cin>>n;
int st=1;
int en=n;
int ans=-1;
while(st<=en)
{
int mid=(st+en)/2;
if((mid*(mid+1))/2 >=n)
{ans=mid;
    en=mid-1;

}
else
st=mid+1;

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

int32_t main() {
  #ifndef ONLINE_JUDGE
    freopen("inp.txt",  "r",  stdin);
    freopen("m3.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int t;
   //cin>>t;

 t=1;
while(t--)
{
  solve();

   }
    return 0;

}

#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
using namespace std;
int Power(int Num,int Index){
    int r=1 ;
    for(int i=Index;i>0;i/=2,Num*=Num){
        if(i%2==1){
            r*=Num ;
        }
    }
    return r ;
}
int Factorial(int Number){
    int m=1;
    for(int i=1;i<=Number;i++){
        m*=i;
    }
    return m;
}
int BinToDec(string Bin){
    int n=0;
    for(int i=Bin.size()-1;i>=0;i--){
        n+=(Bin[Bin.size()-1-i]-'0')*Power(2,i);
    }
    return n;
}
int HexadecToDec(string Hex){
    int n=0;
    for(int i=Hex.size()-1;i>=0;i--){
        if(Hex[i]>='A'&&Hex[i]<='F'){
            n+=(Hex[i]-'A'+10)*Power(16,Hex.size()-i-1);
        }
        else{
            n+=(Hex[i]-'0')*Power(16,Hex.size()-1-i);
        }
    }
    return n;
}
int nCr(int Num1,int Num2){
    int k=1;
    for(int i=Num1-Num2+1;i<=Num1;i++){
        k*=i;
    }
    int x=k/(Factorial(Num2));
    return x;
}
string DecToBin(int Num){
    string k="";
    while(Num){
        int r=Num%2;
        string a=to_string(r);
        k+=a;
        Num/=2;
    }
    reverse(k.begin(),k.end());
    return k;
}
string DecToHexadec(int Num){
    string k="";
    while(Num){
        int r=Num%16;
        if(r<=9){
            string a=to_string(r);
            k+=a;
        }
        else{
            k+=(r-10+'A');
        }
        Num/=16;
    }
    reverse(k.begin(),k.end());
    return k;
}
bool VowelChecker(char Letter){
    Letter=tolower(Letter);
    if(Letter=='a'||Letter=='e'||Letter=='i'||Letter=='o'||Letter=='u'){
        return true;
    }
    else{
        return false;
    }
}
bool PrimeChecker(int Num){
    bool ok=true;
    for(int i=2;i<=sqrt(Num);i++){
        if(Num%i==0){
            ok=false;
        }
    }
    if(ok==true){
        return true;
    }
    else{
        return false;
    }
}
bool Palindrome(string Word){
    string c=Word;
    reverse(c.begin(),c.end());
    if(c==Word){
        return true;
    }
    else{
        return false;
    }
}
vector<int> Factors(int Num){
    vector<int>s;
    for(int i=1;i*i<=Num;i++){
        if(Num%i==0){
            if(Num/i==i){
                s.push_back(i) ;
            }
            else{
                s.push_back(i) ;
                s.push_back(Num/i) ;
            }
        }
    }
    sort(s.begin(),s.end());
    return s ;
}
vector<int> PrimeFactorisation(int Num){
    vector<int>p;
    while(Num%2==0){
        p.push_back(2);
        Num/=2;
    }
    for(int i=3;i<=sqrt(Num);i+=2){
        while(Num%i==0){
            p.push_back(i);
            Num/=i;
        }
    }
    if(Num>2){
        p.push_back(Num);
    }
    return p;
}
vector<int> SieveOfEratosthenes(int Num){
    vector<int>s;
    bool prime[Num+1];
    memset(prime,true,sizeof(prime));
    for(int p=2;p*p<=Num;p++){
        if (prime[p]==true){
            for(int i=p*p;i<=Num;i+=p){
                prime[i]=false;
            }
        }
    }
    for (int p=2;p<=Num;p++){
        if (prime[p]){
            s.push_back(p);
        }
    }
    return s;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc ;
    tc = 1 ;
    // cin >> tc ;
    while(tc--){
        int n;cin>>n;
        for(int i=1;i<=n;i++){
            if((i*(i+1))/2>=n){
                cout << i ;break;
            }
        }
    }
	return 0;
}


#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 202020
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cerr<<clock()/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n;
vector<ll>a[3];

int main()
{
	file();
	map<char,int>mp; mp['R']=0,mp['G']=1,mp['B']=2;
	read(n);
	ll x; char cc;
	rep(i,1,n*2) read(x),cin>>cc,a[mp[cc]].push_back(x);
	rep(i,0,2) sort(a[i].begin(),a[i].end());
	auto qq=[&](int id,ll w)
	{
		if (!a[id].size()) return ll(1e18);
		int t=lower_bound(a[id].begin(),a[id].end(),w)-a[id].begin(); ll res=1e18;
		if (t) chkmin(res,w-a[id][t-1]);
		if (t!=(int)a[id].size()) chkmin(res,a[id][t]-w);
		return res;
	};
	int c=0,p=0; rep(i,0,2) if (a[i].size()%2==0u) ++c,p=i; if (c==3) return puts("0"),0;
	ll ans=1e18;
	rep(i,0,2) if (i!=p) for (auto x:a[i]) chkmin(ans,qq(3-i-p,x));
	int p1=(p==0?1:0),p2=3-p-p1;
	auto wk=[&](){ll mn=1e18;for (auto x:a[p]) chkmin(ans,mn+qq(p2,x)),chkmin(mn,qq(p1,x));};
	wk(); swap(p1,p2); wk();
	cout<<ans;
	return 0;
}

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
vector < int > G[3];
int n, pos_l, pos_r;

int id( char ch ) {
	if( ch == 'R' ) return 0;
	if( ch == 'B' ) return 1;
	if( ch == 'G' ) return 2;
}

int Fabs( int x ) {
	return x < 0 ? -x : x;
}

void work( int c, int val ) {
	int l = 0, r = G[c].size() - 1;
	pos_l = 0, pos_r = G[c].size() - 1;
	while( l <= r ) {
		int mid = ( l + r ) >> 1;
		if( G[c][mid] <= val ) pos_l = mid, l = mid + 1;
		else r = mid - 1;
	}
	l = 0, r = G[c].size() - 1;
	while( l <= r ) {
		int mid = ( l + r ) >> 1;
		if( G[c][mid] >= val ) pos_r = mid, r = mid - 1;
		else l = mid + 1;
	}
}

signed main() {
	scanf( "%lld", &n );
	for( int i = 1;i <= ( n << 1 );i ++ ) {
		char c; int a;
		scanf( "%lld %c", &a, &c );
		G[id( c )].push_back( a );
	}
	int c1 = -1, c2 = -1;
	for( int i = 0;i < 3;i ++ )
		if( G[i].size() & 1 ) {
			if( ~ c1 ) c2 = i;
			else c1 = i;
		}
	if( c1 == -1 ) return ! printf( "0\n" );
	else {
		int ans = 1e18;
		sort( G[c2].begin(), G[c2].end() );
		for( int i = 0;i < G[c1].size();i ++ ) {
			work( c2, G[c1][i] );
			ans = min( ans, min( Fabs( G[c1][i] - G[c2][pos_l] ), Fabs( G[c2][pos_r] - G[c1][i] ) ) );
		}
		int ans1 = 1e18, ans2 = 1e18, c;
		for( int i = 0;i < 3;i ++ )
			if( c1 == i || c2 == i ) continue;
			else c = i;
		if( ! G[c].size() ) goto pass;
		sort( G[c].begin(), G[c].end() );
		for( int i = 0;i < G[c1].size();i ++ ) {
			work( c, G[c1][i] );
			ans1 = min( ans1, min( Fabs( G[c1][i] - G[c][pos_l] ), Fabs( G[c][pos_r] - G[c1][i] ) ) );
		}
		for( int i = 0;i < G[c2].size();i ++ ) {
			work( c, G[c2][i] );
			ans2 = min( ans2, min( Fabs( G[c2][i] - G[c][pos_l] ), Fabs( G[c][pos_r] - G[c2][i] ) ) );
		}
		pass :
			printf( "%lld\n", min( ans, ans1 + ans2 ) );
	}
	return 0;
}


#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
#define NDEBUG
#endif
#include<bits/stdc++.h>
#define int long long
#define LL long long
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef pair<int,int>PII;typedef vector<int>VI;typedef vector<PII>VII;
template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
const int N=100005;
int n,L,a[N],b[N],ans;
vector<int>G[N];
map<int,int>lst,sum;
void sol(){
	lst.clear(),sum.clear(),lst[0]=0;
	rep(i,1,n)a[i]-=i,b[i]-=i;
	rep(i,1,n){
		lst[a[i]]=i;
		if(b[i]<a[i]){
			if(!lst.count(b[i]))puts("-1"),exit(0);
			ans+=i-lst[b[i]];
			ans-=sum[b[i]];
			sum[b[i]]=i-lst[b[i]];
		}
	}
	rep(i,1,n)a[i]+=i,b[i]+=i;
}
signed main(){
	rd(n),rd(L);
	rep(i,1,n)rd(a[i]);
	rep(i,1,n)rd(b[i]);
	sol();
	rep(i,1,n)a[i]=L-a[i]+1,b[i]=L-b[i]+1;
	reverse(a+1,a+1+n);
	reverse(b+1,b+1+n);
	sol();
	pt(ans,'\n');
	return 0;
}

#include <iostream>
#include <vector>
#include <queue>

using pli = std::pair<int64_t, int>;

struct Edge {
  Edge(int to, int t_p, int c) : to(to), t_point(t_p), cost(c) {}
  int to, t_point, cost;
};

int64_t earliest_time(const std::vector<std::vector<Edge>>& graph,
                  int n, int from, int to) {
  std::priority_queue<pli, std::vector<pli>, std::greater<pli>> que;
  std::vector<bool> used(n + 1, false);
  que.emplace(0, from);
  while (!que.empty()) {
    pli cur = que.top();
    que.pop();
    int64_t arrival = cur.first;
    int v = cur.second;
    if (v == to) return arrival;
    if (used[v]) continue;
    used[v] = true;
    for (const auto& edge : graph[v]) {
      if (used[edge.to]) continue;
      int64_t leave = (arrival + edge.t_point - 1) / edge.t_point * edge.t_point;
      que.emplace(leave + edge.cost, edge.to);
    }
  }
  return -1;
}

int main() {
  int n, m, from, to;
  std::cin >> n >> m >> from >> to;
  std::vector<std::vector<Edge>> graph(n + 1, std::vector<Edge>());
  for (int i = 0; i < m; ++i) {
    int u, v, t_p, c;
    std::cin >> u >> v >> c >> t_p;
    graph[u].emplace_back(v, t_p, c);
    graph[v].emplace_back(u, t_p, c);
  }
  std::cout << earliest_time(graph, n, from, to) << std::endl;
  return 0;
}


using namespace std;
#include <bits/stdc++.h>
#define ll long long
ll n,m;
struct Num{
	ll a,b;
};
Num mul(Num x,Num y){
	Num z;
	z.a=x.a*y.a%m;
	z.b=(x.a*y.a/m+x.a*y.b+x.b*y.a)%m;
	return z;
}
Num qpow(ll x,ll y){
	Num z={x%m,x/m%m},r={1,0};
	for (;y;y>>=1,z=mul(z,z))
		if (y&1)
			r=mul(r,z);
	return r;
}
int main(){
	scanf("%lld%lld",&n,&m);
	if (m==1){
		printf("0\n");
		return 0;
	}
	ll ans=qpow(10,n).b;
	printf("%lld\n",ans);
	return 0;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int numwall,killo;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   cin>>killo>>numwall;

   cout<<killo/numwall;
    return 0;
}