#pragma GCC optimize("O2")
#pragma GCC target("avx")
#pragma clang optimize on
#include <cstdio>
#include <functional>
#include <queue>
#include <tuple>
using namespace std;

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

int main() {
    int_fast32_t R, C;
    scanf("%d%d", &R, &C);
    int_fast32_t A[250000], B[250000];
    int_fast32_t dist[500000], seen[500000] = {0}, cost, pt, to_hide = R * C;
    priority_queue<pair<int_fast32_t, int_fast32_t>, vector<pair<int_fast32_t, int_fast32_t>>,
                   greater<pair<int_fast32_t, int_fast32_t>>>
        queue;
    for(int_fast32_t i = 0; i < R * C; ++i)
        if(i % C != C - 1) A[i] = get_digit();
    for(int_fast32_t i = 0; i < (R - 1) * C; ++i) B[i] = get_digit();
    for(int_fast32_t i = 1; i < to_hide + to_hide; ++i) dist[i] = 10000000;
    queue.emplace(pair<int_fast32_t, int_fast32_t>(0, 0));
    while(!queue.empty()) {
        tie(cost, pt) = queue.top();
        if(pt == to_hide - 1) break;
        queue.pop();
        seen[pt] = true;
        if(pt < to_hide) {
            if(!seen[pt + 1] && pt % C != C - 1) {
                if(cost + A[pt] < dist[pt + 1]) {
                    dist[pt + 1] = cost + A[pt];
                    queue.emplace(pair<int_fast32_t, int_fast32_t>(dist[pt + 1], pt + 1));
                }
            }
            if(!seen[pt - 1] && pt % C != 0) {
                if(cost + A[pt - 1] < dist[pt - 1]) {
                    dist[pt - 1] = cost + A[pt - 1];
                    queue.emplace(pair<int_fast32_t, int_fast32_t>(dist[pt - 1], pt - 1));
                }
            }
            if(!seen[pt + C] && pt < to_hide - C) {
                if(cost + B[pt] < dist[pt + C]) {
                    dist[pt + C] = cost + B[pt];
                    queue.emplace(pair<int_fast32_t, int_fast32_t>(dist[pt + C], pt + C));
                }
            }
            if(!seen[pt + to_hide] && cost + 1 < dist[pt + to_hide]) {
                dist[pt + to_hide] = cost + 1;
                queue.emplace(pair<int_fast32_t, int_fast32_t>(dist[pt + to_hide], pt + to_hide));
            }
        } else {
            if(to_hide < pt - C && !seen[pt - C] && cost + 1 < dist[pt - C]) {
                dist[pt - C] = cost + 1;
                queue.emplace(pair<int_fast32_t, int_fast32_t>(cost + 1, pt - C));
            }
            if(!seen[pt - to_hide] && cost < dist[pt - to_hide]) {
                dist[pt - to_hide] = cost;
                queue.emplace(pair<int_fast32_t, int_fast32_t>(cost, pt - to_hide));
            }
        }
    }
    printf("%d\n", dist[to_hide - 1]);
}

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

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

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
using vii = vector<pii>;
using viii = vector<tiii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 505;

int R, C;
int A[N][N];
int B[N][N];
viii g[N + N][N + N];

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

    cin >> R >> C;

    for (int r = 1; r <= R; r++) {
        for (int c = 1; c <= C - 1; c++) {
            cin >> A[r][c];
        }
    }

    for (int r = 1; r <= R - 1; r++) {
        for (int c = 1; c <= C; c++) {
            cin >> B[r][c];
        }
    }

    for (int r = 1; r <= R; r++) {
        for (int c = 1; c <= C; c++) {
            if (c + 1 <= C)
                g[r][c].pb({r, c + 1, A[r][c]});

            if (c - 1 >= 1)
                g[r][c].pb({r, c - 1, A[r][c - 1]});

            if (r + 1 <= R)
                g[r][c].pb({r + 1, c, B[r][c]});

            g[r][c].pb({r + R, c + C, 1});
            g[r + R][c + C].pb({r, c, 0});
            if (r - 1 >= 1) {
                g[r + R][c + C].pb({r - 1 + R, c + C, 1});
            }
        }
    }

    auto dijkstra = [&] (int x0, int y0) {
        vector<vector<int>> dist(2*R + 1, vector<int>(2*C + 1, INF));
        dist[x0][y0] = 0;

        set<tiii> S;
        S.insert({0, x0, y0});

        while (!S.empty()) {
            auto [d, x1, y1] = *S.begin();
            S.erase(S.begin());

            for (auto [x2, y2, z]: g[x1][y1]) {
                if (dist[x2][y2] > d + z) {
                    S.erase({dist[x2][y2], x2, y2});
                    dist[x2][y2] = d + z;
                    S.insert({dist[x2][y2], x2, y2});
                }
            }
        }

        return dist[R][C];
    };

    cout << dijkstra(1, 1) << "\n";
}


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

int a, b, c;
double dp[105][105][105];

double solve(int a, int b, int c) {
    if(dp[a][b][c])
        return dp[a][b][c];
    if(a==100 or b==100 or c==100)
        return 0;
    double ans = 0;
    ans += (solve(a+1,b,c)+1)*a/(a+b+c);
    ans += (solve(a,b+1,c)+1)*b/(a+b+c);
    ans += (solve(a,b,c+1)+1)*c/(a+b+c);
    dp[a][b][c] = ans;
    return ans;
}

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

    cin >> a >> b >> c;
    cout << setprecision(10) << fixed << solve(a, b, c);
    return 0;
}

//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define P pair<ll,ll>
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;
const ll M = 1000000007;

ll lmax(ll x,ll y){
  if(x < y) return y;
  else return x;
}

ll lmin(ll x, ll y){
  if(x > y)return y;
  else return x;
}

ll gen(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y%2 == 1){
    return ((x%M)*gen(x,y-1)%M)%M;
  }else{
    ll res = gen(x,y/2)%M;
    return ((res%M)*(res%M))%M;
  }
}

ll gcd(ll x, ll y){
  if(x < y) swap(x,y);
  if(y == 0) return x;
  return gcd(y,x%y);
}

ll lcm(ll x,ll y){
  ll s = gcd(x,y);
  x /= s;
  y /= s;
  return x*y*s;
}

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> a(h);
  rep(i,h) cin >> a[i];
  pair<int,int> s,g;
  vector<vector<pair<int,int>>>  p(26);
  vector<int> sumi(26,1);
  rep(i,h)rep(j,w){
    if(a[i][j] == 'S'){
      s.first = i;
      s.second = j;
    }
    else if(a[i][j] == 'G'){
      g.first = i;
      g.second = j;
    }else if(a[i][j] != '.' && a[i][j] != '#'){
      char mozi = a[i][j];
      p[mozi-'a'].push_back(make_pair(i,j));
    }else{
      continue;
    }
  }
  queue<pair<int,int>> q;
  vector<int> di = {0,1,0,-1}, dj = {1,0,-1,0};
  vector<vector<int>> ans(h,vector<int>(w,-1));
  ans[s.first][s.second] = 0;
  q.push(s);
  ll cnt = 0;
  while(!q.empty()){
    int i = q.front().first,j = q.front().second;
    rep(k,4){
      cnt++;
      int ni = i+di[k],nj = j+dj[k];
      if(ni < 0 || ni >= h || nj < 0 || nj >= w)continue;
      if(a[ni][nj] == '#')continue;
      if(a[ni][nj] == 'S')continue;
      if(a[ni][nj] == 'G'){
        if(ans[ni][nj] == -1) ans[ni][nj] = ans[i][j] + 1;
        else ans[ni][nj] = min(ans[i][j] + 1,ans[ni][nj]);
      }
      else if(a[ni][nj] == '.'){
        if(ans[ni][nj] == -1){
          ans[ni][nj] = ans[i][j] + 1;
          q.push(make_pair(ni,nj));
        }else if(ans[ni][nj] <= ans[i][j]+1){
          continue;
        }else{
          ans[ni][nj] = ans[i][j] + 1;
          q.push(make_pair(ni,nj));
        }
      }else{
        char m = a[i][j];
        if(a[ni][nj] != m){
          if(ans[ni][nj] == -1){
            ans[ni][nj] = ans[i][j] + 1;
            q.push(make_pair(ni,nj));
          }else if(ans[ni][nj] <= ans[i][j]+1){
            continue;
          }else{
            ans[ni][nj] = ans[i][j] + 1;
            q.push(make_pair(ni,nj));
          }
        }
      }
    }
    if(a[i][j] != 'S' && a[i][j] != 'G' && a[i][j] != '.' && a[i][j] != '#' && sumi[a[i][j]-'a'] == 1){
      for(auto x : p[a[i][j]-'a']){
        cnt++;
        if(x.first == i && x.second == j)continue;
        if(ans[x.first][x.second] == -1){
          ans[x.first][x.second] = ans[i][j] + 1;
          q.push(make_pair(x.first,x.second));
        }else if(ans[x.first][x.second] <= ans[i][j]+1){
          continue;
        }else{
          ans[x.first][x.second] = ans[i][j] + 1;
          q.push(make_pair(x.first,x.second));
        }
      }
      sumi[a[i][j]-'a'] = 0;
    }

    q.pop();
    cnt++;
  }
  cout << ans[g.first][g.second] << endl;

  return 0;
}


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

int C[2000] = {0};

int main(){
    int N,M;
    cin >> N >> M;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        C[a]++;
    }
    for(int i=0;i<M;i++){
        int b;
        cin >> b;
        C[b]++;
    }
    for(int i=0;i<2000;i++){
        if(C[i]==1){
            cout << i <<' ';
        }
    }
    cout << endl;
}

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

using ll = long long;
using v1 = vector<ll>;
using v2 = vector<vector<ll>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const ll INF = 1e9;
const ll mod = 1e9+7;

