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

void main()
{

	set <pair<string,string>> S;
	string o,t;
	int e;
	cin>>e;
	 for (int i=0; i<e; i++)
	 {
	 cin >> o>>t;
	S.insert(make_pair(o,t));
	 }

	 cout << S.size() << endl;

}


#include<stdio.h>
#include<string>
#include<set>
using namespace std;
set<string> hz;
char s[10000];
int main()
{
    int n;
    gets(s);
    sscanf(s,"%d",&n);
    for(int i=0;i<n;i++)
    {
        gets(s);
        hz.insert(s);

    }
    printf("%d\n",hz.size());
}


#include<stdio.h>
#include<string>
#include<set>
using namespace std;
set<string> hz;
char s[10000];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        gets(s);
        hz.insert(s);

    }
    printf("%d\n",hz.size());
}


#pragma comment(linker,"/stack:67108864")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <climits>
#include <cfloat>
#include <functional>
#include <ctime>
#include <numeric>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <bitset>
#include <string>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <typeinfo>
#include <cassert>
#include <ctime>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(v) (v).begin(),(v).end()

const bool TM=true;

string ts,type,name,lists[100];
int i,j,n,ans;
bool stop;

int main(){
    if(TM) freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    cin >> n;
    ans=0;
    for(i=0;i<n;i++){
        stop=false;
        cin >> type >> name;
        ts=type+" "+name;
        for(j=0;j<ans;j++){
            if(lists[j]==ts){
                stop=true;
                break;
            }
        }
        if(!stop){
            lists[j]=ts;
            ans++;
        }
    }
    cout << ans;

    return 0;
}


#pragma comment(linker,"/stack:67108864")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <climits>
#include <cfloat>
#include <functional>
#include <ctime>
#include <numeric>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <bitset>
#include <string>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <typeinfo>
#include <cassert>
#include <ctime>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(v) (v).begin(),(v).end()

const bool TM=false;

string ts,type,name,lists[100];
int i,j,n,ans;
bool stop;

int main(){
    if(TM) {freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);}
    cin >> n;
    ans=0;
    for(i=0;i<n;i++){
        stop=false;
        cin >> type >> name;
        ts=type+" "+name;
        for(j=0;j<ans;j++){
            if(lists[j]==ts){
                stop=true;
                break;
            }
        }
        if(!stop){
            lists[j]=ts;
            ans++;
        }
    }
    cout << ans;

    return 0;
}


#pragma comment(linker,"/stack:67108864")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <climits>
#include <cfloat>
#include <functional>
#include <ctime>
#include <numeric>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <bitset>
#include <string>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <typeinfo>
#include <cassert>
#include <ctime>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(v) (v).begin(),(v).end()

const bool TM=false;

string ts,type,name,lists[100];
int i,j,n,ans;
bool stop;

int main(){
    if(TM) freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    cin >> n;
    ans=0;
    for(i=0;i<n;i++){
        stop=false;
        cin >> type >> name;
        ts=type+" "+name;
        for(j=0;j<ans;j++){
            if(lists[j]==ts){
                stop=true;
                break;
            }
        }
        if(!stop){
            lists[j]=ts;
            ans++;
        }
    }
    cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;
int main()
{
	int leaves;
	cin>>leaves;
	vector < pair<string,string> > p(leaves);
	string str;
	for(int i=0; i<leaves ;i++)
		cin>>p[i].first>>p[i].second;
	for(int i=0;i<p.size();i++)
	{
		int count=0;
		for(int j=i+1;j<p.size();j++)
			if(p[i].first == p[j].first && p[i].second == p[j].second && i != j) count++;
		if(count >= 1) leaves--;
	}
	cout<<leaves<<endl;
	return 0;
}


#include <stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
using namespace std;

int n;

void solve() {
    int i,j,sum=0;
    map<string,int> m;
    map<string,int>::iterator it;
    char c[200];
    string s;
    gets(c);
    for(i=0;i<n;i++) {
        gets(c);
        s=c;
        m[s]=1;
    }
    for(it=m.begin();it!=m.end();it++) {
        sum+=it->second;
    }
    printf("%d",sum);
    return;
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    scanf("%d",&n);
    solve();
    return 0;
}


#include <iostream>
#include <vector>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>

using namespace std;

int n;
set <string> s;
string str;
vector <string> a;

int main(){
    cin>>n;

    a.resize(n+1);

    for (int i=0; i<=n; i++){
        getline(cin, str);
        a[i]=str;
    }

    for (int i=0; i<=n; i++)
        s.insert(a[i]);

    cout<<s.size()-1;

    return 0;
}


#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    string str;
    string s;
    vector <string> a(101);
    int n;
    int k=0;
    cin>>n;

    for(int i=0; i<=n; i++){
        getline(cin,str);
        a[i]=str;
    }

    if ((n==2) && (a[1]==a[2]))
        cout<<1;
    else{
        for (int i=0; i<n-1; i++)
            for (int j=i+1; j<=n; j++)
                if (a[i]==a[j])
                    k++;
        cout<<n-k;
    }

    return 0;
}


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

using namespace std;

int main(){
    string str;
    set <string> r;
    vector <string> a(101);
    int n;
    cin>>n;

    for(int i=0; i<=n; i++){
        getline(cin,str);
        a[i]=str;
    }

    for (int i=0; i<=n; i++)
        r.insert(a[i]);

    cout<<r.size()-1;
    return 0;
}


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

using namespace std;

void solution(string strings[], int size) {
    vector<string> stack;

    for (int i = 0; i < size; i++) {
        if (find(stack.begin(), stack.end(), strings[i]) == stack.end()) {
            stack.push_back(strings[i]);
        }
    }

    cout << stack.size() << endl;
}

int main(int argc, const char * argv[]) {
    int total;

    cin >> total;

    string strings[total];

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

    solution(strings, total);

    return 0;
}


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

using namespace std;

void solution(vector<string> input, int size) {
    vector<string> stack;

    for (int i = 0; i < size; i++) {
        if (find(stack.begin(), stack.end(), input[i]) == stack.end()) {
            stack.push_back(input[i]);
        }
    }

    cout << stack.size() << endl;
}

int main(int argc, const char * argv[]) {
    int total;

    cin >> total;

    vector<string> input;

    string str;

    getline(cin, str);

    for (int i = 0; i < total; i++) {
        getline(cin, str);

        input.push_back(str);
    }

    solution(input, total);

    return 0;
}


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

using namespace std;

void solution(vector<string> strings, int size) {
    vector<string> stack;

    for (int i = 0; i < size; i++) {
        if (find(stack.begin(), stack.end(), strings[i]) == stack.end()) {
            stack.push_back(strings[i]);
        }
    }

    cout << stack.size() << endl;
}

int main(int argc, const char * argv[]) {
    int total;

    cin >> total;

    vector<string> input;

    for (int i = 0; i < total; i++) {
        string str;

        cin >> str;

        input.push_back(str);
    }

    solution(input, total);

    return 0;
}


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

int main() {
	int x;
	string name;
	set<string> leafName;
	cin >> x;

	for (int i = 0; i <= x; i++) {
		getline(cin, name);
		leafName.insert(name);
	}
	cout << leafName.size() - 1 << endl;
}


#include <iostream>
#include <string>
#include <set>
#include <cstdlib>
using namespace std;

int main() {
	int x;
	string name;
	set<string> leafName;
	cin >> x;

	for (int i = 0; i <= x; i++) {
		getline(cin, name);
		leafName.insert(name);
	}
	cout << leafName.size() - 1 << endl;
	system("pause");
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#pragma comment(linker, "/STACK:64000000")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main()
{
	int n, k = 0;
	set <string> m;
	string s;
	//freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

	cin >> n;
	getline(cin, s);
	for (int i = 0; i < n; ++i)
	{
			getline(cin, s);
			if (!m.count(s)) ++k;
			m.insert(s);
	}

	cout << k;
	return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#pragma comment(linker, "/STACK:64000000")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main()
{
	int n, k = 0;
	map <string, string> m;
	string s, q;
	//freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> s >> q;
		if (!(m.count(s) && m.count(q)))
		{
			m[q] = s;
			m[s] = q;
			++k;
		}

	cout << k;

	return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#pragma comment(linker, "/STACK:64000000")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main()
{
	int n, k = 0;
	map <string, string> m;
	string s, q;
	//freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> s >> q;
		if (m.count(s) && m.count(q))
		{
			if (m[q] != s && m[s] != q) ++k;
		}
		else
		{
			m[q] = s;
			m[s] = q;
			++k;
		}
	}

	cout << k;

	return 0;
}


#include <stdio.h>
#include <queue>
#include <vector>
#include <string>
#include <math.h>
#include <map>
#include <set>

using namespace std;

typedef long long LL;

typedef vector<int> vint;
typedef vector<vint> vvint;

int n;

set<string> S;

char s[100000];

int main()
{
	scanf("%d%*c", &n);
	for(int i = 0; i < n; ++i)
	{
		gets(s);
		S.insert(string(s));
	}
	printf("%d", S.size());
	return 0;
}


#include <stdio.h>
#include <vector>
#include <string>
#include <map>

using namespace std;

map<string, int> M1, M2;

int ID1(string s)
{
	if (M1[s] == 0)
		M1[s] = M1.size();
	return M1[s] - 1;
}

int ID2(string s)
{
	if (M2[s] == 0)
		M2[s] = M2.size();
	return M2[s] - 1;
}

typedef vector<int> vint;
typedef vector<vint> vvint;

vvint a;

int n;

char s1[1000], s2[1000];

int main()
{
	a.resize(1000, vint(1000, 0));
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%*c%s%*c%s", &s1, &s2);
		int x = ID1(string(s1));
		int y = ID2(string(s2));
		a[x][y] = 1;
	}
	int res = 0;
	for(int i = 0; i < 1000; ++i)
		for(int j = 0; j < 1000; ++j)
			res += a[i][j];
	printf("%d", res);
	return 0;
}


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

using namespace std;

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

set <string> s;
string str;
vector <string> l(n+1);

for(int i=0; i<=n; i++){
getline(cin, str);
l[i] = str;
}

for(int i=0; i<=n; i++){
s.insert(l[i]);
}

cout<<s.size()-1;

}


#include <iostream>
#include <string>
#include <set>
using namespace std;
int n;
string str;
set<string> st;

void init(){
    cin>>n;
    getline(cin,str);
    for(int i=0;i<n;i++){
        getline(cin,str);
        st.insert(str);
    }
}

void solve(){
    cout<<st.size()<<endl;
}

int main(){
    init();
    solve();
    return 0;
}


#include "iostream"
#include "string.h"
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
#include "limits.h"
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <queue>
#define PI       3.14159265358979323846
#define ull  unsigned long long int
#define ll  long long int
#define EPS 1e-11
#define pb push_back
#define EOS(c) (c != EOF && c != '\0' && c != '\n' && c != ' ')
#define oo 1000000005
#define ALL(v) v.begin(), v.end()
#define win return 0

using namespace std;

int MAX(int a, int b)
{
    return (a > b) ? a : b;
}

double FMAX(double a, double b)
{
    return (a > b) ? a : b;
}

int MIN(int a, int b)
{
    return (a < b) ? a : b;
}

double FMIN(double a, double b)
{
    return (a < b) ? a : b;
}

int GCD(int a,int b)
{
    return b ? GCD(b, a % b) : a;
}

ull UGCD(ull a, ull b)
{
    return b ? GCD(b, a % b) : a;
}

int LCM(int a,int b)
{
    return a / GCD(a, b) * b;
}

ull LCM(ull a, ull b)
{
    return a / GCD(a, b) * b;
}

void fswop(double &a, double &b)
{
    double c = a;
    a = b;
    b = c;
}

void bez_swop(int &a, int &b)
{
    int c = a;
    a = b;
    b = c;
}

void swop(int &a, int &b)
{
    a = a ^ b;
    b = a ^ b;
    a = a ^ b;
}

ll u(ll a)
{
    if(a >= 0)
        return a;
    return a * (-1);
}

map<pair<string, string>, int> t;
map<pair<string, string>, int>::iterator it;
int co;

void faa(pair<string, string> s)
{
    it = t.find(s);
    if(it == t.end())
    {
        t[s] = co++;
    }
}

int main()
{
    int n;
    string s, y;

    cin >> n;

    while(n--)
    {
        cin >> s >> y;
        faa(make_pair(s, y));
    }

    cout << co;

    win;
}


