#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

bool Cmp(pii a,pii b){
  if(a.first>b.first){
    return true;
  }else{
    return false;
  }
}

int main(){
  int n;
  cin>>n;
  vector<pii>team;
  for(int j=0;j<n;j++) team.push_back(pii(0,j));
  for(int i=0;i<(n*(n-1))/2;i++){
    int ta,tb,sa,sb;
    cin>>ta>>tb>>sa>>sb;
    if(sa>sb){
      team[--ta].first+=3;
    }else if(sa<sb){
      team[--tb].first+=3;
    }else{
      team[--ta].first++;
      team[--tb].first++;
    }
  }
  sort(team.begin(),team.end(),Cmp);
  //for(pii a : team)cout <<"score :" << a.first << " team num: " <<a.second << endl;
  //cout << endl;
  int ans[n];
  for(int i=0;i<team.size();i++){
    int cnt=0;
      while(team[i].first==team[i-1-cnt].first)cnt++;
    ans[team[i].second]=i+1-cnt;
  }
  for(int i=0;i<n;i++){
    cout << ans[i] << endl;
  }
 return 0;
}

//https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_A

#include <bits/stdc++.h>

using namespace std;

template<class Weight>
struct WeightedGraph {
    struct Edge {
        int to;
        int weight;
    };
    int n;
    vector<vector<Edge> > adj, rdj;

    explicit WeightedGraph(int n) : n(n), adj(n), rdj(n) {
    }

    void addEdge(int u, int v, Weight w) {
        adj[u].push_back({v, w});
        rdj[v].push_back({u, w}); // can be omitted for the standard dijkstra
    }
};

template<class Weight>
struct ShortestPath {
    WeightedGraph<Weight> g;

    explicit ShortestPath(WeightedGraph<Weight> g) : g(g), dist(g.n), prev(g.n) {
    }

    vector<Weight> dist;
    vector<int> prev;

    void solve(int s) {
        prev.assign(g.n, -1);
        dist.assign(g.n, -1);
        dist[s] = 0;

        using Node = pair<Weight, int>;
        priority_queue<Node, vector<Node>, greater<> > que;
        que.push({0, s});
        while (!que.empty()) {
            auto d = que.top().first;
            auto u = que.top().second;
            que.pop();
            if (dist[u] < d) continue;
            for (auto e: g.adj[u]) {
                auto v = e.to;
                auto w = e.weight;
                if (dist[v] >= 0 && dist[v] <= dist[u] + w) continue;
                dist[v] = dist[u] + w;
                prev[v] = u;
                que.push({dist[v], v});
            }
        }
    }

    int solve(int s, int t) {
        if (s == t) return dist[s] = 0;
        fill(dist.begin(), dist.end(), -1);
        dist[s] = 0;
        vector<Weight> drev(g.n, -1);
        drev[t] = 0;

        using Node = pair<Weight, int>;
        priority_queue<Node, vector<Node>, greater<> > qs, qt;
        qs.push({0, s});
        qt.push({0, t});
        int mu = -1;
        while (!qs.empty() && !qt.empty()) {
            if (mu >= 0 && qs.top().first + qt.top().first >= mu) break;
            if (qs.top().first <= qt.top().first) {
                auto d = qs.top().first;
                auto u = qs.top().second;
                qs.pop();
                if (dist[u] > d) continue;
                for (auto e: g.adj[u]) {
                    auto v = e.to;
                    auto w = e.weight;
                    if (dist[v] >= 0 && dist[v] <= dist[u] + w) continue;
                    dist[v] = dist[u] + w;
                    qs.push({dist[v], v});
                    if (drev[v] >= 0) {
                        auto nu = dist[v] + drev[v];
                        if (mu < 0 || mu > nu) mu = nu;
                    }
                }
            } else {
                auto d = qt.top().first;
                auto u = qt.top().second;
                qt.pop();
                if (drev[u] > d) continue;
                for (auto e: g.rdj[u]) {
                    auto v = e.to;
                    auto w = e.weight;
                    if (drev[v] >= 0 && drev[v] <= drev[u] + w) continue;
                    drev[v] = drev[u] + w;
                    qt.push({drev[v], v});
                    if (dist[v] >= 0) {
                        auto nu = dist[v] + drev[v];
                        if (mu < 0 || mu > nu) mu = nu;
                    }
                }
            }
        }
        return mu;
    }
};

int main() {
    int V, E, r;
    cin >> V >> E >> r;

    WeightedGraph<int> g(V);
    for (int i = 0; i < E; ++i) {
        int s, t, c;
        cin >> s >> t >> c;
        g.addEdge(s, t, c);
    }

    ShortestPath<int> solver(g);
    solver.solve(r);
    for (int i = 0; i < V; ++i) {
        if (solver.dist[i] != -1) {
            cout << solver.dist[i] << endl;
        } else {
            cout << "INF" << endl;
        }
    }

    return 0;
}

/*
 * Dijkstra
 */


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

void Sum(int data[3],int K){

    data[2] *= 2;

    if(K == 1){
        int sum = 0;
        for(int i=0;i<3;i++) sum += data[i];
        cout << sum << endl;
    }
    else{
        Sum(data,K-1);
    }
}

int main(void){

    int data[3];
    int K;

    for(int i=0;i<3;i++) cin >> data[i];
    cin >> K;
    sort(data,data+3);

    Sum(data,K);

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	long double n, m, x;
	cin>>n>>m>>x;
	cout<<(ll)ceil(x/max(n, m));
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A.at(i);
    set<int> B;
    bool flg = true;
    for(int i=0; i<N; i++){
        if(B.find(A.at(i)) == B.end()) B.insert(A.at(i));
        else{
            flg = false;
            break;
        }
    }
    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
}

#define LOCAL

#undef _GLIBCXX_DEBUG

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

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define LLINF 100000000000000005LL
#define INF (int)1e9+1

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// End of Gennady-Korotkevich's template

using llong = long long;
using PII = pair<int, int>;

int n;
vector<vector<vector<double>>> dp;

double dfs(int one, int two, int three) {
	double& ret = dp[one][two][three];
	int cnt = one + two + three;
	if (cnt == 0) return 0;
	if (ret != -1) return ret;
	ret = 0;
	if (one >= 1) ret += dfs(one - 1, two, three) * one / (cnt);
	if (two >= 1) ret += dfs(one + 1, two - 1, three) * two / (cnt);
	if (three >= 1) ret += dfs(one, two + 1, three - 1) * three / (cnt);
	ret += (double)n / (cnt);
	return ret;
}

int main() {
	IOS;
	cin >> n;
	dp = vector<vector<vector<double>>>(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, -1)));
	int one = 0, two = 0, three = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		if (a == 1) one++;
		else if (a == 2) two++;
		else three++;
	}
	cout << fixed << setprecision(15);
	cout << dfs(one, two, three);
}


#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using usize = std::size_t;

i32 a[200000];

auto main() -> i32 {
	i32 n, k;
	scanf("%d%d", &n, &k);
	for (i32 i = 0; i < n; i += 1) {
		scanf("%d", a + i);
	}
	i32 b[200001];
	for (i32 step = 0; step < std::min(64, k); step += 1) {
		std::fill(b, b + n + 1, 0);
		for (i32 i = 0; i < n; i += 1) {
			b[std::max(0, i - a[i])] += 1;
			b[std::min(n, i + a[i] + 1)] -= 1;
		}
		a[0] = b[0];
		for (i32 i = 1; i < n; i += 1) {
			b[i] += b[i - 1];
			a[i] = b[i];
		}
	}
	for (i32 i = 0; i < n; i += 1) {
		printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
	}
	return 0;
}

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

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

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    int n,k; cin >> n >> k;
    int a[n];
    rep(i,n) cin >> a[i];
    int tmp[n];

    for(int t = 0; t < k; t++){
        rep(i,n) tmp[i] = 0;
        rep(i,n){
            if(i - a[i] < 0){
                tmp[0]++;
            }else{
                tmp[i-a[i]]++;
            }
            if(i + 1 + a[i] < n){
                tmp[i+1+a[i]]--;
            }
        }
        a[0] = tmp[0];
        rep(i,n-1){
            a[i+1] = a[i] + tmp[i+1];
        }
        bool f = true;
        rep(i,n) if(a[i] != n) f = false;
        if(f) break;
    }
    rep(i,n) cout << a[i] << ' ';
}


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

