/*        All is Well        */
#include <bits/stdc++.h>
using namespace std;
#define tera_baap_aaya main
#define TEZZ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);//
#define ll long long int
#define PB push_back
#define MP make_pair
const ll C=1e9+7;
////////////////////
bool checkprime(ll n)
{
    for (ll i=2;i*i<=n;i++)
    {
        if (n%i==0)
        {
            return false;
        }
    }
    return true;
}//////////
ll ncr(int n, int r)
{
    if (r>n)
    {
        return 0;
    }
    r=min(r,n-r);
    ll num=1,den=1;
    for (int i=0;i<r;i++)
    {
        num*=n-i;
        den*=i+1;
        ll g=__gcd(num,den);
        num/=g;
        den/=g;
    }
    return num;
}//////////
ll pasc_triangle(int n, int r)
{
    if (r>n)
    {
        return 0;
    }
    r=min(r,n-r);
    if (r==0)
    {
        return 1;
    }
    vector <ll> a;
    a.PB(1);
    for (int i=0;i<n-1;i++)
    {
        vector <ll> b;
        b.PB(1);
        for (int j=1;j<a.size();j++)
        {
            b.PB((a[j]+a[j-1])%C);
        }
        b.PB(1);
        a=b;
    }
    return (a[r]+a[r-1])%C;
}//////////
vector <ll> fact(200000+1);
void factarray()
{
    fact[0]=1%C;
    for (int i=1;i<200000+1;i++)
    {
        fact[i]=(fact[i-1]*i)%C;
    }
}//////////
ll modpower(ll n,ll p)
{
    if (p==0)
    {
        return 1%C;
    }
    ll m=modpower(n,p/2);
    m*=m;
    m%=C;
    if (p%2)
    {
        m*=n%C;
        m%=C;
    }
    return m;
}//////////
ll modinverse(ll n)
{
    return modpower(n, C-2);
}//////////
ll ncrmodc(int n,int r)
{
    if (r>n)
    {
        return 0;
    }
    r=min(r,n-r);
    return ((fact[n]*modinverse(fact[r]))%C*modinverse(fact[n-r]))%C;
}//////////
/******************/
void solve()
{
    int n;
    cin>>n;
    vector <pair <ll, ll>> p1(n),p2(n);
    for (int i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        p1[i]=MP(x,y);
        p2[i]=MP(y,x);
    }
    sort(p1.begin(),p1.end());
    sort(p2.begin(),p2.end());
    ll ans1=abs(p1[0].first-p1[n-1].first),ans2=abs(p2[0].first-p2[n-1].first),ans3,ans4,ans5,ans6;
    ans3=abs(p1[1].first-p1[n-1].first);
    ans4=abs(p1[0].first-p1[n-2].first);
    ans5=abs(p2[1].first-p2[n-1].first);
    ans6=abs(p2[0].first-p2[n-2].first);
    //ll x=abs(p1[0].second-p1[n-1].second),y=abs(p2[0].second-p2[n-1].second);
    set <pair <ll, ll>> s1,s2;
    s1.insert(p1[0]);
    s1.insert(p1[n-1]);
    s2.insert(MP(p2[0].second,p2[0].first));
    s2.insert(MP(p2[n-1].second,p2[n-1].first));
    if (s1==s2)
    {
        cout<<max({ans3, ans4, ans5, ans6});
        return;
    }
    if (ans1==ans2)
    {
        cout<<ans1;
        return;
    }
    if (ans1>ans2)
    {
        cout<<max({ans2, ans3, ans4});
        return;
    }
    if (ans1<ans2)
    {
        cout<<max({ans1, ans5, ans6});
        return;
    }
}//////////
////////////////////
int tera_baap_aaya()
{
    TEZZ;
    int t=1;
    //cin>>t;
    cout<<fixed<<setprecision(8);
    //factarray();
    while (t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}
/*..fir milenge chalte chalte*/

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

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

  int x, y;
  vector<vector<int>> xmin(2, vector<int> {0, 1000000001});
  vector<vector<int>> xmax(2, vector<int> {0, -1000000001});
  vector<vector<int>> ymin(2, vector<int> {0, 1000000001});
  vector<vector<int>> ymax(2, vector<int> {0, -1000000001});
  for(int i = 0; i<N; i++){
    cin >> x >> y;
    if(x < xmin.at(0).at(1)){
      xmin.at(1).at(1) = xmin.at(0).at(1);
      xmin.at(1).at(0) = xmin.at(0).at(0);
      xmin.at(0).at(1) = x;
      xmin.at(0).at(0) = i;
    }
    else if (x < xmin.at(1).at(1)){
      xmin.at(1).at(1) = x;
      xmin.at(1).at(0) = i;
    }
    if(x > xmax.at(0).at(1)){
      xmax.at(1).at(1) = xmax.at(0).at(1);
      xmax.at(1).at(0) = xmax.at(0).at(0);
      xmax.at(0).at(1) = x;
      xmax.at(0).at(0) = i;
    }
    else if (x > xmax.at(1).at(1)){
      xmax.at(1).at(1) = x;
      xmax.at(1).at(0) = i;
    }
    if(y < ymin.at(0).at(1)){
      ymin.at(1).at(1) = ymin.at(0).at(1);
      ymin.at(1).at(0) = ymin.at(0).at(0);
      ymin.at(0).at(1) = y;
      ymin.at(0).at(0) = i;
    }
    else if (y < ymin.at(1).at(1)){
      ymin.at(1).at(1) = y;
      ymin.at(1).at(0) = i;
    }
    if(y > ymax.at(0).at(1)){
      ymax.at(1).at(1) = ymax.at(0).at(1);
      ymax.at(1).at(0) = ymax.at(0).at(0);
      ymax.at(0).at(1) = y;
      ymax.at(0).at(0) = i;
    }
    else if (y > ymax.at(1).at(1)){
      ymax.at(1).at(1) = y;
      ymax.at(1).at(0) = i;
    }
  }

  vector<vector<int>> ans(3, vector<int>(3, -2000000001));
  for(int i = 0; i<2; i++){
    for(int j = 0; j<2; j++){
      int v = xmax.at(j).at(1) - xmin.at(i).at(1);
      if(v > ans.at(0).at(0)){
        ans.at(2) = ans.at(1);
        ans.at(1) = ans.at(0);
        ans.at(0).at(0) = v;
        ans.at(0).at(1) = min(xmax.at(j).at(0), xmin.at(i).at(0));
        ans.at(0).at(2) = max(xmax.at(j).at(0), xmin.at(i).at(0));
      }
      else if(v > ans.at(1).at(0)){
        ans.at(2) = ans.at(1);
        ans.at(1).at(0) = v;
        ans.at(1).at(1) = min(xmax.at(j).at(0), xmin.at(i).at(0));
        ans.at(1).at(2) = max(xmax.at(j).at(0), xmin.at(i).at(0));
      }
      else if(v > ans.at(2).at(0)){
        ans.at(2).at(0) = v;
        ans.at(2).at(1) = min(xmax.at(j).at(0), xmin.at(i).at(0));
        ans.at(2).at(2) = max(xmax.at(j).at(0), xmin.at(i).at(0));
      }
      v = ymax.at(j).at(1) - ymin.at(i).at(1);
      if(v > ans.at(0).at(0)){
        ans.at(2) = ans.at(1);
        ans.at(1) = ans.at(0);
        ans.at(0).at(0) = v;
        ans.at(0).at(1) = min(ymax.at(j).at(0), ymin.at(i).at(0));
        ans.at(0).at(2) = max(ymax.at(j).at(0), ymin.at(i).at(0));
      }
      else if(v > ans.at(1).at(0)){
        ans.at(2) = ans.at(1);
        ans.at(1).at(0) = v;
        ans.at(1).at(1) = min(ymax.at(j).at(0), ymin.at(i).at(0));
        ans.at(1).at(2) = max(ymax.at(j).at(0), ymin.at(i).at(0));
      }
      else if(v > ans.at(2).at(0)){
        ans.at(2).at(0) = v;
        ans.at(2).at(1) = min(ymax.at(j).at(0), ymin.at(i).at(0));
        ans.at(2).at(2) = max(ymax.at(j).at(0), ymin.at(i).at(0));
      }
    }
  }

  if (ans.at(0).at(1) == ans.at(1).at(1) && ans.at(0).at(2) == ans.at(1).at(2)){
    cout << ans.at(2).at(0) << endl;
  }
  else {
    cout << ans.at(1).at(0) << endl;
  }
}


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

int main() {
  int M, H;
  cin >> M >> H;
  if (H%M == 0) {
    cout << "Yes";
  }
  else if (H%M != 0) {
        cout << "No";

  }
}

#include<bits/stdc++.h>
//Ctrl + B
using namespace std;
#define endl '\n'
#define nitro {std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);}
#define pi 3.141592653589793
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(), v.end()
#define debug(x) cout<<#x": "<<(x)<<endl;
#define case_g(x) cout<<"Case "<<x<<": ";
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned long ul;
typedef std::vector<int> vi;
typedef std::vector<ll> vl;
typedef std::vector<bool> vb;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, bool> pib;
typedef std::vector<pii> vii;
typedef std::vector<pll> vll;
typedef std::vector<pib> vib;
typedef std::unordered_map<int, int> umapii;
typedef std::unordered_map<ll, ll> umapll;
typedef std::unordered_map<int , bool> umapib;
typedef std::map<int, int> mapii;
typedef std::map<ll, ll> mapll;
typedef std::map<int, bool> mapib;

ll modpow(ll a, ll b) { //modulo power
	ll result = 1, M=mod;
	while(b!=0) {
		if(b&1) {
			result = ((result%M)*(a%M))%M;
		}
		a = ((a%M)*(a%M))%M;
		b >>= 1;
	}
	return result;
}

ll modinv(ll a) { //modulo inverse
	ll m = mod, y = 0, x = 1;
	while (a > 1) {
		ll q = a / m, t = m;
		m = a % m;
		a = t;
		t = y;
		y = x - q * y;
		x = t;
	}
	return x < 0 ? x + mod : x;
}