int main(){
    int n, m;
    cin >> n >> m;
    v1 x(n+m);
    REP(i,n+m) cin >> x[i];
    x.push_back(0);
    x.push_back(INF);
    v1 ans;
    sort(x.begin(),x.end());
    for(int i = 1; i <= n+m; i++){
        if(x[i] != x[i+1] && x[i] != x[i-1]) ans.push_back(x[i]);
    }
    if(ans.size()!=0){
        cout << ans[0];
        REP(i,ans.size()-1) cout << " " << ans[i+1];
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int m;
    cin>>m;
    int a[n][n];
    for(int i=0;i<n;++i) for(int j=0;j<n;++j) {a[i][j]=0;if(i==j) a[i][j]=1;}
    for(int i=0;i<m;++i)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;
        a[x][y]=1;
        a[y][x]=1;
    }
    bool ok[1<<n];
    for(int mask=0;mask<(1<<n);++mask)
    {
        int sum=0;
        vector <int> v;
        for(int i=0;i<n;++i)
        {
            if(mask & (1<<i))
            {
                v.push_back(i);
            }
        }
        for(int i=0;i<v.size();++i) for(int j=0;j<v.size();++j) sum+=a[v[i]][v[j]];
        ok[mask]=(sum==(v.size()*v.size()));
    }
    int res[1<<n];
    res[0]=0;
    for(int mask=1;mask<(1<<n);++mask)
    {
        if(ok[mask])
        {
            res[mask]=1;
            continue;
        }
        res[mask]=1e18;
        for(int i=mask;;i=((i-1) & mask))
        {
            if(ok[i])
            {
                res[mask]=min(res[mask],res[mask^i]+1);
            }
            if(i==0)
            {
                break;
            }
        }
    }
    cout<<res[(1<<n)-1];
    return 0;
}

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	int n,m;
	std::cin >> n >> m;
	V<V<int> > g(n,V<int>(n,0));
	rep(i,n) g[i][i]=1;
	rep(i,m) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		g[a][b]=1;
		g[b][a]=1;
	}
	V<lnt> comp(1<<n,0);
	rep(i,1<<n) {
		int ok=true;
		rep(j,n) {
			rep(k,n) {
				if((i>>j&1)&&(i>>k&1)&&g[j][k]==0) ok=false;
			}
		}
		comp[i]=ok;
	}
	V<lnt> dp(1<<n,n);
	rep(S,1<<n) {
		if(comp[S]) {
			dp[S]=1;
			continue;
		}
		for(int T=(S-1)&S;T>0;T=(T-1)&S) {
			dp[S]=std::min(dp[S],dp[T]+dp[S^T]);
		}
	}
	print(dp[(1<<n)-1]);
}


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

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
        long long n, p; cin >> n >> p;
        long long sq = sqrt(p) ;
        string ans = "No";
        for(int i = 1; i <= sq; i++){
            if(p % i != 0) continue;
            long long pr = i, an = p/i;
            if(pr + an == n) ans = "Yes";
        }
        cout << ans << "\n";
    return 0;
}

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

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

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

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

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

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

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

//modの値の確認をすること
int main(){
    ll s,p;
    cin >> s >> p;
    for (ll i = 1; i * i <= p; ++i) {
        if(i * (s - i) == p){
            yes;
            return 0;
        }
    }
    no;
    return 0;
}


#include <iostream>

using ll = long long;

int solve() {
  ll n;
  std::cin >> n;
  if(n % 4 == 0)
    return 2;
  else if(n % 2 == 0)
    return 1;
  else
    return 0;
}

int main() {
  int t;
  std::cin >> t;
  for(int testcase = 1; testcase <= t; testcase++) {
    int val = solve();
    if(val == 0)
      std::cout << "Odd\n";
    else if(val == 1)
      std::cout << "Same\n";
    else if(val == 2)
      std::cout << "Even\n";
  }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
ll n;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		if(n%2) {cout<<"Odd"<<endl;continue;
		}
		else
		{
			n/=2;
			if(n%2) { cout<<"Same"<<endl;continue;
			}
			else
			{
				cout<<"Even"<<endl;continue;
			}
		}
	}
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;

using namespace std;

int N,X;
int d;

int main() {
	cin >> N >> X;
	rep(i,N) {
		cin >> d;
		if(d != X) cout << d << " ";
	}

	return 0;

}

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> remove(int a,int b,vector<int> v){
    int target=b;
    vector<int> vec;
    for(int i{0};i<a;i++){
        if(target != v.at(i)){
            vec.push_back(v.at(i));
        }
    }
    return vec;
}
int main(){
    int a{};
    cin>>a;
    int b{};
    cin>>b;
    vector<int> vec;
    for(int i{0};i<a;i++){
        int num{};
        cin>>num;
        vec.push_back(num);
    }
    vector<int> v=remove(a,b,vec);
    for(auto c:v){
        cout<<c<<" ";
    }
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (int)(x); i < (int)(y); ++i)
#define MP make_pair
#define fst first
#define snd second
typedef pair<int, int> pii;

const int maxn = 4e5 + 5;

int n, top = 0;
int a[maxn], ord[maxn], rev[maxn], stk[maxn];
char s[maxn];

inline bool cmp(const int &i, const int &j){ return a[i] < a[j]; }

int main(){
	scanf("%d", &n);
	FOR(i, 0, n << 1){
		scanf("%d", a + i);
		ord[i] = i;
	}
	sort(ord, ord + (n << 1), cmp);
	FOR(i, 0, n << 1)
		rev[ord[i]] = i;
	FOR(i, 0, n << 1){
		if(top && (rev[stk[top]] < n) != (rev[i] < n)){
			s[stk[top]] = '(', s[i] = ')';
			--top;
		}
		else
			stk[++top] = i;
	}

	puts(s);
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f
#define PI 3.1415926535898
#define pb push_back
#define F first
#define S second
#define lson i << 1
#define rson i << 1 | 1
#define mem(x, y) memset(x, y, sizeof(x))
#define fin(x) freopen(x, "r", stdin)
#define fout(x) freopen(x, "w", stdout)
#define fcl fclose(stdin), fclose(stdout)
#define ioss ios::sync_with_stdio(false), cout.tie(NULL)
#define pii pair<int, int>
#define vec vector
#define all(x) x.begin(), x.end()
#define lowbit(x) x &(-x)
const int MAX = 6e5 + 10;
const int MOD = 1e9 + 7;
using namespace std;

int n, c[MAX], a[MAX];
void update(int i, int k) //定点更新
{
    while (i <= n)
    {
        c[i] += k;
        i += lowbit(i);
    }
}
int getsum(int i) //求和
{
    int res = 0;
    while (i > 0)
    {
        res += c[i];
        i -= lowbit(i);
    }
    return res;
}

int main()
{
    ioss;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]++;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += i - getsum(a[i]);
        update(a[i], 1);
    }
    memset(c, 0, sizeof(c));
    cout << ans << endl;
    for (int i = 0; i < n - 1; i++)
    {
        int k = getsum(a[i]), p = i - k;
        update(a[i], 1);
        // cout << k << endl;
        ans -= a[i] - 1;
        ans += n - a[i];
        cout << ans << endl;
    }
    return 0;
}
// (2 * a + n - 1)n/2
// an + n2/2 = x


#include <bits/stdc++.h>
using namespace std;
int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0));
using Int = long long;
int main() {
    int N, M; cin >> N >> M;
    map<int, vector<int>> black;
    for (int i = 0; i < M; i++) {
        int x, y; cin >> x >> y;
        black[y].push_back(x);
    }
    for (auto &[y, xs] : black) {
        sort(begin(xs), end(xs));
    }
    set<pair<int, int>> visited;
    int ans = 0;
    stack<pair<int, int>> S;
    S.emplace(0, N);
    while (!S.empty()) {
        auto [x, y] = S.top();
        S.pop();
        if (visited.count(make_pair(x, y))) {
            continue;
        }
        visited.emplace(x, y);
        auto &C = black[y];
        auto itC = lower_bound(begin(C), end(C), x + 1);
        int xlim = -1;
        if (itC == end(C)) {
            ans++;
            xlim = 2 * N;
        } else {
            xlim = *itC;
        }
        auto &L = black[y - 1];
        auto itL = lower_bound(begin(L), end(L), x + 1);
        while (itL != end(L) && *itL <= xlim) {
            S.emplace(*itL, y - 1);
            ++itL;
        }
        auto &R = black[y + 1];
        auto itR = lower_bound(begin(R), end(R), x + 1);
        while (itR != end(R) && *itR <= xlim) {
            S.emplace(*itR, y + 1);
            ++itR;
        }
    }
    cout << ans << '\n';
    return 0;
}


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

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

    int N,M; cin >> N >> M;
    vector<int> g(N);
    rep(i,M){
        int a,b; cin >> a >> b; a--; b--;
        g[a] |= 1 << b;
        g[b] |= 1 << a;
    }

    vector<int> dp(1 << N, 1e9);
    dp[0] = 1;
    rep(i,N)rep(j,1<<N) if(dp[j] == 1 && (g[i] & j) == j) dp[j | 1 << i] = 1;
    rep(i,1<<N)for(int j = i; --j &= i;) dp[i] = min(dp[i], dp[i ^ j] + dp[j]);
    cout << dp.back() << endl;
}

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> v(n, vector<int>(n, 0));
    for(int i = 0; i < n; i++)
        v[i][i] = 1;
    int a, b;
    for(int i = 0; i < m; i++)
    {
        cin >> a >> b;
        v[a - 1][b - 1] = 1;
        v[b - 1][a - 1] = 1;
    }

    vector<bool> dp((1 << n), false);

    for(int i = 0; i < (1 << n); i++)
    {
        bool good = true;

        for(int j = 0; j < n && good; j++)
        {
            if(!((i >> j) & 1))
                continue;
            for(int k = 0; k < n && good; k++)
            {
                if(!((i >> k) & 1))
                    continue;
                if(v[k][j] == 0)
                    good = false;
            }
        }
        if(good)
            dp[i] = true;
    }

    vector<int> ret(1 << n, 1e9);
    ret[0] = 0;

    for(int i = 1; i < (1 << n); i++)
    {
        if(dp[i])
        {
            ret[i] = 1;
            continue;
        }
        for(int mask = i; mask; mask = (mask - 1) & i)
        {
            ret[i] = min(ret[i], ret[mask] + ret[i ^ mask]);
        }
    }
    cout << ret[(1 << n) - 1] << endl;

    return 0;
}


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