int main() {
  long n,m,x=0,ans=0;
  cin >> n >> m;
  map<long,long> aaa;
  aaa[0]=1;
  for(long i=0;i<n;i++) {
    long a;
    cin >> a;
    x+=a;
    x=x%m;
    aaa[x]++;
    ans+=aaa[x]-1;
  }
  cout << ans << endl;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 2007;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m;
char s[maxN][maxN];
int a[maxN], b[maxN], c[maxN];
int mat[maxN][maxN];
int stack[maxN], Top, ans = 0;

int main() {

	n = ri(), m = ri();
	rep (i, 1, n) scanf("%s", s[i]+1);

	For (i, 1, n) {
		rep (j, 1, m) a[j] = s[i][j] == '.' ? 1 : 0;
		rep (j, 1, m) b[j] = s[i+1][j] == '.' ? 1 : 0;

		rep (k, 0, 1) {
			rep (j, 1, m) b[j] ^= k;
			per (j, m, 1) c[j] = (a[j] == b[j]) ? 1 + c[j+1] : 0;
			rep (j, 1, m) mat[i][j] = max(mat[i][j], c[j]);
		}
	}

	rep (j, 1, m) {
		Top = 0;
		For (i, 1, n) {
			for (; Top && mat[stack[Top]][j] >= mat[i][j]; --Top) {
				ans = max(ans, mat[stack[Top]][j] * (i - stack[Top-1]));
			}
			stack[++Top] = i;
		}
		for (; Top; --Top) {
			ans = max(ans, mat[stack[Top]][j] * (n - stack[Top-1]));
		}
	}

	printf("%d\n", max(ans, m));

	return 0;
}


#include<iostream>

using namespace std;

int n,A,B;

int main(){
	while(true){
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			int a,b;
			cin>>a>>b;
			if(a>b)A=A+a+b;
			else if(a<b)B=B+a+b;
			else A=A+a,B=B+b;
		}
		cout<<A<<" "<<B<<endl;
		A=0,B=0;
	}
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
	int n, a, b, count = 0, pointX = 0, pointY = 0;
	cin >> n;
	do {
		cin >> a >> b;
		if (a > b) {
			pointX += (a + b);
		}
		else if (a < b) {
			pointY += (a + b);
		}
		else {
			pointX += a;
			pointY += b;
		}
		count++;
		if (count == n) {
			cout << pointX << " " << pointY << endl;
			pointX = pointY = count = 0;
			cin >> n;
		}
	} while (n != 0);
	return 0;
}


#include <iostream>
#include <vector>
//#define rep(i,n) for(int i = 0; i , (n); ++i)
using ll = long long;
using namespace std;

int sum(int n) {
    if (n == 0) {
        return 0;
    }

    int s = sum(n - 1);
    return s + n;
}
int main() {
    int N, W;
        cin >> N >> W;
        vector<vector<char>>A(N, vector<char>(W));

        for (int i = 0;i < N;i++) {
            for (int j = 0;j < W;j++) {
                cin >> A.at(i).at(j);
            }
        }
        bool hantei = true;
        for (int i = 0;i < N;i++) {
            for (int j = 0;j < W;j++){
                    if (j>0&&j<(W-1)&&i>0&&i<(N-1)&&A.at(i).at(j) == '#'&&A.at(i + 1).at(j) == '.' && A.at(i - 1).at(j) == '.' &&
                        A.at(i).at(j + 1) == '.' && A.at(i).at(j - 1) == '.') {
                         hantei=false;
                             break;
                    }
            }
            if (hantei == false) {
                break;
            }
        }
        if (hantei) {
            cout << "Yes";
        }
        else {
            cout << "No";
        }
}

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

#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}    //最大公約数
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}     //最小公倍数
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} //コンビネーション
int nHr(int a,int b){return nCr(a+b-1,b);}       // 重複組み合わせ
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}  //階乗
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} // a~bまでの階乗
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}   //数字の各位の和
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}  // b進数の各位の和？
int sankaku(int x){return ((1+x)*x)/2;} //三角数 xまでの和

//以下long long ver
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}

//double
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}

typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) ; for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
bool is_prime (int x){
  if (x<=1) return false ;
  for (int i=2 ; i*i<=x ; i++){
    if (x%i==0) return false ;
  }
   return true;
}
string alpha = "abcdefghijklmnopqrstuvwxyz" ;
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

bool chmin (int a,int b){
    if ( a > b ){
    a = b;
    return true ;
    }
    return false ;
}
 bool chmax (int a,int b){
    if ( a < b ){
    a = b;
    return true ;
    }
    return false ;
}
#define SORT(c) sort((c).begin(),(c).end());
#define ANS(ans) cout<<(ans)<<endl;

 string split (string s , ll  n , char x){
   // n文字目は前の文字列
   string a ,b,c,d;
   a = s;
   b = s;
   if ( x == 'f'){
     return c  = a.erase(n) ;
   }else if ( x == 'l'){
     return d = b.substr(n) ;
   }
 }
/*CODE START HERE*/
int main() {
  int h, w;
 cin >> h >> w;
  bool ans = true ;
 string board[50];
  for (int i = 0; i < h; ++i) cin >> board[i];

   for (int i = 0; i < h; ++i) {
 for (int j = 0; j < w; ++j) {
   if (board[i][j] == '.') continue;
int num = 0;
 for (int d = 0; d < 4; ++d) {
 const int ni = i + dy[d];
 const int nj = j + dx[d];

 if(ni<0 || h<=ni)continue;
 if(nj<0 || w<=nj)continue;
 if (board[ni][nj] == '#') num++;
 }
  if ( num == 0){
    ANS("No");
    return 0 ;
  }
 }
   }
ANS("Yes") ;
}


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

int main() {

    int64_t n;
    cin>>n;

    vector<int> L(2*n);
    for(int i=0;i<2*n;i++){
        cin>>L.at(i);
    }

    sort(L.begin(),L.end());

    int64_t sum=0;
    for(int i=0;i<2*n;i++){
        if(i%2==1)
            sum+=min(L.at(i),L.at(i-1));
    }

    cout<<sum<<endl;

 	return 0;
}

//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 220
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int a[N];
int n;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read()<<1;
	for(register int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);int ans=0;
	for(register int i=1;i<=n;i+=2)ans+=a[i];
	printf("%d\n",ans);
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
static const long long INF = 100000000000000;
bool warshall_floyd(vector<vector<long long> > &graph);

int main() {
    int v,e;
    scanf ("%d %d",&v,&e);
    vector<vector<long long> > g (v, vector<long long>(v,INF));
    int s,t,d;
    for(int i=0;i<e;i++){
      scanf ("%d %d %d",&s,&t,&d);
      g[s][t]=d;
    }
    bool x;
    x=warshall_floyd(g);
    if(x==true){
      for(int i=0;i<v;i++){
        if(g[i][0]>=INF){
          printf("INF");
        }
        else{
          printf("%lld",g[i][0]);
        }
        for(int j=1;j<v;j++){
          if(g[i][j]>=INF){
            printf(" INF");
          }
          else{
            printf(" %lld",g[i][j]);
          }
        }
        printf("\n");
      }
    }
    else{
      printf("NEGATIVE CYCLE\n");
    }
}

// graph は隣接行列形式！
// 戻り値は負閉路検出結果で、負閉路があれば false 、なければ true
bool warshall_floyd(vector<vector<long long> > &graph) {
    int V = graph.size();
    // 自分までの距離は 0 としておく。後で使う。
    for (int i = 0; i < V; i++) { graph[i][i] = 0; }
    // 本体
    for (int k = 0; k < V; k++) {
      for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
          // 右辺に INF を含むときは計算しないようにする。
          // 重みが負になる辺があると INF - 1 とかになってしまい、
          // INF と区別がつかなくなる。
          if (graph[i][k] < INF && graph[k][j] < INF){
            graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
          }
        }
      }
    }
    // 負閉路検出をやる
    for (int i = 0; i < V; i++) {
      if (graph[i][i] < 0) {
        // これ、もし負閉路がなければ最初に入れた 0 が残っているはず。
        // そうでないということは、負閉路があって、そこを経由して自分自身に戻ってきたということ。
        return false;
      }
    }
    return true;
}

// D - Make Them Even

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

struct Cell {
	int y;
	int x;
	int c;
};

struct Move {
	int y1;
	int x1;
	int y2;
	int x2;
};

int field[500][500];
Cell cells[500 * 500];

int main() {
	int H, W;
	cin >> H >> W;

	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			cin >> field[i][j];
		}
	}

	int k = 0;
	for (int i=0; i<H; i++) {
		if (i % 2 == 0) {
			for (int j=0; j<W; j++) {
				cells[k] = {i, j, field[i][j]};
				k++;
			}
		} else {
			for (int j=W-1; j>=0; j--) {
				cells[k] = {i, j, field[i][j]};
				k++;
			}
		}
	}

	int N = 0;
	vector<Move> ans;
	for (int i=0; i<H*W-1; i++) {
		if (cells[i].c % 2 == 1) {
			ans.push_back(Move{cells[i].y, cells[i].x, cells[i+1].y, cells[i+1].x});
			cells[i+1].c++;
			N++;
		}
	}

	cout << N << endl;
	for (Move a : ans) {
		cout << a.y1 + 1 << " " << a.x1 + 1 << " " << a.y2 + 1 << " " << a.x2 + 1 << endl;
	}

	return 0;
}


// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>str;
    if(str.length()==2&&str[0]==str[1]) {
      cout<<1<<" "<<2<<endl;
      return 0;
    }
    rep(i,str.length()-2){
      if(str[i]==str[i+1]){
        cout<<i+1<<" "<<i+3<<endl;
        return 0;
      }if(str[i]==str[i+2]){
        cout<<i+1<<" "<<i+3<<endl;
        return 0;
      }
    }
    if(str[str.length()-2]==str[str.length()-1]) {
      cout<<str.length()-2<<" "<<str.length()<<endl;
      return 0;
    }
    cout<<-1<<" "<<-1<<endl;

}

#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

string replaceOtherStr(std::string &replacedStr, std::string from, std::string to) {
    const ll pos = replacedStr.find(from);
    const ll len = from.length();

    if (pos == (ll)std::string::npos || from.empty()) {
        return replacedStr;
    }

    return replacedStr.replace(pos, len, to);
}

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

    stack<char> stk;

    rep(i, (ll)s.length()) {
        if (stk.empty()) {
            stk.push(s[i]);
        } else {
            if (stk.top() == 'S' && s[i] == 'T') {
                stk.pop();
            } else {
                stk.push(s[i]);
            }
        }
    }
    mes(stk.size());
    re0;

}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 2e5 + 5;
typedef long long ll;
using namespace std;

int n, A, B, x[N];
ll ans;

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin);
#endif
	n = read <int> (), A = read <int> (), B = read <int> ();
	for(int i = 1; i <= n; i++) x[i] = read <int> ();
	for(int i = 1; i < n; i++) ans += min(1ll * B, 1ll * A * (x[i + 1] - x[i]));
	printf("%lld\n", ans);
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vii vector <int>::iterator
#define vd vector <double>
#define vdd vector <double>::iterator
#define vs vector <string>
#define vss vector <string>::iterator
#define vc vector <char>
#define vcc vector <char>::iterator
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
#define SORT(x)     sort(x.begin(),x.end())
#define fill(x,y)   memset(x, y, sizeof(x))
#define PI 2*acos(0.0)
#define fio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
int main(){
   ll a;
   cin >> a;
   cout << a*(1+(a*(a+1))) << endl;
}


#include<iostream>
using namespace std;
#include<stdio.h>
int f_r(int d,int x){
x=x+d;
if(x>=600)return 0;
return d*x*x+f_r(d,x);
}
int main(){
int d;
int s;
while((scanf("%d",&d))!=EOF){
s=f_r(d,0);
printf("%d\n",s);
}
return 0;
}

#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

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

	LL d;
	while (cin >> d) {
		LL ans = 0;
		for (LL i = 1; i * d <= 600 - d; i++) {
			ans += i * d * i * d * d;
		}
		cout << ans << endl;
	}
	return 0;
}


#include <stdio.h>

int main() {
    int n, i, num[2], result[2] = { 0,0 };

    while (scanf("%d", &n)) {
        if (n == 0) break;

        result[0] = 0;
        result[1] = 0;
        for (i = 0; i < n; i++) {
            scanf("%d %d", &num[0], &num[1]);
            if (num[0] > num[1]) result[0] += num[0] + num[1];
            else if (num[0] < num[1]) result[1] += num[0] + num[1];
            else result[0] += num[0], result[1] += num[1];
        }
        printf("%d %d\n", result[0], result[1]);
    }

    return 0;
}

#include<iostream>
using namespace std;

int main(){
int a;
int uma;
int ushi;
int b;
int c;
int i;
while (true){
cin >> a;
if (a == 0){ break; }
else{
	while (true){
	if (i<a){
	cin >> b;
	cin >> c;
	if (b>c){
		uma = uma + b + c;
	}
	else if (b == c){
		uma = uma + b;
		ushi = ushi + c;
	}
	else{
	ushi = ushi + b + c;
	}
	i = i + 1;
}if (i == a){ break; }
}
cout << uma << " " << ushi << endl;
uma = 0;
ushi = 0;
i = 0;
}
}
}


#include <bits/stdc++.h>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

const int match[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};