void solve()
{
	ll n,k;
	cin >> n >> k;
	for(int i=1;i<=k;i++)
	{
		if(n%200==0)
		{
			n/=200;
		}
		else
		{
			string s= "200";
			string x = to_string(n)+s;
			n = stoll(x);
		}
	}
	cout << n;

}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	#endif
	nitro
	int tc;
	tc =1;
	//cin >> tc;
	for(int i=1; i<=tc; ++i)
	{
		//case_g(i);
		solve();
	}
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if (d>a*c||d<a*b)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vi>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define each(x, a) for (auto&& x : (a))
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
constexpr int inf = (1LL<<31) - 1;
constexpr int mod = 1e9 + 7;
constexpr double eps = 1e-10;
const double pi = acos(-1.0);
constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};
template<typename T> constexpr void print(const T& t) { cout << t << "\n"; }
template<typename T, typename U> constexpr bool chmax(T& a, const U& b) { if (a < b) a = b; return a < b; }
template<typename T, typename U> constexpr bool chmin(T& a, const U& b) { if (a > b) a = b; return a > b; }
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { is >> p.fi >> p.se; return is; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.fi << " " << p.se; return os; }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(e, v) is >> e; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { each(e, v) os << e << " "; return os; }
struct Init { Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }} init;

int main() {
    ll x, y, a, b;
    cin >> x >> y >> a >> b;
    ll cnt = 0;
    while ((double)a*x<=2e18 && a * x < y && x * a <= x + b) {
        x *= a;
        ++cnt;
    }
    cnt += (y - 1 - x) / b;
    print(cnt);
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
struct UnionFind {
	using T = int;
	const T def = 0;
	T f(T a, T b) { return a + b; }
	//==========================================
    vector<int> par;
	vector<T> value;
    UnionFind() {}
    UnionFind(int NV) { init(NV); }
	void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); value.resize(NV, 1); }
    void reset() { rep(i, 0, par.size()) par[i] = i; }
	int operator[](int x) {
		if (par[x] == x) return x;
		else {
			int res = operator[](par[x]);
			if (res != par[x]) {
				value[res] = f(value[res], value[par[x]]);
				value[par[x]] = def;
			}
			return par[x] = res;
		}
	}
	// uf(x,y)->y
    void operator()(int x, int y) {
		x = operator[](x); y = operator[](y);
		if (x != y) {
			value[y] += value[par[x]];
			value[par[x]] = def;
			par[x] = y;
		}
	}
	T getValues(int x) { return value[operator[](x)]; };
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N, M;
vector<int> E[20];
//---------------------------------------------------------------------------------------------------
int vis[20];
void dfs2(int cu, vector<int>& arranged) {
	if (vis[cu]) return;
	vis[cu] = 1;

	arranged.push_back(cu);

	fore(to, E[cu]) dfs2(to, arranged);
}
//---------------------------------------------------------------------------------------------------
int col[20];
ll dfs(int _cu, vector<int>& vs) {
	if (_cu == vs.size()) return 1;
	int cu = vs[_cu];

	vector<int> cnt(3, 0);
	fore(to, E[cu]) if (0 <= col[to]) cnt[col[to]]++;

	int res = 0;
	rep(c, 0, 3) if (cnt[c] == 0) {
		col[cu] = c;
		res += dfs(_cu + 1, vs);
		col[cu] = -1;
	}
	return res;
}
ll get(vector<int> vs) {
	rep(i, 0, N) col[i] = -1;
	rep(i, 0, N) vis[i] = 0;

	vector<int> arrangedVs = vector<int>();
	dfs2(vs[0], arrangedVs);
	return dfs(0, arrangedVs);
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	UnionFind uf(N);
	rep(i, 0, M) {
		int A, B; cin >> A >> B;
		A--; B--;
		uf(A, B);

		E[A].push_back(B);
		E[B].push_back(A);
	}

	map<int, vector<int>> grp;
	rep(i, 0, N) grp[uf[i]].push_back(i);
	ll ans = 1;
	fore(p, grp) ans *= get(p.second);
	cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef int int2;
#define int long long
#define pi pair<int, int>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
const int inf = 1e18;

int t;

const int maxn = 25;
int adj[maxn][maxn];
int n, m;
int color[maxn];

bool dfs(int u, int p, int col) { // returns if there is a cycle
    color[u] = col;
    // cout << "u: " << u << ", p: " << p << ", col: " << col << "\n";
    // cout << "color[u]: " << color[u] << "\n";
    for (int v = 0; v < n; v++) {
        if (adj[u][v]) {
            if (color[v] != -1) {
                if (v != p) {
                    if (color[v] == color[u]) return true;
                    if (color[v] == 0 and dfs(v, u, 3 - col)) return true;
                }
            }
        }
    }
    return false;
}

string encode(int mask) {
    string res;
    for (int i = 0; i < n; i++) {
        res += (char)('0' + ((mask & (1 << i)) >> i));
    }
    return res;
}

int2 main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u][v] = adj[v][u] = 1;
    }
    int maxmask = (1 << n) - 1;
    // int maxmask = 0;
    int ans = 0;
    for (int mask = 0; mask <= maxmask; mask++) {
        // cout << "mask: " << encode(mask) << "\n";
        for (int i = 0; i < n; i++) {
            if (mask & (1 << i)) color[i] = -1;
        }
        int next_ans = 1;
        bool possible = true;
        for (int i = 0; i < n; i++) {
            if (mask & (1 << i)) {
                for (int j = 0; j < n; j++) {
                    if (mask & (1 << j)) {
                        if (adj[i][j]) {
                            possible = false;
                        }
                    }
                }
            }
        }
        if (!possible) {
            for (int i = 0; i < n; i++) {
                color[i] = 0;
            }
            continue;
        }
        for (int i = 0; i < n; i++) {
            if (!color[i]) {
                // cout << "i: " << i << "\n";
                // cout << "color[i]: " << color[i] << "\n";
                bool cycle = dfs(i, i, 1);
                if (cycle) {
                    possible = false;
                    break;
                }
                next_ans *= 2LL;
                // cout << "\n";
            }
        }
        for (int i = 0; i < n; i++) {
            color[i] = 0;
        }
        if (!possible) continue;
        // cout << "mask: " << encode(mask) << ", next_ans:" << next_ans << "\n";
        ans += next_ans;
    }
    cout << ans << "\n";
}


#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	vector<LLONG> as(N); REP(i, N) cin >> as[i];
	vector<LLONG> tmps(N);
	LLONG sum = 0;
	REP(i, N)
	{
		sum += as[i];
		tmps[i] = sum;
	}
	vector<LLONG> sums(N);
	sum = 0;
	REP(i, N)
	{
		sum += tmps[i];
		sums[i] = sum;
	}
	int pos = distance(sums.begin(),
		max_element(sums.begin(), sums.end()));
	sum = sums[pos] - tmps[pos];
	LLONG ans = 0;
	REP(i, pos + 1)
	{
		sum += as[i];
		ans = max(ans, sum);
	}
	if (pos < N - 1)
	{
		REP(i, pos + 2)
		{
			sum += as[i];
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
}

// AtCoder :: Beginner Contest 182 :: D - Wandering
// https://atcoder.jp/contests/abc182/tasks/abc182_d

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<ll> A;
    A.reserve(N);
    copy_n(istream_iterator<ll>(cin), N, back_inserter(A));
    vector<ll> P(N, 0);
    partial_sum(A.begin(), A.end(), P.begin());
    ll posn{0};
    ll soln{0};
    ll max_advance{0};
    for (auto p : P) {
        max_advance = max(max_advance, p);
        soln = max(soln, posn + max_advance);
        posn += p;
    }
    cout << soln << "\n";
    return EXIT_SUCCESS;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
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; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((ll)(c).size())
#define BIT(b,i) ((b>>i) & 1)
#define PCNT(b) __builtin_popcountll(b)
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n'
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; }
string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; }
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

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

    ll N, M; cin >> N >> M;
    VLL ans(N,INF);

    VVLL H(N,VLL(N,INF));
    REP(_,M) {
        ll A, B, C; cin >> A >> B >> C;
        A--; B--;
        if (A == B) {
            chmin(ans[A], C);
        } else {
            chmin(H[A][B], C);
        }
    }

    VVP G(N);
    REP(i,N) REP(j,N) if (H[i][j] != INF) G[i].push_back(P(H[i][j],j));
    VLL dist(N);
    queue<P> q;
    REP(s,N) {
        REP(i,N) dist[i] = INF;
        dist[s] = 0; q.push(P(0, s));
        while (!q.empty()) {
            auto [min_dist, u] = q.front(); q.pop();
            if (dist[u] < min_dist) continue;
            for (auto [c, v] : G[u]) {
                if (v == s) {
                    chmin(ans[s], dist[u] + c);
                } else {
                    if (chmin(dist[v], dist[u] + c)) {
                        q.push(P(dist[v], v));
                    }
                }
            }
        }
    }

    REP(i,N) if (ans[i] == INF) ans[i] = -1;
    REP(i,N) COUT(ans[i]);

    return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) (int)(x).size()
#define lowbit(x) (x)&(-x)
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))

namespace FastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
    bool IOerror=0;
    inline char nc() {
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
        if(p1==pend) {
            p1=buf;
            pend=buf+fread(buf,1,BUF_SIZE,stdin);
            if(pend==p1) {
                IOerror=1;
                return -1;
            }
        }
        return *p1++;
    }
    inline bool blank(char ch) {
        return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
    }
    template<class T> inline bool read(T &x) {
        bool sign=0;
        char ch=nc();
        x=0;
        for(; blank(ch); ch=nc());
        if(IOerror)return false;
        if(ch=='-')sign=1,ch=nc();
        for(; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
        if(sign)x=-x;
        return true;
    }
    template<class T,class... U>bool read(T& h,U&... t) {
        return read(h)&&read(t...);
    }
#undef OUT_SIZE
#undef BUF_SIZE
};
using namespace std;
using namespace FastIO;

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

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

const int INF = 0x3f3f3f3f;
const int N = 2222;

vector<pii>e[N];
int d[N][N];
int dis[N][N],vis[N][N];

void dij(int s){
	dis[s][s] = 0;
	priority_queue<pii>q;
	q.push(mp(0,s));
	while(!q.empty()){
		int u = q.top().se;
		q.pop();
		if(vis[s][u]) continue;
		vis[s][u] = 1;
		for(auto x:e[u]){
			int v = x.fi;
			int w = x.se;
			if(dis[s][v]>dis[s][u]+w){
				dis[s][v] = dis[s][u]+w;
				q.push(mp(-dis[s][v],v));
			}
		}
	}
}