//#pragma comment(linker, "/STACK:65777216")
//#include <iostream>
//#include <vector>
//#include <math.h>
//#include <stdio.h>
//#include <algorithm>
//#include <cstring>
//#include <string>
//#include <stack>
//#include <deque>
//#include <queue>
//#include <set>
//#include <map>
//#include <utility>
//#include <ctime>
//#define pb push_back
//#define mp make_pair
//#define par first
//#define siz second
//#define ll long long
//
//using namespace std;
//
//ll binpow (ll a1, ll b1)
//{
//    if (b1 == 0)
//    {
//        return 1;
//    }
//    if (b1 % 2 == 1)
//    {
//        return binpow (a1, b1-1) * a1;
//    }
//    else
//    {
//        ll b = binpow (a1, b1/2);
//        return b * b;
//    }
//}
//
//ll gcd (ll a1, ll b1)
//{
//    if (b1 == 0)
//        return a1;
//    else
//        return gcd (b1, a1 % b1);
//}
//
//
//ll n, m;
//bool d[200005];
//vector <pair<pair<bool, ll>, pair<ll, ll>>> r;
//
//
//int main ()
//{
//	cin>>n>>m;
//	for (int i=0; i<m; i++)
//	{
//		ll a1, b1, r1;
//		cin>>a1>>b1>>r1;
//
//		r.pb(mp(mp(0, r1), mp(a1, b1)));
//	}
//
//	sort(r.begin(), r.end());
//	for (int i=0; i<n; i++)
//	{
//		for (int j=0; j<r.size(); j++)
//		{
//
//		}
//	}
//}

#pragma comment(linker, "/STACK:65777216")
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define pb push_back
#define mp make_pair
#define par first
#define siz second
#define ll long long

using namespace std;

ll binpow (ll a1, ll b1)
{
    if (b1 == 0)
    {
        return 1;
    }
    if (b1 % 2 == 1)
    {
        return binpow (a1, b1-1) * a1;
    }
    else
    {
        ll b = binpow (a1, b1/2);
        return b * b;
    }
}

ll gcd (ll a1, ll b1)
{
    if (b1 == 0)
        return a1;
    else
        return gcd (b1, a1 % b1);
}

ll n;
string s;
set <string> m;

int main ()
{
	cin>>n;
	getline(cin, s);
	for (int i=0; i<n; i++)
	{
		getline(cin, s);
		m.insert(s);
	}
	cout<<m.size();
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <hash_map>
#include <map>
#include <hash_set>
#include <set>
#include <stack>
#include <algorithm>
#include <sstream>
#include <queue>
#include <math.h>
using namespace std;
typedef long long LL;
#define mems(arr, val) memset(arr, val, sizeof(arr));
#define all(A) A.begin(), A.end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define INF 2000000000
#define SIZE 1000009
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
const int MAXN = 3 * 100000 + 100;
vector<char> M(3);
LL minval = LLONG_MAX;
LL rec(vector<LL> a, int pos)
{
	if (pos == 3) {
		minval = min(minval, (LL)a[0]);
		return 0;
	}

	for(int i = 0; i < a.size(); ++i)
	{
		for(int j = i + 1; j < a.size(); ++j)
		{
			vector<LL> newa;
			for(int k = 0; k < a.size(); ++k)
			{
				if (k == i || k == j) continue;
				newa.push_back(a[k]);
			}
			newa.push_back(M[pos] == '*'?(a[i] * a[j]) : (a[i] + a[j]));
			rec(newa, pos + 1);
		}
	}

}

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

	map<string, int> A;
	int n;
	scanf("%d\n", &n);
	int ans = 0;
	forn(i, 0, n)
	{
		string str;
		getline(cin, str);

		if (!A.count(str)) {A[str] = 1; ans++; }
	}
	cout<<ans;

	return 0;
}


#include <cstdio>
#include <set>
#include <string>
using namespace std;

set<string> maj;

int n;
char str[100];

void main() {
	scanf("%d\n", &n);
	while(--n >= 0) {
		gets(str);
		maj.insert(str);
	}
	printf("%d\n", maj.size());
}


#include <cstdio>
#include <set>
#include <string>
using namespace std;

set<string> maj;

int n;
char str[100];

void main() {
	scanf("%d", &n);
	while(--n >= 0) {
		gets(str);
		maj.insert(str);
	}
	printf("%d\n", maj.size());
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
template<class T>inline int SIZE(T & n){return n.size();}
template<class T>void OUT(const T & n){for(unsigned int i = 0; i < n.size(); ++i){cout << n[i] << " ";}cout << endl;}

int toInt(string s){int r = 0;stringstream sin(s);sin>>r;return r;}
template<class T>string toString(T  n){ostringstream ost; ost << n; ost.flush(); return ost.str();}

class IndianSummer{
public:
	int howMany(vector<string> leaves){

		int res = 1;
		for(int i = 0; i < leaves.size(); ++i)
		{
			int cnt = 0;
			for(int j = 0; j < leaves.size(); ++j)
			{
				if(i!= j)
				{
					if(leaves[i] != leaves[j])
					{
						cnt++;
						res = max(res, cnt);
					}
				}
			}
		}
		return res;
	}
};

int N;
string str1, str2;
int main()
{

	vector<string> leaves;
	cin >> N;
	for(int i = 0; i < N; ++i)
	{
		cin >> str1 >> str2;
		str1.append(" ");
		str1.append(str2);
		leaves.push_back(str1);
	}
	IndianSummer Leaves;
	int res = Leaves.howMany(leaves);
	cout << res << endl;

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); ++i)
template<class T>inline int SIZE(T & n){return n.size();}
template<class T>void OUT(const T & n){for(unsigned int i = 0; i < n.size(); ++i){cout << n[i] << " " << endl;}cout << endl;}

int toInt(string s){int r = 0;stringstream sin(s);sin>>r;return r;}
template<class T>string toString(T  n){ostringstream ost; ost << n; ost.flush(); return ost.str();}

class IndianSummer{
public:
	int howMany(vector<string> leaves){
		{
			int res = 1;
			sort(leaves.begin(), leaves.end());
			for(int i = 0; i < leaves.size()-1; ++i)
			{
				if(leaves[i] != leaves[i+1])
				{
					res++;
				}
			}
			return res;
		}
	}
};

int N;
string str1, str2;
int main()
{

	vector<string> leaves;
	cin >> N;
	for(int i = 0; i < N; ++i)
	{
		cin >> str1 >> str2;
		str1.append(" ");
		str1.append(str2);
		leaves.push_back(str1);
	}
	IndianSummer Leaves;
	int res = Leaves.howMany(leaves);
	cout << res << endl;
	return 0;
}


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

using namespace std;
void main()
{
    set<string> ins;
    int n,a;
    string str;
    cin>>n;
    while (getline(cin,str))
        ins.insert(str);
    cout<<ins.size()-1<<endl;

}


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

using namespace std;
void main()
{
	set<string> ins;
	int n,a;
	string str;
	cin>>n;
	for (int i=0; i<n;i++)
	{
		if (getline(cin,str))
			ins.insert(str);
	}
	cout<<ins.size()-1<<endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <assert.h>
#include <string.h>
#include <limits>
using namespace std;

#define INF 100000000
#define PI 3.1415926535897932384626433832795
#define PI_HALF 1.570796327
#define EPS 1e-9

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair< int, int > PII;
typedef pair< LL, LL > PLL;
typedef vector< int > VI;
typedef vector< LL > VLL;
typedef vector< string > VS;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define SZ(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort( ALL( c ) )
#define SORT_(c,f) sort( ALL( c ), f )
#define FILL(x,v) memset( x, v, sizeof( x ) );

#define REP(i,n) for ( int i = 0, max_ = (n); i < max_; ++i )
#define REPD(i,n) for ( int i = (n) - 1; i >= 0; --i )
#define FOR(i,a,b) for ( int i = (a), max_ = (b); i < max_; ++i )
#define FORD(i,a,b) for ( int i = (a) - 1, min_ = (b); i >= min_; --i )

LL GCD ( LL a, LL b ) { return b != 0 ? GCD(b, a % b) : a; }
LL LCM ( LL a, LL b ) { return a*(b / GCD(a,b)); }
LL Pow ( LL n, LL e ) { if ( e == 0 ) return 1; if ( e == 1 ) return n; else if ( e & 1 ) { LL t = Pow(n,e/2); return n*t*t; } else { LL t = Pow(n,e/2); return t*t; } }

int main ()
{
    set< string > m;
    int N, res = 0;
    scanf( "%d", &N );
    string s;
    getline( cin, s );
    REP(i,N)
    {
        getline( cin, s );
        if ( m.find( s ) == m.end() )
        {
            ++res;
            m.insert( s );
        }
    }
    printf( "%d\n", res );

    return 0;
}


#include <iostream>
#include <set>

using namespace std;

set<string> myset;

int main(){
	int n;
	cin>> n;
	cin.ignore();
	while(n--){
		string leaf;
		getline(cin, leaf);
		myset.insert(leaf);
	}
	cout<<myset.size()<<endl;
}


#include <iostream>
#include <set>

using namespace std;

set<string> myset;

int main(){
	int n;
	cin>> n;
	while(n--){
		string leaf;
		getline(cin, leaf);
		myset.insert(leaf);
	}
	cout<<myset.size()<<endl;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

using namespace std;

set<string> myset;

int main(){
	int n;
	cin>> n;
    cin.ignore();
	myset.clear();
	while(n--){
		string leaf;
		getline(cin, leaf);
		myset.insert(leaf);
	}
	cout<<myset.size()<<endl;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

set<string> myset;

int main(){
	int n;
	cin>> n;
	while(n--){
		string leaf;
		getline(cin, leaf);
		myset.insert(leaf);
	}
	cout<<myset.size()<<endl;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

using namespace std;

set<string> myset;

int main(){
	int n;
	cin>> n;
	while(n--){
		string leaf;
		getline(cin, leaf);
		myset.insert(leaf);
	}
	cout<<myset.size()<<endl;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

using namespace std;

set<string> myset;

int main(){
	int n;
	cin>> n;
	myset.clear();
	while(n--){
		string leaf;
		getline(cin, leaf);
		myset.insert(leaf);
	}
	cout<<myset.size()<<endl;
}


#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
//setw(x)..cout.width...cout.precision(x)

using namespace std;

int main()
{
      //   freopen("a.in","r",stdin);
    int n,num[102];

     while(cin>>n)
     {

         num[1]=1;

         for(int i=2;i<=n;i++)

             num[i]=(num[i-1]+i)%n;
         for(int i=1;i<n-1;i++)
             cout<<num[i]+1<<" ";
         cout<<num[n-1]+1<<endl;

     }

    return 0;
}


#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
//cout.precision(0);
//cout.setf(ios_base::fixed)

using namespace std;

int main()
{
 // freopen("aa.in","r",stdin);
string n[101],r[101];
int t;

 while(cin>>t)
 {
     for(int i=0;i<t;i++)
         cin>>n[i]>>r[i];
     for(int i=0;i<t;i++)
          for(int j=i+1;j<t;j++)
              if(n[i]==n[j] && r[i]==r[j])
              {
                  n[i]=" ";
              }
              int c=0;
              for(int i=0;i<t;i++)
                  if(n[i]!=" ")
                      c++;
              cout<<c<<endl;
 }

    return 0;
}


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

using namespace std;

typedef struct {
    string s1;
    string s2;
} T1;

set <pair <string, string>> S;

int main() {
    //freopen("input.txt", "r", stdin);

    int n;
    cin >> n;

    T1 buf;

    for (int i = 0; i < n; i++) {
        cin >> buf.s1 >> buf.s2;

        S.insert(make_pair(buf.s1, buf.s2));
    }

    cout << S.size();

    return 0;
}


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

using namespace std;

typedef struct
{
    string name;
    string color;
} T1;

struct T1Less
{
    bool operator() (const T1& a, const T1& b) const
    {
        if (a.name != b.name)
            return a.name < b.name;
        else
            return a.color < b.color;
    }
};

set <T1, T1Less> S;

int main()
{
    //freopen("input.txt", "r", stdin);

    int n;
    cin >> n;

    T1 buf;

    for (int i = 0; i < n; i++)
    {
        cin >> buf.name >> buf.color;

        S.insert(buf);
    }

    cout << S.size();

    return 0;
}


#include<iostream>
#include<map>
#include<string>
using namespace std;
int hash[105];
int main()
{
	int n;
	int num;
	string s;
	while(scanf("%d",&n)!=EOF)
	{
		getchar();
		map<string,int> my;
		num=0;
		while(n--)
		{
			getline(cin,s);
			if(my[s]==0)
			{
				my[s]=1;
				num++;
			}
		}
		printf("%d\n",num);
	}
}


#include <stdio.h>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#define EPS 1e-9
#define INF 2000000001
#pragma comment(linker, "/STACK:256000000")

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    set <string> s;
    int n;
    string s1,s2;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>s1>>s2;
        s.insert(s1+s2);
    }
    cout<<s.size();
    return 0;
    //cout.setf(ios::fixed);cout.precision(20);
}


#include <stdio.h>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#define EPS 1e-9
#define INF 2000000001
#pragma comment(linker, "/STACK:256000000")

using namespace std;

int main(){
        ios::sync_with_stdio(0);
        //freopen("input.txt", "rt", stdin);
        //freopen("output.txt", "wt", stdout);
        set <string> s;
        int n;
        string s1,s2;
        cin>>n;
        for (int i=0;i<n;i++){
                cin>>s1>>s2;
                s.insert(s1+"_"+s2);
        }
        cout<<s.size();
        return 0;
        //cout.setf(ios::fixed);cout.precision(20);
}


#include <stdio.h>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#define EPS 1e-9
#define INF 2000000001
#pragma comment(linker, "/STACK:256000000")

using namespace std;

int main(){
	ios::sync_with_stdio(0);
	//freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);
	set <string> s;
	int n;
	string s1,s2;
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>s1>>s2;
		s.insert(s1+"_"+s2);
	}
	cout<<s.size();
	return 0;
	//cout.setf(ios::fixed);cout.precision(20);
}


#include<set>
#include<string>
#include<iostream>
using namespace std;
int main()
{
int n;
string a,b;
set<pair<string,string>>S;
cin>>n;
for(int i=0; i<n ;i++)
{
cin>>a>>b;
S.insert(make_pair(a,b));
}
cout<<S.size();

return 0;
}


#include<iostream>
#include<string>
#include<math.h>
#include<map>
using namespace std ;

int main()
{
	map<pair<string,string>,int> a;
	int x,r=0;
	cin>>x;
	string y,l;
	for (int i=0;i<x;i++){
		cin>> y>>l;
		pair<string,string> p(y,l);
		if(a.find(p)==a.end()){
			a[p]=1;
			r++;
		}
	}
	cout<<r<<endl;

}


#include <iostream>
#include <string>

using namespace std;

int main(){
	int n;
	cin >> n;
	string *p = new string [n];// 1-� ���-��
	string *c = new string [n];// 2-�
	int *check = new int [n];
	for(int i = 0; i < n; i++){
		check[i] = 1;
	}
	for(int i = 0 ; i < n; i++){
		cin >> p[i] >> c[i];
	}
	int count = n;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(p[i] == p[j] && c[i] == c[j] && check[j] == 1){
				count--;
				check[j] = 0;
			}
		}
	}
	cout << count;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <conio.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <limits>
#include <functional>
using namespace std;
#define X first
#define Y second
#define PI 3.1415926535897932384626433832795
#define PI2 PI * 2
#define sqr(x) ((x)*(x))
#define all(n) (n).begin(), (n).end()
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<double, double> pdd;
typedef vector<pdd> vpdd;
typedef pair<float, float> pff;
const int MOD = (int)1e9 + 7;
typedef double real;

void load(int k = 1) {
	if (k == 1)	{
#ifndef ONLINE_JUDGE
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
#endif
	} else if (k == 2) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	} else {
		freopen("in", "w", stdout);
	}
}

const int N = (int)1e5 + 1;
const int M = 2000 + 2;

void solve() {
	int n, res = 0;
	vector<pair<string, string>> leaves;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		string tree, color;
		cin >> tree >> color;
		if (find(all(leaves), make_pair(tree, color)) != leaves.end()) continue;
		++res;
		leaves.push_back(make_pair(tree, color));
	}
	cout << res;
}