int main()
{
    int N, M;
    cin >> N >> M;
    int A[M];
    REP(i, M)
    {
        cin >> A[i];
        A[i]--;
    }

    vector<array<int, 9>> dp(N + 1, {0});
    bool isMake[N + 1] = {false};
    isMake[0] = true;
    for (int i = 1; i <= N; ++i)
    {
        vector<array<int, 9>> candidate;
        REP(j, M)
        {
            if (i - match[A[j]] >= 0)
            {
                if (isMake[i - match[A[j]]])
                {
                    array<int, 9> current = dp[i - match[A[j]]];
                    current[A[j]]++;
                    candidate.push_back(current);
                    isMake[i] = true;
                }
            }
        }
        if (isMake[i])
        {
            array<int, 9> maxArray = {0};
            int countMaxSet = 0;
            for (auto iter = candidate.begin(); iter != candidate.end(); ++iter)
            {
                int count = 0;
                REP(j, 9) count += (*iter)[j];
                if (count != countMaxSet)
                {
                    if (count > countMaxSet)
                    {
                        countMaxSet = count;
                        maxArray = *iter;
                    }
                }
                else
                {
                    for (int j = 8; j >= 0; --j)
                    {
                        if (maxArray[j] > (*iter)[j])
                        {
                            break;
                        }
                        else if (maxArray[j] < (*iter)[j])
                        {
                            maxArray = *iter;
                            break;
                        }
                    }
                }
            }
            dp[i] = maxArray;
        }
    }

    for(int i = 8; i >= 0; --i) REP(j, dp[N][i]) cout << i + 1;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    vector<ll> va(n*m+1,0), vb(n*m+1,0);
    rep(i,n) {
      cin >> a[i];
      va[a[i]]++;
    }
    rep(i,m) {
      cin >> b[i];
      vb[b[i]]++;
    }
    vector<ll> num(n*m+1,0);
    rep(i,n) {
      rep(j,m) num[min(a[i],b[j])]++;
    }
    ll ans = 1, s = 0;
    for(int i = n*m; i >= 1; i--) {
      if(va[i] >= 2 || vb[i] >= 2) {
        ans = 0;
      } else if (va[i] == 1 && vb[i] == 1){
        ans *= 1;
      } else if(va[i] == 1 || vb[i] == 1) {
        (ans *= num[i]) %= mod;
      } else {
        (ans *= num[i] + s) %= mod;
      }
      s += num[i] - 1;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int d,t,s;
  cin >> d >> t >> s;
  if (s*t>=d) cout << "Yes" << endl;
  else cout << "No " << endl;
}

#include <iostream>

#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>

using namespace std;
//const char a[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
const int maxN=50;
int dp[maxN+1][maxN+1][maxN*maxN+1];

void solver() {

    string a,b,c;
    cin>>a>>b>>c;

    char n = a[0];
    a.erase(0,1);

    while(1){

        if(n == 'a'){
            if(a.size() == 0){
                cout<<"A"<<endl;
                return; }
            n = a[0];
            a.erase(0,1);
        }else if(n == 'b'){
            if(b.size() == 0){
                cout<<"B"<<endl;
                return;
            }
            n = b[0];
            b.erase(0,1);
        }
        else if(n == 'c'){
            if(c.size() == 0){
                cout<<"C"<<endl;
                return;
            }
            n = c[0];
            c.erase(0,1);
        }
    }

    return;
}

int main() {
    int n=1;
    //cin>>n;
    while(n--)
    {
        solver();
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int, int> P;

class UnionFind {
  public:
    vector<int> Parent;

    UnionFind(int N) {
      Parent = vector<int>(N, -1);
    }

    int root(int A) {
      if(Parent[A] < 0) return A;
      return Parent[A] = root(Parent[A]);
    }

    int size(int A) {
      return -Parent[root(A)];
    }

    bool connect(int A, int B) {
      A = root(A);
      B = root(B);
      if(A==B) {
        return false;
      }

      if(size(A) < size(B)) swap(A, B);
      Parent[A] += Parent[B];
      Parent[B] = A;
      return true;
    }
};

int main() {
  int N, K, L; cin >> N >> K >> L;
  UnionFind Uni(N);
  UnionFind U(N);
  map<P, int> m;
  for(int i = 0; i < K; ++i) {
    int p, q; cin >> p >> q;
    p--, q--;
    Uni.connect(p, q);
  }
  for(int i = 0; i < L; ++i) {
    int r, s; cin >> r >> s;
    r--, s--;
    U.connect(r, s);
  }
  for(int i = 0; i < N; ++i) {
    try {
      int cnt = m.at({Uni.root(i), U.root(i)});
      m.erase({Uni.root(i), U.root(i)});
      m.insert({{Uni.root(i), U.root(i)}, cnt+1});
    } catch(std::out_of_range&) {
      m.insert({{Uni.root(i), U.root(i)}, 1});
    }
  }
  for(int i = 0; i < N; ++i) {
    try {
      cout << m.at({Uni.root(i), U.root(i)});
    } catch(std::out_of_range&) {
      cout << 0;
    }
    if(i != N-1) cout << " ";
  }
  cout << endl;
  return 0;
}

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 2;

int n, k, l;
int tot, head[N], headc[N], ver[M], nxt[M];
int in1[N], cnt1, in2[N], cnt2;
bool vis1[N], vis2[N];
map <PII, int> p;

inline void add(int h[], int u, int v)
{
	ver[++tot] = v, nxt[tot] = h[u], h[u] = tot;
}

void dfs1(int u, int id)
{
	in1[u] = id;
	vis1[u] = true;
	for (int i = head[u]; i; i = nxt[i])
	{
		int v = ver[i];
		if (!vis1[v]) dfs1(v, id);
	}
}

void dfs2(int u, int id)
{
	in2[u] = id;
	vis2[u] = true;
	for (int i = headc[u]; i; i = nxt[i])
	{
		int v = ver[i];
		if (!vis2[v]) dfs2(v, id);
	}
}

int main()
{
	//File("");
	n = gi <int> (), k = gi <int> (), l = gi <int> ();
	for (int i = 1; i <= k; i+=1)
	{
		int u = gi <int> (), v = gi <int> ();
		add(head, u, v), add(head, v, u);
	}
	for (int i = 1; i <= l; i+=1)
	{
		int u = gi <int> (), v = gi <int> ();
		add(headc, u, v), add(headc, v, u);
	}
	for (int i = 1; i <= n; i+=1)
		if (!vis1[i]) dfs1(i, ++cnt1);
	for (int i = 1; i <= n; i+=1)
		if (!vis2[i]) dfs2(i, ++cnt2);
	for (int i = 1; i <= n; i+=1) ++p[make_pair(in1[i], in2[i])];
	for (int i = 1; i <= n; i+=1)
		printf("%d ", p[make_pair(in1[i], in2[i])]);
	return 0;
}


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

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

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

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const ll MOD = 1e9 + 7;
inline ll addmod(ll a, ll b){
	if(a+b<MOD)return a+b;
	return a+b-MOD;
}
inline ll mulmod(ll a, ll b){
	return (a*b)%MOD;
}
inline ll expmod(ll a, ll e){
	ll ret = 1;
	while(e){
		if(e&1)ret = mulmod(ret, a);
		a = mulmod(a, a);
		e >>= 1;
	}
	return ret;
}
inline ll divmod(ll a, ll b){
	return mulmod(a, expmod(b, MOD-2));
}

int n,x,y,z;
int tmask;
int m1, m2, m3;

int memo[40][1<<16][2];
int dp(int now, int mask, bool ok){
	if(now == n)return ok;

	int& ret = memo[now][mask][ok];
	if(ret != -1)return ret;
	ret = 0;

	int nmask = mask<<1|1;
	REP(i,1,10){
		bool nok = ok;
		if((nmask & m1) && (nmask & m2) && (nmask & m3)){
			nok = true;
		}
		ret = addmod(ret, dp(now+1, nmask & tmask, nok));
		nmask <<= 1;
	}
	// if(ret > 0){
	// 	printf("%d %d %d = %d\n",now,mask,ok,ret);
	// }
	return ret;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>n>>x>>y>>z;
    tmask = (1 << (x + y + z - 1)) - 1;
    m1 = 1<<(z-1);
    m2 = 1<<(y+z-1);
    m3 = 1<<(x+y+z-1);

    memset(memo, -1, sizeof memo);
    cout << dp(0, 0, false) << endl;

    return 0;
}

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 2e5 + 5;

int F[N], I[N];

int P(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1LL * a * a % MOD) if (b & 1) res = 1LL * res * a % MOD;
	return res;

}
int C(int n, int r) { return r > n ? 0 : 1LL * I[r] * I[n - r] % MOD * F[n] % MOD; }

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	F[0] = 1;
	for (int i = 1; i < N; i++) F[i] = 1LL * F[i - 1] * i % MOD;
	I[N - 1] = P(F[N - 1], MOD - 2);
	for (int i = N - 2; i >= 0; i--) I[i] = 1LL * I[i + 1] * (i + 1) % MOD;

	int n, m, k; cin >> n >> m >> k;
	int ans = 0;
	for (int i = 1; i <= n; i++) ans = (ans + 1LL * i * (n - i) % MOD * m % MOD * m % MOD) % MOD;
	for (int i = 1; i <= m; i++) ans = (ans + 1LL * i * (m - i) % MOD * n % MOD * n % MOD) % MOD;
	cout << 1LL * ans * C(n * m - 2, k - 2) % MOD << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b
vi vx={-1,0,1,0};
vi vy={0,1,0,-1};
using pi = pair<int,int>;

signed main(){
	int a,b; cin>>a>>b;
	vvi v(a,vi(b));
	queue<pi> q;
	rep(i,0,a){
		rep(j,0,b){
			char c; cin>>c;
			if(c=='#'){
				v[i][j]=1;
				q.push(make_pair(i,j));
			}
			else v[i][j]=0;
		}
	}
	while(!q.empty()){
		pi p=q.front(); q.pop();
		int k,l; tie(k,l)=p;
		bool ok=false;
		rep(i,0,4){
			k+=vx[i]; l+=vy[i];
			if(k>=0 && k<a){
				if(l>=0 && l<b){
					if(v[k][l]==1)ok=true;
				}
			}
			k-=vx[i]; l-=vy[i];
		}
		if(!ok){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    int n, r;
    cin >> n >> r;
    if(n>=10){
        cout << r << endl;
    }else{
        cout << r + 1000 - 100 * n << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n, r;
    cin >> n >> r;
    int rate;
    if (n > 10) {
        rate = r;
    } else {
        rate = r + (100 * (10 - n));
    }
    cout << rate << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i < (int)(b); ++i)
#define endl "\n"
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < int(vec.size()); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < int(table.size()); i++) {
        for (int j = 0; j < int(table.at(0).size()); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
vector<long long> divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;

    /*long long N;
    cin >> N;
    vector<long long> res = divisors(N);
    for (int i = 0; i < res.size(); ++i) {
        cout << res[i] << " ";
    }
    cout << endl;*/
}
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
void Yes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void YES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  int n,cnt=0;
  cin >> n;
  string a,b,c;
  cin >> a >> b >> c;
  rep(i,0,n){
    if(a[i]==b[i]&&b[i]==c[i]){
      continue;
    }else if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]){
      cnt+=2;
    }else{
      cnt++;
    }
  }
  cout << cnt << endl;
}

#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll mi = 1e9, sum = 0;
	vector<ll> a(n);
	int cnt = 0;
	bool zero = false;
	rep(i,n){
		cin >> a[i];
		if(a[i] < 0){
			++cnt;
			chmin(mi, -a[i]);
			sum -= a[i];
		}
		else if(a[i] == 0) zero = true;
		else{
			chmin(mi, a[i]);
			sum += a[i];
		}
	}
	ll ans = sum;
	if(!zero && (cnt%2 == 1)) ans -= 2 * mi;
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
    return 0;
}

#include <stdio.h>

int main ()
{
	char x[100];
	char y[100];

	scanf("%s%s\n", &x,&y);

	printf("%s%s\n", y, x);

	return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21
llfor;
const ll mod=1000000007;
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n;cin>>n;
 bool a[n+10];
 rep(i,1,n+1)sc(a[i]);
 ll box[n+10]={0},c,sum=0;

 rrp(i,n+1,1){
  c=0;
  for(j=2;j*i<=n;j++)c+=box[j*i];
  if(c%2!=a[i]){
   box[i]=1;
   sum++;
  }
 }
 pr(sum);
 rep(i,1,n+1){
  if(box[i]!=0)cout<<i<<" ";
 }
  pnn;
return 0;}

#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int A[5*100000 + 10];
int S[5*100000 + 10];

vi idx[(1LL<<20)+10];
//idx[i]:S中の，iの存在するindexのリスト
int zero[5*100000 + 10];
//zero[i]:S中のi番目までに，いくつ０があるか
int dp[5*100000+10];
//dp[i]:i番目まで見たときの場合の数

signed main(void) {
    int N;
    cin>>N;
    S[0]=0;
    zero[0]=0;
    REP(i,1,N) {
        cin>>A[i];
        S[i] = S[i-1]^A[i];
        if (S[i] == 0) zero[i] = zero[i-1]+1;
        else zero[i] = zero[i-1];
        idx[S[i]].pb(i);
//        cerr<<S[i]<<"\t";
    }
//    cerr<<endl;
//    REP(i,1,N) cerr<<zero[i]<<"\t";
//    cerr<<endl;

    if (S[N] == 0) {
        //Sの右端が0のケース
        int ans = 0;
        REP(d,1,1LL<<20) {
//    REP(d,1,8) {
            //まず，dがSのなかにいくつあるのか確認
            int dnum = idx[d].size();
            if (dnum==0) continue;
            //0,d,0,...,d,0だから，必要なdp配列の数はdnum*2+1;
            dp[0]=1; //スタート→１通り
            int from_zero=1;
            int from_d=0;
            REP(i,1,dnum*2) {
                if (i==dnum*2) { //ラス１→絶対右端で止まらないといけないので１通り
                    dp[i] = from_d;
                } else if (i%2==0) { //iが偶数→現在地はd
                    //まず，行き先候補の0の数を計算
                    int znum = (zero[idx[d][i/2]]-zero[idx[d][i/2-1]]) % mod;
                    dp[i] = znum * from_d % mod;
                    from_zero += dp[i];
                    from_zero %= mod;
                } else { //iが奇数→現在地は0
                    dp[i] = from_zero;
                    from_d += dp[i];
                    from_d %= mod;
                }
//            cerr<<dp[i]<<"\t";
            }
//        cerr<<endl;
//        cerr<<"d="<<d<<"の時："<<dp[dnum*2]<<endl;
            ans += dp[dnum*2];
            ans %= mod;
        }
        //d=0でpartitionする場合→2^(0の総数-1)通り
        int pow2 = 1;
        REP(j,1,zero[N]-1) {
            pow2 *= 2;
            pow2 %= mod;
        }
        cout << (ans + pow2) % mod << endl;
    } else { //Sの右端が0でない→それをdとしてやるだけ
        int d=S[N];
        //まず，dがSのなかにいくつあるのか確認
        int dnum = idx[d].size();
        //0,d,0,...,0,dだから，必要なdp配列の数はdnum*2;
        dp[0]=1; //スタート→１通り
        int from_zero=1;
        int from_d=0;
        REP(i,1,dnum*2-1) {
            if (i%2==0) { //iが偶数→現在地はd
                //まず，行き先候補の0の数を計算
                int znum = (zero[idx[d][i/2]]-zero[idx[d][i/2-1]]) % mod;
                dp[i] = (znum * from_d) % mod;
                from_zero += dp[i];
                from_zero %= mod;
            } else { //iが奇数→現在地は0
                dp[i] = from_zero;
                from_d += dp[i];
                from_d %= mod;
            }
//            cerr<<dp[i]<<"\t";
        }
//        cerr<<endl;
//        cerr<<"d="<<d<<"の時："<<dp[dnum*2]<<endl;
        cout << dp[dnum*2-1] % mod << endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

ll modPow(ll a, ll n) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
  ll t = modPow(a, n / 2);
  return (t * t) % MOD;
}
ll modComb(ll n,ll a){
  ll x=1,y=1;
  rep(i,a){
    x*=n-i;
    x%=MOD;
    y*=i+1;
    y%=MOD;
  }
  y=modPow(y,MOD-2);
  return (x*y)%MOD;
}

int main(){
  ll N,M,K,ans=0,x;
  cin >> N >> M >> K;
  x=modComb(N*M-2,K-2);
  rep(i,N){
    ll k;
    k=i*(N-i);
    k%=MOD;
    k*=M;
    k%=MOD;
    k*=M;
    k%=MOD;
    k*=x;
    k%=MOD;
    ans+=k;
    ans%=MOD;
  }
  rep(i,M){
    ll k;
    k=i*(M-i);
    k%=MOD;
    k*=N;
    k%=MOD;
    k*=N;
    k%=MOD;
    k*=x;
    k%=MOD;
    ans+=k;
    ans%=MOD;
  }
  cout << ans << endl;
}

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

int main(){
  int N; cin >> N;
  int h,w; cin >> h >> w;
  int r = (N-h+1) * (N-w+1);
  cout << r << "\n";

}


#include <stdio.h>

#define ICES 10

int main(){
    int num[ICES];
    int n, tmp;

    while (scanf("%d",&n), n!=0){
        for (int i=0; i<ICES; i++) num[i]=0;
        for (int i=0; i<n; i++){
            scanf("%d", &tmp);
            num[tmp]++;
        }
        for (int i=0; i<ICES; i++){
            if (num[i]==0){
                printf("-\n");
            } else {
                for (int j=0; j<num[i]; j++){
                    printf("*");
                }
                printf("\n");
            }
        }
    }
    return 0;
}

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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

//-------------------------------------------------------------------\\

int main()
{
    IOS;
    //fileRead
    int tc = 1;
    //cin>>tc;
    while(tc--)
    {
        int n; cin>>n;
        cout<<n+sqr(n)+sqr(n)*n;
    }
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//使う前にCOMinit
//最大に注意！！！！！！！！！！！！！！！

int main() {
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans1=0;
    rep(i,n){
        ll num1=n-i;
        ans1+=num1*i*m*m;
        ans1%=MOD;
    }
    rep(i,m){
        ll num2=m-i;
        ans1+=num2*i*n*n;
        ans1%=MOD;
    }
    COMinit();
    if(n*m==2)cout<<ans1<<endl;
    else{
        ll ans=ans1*COM(n*m-2,k-2);
        ans%=MOD;
        cout<<ans<<endl;
    }

    return 0;
}

#include <bits/stdc++.h>

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(box) box.begin(), box.end()

using namespace std;

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

const long long INF = LLONG_MAX/3;

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

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=1e9+7;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
signed main(){
	int n,m,k;
	cin>>n>>m>>k;
	int cn=0;
	int cnt=0;
	for(int i=2;i<=n;i++)cnt+=i-1;
	cn+=cnt;
	for(int i=2;i<=n;i++){
		cnt-=n-i+1;
		cnt+=i-1;
		cn+=cnt;
	}
	cn/=2;
	int ans=0;
	ans+=(((m*m)%MOD*cn)%MOD*COM(n*m-2,k-2))%MOD;
	int cm=0;
	cnt=0;
	for(int i=2;i<=m;i++)cnt+=i-1;
	cm+=cnt;
	for(int i=2;i<=m;i++){
		cnt-=m-i+1;
		cnt+=i-1;
		cm+=cnt;
	}
	cm/=2;
	ans+=(((n*n)%MOD*cm)%MOD*COM(n*m-2,k-2))%MOD;
	cout<<ans%MOD<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> vec(N,vector<int>(3));
  for(int i=0; i<N; i++){
    for(int j=0; j<3; j++){
      cin >> vec.at(i).at(j);
    }
  }
  vector<int> query(Q+2,-1e9);
  for(int i=1; i<=Q; i++){
    cin >> query.at(i);
  }
  query.at(Q+1) = 1e9+10;
  vector<vector<int>> in(Q+2,vector<int>(0));
  vector<vector<int>> out(Q+2,vector<int>(0));

  vector<int>::iterator pos;
  int idx;
  for(int i=0; i<N; i++){
    int s = vec.at(i).at(0);
    int e = vec.at(i).at(1);
    int p = vec.at(i).at(2);
    pos = lower_bound(query.begin(),query.end(),s-p);
    idx = distance(query.begin(),pos);
    in.at(idx).push_back(p);
    pos = lower_bound(query.begin(),query.end(),e-p);
    idx = distance(query.begin(),pos);
    out.at(idx).push_back(p);
  }

  map<int,int> mp;
  mp[1e9+10] = 1;
  for(int i=0; i<Q+1; i++){
    for(int j=0; j<in.at(i).size(); j++){
      if(mp.count(in.at(i).at(j))){
        mp[in.at(i).at(j)]++;
      }
      else{
        mp[in.at(i).at(j)] = 1;
      }
    }
    for(int j=0; j<out.at(i).size(); j++){
      mp[out.at(i).at(j)]--;
      if(mp[out.at(i).at(j)] == 0){
        mp.erase(out.at(i).at(j));
      }
    }
    if(i != 0){
      int x = mp.begin()->first;
      if(x == 1e9+10){
        cout << -1 << endl;
      }
      else{
        cout << x << endl;
      }
    }
  }
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    int N, Q;
    cin>>N>>Q;
    vector<pair<ll, ll> > sarr(N), tarr(N);
    multiset<ll> xset;
    ll S, T, X;
    for(int i=0;i<N;++i){
        cin>>S>>T>>X;
        sarr[i] = mp(S-X, X);
        tarr[i] = mp(T-X, X);
    }
    sort(sarr.begin(), sarr.end());
    sort(tarr.begin(), tarr.end());
    ll D[Q];
    for(int i=0;i<Q;++i){
        cin>>D[i];
    }
    ll ans[Q];
    int sindex = 0, tindex = 0;
    for(int i=0;i<Q;++i){
        while(sindex<N && sarr[sindex].fi<=D[i]){
            xset.insert(sarr[sindex].se);
            sindex++;
        }
        while(tindex<N && tarr[tindex].fi<=D[i]){
            xset.erase(xset.find(tarr[tindex].se));
            tindex++;
        }
        if(sindex==tindex) ans[i] = -1;
        else ans[i] = *xset.begin();
    }
    for(int i=0;i<Q;++i){
        cout<<ans[i]<<endl;
    }
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define int long long
#define ll long long
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = 1e-9;
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;
}
using namespace std;
inline ll gcd(ll a, ll b) {
	while (b) {
		ll c = a;
		a = b; b = c % b;
	}
	return a;
}
inline ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
bool isprime(ll n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
ll mypow(ll a, ll b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int n, m, a[110];
signed main() {
	cin >> n >> m;
	int oddcount = 0;
	rep(i, m) {
		cin >> a[i];
		if (a[i] & 1)oddcount++;
	}
	if (m == 1) {
		if (a[0] == 1) {
			cout << 1 << endl << 1 << endl << 1 << endl;
			return 0;
		}
		cout << a[0] << endl;
		cout << 2 << endl;
		cout << a[0] - 1 << " " << 1 << endl;
		return 0;
	}
	if (oddcount >= 3) {
		puts("Impossible");
		return 0;
	}
	if (oddcount == 2 && (n & 1)) {
		puts("Impossible");
		return 0;
	}
	REP(i, m - 1) {
		if (a[i] & 1) {
			if (a[0] & 1) {
				swap(a[i], a[m - 1]);
				break;
			}
			swap(a[0], a[i]);
		}
	}
	rep(i, m - 1)cout << a[i] << " ";
	cout << a[m - 1] << endl;
	if (a[0] != 1) {
		cout << m << endl;
		cout << a[0] - 1 << " ";
	}
	else cout << m - 1 << endl;
	REP(i, m - 2)cout << a[i] << " ";
	cout << a[m - 1] + 1 << endl;
	return 0;
}

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;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;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int mod=998244353;
const int MAXN=3000005;
int pre[MAXN],inv[MAXN];
int C(int n,int m)
{
	if(n<m)return 0;
	return 1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;
}
int n,m;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int pow_mod(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)ret=1LL*ret*a%mod;
		a=1LL*a*a%mod;b>>=1;
	}
	return ret;
}
int main()
{
	pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
	inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
	for(int i=MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
	n=read();m=read();
	int ans=0;
	for(int i=0;i<=m;i++)
		if(!((3*m-i)&1))
			ad(ans,1LL*C(n,i)*C(((3*m-i)>>1)+n-1,n-1)%mod);
//	dl(ans,1LL*n*C(m-2+n-1,n-1)%mod);
	dl(ans,1LL*n*C(m-1+n-1,n-1)%mod);
	pr2(ans);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

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

    vector<int> L(M), R(M);

    for(int i = 0; i < M; i++) {
        cin >> L[i] >> R[i];
        L[i]--, R[i]--;
    }

    vector<vector<int>> train(N, vector<int>(N, 0));
    vector<vector<int>> train_cum(N+1, vector<int>(N+1, 0));

    for(int i = 0; i < M; i++) {
        train[L[i]][R[i]] += 1;
    }

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            train_cum[i+1][j+1] = train_cum[i][j+1] + train_cum[i+1][j] - train_cum[i][j] + train[i][j];
        }
    }

    int p, q;
    vector<int> answer;

    for(int k = 0; k < Q; k++) {
        cin >> p >> q;

        answer.push_back(train_cum[q][q] - train_cum[p-1][q] - train_cum[q][p-1] + train_cum[p-1][p-1]);
    }

    for(auto i : answer) {
        cout << i << endl;
    }

	return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#define INF 50000000000
struct vertex{
	std::vector<int> edge_to;
	std::vector<int> edge_cost;
	bool done;
	long long int mincost;
};
std::vector<vertex> G(100000);
void shortest_path(int v);
int V,E;
int r;
int main(void){
	std::cin>>V>>E>>r;
	for(int i=0;i<E;i++){
		int from,to,cost;
		std::cin>>from>>to>>cost;
		G[from].edge_to.push_back(to);
		G[from].edge_cost.push_back(cost);
//		G[to].edge_to.push_back(from);
//		G[to].edge_cost.push_back(cost);
	}
	shortest_path(r);
	for(int i=0;i<V;i++){
		if(G[i].mincost!=INF){
			std::cout<<G[i].mincost<<std::endl;
		}else {
			std::cout<<"INF"<<std::endl;
		}
	}
	return 0;
}
void shortest_path(int v){
	for(int i=0;i<V;i++){
		G[i].mincost=INF;
	}
	G[v].mincost=0;
	while(1){
		bool update=false;
		for(int i=0;i<V;i++){
			for(int j=0;j<G[i].edge_to.size();j++){
				if(G[ G[i].edge_to[j] ].mincost>G[i].mincost+G[i].edge_cost[j]){
					G[ G[i].edge_to[j] ].mincost=G[i].mincost+G[i].edge_cost[j];
					update=true;
				}
			}
		}
		if(!update){
			break;
		}
	}

}


#include<iostream>
using namespace std;

class Dice {
    public:
        int *num;

        Dice(int *n) {
            num = n;
        }

        int top() {
            return num[0];
        }

        void move(char c) {
            int n[6];
            for (int i = 0; i < 6; i++) {
                n[i] = num[i];
            }
            if (c == 'N') {
                num[0] = n[1];
                num[1] = n[5];
                num[4] = n[0];
                num[5] = n[4];
            } else if (c == 'S') {
                num[0] = n[4];
                num[1] = n[0];
                num[4] = n[5];
                num[5] = n[1];
            } else if (c == 'W') {
                num[0] = n[2];
                num[2] = n[5];
                num[3] = n[0];
                num[5] = n[3];
            } else {
                num[0] = n[3];
                num[2] = n[0];
                num[3] = n[5];
                num[5] = n[2];
            }
        }
};

int main() {
    int num[6];
    string c;
    for (int i = 0; i < 6; i++) {
        cin >> num[i];
    }
    cin >> c;

    Dice d(num);
    for (int i = 0; i < c.size(); i++) {
        d.move(c[i]);
    }
    cout << d.top() << endl;
}

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

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

int main()
{
	int H, W; cin >> H >> W;
	vector<char> cs(H * W);
	REP(i, H) REP(j, W) cin >> cs[i * W + j];
	const int INF = 1e9;
	vector<int> dists(H * W, INF);
	vector<int> parents(H * W, -1);
	dists[0] = 0;
	deque<int> Q{ 0 };
	while (!Q.empty())
	{
		int v = Q.front(); Q.pop_front();
		int r = v / W, c = v % W;
		vector<int> neighbors;
		if (r > 0 && cs[v - W] == '.') neighbors.push_back(v - W);
		if (r < H - 1 && cs[v + W] == '.') neighbors.push_back(v + W);
		if (c > 0 && cs[v - 1] == '.') neighbors.push_back(v - 1);
		if (c < W - 1 && cs[v + 1] == '.') neighbors.push_back(v + 1);
		for (const int n : neighbors)
		{
			if (dists[n] > dists[v] + 1)
			{
				dists[n] = dists[v] + 1;
				parents[n] = v;
				Q.push_back(n);
			}
		}
	}
	if (dists[H * W - 1] == INF)
	{
		cout << -1 << endl;
	}
	else
	{
		vector<int> path;
		for (int v = H * W - 1; v != -1; v = parents[v])
		{
			path.push_back(v);
		}
		int ans = H * W;
		for (const char ch : cs)
		{
			if (ch == '#') --ans;
		}
		cout << ans - path.size() << endl;
	}
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

vector<int> g[N], ans;
bool bio[N];
int parent[N];

void dfs(int u) {
  bio[u] = true;
  for (int v: g[u]) {
    if (bio[v]) continue;
    dfs(v);
  }
  ans.push_back(u);
}

void solve() {
  int n, m; scanf("%d%d", &n, &m);
  for (int u, v, i = 0; i < n-1+m; ++i) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; ++i) {
    if (bio[i]) continue;
    dfs(i);
  }
  for (int u: ans)
    for (int v: g[u])
      if (!parent[v])
	parent[v] = u;
  for (int i = 1; i <= n; ++i) printf("%d\n", parent[i]);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}

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

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> A(N+M-1),B(N+M-1),G[N],in_cnt(N,0);
	vector<bool> is_root(N,true);

	for(int i=0;i<N+M-1;i++){
		cin >> A[i] >> B[i];
		A[i]--,B[i]--;
		G[A[i]].push_back(B[i]);
		is_root[B[i]] = false;
		in_cnt[B[i]]++;
	}

	int root;
	for(int i=0;i<N-1;i++){
		if(is_root[i]) root = i;
	}

	vector<ll> pa(N,-1);
	queue<ll> q;
	q.push(root);

	while(q.size()){
		ll from = q.front();
		q.pop();
		for(auto to:G[from]){
			pa[to] = from;
			in_cnt[to]--;
			if(in_cnt[to] == 0){
				q.push(to);
			}
		}
	}

	pa[root] = -1;
	for(auto x:pa){
		cout << x+1 << "\n";
	}

}


#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
void solve(){
    ll k,i,j;
    string n,m="0";
    vt<ll> dislike;
    cin>>n>>k;
    m=m+n;
    read(dislike,k);
    fd(i,m.length()-1,1,1)
        while(find(dislike.begin(),dislike.end(),m[i]-'0')!=dislike.end()){
            j=i;
            if (m[j]!='9'){
                m[j]=((m[j]-'0'+1)%10)+'0';
                f(j,j+1,m.length(),1)
                    m[j]='0';
                i=m.length()-1;
            }
            else{
                while(m[j]=='9'){
                    m[j]='0';
                    j--;
                }
                m[j]=((m[j]-'0'+1)%10)+'0';
                i=m.length()-1;
            }
        }
    if (m[0]!='0'){
        while(find(dislike.begin(),dislike.end(),m[0]-'0')!=dislike.end()){
            m[0]=((m[0]-'0'+1)%10)+'0';
        }
        f(j,1,m.length(),1)
            m[j]='0';
        fd(i,m.length()-1,1,1)
            while(find(dislike.begin(),dislike.end(),m[i]-'0')!=dislike.end()){
                j=i;
                if (m[j]!='9'){
                    m[j]=((m[j]-'0'+1)%10)+'0';
                    f(j,j+1,m.length(),1)
                        m[j]='0';
                    i=m.length()-1;
                }
                else{
                    while(m[j]=='9'){
                        m[j]='0';
                        j--;
                    }
                    m[j]=((m[j]-'0'+1)%10)+'0';
                    i=m.length()-1;
                }
            }
    }
    if (m[0]!='0')
        cout<<m<<endl;
    else
        cout<<m.substr(1)<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  vector<vector<bool>> seen(h, vector<bool>(w));
  for(int i=0;i<h;i++) cin >> g[i];
  long long ans = 0;
  long long black = 0, white = 0;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      if(seen[i][j]) continue;
      queue<P> que;
      que.emplace(make_pair(i, j));
      while(!que.empty()) {
        P p = que.front();que.pop();
        if(seen[p.first][p.second]) continue;
        seen[p.first][p.second] = true;
        char c = g[p.first][p.second];
        if(c == '.') white++;
        else black++;
        if(p.first != 0 && !seen[p.first-1][p.second] && g[p.first-1][p.second] != c) que.emplace(make_pair(p.first-1, p.second));
        if(p.first != h-1 && !seen[p.first+1][p.second] && g[p.first+1][p.second] != c) que.emplace(make_pair(p.first+1, p.second));
        if(p.second != 0 && !seen[p.first][p.second-1] && g[p.first][p.second-1] != c) que.emplace(make_pair(p.first, p.second-1));
        if(p.second != w-1 && !seen[p.first][p.second+1] && g[p.first][p.second+1] != c) que.emplace(make_pair(p.first, p.second+1));
      }
      ans += black * white;
      black = white = 0;
    }
  }
  cout << ans << endl;
}


