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

//using namespace __gnu_pbds;
using namespace std;

#define sz(x)                 (int)(x).size()
#define all(x)                (x).begin(), (x).end()
#define tr(x, it)             for(auto (it) = (x).begin();it != (x).end();it++)
#define fo(i, k, n)           for(int i = (k);i < (n);i++)
#define Fo(i, k, n)           for(int i = (k);i >= (n);i--)
#define el                    "\n"
#define ff                    first
#define ss                    second
#define ll                    long long
#define pb                    push_back
#define mp                    make_pair
#define pii                   pair<int, int>
#define vi                    vector<int>
#define mii                   map<int, int>
//#define pqb                   priority_queue<int>
//#define pqs                   priority_queue<int, vi, greater<int>>
//#define pc(x)                 putchar(x);
//#define setbits(x)            __builtin_popcountll(x)
//#define zrobits(x)            __builtin_ctzll(x)
#define mod                   1000000007
#define inf                   1e18
#define deb(x)                cout<<#x<< " = "<< x<<"\n";
//#define ps(x, y)              fixed<<setprecision(y)<<x
//#define mk(arr, n, type)      type *arr = new type[n];
//#define w(x)                  int x; cin>>x; while(x--)

void solve(){
	int n;
	cin>>n;
	double ar[n][2];
	fo(i, 0, n){
		cin>>ar[i][0]>>ar[i][1];
	}
	ll ans = 0;
	fo(i, 0, n){
		fo(j, i+1, n){
			double k = (ar[j][1] - ar[i][1])/(ar[j][0] - ar[i][0]);
			if(k <= 1 && k >= -1){
				ans++;
			}
		}
	}
	cout<<ans;
}

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

#include <bits/stdc++.h>

//#include <atcoder/modint>

#define inc(i, n) for (int i = 0; i < (n); i++)
#define incs(i, s, n) for (int i = (s); i < (n); i++)

#define yes printf("Yes\n")
#define no printf("No\n")

using namespace std;
//using mint = atcoder::modint998244353;
using pii = pair<int, int>;
using ll = long long;

const int ARR_SIZE = 2e5+5;
const double epsilon = 1e-8;

char arr[ARR_SIZE];

int main(int argc, char const *argv[])
{
    scanf("%s", arr);

    int cnts[10];
    memset(cnts, 0, sizeof cnts);
    int arrLen = strlen(arr);

    if (arrLen == 1) {
        if(arr[0] == '8') {
            yes;
            return 0;
        }
        no;
        return 0;
    }

    if (arrLen == 2) {
        char narr[3] = {0};
        narr[0]=arr[1], narr[1]=arr[0];

        if (stoi(arr)%8==0 || stoi(narr)%8==0) {
            yes;
            return 0;
        }

        no;
        return 0;
    }

    inc(i, arrLen) {
        cnts[arr[i]-'0']++;
    }

    int ncnts[10];
    for (int i = 104; i < 1000; i += 8) {
        int num = i;
        memcpy(ncnts, cnts, sizeof cnts);

        bool flag = true;
        while(num > 0) {
            if(--ncnts[num%10] < 0) {
                flag = false;
                break;
            }
            num/=10;
        }
        if (flag) {
            yes;
            return 0;
        }
    }

    for (int i = 104; i < 1000; i += 8) {
        int num = i;
        memcpy(ncnts, cnts, sizeof cnts);

        bool flag = true;
        while(num > 0) {
            if(--ncnts[num%10] < 0) {
                flag = false;
                break;
            }
            num/=10;
        }
        if (flag) {
            yes;
            return 0;
        }
    }

    no;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rrep(i,a,b) for(ll i=a;i>=b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
#define all(x)  x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll INF = 1e18+10;
const ll mod = 1e9+9;
const ll MAXN = 2e5+10;

ll poww(ll a, ll b) {
    if(b<0) return 0LL;
    ll ans = 1;
    while (b) {
        if (b & 1)ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}
ll binpow(ll a, ll b, ll m)
{
    if (b < 0) return 0LL;
    if (a <= 0)return 0LL;
    a %= m;

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

void solve() {
    ll a,b,c; cin>>a>>b>>c;
    ll x = a%10,og=a%10;
    set<ll> st; vector<ll> v;
    st.insert(x); v.pb(x); x*=x; x%=10;
    while(st.find(x)==st.end()) {
        st.insert(x); v.pb(x); x*=og; x%=10;
    }
    ll sz = st.size();
    ll r = binpow(b,c,sz); r = (r-1+sz)%sz;
    cout<<v[r];
}

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

    //ll no_of_test_cases; cin>>no_of_test_cases;
    ll no_of_test_cases = 1;
    //cout<<setprecision(10);

    for(ll i=1; i<=no_of_test_cases; i++) {
        solve();
    }
    return 0;
}

#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define ALL(a) (a).begin(),(a).end()
#define ALL2(a, n) (a),(a)+(n)
template<class T,class C> T max(T a,C b){ return std::max(a, (T)b); }
template<class T,class C> T min(T a,C b){ return std::min(a, (T)b); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){

}
ll n;
map<ll,ll> que[LIMIT1];
ll all_add=0;
vector<ll> edge[LIMIT1];
ll res[LIMIT1]={0};
vector<bool> visited(LIMIT1,false);
void dfs(ll i,ll parent,ll addd){
  visited[i] = true;

  res[i] += addd;
  for(auto p : edge[i]){
    if(!visited[p]){
      if(que[p].count(i)){
        addd += que[p][i];
      }
      if(que[i].count(p)){
        addd -= que[i][p];
        all_add += que[i][p];
      }
      dfs(p,i,addd);
      if(que[p].count(i)){
        addd -= que[p][i];
      }
      if(que[i].count(p)){
        addd += que[i][p];
      }
    }
  }
}
int main(void){
  initialize();
  ll m,i,j,k,result=0,q,t,e,x;
  int a[LIMIT2]={0},b[LIMIT1]={};
  string s;
  queue<ll> path;

  cin >> n;
  rep(i,n-1){
    cin >> a[i] >> b[i];
    a[i]--;b[i]--;
    edge[a[i]].push_back(b[i]);
    edge[b[i]].push_back(a[i]);
  }
  cin >> q;
  rep(i,q){
    cin >> t >> e >> x;
    e--;
    if(t==1){
      que[a[e]][b[e]] += x;
    }else{
      que[b[e]][a[e]] += x;
    }
  }

  dfs(0,-1,0);

  rep(i,n){
    res[i] += all_add;
    cout << res[i] << '\n';
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ull unsigned long long
void testcase(){
    ll n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        bool st=true;
        int j=i;
        while(j){
            if(j%10==7){
                st=false;
                break;
            }
            j/=10;
        }
        j=i;
        while(j){
            if(j%8==7){
                st=false;
                break;
            }
            j/=8;
        }
        if(st){
            ans++;
        }
    }
    cout<<ans;
}
int main() {
    ll t=1;
    //cin>>t;
    while(t--){
        testcase();
        //cout<<'\n';
    }
}

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

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

  int n;
  cin >> n;

  cout << (1<<n) - 1 << '\n';
  vector<string> ans = {"AB"};

  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < (1<<i) - 1; ++j) {
      string tmp = ans[j];
      for (int k = 0; k < (int)tmp.size(); ++k) {
        tmp[k] = (tmp[k] == 'A' ? 'B' : 'A');
      }
      ans.push_back(ans[j] + tmp);
      ans[j] += ans[j];
    }
    ans.push_back(string ((1<<i), 'A') + string ((1<<i), 'B'));
  }

  for (auto i : ans) cout << i << '\n';
}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
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 (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll A, B;
    cin >> A >> B;

    ll res = 1;
    for(ll g=1;g<=B;g++){
        ll cnt = 0;
        for(ll x=g;x<=B;x+=g){
            if(A <= x and x <= B){
                cnt++;
            }
        }
        if(cnt >= 2){
            res = g;
        }
    }

    cout << res << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll findMaxGCD(vector<ll> &arr) {
    ll n=arr.size();

    ll high = 0;
    for (ll i = 0; i < n; i++)
        high = max(high, arr[i]);

    ll divisors[high + 1] = { 0 };

    for (ll i = 0; i < n; i++) {

        for (ll j = 1; j <= sqrt(arr[i]); j++) {

            if (arr[i] % j == 0) {

                divisors[j]++;

                if (j != arr[i] / j)
                    divisors[arr[i] / j]++;
            }
        }
    }

    for (ll i = high; i >= 1; i--)

        if (divisors[i] > 1)
            return i;
}

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

    ll l;
    cin >> l;
    ll r;
    cin >> r;
    vector<ll> arr;
    for(ll i=l; i<=r; i++) {
        arr.push_back(i);
    }
    cout << findMaxGCD(arr) << '\n';
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define all(a) a.begin(), a.end()
#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
ll bp(ll a,ll b,int Mod=mod)
{
    ll res=1;
    a%=Mod;
    while(b>0)
    {
        if(b&1)
        res=(a*res)%Mod;
        a=(a*a)%Mod;
        b/=2;
    }
    return res;
}
main()
{
   IO
   int n;
   cin>>n;
   int a[n];
   int g=1e18;
   for(int x=0;x<n;x++)
     {cin>>a[x];
     g=min(g,a[x]);}
   set<int> as;
   as.insert(1);
   for(int x=0;x<n;x++)
    {
        int h=sqrt(a[x]);
        for(int y=2;y<=h;y++)
        {
            if(a[x]%y==0)
            {
                as.insert(y);
                if(a[x]/y!=y)
                as.insert(a[x]/y);
            }
        }
    }
   int f=0;
   for(auto i : as)
   {   if(i>g)break;
      int w=0;
   	   for(int x=0;x<n;x++)
   	   {
   	   	  if(a[x]%i==0)
   	   	    {w=__gcd(w,a[x]);
   	   	    if(w<i)break;}
   	   }
   	   if(w==i)++f;
   }
   if(!as.count(g))++f;
   cout<<f;
}

#include <bits/stdc++.h>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,n) for(int i = n-1; i >= 0; i--)
#define ll long long
#define P pair<int, int>

#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);

unsigned GetDigit(unsigned num) { return log10(num)+1; }
void chmin(int& a, int b){ if (a > b) a = b; }
void chmax(int& a, int b){ if (a < b) a = b; }
void chmin(double& a, double b){ if (a > b) a = b; }
void chmax(double& a, double b){ if (a < b) a = b; }

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

	vector<string> s(n);
	vector<int> t(n);
	rep(i, n) cin >> s[i] >> t[i];

	map<int, string> m;
	rep(i, n) m.insert(make_pair(t[i], s[i]));

	sort(t.begin(), t.end(), greater<int>());

	cout << m.at(t[1]) << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...)
#endif
#define endl "\n"
#define pb push_back
#define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define all(c) c.begin(),c.end()
#define read(v) for(auto &it:v) cin>>it;
const int inf = 1e18;
const int N   = 2e5 + 5;
const int mod = 1000000007;

void testCase() {
    int a,b,c;
    cin>>a>>b>>c;

    if(a*a+b*b < c*c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}

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

//#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#define swap(x,y) (y -= (x = ((y += x) - x)))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1, i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
using ll = long long;
using namespace std;
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; }
int digit(ll n, int a) { int s = 0;	for (int i = 0; n > 0; i++) { s++;	n /= a; }	return s; }
int imax(int a[], int n) { int s = a[0];	rep(i, n) { s = max(s, a[i]); }	return s; }
int imin(int a[], int n) { int s = a[0];	rep(i, n) { s = min(s, a[i]); }	return s; }
int cmax(string a, int n) { int s = 0;	rep(i, n) { s = max(s, (int)a[i] - '0'); }	return s; }
int cmin(string a, int n) { int s = 9;	rep(i, n) { s = min(s, (int)a[i] - '0'); }	return s; }

//quick sort(int)
int ascfunc(const void* n1, const void* n2) {
	if (*(int*)n1 > *(int*)n2) {
		return 1;
	}
	if (*(int*)n1 < *(int*)n2) {
		return -1;
	}
	if (*(int*)n1 == *(int*)n2) {
		return 0;
	}
}

int main(void) {
	ll n, s, d;	cin >> n >> s >> d;
	ll* x = new ll[n];
	ll* y = new ll[n];
	bool can = false;
	rep(i, n) {
		cin >> x[i];
		cin >> y[i];
		if (x[i]<s && y[i]>d) {
			can = true;
		}
	}
	if (can) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	cout << endl;
	delete[] x;	delete[] y;
	return 0;
}


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

using namespace std;
typedef long long int64;

struct Edge {
    int to;
    int cost;
};

using Graph = vector<vector<Edge>>;

int ans[200010]={0};

int N=0;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v,int prev_label) {
    //printf("%d is seen prev_label=%d\n",v,prev_label);
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v.to]) continue; // next_v が探索済だったらスルー

        int label=next_v.cost;
        if(prev_label!=label)ans[next_v.to]=label;
        else
        {
            if(label+1<=N)label++;
            else label--;
            ans[next_v.to]=label;
        }
        dfs(G, next_v.to,label); // 再帰的に探索
        //break;
    }
    if(ans[v]==0)
    {
        //printf("%d is ume\n",v);
        if(prev_label+1<=N)ans[v]=prev_label+1;
        else ans[v]=prev_label-1;
    }
}