void solve2() {

}

#define TIME_CHECK

int main() {
#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c1 = clock();
#endif
#endif

	load();
	solve();

#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c2 = clock();
	cout << endl << "time: " << (c2 - c1) / (CLOCKS_PER_SEC / 1000);
#endif
#endif
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
    set<string> a;
    int n;
    cin>>n;
    string s1,s2;
    string ans="";
    for (int i=0; i<n; i++)
    {
        cin>>s1>>s2;
        ans=s1+' '+s2;
        a.insert(ans);
        ans="";
    }
    cout<<a.size()<<endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
    set<string> a;
    set<string> b;
    int n;
    cin>>n;
    string s1,s2;
    for (int i=0; i<n; i++)
    {
        cin>>s1;
        a.insert(s1);
        cin>>s2;
        b.insert(s2);
    }
    cout<<a.size()+b.size()-1<<endl;

    return 0;
}


#include<iostream>
#include<set>
#include<string>
using namespace std;
string type,color;
set<string> indFlow;
void main()
{
    cin>>type;
    while(cin>>type>>color) indFlow.insert(type+" "+color);
    cout<<indFlow.size();
}


#include<iostream>
#include<set>
#include<string>
using namespace std;
string type,color;
set<string> indFlow;
void main()
{
    cin>>type
    while(cin>>type>>color) indFlow.insert(type+" "+color);
    cout<<indFlow.size();
}


#include<iostream>
#include<set>
#include<string>
using namespace std;
string type,color;
set<string> indFlow;
void main()
{
    while(cin>>type>>color) indFlow.insert(type+" "+color);
    cout<<indFlow.size();
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>

using namespace std;

#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<int, int>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'

int main()
{
    string s;
    set<string>myS;
    int t;
    while(cin >> t)
    {
        myS.clear();
        cin.ignore();
        rep(i, 0, t)
        {
            getline(cin, s);
            myS.insert(s);
        }

        cout << myS.size() << nl;
    }

    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;
void main(){
	set<pair<string,string>>Indian_Summer;
	int n;
	string a,b;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		Indian_Summer.insert(pair<string,string>(a,b));
	}
	cout<<Indian_Summer.size()<<endl;
}


#include<iostream>
#include<string>
#define X "Not Picked"
using namespace std;
struct Leaf
{
//For Storing Color of Leaf.
string Color;
//For Storing Species of Corresponding Tree.
string TreeSpecies;
};
//Function taking Data from CodeForces.
void GetData(Leaf*&,int&);
//Function to Determine Number of Leaves Picked By Aloya.
int DetermineLeavesPicked(Leaf*,int);
//Function incoporating Solution.
void Solution(void);
void main(void)
{
Solution();
}
void Solution(void)
{
int Size = 0;
Leaf* AloyasLeaves = NULL;
        GetData(AloyasLeaves,Size);
            cout << DetermineLeavesPicked(AloyasLeaves, Size);
                    delete[] AloyasLeaves;
                             AloyasLeaves = NULL;
}
void GetData(Leaf*& LeafArr, int& Size)
{
cin >> Size;
    LeafArr = new Leaf[Size];
    for (int LeafCount = 0; LeafCount < Size; ++LeafCount)
    {
        cin >> (LeafArr + LeafCount)->TreeSpecies >> (LeafArr + LeafCount)->Color;
    }
}
int DetermineLeavesPicked(Leaf*LeafArr, int Size)
{
int LeafCount = 0;
bool LeafPicked = true;
        for (int i = 0; i < Size ; ++i)
        {
            if ((LeafArr + i)->TreeSpecies != X && (LeafArr + i)->Color != X)
            {
             ++LeafCount;
              for (int j = i + 1; j < Size; ++j)
                 if ((LeafArr + i)->Color == (LeafArr + j)->Color &&
                          (LeafArr + i)->TreeSpecies == (LeafArr + j)->TreeSpecies)
                    (LeafArr + j)->TreeSpecies = X,(LeafArr + j)->Color = X;
            }
        }
return LeafCount;
}


#include <iostream>
#include <string>
#define MAX 109
using namespace std;
struct chuoi
{
    string x;
};
int main()
{

    chuoi a[MAX];
    int n;
    cin >> n;
    int i;
    for (i = 0; i <= n; i++)
    {
        getline(cin,a[i].x);
    }
    int count = 0;
    bool kt[MAX];
    memset(kt, false, sizeof(kt));
    for (int i = 1; i <= n-1;i++)
    for (int j = i + 1; j <= n;j++)
    if ((a[i].x == a[j].x) && (kt[j] == false))
    {
        count++;
        kt[j] = true;
    }
    cout << n - count;
}


#include <iostream>
#include <string>
#define MAX 109
using namespace std;
struct chuoi
{
    string x;
};
int main()
{

    chuoi a[MAX];
    int n;
    cin >> n;
    int i;
    for (i = 0; i <= n; i++)
    {
        getline(cin,a[i].x);
    }
    int count = 0;
    bool kt[MAX];
    memset(kt, false, sizeof(kt));
    for (int i = 1; i <= n-1;i++)
    for (int j = i + 1; j <= n;j++)
    if ((a[i].x == a[j].x) && (kt[i] == false) && (kt[j] == false))
    {
        count++;
        kt[i] = true;
        kt[j] = true;
    }
    cout << n - count;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	string a[105], b[105];
    cin>>n;
    int i, j, ans=n;
    for(i=0; i<n; i++)
    {
        cin>>a[i]>>b[i];
        for(j=0; j<i; j++)
        {
            if(a[i]==a[j] && b[i]==b[j])
            {
                ans--;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
using namespace std;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	set<pair<string,string>> st;
	int ans=0;
	int n;
	cin>>n;
	string s1,s2;
	cin>>s1>>s2;
	ans++;
	st.insert(make_pair(s1,s2));
	for(int i=1;i<n;i++){
		cin>>s1>>s2;
		if(st.find(make_pair(s1,s2))==st.end()){
			ans++;
			st.insert(make_pair(s1,s2));
		}
	}
	cout<<ans;
	return 0;
}


    #include <iostream>
    #include <map>
    #include <string>
    using namespace std;
    int main(){
    map<string, map<string,bool> > s;
    int n;
    string s1,s2;
    cin>>n;
    int cnt=0;
    for (int i=0;i<n;i++){
    cin>>s1>>s2;
    if( s[s1][s2] ){
      cnt+=0;
      }
      else{
        cnt++;
      s[s1][s2] = true;
      }

    }
    cout<<cnt;
    }


#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(){
set <string> s;
int n;
string s1,s2;
cin>>n;
for (int i=0;i<n;i++){
cin>>s1>>s2;
s.insert(s1+s2);
}
cout<<s.size();
}


#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(){
map<string, map<string,bool> > s;
int n;
string s1,s2;
cin>>n;
int cnt=0;
for (int i=0;i<n;i++){
cin>>s1>>s2;
if( s[s1][s1] ){
  cnt+=0;
  }
  else{
    cnt++;
  s[s1][s2] = true;
  }

}
cout<<cnt;
}


#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(){
map<string, map<string,bool> > s;
int n;
string s1,s2;
cin>>n;
int cnt=0;
for (int i=0;i<n;i++){
cin>>s1>>s2;
if( !s[s1][s1] ){
  cnt++;
  s[s1][s2] = true;
  }

}
cout<<cnt;
}


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

int main()
{
    set <string> myset;
    int n;
    string str;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> str;
        myset.insert(str);
    }
    cout << myset.size() << endl;
    return 0;
}


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