#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <memory.h>
#include <cmath>
#include <array>

using namespace std;

void re(int& x);

template<class T, class... Ts> void re(T& t, Ts&... ts);

void pr(long long x);

void pr(const char *x);

void ps();
template<class T, class... Ts> void ps(const T& t, const Ts&... ts);

#ifdef FFDBG

#else
#define dbg(x...) dsfdsfsdfasd
#endif

typedef long long ll;

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

int n, x;
long long tgt = 0;

struct ex {
    int l, r, b;
} exam[110000];

long long score(const ex& a, long long h) {
    long long sc = a.l * 1ll * min(h, (ll)a.b);
    sc += a.r * 1ll * max(0LL, h-a.b);
    return sc;
}

bool check(long long hrs) {
    int full = hrs / x;
    int rem = hrs % x;

    long long sc = 0;
    rep(i,0,full) sc += score(exam[i], x);
    long long best = sc;

    rep(i,full,n) best = max(best, sc + score(exam[i], rem));

    if (full < n) {
        sc += score(exam[full], x);
        rep(i,0,full) best = max(best, sc - score(exam[i], x) + score(exam[i],rem));
    }

    return best >= tgt;
}

void solve()
{
    re(n,x);
    rep(i,0,n) re(exam[i].b, exam[i].l, exam[i].r);

    rep(i,0,n) tgt += exam[i].l * 1ll * exam[i].b;

    sort(exam, exam+n, [](const ex& a, const ex& b) {
        return score(a,x) > score(b,x);
    });

    long long st = 0, ed = n*1ll*x;
    while (st < ed) {
        long long md = (st+ed)/2;
        if (check(md)) ed = md;
        else st = md+1;
    }

    ps(st);
}