signed main() {

#ifdef xiaofan
    freopen("1.in","r",stdin);
    freopen("1.out","w",stdout);
#endif

	int n,m;
	cin>>n>>m;
	mem(d,INF);
	for(int i=1;i<=m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		e[u].pb(mp(v,w));
		d[u][v] = min(d[u][v],w);
	}
	mem(dis,INF);
	for(int i=1;i<=n;i++) dij(i);
	for(int i=1;i<=n;i++){
		int ans = d[i][i];
		for(int j=1;j<=n;j++){
			if(i!=j) ans = min(ans,dis[i][j]+dis[j][i]);
		}
		if(ans == INF) ans = -1;
		cout<<ans<<endl;
	}

    return 0;
}


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

long long int to_octal(long long int n)
{
    long long int num = 0, cnt = 1;
    while(n != 0) {
        int r = n % 8;
        num += r * cnt;
        cnt = cnt * 10;
        n /= 8;
    }
    return num;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long int n;
    string o, d;
    cin >> n;
    long long int cnt = n;
    long long int len = to_octal(n);
    for(int i = 1; i <= n; ++i) {
        d = to_string(i);
        size_t find1 = d.find("7");
        long long int x = to_octal(i);
        o = to_string(x);
        size_t find2 = o.find("7");
        if(find1 != string::npos) cnt--;
        else if(find2 != string::npos) cnt--;
    }
    cout << cnt << endl;
}

#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007 // 998244353
#define INFLL (1LL<<62)
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
__attribute__((constructor))
void init(){ std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout<<std::fixed<<std::setprecision(15); }
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ll a1, a2, a3, a4;
    cin >> a1>> a2>>a3>>a4;
    cout << min(min(a1, a2), min(a3, a4)) << endl;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 998244353;
using namespace std;

ll fpow(ll base, ll exp) {
	ll res = 1;
	while(exp) {
		if ( exp&1 )
			res = (res*base) % mod;
		exp >>= 1;
		base = (base*base) % mod;
	}
	return res;
}

void solve() {
	int n; cin >> n;
	vector<ll> v(n),pre(n+1);
	ll ans = 0;
	rep(i,0,n) cin >> v[i], ans = (ans + v[i] * v[i] % mod) % mod;
	sort(v.begin(), v.end());
	//pre[0] = v[0];
	rep(i,1,n) pre[i] = v[i];
	pre[0] = v[0];
	rep(i,1,n) {
		pre[i] = (pre[i] + pre[i-1] * 2 % mod) % mod;
		ans = (ans + v[i]*pre[i-1]%mod)%mod;
	}
	cout << ans << '\n';
}

int main(int argc, char * argv[]) {
	ios_base::sync_with_stdio(false); cin.tie(0);
	//int t; cin >> t; while(t--)
	solve();

    return 0;
}

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

using namespace std;

constexpr int MOD = 998244353;
struct M {
    int v;
    M(int x = 0) {
        if (x < -MOD || x >= MOD) x %= MOD;
        v = (x >= 0) ? x : x + MOD;
    }
    explicit operator int() const { return v; }
    bool operator==(const M& b) const { return v == b.v; }
    bool operator!=(const M& b) const { return v != b.v; }
    M operator-() { return M(-v); }
    M operator+=(const M& b) { if ((v += b.v) >= MOD) v -= MOD; return *this; }
    M operator-=(const M& b) { if ((v -= b.v) < 0) v += MOD; return *this; }
    M operator*=(const M& b) { v = (long long)v * b.v % MOD; return *this; }
    M operator/=(const M& b) { return *this *= b ^ (MOD - 2); }
    friend M operator^(M a, int b) {
        M ret = 1;
        for (; b; a *= a, b >>= 1) if (b & 1) ret *= a;
        return ret;
    }
    friend M operator+(M a, const M& b) { return a += b; }
    friend M operator-(M a, const M& b) { return a -= b; }
    friend M operator*(M a, const M& b) { return a *= b; }
    friend M operator/(M a, const M& b) { return a /= b; }
};
using Mod = M;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &i : a) {
        cin >> i;
    }

    sort(a.begin(), a.end());
    Mod ans = 0;
    for (int &i : a) {
        ans += Mod(i) * i;
    }

    Mod cur = 0;
    for (int i = 0; i < n; i++) {
        ans += cur * a[i];
        cur = cur * 2 + a[i];
    }
    cout << int(ans) << '\n';
}

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


#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;
constexpr LL MOD = 1e9 + 7;

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

	int k;
	string s;
	cin >> s >> k;
	for (char &c : s) c = isdigit(c)? (c - '0') : (c - 'A' + 10);

	vector< LL> dp(17);
	dp[1] = s[0] - 1;
	int mask = 1 << s[0];

	for (int i = 1; i < int(s.size()); i++) {
		int d = s[i];
		vector< LL> ndp(17);

		for (int j = 0; j <= 16; j++) {
			(ndp[j] += dp[j] * j) %= MOD;
			if (j + 1 <= 16) (ndp[j + 1] += (16 - j) * dp[j]) %= MOD;
		}

		ndp[1] += 15;
		for (int j = 0; j < d; j++) ndp[__builtin_popcount(mask | (1 << j))]++;

		mask |= (1 << d);
		dp = ndp;
	}

	dp[__builtin_popcount(mask)]++;

	cout << dp[k] << endl;
}

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

//.define
// #define FILE_IN_OUT
#define RET(_x)    cout << (_x) << '\n'; return;
#define all(_obj)  (_obj).begin(), (_obj).end()
#define loop(_n)   for (int i = 0; i < (_n); ++i)
#define sz(_obj)   static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)  std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)  {}
#endif
#define endl "\n"
template<typename P, typename Q>
inline P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll = int64_t;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<int>(1e9 + 7);

//.data
int Add(int x, int y) {
    x += y;
    return x < MOD ? x : x - MOD;
}

int Sub(int x, int y) {
    x -= y;
    return x >= 0 ? x : x + MOD;
}

int Mul(int x, int y) {
    return int(1LL * x * y % MOD);
}

//.code
void SolveTask() {
    int n;
    cin >> n;
    vector<int> arr(n);
    ll sum = 0;
    loop(n) {
        cin >> arr[i];
        sum += arr[i];
    }
    double avg = 1.0 * sum / n;
    sort(all(arr), greater<>());
    double ans = avg;
    loop(n) {
        double x = arr[i] / 2.0;
        ans = min(ans, avg + x - (i * (x + x) + sum) / n);
        sum -= arr[i];
    }
    cout << fixed << setprecision(10) << ans << endl;
}

int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int test_cases = 1;
    // cin >> test_cases;
    for (int yt = 1; yt <= test_cases; ++yt) {
        SolveTask();
    }
#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}


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

using ll=long long;

int main(){

	ll n;
	cin >> n;

	set<ll> st;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			st.insert(i);
			st.insert(n/i);
		}
	}

	for(auto u:st){
		cout << u << endl;
	}
}

#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i, begin, end) for(int i = int(begin); i < int(end); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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 INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;cin >>n;
    for(auto a:divisor(n)){
        cout << a << endl;
    }

}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}

signed main(){
  int n;cin>>n;
  string s;cin>>s;
  vector<int> v(n+1);
  REP(i,n+1)cin>>v[i];
  int mn=1000000;
  REP(i,n)chmin(mn,abs(v[i+1]-v[i]));
  cout<<mn<<endl;
  REP(_,mn){
    REP(i,n+1)cout<<v[i]/mn+(_<v[i]%mn)<<" ";cout<<endl;
  }
}

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