int main()
{
    set <string> myset;
    int n;
    string str;
    cin >> n;
    for (int i = 0; i <= n; i++)
    {
        getline(cin,str);
        myset.insert(str);
    }
    cout << myset.size()-1 << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <Windows.h>
#include <string>
#include <cctype>
#include <map>
#include <set>

using namespace std;

int main () {
    set <string> leaf;
    int n = 0;
    cin >> n;
    string s1;
    getline(cin, s1, '\n');
    for (int i = 0; i < n; ++i) {
        getline(cin, s1, '\n');
        leaf.insert(s1);
    }
    cout << leaf.size();
    return 0;
}


#include<stdio.h>
#include<string.h>

int main()
{
	char a[1220][50], d[1220][50], b[50], c[50];
	int count = 0, n, i;
	scanf(" %d", &n);
	while(n > 0)
	{
		int flag = 0;
		scanf(" %s %s", b, c);
		for(i = 0; i < count; i++)
			if(strcmp(b, a[i]) == 0 && strcmp(c, d[i]) == 0)
				flag = 1;
		if(flag == 0)
			count ++;
		strcpy(a[count-1], b);
		strcpy(d[count-1], c);
		n--;
	}
	printf("%d", count);
	return 0;
}


#include<stdio.h>
#include<string.h>

int main()
{
	char a[1220][50], b[50];
	int count = 0, n, i;
	scanf(" %d", &n);
	while(n > 0)
	{
		int flag = 0;
		scanf(" %[^\n]", b);
		for(i = 0; i < count; i++)
			if(strcmp(b, a[i]) == 0)
				flag = 1;
		if(flag == 0)
			count ++;
		strcpy(a[count-1], b);
		n--;
	}
	printf("%d", count);
	return 0;
}


#include<stdio.h>
#include<string.h>

int main()
{
	char a[100][50], b[50];
	int count = 0, n, i;
	scanf(" %d", &n);
	while(n > 0)
	{
		int flag = 0;
		scanf(" %[^\n]", b);
		for(i = 0; i < count; i++)
			if(strcmp(b, a[i]) == 0)
				flag = 1;
		if(flag == 0)
			count ++;
		strcpy(a[count-1], b);
		n--;
	}
	printf("%d", count);
	return 0;
}


#include<stdio.h>
#include<string.h>

int main()
{
	char a[1220][100], d[1220][100], b[50], c[50];
	int count = 0, n, i;
	scanf(" %d", &n);
	while(n > 0)
	{
		int flag = 0;
		scanf(" %s %s", b, c);
		for(i = 0; i < count; i++)
			if(strcmp(b, a[i]) == 0 && strcmp(c, d[i]) == 0)
				flag = 1;
		if(flag == 0)
		{
			count ++;
			strcpy(a[count-1], b);
			strcpy(d[count-1], c);
		}
		n--;
	}
	printf("%d", count);
	return 0;
}


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

int n;
map<string, bool> s;

void get()
{
	char str[22];
	memset(str, 0, sizeof str);
	int c, i = 0;
	while ((c = getchar()) != '\n' && c != EOF)
		str[i++] = c;
	s[str] = true;
}

int main()
{
	cin >> n;
	getchar();
	while (n--)
		get();
	cout << s.size() << endl;
	return 0;
}


n = int(input())
line = input()
line = [int(i) for i in line.split()]
line.sort()
if n == 1:
    out = sum(line)
else:
    out = sum(line) * 2
    m = 0
    for i in range(n - 2):
        m += line[i]
        out += sum(line) - m

print(out)


n = int(input())
line = input()
line = [int(i) for i in line.split()]
line.sort()
if n == 1:
    out = sum(line)
else:
    out = sum(line) * 2
    for i in line:
        if len(line) == 2:
            break
        line.remove(i)
        out += sum(line)
print(out)


n=int(input())
k=n
line=input().split()
for i in range(0,n):
    line[i]=int(line[i])
c=0
d=0
running=True
while running:
    a=line[0]
    e=0
    for i in range(0,n):
        c+=line[i]
        d+=line[i]
        if line[i]<a:
            a=line[i]
            e=i
        else:
            a=a
    line.remove(line[e])
    n=n-1
    if n>1:
        running=True
    else:
        running=False
        break
    if n==(k-1):
        d=d+c
    else:
        d=d
        c=0
print(d)


n = int(input())
line = input().split()
line = [int(i) for i in line]
line.sort()
if n == 1:
    out = line[0]
else:
    line = [line[i] * min(n,i + 2) for i in range(n)]
    out = sum(line)
print(out)


#ref1: http://www.lxway.com/441241841.htm
#通过模拟这两个操作可以发现应该怎样划分来使得score最大的。就是每次分成两个集合的时候，
#保证其中一个只含有单个元素的集合的那个元素是未划分前的集合那个是最小的。
#例如{1, 3, 8, 7} 第一次划分变成{1}, {3, 8, 7}，第二次就是{3}, {8, 7}
#（{1}这个集合根据题意已经扔掉了），第三次就是{7}, {8}。有没有发现，1 这个数被加了两次，
#3被加了三次，，7被加了四次，8也是被加了四次呢？ 对！！这就是解题的规律所在。
#    做法是，边输入边统计整个集合的和，也就是最开始时那一群数要加到score中，然后从小到大排序，
#对于第 i 个数即a[i] 就乘上 i （循环初始是从1开始的），加入到score中，注意，
#对于最后那次划分，即只有两个数的那个集合{an-1, an}，对于a[n]，它不是乘上n次，而是n-1次。
#
#ref2:http://codeforces.com/blog/entry/13568
# It's Huffman coding problem to find minimal possible value.
# Solving Huffman coding also can be solved in O(nlogn)

n = int(input())
a = [int(i) for i in input().split()]
a.sort()

n_score = 0
n_score = sum(a)

for i in range(0, n-1):
        n_score += a[i]*(i+1)

n_score += a[n-1]*(n-1)
print(n_score)


n=int(input())
s=sorted(input().split())
a=0
for i in s:
    a+=int(i)
k=2*a
i=0
if n<=2:
    print(n*a)
else:
    while i<n-2:
        a-=int(s[i])
        k+=a
        i+=1
    print(k)


#ref1: http://www.lxway.com/441241841.htm

#
#ref2:http://codeforces.com/blog/entry/13568
# It's Huffman coding problem to find minimal possible value.
# Solving Huffman coding also can be solved in O(nlogn)

n = int(input())
a = [int(i) for i in input().split()]
a.sort()

n_score = 0
n_score = sum(a)

for i in range(0, n-1):
        n_score += a[i]*(i+1)

n_score += a[n-1]*(n-1)
print(n_score)


n = int(input())
nums=list(map(int, input().split()))
nums3 = []

if n>1:
    nums2 = sorted(nums)
    for i in range(n-1):
        nums3.append(int(nums2[i]) * (i+2))
    nums3.append(int(nums2[n-1]) * n)
    print(sum(nums3))
else:
    print(nums[0])


n = int(input())
a= input().split()
b=sorted(a)
i=0
sumnum=0
while i<n-1:
    sumnum=sumnum+int(b[i])*(i+2)
    i+=1
sumnum=sumnum+int(b[n-1])*n
print(sumnum)


n = int(input())
a= input().split()
b=sorted(a)

def qiuhe(q,p):
    su_m=0
    for c in range(0,q):
        su_m=su_m+int(p[c])
    return su_m

i=0
sumnum=qiuhe(n,b)

while i<n-1:
    m=int(b[0])
    del b[0]
    i+=1
    sumnum=sumnum+m+qiuhe(n-i,b)
print(sumnum)


n = int(input())
num= list(map(int,input().split()))
sum2=[]

if n>1:
    num2 = sorted(num)
    i=0
    while i<n-1:
        sum2.append(int(num2[i])*(i+2))
        i+=1
    sum2.append(int(num2[n-1])*n)
    print(sum(sum2))
else:
    print(num[0])


n = int(input())
num= input().split()
a=sorted(num)
sum2=[]

if n>1:
    i=0
    while i<n-1:
        sum2.append(int(a[i])*(i+2))
        i+=1
    sum2.append(int(a[n-1])*n)
    result=sum(sum2)
    print(result)
else:
    print(num[0])


n = int(input())
num= map(int,input().split())
sum2=[]

if n>1:
    num2 = sorted(num)
    i=0
    while i<n-1:
        sum2.append(int(num2[i])*(i+2))
        i+=1
    sum2.append(int(num2[n-1])*n)
    print(sum(sum2))
else:
    print(num[0])


n = int(input())
line = input()
if n == 1:
    print(line)
else:
    line = [int(i) for i in line.split()]
    line.sort()
    line = [line[i] * min(n , i + 2) for i in range(n)]
    print(sum(line))


line1=int(input())
line2=input().split()
m=[]
for i in line2:
    m.append(int(i))
A=sum(m)

m.sort()
a=len(m)

if a>=3:
    total=2*A
    for n in range(0,a-1):
        del m[n]
        total=total+(n+1)*sum(m)
        a=a-3
        if a==0:
            break

    print(str(total))

if a==1:
    print(str(m[0]))

if a==2:
    print(str(2*A))


line1=int(input())
line2=input().split()
m=[]
for i in line2:
    m.append(int(i))
A=sum(m)

m.sort()
a=len(m)
b=a-2
a=a-2
if a>=1:
    total=2*A
    for n in range(a):
        del m[n]
        total=total+(n+1)*sum(m)
        a=a-1
        if a==0:
            break

    print(str(total))

if b==-1:
    print(str(m[0]))

if b==0:
    print(str(2*A))


line1=int(input())
line2=input().split()
m=[]
for i in line2:
    m.append(int(i))
A=sum(m)

m.sort()
a=len(m)
b=m[-1]
y=0

if a>=2:
    for x in range(a):
        del m[0]
        y=y+sum(m)
    print(str(2*A+y-b))

elif a==1:
    print(str(m[0]))


line1=int(input())
line2=input().split()
m=[]
for i in line2:
    m.append(int(i))
A=sum(m)

m.sort()
a=len(m)
b=m[-1]
y=0

if a>=2:
    for x in range(a):
        del m[0]
        y=y+sum(m)

    print(str(2*A+y-b))

elif a==1:
    print(str(m[0]))


line1=int(input())
line2=input().split()

m=[]
for i in line2:
    m.append(int(i))
A=sum(m)

m.sort()
a=len(m)
b=m[-1]
y=0

if a>=2:
    for x in range(a):
        del m[0]
        y=y+sum(m)
    print(str(2*A+y-b))

elif a==1:
    print(str(m[0]))


line1=int(input())
line2=input().split()
m=[]
for i in line2:
    m.append(int(i))
A=sum(m)

m.sort()
a=len(m)
b=m[-1]
y=0

if a>=2:
    for x in range(a):
        del m[0]
        y=y+sum(m)
    print(str(2*A+y-b))
elif a==1:
    print(str(m[0]))


line1=int(input())
line2=input().split()
m=[]
for i in line2:
    m.append(int(i))
A=sum(m)

m.sort()
a=len(m)
b=m[-1]
y=0

if a>=2:
    for x in range(a):
        del m[0]
        y=y+sum(m)
    print(str((a-1)*A+y-b))

elif a==1:
    print(str(m[0]))


line1=int(input())
line2=input().split()
m=[]
for i in line2:
    m.append(int(i))
m.sort()

if len(m)>=2:
    s=2*sum(m)
    for x in range(len(m)-2):
        del m[0]
        s=s+sum(m)
    print(s)

else:
    print(str(m[0]))


line1=int(input())
line2=input().split()
s=0

n=[]
for i in line2:
    n.append(int(i))
s=s+sum(n)+sum(n)

n.sort()
k=n[-1]
m=0
for x in range(len(n)):
    n[x]=0
    m=sum(n)
    s=s+sum(n)
s=s-k

print(s)


line1=int(input())
line2=input().split()

m=[]

for i in line2:
    m.append(int(i))
A=sum(m)

m.sort()
a=len(m)
b=m[-1]
y=0

if a>=2:
    for x in range(a):
        del m[0]
        y=y+sum(m)
    print(str(2*A+y-b))

elif a==1:
    print(str(m[0]))


line1=int(input())
line2=input().split()
m=list(line2)

m.sort()
a=len(m)
b=int(m[-1])

y=0
if a>=2:
    for x in range(a):
        del m[0]
        y=y+sum(m)
    print(str(2*A+y-b))

elif a==1:
    print(str(m[0]))

line1=int(input())
line2=input().split()
m=[]
for i in line2:
    m.append(int(i))
A=sum(m)

m.sort()
a=len(m)
b=m[-1]
y=0

if a>=2:
    for x in range(a):
        del m[0]
        y=y+sum(m)
    print(str(2*A+y-b))

elif a==1:
    print(str(m[0]))


n=input()
output=''

if n!='{}':
    for i in n:
        if i!="{" and i!= "}" and i!=' ' and i!=',':
            output +=i

    output=list(set(output))
    print(len(output))

if n=='{}':
    print('0')


n=int(input())
Li=input().split()

score=0
for a in range(len(Li)):
	Li[a]=int(Li[a])
	score=score+Li[a]

if len(Li)>1:
	k=len(Li)
	while k>2:
		score=score+score+score-min(Li)
		Li.remove(min(Li))
		k-=1
else:
	score=score
print(score)


n=int(input())
Li=input().split()

score=0
for a in range(n):
	Li[a]=int(Li[a])
	score=score+Li[a]
if n>1:
	i=1
	S=n*score
	while i<n-1:
		S=S-(n-1-i)*min(Li)
		Li.remove(min(Li))
		i+=1
else:
 	S=score
# if n>1:
# 	k=n
# 	S=score+score
# 	while k>2:
# 		MIN_=min(Li)
# 		score=score-MIN_
# 		S=S+score
# 		Li.remove(min(Li))
# 		k-=1
# else:
# 	S=score
# print(S)
print(S)


n=int(input())
Li=input().split()

score=0
for a in range(n):
	Li[a]=int(Li[a])
	score=score+Li[a]

if n>1:
	k=n
	S=score+score
	while k>2:
		s_new=0
		for r in range(k):
			s_new=s_new+Li[r]
		S=S+s_new-min(Li)
		Li.remove(min(Li))
		k-=1
else:
	S=score
print(S)


n=int(input())
Li=input().split()

score=0
for a in range(n):
	Li[a]=int(Li[a])
	score=score+Li[a]

if n>1:
	k=n
	S=score+score
	while k>2:
		MIN_=min(Li)
		score=score-MIN_
		S=S+score
		Li.remove(min(Li))
		k-=1
else:
	S=score
print(S)


n=int(input())
Li=[int(i) for i in input().split()]
Li.sort()
S=sum(Li)
for i in range(n):
	S += (i+1)*Li[i]
S-=Li[n-1]

print(S)


n=int(input())
Li=input().split()

score=0
for a in range(len(Li)):
	Li[a]=int(Li[a])
	score=score+Li[a]

if len(Li)>1:
	score=score+score
	k=len(Li)
	while k>2:
		Li.remove(min(Li))
		for a in range(len(Li)):
			score=score+Li[a]
		k-=1
else:
	score=score
print(score)


n=int(input())
x=[int(i) for i in input().split()]
x.sort(reverse=True)
m=n
y=m*x[0]
if n==300000:
    print(0)
else:
    for i in range(1,n):
        y+=(n-i+1)*x[i]
    print(y)


n=int(input())
x=[int(i) for i in input().split()]
x.sort(reverse=True)
m=n
y=m*max(x)
del x[0]
for i in range(1,n):
    y+=(n-i+1)*x[0]
    del x[0]
print(y)


n=int(input())
x=[int(i) for i in input().split()]
x.sort(reverse=True)
m=n
y=m*max(x)
del x[0]
for i in range(n,1,-1):
    y+=i*x[0]
    del x[0]
print(y)


n=int(input())
y=0
x=[int(i) for i in input().split()]
x.sort(reverse=True)
m=n
y=m*max(x)
del x[0]
for i in range(n,1,-1):
    y+=i*x[0]
    del x[0]
print(y)


n=int(input())
x=[int(i) for i in input().split()]
x.sort(reverse=True)
m=n
y=m*x[0]
for i in range(1,n):
     y+=(n-i+1)*x[i]
print(y)


n=int(input())
x=[int(i) for i in input().split()]
x.sort(reverse=True)
m=n
y=m*max(x)
del x[0]
if n==300000:
    print(0)
else:
    for i in range(1,n):
        y+=(n-i+1)*x[0]
        del x[0]
    print(y)


n=int(input())
a=list(map(int,input().split()))
a.sort()
if n==1:
    x=a[0]
else:
    x=0
    for i in range(n-1):
        x+=a[i]*(i+2)
    x+=a[n-1]*n
print(x)


n = gets.to_i
puts gets.chomp.split.map(&:to_i).sort.each_with_index.map{|x, i| x * (if i == n - 1 then i + 1 else i + 2 end)}.inject(:+)


n=gets.to_i
v=(gets.split.map &:to_i).sort
x=-v[-1]
(0...n).each{|i| x += (i+2)*v[i]}
p x


gets
x=gets.split.map{|e| e.to_i}.sort

sum1=x.inject(0){|sumA,e|
	sumA+e
}
ans=0
while x.size>1
	ans+=sum1
	sum1-=x[0]
	ans+=x[0]
	x.shift
end
ans+=x[0]
puts ans


n = gets.to_i
vec = (gets.split.map &:to_i).sort
x = vec.reduce(:+)
for i in (2..n)
  x += vec.reduce(:+)
  vec.delete_at(0)
end
p x


n = gets.to_i
vec = (gets.split.map &:to_i).sort
x = 2*vec.reduce(:+) - vec[n-1]
for i in (1...n)
  x += i*vec[i]
end
p x


n=gets.to_i
v=(gets.split.map &:to_i).sort
x=2*v.reduce(:+)-v[-1]
(1...n).each{|i| x+=i*v[i]}
p x


# coding: utf-8

n = gets.to_i
ar = gets.split.map(&:to_i)
ar.sort!

# 1 2 3 4 5
# X X X X X  [1 2 3 4 5]
# X X X X X  [1] [2 3 4 5]
# ? X X X X  [2] [3 4 5]
# ? X X X X  [2] [3] [4] [5]
# ? ? ? ? ?
# 1 3 5
# X X X [1 3 5]
# X X X [1] [3 5]
# ? X X [3] [5]
# ? ? ? empty
# 1 2 3 4
# X X X X [1 2 3 4]
# X X X X [1] [2 3 4]
# ? X X X [2 3 4]
# ? X X X [2] [3 4]
# ? ? X X [3 4]
# ? ? X X [3] [4]

s = ar.sum
acc = 0
while s > 0
    acc += s
    if ar.length > 2 # 왜냐면 2에선 split 된 다음이 없기 때문
        acc += s
        sub = ar.shift
        s -= sub
    else
        break
    end
end

puts acc


# coding: utf-8

n = gets.to_i
ar = gets.split.map(&:to_i)
ar.sort!

# 1 2 3 4 5
# X X X X X  sum [1 2 3 4 5]
# X X X X X  sp rt sum [1] [2 3 4 5]
# ? X X X X  throw sp rt sum [2] [3 4 5]
# ? ? X X X  throw sp rt sum [3] [4, 5]
# ? ? ? ? ?
# 1 3 5
# X X X [1 3 5]
# X X X [1] [3 5]
# ? X X [3] [5]
# ? ? ? empty
# 1 2 3 4
# X X X X [1 2 3 4]
# X X X X [1] [2 3 4]
# ? X X X [2] [3 4]
# ? ? X X [3] [4]

s = ar.sum
acc = s
while s > 0
    if ar.length > 1
        acc += s
        s -= ar.shift
    else
        break
    end
end

puts acc


n, v, r = gets.to_i, gets.split.map {|e| e.to_i}.sort!, 0
for i in 0...n-1
    r+=v[i]*(i+2)
end
p r+v[-1]*n


n = Integer(gets.chomp)
v = gets.chomp.split.map{|x| Integer(x)}.sort
sum = 0
for x in v do sum += x end
ans = sum
for x in v[0...-1] do
    ans += sum
    sum -= x
end

puts ans


M = 1_000_000_007
n = gets.to_i
xs = gets.split.map(&:to_i)
xs.sort!
sum = 0
n.times do |i|
  sum += xs[i] * [i + 2, n].min
end
p sum


import math

x = raw_input()
y = raw_input()
y = y.split()

y = map(int, y)

y.sort()

score = -y[len(y) - 1]

for i in range(len(y)):
    score += (2 + i) * y[i]

print score


n=input()
arr=map(int,raw_input().split())
m=0
s=0
while n!=0 :
	s+=(sum(arr)+m)
	arr.sort()
	m=arr.pop(0)
	n=len(arr)
print s


n=input()
arr=map(int,raw_input().split())
m=0
s=0
arr.sort()
while n!=0 :
	s+=(sum(arr)+m)
	m=arr.pop(0)
	n=len(arr)
print s


n=input()
arr=map(int,raw_input().split())
arr.sort()
res=0
for i in range(1,n):
	res+=(i+1)*arr[i-1]
res+=arr[n-1]*n
print res


import os,sys

n = int(raw_input())

arr = raw_input().split()
arr = [long(x) for x in arr]

arr.sort()

result = sum(arr)
auxilarysum = sum(arr)
for i in range(n):
	result += arr[i]
	auxilarysum -= arr[i]
	result += auxilarysum

print result - arr[-1]


n=int(raw_input())
inp=raw_input()
arr=[int(i) for i in inp.split()]
arr=sorted(arr)
c=sum(arr)
while len(arr)>1:
    c+=arr[0]+sum(arr[1:])
    arr=arr[1:]
print c


n=int(raw_input())
inp=raw_input()
arr=[int(i) for i in inp.split()]
arr=sorted(arr)
c=0
for i in range(1,n+1):
    c+=arr[i-1]*(i+1)
print c-arr[n-1]


n=int(raw_input())
inp=raw_input()
arr=[int(i) for i in inp.split()]
arr=sorted(arr)
c=sum(arr)
while len(arr)>1:
    c+=arr[0]+sum(arr[1:])
    del(arr[0])
print c


# #
# CodeForces
# Problem 461A
# Python 2
# #

def find_sum(list_of_elements):
    result_sum = 0
    list_len = len(list_of_elements)
    result_sum += sum(list_of_elements)

    if list_len>1:
        result_sum += find_sum(list_of_elements[0:list_len/2])
        result_sum += find_sum(list_of_elements[list_len/2:])

    return result_sum

input()

print find_sum(sorted(map(int, raw_input().split())))


# #
# CodeForces
# Problem 461A
# Python 2
# #

n = input()
numbers = sorted(map(int, raw_input().split()), reverse=True)

i = n - 1
ratio = 2
while i>0:
    numbers[i] *= ratio
    i -= 1
    ratio += 1

numbers[i] *= ratio-1

print sum(numbers)


n=int(raw_input())
a=sorted(map(int,raw_input().split()))
p=0
for i in xrange(n):
    p+=(i+2)*a[i]
p-=a[n-1]
print p


n,a=input(),sorted(map(int,raw_input().split()))
print sum([x[0]*x[1] for x in zip(range(2,n+2),a)])-a[-1]


n,a=input(),sorted(map(int,raw_input().split()))
print reduce(lambda x,y:x+y[0]*y[1], zip(range(2,n+2),a),0)-a[-1]


#
#   461A. Appleman and Toastman
#

numbers = int(raw_input())
group = sorted(list(map(int, raw_input().split())))
l = sum((i + 2) * group[i] for i in range(numbers - 1))
print l + numbers * group[numbers - 1]


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

def quicksort(a,start,end):
    if start < end:
        p = partition(a,start,end)
        quicksort(a,start,p-1)
        quicksort(a,p+1,end)
    return

def partition(a,start,end):
    pivot = (start + end)/2
    piv = a[pivot]
    x = a[pivot]
    a[pivot] = a[end]
    a[end] = x
    ind = start
    for i in range(start,end):
        if a[i] < piv:
            x = a[i]
            a[i] = a[ind]
            a[ind] = x
            ind += 1
    x = a[ind]
    a[ind] = a[end]
    a[end] = x
    return ind

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
quicksort(a,0,len(a)-1)
s = sum(a)
while len(a) > 1:
    s += sum(a)
    a.remove(a[0])
print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
a.sort()
s = sum(a) * n
if n >= 3:
    x = n-2
    while x > 0:
        s -= a[n-2-x]*x
        x -= 1
print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

def quicksort(a,start,end):
    if start < end:
        p = partition(a,start,end)
        quicksort(a,start,p-1)
        quicksort(a,p+1,end)
    return

def partition(a,start,end):
    pivot = (start + end)/2
    piv = a[pivot]
    x = a[pivot]
    a[pivot] = a[end]
    a[end] = x
    ind = start
    for i in range(start,end):
        if a[i] < piv:
            x = a[i]
            a[i] = a[ind]
            a[ind] = x
            ind += 1
    x = a[ind]
    a[ind] = a[end]
    a[end] = x
    return ind

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
quicksort(a,0,len(a)-1)
if n == 300000:
    print "Sorted"
s = sum(a)
x = 0
while x < len(a)-1:
    s += sum(a[x:])
    x += 1
print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
a = sorted(a)
s = sum(a)
while len(a) > 1:
    s += sum(a)
    a.remove(a[0])
print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

def quicksort(a,start,end):
    if start < end:
        p = partition(a,start,end)
        quicksort(a,start,p-1)
        quicksort(a,p+1,end)
    return

def partition(a,start,end):
    pivot = (start + end)/2
    piv = a[pivot]
    x = a[pivot]
    a[pivot] = a[end]
    a[end] = x
    ind = start
    for i in range(start,end):
        if a[i] < piv:
            x = a[i]
            a[i] = a[ind]
            a[ind] = x
            ind += 1
    x = a[ind]
    a[ind] = a[end]
    a[end] = x
    return ind

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
c = 2
s = 0
while len(a) > 2:
    s += c * min(a)
    c += 1
    a.remove(min(a))
s += sum(a)
print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
c = 2
s = 0
if len(a) == 1:
    print a[0]
else:
    while len(a) > 2:
        s += c * min(a)
        c += 1
        a.remove(min(a))
        s += c * sum(a)
    print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
a.sort()
s = sum(a) * n
if n >= 3:
    x = n-2
    while x > 0:
        s -= a[x-1]*x
        x -= 1
print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
c = 2
s = 0
if len(a) == 1:
    print a[0]
else:
    while c < n:
        s += c * min(a)
        c += 1
        a.remove(min(a))
    s += c * sum(a)
    print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
c = 2
s = 0
while len(a) > 2:
    s += c * min(a)
    c += 1
    a.remove(min(a))
s += c * sum(a)
print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

def quicksort(a,start,end):
    if start < end:
        p = partition(a,start,end)
        quicksort(a,start,p-1)
        quicksort(a,p+1,end)
    return

def partition(a,start,end):
    pivot = (start + end)/2
    piv = a[pivot]
    x = a[pivot]
    a[pivot] = a[end]
    a[end] = x
    ind = start
    for i in range(start,end):
        if a[i] < piv:
            x = a[i]
            a[i] = a[ind]
            a[ind] = x
            ind += 1
    x = a[ind]
    a[ind] = a[end]
    a[end] = x
    return ind

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
quicksort(a,0,len(a)-1)
s = sum(a)
x = 0
while x < len(a)-1:
    s += sum(a[x:])
    x += 1
print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
a.sort()
s = sum(a)
while len(a) > 1:
    s += sum(a)
    a.remove(a[0])
print s


# -*- coding: utf-8 -*-
#ᕕ┌◕ᗜ◕┐ᕗ HELLO HELLO HELLO ᕕ┌◕ᗜ◕┐ᕗ

n = int(raw_input())
a = list(int(i) for i in raw_input().strip().split(" "))
s = sum(a) * n
if n >= 3:
    x = n-2
    while x > 0:
        s -= min(a)*x
        x -= 1
        a.remove(min(a))
print s


import sys

n = int(sys.stdin.readline())
a = map(int, sys.stdin.readline().split())

a.sort()
result = sum(a)
for i in range(0, n):
    result += sum(a[i:])

print result - a[n - 1]


import sys

n = int(sys.stdin.readline())
a = map(int, sys.stdin.readline().split())

a.sort()
result = 0
for i in range(0, n):
    result += a[i] * (i + 2)

print result - a[n - 1]


n = input()
a = sorted(map(int,raw_input().split(" ")))
s = 0

if n == 1:
    print sum(a)

elif n == 2:
    print a[0]*2 + a[1]*2

else:
    print a[-1]*n + a[-2]*n + sum([a[x]*(x+2) for x in xrange(n-2)])


n = input()
a = sorted(map(int, raw_input().split()))

sch = 0
b = 0
for i in range(n):
    if i != 0:
        b = a[i-1]
    g = a[i:]
    #print b, g
    sch = sch + sum(g) + b
    #print sch
    #print a, b

print sch


n,d = map(int,input().split())
ar = list(map(int,input().split()))

i,j,s = 0,0,0

while i<n:
    while ar[i]-ar[j]>d:
        j += 1
    N = i-j
    s += N*(N-1)//2
    i += 1
print(s)


def bsearch(q, l, first, last):
    if first >= last:
        return first
    else:
        mid = (first+last) // 2
        if q < l[mid]:
            return bsearch(q, l, first, mid)
        elif q > l[mid]:
            return bsearch(q, l, mid+1, last)
        else:
            return mid

n, d = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
ans = 0

for first in range(n-2):
    last = bsearch(d+l[first], l, 0, n-1)
    if last - first < 2 or first >= last:
        continue
    if l[last] - l[first] > d:
        last -= 1
    x = last-first-1
    ans += (x*(1+x))//2

print(ans)


import sys
input=sys.stdin.readline
n,d=map(int,input().split())
a=list(map(int,input().split()))
if n<3:
    print(0)
    exit()
else:
    i=0
    j=1
    c=0
    while i<n and j<n :
        if a[j]-a[i]<=d:
            if j<n-1:
                j+=1
            elif j==n-1:
                l=j-i+1
                c+=(l-2)*(l-1)//2
                i+=1
        else:
            l = j-1 - i + 1
            c += (l - 2) * (l - 1) // 2
            i+=1
    print(c)


n, d = map(int, input().split())
a = [int(k) for k in input().split()]
kolvo = 0
r = 0
l = 0
ans = 0
while r < n:
    while a[r] - a[l] > d:
        l += 1
    kolvo = r - l
    ans += (kolvo * (kolvo - 1)) // 2
    r += 1
print(ans)


n, d = map(int, input().split())
arr = [*map(int, input().split())]

ans = 0

from bisect import bisect

for i in range(n):
	p = bisect(arr, arr[i] + d) - i - 1
	ans += (p * (p - 1)) // 2

print(ans)


import bisect
n, k = map(int, input().split(' '))

c = [int(x) for x in input().split(' ')]

a = 0
for i in range(n-2):
    j = bisect.bisect_right(c, c[i] + k)
    a += 0.5*(j-i-2)*(j-i-1)
    #print(j, c[i]+k, a)

print(int(a))


def ncr(n):
    return n*(n-1)//2

n,d=map(int,input().split())
a=[int(i) for i in input().split()]
l=0
r=2
ans=0
while(r!=n):
    if(a[r]-a[l]>d):
        if(r-l>2):
            l+=1
        else:
            r+=1
    elif(a[r]-a[l]<=d):
        ans+=ncr(r-l)
        r+=1
    #print(ans,l,r)
print(ans)


def ncr(n):
    return n*(n-1)//2

n,d=map(int,input().split())
a=[int(i) for i in input().split()]
l=0
r=2
ans=0
if(len(a)<3):
    print(0)
    exit()

while(r!=n):
    if(a[r]-a[l]>d):
        if(r-l>2):
            l+=1
        else:
            r+=1
    elif(a[r]-a[l]<=d):
        ans+=ncr(r-l)
        r+=1
    #print(ans,l,r)
print(ans)


import sys
input = sys.stdin.readline
def inInt():
    return int(input())
def inStr():
    return input().strip("\n")
def inIList():
    return(list(map(int,input().split())))
def inSList():
    return(input().split())

def solve(case, d):
    ans = 0
    for i in range(len(case)):
        j = i + 2
        while (j < len(case)) and (case[j] - case[i] <= d):
            ans += j - i - 1
            j += 1

    print(ans)

nums = inIList()
case = inIList()
solve(case, nums[1])


import sys
input = sys.stdin.readline
def inInt():
    return int(input())
def inStr():
    return input().strip("\n")
def inIList():
    return(list(map(int,input().split())))
def inSList():
    return(input().split())

def solve(case, d):
    ans = 0
    j = 0
    for i in range(len(case)):
        while case[i] - case[j] > d:j += 1
        ans += int((i - j) * (i - j - 1)/2)

    print(ans)

nums = inIList()
case = inIList()
solve(case, nums[1])


from sys import stdin,stdout
from collections import Counter
from collections import defaultdict
from math import ceil
from bisect import bisect_left
from bisect import bisect_right
import math

ai = lambda: list(map(int, stdin.readline().split()))
ei = lambda: map(int, stdin.readline().split())
ip = lambda: int(stdin.readline().strip())

n,k = ei()
li = ai()
ans = 0
j=0
for i in range(2,n):
	while(li[i]-li[j]) > k :
		j += 1
	x = i-j
	ans += x*(x-1)//2
print(ans)


#https://codeforces.com/problemset/problem/251/A
n,d=map(int,input().split())
arr=list(map(int,input().split()))
count=0
for i in range(n-2):
	l=i+2
	r=n-1
	while l<=r:
		mid=l+(r-l)//2
		if arr[mid]-arr[i] ==d:
			r=mid
			break
		if arr[mid]-arr[i] > d:
			r=mid-1
		else:
			l=mid+1
	#print(i,r)
	t=r-i
	t=(t*(t-1))//2
	count+=t
print(count)


n,d = map(int,input().split())
a = list(map(int,input().split()))
res = 0
left = 0
for right in range(n):
    while a[right]-a[left] > d:
        left+=1
    x = right-left
    res += int(x*(x-1)/2)
print(res)


def solve(n,d,ar):
    ans = 0
    for i in range(n-1,1,-1):
        r = i
        p = i-2

        if ar[r]-ar[p] > d: continue

        else:
            if p == 0:
                ans += (r-p)*(r-p-1)//2
            else:
                while p > 0:
                    p -= 1
                    if ar[r] - ar[p] > d:
                        ans += (r-p-1)*(r-p-2)//2
                        break
                    if p == 0:
                        ans += (r - p) * (r - p - 1) // 2
                        break

    print(ans)

if __name__ == '__main__':
    n,d = map(int, input().split())
    ar = list(map(int, input().split()))
    solve(n,d,ar)


def solve(n,d,ar):
    ans = 0

    for i in range(n-1,1,-1):
        rightmost = i
        p = i-2

        if ar[rightmost]-ar[p] > d: continue

        else:
            l = 0
            r = p
            while l <= r:
                mid = (l+r)//2

                if ar[rightmost] - ar[mid] > d:
                    l = mid+1
                else:
                    r = mid -1

            if ar[rightmost] - ar[mid] > d:
                k = mid + 1
            else:
                k = mid

            ans += (rightmost-k)*(rightmost-k-1) // 2

    print(ans)

if __name__ == '__main__':
    n,d = map(int, input().split())
    ar = list(map(int, input().split()))
    solve(n,d,ar)


n, d = map(int, input().split())
a = list(map(int, input().split()))

ret = 0
for i, val in enumerate(a):
    left, right = i - 1, n
    while left + 1 < right:
        mid = (left + right) >> 1
        if a[mid] - val > d:
            right = mid
        else:
            left = mid
    if left != i - 1:
        size = left - i - 1
        ret += size * (size + 1) // 2
print(ret)


# Target - Expert on CF
# Be Humblefool

import sys

# inf = float("inf")
# sys.setrecursionlimit(100000)

# abc='abcdefghijklmnopqrstuvwxyz'
# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
# mod, MOD = 1000000007, 998244353
# words = {1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',8:'eight',9:'nine',10:'ten',11:'eleven',12:'twelve',13:'thirteen',14:'fourteen',15:'quarter',16:'sixteen',17:'seventeen',18:'eighteen',19:'nineteen',20:'twenty',21:'twenty one',22:'twenty two',23:'twenty three',24:'twenty four',25:'twenty five',26:'twenty six',27:'twenty seven',28:'twenty eight',29:'twenty nine',30:'half'}
# vow=['a','e','i','o','u']
# dx,dy=[0,1,0,-1],[1,0,-1,0]

# import random
# from collections import deque, Counter, OrderedDict,defaultdict
# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
# from math import ceil,floor,log,sqrt,factorial,pi,gcd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def calculate(n):
    if n<1: return 0
    return (n*(n+1))//2

n,d = get_ints()
Arr = get_array()
ans = 0
for i in range(n):
    index = bisect_right(Arr,Arr[i]+d)
    ans+=calculate(index-i-2)
print(ans)


# Target - Expert on CF
# Be Humblefool

import sys

# inf = float("inf")
# sys.setrecursionlimit(100000)

# abc='abcdefghijklmnopqrstuvwxyz'
# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
# mod, MOD = 1000000007, 998244353
# words = {1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',8:'eight',9:'nine',10:'ten',11:'eleven',12:'twelve',13:'thirteen',14:'fourteen',15:'quarter',16:'sixteen',17:'seventeen',18:'eighteen',19:'nineteen',20:'twenty',21:'twenty one',22:'twenty two',23:'twenty three',24:'twenty four',25:'twenty five',26:'twenty six',27:'twenty seven',28:'twenty eight',29:'twenty nine',30:'half'}
# vow=['a','e','i','o','u']
# dx,dy=[0,1,0,-1],[1,0,-1,0]

# import random
# from collections import deque, Counter, OrderedDict,defaultdict
# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
# from math import ceil,floor,log,sqrt,factorial,pi,gcd
# from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def calculate(n):
    if n<=0: return 0
    return (n**3 + 3*n**2 + 2*n)//6

n,d = get_ints()
Arr = get_array()
ans = 0
start = 0
end = 1
while end<n:
    if (Arr[end]-Arr[start])<=d:
        end+=1
    else:
        ans+=calculate(end-start-2)
        while (Arr[end]-Arr[start]>d):
            start+=1
        end+=1
ans+=calculate(end-start-2)
print(ans)


# Target - Expert on CF
# Be Humblefool

import sys

# inf = float("inf")
# sys.setrecursionlimit(100000)

# abc='abcdefghijklmnopqrstuvwxyz'
# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
# mod, MOD = 1000000007, 998244353
# words = {1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',8:'eight',9:'nine',10:'ten',11:'eleven',12:'twelve',13:'thirteen',14:'fourteen',15:'quarter',16:'sixteen',17:'seventeen',18:'eighteen',19:'nineteen',20:'twenty',21:'twenty one',22:'twenty two',23:'twenty three',24:'twenty four',25:'twenty five',26:'twenty six',27:'twenty seven',28:'twenty eight',29:'twenty nine',30:'half'}
# vow=['a','e','i','o','u']
# dx,dy=[0,1,0,-1],[1,0,-1,0]

# import random
# from collections import deque, Counter, OrderedDict,defaultdict
# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
# from math import ceil,floor,log,sqrt,factorial,pi,gcd
# from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def calculate(n):
    return (n**3 + 3*n**2 + 2*n)//6

n,d = get_ints()
Arr = get_array()
start = 0
end = 0
ans = 0
while (end+1)<n :
    if (Arr[end+1]-Arr[start])<=d:
        end+=1
    else:
        if (Arr[end]-Arr[start])<=d:
            ans+=calculate(end-start+1-2)
        start+=1
        end+=1

while start<=(end-2):
    if (Arr[end]-Arr[start])>d:
        start+=1
    else:
        ans+=calculate(end-start+1-2)
        break
print(ans)


n,d=list(map(int,input().split()))
a=list(map(int,input().split()))
i=0
ans=0
for j in range(2,n):
    while j-i>=3 and a[j]-a[i]>d:
        i+=1
    if a[j]-a[i]<=d:
        ans+=((j-i-1)*(j-i))//2
print(ans)


n,d=map(int,input().split())
a=list(map(int,input().split()))
def bs(ele,left,right):
    best=1
    while(left<=right):
        mid=left+(right-left)//2
        if(abs(ele-mid)<2):
            left+=1
        elif(abs(a[ele]-a[mid])<=d):
            best=mid
            left=mid+1
        else:
            right=mid-1
    return best
cnt=0
for i in range(n-2):
    c=bs(i,i,n-1)-i
    if(c>=2):
        cnt+=c*(c-1)//2
print(cnt)


n,d=map(int, input().split())

a=list(map(int, input().split()))

if n<3:
    print (0)
else:
    i=0
    j=n-1

    count=0

    while i<n-2:

        while (a[j]-a[i]>d) and j-1>=i:
            j=j-1

        count=count+((j-i-1)*(j-i))//2

        i=i+1

        while (a[j]-a[i]<=d) and j+1<n:
            j=j+1

    print (count)


import math
n,d = map(int , input().split())
a = list(map(int , input().split()))

j=2
ans = 0
for i in range(n):
    while j<n and a[j] - a[i] <= d:
        j+=1
    if j-i>1:
        ans+=((j-i-1)*(j-i-2))//2
print(ans)


import math

n,d = map(int , input().split())
a = list(map(int , input().split()))
i=0
j=2
ans = 0
while j<n:

    while j<n and abs(a[j] - a[i]) <= d:
        j+=1
    if j-i >= 3:
        # print(i,j)
        ans = ans + (math.factorial(j-i) //( math.factorial(3) * math.factorial(j-i-3)))
    i+=1
print(ans)


import math

n,d = map(int , input().split())
a = list(map(int , input().split()))
i=0
j=2
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if abs(a[k] - a[i]) <= d:
                ans+=1
            else:
                break
print(ans)


from collections import defaultdict
def ncr(n, k):
    C = [[0 for x in range(k + 1)] for x in range(n + 1)]
    for i in range(n + 1):
        for j in range(min(i, k) + 1):
            if j == 0 or j == i:
                C[i][j] = 1
            else:
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j]

    return C[n][k]
#print(ncr(5,2))
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
i=0
j=0
ans=0
prev=-1
while(j<n):
    while(j<n and a[j]-a[i]<=k):
        j+=1
    if(j-i>=3):
        if(prev-i<3 and j-1!= prev):
            ans+=ncr(j-i,3)
        elif(j-1 != prev):
            ans+=(ncr(j-i,3)-ncr(prev-i,3))
    #print(ans,i,j)
    i+=1
    prev=j-1
print(ans)


def fact(n):
    if(n<=1):
        return 1
    else:
        return n*fact(n-1)
n,d=map(int,input().split())
a=[int(x) for x in input().split()]
i=0
j=1
ans=0
while(j<n):
    while(j<n and a[j]-a[i]<=d):
        j+=1
    j-=1
    if(j-i+1>=3):
        res=j-i+1
        ans+=fact(res)//(fact(res-3)*fact(3))
    i+=1
    j+=1
print(ans)


from collections import defaultdict
def ncr(n, k):
    C = [[0 for x in range(k + 1)] for x in range(n + 1)]
    for i in range(n + 1):
        for j in range(min(i, k) + 1):
            if j == 0 or j == i:
                C[i][j] = 1
            else:
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j]

    return C[n][k]