int main() {
    // 頂点数と辺数、s と t
    int M;
    cin >> N >> M;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b,c;
        cin >> a >> b >> c;
        Edge e,f;
        e.to = b-1;
        e.cost = c;
        f.to = a-1;
        f.cost = c;
        G[a-1].push_back(e);
        G[b-1].push_back(f);
    }

    // 頂点 s をスタートとした探索
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    ans[0]=1;
    dfs(G, 0,1);

    for(int i=0;i<N;i++)
    {
        if(ans[i]==0)printf("%d\n",N);
        else printf("%d\n",ans[i]);
    }
}

// *********************************************************************************
// *                        MURTAZA MUSTAFA KHUMUSI                                *
// *                        NIT-DGP,CSE - 2019-2023                                *
// *********************************************************************************

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loop1(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloop1(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define vi vector<int>
#define si set<int>
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
const int maxm = 100001;

// ll m = 1e9+7;
ll m = 998244353;
vector<vector<pi>> adj;
vi h, sz, in,vis,ans;
vector<ll> fact;

//modular arithmentic

ll add(ll a, ll b, ll mod = m)
{
    return ((a % mod) + (b % mod)) % mod;
}
ll mul(ll a, ll b, ll mod = m)
{
    return ((a % mod) * (b % mod)) % mod;
}
ll sub(ll a, ll b, ll mod = m)
{
    return ((a % mod) - (b % mod) + mod) % mod;
}

ll modmul(ll a, ll b, ll mod = m)
{
    ll ans = 0;
    a = a % mod;
    while (b)
    {
        if (b & 1)
            ans = add(ans, a, mod);
        a = mul(a, 2, mod);
        b >>= 1;
    }
    return ans;
}

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

ll fe(ll base, ll exp, ll mod = m)
{
    ll ans = 1;
    while (exp)
    {
        if (exp & 1)
            ans = mul(ans, base, mod);
        base = mul(base, base, mod);
        exp >>= 1;
    }
    return ans;
}

ll modin(ll a, ll mod = m)
{
    return fe(a, mod - 2, mod);
}

ll nCr(ll a, ll b, ll mod = m)
{
    if (a < b)
        return 0;
    return mul(fact[a], mul(modin(fact[b], mod), modin(fact[a - b], mod)));
}

//graph theory
void dfs(int cur)
{
    vis[cur] = 1;
    for (const auto &v : adj[cur])
    {
        if (vis[v.ff])continue;
        if(v.ss==ans[cur]){
            if(v.ss==1)
            ans[v.ff] = 2;
            else
            ans[v.ff] = 1;
        }else{
            ans[v.ff] = v.ss;
        }
        dfs(v.ff);
    }
}

void buildGraph(int n, int m)
{
    adj = vector<vector<pi> >(n + 1);
    ans = vi(n+1);
    vis = vi(n+1);

    loop(i, 0, m)
    {
        int a, b, c;
        cin >> a >> b>>c;
        adj[a].pb(MP(b,c));
        adj[b].pb(MP(a,c));
    }
    ans[1] = 1;
    dfs(1);
}
struct cmp
{
    bool operator()(const pi &a, const pi &b)
    {
        return a.ff < b.ff;
    }
};

void solve()
{
    int n,m;cin>>n>>m;
    buildGraph(n, m);
    loop1(i,1,n){
        cout<<ans[i]<<"\n";
    }
    // cout<<"\n";
}
int main()
{
    io;
#ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    int test;
    // cin >> test;?
    test=1;
    while (test--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back
#define INF 1e6
vector<int>ans,a,b;

void dfs(int u, vector<int>&visited, vector<vector<pair<int,int> >>&adj)
{
    visited[u]  =1;
    for(auto p:adj[u])
    {
        int v = p.first;
        int id = p.second;
        if(a[id] == u && b[id]==v)ans[id] = 1;
        if(a[id] == v && b[id]==u)ans[id] = -1;
        if(!visited[v])dfs(v,visited,adj);
    }
}

void solve(int test)
{
   int n,m;
   cin>>n>>m;

   a.resize(m);
   b.resize(m);
   int i,j;
   vector<vector<pair<int,int> >>adj(n);
   for(i=0;i<m;i++){cin>>a[i]>>b[i];a[i]--;b[i]--;}

   vector<int>c(n);
   for(i=0;i<n;i++)cin>>c[i];

   ans.resize(m,0);

   for(i=0;i<m;i++)
   {
       if(c[a[i]] > c[b[i]]){ans[i] = 1;continue;}
       if(c[a[i]] < c[b[i]]){ans[i] = -1;continue;}
       adj[a[i]].pb(mp(b[i],i));
       adj[b[i]].pb(mp(a[i],i));
   }
   vector<int>visited(n,0);

   for(i=0;i<n;i++)
   {
       if(!visited[i])dfs(i,visited,adj);
   }

   for(i=0;i<m;i++)
   {
       if(ans[i] < 0)cout<<"<-"<<endl;
       else
        cout<<"->"<<endl;
   }

}

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

  for(int x=1;x<=t;x++)
  {
      solve(x);
  }
  return 0;
}

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

//#include <atcoder/all>
//using namespace atcoder;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, y) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), y))
#define Upper_bound(v, y) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), y))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

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

/* Macros reg. ends here */

struct UnionFind {
  vector<ll> par, sizes;
  ll cnt;
  UnionFind(ll N) : par(N), sizes(N, 1), cnt(N) {
    for (ll i = 0; i < N; i++) par[i] = i;
  }

  ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

  bool same(ll x, ll y) { return find(x) == find(y); }

  ll size(ll x) { return sizes[find(x)]; }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
    cnt--;
  }

  ll count() const { return cnt; }
};

const ll INF = 1LL << 50;

using vvT = vector<vT>;
vll ans;
vvT to;
vector<bool> seen;

void dfs(ll u){
  if(seen[u]) return;
  seen[u] = true;
  for(auto [id, v, dir] : to[u]){
    if(ans[id] != -1) continue;
    ans[id] = dir;
    dfs(v);
  }
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

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

  ans.assign(m, -1);
  to.resize(n);
  seen.resize(n);
  rep(i, m){
    ll a, b;
    cin >> a >> b;
    a--, b--;
    to[a].emplace_back(i, b, 0);
    to[b].emplace_back(i, a, 1);
  }

  vll cs(n);
  rep(i, n) cin >> cs[i];

  rep(u, n){
    for(auto [id, v, dir] : to[u]){
      if(cs[u] > cs[v]) {
        assert(ans[id] == -1);
        ans[id] = dir;
      }
    }
  }

  rep(u, n) dfs(u);

  rep(i, m) cout << ((ans[i] == 0) ? "->" : "<-") << endl;

  return 0;
}


#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on

class iunionfind {
   public:
    // 連続するuintにのみ使える。vectorであるため定数時間がとれる。
    // 基本的にこれだけあればよい。任意の構造体を扱うときは、IDと構造体のマッピングをとるvectorを別途用意する。
    // libs-test.cppの iuf_map あたりを検索。
    vector<ull> partition;
    vector<ull> rank;

    iunionfind(ull n) {
        partition.resize(n);
        rank.resize(n);
        for (ull x = 0; x < n; x++) {
            partition[x] = x;
            rank[x] = 0;
        }
    }
    ull find(ull x) {
        if (partition[x] == x) {
            return x;
        } else {
            partition[x] = find(partition[x]);
            return partition[x];
        }
    }
    void unite(ull x, ull y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return;
        }
        if (rank[x] < rank[y]) {
            partition[x] = y;
        } else {
            partition[y] = x;
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
    }
    bool same(ull x, ull y) {
        return find(x) == find(y);
    }
};

const ll MODULO = 998244353L;
int main() {
    ll N, K;
    cin >> N >> K;
    vector<vector<ll>> a(N, vector<ll>(N, 0));
    // vector<ll> rtotal(N, 0);
    // vector<ll> ctotal(N, 0);
    for (ll r = 0; r < N; r++) {
        for (ll c = 0; c < N; c++) {
            cin >> a[r][c];
            // rtotal[r] += a[r][c];
            // ctotal[c] += a[r][c];
        }
    }
    auto rswap = iunionfind(N);
    for (ll r = 0; r < N; r++) {
        for (ll rr = r + 1; rr < N; rr++) {
            bool swapok = true;
            for (ll c = 0; c < N; c++) {
                if (a[r][c] + a[rr][c] > K) {
                    swapok = false;
                }
            }
            if (swapok) {
                rswap.unite(r, rr);
            }
        }
    }
    auto cswap = iunionfind(N);
    for (ll c = 0; c < N; c++) {
        for (ll cc = c + 1; cc < N; cc++) {
            bool swapok = true;
            for (ll r = 0; r < N; r++) {
                if (a[r][c] + a[r][cc] > K) {
                    swapok = false;
                }
            }
            if (swapok) {
                cswap.unite(c, cc);
            }
        }
    }
    vector<ll> facttbl(N + 1, 1);
    for (ll i = 2; i <= N; i++) {
        facttbl[i] = (facttbl[i - 1] * i) % MODULO;
    }

    vector<ll> rcluster(N, 0);
    for (ll r = 0; r < N; r++) {
        rcluster[rswap.find(r)]++;
    }
    ll rnum = 1;
    for (ll r = 0; r < N; r++) {
        ll clsize = rcluster[r];
        if (clsize >= 2) {
            rnum = (rnum * facttbl[clsize]) % MODULO;
        }
    }

    vector<ll> ccluster(N, 0);
    for (ll c = 0; c < N; c++) {
        ccluster[cswap.find(c)]++;
    }
    ll cnum = 1;
    for (ll c = 0; c < N; c++) {
        ll clsize = ccluster[c];
        if (clsize >= 2) {
            cnum = (cnum * facttbl[clsize]) % MODULO;
        }
    }
    //print(cnum, rnum);
    ll ans = (rnum * cnum) % MODULO;
    //ll ans = fact(rswap + 1) * fact(cswap + 1) % MODULO;
    print(ans);
}

#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define MOD 998244353

int dp[3001][3001];
int main() {
    int N,K;
    cin >> N >> K;

    int i,j;
    for (i = 0; i <= N; i++) {
        for (j = 0; j <= N; j++) {
            if ((i == 0) || (j == 0)) dp[i][j] = 1;
            else {
                if (j > 1) dp[i][j] = dp[i][j-1];
                if ((i >= j) && (2*j <= N)) dp[i][j] += dp[i-j][2*j];
                if (dp[i][j] >= MOD) dp[i][j] -= MOD;
            }
        }
    }
    cout << dp[N-K][K] << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,x,n) for(int i=x;i<(int)n;++i)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define out(a) cout<<a<<endl;
#define vout(v) rep(i,0,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vvout(vv) rep(j,0,vv.size()){vout(vv[j])}
#define mout(m) for(auto&e:m)cout<<e.first<<": "<<e.second<<endl;
#define _CHK_ 1
#define chk(a) if constexpr (_CHK_){cout<<#a<<": ";out(a)}
#define vchk(v) if constexpr (_CHK_){cout<<#v<<": ";vout(v)}
#define vvchk(vv) if constexpr (_CHK_){cout<<#vv<<": "<<endl;vvout(vv)}
#define mchk(m) if constexpr (_CHK_){cout<<#m<<": "<<endl;mout(m)}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    std::vector<long long> W(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&W[i]);
    }
    sort(H.begin(), H.end());
    sort(W.begin(), W.end());
    // vchk(H)
    // vchk(W)

    vector<long long> diff1((N+1)/2);
    vector<long long> diff2((N+1)/2);
    for (long long i = 0; i+1 < (N+1)/2; i++) {
        diff1[i]=H[2*i+1]-H[2*i];
        diff2[i]=H[2*i+2]-H[2*i+1];
    }
    // vchk(diff1)
    // vchk(diff2)

    vector<long long> acc1((N+1)/2);
    vector<long long> acc2((N+1)/2);
    acc1[0]=diff1[0];
    acc2[0]=diff2[0];
    for (long long i = 1; i < (N+1)/2; i++) {
        acc1[i]=acc1[i-1]+diff1[i];
        acc2[i]=acc2[i-1]+diff2[i];
    }
    // vchk(acc1)
    // vchk(acc2)

    long long ret=LLONG_MAX;
    for (long long i = 0; i < M; i++) {
        long long sum=0;
        auto itr = upper_bound(H.begin(), H.end(), W[i]);
        long long pos = itr - H.begin();
        // chk(W[i])
        // chk(pos)
        if(pos%2){
            sum+=W[i]-H[pos-1];
            if(pos/2-1>=0) {
                sum+=acc1[pos/2-1];
            }
            sum+=acc2[(N+1)/2-1];
            if(pos/2-1>=0) {
                sum-=acc2[pos/2-1];
            }
        }else{
            sum+=H[pos]-W[i];
            if(pos/2-1>=0) {
                sum+=acc1[pos/2-1];
            }
            if(pos/2<N/2){
                sum+=acc2[N/2-1];
                if(pos/2-1>=0) {
                    sum-=acc2[pos/2-1];
                }
            }
        }
        ret=min(ret, sum);
    }
    out(ret)

    return 0;
}