int main() {

    solve();
}

void re(int& x) { scanf("%d", &x); }

template<class T, class... Ts> void re(T& t, Ts&... ts) {
    re(t); re(ts...);
}

void pr(long long x) { printf("%lld", x); }

void pr(const char *x) { printf("%s", x); }

void ps() { pr("\n"); }
template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
    pr(t); if (sizeof...(ts)) pr(" "); ps(ts...);
}

// Program Name: Minimum Spanning Tree
// Written by: by_sknight
// Date: 2019/4/27
#include <bits/stdc++.h>
using namespace std;
#define MAX 105
#define INFTY INT_MAX
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, G[MAX][MAX];

int prim() {
    int d[MAX], p[MAX], color[MAX];
    int u, minv;
    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    d[0] = 0;

    while (1) {
        u = -1;
        minv = INFTY;
        for (int i = 0; i < n; i++) {
            if (color[i] != BLACK && d[i] < minv) {
                minv = d[i];
                u = i;
            }
        }
        if (u == -1)
            break;
        color[u] = BLACK;
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && G[u][v] < d[v]) {
                d[v] = G[u][v];
                p[v] = u;
                color[v] = GRAY;
            }
        }
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] != -1) {
            sum += d[i];
        }
    }
    return sum;
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int k;
            cin >> k;
            G[i][j] = (k == -1 ? INFTY : k);
        }
    }

    int sum = prim();

    cout << sum << endl;
}


// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0,h,w;
    string str;
    cin>>n>>h>>w;
    a=n-h+1;
    b=n-w+1;
    cout<<a*b<<endl;

    return 0;
}

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

int main() {

  int A, B;
  cin >> A >> B;

  cout << max(max(A+B,A-B),A*B) << endl;

return 0;
}


#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll unsigned long long

const ll MOD = 1000000000000000000;

int main() {
	//入力
	int k;
	string s;
	cin >> k >> s;

	//処理
	string ans = s;
	if (s.size() > k) {
		ans = s.substr(0, k) + "...";
	}

	//出力
	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

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

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX]; //n!, 1/n!, 1/n

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(ll n, ll k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime_factor(ll n){
  map<ll,ll> res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n] = 1;
  return res;
}

int main(){
  ll n,m;
  cin >> n >> m;
  COMinit();
  ll ans=1;
  map<ll,ll> M = prime_factor(m);
  for(auto p : M){
    ll k = p.second;
    ans *= COM(n+k-1,k);
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


#include <iostream>
#include <string>
#include <set>

using namespace std;

void input(int& N, set<int>& R_INDEX, set<int>& G_INDEX, set<int>& B_INDEX)
{
  char c;
  for (int i= 0; i < N; i++){
    cin >> c;
    switch(c){
    case 'R':
      R_INDEX.insert(i);
      break;
    case 'G':
      G_INDEX.insert(i);
      break;
    case 'B':
      B_INDEX.insert(i);
      break;
    }
  }
}

long long int findsetnum(set<int>& R_INDEX, set<int>& G_INDEX, set<int>& B_INDEX)
{
  long long int sum = 0;
  int a, b, c;
  set<int>::iterator R_iter, G_iter;
  for (R_iter = R_INDEX.begin(); R_iter != R_INDEX.end(); R_iter++)
    for (G_iter = G_INDEX.begin(); G_iter != G_INDEX.end(); G_iter++){
      a = (B_INDEX.find(2 * (*G_iter) - *R_iter) == B_INDEX.end())? 0 : 1;
      b = (B_INDEX.find(2 * (*R_iter) - *G_iter) == B_INDEX.end())? 0 : 1;
      c = (B_INDEX.find((*G_iter + *R_iter) / 2) == B_INDEX.end() || (*G_iter + *R_iter) % 2 != 0)? 0 : 1;
      sum += (B_INDEX.size() - a - b - c);
    }
  return sum;
}

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  set<int> R_INDEX, G_INDEX, B_INDEX;
  input(N, R_INDEX, G_INDEX, B_INDEX);
  cout << findsetnum(R_INDEX, G_INDEX, B_INDEX) << '\n';
  return 0;
}

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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;

    long long n,r,g,b;
    cin>>n;
    string s;
    cin>>s;

    r=0;
    g=0;
    b=0;

    for(int i=0;i<n;i++) {
        if(s[i]=='R')r++;
        else if (s[i]=='G')g++;
        else if (s[i]=='B')b++;
    }

    int count =0;
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            int k=2*j-i;

            if(i>=j||k>=n||k<=j) continue;

            if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]) count++;
        }
    }

    cout<<r*g*b-count<<endl;
}


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

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int b = 0;
	for(auto c : s) if(c == 'B') ++b;
	long long ans = 0;
	for(int i = 0; i < n; ++i){
		if(s[i] != 'R') continue;
		for(int j = 0; j < n; ++j){
			if(s[j] != 'G') continue;
			ans += b;
			int x = i, y = j;
			if(x > y) swap(x, y);
			int d = y - x;
			if(d % 2 == 0 && s[x + d / 2] == 'B') --ans;
			if(x - d >= 0 && s[x - d] == 'B') --ans;
			if(y + d < n && s[y + d] == 'B') --ans;
		}
	}
	cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int a,b,s,i,x;
	s=100;
	x=0;
	for(i=0;i<4;i++){
		cin>>a;
		if(s>a) s=a;
		x=x+a;
	}
	x=x-s;
	s=100;
	for(i=0;i<2;i++){
		cin>>b;
		if(s>b) s=b;
		x=x+b;
	}
	x=x-s;
	cout<<x<<endl;
	return 0;
}