#print(ncr(5,2))
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
i=0
j=0
ans=0
prev=-1
while(j<n):
    while(j<n and a[j]-a[i]<=k):
        j+=1
    if(j-i>=3):
        if(prev-i<3):
            ans+=ncr(j-i,3)
        else:
            ans+=(ncr(j-i,3)-ncr(prev-i,3))
    i+=1
    prev=j-1
print(ans)


from collections import defaultdict
def ncr(n, k):
    C = [[0 for x in range(k + 1)] for x in range(n + 1)]
    for i in range(n + 1):
        for j in range(min(i, k) + 1):
            if j == 0 or j == i:
                C[i][j] = 1
            else:
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j]

    return C[n][k]
#print(ncr(5,2))
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
j=0
ans=0
#prev=-1
for i in range(n):
    while(a[i]-a[j]>k):
        j+=1
    ans+=((i-j)*(i-j-1))//2
print(ans)


'''input
4 2
-3 -2 -1 0
'''
from sys import stdin
from bisect import bisect_right

def combi(n, c):
	return (n * (n - 1)) // 2

# main starts
n, d = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
count = 0
for i in range(n):
	index = bisect_right(arr, arr[i] + d)
	count += combi(index - i - 1 , 2)
print(count)


'''input
4 2
-3 -2 -1 0
'''
from sys import stdin
from bisect import bisect_right