char s[200050];
char t[5]="110";
int check(int i)
{
    int j;
    for(j=0;s[j];j++,i++)
    {
        if(s[j]!=t[i%3]) return 0;
    }
    return 1;
}
int main(){

    int64_t ans=1e10;
    int n;
    cin>>n;
    scanf("%s",s);
    int i;
    for(i=0;i<3;i++)
       if(check(i)) break;

    if(i>=3) ans=0;
    else if(n==1&&s[0]=='1') ans*=2;
    else ans=ans-(i+n-1)/3;
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (998244353)
#define INF (int) 1e9
#define LLINF (ll) 1e18
#define MAX_N (int) 200005

struct UnionFind{
    ll par[MAX_N]; // 親
    ll rank[MAX_N]; // 木の深さ
    ll siz[MAX_N]; // 素集合のサイズ

    // n要素で初期化
    void init(ll n){
        for(ll i=0;i<n;i++){
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    // 木の根を求める
    ll root(ll x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = root(par[x]);
        }
    }

    // xとyの属する集合を併合
    bool unite(ll x, ll y){
        x = root(x);
        y = root(y);
        if(x==y) return false; // 併合失敗
        if(rank[x] < rank[y]){
            par[x] = y;
            siz[y] += siz[x];
        }else{
            par[y] = x;
            siz[x] += siz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
        return true; // 併合成功
    }

    bool issame(ll x, ll y){
        return root(x)==root(y);
    }

    ll size(ll x){
        return siz[root(x)];
    }
};

ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

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

	UnionFind uf;
	uf.init(n);

	rep(i, n){
		int f;
		cin >> f;
		uf.unite(i, f-1);
	}

	set<int> s;
	rep(i, n){
		s.insert(uf.root(i));
	}

	cout << (modpow(2, s.size())-1+MOD)%MOD << endl;
	// printf("%d\n", N);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  int s=0,t=0;
  while(a)
  {s+=a%10;
   a/=10;
  }
  while(b)
  {t+=b%10;
   b/=10;
  }
  cout<<max(s,t);
}


/**
*    author: Dooloper
*    created: 15.05.2021 20:54:02
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repp(i,k, n) for(int i = (int)(k); i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using P = pair<int, int>;
struct Edge{int to; ll w; Edge(int to, ll w) : to(to), w(w) {}};
using Graph = vector<vector<Edge>>;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

ll kaijo(int x, int k){
    int ans = 1;
    rep(i,k){
        ans *= x;
        x--;
    }
    return ans;
}

int main(){
    string s; cin >> s;
    vector<int> table(10,0);
    rep(i,10){
        if(s[i] == 'o') table[i] = 2;
        if(s[i] == '?') table[i] = 1;
        if(s[i] == 'x') table[i] = 0;
    }

    int ans = 0;

    rep(i,10){
        rep(j,10){
            rep(k,10){
                rep(l,10){
                    vector<bool> ok(10,false);
                    rep(m,10) ok[m] = false;
                    bool flag = true;
                    ok[i] = true;
                    ok[j] = true;
                    ok[k] = true;
                    ok[l] = true;
                    rep(m,10){
                        if(ok[m] == false && table[m] == 2) flag = false;
                        if(ok[m] == true && table[m] == 0) flag = false;
                    }
                    if(flag) ans ++;
                    //if(flag) cout << i << j << k << l << endl;
                }
            }
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define F first
#define S second
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> cnd(m);
    rep(i,m){
        cin>>cnd.at(i).F>>cnd.at(i).S;
    }
    int k;
    cin>>k;
    vector<pair<int,int>> put(k);
    rep(i,k){
        cin>>put.at(i).F>>put.at(i).S;
    }
    int ans=0;
    rep(i,1<<k){
        vector<int> dish(n);
        rep(j,k){
            if((i>>j)%2==1){
                dish.at(put.at(j).F-1)=true;
            }
            else{
                dish.at(put.at(j).S-1)=true;
            }
        }
        int cnt=0;
        rep(i,m){
            if(dish.at(cnd.at(i).F-1)&&dish.at(cnd.at(i).S-1)==true){
                cnt++;
            }
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PIL = pair<int,ll>;
using PLI = pair<ll,int>;
using PLL = pair<ll,ll>;
using Graph = vector<vector<int>>;
using Cost_Graph = vector<vector<PIL>>;

template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}
#define rep(i,n) for(int i=0;i<int(n);i++)
#define roundup(a,b) (a+b-1)/b
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;
const double pi = 3.14159265358979;

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

    int h,w;
    cin >> h >> w;
    vector<vector<char>> table(h, vector<char>(w));
    for (int i = 0;i < h;i++){
        for (int j = 0;j < w;j++){
            cin >> table[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < h-1; i++){
        for (int j = 0; j < w-1; j++){
            int counter = 0;
            if (table[i][j] == '#') counter++;
            if (table[i+1][j] == '#') counter++;
            if (table[i][j+1] == '#') counter++;
            if (table[i+1][j+1] == '#') counter++;

            if (counter == 1 || counter == 3) ans++;
        }
    }

    cout << ans << endl;
}

#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
#include<stdio.h>
#include<string.h>
const double pi=acos(-1.0);
using namespace std;
//using namespace __gnu_pbds;
#define   endl    '\n'
#define   sl(n)     scanf("%lld",&n)
#define   mp      make_pair
#define   pb      push_back
#define   ppb     pop_back
#define   fi      first
#define   se      second
#define   ll      long long
#define   ull     unsigned long long
#define   ld      long double
#define   pii     pair<int, int>
#define   f(i,a,b)  for(ll i = (ll)(a); i < (ll)(b); i++)
#define   rf(i,a,b)   for(ll i = (ll)(a); i > (ll)(b); i--)
#define   ms(a,b)   memset((a),(b),sizeof(a))
#define   abs(x)    ((x<0)?(-(x)):(x))
#define   MAX     1000005
#define   inf     LLONG_MAX
#define   ninf    LLONG_MIN
#define   MIN     INT_MIN
#define   yeet    return 0;
#define tihs if(fopen("input.txt","r"))freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);

#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long  b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}

//typedef
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int mod = 1e9 +7 ;
int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {if (!a) {x = 0;y = 1;return b;}int64_t x1, y1;int64_t d = extGcd(b % a, a, x1, y1);x = y1 - (b / a) * x1;y = x1;return d;}
inline ll addmod(ll a,ll b){a=a%mod+b%mod;if(a>mod)a%=mod;return a;}
inline ll submod(ll a,ll b){a=a%mod-b%mod;if(a<0)a+=mod;return a;}
inline ll mulmod(ll a,ll b){return (a%mod * b%mod)%mod;}

int dx[]={1,1,0,-1,-1,-1, 0, 1};
int dy[]={0,1,1, 1, 0,-1,-1,-1};
inline ll exp(ll a,ll b){if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=r*(a%mod);r=(r+mod)%mod;}b/=2;a=(a%mod)*(a%mod);a=(a+mod)%mod;}return (r+mod)%mod;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
uint32 setbits(ll n){uint32 count=0;while (n){n&=(n-1);count++;}return count; }

////****************************************************************************************************************************************************************************************************************////

int main(){
    int h,w;
	cin>>h>>w;
	vector<string> s(h);

	f(i,0,h){
	    cin>>s.at(i);
	}
int ans=0;
	f(i,0,h-1){
	f(j,0,w-1){
	    if(s.at(i).at(j)=='#'&&s.at(i+1).at(j)=='.'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j+1)=='.'){
	        ans++;
	    }
	    if(s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='#'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j+1)=='.'){
	        ans++;
	    }
	    if(s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='.'&&s.at(i).at(j+1)=='#'&&s.at(i+1).at(j+1)=='.'){
	        ans++;
	    }
	    if(s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='.'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j+1)=='#'){
	        ans++;
	    }
	    if(s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='#'&&s.at(i).at(j+1)=='#'&&s.at(i+1).at(j+1)=='#'){
	        ans++;
	    }
	    	    if(s.at(i).at(j)=='#'&&s.at(i+1).at(j)=='.'&&s.at(i).at(j+1)=='#'&&s.at(i+1).at(j+1)=='#'){
	        ans++;
	    }
	    	    if(s.at(i).at(j)=='#'&&s.at(i+1).at(j)=='#'&&s.at(i).at(j+1)=='.'&&s.at(i+1).at(j+1)=='#'){
	        ans++;
	    }
	    	    if(s.at(i).at(j)=='#'&&s.at(i+1).at(j)=='#'&&s.at(i).at(j+1)=='#'&&s.at(i+1).at(j+1)=='.'){
	        ans++;
	    }
	}
	}
cout<<ans;
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }

ll myceil(ll a, ll b) { return (a + (b - 1)) / b; }
/*** mod int ***/
// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}; //comb(2000005);

using vm = vector<mint>;
using vvm = vector<vm>;

mint dp[5005][5005];
int ch[5005][5005];

void Main(){
    int h, w, k; cin >> h >> w >> k;
    rep(i, k){
        int a, b; char c;
        cin >> a >> b >> c;
        a--; b--;
        int tmp = c - 'A';
        ch[a][b] = tmp;
    }
    int cnt = h * w - k;

    mint inv3 = mint(1)/3;

    dp[0][0] = mint(3).pow(cnt);
    rep(i, h) rep(j, w){
        if(ch[i][j] == 0){
            if(i+1 < h) dp[i+1][j] += dp[i][j] * 2 * inv3;
            if(j+1 < w) dp[i][j+1] += dp[i][j] * 2 * inv3;
        }else if(ch[i][j] == int('D' - 'A')){
            if(i+1 < h) dp[i+1][j] += dp[i][j] * 1;
            if(j+1 < w) dp[i][j+1] += dp[i][j] * 0;
        }else if(ch[i][j] == int('R' - 'A')){
            if(i+1 < h) dp[i+1][j] += dp[i][j] * 0;
            if(j+1 < w) dp[i][j+1] += dp[i][j] * 1;
        }else if(ch[i][j] == int('X' - 'A')){
            if(i+1 < h) dp[i+1][j] += dp[i][j] * 1;
            if(j+1 < w) dp[i][j+1] += dp[i][j] * 1;
        }
    }
    cout << dp[h-1][w-1] << endl;
    return;
}

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

/* C - Robot on Grid */
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using pii = pair<int, int>;

const int N = 5e3 + 10;
const int mod = 998244353;
int h, w, n, s[N][N];
char a[N][N];

int ksm(int a, int b, int p)
{
    int res = 1 % p;
    while (b) {
        if (b & 1) res = (ll)res * a % p;
        a = (ll)a * a % p;
        b >>= 1;
    }
    return res;
}

int solve(void)
{
	int inv = ksm(3, mod - 2, mod);
	s[1][1] = 1;
	for (int k = 1; k <= h; ++k) {
		for (int i = 1; i <= w; ++i) {
			if ('R' == a[k][i]) 		s[k][i + 1] = (s[k][i] + s[k][i + 1]) % mod;
			else if ('D' == a[k][i])	s[k + 1][i] = (s[k][i] + s[k + 1][i]) % mod;
			else if ('X' == a[k][i]) {
				s[k][i + 1] = (s[k][i] + s[k][i + 1]) % mod;
				s[k + 1][i] = (s[k][i] + s[k + 1][i]) % mod;
			}
			else {
				int val = (ll)s[k][i] * 2 * inv % mod;
				s[k][i + 1] = (val + s[k][i + 1]) % mod;
				s[k + 1][i] = (val + s[k + 1][i]) % mod;
			}
		}
	}
	return (ll)s[h][w] * ksm(3, h * w - n, mod) % mod;
}

signed main(int argc, char** argv)
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	#endif
	while (cin >> h >> w >> n) {
		for (int k = 1; k <= n; ++k) {
			int x, y;
			char c;
			cin >> x >> y >> c;
			a[x][y] = c;
		}
		cout << solve() << endl;
	}
	return 0;
}


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

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

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

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