#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back
#define PS string qqwwee;cin>>qqwwee;

const int maxn = 200005;
ll a[maxn], b[maxn], pre[maxn], suf[maxn];
int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    ii cin >> a[i];
    sort(a+1, a+1+n);
    for(int i=2;i<=n;++i) pre[i] = pre[i-2] + abs(a[i] - a[i-1]);
    for(int i=n-1;i>=1;--i) suf[i] = suf[i+2] + abs(a[i] - a[i+1]);
    for(int i=1;i<=m;++i) cin >> b[i];
    sort(b+1, b+1+m);
    auto go = [&](int x) -> ll {
        int pos = lower_bound(b+1,b+1+m,x)-b;
        ll ret = 1e18;
        for(int i=max(1,pos-1);i<=min(m,pos+1);++i) ret = min(ret, abs(b[i] - x));
        return ret;
    };
    ll ans = 1e18;
    for(int i=1;i<=n;++i) {
        if(i % 2 == 0) ans = min(ans, pre[i-2] + suf[i+2] + abs(a[i-1] - a[i+1]) + go(a[i]));
        else ans = min(ans, pre[i-1] + suf[i+1] + go(a[i]));
    }
    cout << ans << endl;
}


#include<iostream>

using namespace std;

int main()
{
  int m,h;
  cin>>m>>h;
  if(h%m==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int N = 105;
char s[N];
char dp[N][N];

int getWin(char a, char b)
{
    if (a == b)
        return a;
    if (a == 'R')
    {
        if (b == 'S')
            return a;
        return b;
    }
    if (a == 'P')
    {
        if (b == 'R')
            return a;
        return b;
    }
    if (a == 'S')
    {
        if (b == 'P')
            return a;
        return b;
    }
}

int main(int,  char **)
{
#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n, k;
    scanf("%d%d", &n, &k);
    scanf("%s", s);

    for (int sh = 0; sh < n; sh++)
        dp[0][sh] = s[sh];

    int deg = 1;
    for (int i = 0; i < k; i++)
    {
        for (int sh = 0; sh < n; sh++)
        {
            dp[i + 1][sh] = getWin(dp[i][sh], dp[i][(sh + deg) % n]);
        }
        deg = (deg * 2) % n;
    }
    printf("%c\n", dp[k][0]);

	return 0;
}

//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
//#include<ctime>
//#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

//ここに適切な判断条件を書く
bool isOK(ll index,ll n) {
  if(((long double)(index+1) <= 2.0*(long double)(n+1)/(long double)(index))
   and (index*(index+1))/2 <= n+1) return true;
  return false;
}

//臨機応変に引数を書き換える
int binary_search(ll n) {
    ll ok = 0;
    ll ng = min(n,ll(1000000002));

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

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

int main(){
  ll n,k; string s; cin >> n >> k >> s;

  if(n % 2 == 1) s += s;

  ll now = n;

  //cout << s << endl;

  ll cnt = 0;

  queue<char> q;

  for(char c : s){
    q.push(c);
  }

  while(cnt < k){
    if(q.size() % 2 == 1){
      queue<char> pq;
      rep(i,q.size()){

        pq.push(q.front());
        q.push(q.front());
        q.pop();
      }
      while(!pq.empty()){
        q.push(pq.front());
        pq.pop();
      }
    }

    //cout << q.size() << endl;

    queue<char> pq;

    /*rep(i,q.size()){
      pq.push(q.front());
      q.pop();
    }
    while(!pq.empty()){
      cout << pq.front();
      q.push(pq.front());
      pq.pop();
    }
    cout << endl;*/

    now = q.size();

    rep(i,now/2){
      char first = q.front(); q.pop(); char second = q.front(); q.pop();

      if((first == 'P' and second == 'S') or (first == 'S' and second == 'P')){
        q.push('S');
      }
      else if((first == 'R' and second == 'S') or (first == 'S' and second == 'R')){
        q.push('R');
      }
      else if(first == second) q.push(first);
      else q.push('P');
    }

    cnt++;
  }

  cout << q.front() << endl;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 1e5 , inf = 1e9;
int n , m , k , c[17] , dist[17][N] , id[N] , dp[17][1<<17] , vis[N];
vector<int> g[N];
void bfs(int srce){
	memset(vis , 0 , sizeof vis);
	vis[srce] = 1;
	queue<int> q;
	q.push(srce);
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(auto u : g[x]){
			if(vis[u]) continue;
			vis[u] = 1;
			dist[id[srce]][u] = dist[id[srce]][x] + 1;
			q.push(u);
		}
	}
}
int main() {
	scanf("%d%d",&n,&m);
	for (int i = 0,u,v; i < m; ++i){
		scanf("%d%d",&u,&v);
		--u,--v;
		g[u].pb(v);
		g[v].pb(u);
	}
	scanf("%d",&k);
	for (int i = 0; i < k; ++i){
		scanf("%d", &c[i]);
		--c[i];
		id[c[i]] = i;
	}

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

	for (int j = 0; j < k; ++j){
		if(vis[c[j]] == 0) return puts("-1") , 0;
	}

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

	vector<vector<int>> msk(k+1);
	for (int i = 0; i < (1 << k); ++i){
		msk[__builtin_popcount(i)].pb(i);
	}

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

	for (int i = 2; i <= k; ++i){
		for(auto mask : msk[i-1]){

			for (int j = 0; j < k; ++j){
				for (int o = 0; o < k; ++o){
					if(mask >> j & 1) continue;
					if(mask >> o & 1){
						dp[j][mask|(1<<j)] = min(dp[j][mask|(1<<j)] , dp[o][mask] + dist[o][c[j]]);
					}
				}
			}

		}
	}

	int ans = inf;
	for (int i = 0; i < k; ++i){
		ans = min(ans , dp[i][(1 << k) - 1]);
	}
	printf("%d\n", ans);
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

template<typename M, typename N>
istream& operator>>(istream&is, pair<M,N> & p){is >> p.first >> p.second; return is;}
template<typename M>
istream& operator>>(istream&is, vector<M> & v){for(auto &it:v) is >> it; return is; }
template<typename M>
istream& operator>>(istream&is, vector<vector<M>> & v){for(auto &it:v) is >> it; return is; }
template<typename M, typename N>
ostream& operator<<(ostream&os, const pair<M,N> &p){os << p.first << ' ' << p.second << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<M> &v){for(auto it: v)os << it << ' ';cout << '\n';return os;}
template<typename M>
ostream& operator<<(ostream&os, const vector<vector<M>> &v){for(auto it: v)os << it;return os;}

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
#define acc(x) accumulate((x).begin(),(x).end(),0ll)
#define unique(x) sort(all(x)); x.erase(unique(all(x)),x.end());
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef complex<long double> cd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pi=acos(-1);
const ll inf=(ll)1e9+10;
const int mod=1000000007;
//const int mod=998244353;

int n, m, k;
const int N=1e2+10;

vvi g(N);
set<pii> ee;
vi mark(N);
void dfs(int node, int par){
    mark[node]=1;
    for(int child: g[node]){
        if(child!=par){
            if(!mark[child]){
                dfs(child, node);

            }
            if(ee.find({child,node})==ee.end())
                ee.insert({node,child});
        }
    }
};

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vpi e(m);
    for(int i=0; i<m; i++){
        cin >> e[i].fi >> e[i].se;
        e[i].fi--; e[i].se--;
    }
    vi c(n);
    cin >> c;
    vi todo(n);
    for(int i=0; i<m; i++){
        if(c[e[i].fi]==c[e[i].se]){
            todo[e[i].fi]=1;
            todo[e[i].se]=1;
            g[e[i].fi].pb(e[i].se);
            g[e[i].se].pb(e[i].fi);
        }
    }
    for(int i=0; i<n; i++){
        if(todo[i] && !mark[i]){
            dfs(i,i);
        }
    }
    for(int i=0; i<m; i++){
        if(c[e[i].fi]==c[e[i].se]){
            if(ee.find({e[i].fi,e[i].se})!=ee.end()){
//                cout << e[i].fi+1 << ' ' << e[i].se+1 << el;
                cout << "->\n";
            }
            else{
                assert(ee.find({e[i].se,e[i].fi})!=ee.end());
                cout << "<-\n";
            }
        }
        else if(c[e[i].fi]>c[e[i].se]){
            cout << "->\n";
        }
        else{
            cout << "<-\n";
        }
    }

    return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<algorithm>
#include<cstddef>
#include<vector>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = size_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
void solve(){
}
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    u64 n,m;
    cin >> n >> m;
    vec<u64> a(n),b(m);
    rep(i,n)cin >> a[i];
    rep(i,m)cin >> b[i];
    vec<vec<u64>> dp(n + 1,vec<u64> (m + 1,1e18));
    dp[0][0] = 0;
    rep(i,n + 1){
        rep(j,m + 1){
            if(i && j){
                if(a[i - 1] == b[j - 1])dp[i][j] = min(dp[i][j],dp[i - 1][j - 1]);
                else dp[i][j] = min(dp[i][j],dp[i - 1][j - 1] + 1);
            }
            if(i)dp[i][j] = min(dp[i][j],dp[i - 1][j] + 1);
            if(j)dp[i][j] = min(dp[i][j],dp[i][j - 1] + 1);
        }
    }
    cout << dp.back().back() << endl;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

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

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

    // either remove this character from b, or remove it from a

   	vector<vector<int>> dp(n + 1, vector<int>(m + 1, 1 << 30));

   	dp[0][0] = 0;
   	for(int i = 0; i <= n; i++) {
   		for(int j = 0; j <= m; j++) {
   			int here = dp[i][j];
   			if(here == 1 << 30) continue;

   			// so given that we are considering position i, j in both strings
   			// we can either either remove from i => + 1
   			// remove from j => + 1
   			// we dont remove from either, then + whether or not a_i != b_j

   			if(i + 1 <= n)
   				dp[i + 1][j] = min(1 + here, dp[i + 1][j]);
   			if(j + 1 <= m)
   				dp[i][j + 1] = min(1 + here, dp[i][j + 1]);
   			if(i + 1 <= n && j + 1 <= m)
   				dp[i + 1][j + 1] = min((a[i] == b[j] ? 0 : 1) + here, dp[i + 1][j + 1]);
   		}
   	}

   	cout << dp[n][m] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
    ll a, b, w; cin >> a >> b >> w; w*=1000;
    ll ma = -1; ll mi = INF;
    FOR(i,1,1000100) {
        if (a*i<=w && b*i>=w) {
            ma = max(ma,i); mi = min(mi,i);
        }
    }
    if (ma==-1 || mi==INF) cout << "UNSATISFIABLE" << endl;
    else cout << mi << " " << ma << endl;
}

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

int main(void) {
	int a, b, w;
	cin >> a >> b >> w;
	w *= 1000;
	int ca = w / a, cb = (w + b - 1) / b;
	if (cb <= ca) {
		cout << cb << " " << ca << endl;
	} else {
		cout << "UNSATISFIABLE" << endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    int h,w,x,y;
    cin >> h >> w >> x >> y;
    vector<string> s(h);
    for(int i = 0;i < h;i++){
        cin >> s[i];
    }
    x--;
    y--;
    int ans = 1;
    for(int i =y+1;i < w;i++){
        if(s[x][i] == '.'){
            ans ++;
        }else{
            break;
        }
    }
    for(int i = y-1;0 <= i;i--){
        if(s[x][i] == '.'){
            ans ++;
        }else{
            break;
        }
    }
    for(int i = x+1;i < h;i++){
        if(s[i][y] == '.'){
            ans ++;
        }else{
            break;
        }
    }
    for(int i = x-1;0 <= i;i--){
        if(s[i][y] == '.'){
            ans ++;
        }else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
//using namespace atcoder;

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

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

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

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

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

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

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

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

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

// edit

template<typename T>
class graph {
    struct edge {
        int src, to;
        T cost;
    };

public:
    int n;
    vector<vector<edge>> edges;

    graph(int n_) : n(n_), edges(n_) {
    }

    void add_edge(int src, int to, T cost) {
        edges[src].push_back({src, to, cost});
    }
};

template<typename T>
pair<vector<T>, vector<int>> dijkstra(const graph<T> &g, int s, T inf) {
    vector<T> d(g.edges.size(), inf);
    vector<int> p(g.edges.size());

    using Pi = pair<T, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;

    que.emplace(0, s);
    d[s] = 0;
    p[s] = -1;

    while (!que.empty()) {
        T cost;
        int v;
        tie(cost, v) = que.top();
        que.pop();

        if (d[v] < cost) continue;
        for (const auto &e : g.edges[v]) {
            T ncost = cost + e.cost;
            int nv = e.to;
            if (ncost < d[nv]) {
                d[nv] = ncost;
                p[nv] = v;
                que.emplace(ncost, nv);
            }
        }
    }

    return make_pair(d, p);
}

void solve() {
    int N, M;
    cin >> N >> M;
    graph<int> G(N + 1);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        G.add_edge(a, b, 0);
    }

    int ans = 0;
    for (int s = 1; s <= N; ++s) {
        auto tapu = dijkstra(G, s, INF).first;
        int cnt = 0;
        for (int i = 1; i <= N; ++i) {
            if (tapu[i] == 0) {
                cnt++;
            }
        }
        ans += cnt;
    }
    cout << ans << endl;

}

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

    solve();

    return 0;
}


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

struct edge {
    ll to;
    ll cost;
    ll d;
};
using P = pair<ll, ll>;
vector<vector<edge>> G;
vector<ll> d;
void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d.begin(), d.end(), INF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        rep(i, G[v].size()) {
            edge e = G[v][i];

            ll sq = sqrt(e.d);
            if (sq * sq != e.d) sq++;
            sq--;

            ll cost = 0;
            if (d[v] < sq)
                cost = sq - d[v] + e.cost + e.d / (sq + 1);
            else
                cost = e.cost + e.d / (d[v] + 1);

            if (d[e.to] > d[v] + cost) {
                d[e.to] = d[v] + cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    cin >> N >> M;
    G.resize(N);
    d.resize(N);
    rep(i, M) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--;
        G[a].push_back({b, c, d});
        G[b].push_back({a, c, d});
    }

    dijkstra(0);
    ll ans = d[N - 1];

    if (ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;

    return 0;
}

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

int n,m;
vector<int> a,b;
vector<ll> c,d;
vector<vector<int>> links;
vector<ll> earliest;
priority_queue<pair<ll,int>, vector<pair<ll,int>>,greater<pair<ll,int>>> q;

void initialize(){
  cin >> n >> m;
  links.resize(n,vector<int>(0));
  earliest.resize(n,-1);
  a.resize(m);
  b.resize(m);
  c.resize(m);
  d.resize(m);
  for(int i=0; i<m; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    links[a[i]-1].push_back(i);
    links[b[i]-1].push_back(i);
  }
}

/*
template <typename T> void print_vv(vector<vector<T>> &vv){
  for(int i=0;i<vv.size();i++){
    cout << i << " * ";
    for(auto& j:vv[i]) cout << j << ' ';
    cout << endl;
  }
}
template <typename T> void print_v(vector<T> &a){
  cout << "{ ";
  for(auto& i:a) cout << i << ' ';
  cout << '}' << endl;
}*/

ll fastest(ll di,ll start){
  //cout << "fastest " << di << ' ' << start << " : ";
  ll t = max(start,(ll)round(sqrt(di))-2);
  ll i=di/(t+1)+t;
  while(i>di/(t+2)+t+1){
    t ++;
    i = di/(t+1)+t;
  }
  //cout << i << endl;
  return i;
}

int main(){

  initialize();
  /*
  print_vv(links);
  print_v(c);
  print_v(d);
  print_v(earliest);
  */
  q.push( {0, 0} );

  while(q.size()>0){

    auto node = q.top();
    q.pop();
    if(earliest[node.second] != -1) continue;
    earliest[node.second] = node.first;
    //cout << node.second << ' ' << node.first << endl;

    for(auto& i : links[node.second]){
      int tmp = (a[i]-1 == node.second ? b[i]-1 : a[i]-1);
      q.push( {c[i]+fastest(d[i], node.first), tmp} );
    }

    //print_v(earliest);

  }

  cout << earliest[n-1] << endl;
}


#include<iostream>
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  int AB,AC,BC;
  AB = A + B;
  AC = A + C;
  BC = B + C;
  if(AB >= AC && AB >= BC){
    cout << AB;
  }
  else if(AC >= AB && AC > BC){
    cout << AC;
  }
  else{
    cout << BC;
  }
  return 0;
}

///******* In the name of Allah *******///

#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL);
#define nl '\n'

void Ok()
{
    long int a[13],b,c, d, e, f, g, h, t, i, j, k, l, m, n, Mn, Mx;
    long int ans_1, ans_2, ans_3, cnt_1, cnt_2, cnt_3, flag_1, flag_2, flag_3, temp, sum;
    double aa, bb, cc, dd, ee, ff, gg;
    char aaa, bbb, ccc, ddd;
    string spc, in, keyword;

    fastio;

    cin>>a[1]>>a[2]>>a[3];
    sort(a+1,a+3+1);

    sum = a[2] + a[3];
    cout<<sum<<nl;

    return;
}

int main()
{
    Ok();

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

constexpr int mod = 1e9 + 7;

#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

ll solve(modint<mod> N, modint<mod> A, modint<mod> B) {

    if (A.a + B.a > N.a) return 0;
    // ensure A <= B
    if (A.a > B.a) swap(A, B);

    // we think the problem of 1d version.
    modint<mod> p1 = (B + A - 1) * ((N - B + 1 - (A - 1) * 2));
    modint<mod> p2 = (((A - 1) * B + (A - 1) * A) - (A - 1) - A * (A - 1) / 2) * 2;

    //cout << p1 << ", " << p2 << endl;
    modint<mod> A2 = (N - A + 1) * (N - A + 1);
    modint<mod> B2 = (N - B + 1) * (N - B + 1);

    modint<mod> ans_p = p1 + p2;
    return (A2 * B2 - ans_p * ans_p).a;
}

void solve() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        ll N, A, B;
        cin >> N >> A >> B;
        cout << solve(N, A, B) << endl;
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);

    solve();
}

#pragma warning(disable:4996)

#include<iostream>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_map>
#include<numeric>
#include<fstream>
#include<iomanip>
#include<string>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<cstdlib>
#include <assert.h>
#define pb push_back
#define INF 0x3F3F3F3F //int 下较大值
#define inf 0x3F3F3F3F3F3F3F3F  // ll 下较大值
#define moD 1000000003
#define pii pair<int,int>
#define eps 1e-10
#define equals(a,b) (fabs(a-b)<eps)
#define bug puts("bug")
#define re  register
#define fi first
#define se second
typedef  long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll Mod = 998244352;
const int maxn = 2e5 + 5;
const double Inf = 10000.0;
const double PI = acos(-1.0);
using namespace std;

int bitcount(int x) {
    return x == 0 ? 0 : bitcount(x / 2) + (x & 1);
}

int _popcount(int x) {
    int cnt = 0;
    for (int i = 0; i < 32; i++)
        if (x & (1 << i)) cnt++;
    return cnt;
}

ll mul(ll a, ll b, ll m) {
    ll res = 0;
    while (b) {
        if (b & 1) res = (res + a) % m;
        a = (a + a) % m;
        b >>= 1;
    }
    return res % m;
}

ll quickPower(ll a, ll b, ll m) {
    ll base = a;
    ll ans = 1ll;
    while (b) {
        if (b & 1) ans = mul(ans, base, m);
        base = mul(base, base, m);
        b >>= 1;
    }
    return ans;
}

ll ksm(ll a, ll b, ll m) {
    ll base = a % m;
    ll ans = 1ll;
    while (b) {
        if (b & 1) ans *= base, ans %= m;
        base *= base, base %= m;
        b >>= 1;
    }
    return ans;
}

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

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

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

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

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

void Put(ll x) {
    if (x < 0) putchar('-'), x *= -1;
    if (x > 9) Put(x / 10);
    putchar(x % 10 + '0');
}

int main() {
    int T = readint();
    while (T--) {
        ll n = readll();
        ll a = readll();
        ll b = readll();
        if (a + b > n) {
            puts("0");
            continue;
        }
        if (a > b) swap(a, b);
        ll c1 = n - a + 1;
        ll c2 = n - b + 1;
        ll c3 = n - a - b + 1;
        ll res = c1 * c1 % MOD * c2 % MOD * c2 % MOD;
        ll f = c1 * c2 % MOD - c3 * (c3 + 1) % MOD + MOD;
        f %= MOD;
        res = res - f * f % MOD + MOD;
        res = res % MOD + MOD;
        res %= MOD;
        Put(res);
        puts("");
    }
}


#include <algorithm>

#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vii = vector<int>;
using vvii = vector<vector<int>>;
using vvvii = vector<vector<vector<int>>>;
using vdd = vector<double>;
using vvdd = vector<vector<double>>;
using vvvdd = vector<vector<vector<double>>>;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define endl '\n'
#define stpr std::fixed << setprecision
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define drep(i, a, b, d) for (ll i = (a); i <= (b); i += d)
#define Rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define drrep(i, a, b, d) for (ll i = (a); i >= (b); i -= d)
#define rRep(i, a, b) for (ll i = a; i >= b; i--)
#define crep(i) for (char i = 'a'; i <= 'z'; ++i)
#define Crep(i) for (char i = 'A'; i <= 'Z'; ++i)
#define ALL(x) (x).begin(), (x).end()
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll MOD = 1000000007;
constexpr ll INF = 1000000011;
constexpr ll MOD2 = 998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS = 10e-10;
template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first;
  is >> p.second;
  return is;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &&x : v) is >> x;
  return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = begin(v); i != end(v); ++i) {
    if (i != begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
    ll n, k, ans, a, b;
    cin >> n >> k;
    map<ll, ll> T;
    rep(i,n){
        cin >> a >> b;
        if(T.find(a)==T.end()){
            T.insert(make_pair(a,b));
        }
        else{
            T[a] += b;
        }
    }
    ans = k;
    while(1){
        auto itr = T.begin();
        if(ans >= itr->first){
            ans += itr->second;
            T.erase(itr);
        }
        else {break;}
        if(T.size()==0){break;}
    }
    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "SKILEVEL"
#define pii pair<ll, pll>
using namespace std;
using ll = long long;
const int  N = 5e5+5;
const ll mod = 1e9+7;
const ll base = 350;
const ll cs = 331;
ll m, n, t, k, tong, q, ans, a[N], b[N], fe[N], c[N*20];
vector<ll> adj[N];
vector<pll> kq;
string s;
void add(ll id)
{
    for(; id <= k; id += id & -id)++fe[id];
}
ll get(ll id)
{
    ll total = 0;
    for(; id; id -= id & -id)total += fe[id];
    return total;
}
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
pll p[N];
void sol()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i ++)cin >> p[i].fi >> p[i].se;
    sort(p+1, p+1+n);
    for(int i = 1; i <= n; i ++)
    {
        if(p[i].fi - p[i-1].fi > k)
        {
            cout << p[i-1].fi+k;
            return;
        }
        k -= p[i].fi - p[i-1].fi;
        k += p[i].se;
    }
    cout << p[n].fi+k;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
4
ANTON
NAAN
AAAAAA
OAANTTON

*/


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

const ll INF = 1000000000000000000;

ll dfs(ll z, int j, ll y, map<ll, ll> &mp){
    if(j == 0){
        return mp[z] = abs(z - y);
    }
    if(mp.count(z)) return mp[z];
    ll res = INF;
    if(((z + 1) << j) <= y){
        res = min(res, dfs((z + 1) * 2, j - 1, y, mp) + 2);
    }
    else if((z << j) <= y){
        res = min(res, dfs((z + 1) * 2, j - 1, y, mp) + 2);
        res = min(res, dfs(z * 2, j - 1, y, mp) + 1);
    }
    if(((z - 1) << j) >= y){
        res = min(res, dfs((z - 1) * 2, j - 1, y, mp) + 2);
    }
    else if((z << j) >= y){
        res = min(res, dfs((z - 1) * 2, j - 1, y, mp) + 2);
        res = min(res, dfs(z * 2, j - 1, y, mp) + 1);
    }
    return mp[z] = res;
}

int main()
{
    ll x, y;
    cin >> x >> y;
    ll ans = abs(y - x);
    map<ll, ll> mp;
    for(int i = 0; i <= 60; i++){
        ll l = y, r = y;
        for(int j = 0; j < i; j++){
            l = l / 2;
            r = (r + 1) / 2;
        }
        if(l == 0) break;
        ll z = x;
        ll s = 0;
        if(z < l){
            s += l - z;
            z = l;
        }
        if(z > r){
            s += z - r;
            z = r;
        }
        ans = min(ans, dfs(z, i, y, mp) + s);
    }
    cout << ans << endl;
}

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

using ll = long long;
using namespace std;

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

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

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

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

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

constexpr int mod = 1'000'000'007; //1e9+7(prime number)
constexpr int INF = 1'000'000'000; //1e9
constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18
constexpr int SIZE = 200010;

int main() {
  ll X, Y;
  ll ans = LLINF;

  cin >> X >> Y;

  set<ll> visited;
  queue<pair<ll, int>> que;

  que.push({Y, 0});

  while (que.size()) {
    auto p = que.front();
    que.pop();

    if (visited.count(p.first)) continue;
    visited.insert(p.first);

    chmin(ans, abs(p.first - X) + p.second);

    if (p.first % 2) {
      que.push({p.first + 1, p.second + 1});
      que.push({p.first - 1, p.second + 1});
    } else {
      que.push({p.first / 2, p.second + 1});
    }
  }

  cout << ans << endl;

  return 0;
}


// JG GAP GG
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<unordered_map>
#include<iomanip>
#include<queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;
ll amari = 1000000007;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];
#define forr(a,b) for(ll i=a;i<b;i++);
#define vecsort(myVec,x,y) sort(myVec.begin(),myVec.end(),[](const vector<y> &alpha,const vector<y> &beta){return alpha[x] < beta[x];});
ll modpow(ll a, ll n, ll mod)
{
	ll res = 1;
	while (0 < n)
	{
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
ll gcd(ll x, ll y)
{
	if (x % y == 0) return y;
	else return gcd(y, x % y);
}
ll lcm(ll x, ll y)
{
	return  (y / gcd(x, y)) * x;
}
// 1or素数だと１を返す
ll primebool(ll x)
{
	for (ll i = 2; i * i <= x; i++)
	{
		if (x % i == 0) return 0;
	}
	return 1;
}
//下のnck関数のための準備
const ll MOD = amari;
vector<long long> fact_inv, inv, Com;
void init_nCk(ll n, ll SIZE) {
	fact_inv.resize(SIZE + 5);
	inv.resize(SIZE + 5);
	fact_inv[0] = fact_inv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < SIZE + 1; i++) {
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
	}
	Com.resize(SIZE + 5);
	Com[0] = 1;
	for (ll i = 1; i < SIZE + 1; i++) {
		Com[i] = Com[i - 1] * ((n - i + 1) * inv[i] % MOD) % MOD;
	}
}
//nCkを計算し、10^9+7で割ったあまりを返す。
ll nck(ll n, ll k)
{
	init_nCk(n, k);
	return Com[k];
}

//ここから

int main()
{
	char s;
	cin >> s;
	char ans;
	char t;
	cin >> t;
	if (s == 'Y')
	{
		if (t == 'a')
        {
          ans = 'A';
        }
		else
		{
			if (t == 'b')
            {
              ans = 'B';
            }
			else
            {
              ans = 'C';
            }
		}
	}
	else
	{
		ans = t;
	}

	cout << ans << "\n";
	return 0;
}

#include <iostream>
#include <cstring>

using namespace std;

int N;
long long dp[105][105][105];
int a[101];
long long X;
int len;

// f(i, j, k) -> minimo tiempo para alcanzar X tomando a i pociones y llevando j pociones actualmente con suma k

long long f(int i, int j, int k)
{
    if (i == 0)
        return k == X%len? 0LL : -1e18;

    if (j == N)
        return -1e18;

    if (dp[i][j][k] != -1)
        return dp[i][j][k];

    long long ans = 0;

    ans = max(f(i, j + 1, k),  f(i - 1, j + 1, (k + a[j])%len) + a[j]);

    return dp[i][j][k] = ans;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    long long ans = 1e18;
    for (int i = 1; i <= N; i++) {
        memset(dp, -1, sizeof dp);
        len = i;
        long long res = f(i, 0, 0);
        if (res > 0)
            ans = min(ans, (X - res)/i);
    }
    cout << ans << '\n';
}


#include <iostream>
using namespace std;

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

#include <bits/stdc++.h>
using namespace std;
int main(){
       int a,b,c,d;
       cin >> a >> b >> c >> d;
       cout << b - c << endl;
}


#include <bits/stdc++.h>

#define int long long
#define endl "\n"
#define mod 1000000007
#define inf 0xFFFFFFFFFFFFFFFL

using namespace std;

void solve()
{
	int n, q;
	cin >> n >> q;
	vector<int> v(n);
	int mn = INT_MAX, mx = INT_MIN;
	for (int i = 0; i < n; i++)
		cin >> v[i], mn = min(v[i], mn), mx = max(v[i], mx);

	vector<vector<int>> a;
	vector<int> temp;
	for (int i = 0; i < n; i++)
	{
		temp.push_back(v[i]);
		if (i == n - 1 or v[i] + 1 != v[i + 1])
		{
			a.push_back(temp);
			temp.clear();
		}
	}
	vector<int> till;
	int cnt = 0;
	for (auto x : a)
	{
		cnt++;
		if (cnt == 1)
		{
			till.push_back(x.front() - 1);
		}
		else
		{
			till.push_back((x.front() - temp.back()) + till.back() - 1);
		}
		temp = x;
		// cout << till.back() << endl;
	}
	while (q--)
	{
		int k;
		cin >> k;
		int in;
		int l = 0, r = till.size();

		while (r - l > 1)
		{
			int mid = (r + l) / 2;
			if (till[mid] >= k)
				r = mid;
			else if (till[mid] < k)
				l = mid;
		}
		in = l;
		// cout << in << endl;
		if (k <= till[0])
			cout << k << endl;
		else if (in == till.size() - 1)
			cout << k + n << endl;
		else
			cout << (a[in].back() + (k - till[in])) << endl;
	}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	srand(chrono::steady_clock::now().time_since_epoch().count());

	cout << fixed << setprecision(3) << endl;

	// int tt;
	// cin >> tt;
	// while (tt--)
	solve();

	cerr << endl
		 << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;

	return 0;
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=1e9+7;

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N=2e5+5;
vi adj[N],ex(N,0),ans(N,0),vis(N,0);
int mxd=0,root,timer=0,r1,r2;

void dfs(int u,int p,int d,int dd=0){
    if(d>mxd){
        root=u;
        mxd=d;
    }
    for(auto v: adj[u]){
        if(v!=p){
            if(dd){
                ex[v]=u;
            }
            dfs(v,u,d+1,dd);
        }
    }
}

void traverse(int u,int p){
    ans[u]=++timer;
    vis[u]=true;
    for(auto v: adj[u]){
        if(v==p || v==ex[u] || vis[v])
            continue;
        traverse(v,u);
    }
    if(ex[u]!=0 && vis[ex[u]]==false)
    traverse(ex[u],u);
    timer++;
}

void solve(){
    int n,u,v;
    cin>>n;
    fr(i,0,n-1){
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,0,1);
    r1=root;
    mxd=0;
    dfs(r1,0,1,1);
    r2=root;
    traverse(r2,0);
    fr(i,1,n+1){
        cout<<ans[i]<<" ";
    }
    return;
}

int main()
{
    boost();

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


#include <bits/stdc++.h>
#include <random>
#include <chrono>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);

const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2e18;
const ld PI=3.14159265358979323846;
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
ll fpow(ll a,ll b,ll m)
{
    if(!b) return 1;
    ll ans=fpow(a*a%m,b/2,m);
    return (b%2?ans*a%m:ans);
}
ll inv(ll a,ll m) {return fpow(a,m-2,m);}

#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define F first
#define S second
#define pb push_back
#define SZ(a) ((ll)a.size())
#define reset(a) memset(a,0,SZ(a))
#define cd(a,b) ((a+b-1)/b)
#define pow2(a) (1LL<<a)
#define LB(a,x) (lower_bound(a.begin(),a.end(),x))
#define LPOS(a,x) (lower_bound(a.begin(),a.end(),x)-a.begin())
#define UB(a,x) (upper_bound(a.begin(),a.end(),x))
#define UPOS(a,x) (upper_bound(a.begin(),a.end(),x)-a.begin())
#define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unisort(c) sort(c.begin(),c.end()),uni(c)
ll a[105],dp[105][100005];
signed main()
{
    MottoHayaku
    ll n,sum=0;
    cin>>n;
    rep1(i,n)
    {
        cin>>a[i];
        sum+=a[i];
        dp[i][0]=1;
        rep1(j,100000)
        {
            dp[i][j]=dp[i-1][j];
            if(j>=a[i]) dp[i][j]|=dp[i-1][j-a[i]];
        }
    }
    ll ans=0;
    for(int i=sum/2;i>=0;i--)
    {
        if(dp[n][i])
        {
            ans=sum-i;
            break;
        }
    }
    cout<<ans<<"\n";
}

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

//#include <atcoder/convolution>
//#include <atcoder/modint>
//using Modint = atcoder::modint998244353;

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 = 1000005;
const int mod = 998244353;

vector<int>prim;
bool b[maxn];
void init(){
  for(int i=2;i<maxn;i++){
    if(!b[i]){
      prim.push_back(i);
      for(int j=i+i;j<maxn;j+=i)b[j]=1;
    }
  }
}

vector<int>p,c;
void dfs(int pos, int cur, int cnt, int l, int r, int& sum){
  if(cur>r)return;
  if(pos==p.size()){
    if(cnt==0)return;
    int tt = r/cur-(l-1)/cur;
    if(cnt&1)sum += tt;
    else sum -= tt;
    return;
  }
  dfs(pos+1, cur * p[pos], cnt+1, l,r,sum);
  dfs(pos+1, cur, cnt, l, r, sum);
}
void dfs2(int pos, int cur, int l, int r, int&sum){
  if(cur>r)return;
  if(pos==p.size()){
    if(cur>=l&&cur<=r)sum++;
    return;
  }
  int tt = 1;
  for(int i=0;i<=c[pos];i++){
    dfs2(pos+1, cur*tt, l,r,sum);
    tt*=p[pos];
  }
}
int solve(int l, int x) {
  if(l>=x)return 0;
  p.clear();
  c.clear();
  int cur = x;
  for(int i=0;prim[i]*prim[i]<=cur;i++){
    int tt = prim[i];
    if(cur%tt==0){
      int cnt = 0;
      while(cur%tt==0){
        cur/=tt;
        cnt++;
      }
      p.push_back(tt);
      c.push_back(cnt);
    }
  }
  if(cur>1){
    p.push_back(cur);
    c.push_back(1);
  }
  int sum = 0;
  dfs(0,1,0,l,x-1,sum);
  int sum2=0;
  dfs2(0,1,l,x-1,sum2);
  return sum-sum2;
}

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


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf 1e18
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
#define N 200000
//***DON'T GET STUCK ON ONE APPROACH
ll power(ll a, ll n, ll m);
ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll x = power(a, n / 2, m);
    if (n % 2 != 0)
        return (((a * x) % m) * (x) % m) % m;
    else
        return (x * x) % m;
}
int32_t main()
{
    ll i, n, j, x, y, m, k, t, sum, count, cnt, b, c, d, j1, z, a, o, temp;
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    cnt = 0;
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j * i <= n; j++)
        {
            for (k = 1; k * j * i <= n; k++)
            {
                //   cout << i << " " << j << " " << k << " ";
                cnt++;
            }
        }
    }
    cout << cnt;
    return 0;
}

///  ||====================================================================||
///  ||                Name: Ezaz Hossain                                  ||
///  ||                CodeChef: ezaz21025                                 ||
///  ||                NIT Durgapur                                        ||
///  ||====================================================================||

#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
#define mod 1000000007
#define MAX 1000000000000000000
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define in insert
#define con continue
#define br break;
#define pi pair<int,int>
#define pl pair<ll,ll>
#define ppl pair<pair<ll,ll>,ll>
#define plp pair<ll,pair<ll,ll>>
#define mem(x,y) memset(x,y,sizeof(x))
#define lcm(a,b) (a*b)/__gcd(a,b)
#define inverse_cos(x) acos(x)
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define set_bit_count(x) __builtin_popcount(x)
#define leading_zero_count(x) __builtin_clz(x)
#define tailing_zero_count(x) __builtin_ctz(x)
#define str_rev(str) reverse(str.begin(),str.end())
#define loop(i,x,y) for(ll i=x;i<y;i++)
#define rloop(i,x,y) for(ll i=x-1;i>=y;i--)
using namespace std;
int main()
{
    ll n;
    cin>>n;
    if(n>=0)
        cout << n << endl;
    else
        cout << 0 << endl;
}


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

int n,k,mod,dp[110][1000010],sum[110];

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n>>k>>mod;
	dp[0][0]=1;
	for(int i=1;i<=n;i++) {
		memset(sum,0,4*i);
		for(int j=0,lim=n*n*k;j<=lim;j++) {
			int r=j%i;
			sum[r]=(sum[r]+dp[i-1][j])%mod;
			if(j-(k+1)*i>=0) sum[r]=(sum[r]-dp[i-1][j-(k+1)*i]+mod)%mod;
			dp[i][j]=sum[r];
		}
	}
	for(int x=1;x<=n;x++) {
		int ans=0,l=x-1,r=n-x;
		for(int i=0;i<=n*n*k;i++) ans=(ans+1ll*dp[r][i]*dp[l][i])%mod;
		ans=(1ll*ans*(k+1)-1+mod)%mod;
		cout<<ans<<'\n';
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,l,r) for(int i=l;i<r;i++)
const int inf=2e9+10;
const int INF=9e18+10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const ll MOD=1e9+7;

const ll tmax=200000;

int main(){
    int h,w;cin>>h>>w;
    char s[h][w];
    rep(i,h)rep(j,w){
        cin>>s[i][j];
    }
    ll dp[h][w];
    rep(i,h)rep(j,w)dp[i][j]=0;
    dp[h-1][w-1]=1;
    ll plusw=1;
    ll plush[w];
    rep(i,w)plush[i]=0;
    plush[w-1]=1;
    int plusd[h+w-1];
    rep(i,h+w-1)plusd[i]=0;
    plusd[w-1]=1;
    for(int i=h-1;i>=0;i--)for(int j=w-1;j>=0;j--){
        if(i==h-1&&j==w-1)continue;
        if(s[i][j]=='#'){
            plusw=0;
            plush[j]=0;
            plusd[j+h-1-i]=0;
            continue;
        }
        dp[i][j]+=plusw;
        dp[i][j]%=MOD;
        /*for(int k=j+1;k<w&&s[i][k]=='.';k++){
            dp[i][j]+=dp[i][k];
            dp[i][j]%=MOD;
        }
        */
        dp[i][j]+=plush[j];
        dp[i][j]%=MOD;

        dp[i][j]+=plusd[j+h-1-i];
        dp[i][j]%=MOD;

        plusw+=dp[i][j];
        plusw%=MOD;
        plush[j]+=dp[i][j];
        plush[j]%=MOD;
        if(j==0)plusw=0;
        plusd[j+h-1-i]+=dp[i][j];
        plusd[j+h-1-i]%=MOD;
    }
    /*
    rep(i,h){
        rep(j,w)cout<<" "<<dp[i][j];
        cout<<endl;
    }
    */
    cout<<dp[0][0]<<endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

void Main(){
    int N; cin >> N;
    VL X(N), Y(N), Z(N); REP(i,N) cin >> X[i] >> Y[i] >> Z[i];
    ll d[N][N];
    REP(i,N)REP(j,N){
        ll x = abs(X[i]-X[j]), y = abs(Y[i]-Y[j]), z = max((ll)0, Z[j]-Z[i]);
        d[i][j] = x + y + z;
    }
    REP(k,N)REP(i,N)REP(j,N) chmin(d[i][j], d[i][k]+d[k][j]);

    VI p(1<<N,0);
    REP(i,1<<N){
        int j = i<<1, k = (i<<1)+1;
        if(j<(1<<N)){
            p[j] = p[i];
        }
        if(k<(1<<N)){
            p[k] = p[i]+1;
        }
    }

    ll dp[1<<N][N]; REP(i,1<<N)REP(j,N) dp[i][j] = LINF;
    dp[0][0] = 0;
    REP(i,1<<N){REP(j,N){
        if(dp[i][j]==LINF) continue;
        REP(k,N){
            if((i>>k)&1) continue;
            int nxt = i | (1<<k);
            chmin(dp[nxt][k], dp[i][j]+d[j][k]);
        }
    }
    }

    ll ans = dp[(1<<N)-1][0];
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

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

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

#define pb push_back
#define ff first
#define ss second
#define MAX 300005
#define MOD 1000000007
#define INF 1e9
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int>adj[MAX];
int xMove[] = { 0,1,0,-1,1,1,-1,-1, 2, 2, -2, -2, 1, 1, -1, -1 };
int yMove[] = { 1,0,-1,0,1,-1,1,-1, 1, -1, 1, -1, 2, -2, 2, -2 };
vector<aiii> vec;
int dp[1<<17][17][2],n;

int solve(int mask, int last, int visited_repeated)
{
    if(mask==(1<<n)-1)
    {
        return abs(vec[0][0]-vec[last][0])+abs(vec[0][1]-vec[last][1])+max(0,vec[0][2]-vec[last][2]);
    }

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

    int ans=INF;
    for(int i=0; i<n; i++)
    {
        if(!(mask&(1<<i)))
            ans=min(ans,abs(vec[i][0]-vec[last][0])+abs(vec[i][1]-vec[last][1])+max(0,vec[i][2]-vec[last][2])+solve(mask|(1<<i),i,0));
    }

    if(visited_repeated==0)
        for(int i=0; i<n; i++)
        {
            if(i!=last and (mask&(1<<i)))
                ans=min(ans,abs(vec[i][0]-vec[last][0])+abs(vec[i][1]-vec[last][1])+max(0,vec[i][2]-vec[last][2])+solve(mask,i,visited_repeated+1));
        }

    return dp[mask][last][visited_repeated]=ans;
}

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
    cin.tie(0),cout.tie(0);
    ios_base::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);
    int TC=1;
    int m,k;

    //cin>>TC;
    for(int t1=1; t1<=TC; t1++)
    {
        cin>>n;
        vec.resize(n);
        for(auto &[a,b,c]: vec)
            cin>>a>>b>>c;
        memset(dp,-1,sizeof dp);

        cout<<solve(1,0,0)<<"\n";
    }

    return 0;
}


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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <std::ostream& os = std::cout>
class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
#if __cplusplus >= 201703L
        auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) {
#else
        void operator()(const Args&... args) const {
#endif
            print(args...);
        }
        template <typename T>
#if __cplusplus >= 201703L
        auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) {
#else
        void pvec(const T& vec, size_t sz) const {
#endif
            for (size_t i = 0; i < sz; i++)
                os << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
#if __cplusplus >= 201703L
        auto pmat(const T& mat, size_t h, size_t w) const -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
#else
        void pmat(const T& mat, size_t h, size_t w) const {
#endif
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    os << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { os << term; }
        void print_rest() const { os << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints<> prints;
Prints<std::cerr> prints_err;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    for (ll i = 1; i <= B; i++) {
        int x = (A + i - 1) / i;
        int y = B / i;
        if (x < y) chmax(ans, i);
    }
    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}

#include <iostream>

using namespace std;
int a[110][110];
int main(){
    int i,j,h,w,mn = 1000; cin >> h >> w;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            cin >> a[i][j];
            mn = min(mn,a[i][j]);
        }
    }
    int sum = 0;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            sum += a[i][j] - mn;
        }
    }
    cout << sum << endl;
}