def make_dict(arr):
	mydict = dict()
	for i in arr:
		mydict[i] = True
	return mydict

def combi(n, c):
	return (n * (n - 1)) // 2

# main starts
n, d = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
mydict = make_dict(arr)
count = 0
for i in range(n):
	index = bisect_right(arr, arr[i] + d)
	count += combi(index - i - 1 , 2)
#	print(index, count)
print(count)


import bisect

n,d = [int(x) for x in input().split()]

a = [int(x) for x in input().split()]

ans =0

for i in range(0,n):

  x = bisect.bisect_right(a,a[i]+d)

  ans+=(x-i-1)*(x-i-2)//2

print(ans)


def ans(n,d,p):
    if n<3:
        return 0
    ans = 0
    for i in range(n-2):
        j = i+1
        k = i+2
        if max(abs(p[k]-p[i]),abs(p[k]-p[j])) <= d:
            while k < n and abs(p[k] - p[i]) <= d:
                ans+=1
                k+=1
            k-=1
            j+=1
            while j < k:
                ans+=1
                j+=1
    return ans
n,d = map(int,input().split())
points = [int(i) for i in input().split()]
print(ans(n,d,points))


from bisect import bisect_left

def sol(a,n,d):
    ans = 0
    for i in range(n-2):
        x = a[i]+d
        pos = bisect_left(a,x)
        if pos < n and a[pos] == x:
            pos+=1
        x = pos - (i+2)

        ans+=((x*(x+1))//2)
    return ans

n,d = map(int,input().split())
a = [int(i) for i in input().split()]
print(sol(a,n,d))


from bisect import bisect_left
def points(a,n,d):
    ans = 0
    for i in range(n-2):
        if a[i+2] - a[i] <= d:
            pos = bisect_left(a,a[i]+d,i+2,n)
            if pos == n or a[pos] != a[i]+d:
                pos-=1
            x = pos-(i+2)+1
            ans += ((x*(x+1))//2)
    return ans

n,d = map(int,input().split())
a = [int(i) for i in input().split()]

print(points(a,n,d))


from bisect import bisect_left
def points(a,n,d):
    ans = 0
    for i in range(n-2):
        if a[i+2] - a[i] <= d:
            pos = bisect_left(a,a[i]+d,i+2,n)
            if pos == n:
                pos-=1
            x = pos-(i+2)+1
            ans += ((x*(x+1))//2)
    return ans

n,d = map(int,input().split())
a = [int(i) for i in input().split()]

print(points(a,n,d))


def sol(a,n,d):
    ans = 0
    for i in range(n-2):
        for j in range(n-1,i+1,-1):
            if a[j] - a[i] <= d:
                x = j-i-1
                ans+=x

    return ans

n,d = map(int,input().split())
a = [int(i) for i in input().split()]
print(sol(a,n,d))


n,d = list(map(int,input().split()))
x = list(map(int,input().split()))
i = 0
j = 2
s = 0
while i<n and j<n:
    if x[j]-x[i]<=d:
        s+=j-i-1
        j+=1
    else:
        newi = i+1
        if j-newi > 1:
            i+=1
        else:
            j+=1
j-=1
i+=1
while j-i>1:
    if x[j]-x[i]<=d:
        s+=j-i-1
    i+=1
print(s)


import os,io
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n,d = list(map(int,input().split()))
x = list(map(int,input().split()))
x.append(x[-1]+d+1)
s,i,j=0,0,0
while i<n-1:
    while x[j]-x[i]<=d:
        j+=1
    s += (j-i-1)*(j-i-2)//2
    i+=1
print(s)


n,d = list(map(int,input().split()))
x = list(map(int,input().split()))
x.append(x[-1]+d+1)
i = 0
j = 2
s = 0
while j<n+1:
    if x[j]-x[i]<=d:
        j+=1
    else:
        k = j-i
        if k>2:
            if x[j-1]-x[i]<=d:
                v = (k*(k-1)*(k-2))//6
                s+=v
                j+=1
            i+=1
        else:
            j+=1

print(s)


def nCr(n):
    return (n-1)*n/2

s = 0
n,d = map(int,input().split())
a = list(map(int,input().split()))
l = 1
for i in range(n-2):
    now = a[i]
    r = n-1
    while(r>l):
        c = (r+l)//2 +1
        if a[c]>now+d:
            r=c-1
        else:
            l = c
    if l-i>=2:
     s+=nCr(l-i)
print(int(s))


from math import factorial as f

def nCr(n):
    return (n-1)*n/2

s = 0
#n,d = map(int,input().split())
#a = list(map(int,input().split()))
a = list(map(int,range(1,100001)))
n = 100000
d = 1000
for i in range(n-2):
    now = a[i]
    l = i+1
    r = n-1

    while(r>l):
        c = (r+l)//2 +1
        if a[c]>now+d:
            r=c-1
        else:
            l = c

    if l-i>=2:
     s+=nCr(l-i)
print(int(s))


def nCr(n):
    return (n-1)*n/2

s = 0
n,d = map(int,input().split())
a = list(map(int,input().split()))
l = 1
for i in range(n-2):
    now = a[i]
    while(l < n and a[l]<=now+d): l+=1
    if l-i>=3:
     s+=nCr(l-i-1)
print(int(s))


def nCr(n):
    return (n-1)*n/2

s = 0
n,d = map(int,input().split())
a = list(map(int,input().split()))

for i in range(n-2):
    now = a[i]
    l = i+1
    r = n-1

    while(r>l):
        c = (r+l)//2 +1
        if a[c]>now+d:
            r=c-1
        else:
            l = c

    if l-i>=2:
     s+=nCr(l-i)
print(int(s))


n, dist = map(int, input().split())

points = list(map(int, input().split()))

group_count = 0
tail = 0
for head in range(n) :
    while points[head] - points[tail] > dist:  # when the condition is not working make a step
        tail += 1

    # the number of points in the segment between two pointers, excluding the rightmost point
    k = head - tail

    # there exist exactly k * (k - 1) // 2 triplets of points with the fixed rightmost point
    group_count += (k * (k - 1)) // 2
print(group_count)


import math
import bisect
n,k=map(int,input().split())
arr=list(map(int,input().split()))
ans=0
for i in range(n-2):
    var=arr[i]+k
    t=bisect.bisect_left(arr,var)
    if t>=n:
        t=n-1
    #print("t",t)
    if arr[t]==var:
        t+=1
    f=t-i
    #print("f",f)
    if f>=3:

        ans+=math.factorial(f)//(math.factorial(f-3)*6)
print(ans)


'''
import sys
import math
import bisect
n=int(input())
n,m=map(int,input().split())
arr=list(map(int,input().split()))

t=sys.stdin.buffer.readline()
sys.stdin=open("input.txt")
sys.stdout=open("output.txt", 'w')
sys.stdout.write("Yes" + '\n')
s="abcdefghijklmnopqrstuvwxyz"
mod=1000000007
mod=998244353
vow=['a','e','i','o','u']
t=[[0 for i in range(n)]for j in range(n)]
pow(4,7)
def gcd(x,y):
    while y:
        x,y=y%x,x
    return y'''
import math
import bisect
n,d=map(int,input().split())
arr=list(map(int,input().split()))
i=0
ans=0
while i<n-2:
    var=bisect.bisect_left(arr,arr[i]+d)
    if var-i==2 and arr[var]-arr[i]==d:
        ans+=1
        i+=1
    elif var-i>2:
        if arr[var]>arr[i] + d:
            var-=1

        ans += math.factorial(var - i + 1) // 6
        i=var-1

    else:
        i+=1
print(ans)


# n=int(input())
# n,k=map(int,input().split())
'''l=0
r=10**13
while l+1<r:
    mid=(l+r)//2
    val=(max(0,b_b*mid-b)*rb+max(0,b_s*mid-s)*rs+max(0,b_c*mid-b)*rc)
    if val>money:
        r=mid
    if val<=money:
        l=mid'''
# arr=list(map(int,input().split()))
# n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
n,d=map(int,input().split())
arr=list(map(int,input().split()))
i=0
ans=0
for j in range(n):
    while j-i>=3 and arr[j]-arr[i]>d:
        i+=1
    if arr[j]-arr[i]<=d:
        ans+=(j-i)*(j-i-1)//2
print(ans)


import math
import bisect
n,k=map(int,input().split())
arr=list(map(int,input().split()))
ans=0
max_covered=0
for i in range(n-2):
    var=arr[i]+k
    t=bisect.bisect_left(arr,var)
    if t>max_covered:
        max_covered=t
        #print("t", t)
        if t <= n - 1:
            if arr[t] == var:
                t += 1
        f = t - i
        if f >= 3:
            ans += math.factorial(f) // (math.factorial(f - 3) * 6)
            #print(ans)
            if t == n:
                break
    else:
        pass
print(ans)


'''
import sys
import math
import bisect
n=int(input())
n,m=map(int,input().split())
arr=list(map(int,input().split()))

t=sys.stdin.buffer.readline()
sys.stdin=open("input.txt")
sys.stdout=open("output.txt", 'w')
sys.stdout.write("Yes" + '\n')
s="abcdefghijklmnopqrstuvwxyz"
mod=1000000007
mod=998244353
vow=['a','e','i','o','u']
t=[[0 for i in range(n)]for j in range(n)]
pow(4,7)
def gcd(x,y):
    while y:
        x,y=y%x,x
    return y'''
import math
import bisect
n,d=map(int,input().split())
arr=list(map(int,input().split()))
i=0
ans=0
while i<n-2:
    var=bisect.bisect_left(arr,arr[i]+d)
    if var-i==2 and arr[var]-arr[i]==d:
        ans+=1
        i+=1
    elif var-i>2:
        if arr[var]>=arr[i] + d:
            var-=1

        ans += math.factorial(var - i + 1) // 6
        i=var-1

    else:
        i+=1
print(ans)


'''
import sys
import math
import bisect
n=int(input())
n,m=map(int,input().split())
arr=list(map(int,input().split()))

t=sys.stdin.buffer.readline()
sys.stdin=open("input.txt")
sys.stdout=open("output.txt", 'w')
sys.stdout.write("Yes" + '\n')
s="abcdefghijklmnopqrstuvwxyz"
mod=1000000007
mod=998244353
vow=['a','e','i','o','u']
t=[[0 for i in range(n)]for j in range(n)]
pow(4,7)
def gcd(x,y):
    while y:
        x,y=y%x,x
    return y'''
import math
import bisect
n,d=map(int,input().split())
arr=list(map(int,input().split()))
i=0
ans=0
while i<n-2:
    var=bisect.bisect_left(arr,arr[i]+d)
    if var-i==2 and arr[var]-arr[i]==d:
        ans+=1
        i+=1
    elif var-i>2:
        ans += math.factorial(var - i + 1) // 6
        i=var-1

    else:
        i+=1
print(ans)


def foo(x):
	return (x*(x-1)//2)

n,d=map(int,input().split())
l=list(map(int,input().split()))+[1e10]

j=0
c=0
for i in range(2,n):
	while l[i]-l[j]>d:
		j+=1
	k=i-j
	c=c+foo(k)

print(c)


n, d = (int(x) for x in input().split())
x = [int(x) for x in input().split()]
l = 0
r = 0
ans = 0
while l < n:
	while r < n and x[r] - x[l] <= d:
		r += 1
	ans += (r - l - 1) * (r - l - 2) // 2
	l += 1
print(ans)


n, d = map(int, input().split())
x = [int(i) for i in input().split()]

amounts = [1]
for num in range(2, 10**5):
    amounts.append(amounts[-1] + num)

# print(amounts[:100])

num_of_options = 0
ind = 0
ind2 = 0
while ind2 < n:
    # print(num_of_options)
    if abs(x[ind] - x[ind2]) <= d:
        if ind2 - ind >= 2:
            num_of_options += amounts[ind2 - ind - 2]
        ind2 += 1
    else:
        while abs(x[ind] - x[ind2]) > d:
            ind += 1

print(num_of_options)


import math

n, d = map(int, input().split())
x = [int(i) for i in input().split()]

num_of_options = 0
ind = 0
ind2 = 0
subtract = 0
flag = 1
while ind2 < n:
    # print(num_of_options)
    if abs(x[ind2] - x[ind]) <= d:
        ind2 += 1
        flag = 1
    else:
        if ind2 - ind - 3 >= 0 and subtract - ind - 3 >= 0:
            num_of_options += math.factorial(ind2 - ind) // (math.factorial(3) * math.factorial(ind2 - ind - 3)) - \
                              math.factorial(subtract - ind) // (math.factorial(3) * math.factorial(subtract - ind - 3))
        elif ind2 - ind - 3 >= 0:
            num_of_options += math.factorial(ind2 - ind) // (math.factorial(3) * math.factorial(ind2 - ind - 3))
        flag = 0
        subtract = ind2
        while abs(x[ind2] - x[ind]) > d:
            ind += 1

if flag == 1:
    if ind2 - ind - 3 >= 0 and subtract - ind - 3 >= 0:
        num_of_options += math.factorial(ind2 - ind) // (math.factorial(3) * math.factorial(ind2 - ind - 3)) - \
                          math.factorial(subtract - ind) // (math.factorial(3) * math.factorial(subtract - ind - 3))
    elif ind2 - ind - 3 >= 0:
        num_of_options += math.factorial(ind2 - ind) // (math.factorial(3) * math.factorial(ind2 - ind - 3))

print(num_of_options)


iarr = list(map(int,input().split()))
n = iarr[0]
d = iarr[1]
arr = list(map(int,input().split()))
arr.sort()
ans = 0
for i in range(n-2):
	curr = arr[i]
	l = i+1
	r = n-1
	while (l<=r):
		mid = (l+r)//2
		if arr[mid]>curr+d:
			r = mid-1
		else:
			l = mid+1
	l-=1
	if l>i:
		count = l-i
		ans+=(count*(count-1))//2
print(ans)


def binarysearch(n, seq):
	low = 0
	high = len(seq)-1
	# print(n)
	while low < high:
		mid = (high+low+1)//2
		# print(low, high, mid, n)

		if seq[mid] > n:
			high = mid - 1
		else:
			low = mid

	return low

if __name__ == '__main__':
	n, d = map(int, input().split())
	seq = [int(x) for x in input().split()]

	ans = 0
	for idx, i in enumerate(seq):
		idx2 = binarysearch(i+d, seq)

		num_in_bw = idx2 - idx
		ans += (num_in_bw*(num_in_bw-1)) // 2
		# print(ans,idx2)
	print(ans)


import math
def sum(a, b):
    n = b - a
    return n*(n-1)//2
n, d = map(int, input().split())
arr = list(map(int, input().strip().split()))
s = 0
for i in range(n):
    a = arr[i]
    l = 0
    r = n
    while r - l > 1:
        mid = (r + l) // 2
        if arr[mid] - arr[i] > d:
            r = mid
        else:
            l = mid
    if l - i + 1 >= 3:
        s += sum(i+1, l+1)
print(s)


import heapq
from bisect import bisect_left, bisect_right
from itertools import accumulate

R = lambda: map(int, input().split())
n, k = R()
cs = list(R())
r, res = 0, 0
for l in range(n):
    r = bisect_right(cs, cs[l] + k)
    res += (r - l - 1) * (r - l - 2) // 2 if r - l > 2 else 0
print(res)


R = lambda: map(int, input().split())
n, k = R()
cs = list(R())
r, res = 0, 0
for l in range(n):
    while r < n and cs[r] - cs[l] <= k:
        r += 1
    res += (r - l - 1) * (r - l - 2) // 2 if r - l > 2 else 0
print(res)


n, d = list(map(int, input().split()))
xs = list(map(int, input().split()))
xs.sort()

i = 0
j = 1
ans = 0
for i in range(n):
    while j < len(xs) and xs[j] - xs[i] <= d:
        j += 1
    if xs[j - 1] - xs[i] <= d and j - i >= 3:
        ans += (j - i - 1) * (j - i - 2) // 2
print(ans)


import math
from sys import stdin

def binary_search(data, val):
    test = len(data)
    if val >= data[-1]:
        return [test-1, test-1]
    elif val<= data[0]:
        return [0,0]
    high_index = len(data)-1
    low_index = 0
    while high_index > low_index:
        index = (high_index + low_index) // 2
        sub = data[index]
        if data[low_index] == val:
            return [low_index, low_index]
        elif sub == val:
            return [index, index]
        elif data[high_index] == val:
            return [high_index, high_index]
        elif sub > val:
            if high_index == index:
                return sorted([high_index, low_index])
            high_index = index
        else:
            if low_index == index:
                return sorted([high_index, low_index])
            low_index = index
    return sorted([high_index, low_index])

n, m = map(int, input().split(" "))
l = list(map(int, stdin.readline().rstrip().split(" ")))

ans = 0
for i in range(n):
    x = binary_search(l, l[i]+m)
    c = x[0]-i
    if c >1:
        ans+= (c*(c-1)//2)
print(ans)


import sys
input = sys.stdin.readline

'''

'''

n, d = map(int, input().split())
a = list(map(int, input().split()))
triangle = lambda n: n*(n+1)//2
res = 0
l, r = 0, 1
one_less = n-1

while l < n and r < n:
    while r < one_less and a[r+1] - a[l] <= d:
        r += 1

    if l < r:
        #print(l, r, res)
        res += triangle(r-l-1)
    l += 1
print(res)


def bs(num):
	low = 0
	high = n-1
	while low<high:
		mid = (low+high)//2
		if a[mid]-num>d:
			high = mid-1
		else:
			low = mid+1
	if a[low]-num>d:
		return low-1
	else:
		return low

n,d = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
	f = bs(a[i])
	f = f-i
	ans += max(0,(f*(f-1))//2)
print (ans)


from sys import stdin
from math import factorial as f
a,b=map(int,stdin.readline().split());a+=1
z=[1]+list(map(int,stdin.readline().split()));i,j=1,1;ans=0
r=lambda x:f(x)//(f(x-2)*2)
while i<a:
    if j<=i:j=i
    while j<a and abs(z[j]-z[i])<=b:j+=1
    if j-i-1>=2:ans+=r(j-i-1)
    i+=1
print(ans)


from sys import stdin
a,b=map(int,stdin.readline().split());a+=1
z=[1]+list(map(int,stdin.readline().split()));i,j=1,1;ans=0
r=lambda x:(x*(x+1))//2
while i<a:
    if j<=i:j=i
    while j<a and abs(z[j]-z[i])<=b:j+=1
    if j-i-1>=2:ans+=r(j-i-2)
    i+=1
print(ans)


from math import factorial as f
a,b=map(int,input().split());a+=1
z=[1]+list(map(int,input().split()));i,j=1,1;ans=0
r=lambda x:f(x)//(f(x-2)*2)
while i<a:
    while j<a and abs(z[j]-z[i])<=b:j+=1
    if j-i-1>=2:ans+=r(j-i-1)
    i+=1
print(ans)


from sys import stdin
from math import factorial as f
a,b=map(int,stdin.readline().split());a+=1
z=[1]+list(map(int,stdin.readline().split()));i,j=1,1;ans=0
r=lambda x:f(x)//(f(x-2)*2)
d={}
while i<a:
    if j<=i:j=i
    while j<a and abs(z[j]-z[i])<=b:j+=1
    if j-i-1>=2:
        temp=j-i-1
        if temp not in d:d[temp]=r(temp)
        ans+=d[temp]
    i+=1
print(ans)


from collections import defaultdict

n, d = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
l = 0
r = 0
b = defaultdict(int)
while l <= r and r < len(arr):
	if r - l < 2:
		r += 1
		continue
	if arr[r] - arr[l] > d:
		l += 1
		continue
	b[l] = r
	if r != len(arr) - 1:
		r += 1
	else:
		l += 1
for k, v in b.items():
	if v - k < 2:
		continue
	ans += (v - k) * (v - k - 1) // 2
print(ans)


n, d = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
l = 0
r = 0
b = {}
while l <= r and r < len(arr):
	if r - l < 2:
		r += 1
		continue
	if arr[r] - arr[l] > d:
		l += 1
		continue
	if r not in b:
		b[r] = l
	else:
		b[r] = min(b[r], l)
	if r != len(arr) - 1:
		r += 1
	else:
		l += 1
for v, k in b.items():
	if v - k < 2:
		continue
	ans += (v - k) * (v - k - 1) // 2
print(ans)


def foo(x):
	return ((x*(x-1)*(x-2))//6)

n,d=map(int,input().split())
l=list(map(int,input().split()))

i=0
j=1
c=0
last=1
while(j<n and i<n):
	k=l[i]+d
	while(j<n and l[j]<=k):
		j=j+1

	if(last!=j):
		le=j-i
		#print(le,i,j,foo(le))
		c=c+foo(le)

	last=j
	i=i+1

print(c)


def foo(x):
	return (x*(x-1)//2)

n,d=map(int,input().split())
l=list(map(int,input().split()))+[1e10]

j=0
c=0
for i in range(2,n):
	while l[i]-l[j]>d:
		j+=1
	k=i-j
	c=c+foo(k)

print(c)


import math

n=int(input())
a=list(map(int,input().split()))
for i in range(0,n):
	while(a[i]%2==0):
		a[i]=a[i]//2
	while(a[i]%3==0):
		a[i]=a[i]//3

f=1
#print(*a)
ok=a[0]
for i in range(0,n):
	if a[i]!=ok:
		f=0
		break
if f==1:
	print('Yes')
else:
	print('No')


def foo(x):
	return ((x*(x-1)*(x-2))//6)

n,d=map(int,input().split())
l=list(map(int,input().split()))

i=0
j=1
c=0
last=1
while(j<n and i<n):
	k=l[i]+d
	while(j<n and l[j]<=k):
		j=j+1
		check=1

	if(check!=0):
		le=j-i
		#print(le,i,j,foo(le))
		c=c+foo(le)

	check=0
	i=i+1

print(c)


def foo(x):
	return ((x*(x-1)*(x-2))//6)

n,d=map(int,input().split())
l=list(map(int,input().split()))

i=0
j=1
c=0
while(j<n and i<n):
	k=l[i]+d
	while(j<n and l[j]<=k):
		j=j+1

	le=j-i
	#print(le,i,j)
	c=c+foo(le)
	i=i+1
print(c)