#define M 998244353
#define inf 1e8
#define pb push_back
#define ff first
#define ss second
#define int long long int
#define ld long double
#define pi pair<li, li>
#define ins insert
#define vc vector
#define umap unordered_map
#define uset unordered_set
#define all(x) x.begin(), x.end()
#define fr(i, a, n) for (int i = a; i < n; i++)
#define frr(i, a, n) for (int i = n - 1; i >= a; i--)
#define file_in freopen("a.txt", "r", stdin);
const int mxn=1e6;

void tc() {
    int n; cin>>n;
    string s; cin>>s;
    map<int,int> m;
    m[0] = 1;
    int csum = 0 , ans=0;
    for(int i=0; i<n; i++) {
        if(s[i] == 'A')
            csum -= inf;
        else if(s[i] == 'T')
            csum += inf;
        else if(s[i] == 'G')
            csum += 1;
        else
            csum -= 1;

        if(m.count(csum))
            ans += m[csum];
        m[csum]+=1;
    }
    cout<<ans<<"\n";
}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t; t=1;
    // cin>>t;
    while(t--)  tc();
}

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cmath>
#define inf 0x3f3f3f3f
using namespace std;
const int N = 5010;
int n,f[N][N][4];
string s;
int main(){
//	freopen("1.txt","r",stdin);
	cin>>n>>s;
	int sum=0;
	for(int i=0;i<n;i++){
		int a=0,t=0,c=0,g=0;
		for(int j=i;j<n;j++){
			if(s[j]=='A') a++;
			else if(s[j]=='T') t++;
			else if(s[j]=='C') c++;
			else g++;
			if(a==t&&c==g) sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}


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

    using pii = pair<int, int>;
    template <class T>
    using V = vector<T>;
    template <class T>
    using VV = V<V<T>>;

    #define rep(i, n) rep2(i, 0, n)
    #define rep2(i, m, n) for (int i = m; i < (n); i++)

    void ng() {
        puts("No");
        exit(0);
    }

    int main() {
        int N;
        cin >> N;
        V<int> A(N), B(N);
        int sz = N * 2;
        V<int> tp(sz), com(sz, -1);

        rep(i, N) {
            cin >> A[i] >> B[i];
            if (A[i] != -1) {
                --A[i];
                if (tp[A[i]]) ng();
                tp[A[i]] = i + 1;
            }
            if (B[i] != -1) {
                --B[i];
                if (tp[B[i]]) ng();
                tp[B[i]] = -(i + 1);
            }

            if (A[i] != -1 && B[i] != -1) {
                if (A[i] > B[i]) ng();
                com[A[i]] = B[i];
                com[B[i]] = A[i];
            }
        }

        V<bool> dp(sz + 1);
        dp[0] = true;

        rep(i, sz) {
            if (!dp[i]) continue;
            for (int j = i + 1; j < sz; j += 2) {
                int w = (j - i + 1) / 2;
                bool ok = true;

                rep(k, w) {
                    int p = i + k, q = i + k + w;
                    if (com[p] != -1 && com[p] != q) {
                        ok = false;
                    }
                    if (com[q] != -1 && com[q] != p) {
                        ok = false;
                    }

                    if (tp[p] != 0 && tp[q] != 0 && tp[p] + tp[q] != 0) {
                        ok = false;
                    }
                    if (tp[p] < 0 || tp[q] > 0) {
                        ok = false;
                    }
                }
                if (ok) {
                    dp[j + 1] = true;
                }
            }
        }
        puts(dp[sz] ? "Yes" : "No");

        return 0;
    }

#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

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

    map<int,vector<int>> v;
    rep(i,M){
        int h,w;cin>>h>>w;
        v[h].push_back(w);
    }

    set<int> st;
    st.insert(N);

    for(auto &p:v){
        vector<int> nxt,ers;
        for(auto &j:p.second){
            if(st.count(j)){
                if(!st.count(j-1) and !st.count(j+1)) ers.push_back(j);
            }else{
                if(st.count(j-1) or st.count(j+1)) nxt.push_back(j);
            }
        }
        for(auto &j:ers) st.erase(j);
        for(auto &j:nxt) st.insert(j);
    }
    cout<<st.size()<<endl;
    return 0;
}


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

using namespace std;

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9+7; //998244353;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

//using mint = atcoder::modint1000000007;

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI p(n), b(n), usd(n-1);
	rep(i, n){
		int z; cin >>z; z--;
		p[i] = z;
		b[z] = i;
	}
	VI ans;
	rep(i, n){
		if(p[i]==i) continue;
		int zs = b[i];
		for(int j=zs; j-1>=i ; j--){
			if(usd[j-1]==1){ usd[0] = 1111111; goto lpout;}
			swap(p[j], p[j-1]);
			ans.push_back(j-1);
			b[p[j]] = j;
			b[p[j-1]] = j-1;
			usd[j-1]=1;
		}

	}
	lpout:
	if(count(all(usd),1) != n-1){cout <<"-1\n"; return 0;}
	rep(i, n) if(p[i] !=i){cout <<"-1\n"; return 0;}
	for(auto x :ans) cout<<x+1<<"\n";
	return 0;
}

#define ll loli
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define push emplace
#define lb(x, v) lower_bound(all(x), v)
#define ub(x, v) upper_bound(all(x), v)
#define sz(x) (int)(x.size())
#define re(x) reverse(all(x))
#define uni(x) x.resize(unique(all(x)) - x.begin())
#define all(x) x.begin(), x.end()
#define mem(x, v) memset(x, v, sizeof x);
#define int long long
#define pii pair<int, int>
#define inf 1e9
#define INF 1e18
#define mod 1000000007
#define F first
#define S second
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define chmax(a, b) (a = (b > a ? b : a))
#define chmin(a, b) (a = (b < a ? b : a))
using namespace std;

void trace_() {cerr << "\n";}
template<typename T1, typename... T2> void trace_(T1 t1, T2... t2) {cerr << ' ' << t1; trace_(t2...); }
#define trace(...) cerr << "[" << #__VA_ARGS__ << "] :", trace_(__VA_ARGS__);

int n;

signed main() {
	IO;
	cin >> n;
	int i, sum = 0;
	for (i = 1; sum < n; i++) {
		sum += i;
	}
	cout << i - 1 << '\n';
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

int main() {

	int n, x;
	cin >> n >> x;
	string s;
	cin >> s;

	for (int i = 0; i < s.size(); i++){
		if(s[i]=='o')x++;
		else if(x!=0)x--;
	}

	cout << x << endl;

	return 0;
}

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

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int to_int(string s){
    bool f=false;
    if(s[0]=='-'){
        f=true;
        s=s.substr(1);
    }
    int cnt=4;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='.'){
            s=s.substr(0,i)+s.substr(i+1);
            cnt-=(n-1-i);
            break;
        }
    }
    int res=stoi(s);
    for(int i=0;i<cnt;i++){
        res*=10;
    }
    if(f)res*=-1;
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    ll x,y,r;
    cin >> s; x=to_int(s);
    cin >> s; y=to_int(s);
    cin >> s; r=to_int(s);
    ll res=0;
    constexpr int N=10000;
    auto uo=[](ll x)->ll{
        if(x<=0){
            x-=(N-1);
            x+=abs(x)%N;
            return x;
        }
        x-=abs(x)%N;
        return x;
    };
    auto uoo=[](ll x)->ll{
        if(x<=0){
            x+=abs(x)%N;
            return x;
        }
        x+=(N-1);
        x-=abs(x)%N;
        return x;
    };
    for(ll i=-r;i<=r;){
        if(abs(y+i)%N!=0){
            i++; continue;
        }
        ll L=0,R=2e9;
        while(R-L>1){
            ll mid=(L+R)/2;
            if(mid*mid+i*i<=r*r){
                L=mid;
            }
            else{
                R=mid;
            }
        }
        // cout << i << endl;
        ll X=uo(x+L),XX=uoo(x-L);
        if(X>=XX)res+=(X-XX)/N+1;
        i+=N;
    }
    cout << res << endl;
}