#include<iostream>
#include<string>
#include<stdio.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<vector>

using namespace std;

int main(){
    int N,M,X,Y;cin >> N >> M >> X >> Y;
    int x[100]={};
    int y[100]={};
    int flag = 1;
    for(int i = 0;i < N;i++)cin >> x[i];
    for(int i = 0;i < M;i++)cin >> y[i];
    for(int i = X+1;i <= Y;i++){
        flag = 1;
        for(int j=0;j < N;j++){
            if(x[j] >= i){
                flag = 0;
                continue;
            }
        }
        if(flag==0)continue;
        for(int j = 0;j < M;j++){
            if(y[j] < i){
                flag = 0;
                continue;
            }
        }
        if(flag == 1)break;
    }
    if(flag == 1)cout << "No War" << endl;
    else cout << "War" << endl;
}


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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int cx = 10,cy = 10;
		int v[21][21];
		REP(i, 21) {
			REP(j, 21) {
				v[i][j] = 0;
			}
		}
		int n, m,cnt=0;
		cin >> n;
		if (!n) break;
		REP(i, n) {
			int x, y;
			cin >> x >> y;
			v[x][y] = 1;
		}
		cin >> m;
		REP(i, m) {
			char d;
			int L;
			cin >> d >> L;
			int dx, dy;
			if (d == 'N') {
				dx = 0;dy = 1;
			}
			else if (d == 'E') {
				dx = 1;dy = 0;
			}
			else if(d=='W'){
				dx = -1;dy = 0;
			}
			else {
				dx = 0;dy = -1;
			}
			FOR(j,1, L+1) {
				if (v[cx + j*dx][cy + j*dy] == 1) {
					cnt++;
					v[cx + j*dx][cy + j*dy] = 0;
				}
			}
			cx += L*dx;cy += L*dy;
		}
		if (cnt == n) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define pb push_back
#define sodayoda_C  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define f(i,a,b) for(int i = a;i<b;i++)
#define fb(i,a,b) for(int i = a;i>b;i--)
#define endl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mp make_pair
//memset(name,'',size)
//reverse(s,begin(),s.end())

using namespace std;

int fact(int n){
	if(n == 0) return 1;
	return n*fact(n-1);
}

int main(){
	sodayoda_C;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int t;
	//cin>>t;
	t = 1;
	while(t--){
		int n;
		cin>>n;
		double x[n],y[n];
		f(i,0,n) cin>>x[i]>>y[i];
		double ans = 0;
		f(i,0,n){
			f(j,0,n){
				if(j!=i){
					ans+= (1/(double)n)*sqrt(pow(x[i]-x[j],2) + pow(y[i]-y[j],2));
				}
			}
		}
		printf("%.7f",ans);
	}
	return 0;
}


#include<bits/stdc++.h>

#define LL long long
#define RG register

using namespace std;
template<class T> inline void read(T &x) {
	x = 0; RG char c = getchar(); bool f = 0;
	while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
	while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
	x = f ? -x : x;
	return ;
}
template<class T> inline void write(T x) {
	if (!x) {putchar(48);return ;}
	if (x < 0) x = -x, putchar('-');
	int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
	for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 200010, Mod = 1e9 + 7;
int fac[N], ifac[N], H, W, A, B;
int fpow(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1ll * a * a % Mod)
		if (b & 1) res = 1ll * res * a % Mod;
	return res;
}
int C(int n, int m) {
	if (n < m) return 0;
	return 1ll * fac[n] * ifac[m] % Mod * ifac[n - m] % Mod;
}
int calc(int n, int m) {
	return C(n + m - 2, n - 1);
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	read(H), read(W), read(A), read(B);
	fac[0] = 1;
	for (int i = 1; i <= 200000; i++)
		fac[i] = 1ll * fac[i - 1] * i % Mod;
	ifac[200000] = fpow(fac[200000], Mod - 2);
	for (int i = 200000; i >= 1; i--)
		ifac[i - 1] = 1ll * ifac[i] * i % Mod;
	int ans = 0;
	for (int i = B + 1; i <= W; i++)
		(ans += 1ll * calc(H - A, i) * calc(A, W - i + 1) % Mod) %= Mod;
	printf("%d\n", ans);
	return 0;
}

//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

const long long MAX = 1001000;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long com(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    ll h,w,a,b;
    cin>>h>>w>>a>>b;

    COMinit();

    ll ans=0;
    for(int i=b+1;i<=w;i++){
        ll cur=com(h-1-a-1+i,h-a-1)*com(a-1+w-i,a-1);
        cur=cur%MOD;
        ans+=cur;
        ans=ans%MOD;
    }

    cout<<ans<<endl;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T>
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007

void solve(){
	string s ;
	cin >> s ;
	bool ok = 0 ;;

	trav(i,s)if(i-'0' == 7) ok = 1;
	if(ok) cout << "Yes\n";
	else cout << "No\n";
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();

#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

#include<stdio.h>
int main() {
 int N,B;
 scanf("%d",&N);
 while(N!=0)
 {
  B=N%10;

  if(B==7) {
  printf("Yes");
  break;
  }
  N=N/10;
 }
  if(B!=7)
  printf("No");

 return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;
ll powMod(ll a, ll k)
{
	ll ret = 1;
	while(k)
	{
		if(k & 1) ret = ret * a % mod;
		a = a * a % mod; k >>= 1;
	}
	return ret;
}
ll inv(ll a) { return powMod(a, mod - 2);}
ll C(int n, int m)
{
	ll a = 1, b = 1;
	for(int i = 1; i <= m; ++i)
	{
		a = a * i % mod;
		b = b * (n - i + 1) % mod;
	}
	return b * inv(a) % mod;
}
int main()
{
	ll n, m, k;
	cin >> n >> m >> k;
	ll ans = C(n * m - 2, k - 2);
	ll A = n * n % mod * C(m + 1, 3) % mod;
	ll B = m * m % mod * C(n + 1, 3) % mod;
	ans = ans * (A + B) % mod;
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll pl(ll a, ll b) {
    a %= mod, b %= mod;
    return (a+b) % mod;
}
ll mu(ll a, ll b) {
    a %= mod, b %= mod;
    return (a*b) % mod;
}
ll pow_mod(ll a, ll b) {
    if (b == 0) return 1;
    a %= mod;
    ll k = pow_mod(a, b/2);
    k = mu(k, k);
    if (b & 1) k = mu(k, a);
    return k;
}
ll di(ll a, ll b) {
    a %= mod;
    return mu(a, pow_mod(b, mod-2));
}
ll nCk(ll n, ll k) {
    ll res = 1;
    for (int a = n, b = k; b > 0; a--, b--) {
        res = mu(res, a);
        res = di(res, b);
    }
    return res;
}
int main () {
    ll A[2], K;
    cin >> A[0] >> A[1] >> K;
    ll ans = 0;
    for (int k = 0; k < 2; k++) {
        ll p = A[0], q = A[1];
        for (int i = 1; i <= q-1; i++) {
            ans += mu(mu(mu(p, p), q-i), i);
        }
        swap(A[0], A[1]);
    }
    ans = di(ans, nCk(A[0]*A[1], 2));
    ans = mu(ans, nCk(A[0]*A[1], K));
    ans = mu(ans, nCk(K, 2));
    cout << ans << endl;
}


//
//  main.cpp
//  D
//
//  Created by 曾憲揚 on 2020/8/21.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

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

const int maxn = 4e3+5;

int main(int argc, const char * argv[]) {
    int n; cin>>n;
    string s; cin>>s;

    int r=0, g=0, b=0;
    for(int i=0; i<n; i++){
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else if(s[i]=='B') b++;
    }
    long long ans = 1LL*r*g*b;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(s[i] == s[j]) continue;
            int k = j+(j-i);
            if(k>=n) break;
            if(s[k] != s[i] && s[k] != s[j]) ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool is_palindrome(string str){
  string rstr = str;
  reverse(str.begin(), str.end());

  return rstr == str;
}

int main(){
  int A, B, ans = 0;
  cin >> A >> B;

  for (int i = A; i <= B; i++){
    if (is_palindrome(to_string(i))) ans++;
  }

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


#include<iostream>

int main(void){
	int n;
	std::cin >> n;

	int seq[n];

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

	for (int i = 0; i < n; i ++){
		if (i < n-1) std::cout << seq[(n-1) - i] << " ";
	  else std::cout << seq[ (n-1)-i] << std::endl;
	}

	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
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 main(){
	double i, j, k, l;
	cin >> i >> j >> k >> l;
	cout << fixed << setprecision(8);
	cout << (double)sqrt(pow(i - k, 2.0) + pow(j - l, 2.0)) << endl;
}