#include <bits/stdc++.h>

using namespace std;

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

#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 2e5 + 10, MOD = 1e9 + 7;
int id[N], P[N], F[N], n; ll inv = 0;

void update(int pos, int x) {
	for (pos++; pos < N; pos += pos & -pos) F[pos] += x;
}

ll get(int pos, ll res = 0) {
	for (pos++; pos; pos -= pos & -pos) res += F[pos];
	return res;
}

int main() {
	scanf("%d", &n); vector<int> vec;
	for (int i = 1; i <= n; i++) scanf("%d", &P[i]), inv += get(N - 2) - get(P[i]), update(P[i], 1), id[P[i]] = i;
	if (inv != n - 1) return !printf("-1\n");
	for (int i = 1; i <= n; i++) {
		for (int j = id[i] - 1; j >= i; j--) {
			vec.push_back(j);
			id[P[j]] = j + 1, id[P[j + 1]] = j;
			swap(P[j], P[j + 1]);
		}
	}
	for (int x : vec) printf("%d\n", x);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;

void test_case() {
  int n;
  while (scanf("%d", &n) != EOF) {
    vector<int> p(n+1);
    vector<bool> used(n+1);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &p[i]);
    }
    vector<int> a;
    int k = 0;
    for (int i = 2; i <= n; i++) {
      k++;
      if (p[i-1] > p[i]) {
        a.push_back(i-1);
        used[i-1] = true;
        swap(p[i-1], p[i]);
        k--;
      }
      for (int j = i-1; j > 1 && k > 0; j--) {
        if (p[j-1] > p[j]) {
          if (used[j-1]) {
            break;
          }
          a.push_back(j-1);
          used[j-1] = true;
          swap(p[j-1], p[j]);
          k--;
        } else {
          break;
        }
      }
    }
    bool sorted = true;
    for (int i = 2; i <= n; i++) {
      if (p[i-1] > p[i]) {
        sorted = false;
        break;
      }
    }
    bool bad = !sorted || (int) a.size() != n-1;
    if (bad) {
      printf("-1\n");
    } else {
      for (int i : a) {
        printf("%d\n", i);
      }
    }
  }
}