//
//#ifdef ONLINE_JUDGE
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("O2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//////
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#endif

#include <bits/stdc++.h>

#include <utility>

#define all(x) (x).begin(), (x).end()
#define allp(x) (x)->begin(), (x)->end()

#define pb push_back

using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
typedef long double ld;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

//using ll = long long;
//#ifdef __int128
//using hll = __int128;
//#endif
//using pii = pair<ll, ll>;
//using ld = long double;

template <typename T>
void do_uniq(vector<T> &vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

#ifndef ONLINE_JUDGE

clock_t timestamp_start = clock();
void time_calc()
{
    cerr << (ld)(clock() - timestamp_start) / CLOCKS_PER_SEC << endl;
}
#endif

#ifdef _getchar_nolock
#else
#    define _getchar_nolock getchar_unlocked
#endif

#define integer ll

integer mod = 1e9 + 7;

integer ml(integer a, integer b) {
    return (a * 1ll * b) % mod;
}

integer add(integer a, integer b) {
    return (a + b) % mod;
}

integer sub(integer a, integer b) {
    return add(a, mod - b);
}

integer sq(integer a) {
    return ml(a, a);
}

integer b_p(integer b, integer p) {
    if (p == 0) return 1;
    if (p & 1) return ml(b, b_p(b, p - 1));
    return sq(b_p(b, p >> 1));
}

int gcd(int x, int y){
    return y == 0 ? x : gcd(y, x % y);
}

#define solvsh
//#define multi

#ifdef solvsh

//#define int ll

const int MAXN = 5e3 + 32;

void solve() {

    int n;
    cin >> n;

    vector<int> v;

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

    ll mmx = 0;
    ll pref = 0;
    ll add = 0;

    for (int i = 0; i < n; ++i) {
        mmx = max(mmx, 0ll + v[i]);
        ll answr = (i + 1) * mmx;
        pref += v[i];
        add += pref;
        answr += add;

        cout << answr << "\n";
    }
}

#else

#endif

void multisolve() {

#ifndef ONLINE_JUDGE
    freopen("../input.in", "r", stdin);
#endif

    int t;

    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Case #" << i << ": ";
        solve();
//        i++;
    }
}

#ifndef ONLINE_JUDGE

void gen() {
#ifndef ONLINE_JUDGE
    freopen("../input.in", "w", stdout);
#endif

}

#endif

#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(20);

#ifdef multi
//    gen();
    multisolve();
//    checkk();
#else

    solve();
#endif
//     time_calc();
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<long long> A(N+1);
  for(int i=1; i<=N; i++) cin >> A.at(i);
  int max = 0;
  long long ans;
  long long sum;

  max = A.at(1);
  sum = A.at(1);
  ans = A.at(1)*2;
  cout << ans << endl;

  for(int i=2; i<=N; i++){
    sum += A.at(i);
    ans += sum;
    if(max < A.at(i)){
      ans += (i-1)*(A.at(i)-max);
      max = A.at(i);
    }
    ans += max;
    cout << ans << endl;
  }

}


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

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

    string s;
    cin >> s;
    cout << s[1] << s[2] << s[0] << endl;
    return 0;
}

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

using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

#define sz(x) (int)(x).size()

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

#ifdef XVENOM
  #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: " << dbg_str(__VA_ARGS__)
#else
  #define dbg(...) ;
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const char* e) { return "\"" + string(e) + "\""; }
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
  string s = "[ "; for (auto& x : e) s += to_string(x) + " "; return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
  return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
string dbg_str () { return " \n"; }
template <typename U, typename... V> string dbg_str (U u, V... v) {
  return " " + to_string(u) + dbg_str(v...);
}
/* *** */
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);

  auto f = [&] (ll x) {
    ll res = 1;
    while (x--) res *= 10;
    return res;
  };

  ll n; cin >> n;
  ll ans = 0;
  for (ll i = 0; i <= 5; i++) {
    ll lo = f(3 * i), hi = f(3 * i + 3) - 1;
    ckmin(hi, n);
    ans += i * (hi - lo + 1);
    if (hi == n) break;
  }
  cout << ans << '\n';
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
// find_by_order returns iterator to  element present at that index...
// order_of_key returns no. of elements having value strictly less than that given in the order_of_key();
#warning !!!check the size of arrayss!!!
// NUMERIC DEFINITIONS :

#define MOD  1000000007
#define newMOD  998244353
#define pi 3.1415926535897932384626433832795
#define ld long double
#define ll long long
#define int long long
#define INF 1000000000000000008
#define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define satisfy ll t; cin>> t; while(t--)
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define x first
#define y second
#define endl "\n"
#define pii pair<ll,ll>
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
ll power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}

//ll fact[lim] = {0};
//ll inv[lim];
//void facto(ll modd) {
//
//    fact[0] = 1; fact[1] = 1;
//
//    for(int i = 2; i < lim; i++){fact[i] = (fact[i-1]*i)%modd;}
//    inv[lim-1] = modInverse(fact[lim-1],modd);
//    for(ll i=lim-2;i>=0;i--)
//        inv[i]=(inv[i+1]*(i+1))%modd;
//
//}

void __print(int 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 see(x...)                 \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define see(x...)
#endif
//ll sub(ll x, ll y) {
//    return (x - y + MOD) % MOD;
//}
//ll mul(ll x, ll y) {
//    return (x * y) % MOD;
//}
//ll add(ll x, ll y) {
//    return (x + y) % MOD;
//}

//ll ncr(ll n, ll r,ll modd)
//{
//    if(r>n)return 0;
//    ll res = 1;
//    res = fact[n];
//    res*=inv[r];
//    res%=modd;
//    res*=inv[n-r];
//    res%=modd;
////    res*=modInverse(fact[r],modd);
////    res%=modd
////    res*=modInverse(fact[n-r],modd);
//    return res;
//}

//***************************  REASON EVERY LINE OF CODE ***************************
//***************************  REASON EVERY LINE OF CODE ***************************
//***************************  REASON EVERY LINE OF CODE ***************************

void solve()
{
    ll n;cin>>n;
    ll x =0;
    for(ll i=1;i<=n;i++)
    {
        x+=i;
        if(x>=n)
        {
            cout<<i<<endl;return;
        }
    }

}

signed main()
{
    Need_for_speed(activated);
    //never give up ,irrespective of rating increment/decrement !!!!
    //Clear the global DATA strucrures!!!
    //read question statement carefully...

//    satisfy
//    {
//        solve();
//    }

    solve();

    return 0;
}

#include <bits/stdc++.h>

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A[4]; rep(i, 4) cin >> A[i];
    int sum = A[0]+A[1]+A[2]+A[3];
    rep(i, 16){
        int val = i;
        int res = 0;
        rep(j, 4){
            if(val&1) res += A[j];
            val >>= 1;
        }
        if(res == sum-res){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
ll mod= 1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

vector<pair<ld,ld>> x;
int main(){
  ll n,ans=0;
  cin>>n;
  rep(i,0,n){
  ld t,l,r;
  cin>>t>>l>>r;
  if((ll)t%2==0)r-=0.5;
  if(t>2)l+=0.5;
  x.pb(mp(l,r));
  }
  rep(i,0,n-1){
      rep(j,i+1,n){
          if(x[i].second>=x[j].first && x[j].second>=x[i].first)ans++;
      }
  }
  cout<<ans<<endl;

}

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rep(i, begin, end) for(auto i = begin; i < (end); i++)
#define contains(v, x) (find(all(v), x) != v.end())
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; }
template<class T> T roundup(T a, T b){ return (a + b - 1) / b; }
const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};
using ll = long long;
const ll INF = 1e9;
const double EPS = 1e-10;
/* #include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using d32 = mp::number<mp::cpp_dec_float<32>>; */
const ll MOD = 1e9 + 7;
/* #include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007; */
using P = pair<int, int>;
struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} };
using Graph = vector<vector<int>>;

void solve(){
    int sy, sx, ty, tx;
    cin >> sy >> sx >> ty >> tx;
    rep(_, 0, ty - sy) cout << "D";
    rep(_, 0, sy - ty) cout << "U";
    rep(_, 0, tx - sx) cout << "R";
    rep(_, 0, sx - tx) cout << "L";
    cout << endl;
    cout.flush();
}

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

    rep(_, 0, 1000){
        solve();
        int k;
        cin >> k;
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>
#include <queue>
#include <set>

#define INT_INF 1e9
#define LONG_INF 1e18
#define MOD 1e9 + 7
#define PI 3.14159265358979323846

typedef long long ll;

using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }
    while (n % 10 == 0)
    {
        n = n / 10;
    }
    string a = to_string(n);
    int i = 0, j = a.length() - 1;
    bool f = true;
    while (i < j)
    {
        if (a[i] != a[j])
        {
            f = false;
            break;
        }
        i += 1;
        j -= 1;
    }
    if (f)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using P = pair<int, int>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	vector<ll> A(N, 0), B(N, 0);
	ll amin = INF, bmin = INF;
	vector<vector<ll>> C(N, vector<ll>(N, 0));
	FOR(i,0,N){
		FOR(j,0,N){
			ll c;
			cin >> c;
			C[i][j] = c;
			A[i] += c;
			B[j] += c;
		}
	}

	FOR(i,0,N){
		amin = min(amin, A[i]);
		bmin = min(bmin, B[i]);
	}

	FOR(i,0,N){
		A[i] -= amin;
		B[i] -= bmin;
	}

	FOR(i,0,N){
		if(A[i] % N != 0 || B[i] % N != 0){
			No();
			return 0;
		}
		A[i] /= N;
		B[i] /= N;
	}

	ll add = C[0][0] - A[0] - B[0];

	if(add < 0){
		No();
		return 0;
	}

	FOR(i,0,N){
		B[i] += add;
	}

	FOR(i,0,N){
		FOR(j,0,N){
			if(A[i] + B[j] != C[i][j]){
				No();
				return 0;
			}
		}
	}

	Yes();
	FOR(i,0,N){
		cout << A[i] << " ";
	}
	cout<<endl;
	FOR(i,0,N){
		cout << B[i] << " ";
	}

	return 0;
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(min(a,b),min(c,d)) << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (c&1){
        int na = (a < 0) ? -1 : 1;
        int nb = (b < 0) ? -1 : 1;
        if (na == nb) {
            if (na == -1){
                swap(a, b);
                if (a > b) cout << '>'; else
                if (a==b) cout << '='; else cout << '<';
            } else {
                if (a > b) cout << '>'; else
                if (a==b) cout << '='; else cout << '<';
            }
        } else {
            if (na < nb) cout << '<';
            else cout << '>';
        }
    } else {
        a = abs(a);
        b = abs(b);
        if (a > b) cout << '>'; else
        if (a==b) cout << '='; else cout << '<';
    }
}


/*
Written By mafailure
*/
//In the name of God
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#ifdef ill
#define int long long
#endif
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef AATIF_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
//#define int long long
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
const double eps=1e-9;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))
#define clr(a,b) memset(a,b,sizeof(a))
const int inf= INT_MAX;
//struct point_i{int x,y;};
struct point_i{int x,y;
point_i(){ x=0; y=0;}
point_i(int x_,int y_){x=(x_);y=(y_) ;}
};