int main(){
    ll n,a[10001],min,max,ans=0;
    cin>>n;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        min=INF;
        max=0;
        rep_up(j,i,n){
            chmin(min,a[j]);
            chmax(max,min*(j-i+1));
        }
        chmax(ans,max);
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
ll a[maxn] , b[maxn] , c[maxn] , d[maxn];
int main()
{
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for (int i = 1 ; i <= n ; i++){
        cin >> a[i];
        d[i] = max(d[i - 1] , a[i]);
    }
    for (int i = 1 ; i <= n ; i++){
        cin >> b[i];
    }
    for (int i = 1 ; i <= n ; i++){
        c[i] = max(c[i - 1] , d[i] * b[i]);
        cout << c[i] << endl;
    }
    return 0;
}


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

double dp[101][101][101];

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;

  cout << fixed << setprecision(9) << f(a,b,c) << endl;

  return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forr(i,n) for(int i=int(n-1);i>=0;i--)
#define fora(i,a,b) for(int i=int(a);i<=int(b);i++)
#define forb(i,a,b) for(int i=int(a);i>=int(b);i--)
#define mod 1000000007
using namespace std;
using ll=long long int;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vii;
typedef pair<ll ,ll> pii;

vector<tuple<int,int,int> > v;
int dis(tuple<int,int,int> p, tuple<int,int,int> q)
{
    int a=get<0>(p),b=get<1>(p),c=get<2>(p);
    int x=get<0>(q),y=get<1>(q),z=get<2>(q);
    int ans=abs(x-a)+abs(y-b)+max(0,z-c);
    return ans;
}
int dp[18][1<<18];
void init()
{
    for(int i=0;i<18;i++)
    {
        for(int j=0;j<(1<<18);j++)
        {
            dp[i][j]=-1;
        }
    }
}
int go(int mask,int n,int cur)
{
    if(mask==0)
    {
        return dis(v[cur],v[0]);
    }
    int &x=dp[cur][mask];
    if(x!=-1)return x;
    int ans=INT_MAX;
    forn(i,n)
    {
        if((mask&(1<<i)))
        {
            int cost=0;
            cost = dis(v[cur],v[i]);
            ans=min(ans,cost+go(mask^(1<<i),n,i));
        }
    }
    return x=ans;
}
void solve()
{
    init();
    int n;
    cin>>n;
    int mask=(1<<n)-1;
    forn(i,n)
    {
        int a,b,c;
        cin>>a>>b>>c;
        v.pb({a,b,c});
    }
    cout<<go(mask,n,0);

}

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


#include <bits/stdc++.h>

const int phi10 = 4;// 1 3 7 9
int a, b, c;

int qpow(int a, int b, int p){
	int res = 1;
	a %= p;
	while(b){
		if(b & 1) res = res * a % p;
		a = a * a % p, b >>= 1;
	}
	return res;
}

int main(){
	std::scanf("%d%d%d", &a, &b, &c);
	std::printf("%d\n", qpow(a, qpow(b, c, phi10) + phi10, 10));
}

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

using namespace std;
#define int long long
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define all(x) x.begin(),x.end()

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

void solve()
{
  int a,b,c;
  map<int,vector<int>> mp;
  mp[2] = {6,2,4,8};
  mp[3] = {1,3,9,7};
  mp[7] = {1,7,9,3};
  mp[8] = {6,8,4,2};
  cin >> a >> b >> c;
  if(a%10==0 || a%10==5 || a%10==6 || a%10==1){
    cout << a%10 << endl;
    return;
  }
  else if(a%10==4){
    if(b%2==0) cout << 6 << endl;
    else cout << 4 << endl;
  }
  else if(a%10==9){
    if(b%2==0) cout << 1 << endl;
    else cout << 9 << endl;
    return;
  }
  else{
    int r = b%4;
    if(r==0) cout << mp[a%10].at(0) << endl;
    else if(r==1) cout << mp[a%10].at(1) << endl;
    else if(r==2){
        if(c>=2) cout << mp[a%10].at(0) << endl;
        else cout << mp[a%10].at(2) << endl;
    }
    else if(r==3){
        if(c%2==0) cout << mp[a%10].at(1) << endl;
        else cout << mp[a%10].at(3) << endl;
    }
    return;
  }
}

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


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

int main(){
    int n=0;
    long long sum=0;
    cin>>n;
    vector <int> a(n);
    vector <long long> b(401);
    vector <long long> c(401);

    for (int k=0;k<401;k++){
        b.at(k)=k-200;
    }

    for (int k=0;k<401;k++){
        c.at(k)=0;
    }

    for (int i=0;i<n;i++){
        cin>>a.at(i);
    }
    for (int i=0;i<401;i++){
        for (int j=0;j<n;j++){
            if (b.at(i)==a.at(j)){
                c.at(i)++;
            }
        }
    }

    for (int i=0;i<401;i++){
        for (int j=0;j<401;j++){
            sum+=c.at(i)*c.at(j)*(b.at(i)-b.at(j))*(b.at(i)-b.at(j));
        }
    }
    cout<<sum/2;
    }

#include <iostream>
#include <vector>
#include <map>

using namespace std;

// int main(){
//     int k;
//     cin >> k;
//     int ans = 0;
//     for(int a=1;a<=k;a++){
//         for(int b=a;b<=k;b++){
//             for(int c=b;a*b*c<=k;c++){
//                 if(a==b && b==c){
//                     ans++;
//                 }else if(a==b  || b==c || c==a){
//                     ans += 3;
//                 }else{
//                     ans += 6;
//                 }
//             }
//         }
//     }
//     cout << ans << endl;
// }

int combination(int n, int r)
{
    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

int main(){
    int k;
    cin >> k;
    vector<int> spf(k+1, 0);
    spf[1] = 1;
    for(int i=2;i<=k;i++){
        if(spf[i]==0){
            for(int j=i;j<=k;j+=i){
                if(spf[j]==0){
                    spf[j] = i;
                }
            }
        }
    }

    int ans = 0;
    for(int i=1;i<=k;i++){
        int tmp = 1;
        vector<int> factors;
        int c = i;
        map<int,int> m;
        while(c!=1){
            if(m.count(spf[c]) == 0){
                m[spf[c]] = 1;
            }else{
                m[spf[c]] = m[spf[c]] + 1;
            }
            c /= spf[c];
        }
        for(auto const& [k, v]: m){
            tmp *= combination(v+2, 2);
        }
        ans += tmp;
    }
    cout << ans << endl;

}


#include <bits/stdc++.h>

using namespace std ;

const int MAX = 20 ;

int n , m ;
long long dp[1 << MAX] ;

vector< pair<int , int> >v[MAX] ;

long long solve(int mask)
{
	if(mask == ((1 << n) - 1))
		return 1 ;
	long long &ret = dp[mask] ;
	if(ret != -1)
		return ret ;
	ret = 0 ;
	int idx = __builtin_popcount(mask) ;
	for(auto &p : v[idx])
	{
		int y = p.first , z = p.second ;
		int cnt = 0 ;
		for(int bit = 0 ; bit < y ; ++bit)
		{
			if((mask & (1 << bit)))
				cnt++ ;
		}
		if(cnt > z)
			return 0 ;
	}
	for(int bit = 0 ; bit < n ; ++bit)
	{
		if((mask & (1 << bit)))
			continue ;
		ret += solve(mask | (1 << bit)) ;
	}
	return ret ;
}

int main()
{
	memset(dp , -1 , sizeof(dp)) ;
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	for(int i = 0 ; i < m ; ++i)
	{
		int x , y , z ;
		cin>>x>>y>>z ;
		v[x].emplace_back(y , z) ;
	}
	return cout<<solve(0)<<"\n" , 0 ;
}

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

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

ll dp[1 << 18];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<pair<int, int>> XYZ[20];
	rep(i, M) {
		int x, y, z;
		cin >> x >> y >> z;
		XYZ[y].pb({ x, z });
	}

	dp[0] = 1;
	rep(i, 1 << N) {
		int c = __builtin_popcount(i);
		int OK = 1;
		for (auto p : XYZ[c]) {
			if (__builtin_popcount(i << 32 - p.first) > p.second) {
				OK = 0;
				break;
			}
		}
		if (!OK) {
			dp[i] = 0;
		}
		else {
			int tmp = i;
			for(int j = i + 1; j < (1 << N); j = tmp + 1) {
				dp[i | j] += dp[i];
				tmp |= j;
			}
		}
	}
	co(dp[(1 << N) - 1]);

	Would you please return 0;
}


#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll inf = ll(1e18) + 1;
const ll mod = 1000000007;

int main() {
	char win[222][222];
	win['R']['R'] = win['R']['S'] = win['S']['R'] = 'R';
	win['S']['S'] = win['S']['P'] = win['P']['S'] = 'S';
	win['P']['P'] = win['P']['R'] = win['R']['P'] = 'P';

	ll n,k;
	string s;
	cin >>n >> k >>s;

	while(k--){
		string t = s+s;

		rep(i,n){
			s[i] = win[t[i*2]][t[i*2+1]];
		}

	}

	cout << s[0] << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long INF=1e19+7;
int main()
{
	long long b,c; cin>>b>>c;
	vector<pair<long long,long long> >a;
	a.push_back(make_pair(b-c/2,b));
	if(c>=1) a.push_back(make_pair(-b-(c-1)/2,-b));
	if(c>=1) a.push_back(make_pair(-b,-b+(c-1)/2));
	if(c>=2) a.push_back(make_pair(b,b+(c-2)/2));
	long long cnt=-INF,ans=0;
	sort(a.begin(),a.end());
	for(int i=0;i<a.size();i++){
		cnt=max(cnt,a[i].first);
		if(a[i].second>=cnt){
			ans+=a[i].second-cnt+1;
			cnt=a[i].second+1;
		}
	}
	cout<<ans<<endl;
    return 0;
}

#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
using namespace std;
#define f(x,y,z) for(int x=y;x<=z;++x)
vector<int> v[200001];
array<int, 200001> jr, dkt, tdk, at, uj;
int n, k, a, b, l, r, m, hit;
void jrk(int x) {
    for(int &i:v[x]) if(i != at[x]) {
        at[i] = x, jr[i] = jr[x]+1, jrk(i);
    }
}
bool cek(int &x) {
    // cerr << x;
    fill(dkt.begin(), dkt.end(), 0x3f3f3f3f);
    fill(tdk.begin(), tdk.end(), 0);
    hit = 0;
    f(i,1,n) {
        int &z = uj[i];
        // cerr << ' ' << z;
        if(dkt[z]+tdk[z] <= x) {
            tdk[z] = -1;
        } else if(tdk[z] == x || (z == 1 && tdk[z] >= 0)) {
            ++hit, tdk[z] = -1, dkt[z] = 0;
        }
        tdk[at[z]] = max(tdk[at[z]], tdk[z]+1);
        dkt[at[z]] = min(dkt[at[z]], dkt[z]+1);
    }
    // cerr << '\n';
    return hit <= k;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> k;
    f(i,2,n) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    jrk(1);
    f(i,1,n) uj[i] = i;
    sort(uj.begin()+1, uj.begin()+n+1, [](int &i, int &j){
        return jr[i] > jr[j];
    });
    l = 1, r = n-1;
    while(l <= r) {
        m = (l+r)>>1;
        cek(m) ? r = m-1 : l = m+1;
    }
    cout << l << '\n';
}


#include <bits/stdc++.h>

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)
#define K 400001
#define LL long long
#define mp make_pair
#define pb push_back
#define M 1000000007
#define pow qjwopjqpw

int n, a[K];

vector<int> good;

int main() {
	scanf("%d", &n);

	int b[4] = {3, 5, 7, 11};

	FOE(i, 1, 10000 / 2) {
		int cnt = 0;
		FOR(j, 0, 4) if (i % b[j] != 0) cnt++;

		if (cnt != 4) good.pb(i);
	}

	FOE(i, 1, n - 1) printf("%d ", good[i - 1] * 2);
	printf("%d\n", 3 * 5 * 7 * 11);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> v = {6, 10, 15, 12, 18, 20, 24, 30};
    int cur = 0;
    int plus = 0;
    while (n--) {
        cout << v[cur] + plus << " ";
        cur++;
        if (cur == 8) {
            cur = 0;
            plus += 30;
        }
    }
    cout << endl;
}


#include<bits/stdc++.h>
#define REP(i,b,e) for(int i=b;i<e;i++)

int main(){
	int n, m;
	std::cin >> n >> m;
	std::string ss[m];
	REP(i, 0, m) std::cin >> ss[i];

	std::string ans[n];
	bool used[m] = {};

	REP(si, 0, m){

		int minrow = 0, crost = 50, min_add_len = ss[si].size();
		REP(i, 0, n){
			REP(j, 0, ans[i].size()){
				std::string s1 = ans[i].substr(j);
				std::string s2 = ss[si].substr(0, ans[i].size()-j);
				if(s1 != s2) continue;

				int pushlen = ss[si].size() - ans[i].size() + j;
				if(ans[i].size() + pushlen < n && min_add_len > pushlen){
					min_add_len = pushlen;
					minrow = i;
					crost = j;
				}
			}
		}

		crost = std::min<int>(crost, ans[minrow].size());
		std::string pushs = ss[si].substr(ans[minrow].size() - crost);
		while(minrow < n && ans[minrow].size() + pushs.size() > n) minrow++;
		if(minrow == n) continue;
		ans[minrow] += pushs;
		used[si] = true;

		//for(auto &s: ans) std::cout << s << '\n'; puts("");
	}

	REP(si, 0, m) if(!used[si]) {

		std::sort(ans, ans+n, [](std::string x, std::string y){
			return x.size() > y.size();
		});

		REP(j, 0, n){
			int ok_cnt = 0;
			REP(i, 0, n){
				if(ans[i].size() <= j) ok_cnt++;
			}
			if(ok_cnt < ss[si].size()) continue;

			int idx = 0;
			REP(i, 0, n){
				if(idx >= ss[si].size()) break;
				if(ans[i].size() <= j){
					ans[i] += std::string(j - ans[i].size(), '.');
					ans[i] += ss[si][idx];
					idx++;
				}
			}
			used[si] = true;
			break;
		}
	}

	for(auto &s: ans){
		if(s.size() < n){
			 s += std::string(n-s.size(), '.');
		}
	}

	for(auto &s: ans){
		std::cout << s << '\n';
	}
	return 0;
}

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

int main() {
    mt19937 rng(48);
    cout.tie(nullptr)->sync_with_stdio(false);
    int N, M; cin >> N >> M;

    array<array<bool, 20>, 20> graph{};
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        --a, --b;
        graph[a][b] = graph[b][a] = true;
    }

    int mi = N;
    vector<int> S(N), cc(N);
    iota(S.begin(), S.end(), 0);

    while (clock() <= 1.9 * CLOCKS_PER_SEC) {
        shuffle(S.begin(), S.end(), rng);
        int color = 1;
        for (int i = 1; i < N; ++i) {
            int Q = 0;
            for (int j = 0; j < i; ++j) {
                if (!graph[S[j]][S[i]]) Q |= (1 << cc[j]);
            }
            Q ^= (1 << color) - 1;
            if (Q == 0) {
                cc[i] = color++;
            } else {
                while (true) {
                    cc[i] = uniform_int_distribution<int>(0, color + 1)(rng);
                    if (Q & (1 << cc[i])) break;
                }
            }
        }
        mi = min(mi, color);
    }

    cout << mi << '\n';
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define N 200100
#define MOD 1000000007 //998244353
#define ll long long
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define rep3(i, a, b) for(int i = a; i >= b; --i)
#define eb emplace_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>

int main() {
	int a, b, x, y;
	int ans;
	cin >> a >> b >> x >> y;
	if (a > b) {
		ans = x + (min(2 * x, y) * (a - b - 1));
	}
	else ans = x + (min(2 * x, y)*(b - a));
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros">
#define endl "\n"
#define long long long
#define all(v) (v).begin(),(v).end()
#define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin())
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define getline(x) getline(cin,x)
#define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
bool sortby(pair<int,int> a,pair<int,int> b){
    double x=(double )a.first/a.second;
    double y=(double )b.first/b.second;
    return x<y;}
long Pow(long x, long y) {
    if(y == 0)return 1;
    long tmp=Pow(x,y/2);
    tmp*=tmp;
    if(y&1)tmp*=x;
    return tmp;
}
#define printcase(x)  cout<<"Case "<<in++<<": "<<x<<endl
#define memset(a,b) memset(a,b,sizeof(a))
#define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl;
#define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;}
#define pi acos(-1)
#define esp 1e-9
////////////////////////////////////////////////////////////////////////////</editor-fold>
int t,n,m,c,r,q,k,d,tmp=0,cyc=0,last=0,counter=0,root;
vector<int> g[100010];

int main() {
///<editor-fold desc="ios">
    IOS
#ifdef _AD_
    filein //fileout
#endif
///</editor-fold>

    int in=1,o;
    int a=0,b=0,f=1,cc;
    cin>>n>>m>>t;
    cc=n;
    for(int i = 0; i < m; ++i){
        cin>>a;
        n-=a-b;
        if(n<1)f=0;
        //cout<<n<<endl;
        cin>>b;
        n+=b-a;
        if(n>cc)n=cc;
        if(n<1)f=0;
        //cout<<n<<endl;

    }
    n-=t-b;
    if(n<1)f=0;
    //cout<<n<<endl;
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;
/* using namespace atcoder; */

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

// 約数を列挙
vector<long long> enumerateDivisors(long long n) {
  vector<long long> res;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      // 対応する約数も追加(自分自身でなければ)
      if (n / i != i) {
        res.push_back(n / i);
      }
    }
  }
  // 昇順にソート
  sort(res.begin(), res.end());
  return res;
}

int main() {
  ll n;
  cin >> n;
  auto res = enumerateDivisors(n);
  rep(i, res.size()) {
    cout << res.at(i) << endl;
  }
  return 0;
}

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

//解説ver
int main(){
	init();
	inl(n,m);
	V<ll> a(n),b(m);
	in1(a);
	in1(b);
	VV<ll> dp(n+1,V<ll>(m+1,INF));
	rep(i,n+1)dp[i][0]=i;
	rep(j,m+1)dp[0][j]=j;
	reps(i,0,n+1){
		reps(j,0,m+1){
			if(i>0)chmin( dp[i][j] , dp[i-1][j]+1 );
			if(j>0)chmin( dp[i][j] , dp[i][j-1]+1 );
			if(i>0 && j>0)chmin( dp[i][j] , dp[i-1][j-1]+(a[i-1]!=b[j-1]?1:0) );
		}
	}
	//rep(i,n+1)outv(dp[i]);
	out(dp[n][m]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define lowbit(x) (x&-x)
#define reg register
#define mkpr make_pair
#define fir first
#define sec second
typedef long long LL;
typedef unsigned long long uLL;
const LL INF=0x7f7f7f7f7f7f7f7f;
const int mo=998244353;
const int zero=500;
const LL jzm=2333;
const int iv2=499122177;
const double Pi=acos(-1.0);
typedef pair<int,int> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=getchar();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
	while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
	x*=f;
}
template<typename _T>
void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');}
int t;LL X,Y,P,Q,x[1005],y[1005],d[1005];
LL exgcd(LL a,LL b,LL &x,LL &y){
	if(!b){x=1;y=0;return a;}
	LL d=exgcd(b,a%b,y,x);y-=x*(a/b);return d;
}
signed main(){
	read(t);
	while(t--){
		read(X);read(Y);read(P);read(Q);
		LL A=P+Q,B=2ll*X+2ll*Y,res=INF;
		for(LL i=-Q;i<=Y;i++)d[i+zero]=exgcd(A,B,x[i+zero],y[i+zero]);
		for(LL i=P;i<P+Q;i++)
			for(LL j=X;j<X+Y;j++){
				LL t=j-i,d1=d[t+zero-X+P];if(t%d1!=0)continue;
				LL ax=t/d1*x[t+zero-X+P],ay=i/d1*y[t+zero-X+P],a1=B/d1,b1=A/d1,k;
				if(ax<0)k=(a1-ax)/a1,ax+=k*a1,ay-=k*b1;
				if(ax>=0)k=(ax-1)/a1,ax-=k*a1,ay+=k*b1;
				if(ay>0)k=(ay-1)/b1,ax+=k*a1,ay-=k*b1;
				res=min(ax%a1*A+i,res);
			}
		for(LL i=-Q;i<=Y;i++)d[i+zero]=x[i+zero]=y[i+zero]=0;
		if(res>INF-1)puts("infinity");else printf("%lld\n",res);
	}
	return 0;
}
/*
[(2X+2Y)n+X,(2X+2Y)n+X+Y)
[(P+Q)m+P,(P+Q)(m+1))
(X-P)<=(P+Q)m%(2X+2Y)<(X+Y-P)
(P+Q)x+(2X+2Y)y=+j-i
*/

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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

#define mp make_pair
#define fr first
#define sc second

int lg(ll n) {
    assert(n > 0);
    int ans = -1;
    while (n) {
        ans++;
        n >>= 1;
    }
    return ans;
}

tuple<ll, ll, ll> extgcd(ll a, ll b) {
    // ax + by = gcd(a, b)
    ll x = 1, y = 0;
    ll x1 = 0, y1 = 1, a1 = a, b1 = b;
    while (b1) {
        ll q = a1 / b1;
        tie(x, x1) = make_tuple(x1, x - q * x1);
        tie(y, y1) = make_tuple(y1, y - q * y1);
        tie(a1, b1) = make_tuple(b1, a1 - q * b1);
    }
    // return a1;
    return make_tuple(a1, x, y);
}

ll renorm(ll num, ll mod) {
    num %= mod;
    return num < 0 ? num + mod : num;
}
ll crt_two(ll r1, ll m1, ll r2, ll m2) {
    r1 = renorm(r1, m1);
    r2 = renorm(r2, m2);
    if (m2 == m1) {
        if (r1 == r2) {
            return r1;
        } else {
            return 9e18;
        }
    }
    // x1 = r1 + m1 * k1, x2 = r2 + m2 * k2
    // m1 * k1 - m2 * k2 = r2 - r1
    auto [g, k1, k2] = extgcd(m1, m2);
    if ((r2 - r1) % g) {
        return 9e18;
    }
    // return renorm(r1 + (r2 - r1) / g * m1 * k1, m1 / g * m2);
    return renorm(renorm((r2 - r1) / g * k1, m2 / g) * m1 + r1, m1 / g * m2);
}

void solve() {
    ll X, Y, P, Q;
    cin >> X >> Y >> P >> Q;
    ll ans = 9e18;
    for (ll t1 = X; t1 < X + Y; t1++) {
        for (ll t2 = P; t2 < P + Q; t2++) {
            // ans % 2(X+Y) = t1
            // ans % (P+Q) = t2
            ans = min(ans, crt_two(t1, 2 * (X + Y), t2, P + Q));
        }
    }
    if (ans == 9e18)
        cout << "infinity" << '\n';
    else
        cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(), c.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, a, b) for (int i = a; i <= b; ++i)
#define rep3(i, a, b) for (int i = a; i >= b; --i)
#define endl '\n'
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
template <class T, class S>
inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S>
inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
typedef int64_t ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// constexpr int inf = 1e9;
// constexpr int_64t inf = 1e18;
// const int N = 100 * 1000 + 5;
// const int mod = 1e9 + 7;
tuple<int, int, int> ext_gcd(int a, int b) { // 1. a = bq + r;
    if (b == 0)
        return {a, 1, 0}; // 3. r = 0
    int g, x, y;
    tie(g, x, y) = ext_gcd(b, a % b); // 2. b = rq` + r`
    return {g, y, x - (a / b) * y};
}

void Conpairu() {
    ll n, s, k;
    cin >> n >> s >> k;
    ll g, x, y;
    tie(g, x, y) = ext_gcd(k, n);
    // we find ny + kx and need only x.
    if (s % g == 0) {
        n /= g;
        s /= g;
        k /= g;
        ll ans = ((x * -s) % n + n) % n;
        // minus operation with modular . ((A - B) + n) % n
        // multiple operation with modular (A * B) % n
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        Conpairu();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y;
void exgcd(ll a,ll b,ll &x,ll &y)
{
	if(!b) x=1,y=0;
	else exgcd(b,a%b,y,x),y=y-(a/b)*x;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		ll n,s,k;
		scanf("%lld%lld%lld",&n,&s,&k);
		ll a=n-s;
		ll b=__gcd(k,n);
		if(a%b!=0){
			printf("-1\n");
		}
		else{
			k/=b;
			n/=b;
			a/=b;
			exgcd(k,n,x,y);
			x=x*a;
			x=(x%n+n)%n;
			printf("%lld\n",x);
		}
	}
 }


#pragma GCCoptimize("O3", "unroll-loops")
#include <cstring>
#include <iostream>
using namespace std;
using ll = long long;

const int MAXN = 102;
const int MAXC = 122505;

ll k, mod, table[MAXN][MAXC], ret[MAXN];
int n, now;

void calc() {
    memset(table, 0, sizeof(table));
    table[0][0] = 1;

    for (int i = 1; i <= n; ++i) {
        int c = (k * (i + 1) * i) >> 1;
        c = min(c, MAXC - 1);
        for (int j = 0; j <= c; ++j) {
            for (int v = 0; v <= k; ++v) {
                int tmp = j + v * i;
                if (tmp > c) break;
                table[i][tmp] += table[i-1][j];
                if (table[i][tmp] >= mod) table[i][tmp] -= mod;
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    while (cin >> n >> k >> mod) {
        calc();
        for (now = 1; now * 2 <= n + 1; now++) {
            ll ans = 0;
            int l = now - 1, r = n - now;

            ans += k * table[l][0] * table[r][0];
            ans %= mod;

            for (int j = 1; j < MAXC; ++j) {
                ans += (k + 1LL) * ((table[l][j] * table[r][j]) % mod);
                ans %= mod;
            }

            ret[now] = ans;
            ret[n - now + 1] = ans;
        }

        for (now = 1; now <= n; ++now) cout << ret[now] << '\n';
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
inline int mrand(int k) {return abs((int) mt()) % k;}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";

void chemthan() {
    int n, k, p; cin >> n >> k >> p;
    static int dp[105][105 * 105 * 105];
    dp[0][0] = 1;
    FOR(i, 0, n) {
        FOR(j, 0, n * n * k / 2 + 5) if (dp[i][j]) {
            FOR(l, 0, k + 1) {
                if (n * n * k < j + l * (i + 1)) break;
                addmod(dp[i + 1][j + l * (i + 1)], dp[i][j], p);
            }
        }
    }
    FOR(x, 1, n + 1) {
        int res = 0;
        FOR(i, 0, n * n * k / 2 + 5) {
            addmod(res, mult(dp[x - 1][i], dp[n - x][i], p), p);
        }
        cout << (mult(k + 1, res, p) + p - 1) % p << "\n";
    }
}

int32_t main(int32_t argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//Arr.find_by_order(k-1):kth smallest
//Arr.order_of_key(X):no. of elements less than x
#define int long long
#define ld long double
#define dob double
#define pb push_back
#define tle ios_base::sync_with_stdio(false);cin.tie(NULL);
const int hell=1e9+7;
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int>>
int inf=1e18;
const int N=1e5+9;
//getline(cin,st);   To Take Entire Sentence In Input;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

int power(int a,int b,int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

int32_t main()
{
	tle
	int t=1;
	// cin>>t;
	//precompute();

	while(t--)
	{
		int a,b;
		cin>>a>>b;

		if(a>b)
		{
			for(int i=1;i<=a;i++)
			cout<<i<<" ";

			int sum=a*(a+1)/2;

			int newsum=b*(b-1)/2;
			int diff=sum-newsum;
			cout<<-1*diff<<" ";

			for(int i=1;i<b;i++)
			cout<<-1*i<<" ";
		}

		if(a<b)
		{
			for(int i=1;i<=b;i++)
			cout<<-1*i<<" ";

			int sum=b*(b+1)/2;

			int newsum=a*(a-1)/2;
			int diff=sum-newsum;
			cout<<diff<<" ";

			for(int i=1;i<a;i++)
			cout<<i<<" ";
		}

		if(a==b)
		{
			for(int i=1;i<=a;i++)
			cout<<i<<" "<<-1*i<<" ";
		}

	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rept(i,n) for(int i=1;i<(int)(n);i++)
using intt = int64_t;
using ldou = long double;
int gcd(int a,int b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
int lcm(int a,int b){return a*b/gcd(a,b);}
intt sum(const long &a,const long &b){return(a+b)*(b-a+1)/2;}
int main() {
cout << fixed << setprecision(20);
int a,b;
cin>>a>>b;
vector<int>aa(a);
vector<int>bb(b);
int x=0,y=0;
rep(i,a){
    aa.at(i)=i+1;
    x+=aa.at(i);
}
rep(i,b){
    bb.at(i)=i+1;
    y+=bb.at(i);
}
if(x>y){
    bb.at(b-1)+=x-y;
}
else {
    aa.at(a-1)+=y-x;
}
rep(i,a){
    cout<<aa.at(i)<<" ";
}
rep(i,b){
    cout<<-bb.at(i)<<" ";
}
}
/*

g++ c.cpp
./a.out

*/


#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 N = 105;
int n;
pair<double,double> a[N];
pii dsu[N];

int find(int x)
{
    if(dsu[x].F == x) return x;
    return dsu[x].F = find(dsu[x].F);
}

void merge(int x,int y)
{
    int p = find(x);
    int q = find(y);

    if(p == q) return;

    if(dsu[p].S > dsu[q].S) swap(p,q);

    dsu[q].S+=dsu[p].S;
    dsu[p].F = dsu[q].F;
}

//n is upper
//n+1 is lower

double dis(pair<double,double> x,pair<double,double> y)
{
   return sqrt( ((x.F - y.F)*(x.F - y.F)) + ((x.S - y.S)*(x.S - y.S)) );
}

bool check(double r)
{
    f(i,n+2) dsu[i] = {i,1};

    f(i,n) f(j,n)
        if(dis(a[i],a[j]) <= r + r) merge(i,j);

    f(i,n) if(100 - a[i].S <= r + r) merge(i,n);
    f(i,n) if(a[i].S + 100 <= r + r) merge(i,n+1);

    return find(n) != find(n+1);
}

signed main()
{
    fast;

   cin >> n;

   f(i,n) cin >> a[i].F >> a[i].S;

   vector<double> go;

   f(i,n) f(j,n) go.pb(dis(a[i],a[j])/2);
   f(i,n) go.pb((100 - a[i].S)/2);
   f(i,n) go.pb((a[i].S + 100)/2);

   double res = 0;

   for(auto x : go)
       if(check(x - 1e-9) || check(x + 1e-9)) res = max(res,x);

   cout << fixed << setprecision(4) << res;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int x[110], y[110];

struct UnionFind{
    vector<int> data;
    UnionFind(ll sz){
        data.assign(sz, -1);
    }
    int find(int p){
        if(data[p]<0) return p;
        return data[p]=find(data[p]);
    }
    bool unite(int X, int Y){
        X=find(X), Y=find(Y);
        if(X==Y) return false;
        if(data[X]>data[Y]) swap(X, Y);
        data[X] += data[Y];
        data[Y]=X;
        return true;
    }
    ll size(int k){
        return -data[find(k)];
    }
};

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i) cin >> x[i] >> y[i];
	vector<pair<int, pair<int, int>>> v;
	for(int i=0; i<N; ++i){
		for(int j=i+1; j<N; ++j){
			v.emplace_back(make_pair((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]), make_pair(i, j)));
		}
		v.emplace_back(make_pair((y[i]+100)*(y[i]+100), make_pair(i, N)));
		v.emplace_back(make_pair((y[i]-100)*(y[i]-100), make_pair(i, N+1)));
	}
	sort(v.begin(), v.end());
	UnionFind uf(N+2);
	int now=-1;
	while(uf.find(N)!=uf.find(N+1)){
		++now;
		uf.unite(v[now].second.first, v[now].second.second);
	}
	cout << setprecision(15) << pow(v[now].first, 0.5)*0.5 << endl;
	return 0;
}


#pragma region おまじない
#include "bits/stdc++.h"

#pragma warning(disable : 4996)

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
//#define int long long;
double dist(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll idist(ll x1, ll y1, ll x2, ll y2) {
	return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
#pragma endregion
signed main(){
    ll N;
    cin >> N;
    vector<ll> x(N);
    vector<ll> y(N);
    rep(i,N){
        cin >> x[i] >> y[i];
    }
    ll f = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                if(i != j and j != k and k != i){
                    //cout << i << j << k << endl;
                    if(x[j] == x[k] and x[i] == x[j]){
                        cout << "Yes";
                       return 0;
                    }
                    if(y[j] == y[k] and y[i] == y[j]){
                        cout << "Yes";
                       return 0;
                    }
                    if(x[j]-x[k]==0)break;
                    if(y[j]-y[k]==0)break;
                    double a = (double)((x[i]-x[j])) / (double)((x[j]-x[k]));
                    if((double)(y[i]-y[j]) / (double)(y[j]-y[k])==a){
                    //cout << a << " " << i << j << k << endl;
                       cout << "Yes";
                       return 0;
                    }
                }
            }
        }
    }
    cout << "No";
}

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

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

	vector<int[2]> vec(N);

	for (int i = 0; i < N; ++i) {
		cin >> vec.at(i)[0] >> vec.at(i)[1];
	}

	bool isAns = false;

	for (int i = 0; i < N - 2; ++i) {
		for (int j = 1; j < N - 1; ++j) {
			if (i == j) {
				continue;
			}
			for (int k = 2; k < N; ++k) {
				if (i == k || j == k) {
					continue;
				}
				int dx1 = vec.at(i)[0] - vec.at(j)[0];
				int dy1 = vec.at(i)[1] - vec.at(j)[1];

				int dx2 = vec.at(i)[0] - vec.at(k)[0];
				int dy2 = vec.at(i)[1] - vec.at(k)[1];

				if (dx1 * dy2 == dy1 * dx2) {
					isAns = true;
					break;
				}
			}

			if (isAns) {
				break;
			}
		}

		if (isAns) {
			break;
		}
	}

	if (isAns) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
 }


#include <bits/stdc++.h>

#define rep(i,n) for(LL i=0;i<n;++i)
#define repn(i,n) for(LL i=1;i<=n;++i)
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL qpow(LL x,LL a)
{
	LL res=x,ret=1;
	while(a>0)
	{
		if((a&1LL)==1LL) ret=ret*res%MOD;
		a>>=1LL;
		res=res*res%MOD;
	}
	return ret;
}

LL n,m,t,a[110];
vector <LL> g[110];
vector <vector <LL> > pw[40],res,tmpp,mulv;
vector <LL> tmp;

vector <vector <LL> > mul(vector <vector <LL> > a,vector <vector <LL> > b)
{
	vector <vector <LL> > ret(a.size(),vector <LL>(b[0].size()));
	rep(i,a.size()) rep(j,b[0].size()) rep(k,b.size()) ret[i][j]=(ret[i][j]+a[i][k]*b[k][j]%MOD)%MOD;
	return ret;
}

void getpow()
{
	repn(i,30) pw[i]=mul(pw[i-1],pw[i-1]);
}

int main()
{
  cin>>n>>m>>t;
  repn(i,n) scanf("%lld",&a[i]);
  LL x,y;
  rep(i,m)
  {
    scanf("%lld%lld",&x,&y);
    g[x].pb(y);g[y].pb(x);
  }
  if(t==0)
  {
    repn(i,n) cout<<a[i]<<endl;
    return 0;
  }
  pw[0].clear();
  LL add=1*qpow(m*2,MOD-2);
  repn(i,n)
  {
    tmp.clear();
    repn(j,n) tmp.pb(0);
    tmp[i-1]=(m-g[i].size())*qpow(m,MOD-2)%MOD;
    rep(j,g[i].size())
    {
      tmp[g[i][j]-1]=(tmp[g[i][j]-1]+add)%MOD;
      tmp[i-1]=(tmp[i-1]+add)%MOD;
    }
    pw[0].pb(tmp);
  }
  getpow();
  bool have=false;
  for(LL i=30;i>=0;--i)
  {
    if(t<(1LL<<i)) continue;
    t-=(1LL<<i);
    if(!have) mulv=pw[i];
    else mulv=mul(mulv,pw[i]);
    have=true;
  }
  repn(i,n)
  {
    tmp.clear();
    tmp.pb(a[i]);
    tmpp.pb(tmp);
  }
  res=mul(mulv,tmpp);
  rep(i,n) cout<<res[i][0]<<endl;
	return 0;
}

#include <functional>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

template <typename T>
struct Matrix
{
    using F = function<T(T, T)>;

    int n;
    int m;

    vector<vector<T>> a;

    const F add;
    const F mul;

    const T e0;
    const T e1;

    Matrix(
        int n,
        int m,
        const F add = [](T a, T b){return (a + b) % MOD;},
        const F mul = [](T a, T b){return a * b % MOD;},
        const T e0 = 0,
        const T e1 = 1
    ) : n(n), m(m), add(add), mul(mul), e0(e0), e1(e1){
        a.resize(n);
        for(int i = 0; i < n; i++) a[i].resize(m);
    }

    Matrix(
        int n,
        const F add = [](T a, T b){return (a + b) % MOD;},
        const F mul = [](T a, T b){return a * b % MOD;},
        const T e0 = 0,
        const T e1 = 1
    ) : n(n), m(n), add(add), mul(mul), e0(e0), e1(e1){
        a.resize(n);
        for(int i = 0; i < n; i++) a[i].resize(m);
    }

    static Matrix I(
        int n,
        const F add = [](T a, T b){return (a + b) % MOD;},
        const F mul = [](T a, T b){return a * b % MOD;},
        const T e0 = 0,
        const T e1 = 1
    ){
        Matrix res(n, add, mul, e0, e1);
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++) res.a[i][j] = e0;
        }
        for(int i = 0; i < n; i++) res.a[i][i] = e1;
        return res;
    }

    Matrix &operator+=(const Matrix &b){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++) a[i][j] = add(a[i][j], b.a[i][j]);
        }
        return *this;
    }

    Matrix &operator*=(const Matrix &b){
        vector<vector<T>> c(n, vector<T>(b.m));
        for(int i = 0; i < n; i++){
            for(int j = 0; j < b.m; j++){
                c[i][j] = e0;
                for(int k = 0; k < m; k++){
                    c[i][j] = add(c[i][j], mul(a[i][k], b.a[k][j]));
                }
            }
        }
        a.swap(c);
        return *this;
    }

    Matrix &operator^=(int k){
        Matrix b = Matrix::I(n, add, mul, e0, e1);
        while(k){
            if(k % 2) b *= *this;
            *this *= *this;
            k /= 2;
        }
        a.swap(b.a);
        return *this;
    }

    Matrix operator+(const Matrix &a){
        return (Matrix(*this) += a);
    }

    Matrix operator*(const Matrix &a){
        return (Matrix(*this) *= a);
    }

    Matrix operator^(const int k){
        return (Matrix(*this) ^= k);
    }
};

ll modpow(ll x, ll n){
    ll res = 1, r = x;
    while(n){
        if(n & 1) res = res * r % MOD;
        r = r * r % MOD;
        n >>= 1;
    }
    return res;
}

int main()
{
    int n, m;
    ll k;
    cin >> n >> m >> k;
    ll a[102];
    for(int i = 0; i < n; i++) cin >> a[i];
    Matrix<ll> A(n);
    for(int i = 0; i < n; i++) A.a[i][i] = 1;
    ll r = modpow(m * 2, MOD - 2);
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        A.a[x][x] = (A.a[x][x] + MOD - r) % MOD;
        A.a[y][y] = (A.a[y][y] + MOD - r) % MOD;
        A.a[x][y] = (A.a[x][y] + r) % MOD;
        A.a[y][x] = (A.a[y][x] + r) % MOD;
    }
    A ^= k;
    for(int i = 0; i < n; i++){
        ll s = 0;
        for(int j = 0; j < n; j++) s = (s + A.a[i][j] * a[j]) % MOD;
        cout << s << endl;
    }
    cout << endl;
}


#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
void eras(map<int,int> &m,int x)
{
    m[x]--;
    if (!m[x])
        m.erase(x);
}
const int N=(int)3e5+100;
const int M=(int)2e6+100;
const ll inf=(ll)1e18+100;
#define filename ""

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int x;
    cin>>x;
    int i,j;
    ll ans=0;
    fr(i,1,x+1)
    {
        int y=x/i;
        for(j=1;j<=y;j++)
        {
            ans+=y/j;
        }
    }
    cout<<ans;
}

#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <list>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
void ex_gcd(ll a,ll b, ll& d,ll& x,ll& y){
  if(!b) {d=a;x=1;y=0;}
  else   {	ex_gcd(b,a%b,d,y,x);	y-=a/b*x;}
}
ll inv(ll a,ll n)  {
  ll d,x,y;	ex_gcd(a,n,d,x,y);
  return d==1?(x%n+n)%(n/d):-1;
}
ll gcd(ll x, ll y){
  if(y==0)return x;
  return gcd(y, x%y);
}
const int maxn = 105;
const int mod = 998244353;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  ll ret = 0;
  for(int i=1;i<=n;i++)
  for(int j=1;j<=n&&j*i<=n;j++){
    int tt = n/(i*j);
    ret+=tt;
  }
  cout<<ret<<endl;
  return 0;
}