int main() {
  test_case();
  return 0;
}


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

int main(){
  long n;
  cin >> n;
  vector<long> ans;
  for(int i=1;i<sqrt(n)+1;i++){
    if(n%i==0){
      ans.push_back(i);
      if(i*i != n)ans.push_back(n/i);
    }
  }
  sort(ans.begin(), ans.end());
  rep(i,(int)ans.size()){
    cout << ans[i] << endl;
    while(i+1 < (int)ans.size() && ans[i] == ans[i+1])i++;
  }
  return 0;
}

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

long long n;

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

    cin >> n;
    vector<long long> ans;
    for(long long i = 1;  i*i <= n; i++) {
        if(n%i == 0) {
            cout << i << '\n';
            if(i*i != n) ans.push_back(n/i);
        }
    }
    for(int i = ans.size()-1; i >= 0; i--) cout << ans[i] <<  '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
int main(void){
    // Your code here!
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 int i,j,ans,m,n;
 cin >> n;
 int a[n];
 for(i=0;i<n;i++)
 cin >> a[i];
 ans=0;
 for(i=0;i<n;i++)
 {
  m=INT_MAX;
  for(j=i;j<n;j++)
  {
   m=min(m,a[j]);
   ans=max(ans,(j-i+1)*m);
  }
 }
 cout << ans;
 return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define print(x) if(x)cout<<"YES\n";else cout<<"NO\n";
#define pb push_back
#define F first
#define S second
//#define mod 1000000007
#define mod 998244353
using namespace __gnu_pbds;
using namespace std;
void solve() {
	int n;
	cin >> n;
	ll a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll res = (ll)1e14;
	for (int i = 0; i <= (1 << n); i++) {
		ll x = 0, ans = 0;
		for (int j = 0; j < n; j++) {
			if (j == 0) {
				x = a[j];
			}
			else {
				int curbit = ((i >> j) & 1);
				int lastbit = ((i >> (j - 1) & 1));
				if (curbit == lastbit) {
					x |= a[j];
				}
				else {
					ans ^= x;
					x = a[j];
				}
			}
		}
		ans ^= x;
		res = min(res, ans);
	}
	cout << res << "\n";
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	fastio;
	int T = 1;
	// cin>>T;
	while (T--) {
		solve();
	}
}