struct point
{
	float x,y;
	point (){x=y=0.0;}
	point (float x_,float y_){x=(x_); y=(y_);}
	bool operator < (point other) const{
	  if(fabs(x-other.x)>eps)return x<other.x;
	  return y<other.y;

		}
	bool operator == (point other) const {
		return fabs(other.x-x)<=eps&& fabs(other.y-y)<=eps;
		}

} ;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  ordered_set;
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int power(int x, int y)
{
	if(y==0)return 1;
	int u=power(x,y/2);
	u=(u*u)%mod;
	if(y%2)u=(x*u)%mod;
	return u;

}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{

	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
int Min (int a,int b){return min(a,b);}
int Max(int a,int b){ return max(a,b);}
signed main()
{
	IOS
	int sz=0;
	int num=1;
	int n; cin>>n;
	int a[n]; fr(i,0,n) cin>>a[i];
	fr(i,2,1001)
	{
		int cnt=0;
		fr(j,0,n)
		{
			if(a[j]%i==0)cnt++;
		}
		if(cnt>sz){
			sz=cnt; num=i;
		}
	}
	cout<<num<<endl;

}

#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 mod = 998'244'353ll;

const i64 inf = 1'000'000'000'000'000'000ll;

const long double eps = 1e-8;

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    if (sizeof(i64) != sizeof(long long int)) {
        cerr << "i64 != long long int" << endl;
    }

    i64 n;
    cin >> n;

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

    i64 br = 0;
    i64 bc = 0;

    for (i64 i = 2; i <= 1000; i++) {
        i64 c = 0;
        for (i64 v : a) {
            if (v % i == 0) {
                c += 1;
            }
        }
        if (bc < c) {
            bc = c;
            br = i;
        }
    }

    cout << br << endl;

    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("O2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//
//#pragma GCC target("ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>

#include <utility>

#define all(x) (x).begin(), (x).end()
#define allp(x) (x)->begin(), (x)->end()

#define pb push_back
#define GLIBCDEBUG

using namespace std;
void dout() { cerr << endl; }
//typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

using ll = long long;
//#ifdef __int128
//using hll = __int128;
//#endif
using pii = pair<ll, ll>;
using ld = long double;

template <typename T>
void do_uniq(vector<T> &vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

#ifndef ONLINE_JUDGE
clock_t timestamp_start = clock();
void time_calc()
{
    cerr << (ld)(clock() - timestamp_start) / CLOCKS_PER_SEC << "\n";
}
#endif

#ifdef _getchar_nolock
#else
#    define _getchar_nolock getchar_unlocked
#endif

#define integer int

 integer mod = 1e9 + 7;

integer ml(integer a, integer b) {
    return (a * 1ll * b) % mod;
}

integer add(integer a, integer b) {
    integer rt = a + b;
    if (rt < mod) return rt;
    return rt - mod;
}

integer sub(integer a, integer b) {
    return add(a, mod - b);
}

integer sq(integer a) {
    return ml(a, a);
}

integer b_p(integer b, ll p) {
    if (p == 0) return 1;
    if (p & 1) return ml(b, b_p(b, p - 1));
    return sq(b_p(b, p >> 1));
}

integer divv(integer a, integer b) {
    return ml(a, b_p(b, mod - 2));
}

const ll inf = 1e9 + 231;

#define solvsh
//#define multi

//#define GLIBCXX_DEBUG

//#define STRESS
#ifdef solvsh

const int MAXN = 20;

int tables[MAXN][MAXN];

int lenn[MAXN];

int wss[26];

void solve() {

    ll answr = 0;
    string s;
    cin >> s;

    int n = s.size();

    int ptr = n  - 1;

    while (ptr > 0) {
        if (s[ptr - 1] == s[ptr]) {

            answr += n - 1 - ptr - wss[s[ptr] - 'a'];

            for (int i = 0; i < 26; ++i) wss[i] = 0;
            wss[s[ptr] - 'a'] = n + 1 - ptr;
            --ptr;
            --ptr;

        } else {
            wss[s[ptr] - 'a']++;
            --ptr;
        }
    }

    cout << answr << "\n";
}

#else

#endif
#ifndef STRESS

void multisolve() {
//    precalc();
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
        solve();
        i++;
    }

}

void singlesolve (){
//    precalc();
    solve();

//    cerr << cnt << "\n";
}

#else

#endif

#ifndef ONLINE_JUDGE

#endif

#define int int
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

#ifdef multi
    //            gen();

    multisolve();
#else
    singlesolve();
//    gen();
#endif

}

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
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 INF = 1e18;
#define SZ(x) ((int)(x).size())

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T>
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T>
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T>
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

/*
l = s.size()
各文字の出現回数について累積和を取っておく
lが大きい方から見ていく
s[i]==s[i+1]!=s[i+2]ならひっくり返す
前回ひっくり返した文字と違う文字なら全部ひっくり返して、同じ文字なら途中までひっくり返す

*/

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	string s;
	cin >> s;
	ll l = s.size();
	vector<vector<ll> >cnt(26,vector<ll>(l+1,0));
	for(int i=1;i<=l;i++){
		rep(j,26)cnt[j][i]=cnt[j][i-1];
		int id = s[i-1]-'a';
		cnt[id][i]++;
	}
	ll last_id = l+1;
	ll last_char = '.';
	ll ans = 0;
	//debug(cnt[2]);
	for(int i=l-2;i>=1;i--){
		if(s[i-1]==s[i]&&s[i+1]!=s[i-1]){
			ans += (last_id-i)-(cnt[s[i-1]-'a'][last_id-1]-cnt[s[i-1]-'a'][i-1]);
			//cout << (last_id-i) << endl;
			//cout << (cnt[s[i]-'a'][last_id-1]-cnt[s[i]-'a'][i-1]) << endl;
			if(last_char!=s[i-1]){
				ans += l-last_id+1;
				//cout << ans << endl;
			}
			last_char = s[i-1];
			last_id = i+2;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mymod(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

template<int mod>
struct Modint{
    int x;
    Modint():x(0){}
    Modint(int64_t y):x((y%mod+mod)%mod){}

    Modint &operator+=(const Modint &p){
			if((x+=p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator-=(const Modint &p){
			if((x+=mod-p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator*=(const Modint &p){
			x = (1LL * x * p.x) % mod;
			return *this;
		}

		Modint &operator/=(const Modint &p){
			*this *= p.inverse();
			return *this;
		}

		Modint operator-() const { return Modint(-x); }
		Modint operator+(const Modint &p) const{
			return Modint(*this) += p;
		}
		Modint operator-(const Modint &p) const{
			return Modint(*this) -= p;
		}
		Modint operator*(const Modint &p) const{
			return Modint(*this) *= p;
		}
		Modint operator/(const Modint &p) const{
			return Modint(*this) /= p;
		}

		bool operator==(const Modint &p) const { return x == p.x; }
		bool operator!=(const Modint &p) const{return x != p.x;}

		Modint inverse() const{//非再帰拡張ユークリッド
			int a = x, b = mod, u = 1, v = 0;
			while(b>0){
				int t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return Modint(u);
		}

		Modint pow(int64_t n) const{//繰り返し二乗法
			Modint ret(1), mul(x);
			while(n>0){
				if(n&1)
					ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}

		friend ostream &operator<<(ostream &os,const Modint &p){
			return os << p.x;
		}
};

using modint = Modint<mod>;

template<typename T>
struct Combination{
  //Modint用
  //構築O(N),クエリO(1)
	vector<T>fact,rfact;

	Combination(int n):fact(n+1),rfact(n+1){
		fact[0]=1;fact[1]=1;
		rfact[n]=1;
		for(int i=2;i<=n;++i){
			fact[i]=fact[i-1]*i;
		}
		rfact[n]/=fact[n];
		for(int i=n-1;i>=0;--i){
			rfact[i]=rfact[i+1]*(i+1);
		}
	}

	T C(int n,int r) const{
		if(r<0 || n<r)return 0;
		return fact[n]*rfact[n-r]*rfact[r];
	}
};

void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<ll>a(n);
	rep(i,n)cin>>a[i];
	constexpr ll m=998244353;
	Combination<Modint<m>>c(k+1);
	vector<Modint<m>>sum(k+1),sum2(k+1);
	rep(i,n){
		Modint<m>x=1,y=1;
		rep(j,k+1){
			sum[j]+=x;
			sum2[j]+=y;
			x*=a[i];
			y*=a[i]*2;
		}
	}
	REP(i,1,k+1){
		Modint<m>ans=0;
		rep(j,i+1){
			ans+=c.C(i,j)*sum[j]*sum[i-j];
		}
		ans=(ans-sum2[i])/2;
		cout<<ans<<"\n";
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

/*
ID: gurban1
LANG: C++
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int N = 3e2+5;
const int mod=998244353;
const int maxn=2e5+5;
int n,k;
int a[maxn];
ll C[N][N],ans[N];
ll dp[maxn],pw[maxn][N];

ll bigmod(ll a,ll b) {if(b==0)return 1;ll x=bigmod(a*a%mod,b>>1);return b&1?x*a%mod:x;}

int main(){
	// freopen("","r",stdin);
	// freopen("","w",stdout);

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

	cin >> n >> k;
	for(int i = 1;i <= n;i++) cin >> a[i],pw[i][0] = 1;

	C[0][0] = 1;
	for(int i = 0;i <= k;i++){
		for(int j = 0;j <= i;j++){
			if(j == 0){C[i][j] = 1;continue;}
			if(i == j){C[i][j] = 1;continue;}
			C[i][j] = C[i-1][j-1] + C[i-1][j]; if(C[i][j] > mod) C[i][j] -= mod;
		}
	}

	ll iki = bigmod(2,mod-2);

	dp[0] = n;

	for(int i = 1;i <= k;i++){
		for(int j = 1;j <= n;j++){
			pw[j][i] = (pw[j][i-1] * a[j])%mod;
			dp[i] = (dp[i] + pw[j][i]); if(dp[i] > mod) dp[i] -= mod;
		}
	}

	for(int i = 0;i <= k;i++){
		for(int j = i;j+i <= k;j++){
			ll nw = (dp[i] * dp[j])%mod;
			nw -= dp[i + j]; if(nw < 0) nw += mod;
			if(i == j){nw = (nw * iki) % mod;}
			nw = (C[i+j][i] * nw) % mod;
			// if(i == 1 and j == 1) cout<<nw<<'\n';
			ans[i + j] += nw; if(ans[i+j] > mod) ans[i+j] -= mod;
		}
	}
	for(int i = 1;i <= k;i++) cout<<ans[i]<<'\n';
}


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

int main(){
  string S;cin>>S;
  cout<<S.at(1)<<S.at(2)<<S.at(0)<<endl;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char cn[1200010];
char *ci = cn;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
char tc[200000], * di = tc + 100000;
const char d[2] = "0";

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

	rep(i, 100000) tc[i] = '0';
	rep(i, 100000) di[i] = '1';
	fread(cn, 1, 1200010, stdin);
	int T = getint();

	rep(t, T) {
		int N = getint();
		fwrite(di - N, 1, N << 1, stdout);
		puts(d);
		ci += 6 * N + 3;
	}

	Would you please return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(ll i=a;i<n;i++)
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl
#define MIN(x,y) x=min(x,y)
#define MAX(x,y) x=max(x,y)
#define left 0
#define right 1

const double one = 1.0;
const double PI = 3.14159265/*358979323846*/;
const ll maxn = 1e4+10;

ll Ceil(ll a,ll b)
{
	return (a+b-1)/b;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,m;
	cin>>n>>m;
	vector<ll> blue;
	FOR(i,0,m)
	{
		ll a;
		cin>>a;
		blue.pb(a);
	}
	if(m == 0)
	{
		cout<<1<<endl;
		return 0;
	}
	sort(all(blue));
	vector<ll> dis;
	FOR(i,0,blue.size())
	{
		if(i == 0)
		{
			if(blue[i]-1>1)dis.pb(blue[i]-1);
		}
		if(blue[i+1]-blue[i]>1)dis.pb(blue[i+1]-blue[i]-1);
		if(i == blue.size()-1)
		{
			if(n-blue[i]>1)dis.pb(n-blue[i]);
		}
	}
	ll mi = 1e18;
	FOR(i,0,dis.size())
	{
		mi = min(mi,dis[i]);
	 }
	ll ans = 0;
	FOR(i,0,dis.size())
	{
		ans+=Ceil(dis[i],mi);
	}
	cout<<ans<<Endl;
	return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
#define ld long double
using namespace std;

const ll N = 1e6 + 100;
const ll M = 1e6 + 101;
const ll big = 1e17;
const ll hsh2 = 1964325029 ;
const long long mod = 1e9 + 7;
const long double EPS = 1e-10;
const ll block = 1e7;
const ll shift = 2e3;
const ld pi = acos(-1.0);

ll n, m;
ll a[N];

int main() {
	speed;
	cin >> n >> m;
	ll L = 1, sz = n, ans = 0;
	for(int i = 1; i <= m; i++)
		cin >> a[i];
	sort(a + 1, a + m + 1);
	for(int i = 1; i <= m; i++) {
		if(a[i] != L)
			sz = min(a[i] - L, sz);
		L = a[i] + 1;
	}
	if(a[m] != n)
		sz = min(sz, n - a[m]);
	L = 1;
	for(int i = 1; i <= m; i++) {
		ans += (a[i] - L + sz - 1) / sz;
		L = a[i] + 1;
	}
	ans += (n - L + sz) / sz;
	cout << ans;
}
/*
4 0
3 5 5 4
1
1 1

*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m,val,valu;
    cin>>n;
    double ans=0;
    for(ll i=1; i<n; i++)
    {
           ans+=(1.00*n)/(n-i);
    }
    cout<<fixed<<setprecision(14)<<ans<<endl;

}

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

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

typedef long long ll;
#define all(x) x.begin(),x.end()
class CTo3 {
public:

    void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);

        string s;
        cin >> s;

        int ans = INT_MIN;
        for(int i = 1; i < (1 << s.size()); i++){
            int cur = 0;
            int len = 0;
            for(int j = 0; j < s.size(); j++)
                if (i & (1 << j)){
                    cur += s[j] - '0';
                    len++;
                }
            if (cur % 3 == 0 && len > ans){
                ans = len;
            }
        }
        if (ans == INT_MIN){
            cout << -1 << endl;
            return;
        }
        cout <<  s.size() - ans << endl;

	}
};

#define loveAfterTheGame main

int loveAfterTheGame() {
	CTo3 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define DREP(i,s,n) for(int i = (s); i < (n); i++)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

int main() {
    int N; cin >> N;
    veci A(N); REP(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    veci B(N);
    iota(B.begin(),B.end(),1);
    if(A==B)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define fr(i,x,n) for(ll i=x;i<n;i++)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//-----------------------------------------------------------------------
const int nax =1;
int fac[nax];
int mod_inv[nax];
inline int add(int a, int b){ int c = (a%mod) + (b%mod); if(c >= mod) c -= mod; return c; }
inline int mul(int a, int b){ return ((a%mod) * 1ll * (b%mod)) % mod; }
inline int sub(int a, int b){ int c = (a%mod) - (b%mod); if(c < 0) c += mod; return c; }
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
//-----------------------------------------------------------------------
bool comparision(const pair<int,int> &a,const pair<int,int> &b)
{
    if(a.second==b.second)
    return (a.first>b.first);
    else
    return (a.second>b.second);
}
ll power(ll x,ll y)
{
    ll p=mod;
    ll res = 1;
    x=x%p;
    while(y>0)
    {
        if (y&1) res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}
void pre()
{
    fac[0] = fac[1] = 1;
    for(int i = 2;i<nax;++i){
        fac[i] = mul(i , fac[i-1]);
    }
    mod_inv[0] = mod_inv[1] = 1;
    for(int i =2;i<nax;++i){
        mod_inv[i] = power(fac[i] , mod - 2);
    }

}
ll ncr(ll n, ll r)
{
    if(r > n)return 0LL;
    int ans = mul(fac[n] , mod_inv[r]);
    ans = mul(ans , mod_inv[n-r]);
    return ans;
}
ll count_bit_set(ll n)
{
    int c=0;
    while(n)
    {
        n&=(n-1);
        c++;
    }
    return c;
}
ll mod_inverse(ll n)
{
    //fermate little theorem
    return power(n,mod-2);
}
void dfs(int i,vector<int> &v)
{
    int n;
    vector<bool> visit(21,0);
    vector<vector<int>> g(21,vector<int>(21,0));
    visit[i]=1;
    v.push_back(i);
    for(int k=1;k<=n;k++){if(visit[k]==0 && g[i][k]>0)dfs(k,v);}
}
ll maxSubArraySum(ll p,ll q,vector<ll> &v)
{
    ll msf =-1e16, meh = 0;
    for (int i = p;i<=q; i++)
    {
        meh = meh + v[i];
        if (msf < meh)msf = meh;
        if(meh<0)meh = 0;
    }
    return msf;
}
void seiveoferatosthenes()
{
    int mx=1e7;
    vector<int> seive(mx+1,1);
    for(int i=2;i*i<=mx;i++)
    {if(seive[i]==1)for(int j=i*i;j<=mx;j+=i)seive[j]=0;}
}
void factorize(ll n,vector<pair<ll,ll>> &v)
{
    ll i,count = 0;
    while (!(n % 2)) {
        n >>= 1;
        count++;
    }
    if (count){v.push_back({count,2});}
    for (i=3; i<=sqrt(n);i+= 2) {
        count=0;
        while(n%i == 0){
            count++;
            n=n/i;
        }
        if(count)v.push_back({count,i});
    }
    if (n>2)v.push_back({1,n});
}
ll ceil(ll n,ll k)
{
    return (n+k-1)/k;
}
//-----------------------------------------------------------------------
void solve()
{
    //read the instructions
    vector<int> mark(1001,0);
    int n;
    cin>>n;
    int ar[n];
    fr(i,0,n){cin>>ar[i];mark[ar[i]]=1;}
    fr(i,1,n+1){if(mark[i]==0){cout<<"No"<<endl;return;}}
    cout<<"Yes"<<endl;
}
/*-----------------------------------------------------------------------
1.Read the question properly(name).
2.Read the question properly(name):|
3.Cheak the constraints.
4.Better to look for edge cases and examples.
5.why the contraints and values are like that?{sum always take ll}
6.think the opposite way
-----------------------------------------------------------------------*/
signed main()
{
    fast;
    int test=1;
    //cin>>test;
    //pre();
    for(int i=1;i<=test;i++)
    {
        //cout<<"Case #"<<i<<": ";
        solve();
    }
}


#include "bits/stdc++.h"

using namespace std;

#define ll long long
#define ld long double

#define f first
#define s second
#define pb push_back

#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define sz(li) (int) (li).size()
#define sum(a) (accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) (min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>

#define endl '\n'

#define rep(i, a, b) for(int i = (a); i < (b); i++)

template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "[ "; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << " ]"; }
template<typename A> ostream& operator<<(ostream &cout, vector<vector<A>> const &v) { cout << "["; for (int i = 0; i < v.size(); i++) { if (i) { cout << " "; } cout << v[i]; if (i < v.size() - 1) { cout << endl; } } return cout << "]"; }
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; }
template<typename T, typename U> void cmin(T& a, U b){ if (a > b) a = b; }
template<typename T, typename U> void cmax(T& a, U b){ if (a < b) a = b; }

void solve() {
  int n; cin >> n;
  vi t(n);

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

  int mx = accumulate(all(t), 0);

  vector<bool> possible(mx + 1);
  possible[0] = true;

  vi can;

  for (auto& T : t) {
    for (int i = sz(possible) - 1; i >= T; i--) {
      if (possible[i - T] && !possible[i]) {
        can.pb(i);
        possible[i] = true;
      }
    }
  }

  sort(all(can), greater<int>());

  int mn = INT_MAX;
  for (auto& s : can) {
    mn = min(mn, max(s, mx - s));
  }

  cout << mn << endl;
}

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

  int t = 1;
  // cin >> t;

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

  cerr << "Time: " << 1000.0*clock()/CLOCKS_PER_SEC << " ms\n";
}

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

int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);
    vector<int> cnt(N);

    for(int i=0;i<N;i++){
        int t;
        cin >> t;
        A[i] = t-1;
    }
    for(int i=0;i<N;i++){
        int t;
        cin >> t;
        B[i] = t-1;
    }
    for(int i=0;i<N;i++){
        int t;
        cin >> t;
        C[i] = t-1;
    }

    long long Ans = 0;

    for(int i=0;i<N;i++){
        cnt[B[C[i]]]+=1;
    }
    for(int i=0;i<N;i++){
        Ans+=cnt[A[i]];
    }
    cout << Ans << endl;
    return 0;

}


#include <bits/stdc++.h>

using namespace std;

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

	int tc;
	cin >> tc;
	while(tc--){
		string str;
		cin >> str;

		int n=(int)str.size();
		int res=0;
		string tar="atcoder";

		if(str>tar){
			cout << 0 << "\n";
			continue;
		}

		bool allz=true;
		int ind=-1;
		for(int i=0;i<n;i++){
			if(str[i]!='a'){
				allz=false;
				if(ind==-1) ind=i;
			}
		}
		if(allz){
			cout << -1 << "\n";
			continue;
		}

		while(ind>0){
			swap(str[ind],str[ind-1]);
			ind--;
			res++;
			if(str>tar){
				cout << res << "\n";
				res=-1;
				break;
			}
		}
		if(res!=-1){
			cout << -1 << "\n";
			continue;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
// #include <atcoder/all>
// using namespace atcoder;

const ll INF = 1000000000000000;

int main(){
    int n;
    cin >> n;
    vl x(n), y(n);
    rep(i,n) cin >> x[i] >> y[i];
    ll max_x = -INF;
    ll max_y = -INF;
    ll min_x = INF;
    ll min_y = INF;
    rep(i,n){
        max_x = max(max_x, x[i]);
        max_y = max(max_y, y[i]);
        min_x = min(min_x, x[i]);
        min_y = min(min_y, y[i]);
    }
    bool ok_max = true, ok_min = true;
    // cout << ok_min << ok_min << endl;
    rep(i,n){
        if(x[i] == max_x && y[i] == max_y) {
            // cout << "max" << endl;
            ok_max = false;
            // cout << x[i] << max_x << y[i] << max_y << endl;
        }
        if(x[i] == min_x && y[i] == min_y) {
            // cout << "min" << endl;
            ok_min = false;
            // cout << x[i] << min_x << y[i] << min_y << endl;
        }
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    vl ans(6);
    ans[0] = abs(x[n-1] - x[0]);
    ans[1] = abs(x[n-2] - x[0]);
    ans[2] = abs(x[n-1] - x[1]);
    ans[3] = abs(y[n-1] - y[0]);
    ans[4] = abs(y[n-2] - y[0]);
    ans[5] = abs(y[n-1] - y[1]);
    sort(ans.rbegin(), ans.rend());
    if(ok_max || ok_min) cout << ans[1] << endl;
    else cout << ans[2] << endl;
    // cout << ok_max << ok_min << endl;
}


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

int main()
{
    ll N;
    cin >> N;
    vector<ll> X(N), C(N);
    vector<vector<ll>> ball(N+2, vector<ll>(0));
    ball.at(0).emplace_back(0);
    rep(i, N){
        cin >> X.at(i) >> C.at(i);
        ball.at(C.at(i)).emplace_back(X.at(i));
    }
    ball.at(N+1).emplace_back(0);
    rep(i, N+2){
        sort(all(ball.at(i)));
    }
    vector<vector<ll>> dp(N+2, vector<ll>(2, 0));
    //dp.at(i).at(0)は色iまでを回収して左端にいるときの最小時間
    //dp.at(i).at(1)は右端にいる
    ll p = 0;
    rep(i, N+1){
        if(ball.at(i+1).empty()){
            dp.at(i+1).at(0) = dp.at(i).at(0);
            dp.at(i+1).at(1) = dp.at(i).at(1);
        }
        else{
            ll preleft = ball.at(p).at(0);
            ll preright = ball.at(p).at(sz(ball.at(p))-1);
            ll left = ball.at(i+1).at(0);
            ll right = ball.at(i+1).at(sz(ball.at(i+1))-1);
            // preleft -> left
            dp.at(i+1).at(0) = abs(preleft-right) + right - left + dp.at(i).at(0);
            // preleft -> right
            dp.at(i+1).at(1) = abs(preleft-left) + right - left + dp.at(i).at(0);
            // preright -> left
            chmin(dp.at(i+1).at(0), abs(preright-right) + right - left + dp.at(i).at(1));
            // preright -> right
            chmin(dp.at(i+1).at(1), abs(preright-left) + right - left + dp.at(i).at(1));
            p = i+1;
        }
    }
    cout << min(dp.at(N+1).at(0), dp.at(N+1).at(1)) << '\n';
}

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}
	return b;
}
long long int min(long long int a,long long int b){
	if(a<b){
		return a;
	}
	return b;
}

int main()
{
	int N;
	cin>>N;
	int colour[N][2];//stores min and max for each colour
	for(int i=0;i<N;i++){
		colour[i][0]=0;
		colour[i][1]=0;
	}
	for(int i=0;i<N;i++){
		int x,c;
		cin>>x>>c;
		if(colour[c-1][0]==0){
			colour[c-1][0]=x;
			colour[c-1][1]=x;
		}
		if(colour[c-1][0]>x){colour[c-1][0]=x;}
		if(colour[c-1][1]<x){colour[c-1][1]=x;}
	}
	long long int last_left[2];
	last_left[0]=0;
	last_left[1]=0;
	long long int last_right[2];//moves taken, then place of current person
	last_right[0]=0;
	last_right[1]=0;
	for(int i=0;i<N;i++){
		long long int next_left[2],next_right[2];//moves then place
		if(colour[i][0]==0){continue;}
		next_right[1]=colour[i][1];
		next_left[1]=colour[i][0];
		long long int distR=max(last_right[1]-next_right[1],next_right[1]-last_right[1]);
		long long int distL=max(last_left[1]-next_right[1],next_right[1]-last_left[1]);
		next_left[0]=min(last_right[0]+distR+next_right[1]-next_left[1],last_left[0]+distL+next_right[1]-next_left[1]);
		distR=max(last_right[1]-next_left[1],next_left[1]-last_right[1]);//changing to next color
		distL=max(last_left[1]-next_left[1],next_left[1]-last_left[1]);
		next_right[0]=min(last_right[0]+distR+next_right[1]-next_left[1],last_left[0]+distL+next_right[1]-next_left[1]);
		last_left[0]=next_left[0];
		last_left[1]=next_left[1];
		last_right[0]=next_right[0];
		last_right[1]=next_right[1];
	}
	cout<<min(last_right[0]+max(last_right[1],-last_right[1]),last_left[0]+max(last_left[1],-last_left[1]))<<endl;
}


#include<iostream>
#include<stdio.h>
#include<iomanip>
using namespace std;
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>

long long int pw(int x,int n)
{
    long long int res=1;

    while(n>0)
    {
        if(n%2==0)
        {
            n=n/2;
            x=x*x;
        }

        else
        {
            n=n-1;
            res=res*x;
        }
    }

    return res;

}

int main()
{
    long long int k,i,j;
    cin>>k;

    long long int cnt[10]={0},cntt[10]={0},cnta[10]={0};

    for(i=1;i<=9;i=i+1)
    {
        cnt[i]=k;
    }

    string s,t;
    cin>>s>>t;

    for(i=0;i<s.length()-1;i=i+1)
    {
        cnt[s[i]-'0']--;
        cntt[s[i]-'0']++;
    }

    for(i=0;i<t.length()-1;i=i+1)
    {
        cnt[t[i]-'0']--;
        cnta[t[i]-'0']++;
    }

    long long int sumt=0,suma=0;

    for(i=1;i<=9;i=i+1)
    {
        sumt=sumt+(i*pw(10,cntt[i]));
        suma=suma+(i*pw(10,cnta[i]));
    }

    long long int  prob=0;

    long long int total=(9*k-8);

    for(i=1; i<=9; i=i+1)
    {
        for(j=1; j<=9; j=j+1)
        {

                long long int csumt=sumt-(i*pw(10,cntt[i]))+(i*pw(10,cntt[i]+1));
                long long int csuma=suma-(j*pw(10,cnta[j]))+(j*pw(10,cnta[j]+1));

                if(csumt>csuma && i!=j)
                {
                    prob=prob+(cnt[j])*(cnt[i]);

                }

                else if(csumt>csuma && i==j)
                {
                    prob=prob+(cnt[i])*(cnt[i]-1);
                }

        }
    }

    cout<<(double)prob/total/(total-1) <<endl;

}

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <array>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef tuple<ll, ll, ll> tl3;
typedef tuple<double, ll, ll> tdl2;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9 + 5;
const ll INF = 1000000000000000000 + 5;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
//const int MOD = 10007;
const double EPS = 1e-7;
const int MAX = 24 * 60 * 60;

ll pow10(ll p) {
	ll a = 1;
	for (int i = 0; i < p; i++) {
		a *= 10;
	}
	return a;
}

int main() {
	ll k;
	cin >> k;
	vector<string> s(2);
	for (int i = 0; i < 2; i++) {
		cin >> s[i];
	}

	vector<int> t(10);
	vector<int> a(10);
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 2; j++) {
			int num = s[j][i] - '0';
			if (j == 0) {
				t[num]++;
			}
			else {
				a[num]++;
			}
		}
	}

	ll w = 0;
	ll sum = 0;
	for (int i = 1; i < 10; i++) {
		vector<int> ta(t);
		ta[i]++;

		for (int j = 1; j < 10; j++) {
			vector<int> ao(a);
			ao[j]++;

			bool canConsist = true;
			for (int l = 0; l < 10; l++) {
				if (ta[l] + ao[l] > k) {
					canConsist = false;
				}
			}
			if (!canConsist) {
				continue;
			}

			ll sc = 0;
			for (int l = 0; l < 10; l++) {
				ll st = l * pow10(ta[l]);

				sc += st;

				ll sa = l * pow10(ao[l]);

				sc -= sa;

			}

			ll p = 1;
			if (i != j) {
				p *= (k - t[i] - a[i]);
				p *= (k - t[j] - a[j]);
			}
			else {
				ll r = k - t[i] - a[i];
				p *= r * (r - 1);
			}

			sum += p;
			if (sc > 0) {
				w += p;

			}
		}
	}

	cout << setprecision(20) << 1.0 * w / sum << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <u32 M>
struct modint {
    u32 val;
public:
    static modint raw(int v) { modint x; x.val = v; return x; }
    modint() : val(0) {}
    template <class T>
    modint(T v) { ll x = (ll)(v%(ll)(M)); if (x < 0) x += M; val = u32(x); }
    modint(bool v) { val = ((unsigned int)(v) % M); }
    modint& operator++() { val++; if (val == M) val = 0; return *this; }
    modint& operator--() { if (val == 0) val = M; val--; return *this; }
    modint operator++(int) { modint result = *this; ++*this; return result; }
    modint operator--(int) { modint result = *this; --*this; return result; }
    modint& operator+=(const modint& b) { val += b.val; if (val >= M) val -= M; return *this; }
    modint& operator-=(const modint& b) { val -= b.val; if (val >= M) val += M; return *this; }
    modint& operator*=(const modint& b) { u64 z = val; z *= b.val; val = (u32)(z % M); return *this; }
    modint& operator/=(const modint& b) { return *this = *this * b.inv(); }
    modint operator+() const { return *this; }
    modint operator-() const { return modint() - *this; }
    modint pow(long long n) const { modint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
    modint inv() const { return pow(M-2); }
    friend modint operator+(const modint& a, const modint& b) { return modint(a) += b; }
    friend modint operator-(const modint& a, const modint& b) { return modint(a) -= b; }
    friend modint operator*(const modint& a, const modint& b) { return modint(a) *= b; }
    friend modint operator/(const modint& a, const modint& b) { return modint(a) /= b; }
    friend bool operator==(const modint& a, const modint& b) { return a.val == b.val; }
    friend bool operator!=(const modint& a, const modint& b) { return a.val != b.val; }
};
using mint = modint<MOD>;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    for (auto &&i : v) {
        cin >> i;
    }
    auto dp1 = make_v(h+1, w+1, mint(0));
    auto dp2 = dp1, dp3 = dp1;
    dp1[1][1] = 1; dp2[1][1] = 1; dp3[1][1] = 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(i == 0 && j == 0) continue;
            if(v[i][j] == '#') continue;
            mint val = dp1[i][j+1] + dp2[i+1][j] + dp3[i][j];
            dp1[i+1][j+1] = dp1[i][j+1] + val;
            dp2[i+1][j+1] = dp2[i+1][j] + val;
            dp3[i+1][j+1] = dp3[i][j] + val;
        }
    }
    cout << (dp1[h][w] - dp1[h-1][w]).val << "\n";
    return 0;
}

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

#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int MOD = 1e9+7;
const int N = 2005;

int dp[N][N][4];
string s[N];
int n,m;

void solve()
{
   cin >> n >> m;
   f(i,n) cin >> s[i];

   f(i,n) f(j,m)
   {
       if(s[i][j] == '#') continue;

       if(i == 0 && j == 0) dp[i][j][0] = 1;
       if(i > 0) dp[i][j][0] += dp[i-1][j][1];
       if(j > 0) dp[i][j][0] += dp[i][j-1][2];
       if(i > 0 && j > 0) dp[i][j][0] += dp[i-1][j-1][3];

       dp[i][j][0]%=MOD;

       f(k,3) dp[i][j][k+1] = dp[i][j][0];

       if(i > 0 && j > 0) dp[i][j][3] = (dp[i][j][3] + dp[i-1][j-1][3])%MOD;
       if(i > 0) dp[i][j][1] = (dp[i][j][1] + dp[i-1][j][1])%MOD;
       if(j > 0) dp[i][j][2] = (dp[i][j][2] + dp[i][j-1][2])%MOD;
   }

   cout << dp[n-1][m-1][0];
}

signed main()
{
    fast;

    int t = 1;

//    cin >> t;

    while(t--)

    solve();
}


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

ll mod = 1000000007;

int main() {
    ll N; cin >> N;
    ll dp[N+1][N+1];
    ll sum[N+1]; sum[0] = 0;
    rep(i,N){
        ll a; cin >> a;
        sum[i+1] = sum[i] + a;
    }
    rep(i,N+1){
        rep(j,N+1){
            dp[i][j] = 0;
        }
    }
    rep(i,N) dp[1][i+1] = 1;
    vector<int> prev;
    for(ll i=2;i<=N;i++){
        prev.assign(N+1,-1); prev[0] = 0;
        rep(j,N){
            ll k = sum[j+1]%i;
            if(prev[k]!=-1){
                dp[i][j+1] = dp[i][prev[k]] + dp[i-1][prev[k]];
                dp[i][j+1] %= mod;
            }
            prev[k] = j+1;
        }
    }
    ll ans = 0;
    rep(i,N+1){
        ans += dp[i][N]; ans %= mod;
    }
    cout << ans << endl;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iomanip>
#include <climits>
#define ll long long
#define mod 1000000007

// templates
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define po(x,y)   fixed<<setprecision(y)<<x
#define ss(s) scanf(" %[^\n]%*c", s)
#define sc(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define ps(s) printf("%s\n",s)
#define pr(n) printf("%d\n",n)
#define pl(n) printf("%lld\n",n)
#define prs(n) printf("%d ",n)
#define pls(n) printf("%lld ",n)
using namespace std;

const ll inf = (ll)1e15 + 10;
const int N = 19;
ll dp[N][1 << N];
vector<pair<int, int>>v[N];
int n, m;

ll calc(int p, int mask) {

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

	ll ans = 0;
	for (auto x : v[p]) {

		int y = x.F, z = x.S;
		int rem = mask % (1 << y);
		int d = __builtin_popcount(rem);
		if (d > z) {

			return dp[p][mask] = 0;
		}
	}
	if (p == n) {
		return dp[p][mask] = 1;
	}
	for (int i = 0; i < n; i++) {

		if ((mask >> i) & 1)continue;
		ans += calc(p + 1, mask | (1 << i));

	}
	return dp[p][mask] = ans;
}

void solve()
{
	memset(dp, -1LL, sizeof(dp));
	sc(n), sc(m);
	for (int i = 0; i < m; ++i)
	{
		int x, y, z;
		sc(x), sc(y), sc(z);
		v[x].push_back({y, z});
	}

	pl(calc(0, 0));

}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	// sc(t);
	while (t--) {
		solve();
	}
	// cerr<< (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl;
	return 0;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define endl '\n'

string s[100005];

int dist(string& a, string& b) {
	int ret = 0;
	for (size_t i = 0; i < a.length(); i++) {
		if (a[i] != b[i]) ret++;
	}
	return ret;
}
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	long long first = 0;
	long long ans = 0;
	for (int i = 1; i < n; i++) {
		if (dist(s[0], s[i]) & 1) first++;
	}
	ans = first;
	for (int i = 1; i < n; i++) {
		if (dist(s[0], s[i]) & 1) {
			ans += n - first;
		}
		else {
			ans += first;
		}
	}
	cout << ans / 2 << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m; cin >> n >> m;
  long long odd = 0, even = 0;
  for(int i = 0; i < n; ++i){
    int count = 0;
    string s; cin >> s;
    for(int j = 0; j < m; ++j){
      if(s[j] == '1'){count += 1;}
    }
    if(count%2 == 1){odd += 1;}
    else{even += 1;}
  }
  cout << odd*even << endl;
}


#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define forn(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define ford(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define int long long
#define ii pair<int,int>
#define ar array
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define sz(x) ((int)(x).size())
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
const int N = 2e5+7 ;
int a[N], dp[N] ;
vector<int> g[N] ;
int n , m ;

void solve(){
    cin >> n >> m ;
    forn(i,n){
        cin >> a[i] ;
        dp[i] = INF ;
    }
    forn(i,m){
        int x , y ;
        cin >> x >> y ;
        --x ;
        --y ;
        g[x].pb(y) ;
    }
    int ans = -INF ;
    for(int i = 0 ; i < n ; i++){
        for(int& x : g[i]){
            dp[x] = min(dp[x], min(dp[i], a[i])) ;
        }
        if(dp[i] < INF) ans = max(ans, a[i]-dp[i]) ;
    }
    cout << ans << endl ;
}

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

#define _USE_MATH_DEFINES

#include <iostream>
#include <cstring>
#include <regex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <unordered_set>
#include <queue>
#include <unordered_map>
#include <set>
#include <cassert>
#include <climits>

#pragma GCC optimize("O3")

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

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1ll; i >= 0; --i)
#define FOR(i, a, b) for(ll i = a; i < ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i > ll(b); --i)
#define foreach(i, itr) for(auto& i : (itr))
#define asort(arr, size) std::sort(arr, arr + size)
#define dsort(arr, size) std::sort(arr, arr + size, [](auto a, auto b) { return a > b; })
#define cauto const auto&
#define bit(n) (1LL << (n))

////////////////////////////////////
// ここから下に任意のコードを書く //
////////////////////////////////////

int main() {
    ull N, K;
    cin >> N >> K;
    rep(i, K) {
        if (N % 200) {
            N = N * 1000 + 200;
        }
        else {
            N /= 200;
        }
    }
    cout << N << endl;
    return 0;
}