#include <iostream>
#include <vector>
#include <map>
using namespace std;
const int maxn = 1e2 + 10;
const int maxm = 1e4 + 10;
int n, m;
int c[maxn];
bool visited[maxn];
string ans[maxm];
vector<int> G[maxn];
vector<pair<int, int>> edge;
map<pair<int, int>, int> edge_ind;

void dfs(int v){
	visited[v] = true;
	for(int u : G[v]){
		if(c[u] == c[v]){
			int ind = edge_ind[{u, v}];
			if(ans[ind] == ""){
				if(edge[ind].first == v){
					ans[ind] = "->";
				}
				else{
					ans[ind] = "<-";
				}
			}
			if(!visited[u]){
				dfs(u);
			}
		}
	}
}

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i ++){
		int u, v;
		cin >> u >> v;
		u --, v --;
		G[u].push_back(v);
		G[v].push_back(u);
		edge.push_back({u, v});
		edge_ind[{u, v}] = edge_ind[{v, u}] = i;
	}
	for(int i = 0; i < n; i ++){
		cin >> c[i];
	}
	for(int i = 0; i < n; i ++){
		if(!visited[i]){
			dfs(i);
		}
	}
	for(int i = 0; i < m; i ++){
		if(c[edge[i].first] > c[edge[i].second]){
			ans[i] = "->";
		}
		if(c[edge[i].second] > c[edge[i].first]){
			ans[i] = "<-";
		}
	}
	for(int i = 0; i < m; i ++){
		cout << ans[i] << '\n';
	}
}

#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
template<class T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
constexpr int dy[4]={-1,0,1,0};
constexpr int dx[4]={0,-1,0,1};

int N, M;
int A[100*100], B[100*100];
int C[100];

vector<pair<int,int>> e[101];
vector<int> v[101];
int ans[100*100];

bool vis[100];
queue<int> que;
bool fin[100];
bool dfs(int n, int p, int b){
    if(vis[n]){
        if(n == p) return true;
        else return false;
    }
    vis[n] = true;
    rep(i, e[n].size()){
        if(C[n] != C[e[n][i].first]) continue;
        if(e[n][i].first == b) continue;
        bool ret = dfs(e[n][i].first, p, n);
        if(ret){
            fin[n] = true;
            ans[e[n][i].second] = n;
            que.push(n);
            return true;
        }
    }
    vis[n] = false;
    return false;
}
bool dfs2(int n, int p, int b){
    if(fin[n]) return true;
    if(vis[n]) return false;
    vis[n] = true;
    rep(i, e[n].size()){
        if(C[n] != C[e[n][i].first]) continue;
        if(e[n][i].first == b) continue;
        bool ret = dfs2(e[n][i].first, p, n);
        if(ret){
            fin[n] = true;
            ans[e[n][i].second] = n;
            que.push(n);
            return true;
        }
    }
    vis[n] = false;
    return false;
}

signed main(){
    cin >> N >> M;
    rep(i, M){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        e[A[i]].pb({B[i],i});
        e[B[i]].pb({A[i],i});
    }
    rep(i, N){
        cin >> C[i];
        v[C[i]].pb(i);
    }

    rep(i, 101){
        rep(j, v[i].size()){
            if(!fin[v[i][j]]){
                bool ret = dfs(v[i][j], v[i][j], -1);
            }
            while(que.size()){
                rep(k, e[que.front()].size()){
                    if(C[que.front()] != C[e[que.front()][k].first]) continue;
                    if(fin[e[que.front()][k].first]) continue;
                    dfs2(e[que.front()][k].first, que.front(), que.front());
                    ans[e[que.front()][k].second] = que.front();
                }
                que.pop();
            }
        }
    }

    rep(i, M){
        if(C[A[i]] > C[B[i]]) cout << "->" << endl;
        else if(C[A[i]] < C[B[i]]) cout << "<-" << endl;
        else{
            if(ans[i] == A[i]) cout << "->" << endl;
            else cout << "<-" << endl;
        }
    }
}


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

// union-find
struct union_find {
    vector<int> dat;

    union_find(int size) {dat.resize(size,-1);}

    int find(int x) {
        if (dat[x] < 0) {return x;}
        return dat[x] = find(dat[x]);
    }

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

    int size(int x) {return -dat[find(x)];}
};

int main() {
    int n, q; cin >> n >> q;
    vector<map<int,int>> ct(n);
    rep(i,n) {
        int c; cin >> c;
        ct[i][c]++;
    }
    union_find uf(n);
    rep(i,q) {
        int query, a, b; cin >> query >> a >> b;
        if (query == 1) {
            a--; b--;
            a = uf.find(a);
            b = uf.find(b);
            if (uf.unite(a, b)) {
                int r = uf.find(a);
                for (P p : ct[a + b - r]) {
                    ct[r][p.first] += p.second;
                }
            }
        } else {
            a--;
            cout << ct[uf.find(a)][b] << endl;
        }
    }
}

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

// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o

const int nax=2e5+5;
int par[nax],sz[nax];
map<int,int>adj[nax];
int get(int a){
 return (par[a]==a)?a:get(par[a]);
}
void Union(int a,int b){
 a=get(a);
 b=get(b);
 if(a==b)return;
 if(sz[a]<sz[b])swap(a,b);
 par[b]=a;
 sz[a]+=sz[b];
 for(auto x:adj[b]){
  adj[a][x.first]+=x.second;
 }
}
int n,q;
int c[nax];
int main(){
 cin>>n>>q;
 for(int i=1;i<=n;i++){
  cin>>c[i];
  sz[i]=1;
  par[i]=i;
  adj[i][c[i]]++;
 }
 for(int i=0;i<q;i++){
  int ch,a,b;
  cin>>ch>>a>>b;
  if(ch==1)Union(a,b);
  else{
   a=get(a);
   cout<<adj[a][b]<<"\n";
  }
 }
 return 0;
}


#include                        <bits/stdc++.h>
#include                        <ext/pb_ds/assoc_container.hpp>
#define lb                      lower_bound
#define ub                      upper_bound
#define fe(x)                   (*(x.begin()))
#define le(x)                   (*(x.rbegin()))
#define pb                      push_back
#define load(node,n)            bool operator < (const node &n) const
#define fbo(x,id)               (*(x.find_by_order(id)))
#define ook(y)                  order_of_key(y)
#define all(x)                  (x).begin(),(x).end()
#define si(a)                   scanf("%d",&a)
#define sii(a,b)                scanf("%d %d",&a,&b)
#define siii(a,b,c)             scanf("%d %d %d",&a,&b,&c)
#define sl(a)                   scanf("%lld",&a)
#define sll(a,b)                scanf("%lld %lld",&a,&b)
#define slll(a,b,c)             scanf("%lld %lld %lld",&a,&b,&c)
#define rep(i,a,b)              for(ll i = a; i<=b;  i++)
#define un(x)                   x.erase(unique(all(x)), x.end())
#define TT                      long long TC;  scanf("%lld",&TC);  while(TC--)
#define read                    freopen("input.txt","r",stdin)
#define write                   freopen("output.txt","w",stdout)
#define set(x)                  tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>
#define SZ(x)                   (int)x.size()
#define ff                      first
#define ss                      second
using                           namespace __gnu_pbds;
using                           namespace std;
typedef                         long long ll;
typedef                         pair<ll,ll> pll;
typedef                         pair<int,int> pii;

#define mx 300005

set(pii)st;

bool fn(int x){
    int id = st.ook(pii(x,0));
    if(id==(int)st.size())  return 0;
    pii w = fbo(st,id);
    if(w.ff==x){
        st.erase(w);
        return 1;
    }
    return 0;
}

main(){
//read;

int n,k;
sii(n,k);

for(int i = 0; i<n; i++){
    int a;
    si(a);
    st.insert(pii(a,i+1));
}

ll ans = 0;

for(ll i = 0; i<k; i++){
    for(ll j = 0; ; j++){
        if(fn(j)==false){
            ans+=j;
            break;
        }
    }
}

cout<<ans;

return 0;
}

//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n), b(n);
    cin >> a >> b;
    vi o, e;
    ll tmp = 0;
    rep(i, n) {
        int now = a[i] - b[i];
        tmp += b[i];
        if (i & 1) o.pb(now);
        else e.pb(now);
    }
    sort(rall(o));
    sort(rall(e));
    ll ans = tmp;
    rep(i, n / 2) {
        tmp += o[i] + e[i];
        chmax(ans, tmp);
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int a,b,c,d; cin>>a>>b>>c>>d;
int ans=-1000000;
for(int i=a;i<=b;i++){
for(int j=c;j<=d;j++){
ans=max(ans,i-j);
}}
cout<<ans;
}

#include<iostream>
#include<iomanip>
#include<limits>
#include<vector>
#include<algorithm>
#include<bitset>
#include<string>
#include<queue>
#include<tuple>
#include<cmath>
#include<unordered_set>
#include<iterator>
#include<sstream>
#include<set>

using namespace std;
#define endl "\n"
typedef long long ll;
typedef string str;
const double pi=3.14159265358979323846;
const long long inf = 1LL << 60;
typedef pair<int, int> P;
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

template<class T> inline bool ch_min(T&,T);
template<class T> inline bool ch_max(T&,T);
void Yes(bool f){
    if(f){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}
void YES(bool f){
    if(f){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << b-c << endl;
}

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


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

int main()
{
    int a, b;
    cin >> a >> b;
    for (int g = b; b > a; g--){
        if(b/g-(a-1)/g >=2){
            cout << g << endl;
            return 0;
        }
    }
}

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

#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define int ll
#define popcount(x) __builtin_popcountll(x)
#define pii pair<int , int>
#define arr array

const int mod = 1e9+7;

template <typename T>inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}

#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}

inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }

template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1}; //4 Direction
// char dc[] = {'D' , 'R' , 'U' , 'L'};

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

void solve(){
    int a , b;
    cin >> a>> b;
    int MAX_gcd = gcd(a , b);
    int flag = 1;
    for (int i = 1 ; i <= b ; i++){
        int n1 = ((a+i-1)/i)*i;
        int n2 = n1 + i;
        if (n1 >= a && n2 >= a && n1 <= b && n2 <= b){
            MAX_gcd = max(MAX_gcd , i);
        }
    }
    cout << MAX_gcd << endl;
}

int32_t main(){

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

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    // cin >> t;
    for (int tt = 0 ; tt < t ; tt++){
        // cout << "Case #" << (tt+1) <<": ";
        solve();
    }
}


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

int main(){
  double sx,sy,gx,gy;cin>>sx>>sy>>gx>>gy;
  gy*=-1;

  double a=(sy-gy)/(sx-gx);

  cout<<fixed<<setprecision(10)<<sx-sy/a<<endl;
}

#include<bits/stdc++.h>
// #pragma GCC target("fpmath=387") // Turns on excess precision
using namespace std;
const int p = 31;
const int m = 998244353;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef int in;
#define ar array
#define ff first
#define ss second
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
int main() {

    ld x = 0.0, y = 0.0, r = 0.0;
    cin>>x>>y>>r;
  	r = nextafter(r,INFINITY);
    ld xmn = (ld)(x - r), xmx = (ld)(x + r);
    ll xlf = ceil(xmn), xrt = floor(xmx);
    ll ans = 0;
    ll now = xlf;
    while (now <= xrt) {
        ld val = sqrtl(r*r-(x-now)*(x-now));
        ll a=ceil(y-val);
        ll b=floor(y+val);
        ans +=b-a+1;
        now++;
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string reorigin;
    cin >> reorigin;
    string origin = reorigin;
    reverse(origin.begin(), origin.end());
    if (origin.compare(reorigin) == 0){
        printf("Yes");
    }
    else{
        int size = origin.size();
        int i;
        for(i = 0; i < size; i++){
            if (origin[i] == '0'){
                continue;
            }
            else{
                break;
            }
        }
        int j;
        for(j = size-1; j >=0; j--){
            if(origin[j] == '0'){
                continue;
            }
            else{
                break;
            }
        }
        string substr = origin.substr(i, j-i + 1);
        string newstr = substr;
        reverse(substr.begin(), substr.end());
        if(newstr.compare(substr) == 0){
            cout <<"Yes";
        }
        else{
            cout << "No";
        }
    }
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 7;
const double PI = 3.14159265358979;
#define ALL(x) x.begin(),x.end()

bool isPal(string s){
    bool ret = true;
    for(int i = 0; i < s.size()/2; i++){
        if(s.at(i) != s.at(s.size()-1-i)){
            ret = false;
        }
    }
    return ret;
}

int main(){
    string n; cin >> n;
    for(int i = 0; i <= n.size(); i++){
        string zero = "";
        for(int j = 0; j < i; j++) zero += "0";
        string target = zero + n;
        if(isPal(target)){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}


#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//vector<int> bucket[MAX_N/1000];
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
/*#include<atcoder/all>
using namespace atcoder;
typedef __int128_t llint;*/

lint N,M,X,Y;

struct edge{lint to,cost,k;};
lint V;
vector<edge> G[200000]; // MAX_V
lint d[200000]; // MAX_V
void dijkstra(lint S){
    priority_queue<plint,vector<plint>,greater<plint>> que;
    fill(d,d+V,LINF);
    d[S]=0;
    que.push(plint(0,S));
    while(!que.empty()){
        plint p=que.top();
        que.pop();
        lint v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            lint apr=((d[v]+e.k-1)/e.k)*e.k+e.cost;
            if(d[e.to]>apr){
                d[e.to]=apr;
                que.push(plint(d[e.to],e.to));
            }
        }
    }
}

int main(void){
    cin >> N >> M >> X >> Y;
    V=N;
    X--,Y--;
    rep(i,M){
        lint a,b,t,k;
        cin >> a >> b >> t >> k;
        a--,b--;
        G[a].push_back({b,t,k});
        G[b].push_back({a,t,k});
    }
    dijkstra(X);
    if(d[Y]==LINF) cout << -1 << endl;
    else cout << d[Y] << endl;
}

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>  using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll           long long
#define rep(i,j,n)   for(int i=j;i<n;i++)
#define scn(a)       scanf("%d",&a)
#define scns(a,b)    scanf("%d %d",&a,&b)
#define print(a)     printf("%d\n",a)
#define vec          vector<int>
#define pb           emplace_back
#define pairs        pair<int,int>
#define f            first
#define s            second
#define all(v)       v.begin(),v.end()
#define mem(a,b)     memset(a,b,sizeof(a))
#define inf          1e18
const int mod = 1e9+7;
const int N = 5e5+5;

int n;
ll dis[N];
vector<tuple<int,int,int>> v1[N];

int main()
{
    int test; test = 1;

    while(test--)
    {
        int m,x,y; scns(n,m); scns(x,y);

        rep(i,0,m)
        {
            int u,v,wt,k; scns(u,v); scns(wt,k);

            v1[u].pb(v,wt,k), v1[v].pb(u,wt,k);
        }

        auto dijkstra = [&](int src)
        {
            rep(i,0,n+1)
            dis[i] = inf;

            dis[src] = 0;

            set<pair<ll,int>>ms; ms.emplace(0, src);

            int cnt = -1;

            while((int)ms.size()>0)
            {
                auto [_, u] = *ms.begin(); ms.erase(ms.begin());

                ++cnt;

                for(auto [v, wt, k]:v1[u])
                {
                    ll folds = ((dis[u]-1)/k + 1)*1LL*k;

                    ll cost = folds + wt;

                    if(cnt == 0)
                    folds = 0;

                    // cout<<folds<<" "<<u<<" "<<v<<endl;

                    if(dis[v] > folds + wt)
                    {
                        if(dis[v] != inf)
                        ms.erase({dis[v],v});

                        dis[v] = folds + wt; ms.emplace(dis[v],v);
                    }
                }
            }
        };

        dijkstra(x);

        ll ans = dis[y];

        if(dis[y] >= inf)
        ans = -1;

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

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    char ch[1010];
    int len,i,x;
    cin>>ch;
    len=strlen(ch);
    for(i=0;i<len;i++){
        x=i+1;
        if(x%2==0){
            if(ch[i]>=97 && ch[i]<=122){
                cout<<"No"<<"\n";
                return 0;
            }
        }
        else{
            if(ch[i]>=65 && ch[i]<=90){
                cout<<"No"<<"\n";
                return 0;
            }
        }
    }
    cout<<"Yes"<<"\n";

    return 0;
}

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

#define fi first
#define se second
#define rng(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define per(i, b) gnr(i, 0, b)
#define all(obj) begin(obj), end(obj)
#define allr(obj) rbegin(obj), rend(obj)
#define cinv(a) rep(i, (int)a.size()) cin >> a[i]
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<Pi> vp;
typedef vector<vp> vvp;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int di[] = {0, -1, 0, 1};
const int dj[] = {1, 0, -1, 0};
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e15;
const long double eps = 1e-10;
const char nl = '\n';

ll power(ll a, ll b) { return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; }

ll C(int n, int k)
{
	ll x = 1, y = 1;
	for (int i = 1; i <= k; ++i)
	{
		x = x * (n - i + 1) % MOD;
		y = y * i % MOD;
	}
	return x * power(y, MOD - 2) % MOD;
}

struct UF
{
	vi d;
	UF(int n) : d(n, -1) {}
	int root(int x)
	{
		if (d[x] < 0)
			return x;
		return d[x] = root(d[x]);
	}
	bool unite(int x, int 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(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -d[root(x)]; }
};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	deque<char> t;
	int rev = 0;
	rep(i, sz(s))
	{
		if (s[i] == 'R') rev = 1 - rev;
		else if (rev) t.push_front(s[i]);
		else t.push_back(s[i]);
	}
	string ans = "";
	if (!sz(t))
	{
		cout << ans << nl;
		return 0;
	}
	ans += t.front();
	t.pop_front();
	while (sz(t))
	{
		if (sz(ans) && t.front() == ans.back())
		{
			ans.pop_back();
		}
		else
		{
			ans += t.front();
		}
		t.pop_front();
	}
	if (rev && sz(ans)) reverse(all(ans));
	cout << ans << nl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
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;}

struct Edge{
	ll to;
	char c;
};
using pp = pair<ll,ll>;

int main(){
	// input
	ll n,m;
	cin >> n >> m;
	vector<vector<Edge>> graph(n);
	vector<vector<ll>> adj(n,vector<ll>(n,0));
	REP(i,m){
		int a,b;
		char c;
		cin >> a >> b >> c;
		a--; b--;
		adj[a][b] = 1;
		adj[b][a] = 1;
		{
			Edge e;
			e.to = b; e.c = c;
			graph[a].push_back(e);
		}
		if(a==b)continue;
		{
			Edge e;
			e.to = a; e.c = c;
			graph[b].push_back(e);
		}
	}

	vector<vector<vector<pp>>> dgraph(n);
	REP(i,n) dgraph[i].resize(n);

	REP(i,n){
		REP(j,n){
			for(auto ie:graph[i]){
				for(auto je:graph[j]){
					if(ie.c==je.c){
						dgraph[i][j].push_back(make_pair(ie.to, je.to));
					}
				}
			}
		}
	}

	const ll INF=1e18;
	queue<pp> q;
	vector<vector<ll>> cost(n,vector<ll>(n,INF));
	q.push({0, n-1});
	cost[0][n-1] = 0;
	while(!q.empty()){
		ll nowi = q.front().first;
		ll nowj = q.front().second;
		q.pop();
		ll co = cost[nowi][nowj];

		for(auto child : dgraph[nowi][nowj]){
			if(cost[child.first][child.second] != INF) continue;

			cost[child.first][child.second] = co + 1;
			q.push(child);
		}
	}

	ll ans = INF;
	REP(i,n){
		if(cost[i][i]==INF) continue;
		chmin(ans, cost[i][i]*2);
	}

	REP(i,n){
		REP(j,n){
			if(adj[i][j]==0) continue;

			if(cost[i][j]==INF)continue;
			chmin(ans, 2*cost[i][j] +1 );
		}
	}

	if(ans==INF){
		cout << "-1\n";
	}else{
		cout << ans << endl;
	}

	return 0;
}

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int, int> II;

int solve(int N, int M, std::vector<int>& A, std::vector<int>& B, std::vector<char>& C) {
	vector<vector<pair<int, char>>> edges(N);
	for (int i = 0; i < M; i++) {
		edges[A[i]].emplace_back(make_pair(B[i], C[i]));
		edges[B[i]].emplace_back(make_pair(A[i], C[i]));
	}
	vector<vector<int>> visited(N, vector<int>(N));
	vector<II> q;
	q.emplace_back(II(0, N - 1));
	int ans = 1 << 30;
	for (int c = 2; !q.empty(); c += 2) {
		vector<II> nq;
		for (auto f : q) {
			int f_from = f.first;
			int r_from = f.second;
			for (auto fe : edges[f_from]) {
				int f_to = fe.first;
				int f_color = fe.second;
				if (f_to == r_from) {
					ans = min(ans, c - 1);
				}
				for (auto re : edges[r_from]) {
					int r_to = re.first;
					int r_color = re.second;
//					if (f_from == r_to) {
//						ans = min(ans, c - 1);
//					}
					if (f_color != r_color) continue;
					if (f_to == r_to) {
						ans = min(ans, c);
					}
					II key(f_to, r_to);
					if (!visited[f_to][r_to]) {
						visited[f_to][r_to] = 1;
						nq.emplace_back(II(f_to, r_to));
					}
				}
			}
		}
		if (ans < 1 << 30) return ans;
		q = nq;
	}
	return -1;
}

int main() {
	int N, M;
	std::cin >> N >> M;
	std::vector<int> A(M), B(M);
	std::vector<char> C(M);
	for (int i = 0; i < M; i++) {
		std::cin >> A[i] >> B[i] >> C[i];
		--A[i], --B[i];
	}
	cout << solve(N, M, A, B, C) << endl;
	return 0;
}


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

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

    string s2 = s;
    reverse(s2.begin(), s2.end());

    if(s == s2){
        cout << "Yes";
        return 0;
    }

  	int index = 0;
    while(index<s2.size() && s2[index++] == '0'){
      s = "0" + s;
      s2 = s2 + "0";
      if(s == s2){
        cout<<"Yes";
        return 0;
      }
    }

    cout << "No";
}

#include<iostream>
#include<string>
using namespace std;
int ten(int num){
  int digit = 0;
  while(num!=0){
    num/=10;
    digit++;
  }
  return digit;
}

int main(void){
  int num;
  cin >> num;
  while(num > 0){
    if(num %10 == 0){
      num /= 10;
    }else{
      break;
    }
  }
  int num2 = 0;
  int digit = ten(num);
  if(digit % 2 == 0){
    while(num > num2){
      num2 = num2*10+num%10;
      num /= 10;
    }
  }else{
    for(int i = (digit-1)/2;i > 0;i--){
      num2 = num2*10+num%10;
      num /= 10;
    }
    num /= 10;
  }
  if(num == num2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <array>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>
#include<fstream>
#include<assert.h>

#include<stdio.h>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

int get_gcd(int n, int m) {
	if (n < m) swap(n, m);
	while (m) {
		swap(n, m);
		m %= n;
	}
	return n;
}

vector<int> get_divisor(int N)
{
	vector<int> ret;
	rep(i, 1, sqrt(N) + 1) {
		if (N % i == 0) {
			ret.push_back(i);
			if (i * i != N) ret.push_back(N / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}

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

	int N;
	cin >> N;

	vector<int> A(N);
	int mi = INF;

	map<int, int> dmap;
	rep(i, 0, N)
	{
		cin >> A[i];
		chmin(mi, A[i]);
		auto div = get_divisor(A[i]);
		for (auto v : div)
		{
			if (dmap.find(v) == dmap.end())dmap[v] = A[i];
			else dmap[v] = get_gcd(dmap[v], A[i]);
		}
	}

	int ans = 0;
	for (auto p : dmap)
	{
		if (p.first <= mi && p.first == p.second)ans++;
	}

	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=20000311;
const int maxn=2e5+100;
const int N=2e5+100;
const int M=(1<<20)+10;
const ll mm=(1LL<<32);

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

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

int fa[200],n;
int fd(int x)
{
    return x==fa[x]?x:fa[x]=fd(fa[x]);
}
void Unio(int x,int y)
{
    x=fd(x),y=fd(y);
    if(x!=y) fa[x]=y;
}
pii p[200];
double dist(pii x,pii y)
{
    return sqrt((x.X-y.X)*(x.X-y.X)+(x.Y-y.Y)*(x.Y-y.Y));
}
bool check(double r)
{
    int s=n+2,t=n+1;
    for(int i=1;i<=n+2;++i) fa[i]=i;
    for(int i=1;i<=n;++i)
    {
        if((double)(100-p[i].Y)<2*r) Unio(s,i);
        if((double)(p[i].Y+100)<2*r) Unio(t,i);
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            if(dist(p[i],p[j])<2*r) Unio(i,j);
        }
    }
    if(fd(s)==fd(t)) return 0;
    return 1;
}
int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;//cout.tie(0);
    cin>>n;
    rep1(i,n) cin>>p[i].X>>p[i].Y;
    double l=0.0,r=100.0;
    double ans;
    for(int i=1;i<=2000;++i)
    {
        double mid=(l+r)/2;
        if(check(mid)) ans=mid,l=mid;
        else r=mid;
    }
    printf("%.9f\n",ans);
    return 0;
}


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

int32_t main()
{
  int n;cin>>n;
  string s;string t;cin>>s>>t;
  int prev=-1;
  queue<int>q;
  int ans=0;
  for(int i=0;i<n;i++)
  {
    if (t[i] == '1')
      q.push(i);
        if (s[i] == '1')
        {
            if (prev != -1)
            {
                ans += i - prev;
                prev = -1;
            }
          	else
            {
                if (q.empty())
                    prev = i;
                 else
                 {
                    ans += i - q.front();
                    q.pop();
                 }
            }
        }
    }
  if(!q.empty() || prev!=-1)
    cout<<-1<<endl;
  else
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define ll long long
#define ull unsigned long long
#define y1 orzkcz
using namespace std;
const int N=500005;
int n,q1[N],q2[N];
char s[N],t[N];
ll res;
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	For(i,1,n) if (s[i]=='1') q1[++*q1]=i;
	For(i,1,n) if (t[i]=='1') q2[++*q2]=i;
	int p=1;
	For(i,1,*q2){
		for (;p<=*q1&&q2[i]>q1[p];p+=2)
			res+=q1[p+1]-q1[p];
		if (p>*q1) return puts("-1"),0;
		res+=q1[p]-q2[i]; ++p;
	}
	for (;p<=*q1;p+=2)
		res+=q1[p+1]-q1[p];
	if (p!=(*q1)+1)
		puts("-1");
	else
		printf("%lld\n",res);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int K = 305;
const int N = 200010;
const int MOD = 998244353;
const ll INV = 1 + MOD >> 1;

int n, k;
ll a[N], pwr[N], sum[K], two[K], comb[K][K];

int main() {
  cin >> n >> k;
  for (int i = 0; i <= k; ++i) comb[i][0] = 1;
  for (int i = 1; i <= k; ++i) for (int j = 1; j <= i; ++j) {
    comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % MOD;
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", a + i);
    pwr[i] = 1;
  }
  sum[0] = n, two[0] = 1;
  for (int x = 1; x <= k; ++x) {
    for (int i = 1; i <= n; ++i) {
      pwr[i] = pwr[i] * a[i] % MOD;
      sum[x] = (sum[x] + pwr[i]) % MOD;
    }
    two[x] = two[x - 1] * 2 % MOD;
  }
  for (int x = 1; x <= k; ++x) {
    ll ans = 0;
    for (int i = 0; i <= x; ++i) {
      ll cur = sum[i] * sum[x - i] % MOD;
      cur = cur * comb[x][i] % MOD;
      ans = (ans + cur) % MOD;
    }
    ans = (ans - two[x] * sum[x]) % MOD;
    ans += MOD, ans %= MOD, ans *= INV, ans %= MOD;
    printf("%lld\n", ans);
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef double db;
typedef pair<int, int> pii;typedef pair<ll, ll> pll;
typedef pair<int,ll> pil;typedef pair<ll,int> pli;
#define Fi first
#define Se second
#define _Out(a)	cerr<<#a<<" = "<<(a)<<endl
const int INF = 0x3f3f3f3f, MAXN = 1e6 + 50;
const ll LINF = 0x3f3f3f3f3f3f3f3f, MOD = 998244353;
const db Pi = acos(-1), EPS = 1e-6;
void test(){cerr << "\n";}template<typename T,typename...Args>void test(T x,Args...args){cerr<<x<<" ";test(args...);}
inline ll qpow(ll a, ll b){return b?((b&1)?a*qpow(a*a%MOD,b>>1)%MOD:qpow(a*a%MOD,b>>1))%MOD:1;}
inline ll qpow(ll a, ll b,ll c){return b?((b&1)?a*qpow(a*a%c,b>>1,c)%c:qpow(a*a%c,b>>1,c)) %c:1;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll cede(ll a,ll b){if(b<0)return cede(-a,-b);if(a<0)return a/b;return (a+b-1)/b;}
inline ll flde(ll a,ll b){if(b<0)return flde(-a,-b);if(a<0)return (a-b+1)/b;return a/b;}
inline int sign(db x){return x<-EPS ? -1:x>EPS;}
inline int dbcmp(db l,db r){return sign(l - r);}
namespace Fast_IO{ //orz laofu
    const int MAXL((1 << 18) + 1);int iof, iotp;
    char ioif[MAXL], *ioiS, *ioiT, ioof[MAXL],*iooS=ioof,*iooT=ioof+MAXL-1,ioc,iost[55];
    char Getchar(){
        if (ioiS == ioiT){
            ioiS=ioif;ioiT=ioiS+fread(ioif,1,MAXL,stdin);return (ioiS == ioiT ? EOF : *ioiS++);
        }else return (*ioiS++);
    }
    void Write(){fwrite(ioof,1,iooS-ioof,stdout);iooS=ioof;}
    void Putchar(char x){*iooS++ = x;if (iooS == iooT)Write();}
    inline int read(){
        int x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar();
        if(ioc==EOF)Write(),exit(0);
        for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof;
    }
    inline long long read_ll(){
        long long x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar();
        if(ioc==EOF)Write(),exit(0);
        for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof;
    }
    void Getstr(char *s, int &l){
        for(ioc=Getchar();ioc==' '||ioc=='\n'||ioc=='\t';)ioc=Getchar();
        if(ioc==EOF)Write(),exit(0);
        for(l=0;!(ioc==' '||ioc=='\n'||ioc=='\t'||ioc==EOF);ioc=Getchar())s[l++]=ioc;s[l] = 0;
    }
    template <class Int>void Print(Int x, char ch = '\0'){
        if(!x)Putchar('0');if(x<0)Putchar('-'),x=-x;while(x)iost[++iotp]=x%10+'0',x/=10;
        while(iotp)Putchar(iost[iotp--]);if (ch)Putchar(ch);
    }
    void Putstr(const char *s){for(int i=0,n=strlen(s);i<n;++i)Putchar(s[i]);}
} // namespace Fast_IO
using namespace Fast_IO;
ll fac[MAXN],invfac[MAXN];

void init()
{
    fac[0]=1;for(int i=1;i<MAXN;i++)fac[i]=fac[i-1]*i%MOD;
    invfac[MAXN-1]=qpow(fac[MAXN-1],MOD-2);
    for(int i=MAXN-2;i>=0;i--)invfac[i]=invfac[i+1]*(i+1)%MOD;

}
inline ll C(int n,int m)
{
    if(m<0||m>n)return 0;
    return fac[n]*invfac[m]%MOD*invfac[n-m]%MOD;
}
ll tot[333];
void work()
{
    int n=read(),k=read();
    for(int i=1;i<=n;i++)
    {
        ll x=read();
        ll now=1;
        for(int j=0;j<=k;j++)
        {
            tot[j]=(tot[j]+now)%MOD;
            now=now*x%MOD;
        }
    }
    ll mi2=1;
    for(int i=1;i<=k;i++)
    {
        mi2=mi2*2%MOD;
        ll ans=0;
        for(int j=0;j<=i;j++)
        {
            ans=(ans+tot[j]*tot[i-j]%MOD*C(i,j)%MOD)%MOD;
        }
        ans=(ans-tot[i]*mi2%MOD+MOD)*qpow(2,MOD-2)%MOD;
        printf("%lld\n",ans);
    }
}
int main()
{
    init();
    //std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //int T=read();for(int cas=1;cas<=T;cas++)
    //int T;scanf("%d",&T);for(int i=1;i<=T;i++)
    work();
    // Write();
}

/**
2
5 3 6
3 1 2 4 5

*/


#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>
#include <iomanip>

#include <fstream>

using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){fastio
    ll a,b,c;cin>>a>>b>>c;
    dd dp[101][101][101];
    rep(i,0,100){
        rep(j,0,100){
            rep(k,0,100){
                dp[i][j][k]=0.0;
            }
        }
    }
    dp[a][b][c]=1.0;
    rep(i,a,100){
        rep(j,b,100){
            rep(k,c,100){
                if(i+j+k<=1)continue;
                if((i==100 && j==100) || (j==100 && k==100) || (k==100 && i==100))continue;
                if(i==a && b==j && k==c)continue;
                if(i==100){
                    dp[i][j][k]+=(dp[i-1][j][k]*(i-1))/(i+j+k-1);
                }else if(j==100){
                    dp[i][j][k]+=(dp[i][j-1][k]*(j-1))/(i+j+k-1);
                }else if(k==100){
                    dp[i][j][k]+=(dp[i][j][k-1]*(k-1))/(i+j+k-1);
                }else{
                    if(i>0)dp[i][j][k]+=(dp[i-1][j][k]*(i-1))/(i+j+k-1);
                    if(j>0)dp[i][j][k]+=(dp[i][j-1][k]*(j-1))/(i+j+k-1);
                    if(k>0)dp[i][j][k]+=(dp[i][j][k-1]*(k-1))/(i+j+k-1);
                }
            }
        }
    }
    dd sum=0;
    rep(i,a,100){
        rep(j,b,100){
            rep(k,c,100){
                //cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j][k]<<endl;
                if(i==100 || j==100 || k==100){
                    sum+=(i+j+k-a-b-c)*dp[i][j][k];
                }
            }
        }
    }
    cout<<setprecision(20)<<sum<<endl;

    return 0;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

enum queryType { SUM, MAX, MIN };
template<typename T>
struct SegTree {
  int n;
  T init; // 単位元(初期値)
  vector<T> node;
  function<T(T&, T&)> calc; // 子ノード2つから親ノードのデータにする処理
  SegTree(int sz, queryType qtype) : n(1) {
    // 初期値と処理関数の設定
    switch (qtype) {
      case SUM:
        init = 0;
        calc = [](T& v1, T& v2) { return v1 + v2; };
        break;
      case MAX:
        init = std::numeric_limits<T>::lowest();
        calc = [](T& v1, T& v2) { return (v1 > v2) ? v1 : v2; };
        break;
      case MIN:
        init = std::numeric_limits<T>::max();
        calc = [](T& v1, T& v2) { return (v1 < v2) ? v1 : v2; };
        break;
    }
    while (n < sz) n *= 2; // 最下段のノード数は2のべき乗(n)
    node.resize(2 * n - 1, init); // セグメント木全体で必要なノード数は2n-1個である
  }
  SegTree(vector<T>& v, queryType qtype) : SegTree(v.size(), qtype) {
    // 最下段に値を入れたあとに、下の段から順番に値を入れる
    // 値を入れるには、自分の子の2値を参照すれば良い
    // ノードiの親は(i-1)/2、子は(2i+1,2i+2)で見つける
    for (int i = 0; i < v.size(); i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--) node[i] = calc(node[2 * i + 1], node[2 * i + 2]);
  }
  void update(int i, T v) {
    i += (n - 1); // 最下段のノードにアクセスする
    // 最下段のノードを更新したら、あとは親に上って更新していく
    node[i] = v;
    while (i > 0) {
      i = (i - 1) / 2; // 1つ親にする
      node[i] = calc(node[2 * i + 1], node[2 * i + 2]);
    }
  }
  // 要求区間 [a, b) 中の要素の最小値を答える
  // k := 自分がいるノードのインデックス、対象区間は [l, r) にあたる
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    // 最初に呼び出されたときの対象区間は [0, n)
    if (r < 0) r = n;
    // 要求区間と対象区間が交わらない -> 適当に返す
    if (r <= a || b <= l) return init;
    // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
    if (a <= l && r <= b) return node[k];
    // 要求区間が対象区間の一部を被覆 -> 子について探索を行う
    // 左側の子を vl ・ 右側の子を vr としている
    // 新しい対象区間は、現在の対象区間を半分に割ったもの
    T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return calc(vl, vr);
  }
};

void solve() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  vl c(n + 1);
  vl m(n + 1);
  rep(i, n) c[i + 1] += c[i] + a[i];
  rep(i, n) m[i + 1] = max(m[i], c[i] + a[i]);
  dump(a);
  dump(c);
  dump(m);
  ll x = 0;
  ll ans = -INF;
  rep(i, n) {
    ll nx = x + m[i];
    maxs(ans, nx);
    x += c[i + 1];
    maxs(ans, x);
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}


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

class union_find {
	const int N; // the number of nodes
	int M; // the number of trees
	std::vector<int> parent, sz;
public :
	union_find(const int& n) : N(n), M(n), parent(n, -1), sz(n, 1) {}

	const int& root(const int& k) {return ((parent[k] == -1)?k:(parent[k] = root(parent[k])));}
	bool is_united(const int& i, const int& j) {return (root(i) == root(j));}
	const int& count_trees() const {return M;}
	const int& size(const int& k) {return sz[root(k)];}

	bool unite(int i, int j) {
		i = root(i); j = root(j);
		if (i == j) return false;
		if (sz[i] < sz[j]) std::swap(i, j);
		sz[i] += sz[j];
		parent[j] = i;
		M--;
		return true;
	}
};

int main() {
	int N;
	std::cin >> N;
	int x[N], y[N];
	for (int i = 0; i < N; i++) std::cin >> x[i] >> y[i];

	double ok = 0, ng = 101;
	while (ng - ok > 0.00001) {
		double mid = (ok + ng) / 2;
		union_find uf(N + 2);
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if ((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) < 4 * mid * mid) uf.unite(i, j);
			}
		}
		for (int i = 0; i < N; i++) {
			if (100 - y[i] < mid * 2) uf.unite(i, N);
			if (y[i] + 100 < mid * 2) uf.unite(i, N + 1);
		}
		if (uf.is_united(N, N + 1)) ng = mid;
		else ok = mid;
	}

	std::cout << std::fixed << std::setprecision(5) << ok << '\n';
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 9223372036854775807;
const ll MOD = 1000000007;
const long double PI = acos(-1);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a, b) cout<<a<<" "<<b<<"\n"
#define o3(a, b, c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
#define i1(a) cin>>a
#define i2(a, b) cin>>a>>b
#define i3(a, b, c) cin>>a>>b>>c
#define i4(a, b, c, d) cin>>a>>b>>c>>d
#define fi first
#define se second

inline ll power(ll a, ll b, ll z = MOD)
{
	ll res = 1;
	a = (a%z);
	while(b)
	{
		if(b&1)
			res = (res*a)%z;
		a = (a*a)%z;
		b = b>>1;
	}
	return res;
}

inline ll inverse(ll a, ll z = MOD)
{
	return power(a, z-2, z);
}

ll extend(ll a, ll b, ll &x, ll &y)
{
	if(b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll g = extend(b, a%b, x1, y1);
	x = y1;
	y = x1- (a/b)*y1;
	return g;
}

class matrix
{
	public:
	ll n, aray[5][5], z = MOD-1;
	matrix(ll n)
	{
		this->n = n;
		for(ll i=0;i<n;i++)
		{
			for(ll j=0;j<n;j++)
				aray[i][j] = (i == j);
		}
	}
	matrix operator+(const matrix& a)
	{
		matrix ans = matrix(n);
		for(ll i=0;i<n;i++)
		{
			for(ll j=0;j<n;j++)
				ans.aray[i][j] = (a.aray[i][j] + aray[i][j])%z;
		}
		return ans;
	}
	matrix operator*(const matrix& a)
	{
		matrix ans = matrix(n);
		for(ll i=0;i<n;i++)
		{
			for(ll j=0;j<n;j++)
			{
				ans.aray[i][j] = 0;
				for(ll k=0;k<n;k++)
					ans.aray[i][j] = (ans.aray[i][j] + aray[i][k]*a.aray[k][j])%z;
			}
		}
		return ans;
	}
};

inline matrix mat_power(matrix x, ll b, ll z = MOD)
{
	matrix ans = matrix(x.n);
	while(b)
	{
		if(b&1)
			ans = ans*x;
		x = x*x;
		b = b>>1;
	}
	return ans;
}

// void build(ll node, ll l, ll r)
// {
//     lazy[node] = 0;
//     if(l == r)
//     {
//         tree[node] = aray[l];
//         return ;
//     }
//     ll mid = (l+r)>>1;
//     build(node<<1, l, mid);
//     build((node<<1)+1, mid+1, r);
//     tree[node] = tree[node<<1] + tree[(node<<1)+1];
//     return ;
// }

// void update(ll node, ll l, ll r, ll left, ll right, ll val)
// {
//     if(lazy[node] != 0)
//     {
//         tree[node] += (r-l+1)*lazy[node];
//         if(l != r)
//         {
//             lazy[node<<1] += lazy[node];
//             lazy[(node<<1)+1] += lazy[node];
//         }
//         lazy[node] = 0;
//     }
//     if(left > r || l > right)
//         return ;
//     if(left <= l && right >= r)
//     {
//         tree[node] += val*(r-l+1);
//         if(l != r)
//         {
//             lazy[node<<1] += val;
//             lazy[(node<<1)+1] += val;
//         }
//         return ;
//     }
//     ll mid = (l+r)>>1;
//     update(node<<1, l, mid, left, right, val);
//     update((node<<1)+1, mid+1, r, left, right, val);
//     tree[node] = tree[node<<1] + tree[(node<<1)+1];
//     return ;
// }

// ll query(ll node, ll l, ll r, ll left, ll right)
// {
//     if(left > r || l > right)
//         return 0;
//     if(lazy[node] != 0)
//     {
//         tree[node] += (r-l+1)*lazy[node];
//         if(l != r)
//         {
//             lazy[node<<1] += lazy[node];
//             lazy[(node<<1)+1] += lazy[node];
//         }
//         lazy[node] = 0;
//     }
//     if(left <= l && right >= r)
//         return tree[node];
//     ll mid = (l+r)>>1;
//     return query(node<<1, l, mid, left, right) + query((node<<1)+1, mid+1, r, left, right);
// }

ll x;

map<ll, ll> m;

ll f(ll a)
{
    if(m.count(a))
        return m[a];
    if(a == 1)
        return m[a] = abs(a-x);
    if(a&1)
        return m[a] = min(abs(a-x), min(f((a-1)>>1), f((a+1)>>1)) + 2);
    return m[a] = min(abs(a-x), f(a>>1)+1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll y;
    cin>>x>>y;
    cout<<f(y)<<"\n";
    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
long double pie = acos(-1) ;
ll INF = 1e18 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll extGCD(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x = 1 ;
        y = 0 ;
        return a ;
    }
    ll d = extGCD(b,a%b,y,x) ;
    y -= a/b*x ;
    return d ;
}
void fix_cout(){cout << fixed << setprecision(20) ;}
template<class T> void chmax(T &a,T &b){if(a<b) a = b ;}
template<class T> void chmin(T &a,T &b){if(a>b) a = b ;}

int main(){
    int n ; cin >> n ;
    VV<ll> c(n,V<ll>(n)) ;
    for(auto &i:c) for(auto &j:i) cin >> j ;
    V<pair<ll,ll>> a(n),b(n) ;
    a[0] = {1,0} ;
    for(int i=1;i<n;i++) a[i] = {1,a[i-1].second+c[0][i]-c[0][i-1]} ;
    b[0] = {-1,c[0][0]} ;
    for(int i=1;i<n;i++) b[i] = {-1,b[i-1].second+c[i][0]-c[i-1][0]} ;
    bool ok = true ;
    for(int i=0;i<n;i++) for(int j=0;j<n;j++){
        ok &= c[i][j]==(a[j].second+b[i].second) ;
    }
    ll mn=INF,mx=-INF ;
    for(int i=0;i<n;i++){
        mx = max(mx,-a[i].second) ;
        mn = min(mn,b[i].second) ;
    }
    ok &= mx<=mn ;
    if(!ok) cout << "No" << endl ;
    else{
        cout << "Yes" << endl ;
        ll x = mn ;
        for(int i=0;i<n;i++) cout << -x+b[i].second << (i+1==n?"\n":" ") ;
        for(int i=0;i<n;i++) cout << x+a[i].second << (i+1==n?"\n":" ") ;
    }
}

// URL
#include <iostream>
#include <vector>
using namespace std;

#define loop(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define pb push_back
#define sz size
#define rsz resize
typedef long long LL;
const char NL = '\n';
const char SP = ' ';
const char HB[] = "HOBA";
const LL llinf = 9e18;
const int iinf = 2e9;

ostream& operator<< (ostream& os, vector <int> v) {
  for (int i = 0; i < v.size(); i++) {
    os << v[i] << SP;
  }
  os << NL;
  return os;
}

int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n;
  m = n;
  int c[n][m];
  vector <int> b(m, iinf);
  vector <vector <int> > a(n);
  loop (i, 0, n) {
    a[i].rsz(m);
    loop (j, 0, m) {
      cin >> c[i][j];
    }
  }

  loop (j, 0, m) {
    loop (i, 0, n) {
      b[j] = min(b[j], c[i][j]);
    }
  }
  loop (j, 0, m) {
    loop (i, 0, n) {
      a[i][j] = c[i][j] - b[j];
    }
  }
  loop (j, 1, m) {
    loop (i, 0, n) {
      if (a[i][j] != a[i][j - 1]) {
        cout << "No\n";
        exit(0);
      }
    }
  }
  cout << "Yes\n";
  loop (i, 0, n) {
    cout << a[i][0] << SP;
  }
  cout << NL;
  loop (j, 0, m) {
    cout << b[j] << SP;
  }
  cout << NL;
  return 0;
}
/*
SAMPLE
*/


//ver 8.1
#include <bits/stdc++.h>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
#define each(x,v) for(auto& x : (v))
#define reps(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) ((a)<=(x)&&(x)<=(b))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;}
template<typename T> bool inside(T a,T b){auto it=a.begin()-1;each(x,b){it=find(it+1,a.end(),x);if(it==a.end())return false;}return true;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // ２点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO"  )
#define Yes(n) ((n) ? "Yes" : "No"  )
#define yes(n) ((n) ? "yes" : "no"  )

int main(){
  init();
  inl(n);
  V<ll> a(n);
  in1(a);
  map<ll,ll> m;
  rep(i,n){
    m[a[i]]++;
  }
  ll ans=n*(n-1)/2;
  each(x,m){
    ans-=x.se*(x.se-1)/2;
  }
  out(ans);
  return 0;
}

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

// For Policy Based DS
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// ---------------------------------------
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              emplace_back
#define mp              make_pair
#define pll             pair<int,int>
#define vll             vector<int>
#define vpll            vector<pair<int,int>>
#define all(c)          (c).begin(), (c).end()
#define bs              binary_search
#define pqb             priority_queue<int>
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define mem(arr,x)      memset(arr,x,sizeof(arr))
#define pi              3.14159265358979323846
#define inf             2000000000000000000
#define ps(x,y)         fixed<<setprecision(y)<<x
#define test(x)         int x; cin>>x;while(x--)

template<class A> void read(vector<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) {
  cin >> x;
}
void read(double& d) {
  string t;
  read(t);
  d = stod(t);
}
void read(long double& d) {
  string t;
  read(t);
  d = stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
  read(h);
  read(t...);
}
template<class A> void read(vector<A>& x) {
  for (auto &a : x)
    read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
  for (auto &a : x)
    read(a);
}

const int d4i[4] = { -1, 0, 1, 0};
const int d4j[4] = {0, 1, 0, -1};
const int d8i[8] = { -1, -1, 0, 1, 1, 1, 0, -1};
const int d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void c_p_c()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
int pow(int a, int b)
{
  int res = 1;
  while (b > 0)
  {
    if (b % 2)
      res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
int ncr(int  n, int k)
{ if (k == 0)
    return 1;
  if (k > n - k)
    k = n - k;
  int a = 1, b = 1, d;
  while (k)
  { a *= n; b *= k;
    d = __gcd(a, b);
    a /= d; b /= d;
    n--; k--;
  }
  return a;
}
/***************************CODE BEGINS**************************************/
void solve()
{
  int a, b;
  read(a, b);
  int x = 2 * a + 100;
  cout << x - b;
}
int32_t main()
{
  c_p_c();
  // test(x)
  solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk　bit目
#define vec(T) vector<T>
#define vvec(T) vec(vec(T))
using ll = long long;
using P = pair<int,int>;

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 ll llINF = 1LL << 60;
const int iINF = 1e9;

//------------------------------------------------

struct path{
    int to,id,dir;
    path(int to=0, int id=0, int dir=0):to(to),id(id),dir(dir){}
};

struct Solver{
    vec(int) ans;
    vvec(path) ps;

    void dfs(int now){
        for(auto psi:ps[now]){
            if(ans[psi.id]!=-1) continue;
            ans[psi.id]=psi.dir;
            dfs(psi.to);
        }
    }

    void solve(){
        int N,M;
        cin >> N >> M;

        vec(P) ed(M);
        ps = vvec(path)(N);
        rep(i,M){
            int a,b;
            cin >> a >> b;
            --a; --b;
            ed[i]=P(a,b);
            ps[a].emplace_back(b,i,0);
            ps[b].emplace_back(a,i,1);
        }

        vec(int) C(N);
        rep(i,N) cin >> C[i];

        ans = vec(int)(M,-1);
        rep(i,M){
            int a=ed[i].first;
            int b=ed[i].second;
            if(C[a]>C[b]) ans[i]=0;
            if(C[a]<C[b]) ans[i]=1;
        }

        rep(i,N) dfs(i);

        rep(i,M) cout << (ans[i]?"<-":"->") << endl;
    }
};

int main(){
    int testcasenum=1;
    //cin >> testcasenum;
    rep1(ti,testcasenum){
        Solver solver;
        solver.solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
#define maxn 3e5+50

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

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

 long long modpow(long long n, long long k,long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

vector<vector<pii>>adj(maxn);
vector<bool>vis(maxn,0),have(maxn,0);
vector<int>a(maxn),b(maxn),c(maxn),ans(maxn,0);
void dfs(int v){
   vis[v] = 1;
   for(auto i:adj[v]){
      int u = i.first,idx = i.second;
      if(have[idx]) continue;
      have[idx] = 1;
      if(u == b[idx]) ans[idx] = 1;
      dfs(u);
   }
}

void solve(){
    int n,m;cin >> n >> m;
    for(int i = 0;i<m;i++) cin >> a[i] >> b[i];
    for(int i = 1;i<=n;i++) cin >> c[i];
    for(int i = 0;i<m;i++){
        if(c[a[i]]>c[b[i]]) ans[i] = 1;
        else if(c[a[i]]==c[b[i]])
        {
           int v = a[i],u = b[i];
           adj[v].push_back({u,i});
           adj[u].push_back({v,i});
        }
    }
    for(int i = 1;i<=n;i++){
        if(!vis[i]) dfs(i);
    }
    for(int i = 0;i<m;i++){
        if(ans[i]) cout << "->" <<'\n';
        else cout << "<-" <<'\n';
    }
}

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


#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int MOD=1e9+9;

long long n,a[N],b[N];
int solve() {
    cin>>n;
    string s,str1="",str2="";
    cin>>s;
    for(int i=0;i<2*n;i++)
    {
        if(i<n)
            str1+=s[i];
        else
            str2+=s[i];
    }
    bool cur=0;
    int q;
    cin>>q;
    while(q--)
    {
        int t, i,j;
        cin>>t>>i>>j;
        i--;
        j--;
        if(i>j)
            swap(i,j);
        if(t==1 && cur==0)
        {
            if(i<n && j<n)
                swap(str1[i],str1[j]);
            else if(i>=n && j>=n)
                swap(str2[i-n],str2[j-n]);
            else
            {
                j-=(n);
                swap(str1[i],str2[j]);
            }
        }
        else if(t==1 && cur==1)
        {
            if(i<n && j<n)
                swap(str2[i],str2[j]);
            else if(i>=n && j>=n)
                swap(str1[i-n],str1[j-n]);
            else
            {
                j-=n;
                swap(str2[i],str1[j]);
            }
        }
        else
            cur^=1;
    }
    if(cur==0)
        cout<<str1<<str2;
    else
        cout<<str2<<str1;
    return 0;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt" ,"r" ,stdin);
    freopen("output.txt" ,"w" ,stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /*int t;
    cin>>t;
    while(t--)*/
        solve();
    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<random>
#include<map>
long long int realOdometer = 0;
long long int manhattanOdometer = 0;
long long int generalAverage = 0;
using namespace std;
int main(){
  pair<int, int>s, t;
  map<pair<pair<int, int>, pair<int, int>>, pair<int, int>>distance;
  int loopCount = 0;
  while(cin >> s.first >> s.second >> t.first >> t.second){
    string str = "";
    for(int i=0; i<abs(t.first-s.first); i++){
      str = str + (t.first-s.first>0? "D": "U");
    }
    for(int i=0; i<abs(t.second-s.second); i++){
      str = str + (t.second-s.second>0? "R": "L");
    }
    mt19937 g(loopCount);
    shuffle(str.begin(), str.end(), g);
    if(loopCount<2){
      cout << str << endl;
    }else{
      str.clear();
      pair<int, int>currentPos = s;
      while(currentPos!=t){
        if(currentPos.first==t.first||currentPos.second==t.second){
          if(currentPos.first==t.first){
            str.push_back(currentPos.second<t.second? 'R': 'L');
          }else{
            str.push_back(currentPos.first<t.first? 'D': 'U');
          }
        }else{
          pair<int, int>component0 = make_pair(currentPos.first, currentPos.second + (currentPos.second<t.second? +1: -1));
          pair<int, int>component1 = make_pair(currentPos.first + (currentPos.first<t.first? +1: -1), currentPos.second);
          pair<pair<int, int>, pair<int, int>>candidate0 = make_pair(currentPos, component0);
          pair<pair<int, int>, pair<int, int>>candidate1 = make_pair(currentPos, component1);
          if(candidate0.first>candidate0.second){
            swap(candidate0.first, candidate0.second);
          }
          if(candidate1.first>candidate1.second){
            swap(candidate1.first, candidate1.second);
          }
          int d0 = distance[candidate0].first!=0? distance[candidate0].first: generalAverage;
          int d1 = distance[candidate1].first!=0? distance[candidate1].first: generalAverage;
          if(d0<d1){
            str.push_back(currentPos.second<t.second? 'R': 'L');
          }else{
            str.push_back(currentPos.first<t.first? 'D': 'U');
          }
        }
        currentPos.first+= (str.back()=='D') - (str.back()=='U');
        currentPos.second+= (str.back()=='R') - (str.back()=='L');
      }
      cout << str << endl;
    }
    long long int D;
    cin >> D;
    realOdometer+= D;
    manhattanOdometer+= str.length();
    generalAverage = realOdometer/manhattanOdometer;
    int manhattan_d = str.length();
    vector<pair<pair<int, int>, pair<int, int>>>toDoList;
    for(int i=0; i<manhattan_d; i++){
      pair<int, int>temp1, temp2;
      if(i!=0){
        temp1 = toDoList.back().second;
      }else{
        temp1 = s;
      }
      auto convert = [&](char c){
        pair<int, int> val = temp1;
        if(c=='R'||c=='L'){
          val = make_pair(val.first, val.second + (c=='R'? +1: -1));
        }else{
          val = make_pair(val.first + (c=='D'? +1: -1), val.second);
        }
        return val;
      };
      temp2 = convert(str.at(i));
      toDoList.push_back(make_pair(temp1, temp2));
    }
    while(toDoList.size()!=0){
      if(toDoList.back().first>toDoList.back().second){
        swap(toDoList.back().first, toDoList.back().second);
      }
      distance[toDoList.back()].second++;
      distance[toDoList.back()].first =
        (distance[toDoList.back()].first * (distance[toDoList.back()].second-1)
        + D/manhattan_d)/distance[toDoList.back()].second;
      toDoList.pop_back();
    }
    loopCount++;
  }
  return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, string>> V(M);
	string s;
	rep(i, M) {
		cin >> s;
		V[i] = {s.size(), s};
	}
	sort(all(V));
	vector<vector<string>> T(8);
	rep(i, M) {
		T[(V[i].second[0]-'A')].pb(V[i].second);
	}

	int a=0, b=0, c=0, x, y, z;
	vi v(8);
	vector<string> S(20);
	rep(i, M) {
		s = T[b][v[b]];
		if (S[a].size() + s.size() > 20) a++;
		if (a == 20) break;
		if (S[a].size()) S[a] = S[a].substr(0, S[a].size()-1);
		S[a] += s;
		v[b] = (v[b]+1)%T[b].size();
		b = s[s.size()-1]-'A';
	}
	rep(i, 20) {
		rep(j, 20) {
			if (S[i].size() < 20) S[i] += 'A' + rand()%8;
		}
		std::cout << S[i] << '\n';
	}
}

    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>

    using namespace std;
    using namespace __gnu_pbds;

    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define int long long
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>

    #define re(t) ll t;cin>>t;
    #define all(value) value.begin(),value.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)

    #define what(value) cerr << #value << " is " << value << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;

    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> omultiset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> oset;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> oset1;

/*.....................................................................................................................*/

    //a.erase(unique(a.begin(),a.end()),a.end());
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const int mod=  998244353 ,  inf =1e18;

    long long binpow(int a,int b,int m)
    {
        a %= m;int res = 1;
        while (b > 0)
        {
            if (b & 1)res=(res*a)%m;
            a=(a*a)%m  ;    b/=2;
        }
        return res;
    }
    int modinv(int n,int m) {return binpow(n,m-2,m);}
    const ll  man =(int)2e5+5;

/*......................................................................................................................*/

signed main()
{
    fast;
    int a,b,c;
    cin>>a>>b>>c;
    int ans=1;
    ans=(ans*(a))%mod;
    ans=(ans*(a+1))%mod;
    ans=(ans*modinv(2,mod))%mod;
    ans=(ans*(b))%mod;
    ans=(ans*(b+1))%mod;
    ans=(ans*modinv(2,mod))%mod;
    ans=(ans*(c))%mod;
    ans=(ans*(c+1))%mod;
    ans=(ans*modinv(2,mod))%mod;
    cout<<ans<<endl;
}


#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 998244353;
const int N = 2e5 + 5;

int i, n;
string s;

void solve()
{
    cin >> s;
    map<int, int> freq;
    for (char c : s)
    {
        freq[c - '0']++;
    }
    if (sz(s) == 1)
    {
        if (s == "8")
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
        return;
    }
    if (sz(s) == 2)
    {
        for (i = 16; i < 100; i += 8)
        {
            int a = i / 10, b = i % 10;
            freq[a]--;
            freq[b]--;
            if (freq[a] >= 0 && freq[b] >= 0 && a > 0 && b > 0)
            {
                cout << "Yes" << endl;
                return;
            }
            freq[a]++;
            freq[b]++;
        }
        cout << "No" << endl;
        return;
    }
    for (i = 112; i < 1000; i += 8)
    {
        int a = i / 100, b = (i / 10) % 10, c = i % 10;
        freq[a]--;
        freq[b]--;
        freq[c]--;
        if (a > 0 && b > 0 && c > 0)
        {
            if (freq[a] >= 0 && freq[b] >= 0 && freq[c] >= 0)
            {
                cout << "Yes" << endl;
                return;
            }
        }
        freq[a]++;
        freq[b]++;
        freq[c]++;
    }
    cout << "No" << endl;
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fastio;
    int t;
    //cin >> t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}

// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2e3 + 5;
long long mod = 1e9 + 7;
const int lim = 700;
const int lg = 19;
const long double eps = 1e-6;
ll a[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("tests.inp", "r")){
        freopen("tests.inp", "r", stdin);
        freopen("tests.out", "w", stdout);
    }
    ll n;
    cin >> n;
    ll mn = 1e9;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        mn = min(a[i], mn);
    }
    unordered_map<ll, ll> mem;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j * j <= a[i] && j <= mn; j++){
            if ((a[i] % j) == 0){
                mem[j] = __gcd(mem[j], a[i]);
                if ((a[i] / j) <= mn){
                    mem[a[i] / j] = __gcd(mem[a[i] / j], a[i]);
                }
            }
        }
    }
    ll ans = 0;
    for (auto j : mem){
        if (j.first == j.second) ans++;
    }
    cout << ans;
}
/*
Ans:

Out:
*/


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#pragma GCC optimize("Ofast")
using namespace         std;
//#define                 int long long
#define                 double long double
#define                 fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ArrayFill(arr,a)       memset(arr,a,sizeof arr)
#define                 endl '\n'
#define countBit(x)     __builtin_popcountll(x)
#define all(x)          x.begin() , x.end()
#define ln              cout<<'\n';
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> oset;

int ceil(int a,int b){return (a+b-1)/b;}
#define sim template < class c
#define ris return * this
#define dor > debug_ & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug_&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug_ {~debug_() { cerr << endl; }eni(!=) cerr << boolalpha << i; ris; }eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d){*this << "[";for (auto it = d.b; it != d.e; ++it)*this << ", " + 2 * (it == d.b) << *it;ris << "]";}};
#define db(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define debug(x) debug_() << db(x)

const int MOD = 1000000007ll;
const int N = 1e4+5;
const int inf = MOD;
int A[N];
signed main(){
    fast;
    int n;
    cin >> n;
    for(int i=0;i<n;++i)cin >> A[i];
    int ans=0;
    for(int i=0;i<n;++i){
        int mn = A[i];
        int cur = A[i];
        ans=max(ans,cur);
        int cnt=1;
        for(int j=i+1;j<n;++j){
            mn = min(A[j],mn);
            cur = mn*(++cnt);
            ans=max(ans,cur);
        }
        //debug(ans);
    }
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vll vector<long long>
#define pll pair<long long, long long>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1e18

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;

struct segTree
{
  ll size;
  vll data, delta; // delta contains operations
  ll neutral;

  void init(ll n)
  {
    size = 1;
    while (size < n)
      size *= 2ll;
    data.assign(2 * size, 0ll); // fill depending on what data stores
    delta.assign(2 * size, 0ll);
    neutral = 0;
  }

  ll op(ll a, ll b) // used in update , query , prop
  {
    return a + b;
  }

  ll op2(ll a,ll b)
  {
    return min(a,b);
  }

  void update(ll node) // update parent
  {
    ll left = 2 * node + 1;
    ll right = 2 * node + 2;
    data[node] = op2(data[left]+delta[left], data[right]+delta[right]);
  }

  void prop(ll node)
  {
    ll left = 2 * node + 1;
    ll right = 2 * node + 2;
    // operation here depends on what we modify
    delta[left] += delta[node];
    delta[right] += delta[node];
    delta[node] = 0;
  }

  void modify(ll l, ll r, ll val, ll node, ll lo, ll hi)
  {
    if (l > hi || r < lo)
    {
      return;
    }
    if (l <= lo && r >= hi)
    {
      delta[node] += val;
      return;
    }
    ll mid = lo + (hi - lo) / 2;
    if (lo != hi)
    {
      prop(node);
    }
    modify(l, r, val, 2 * node + 1, lo, mid);
    modify(l, r, val, 2 * node + 2, mid + 1, hi);
    update(node);
  }

  void modify(ll l, ll r, ll val) // set data[indx] = val
  {
    modify(l, r, val, 0, 0, size - 1);
  }

  ll query(ll l, ll r, ll node, ll lo, ll hi)
  {
    if (l > hi || r < lo)
    {
      return INF;
    }
    if (l <= lo && r >= hi)
    {
      return data[node] + delta[node];
    }
    if (lo != hi)
    {
      prop(node);
    }
    ll mid = lo + (hi - lo) / 2;
    ll left_val = query(l, r, 2 * node + 1, lo, mid);
    ll right_val = query(l, r, 2 * node + 2, mid + 1, hi);
    update(node);
    return op2(left_val, right_val);
  }

  ll query(ll l, ll r)
  {
    return query(l, r, 0, 0, size - 1);
  }
};

void solve()
{
  ll n;
  cin>>n;
  ll i,j;
  ll a[n];
  for(i=0;i<n;i++)cin>>a[i];
  ll res=0;
  segTree seg;
  seg.init(n);
  for(i=0;i<n;i++)
  {
    seg.modify(i,i,a[i]);
  }
  for(i=0;i<n;i++)
  {
    ll mini = INF;
    for(j=i;j<n;j++)
    {
      mini = min(mini,a[j]);
      res=max(res,mini*(j-i+1));
    }
  }
  cout<<res<<"\n";

}

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

if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);

ll t=1;

// cin>>t;

while(t--)
{
solve();
}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	if(n%2==0)
	cout<<"White"<<endl;
	else cout<<"Black"<<endl;

	}

#include <bits/stdc++.h>
using namespace std;
template <class c>
struct re {
	c b, e;
};
template <class c>
re<c> range(c i, c j) { return re<c>{i, j}; }
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
	~debug()
	{
		cerr << endl;
	}
	template <class c>
	typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i)
	{
		cerr << boolalpha << i;
		return *this;
	}
	template <class c>
	typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i)
	{
		return *this << range(begin(i), end(i));
	}
	template <class c, class b>
	debug& operator<<(pair<b, c> d)
	{
		return *this << "(" << d.first << ", " << d.second << ")";
	}
	template <class c>
	debug& operator<<(re<c> d)
	{
		*this << "[";
		for (auto it = d.b; it != d.e; ++it)
		{
			*this << ", " + 2 * (it == d.b) << *it;
		}
		return *this << "]";
	}
#else
	template <class c>
	debug& operator<<(const c&)
	{
		return *this;
	}
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define dbg debug()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
typedef long long ll;

void genp(vector<int> &a, int n)  {
	vector<bool> p(1001, true);
	for(int i = 2; i <= 1000; i++) {
		if(p[i]) {
			for(int j = i*i; j <= 1000; j += i) p[j] = false;
		}
	}
	for(int i = 2; (int)a.size() < n; i++) {
		if(p[i])	a.push_back(i);
	}
}

void gen(vector<int> &a, int n) {
	a.push_back(2);
	if(n == 1) {
		return;
	}
	int b = 0;
	for(int i = 3; i > 0; i++) {
		for(int j = 2; j <= i/2; j++) {
			if(i%j == 0) {
				b = 1;
				break;
			}
		}
		if(b == 0) a.push_back(i);
		b = 0;
		if((int)a.size() == n) break;
	}
}

void t_c() {
	int n;
	cin >> n;
	puts(n&1? "Black": "White");
}

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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans = 0;
char battle(char a, char b){
    if(a == b) return a;
    else{
        string s = "";
        s.push_back(a);
        s.push_back(b);
        sort(s.begin(), s.end());//PRS
        if(s == "PR") return 'P';
        else if(s == "PS") return 'S';
        else return 'R';
    }
}
string winner(string s){
    string ret = "";
    for(int i=0; i<s.size(); i += 2){
        ret.push_back(battle(s[i], s[i+1]));
    }
    return ret;
}
void Main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    string s2 = s;
    For(i,0,k){
        if(s.size() % 2 == 1)s = s + s;
        s = winner(s);
    }
    auto ans1 = s[0];
    cout << s[0] << endl;
    /*
    s = s2 + s2;
    int pw = 1;
    For(i,0,k) pw *= 2;
    while(s.size() < pw) s = s + s;
    while(s.size() > pw) s.pop_back();
    //cout << s << endl;
    while(s.size() > 1){
        s = winner(s);
        //cout << s << endl;
    }
    //string nexts = winner(s);
    //cout << nexts << endl;
    auto ans2 = s[0];
    cout << ans1 << " " << ans2 << endl;
    */
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define MP make_pair
#define PB push_back
#define REP(i, L, R) for (int i = L; i < (R); ++i)
#define SZ(x) (int)x.size()

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

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

vector<int> compress(vector<int> &y)
{
    vector<int> v(y);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for (int i = 0; i < SZ(y); ++i)
    {
        y[i] = lower_bound(v.begin(), v.end(), y[i]) - v.begin();
    }

    return v;
}

struct bit
{
    int n;
    vector<ll> v;

    void init(int sz)
    {
        n = sz;
        v.assign(n + 1, 0);
    }

    // sum([0..i])
    ll prefix_sum(int i)
    {
        // internally we use 1-based index
        int _i = i + 1;
        ll s = 0LL;
        while (_i)
        {
            s += v[_i];
            _i -= (_i & -_i);
        }
        return s;
    }

    // sum([i..end])
    ll suffix_sum(int i)
    {
        if (i == 0)
        {
            return prefix_sum(n - 1);
        }

        return prefix_sum(n - 1) - prefix_sum(i - 1);
    }

    void incr(int i, ll a)
    {
        // internally we use 1-based indexing
        int _i = i + 1;
        while (_i <= n)
        {
            v[_i] += a;
            _i += (_i & -_i);
        }
    }
};

const int MAXN = 200005;
void solve()
{
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> t(q + 1), x(q + 1), y(q + 1, 0);
    vector<int> a(n, 0), b(m, 0);
    REP(i, 1, q + 1)
    {
        cin >> t[i] >> x[i] >> y[i];
        --x[i]; // 0-based index
    }

    auto vy = compress(y);
    // NOTE 1(coordinate compression): after compression, y is compressed to [0, q] and vy maps from a compressed y in [0,q] to its original value.

    // r1[i] = #i in b; r2[i] = sum of all i's in b.
    // c1[i] = #i in a; c2[i] = sum of all i's in a.
    bit r1, r2, c1, c2;
    r1.init(MAXN);
    r2.init(MAXN);
    c1.init(MAXN);
    c2.init(MAXN);
    // Initially, all b are 0
    r1.incr(0, m);
    // Initially, all a are 0
    c1.incr(0, n);

    ll ans = 0LL;
    REP(i, 1, q + 1)
    {
        if (t[i] == 1)
        {
            // a[x[i]] = y[i]
            int v = a[x[i]];
            ans -= vy[v] * r1.prefix_sum(v);
            ans -= r2.suffix_sum(v + 1);
            c1.incr(v, -1);
            c2.incr(v, -vy[v]);

            a[x[i]] = y[i];
            c1.incr(y[i], 1);
            c2.incr(y[i], vy[y[i]]);
            ans += vy[y[i]] * r1.prefix_sum(y[i]);
            ans += r2.suffix_sum(y[i] + 1);
        }
        else
        {
            // b[x[i]] = y[i]
            int v = b[x[i]];
            ans -= vy[v] * c1.prefix_sum(v);
            ans -= c2.suffix_sum(v + 1);
            r1.incr(v, -1);
            r2.incr(v, -vy[v]);

            b[x[i]] = y[i];
            r1.incr(y[i], 1);
            r2.incr(y[i], vy[y[i]]);
            ans += vy[y[i]] * c1.prefix_sum(y[i]);
            ans += c2.suffix_sum(y[i] + 1);
        }
        cout << ans << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    while (T--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
#pragma GCC optimize("-O3")
#define endl "\n"
#define mp make_pair
#define st first
#define nd second
#define pii pair<int, int>
#define pb push_back
#define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(12), cin.tie(0), cout.tie(0);
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FWD(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fwd(i, a, b) for (int i = (a); i < (b); ++i)
#define all(c) (c).begin(), (c).end()
#define sz(X) (int)((X).size())
#define what(x) cerr << #x << " is " << x << endl;

ostream &operator<<(ostream &out, string str) {
   for (char c : str)
      out << c;
   return out;
}
template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.st << ", " << p.nd << ")"; }
template <class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
   out << '{';
   for (auto it = a.begin(); it != a.end(); it = next(it))
      out << (it != a.begin() ? ", " : "") << *it;
   return out << '}';
}
void dump() { cerr << "\n"; }
template <class T, class... Ts> void dump(T a, Ts... x) {
   cerr << a << ", ";
   dump(x...);
}
#define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)

int n;
string S, T;

int32_t main() {
   _upgrade;
   cin >> n >> S >> T;
   //    reverse(all(S));
   //    reverse(all(T));
   long long cnt = 0;
   queue<int> plus;

   rep(i, n) {
      if (S[i] == '0' && T[i] == '1') {
         plus.push(i);
      }
      if (S[i] == '1' && T[i] == '0') {
         if (!plus.empty()) {
            int a = plus.front();
            plus.pop();
            cnt += (i - a);
         } else
            plus.push(i);
      }
   }
   if (!plus.empty()) {
      cout << -1 << endl;
      return 0;
   }
   cout << cnt << endl;
}


#include"bits/stdc++.h"
using namespace std;
#define int long long
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 1000000007
int power(int n, int k) {
    if (k == 0) {
        return 1;
    }
    int curr = power(n, k / 2);
    if (k % 2 == 0) {
        return ((curr % mod * curr % mod) % mod);
    }
    else {
        return ((n % mod * curr % mod * curr % mod) % mod);
    }
}
int min(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}
bool compare(int a, int b) {
    return a > b;
}

int32_t main() {
    fio;
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b) {
        cout << c << endl;
    }
    else if (b == c) {
        cout << a << endl;
    }
    else if (a == c) {
        cout << b << endl;
    }
    else {
        cout << "0" << endl;
    }
    return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define f1 first
#define f2 second
#define ll long long
#define pii pair<int,int>
#define fastio() cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)          //no scanf
#define fileio(code) freopen("code.in","r",stdin);freopen("code.out","w",stdout)  //file name
using namespace std;

ll t,x,y,z,n;

bool ff(int a,int b,int c,int d){
	if((a-b==c-d) || (a+b==c+d) || (abs(a-c)+abs(b-d)<4)) return true;
	return false;
}

char ch;
int32_t main(){
	fastio();
	//fileio(code);
	cin>>x>>y>>z>>t;

	if(x==z && y==t) cout<<"0";
	else if(ff(x,y,z,t)) cout<<"1";
	else if(ff(x-3,y,z,t)) cout<<"2";
	else if(ff(x-2,y-1,z,t)) cout<<"2";
	else if(ff(x-2,y,z,t)) cout<<"2";
	else if(ff(x-2,y+1,z,t)) cout<<"2";
	else if(ff(x-1,y-2,z,t)) cout<<"2";
	else if(ff(x-1,y-1,z,t)) cout<<"2";
	else if(ff(x-1,y,z,t)) cout<<"2";
	else if(ff(x-1,y+1,z,t)) cout<<"2";
	else if(ff(x-1,y+2,z,t)) cout<<"2";
	else if(ff(x,y-3,z,t)) cout<<"2";
	else if(ff(x,y-2,z,t)) cout<<"2";
	else if(ff(x,y-1,z,t)) cout<<"2";
	else if(ff(x,y+1,z,t)) cout<<"2";
	else if(ff(x,y+2,z,t)) cout<<"2";
	else if(ff(x,y+3,z,t)) cout<<"2";
	else if(ff(x+1,y-2,z,t)) cout<<"2";
	else if(ff(x+1,y-1,z,t)) cout<<"2";
	else if(ff(x+1,y,z,t)) cout<<"2";
	else if(ff(x+1,y+1,z,t)) cout<<"2";
	else if(ff(x+1,y+2,z,t)) cout<<"2";
	else if(ff(x+2,y-1,z,t)) cout<<"2";
	else if(ff(x+2,y,z,t)) cout<<"2";
	else if(ff(x+2,y+1,z,t)) cout<<"2";
	else if(ff(x+3,y,z,t)) cout<<"2";
	else if((abs(x-z)+abs(y-t))%2==0) cout<<"2";
	else cout<<"3";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  long double n;cin>>n;
  long double ans=0;
  for(int i=1;i<n;i++)ans+=n/i;
  cout<<setprecision(16)<<ans<<endl;
}

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

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

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

// edit

void solve() {
    int N;
    cin >> N;
    vector<ld> dp(N + 1);
    dp[N] = 0;
    for (int x = N - 1; x >= 0; --x) {
        dp[x] = dp[x + 1] + 1. * N / (N - x);
    }
//    cout << dp << endl;
    cout << dp[1] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();

    return 0;
}