#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <tuple>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <iomanip>
using namespace std;

typedef long double ll;

#ifndef ONLINE_JUDGE
#define DEBUG 1
#else
#define DEBUG 0
#endif

const int maxn = 200200;

int n;
int a[maxn];

int main(int argc, char *argv[]) {
	std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
	#if DEBUG
	freopen("/tmp/in.txt", "r", stdin);
	while(cin>>n)
	#else
	cin >> n;
	#endif
	{
		map<ll,ll> bs, b1;
		ll r = 0;
		ll nbr = 0;
		ll ts = 0;
		for(int i=0;i<n;i++) {
			ll x; cin >> x;
			ll nbr0 = b1[x+1] + b1[x] + b1[x-1];
			ll s0 = bs[x+1] + bs[x] + bs[x-1];

			r += (x) * (nbr - nbr0) - (ts-s0);

			bs[x] += x;
			b1[x] += 1;
			ts += x;
			nbr++;
		}

		cout << setprecision(0) << fixed << r << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <tuple>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <iomanip>
#include <sstream>
#include <cstdint>
#include <stdexcept>
#include <type_traits>
#include <utility>
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
template<typename T> T gcd(T x, T y){ if(x<y) swap(x,y); while(y>0) { T f = x%y; x = y; y = f; } return x; }
void exgcd(ll a, ll b, ll &d, ll &x, ll &y) {
	if (!b) {d = a; x = 1; y = 0;}
	else {exgcd(b, a % b, d, y, x); y -= x * (a / b);}
}

ll inv(ll a, ll m) {
	ll x, y, d; exgcd(a, m, d, x, y);
	return d == 1 ? ((x%m) + m) % m : -1;
}

#ifndef ONLINE_JUDGE
#define DEBUG 1
#else
#define DEBUG 0
#endif

const int maxn = 200200;

int n;
int a[maxn];

namespace Int128Impl {
	typedef long long int64;
	typedef int       int32;

	// This class is the base class for the Doubler, it provides the
	// helper routines like
	//    int SubDouble(int128_t *A,const int128_t &B,const int borrow);
	//    int128_t DivideDouble(int128_t *A,const int128_t &B);
	//     int shiftleft(int128_t *Value,const int Carry_prm);
	//
	// Which are used by DoubleInt_t to double the size of the passed class.
	// By itself this class is fairly useful if you happen to need something
	// slightly larger than a 64-bit int (large(er) bitfields come to mind).
	//
	typedef class int128_t
	{
		public:
			// construction/casting
			int128_t()                    :Hi(0),Lo(0) {}
			int128_t(const int128_t &orig):Hi(orig.Hi),Lo(orig.Lo) {}
			int128_t(const int64    &orig):Hi(0),Lo(orig) {}
			// assignment
			int128_t &operator= (const int128_t &rhs) {Hi=rhs.Hi;Lo=rhs.Lo;return *this;}
			// compariston
			bool     operator==(const int128_t &rhs) { if ((Hi==rhs.Hi) && (Lo==rhs.Lo)) return true; return false;}
			bool     operator!=(const int128_t &rhs) { if ((Hi==rhs.Hi) && (Lo==rhs.Lo)) return false; return true;}
			bool     operator>=(const int128_t &rhs) { if ((Hi>rhs.Hi) || ( (Hi==rhs.Hi) && (Lo>=rhs.Lo))) return true; return false;}
			bool     operator<=(const int128_t &rhs) { if ((Hi<rhs.Hi) || ( (Hi==rhs.Hi) && (Lo<=rhs.Lo))) return true; return false;}
			bool     operator> (const int128_t &rhs) { if ((Hi>rhs.Hi) || ( (Hi==rhs.Hi) && (Lo>rhs.Lo ))) return true; return false;}
			bool     operator< (const int128_t &rhs) { if ((Hi<rhs.Hi) || ( (Hi==rhs.Hi) && (Lo<rhs.Lo ))) return true; return false;}
			// operations (these are exported for user use)
			int128_t &operator++() { AddDouble(this,1,0); return *this;}
			int128_t &operator--() { SubDouble(this,1,0); return *this;}

			int128_t &operator>>=(const int      rhs)  { for (int x=0;x<rhs;x++) shiftright(this,0); return *this;}
			int128_t &operator<<=(const int      rhs)  { for (int x=0;x<rhs;x++) shiftleft(this,0); return *this;}
			int128_t &operator-=( const int128_t &rhs) { SubDouble(this,rhs,0); return *this;}
			int128_t &operator+=( const int128_t &rhs) { AddDouble(this,rhs,0); return *this;}
			int128_t &operator*=( const int128_t &rhs) { MultiplyDouble(this,rhs); return *this;}
			int128_t &operator/=( const int128_t &rhs) { DivideDouble(this,rhs); return *this;}
			int128_t &operator%=( const int128_t &rhs) { *this=DivideDouble(this,rhs); return *this;}

			int128_t &operator&=( const int64 &rhs) { this->Lo&=rhs; return *this;}
			int128_t &operator|=( const int64 &rhs) { this->Lo|=rhs; return *this;}
			int128_t &operator^=( const int64 &rhs) { this->Lo^=rhs; return *this;}

			int128_t &operator&=( const int128_t &rhs)  { this->Lo&=rhs.Lo; this->Hi&=rhs.Hi; return *this;}
			int128_t &operator|=( const int128_t &rhs)  { this->Lo|=rhs.Lo; this->Hi|=rhs.Hi; return *this;}
			int128_t &operator^=( const int128_t &rhs)  { this->Lo^=rhs.Lo; this->Hi^=rhs.Hi; return *this;}

	//          int128_t &operator~=( const int64 &rhs) { this->Lo~=rhs; return *this;}

			int128_t operator+(   const int128_t &rhs) { int128_t tmp=*this; AddDouble(&tmp,rhs,0); return tmp;}
			int128_t operator-(   const int128_t &rhs) { int128_t tmp=*this; SubDouble(&tmp,rhs,0); return tmp;}
			int128_t operator/(   const int128_t &rhs) { int128_t tmp=*this; DivideDouble(&tmp,rhs); return tmp;}
			int128_t operator%(   const int128_t &rhs) { int128_t tmp=*this; tmp=DivideDouble(&tmp,rhs); return tmp;}
			int128_t operator*(   const int128_t &rhs) { int128_t tmp=*this; MultiplyDouble(&tmp,rhs); return tmp;}

			int128_t operator&(   const int64    &rhs) { int128_t tmp=*this; tmp&=rhs; return tmp;}
			int128_t operator|(   const int64    &rhs) { int128_t tmp=*this; tmp|=rhs; return tmp;}
			int128_t operator^(   const int64    &rhs) { int128_t tmp=*this; tmp^=rhs; return tmp;}

			int128_t operator>>(  const int      &rhs) { int128_t tmp=*this; tmp>>=rhs; return tmp;}
			int128_t operator<<(  const int      &rhs) { int128_t tmp=*this; tmp<<=rhs; return tmp;}

			// input/output routines
			string AsString(const char *format) const;
			char GetLowByte() {return Lo&0xFF;}
	//  protected:
			// these operations are exported for higher level use
			// they don't use the this variable...
			static int SubDouble(int128_t *A,const int128_t &B,const int borrow);
			static int AddDouble(int128_t *A,const int128_t &B,const int carry);
			static int128_t DivideDouble(int128_t *A,const int128_t &B);
			static int128_t MultiplyDouble(int128_t *A,const int128_t &B);
			static int shiftleft(int128_t *Value,const int Carry_prm);
			static int shiftright(int128_t *Value,const int Carry_prm);
	//  private:
			int64 Hi;
			int64 Lo;
			static const int size; //clean up the memory allocation slightly by moving this out of band..
	} int128;
	const int int128::size=128;

	/*bool operator==(const int128 &a,const int128 &b)
	{
		if ((a.Hi==b.Hi) && (a.Lo==b.Lo)) return true;
		return false;
	}*/

	//
	//
	// Assembly implementations of some functions used
	// by the int128 class.. These are just lightweight
	// inline assembly wrappers for x86 instructions
	//
	//

	static inline int64 Multiply64(int64 *A, int64 *B)
	{
		int64 ret; //unessisary the ret should be in RAX
//		asm ("mul %3    \n\t"
//			:"=a" (*A), "=d" (ret)
//			: "a" (*A), "q" (*B)
//		 );
		return ret;
	}

	// take a long word B:A and divide by C, result in A and remainder is returned
	// This is provided for completeness but isn't used because the
	// divide double is implemented as shifts/subtracts like the doubler is
	static inline int64 Divide64(int64 *A, int64 *B,int64 *C)
	{
		int64 ret;
		if (*C==0)
		{
			throw "Divide by zero";
		}
		if (*B>*C) //if the part in the high 64-bits is larger than the divisor then the
		{          //cannot fit in RAX.
			throw "Underflow";
		}
		asm ("div %4    \n\t"
			 :"=a" (*A), "=d" (ret)
			 : "a" (*A), "d" (*B), "q" (*C)
			 :
		 );
		return ret;
	}

	//returns carry and sum in A
	static inline int Add64(int64 *A,const int64 *B,const int64 carry)
	{
		char ret_carry =0;
		asm (
			 "add %3, %0  \n\t"
			 "adc %4, %0  \n\t"
			 "adc %1, %1  \n\t"
	//       "setc %1     \n\t" //appears slower than the add
	//       "cmovcq %3, %1   \n\t"
			 :"=q" (*A), "=q" (ret_carry)
			 :"0" (*A), "q" (carry), "q" (*B), "1" (ret_carry)
			 : "cc"
		);
		return (int)ret_carry;
	}

	// returns if it borroed one...
	static inline int Sub64(int64 *A, const int64 *B,const int borrow)
	{
		int ret_borrow=0;
		asm (
			"clc                \n\t"
			 "cmp $0,%[bor]      \n\t"
			 "je  0f             \n\t"
			 "stc                \n\t"
			 "0:                 \n\t"
			 "sbb %[src], %[dst] \n\t"
			 "adc %[ret_bor], %[ret_bor]\n\t"
			 : [dst] "=q" (*A), [ret_bor] "=r" (ret_borrow)
			 :        "0" (*A),           "1"  (ret_borrow), [src] "q" (*B), [bor] "q" (borrow)
			 : "cc"
			);
		return ret_borrow;
	}

	//
	//
	//          The int128_t methods
	//
	//
	//

	// A-=B; returns borrow
	inline int int128_t::SubDouble(int128_t *A,const int128_t &B,const int borrow)
	{
		int ret_borrow;
		ret_borrow=Sub64(&A->Lo,&B.Lo,borrow);
		ret_borrow=Sub64(&A->Hi,&B.Hi,ret_borrow);
		return ret_borrow;
	}

	inline int int128_t::AddDouble(int128_t *A,const int128_t &B,const int carry)
	{
		int carry_ret=0;
		carry_ret=Add64(&A->Lo,&B.Lo,carry);
		carry_ret=Add64(&A->Hi,&B.Hi,carry_ret);
		return carry_ret;
	}

	// Ha, this is a 256bit multiply, it takes two 128 bit sources and creates a 128bit destination and 128bit overflow..
	// this general code path can be abstracted into a template to generate any arbitraty length multiply as long as
	// we have a 64bit base class... For template testing we could create a 32-bit base class and compare the results
	// with a 64-bit result
	inline int128_t int128_t::MultiplyDouble(int128_t *A,const int128_t &B)
	{
		int128 ret;
		int64  tmp=0;
		int64  col3=0;

		// a 128 bit multiply works like when you were in grade school except that instead of the max value per column being
		// a 9 the max value is 2^64.

		//   ab
		//*  cd
		//------
		//   bd
		//  ad
		//  bc
		//+ac
		//-------
		// wxyz
		int64 a=A->Hi;
		int64 b=A->Lo;
		int64 c=B.Hi;
		int64 d=B.Lo;
		int64 w=0;
		int64 x=0;
		int64 y=0;
		int64 z=0;
		int   carry=0;
		int   carry2=0;
		int64 xp=0;

		y=Multiply64(&b,&d);
		z=b; b=A->Lo;
		x=Multiply64(&a,&d);
		carry=Add64(&y,&a,0);// y+=a;
		a=A->Hi;
		xp=Multiply64(&b,&c);
		carry=Add64(&x,&xp,carry); //x+=xp+carry;
		carry2=Add64(&y,&b,0);   //y+=b;
		w=Multiply64(&a,&c);
		carry2=Add64(&x,&a,carry2);//x+=a;
		// final w fixup
		int64 longcarry=carry2;
		Add64(&w,&longcarry,carry2);

		A->Lo=z;
		A->Hi=y;
		ret.Lo=x;
		ret.Hi=w;

		return ret;
	}

	// Sort of satanic because of all the carry nonsense being propagated in and out of the flags
	// for an arbitrary length integer the fastest way to do this is to put all the rcr's in a loop
	// or unroll them instead of putting all the carry flag checking everywhere
	int int128_t::shiftright(int128 *Value,const int Carry_prm)
	{
		int Carry_ret=0;
		if (Carry_prm)
		{
			asm ("stc\n\t"
				 "rcr $1,%0 \n\t"
				 "rcr $1,%1 \n\t"
				 "adc %2,%2 \n\t"
				 : "=g" (Value->Hi), "=g" (Value->Lo), "=g" (Carry_ret)    //output
				 : "0" (Value->Hi), "1" (Value->Lo), "2" (Carry_ret)     //input
				 : "cc"                                  //clobber
				);
		}
		else
		{
			asm ("clc\n\t"
				 "rcr $1,%0 \n\t"
				 "rcr $1,%1 \n\t"
				 "adc %2,%2 \n\t"
				 : "=g" (Value->Hi), "=g" (Value->Lo), "=g" (Carry_ret)   //output
				 : "0" (Value->Hi), "1" (Value->Lo), "2" (Carry_ret)     //input
				 : "cc"                                  //clobber
				);

		}
		return Carry_ret;
	}

	// This is the left shift version of the above right shift
	int int128_t::shiftleft(int128 *Value,const int Carry_prm)
	{
		char Carry_ret=0;
		if (Carry_prm)
		{
			asm ("stc\n\t"
				 "rcl $1,%1 \n\t"
				 "rcl $1,%0 \n\t"
	//           "setc %2     \n\t" //appears slower than the add
				 "adc %2,%2 \n\t"
				 : "=q" (Value->Hi), "=q" (Value->Lo), "=q" (Carry_ret)    //output
				 : "0" (Value->Hi), "1" (Value->Lo), "2" (Carry_ret)     //input
				 : "cc"                                  //clobber
				);
		}
		else
		{
			asm ("clc\n\t"
				 "rcl $1,%1 \n\t"
				 "rcl $1,%0 \n\t"
	//           "setc %2     \n\t" //appears slower than the add
				 "adc %2,%2 \n\t"
				 : "=q" (Value->Hi), "=q" (Value->Lo), "=q" (Carry_ret)   //output
				 : "0" (Value->Hi), "1" (Value->Lo), "2" (Carry_ret)     //input
				 : "cc"                                  //clobber
				);

		}
		return Carry_ret;
	}

	// from what I understand there are really only a couple of algorithms
	// useful for really long integer divides. My original plan was to
	// do some form of broken up radix 2^64 divide, but that doesn't actually
	// work without making sure the dividend is less than 2^64, if thats the case
	// we could make a really fast arbitrarily long dividend division. I'm afraid I don't
	// want to make that restriction so, I'm back to the old school, shift and subtract method.
	// A=A/B Ret=Remainder
	int128_t int128_t::DivideDouble(int128_t *A,const int128_t &B)
	{
		int128 quotient=*A;
		int128 remainder;//==0

		if ((int128_t)(B)==0) //TODO: fix this const mess
		{
			throw "division by zero";
		}

		for (int x=0;x<A->size;x++)
		{
			int hibit=shiftleft(&quotient,0);
			shiftleft(&remainder,hibit);
			if (remainder>=B)
			{
				SubDouble(&remainder,B,0); //remainder-=*B;
				quotient.Lo|=1; //quotient|=1;
			}
		}

		*A=quotient;
		return remainder;
	}

	// this takes the 64-bit value and prints it out given the formatter
	// this is about as far from efficient as can be
	string AsString(const int64 &Value,const char *format)
	{
		char temp[256];
		string ret;
		switch (format[1])
		{
			case 'd':
				sprintf(temp,"%lld",Value);
				ret=temp;
				break;
//			case 'b':
//				sprintf(temp,"%llb",Value);
//				ret=temp;
//				break;
			case 'X':
				sprintf(temp,"%llX",Value);
				ret=temp;
				break;
			case 'x':
				sprintf(temp,"%llx",Value);
				ret=temp;
				break;
		}
		return ret;
	}

	//string int128_t::AsString(const int128_t &Value,char *format)
	string int128_t::AsString(const char *format) const
	{
		char buff[256];
		char* temp = buff;
		string ret;
		switch (format[1])
		{
			case 'd':
			break;
			case 'b':
				break;
			case 'X':
			case 'x':
			{
				int128_t tmp;
				tmp=*this;
				temp[(tmp.size>>2)]=0;
				for (int x=(tmp.size>>2)-1;x>=0;x--)
				{
					temp[x]=(tmp.Lo)&0xF;
					if (temp[x]>0x9)
					{
						temp[x]+='A'-10;
					}
					else
					{
						temp[x]+='0';
					}
					shiftright(&tmp,0);
					shiftright(&tmp,0);
					shiftright(&tmp,0);
					shiftright(&tmp,0);
				}
			}
			break;
		}
		printf("-- %s\n", temp);
		ret=temp;
		return ret;
	}

	template<class BaseIntT> class DoubleInt_t
	{
		public:
			// construction/casting
			DoubleInt_t()                    :Hi(0),Lo(0),size(Hi.size*2) {}
			DoubleInt_t(const DoubleInt_t &orig):Hi(orig.Hi),Lo(orig.Lo),size(Hi.size*2) {}
			DoubleInt_t(const BaseIntT    &orig):Hi(0),Lo(orig),size(Hi.size*2) {}
			DoubleInt_t(const int64       &orig):Hi(0),Lo(orig),size(Hi.size*2) {}
			// assignment
			DoubleInt_t &operator= (const DoubleInt_t &rhs) {Hi=rhs.Hi;Lo=rhs.Lo;return *this;}
			// compariston
			bool     operator==(const DoubleInt_t &rhs) { if ((Hi==rhs.Hi) && (Lo==rhs.Lo)) return true; return false;}
			bool     operator!=(const DoubleInt_t &rhs) { if ((Hi==rhs.Hi) && (Lo==rhs.Lo)) return false; return true;}
			bool     operator>=(const DoubleInt_t &rhs) { if ((Hi>rhs.Hi) || ( (Hi==rhs.Hi) && (Lo>=rhs.Lo))) return true; return false;}
			bool     operator<=(const DoubleInt_t &rhs) { if ((Hi<rhs.Hi) || ( (Hi==rhs.Hi) && (Lo<=rhs.Lo))) return true; return false;}
			bool     operator> (const DoubleInt_t &rhs) { if ((Hi>rhs.Hi) || ( (Hi==rhs.Hi) && (Lo>rhs.Lo ))) return true; return false;}
			bool     operator< (const DoubleInt_t &rhs) { if ((Hi<rhs.Hi) || ( (Hi==rhs.Hi) && (Lo<rhs.Lo ))) return true; return false;}
			// operations (these are exported for user use)
			DoubleInt_t &operator>>=(const int      rhs)  { for (int x=0;x<rhs;x++) shiftright(this,0); return *this;}
			DoubleInt_t &operator<<=(const int      rhs)  { for (int x=0;x<rhs;x++) shiftleft(this,0); return *this;}
			DoubleInt_t &operator-=( const DoubleInt_t &rhs) { SubDouble(this,rhs,0); return *this;}
			DoubleInt_t &operator+=( const DoubleInt_t &rhs) { AddDouble(this,rhs,0); return *this;}
			DoubleInt_t &operator*=( const DoubleInt_t &rhs) { MultiplyDouble(this,rhs); return *this;}
			DoubleInt_t &operator/=( const DoubleInt_t &rhs) { DivideDouble(this,rhs); return *this;}
			DoubleInt_t &operator%=( const DoubleInt_t &rhs) { *this=DivideDouble(this,rhs); return *this;}

			DoubleInt_t &operator&=( const int64 &rhs) { this->Lo&=rhs; return *this;}
			DoubleInt_t &operator|=( const int64 &rhs) { this->Lo|=rhs; return *this;}
			DoubleInt_t &operator^=( const int64 &rhs) { this->Lo^=rhs; return *this;}

			DoubleInt_t &operator&=( const DoubleInt_t &rhs) { this->Lo&=rhs.Lo; this->Hi&=rhs.Hi; return *this;}
			DoubleInt_t &operator|=( const DoubleInt_t &rhs) { this->Lo|=rhs.Lo; this->Hi|=rhs.Hi; return *this;}
			DoubleInt_t &operator^=( const DoubleInt_t &rhs) { this->Lo^=rhs.Lo; this->Hi^=rhs.Hi; return *this;}

			DoubleInt_t operator+(   const DoubleInt_t &rhs) { DoubleInt_t tmp=*this; AddDouble(&tmp,rhs,0); return tmp;}
			DoubleInt_t operator-(   const DoubleInt_t &rhs) { DoubleInt_t tmp=*this; SubDouble(&tmp,rhs,0); return tmp;}
			DoubleInt_t operator/(   const DoubleInt_t &rhs) { DoubleInt_t tmp=*this; DivideDouble(&tmp,rhs); return tmp;}
			DoubleInt_t operator%(   const DoubleInt_t &rhs) { DoubleInt_t tmp=*this; tmp=DivideDouble(&tmp,rhs); return tmp;}
			DoubleInt_t operator*(   const DoubleInt_t &rhs) { DoubleInt_t tmp=*this; MultiplyDouble(&tmp,rhs); return tmp;}

			DoubleInt_t operator&(   const int64    &rhs) { DoubleInt_t tmp=*this; tmp.Lo&=rhs; return tmp;}
			DoubleInt_t operator|(   const int64    &rhs) { DoubleInt_t tmp=*this; tmp.Lo|=rhs; return tmp;}
			DoubleInt_t operator^(   const int64    &rhs) { DoubleInt_t tmp=*this; tmp.Lo^=rhs; return tmp;}

			DoubleInt_t operator>>(  const int      &rhs) { DoubleInt_t tmp=*this; tmp>>=rhs; return tmp;}
			DoubleInt_t operator<<(  const int      &rhs) { DoubleInt_t tmp=*this; tmp<<=rhs; return tmp;}

			// consider overridding printf until then use AsString
			string AsString(const char *format);
			void   FromString(const char *Source_prm);
			char   GetLowByte() {return Lo.GetLowByte();}
	//  protected:
			// these operations are exported for higher level use
			// they don't use the this variable...
			static int SubDouble(DoubleInt_t *A,const DoubleInt_t &B,const int borrow);
			static int AddDouble(DoubleInt_t *A,const DoubleInt_t &B,const int carry);
			static DoubleInt_t DivideDouble(DoubleInt_t *A,const DoubleInt_t &B);
			static DoubleInt_t MultiplyDouble(DoubleInt_t *A,const DoubleInt_t &B);
			static int shiftleft(DoubleInt_t *Value,const int Carry_prm);
			static int shiftright(DoubleInt_t *Value,const int Carry_prm);
	//  private:
			BaseIntT Hi;
			BaseIntT Lo;
			const int size;
	};

	// throw exceptions on overflow/underflow etc..
	template<class BaseInnT> class OverflowException_t
	{

	};

	template<class BaseIntT, class ExponentT> class Floating_t
	{
	};

	// normal number systems don't support -0 so we don't either...
	// this class just takes an unsigned base and adds a sign to it,
	// it does this without changing the bit encoding of the value, so its
	// not exactly efficient for certain operations, on the other hand we don't then have
	// to worry about sign extension or anything like that...
	template<class BaseIntT> class SignedInt_t
	{
		public:
			// construction/casting
			SignedInt_t()                    :Value(0),Negative(0) {}
			SignedInt_t(const SignedInt_t &orig):Value(orig.Value),Negative(orig.Negative) {}
			SignedInt_t(const BaseIntT    &orig):Value(orig),Negative(0) {}
			SignedInt_t(const int64       &orig):Value(orig),Negative(0) { if (orig<0) { Negative=1; Value^=BaseIntT(-1); Value+=BaseIntT(1);}} //ugly!
			// assignment
			SignedInt_t &operator= (const SignedInt_t &rhs) {Value=rhs.Value; Negative=rhs.Negative; return *this;}
			// compariston (some of thse operators could use a little teaking for efficiency)
			bool     operator==(const SignedInt_t &rhs) { if ((Value==rhs.Value) && (Negative==rhs.Negative)) return true; return false;}
			bool     operator!=(const SignedInt_t &rhs) { if ((Value==rhs.Value) && (Negative==rhs.Negative)) return false; return true;}
			bool     operator>=(const SignedInt_t &rhs) { if ((Negative==1) && (rhs.Negative==1))   {   if (Value<=rhs.Value)   {   return true;    }   return false;   }
														  else if ((Negative==0) && (rhs.Negative==0))  {   if (Value>=rhs.Value)   {   return true;    }   return false; }
														  else if (Negative==1) {   return false;   }   else    {   return true;    }   return false; }
			bool     operator<=(const SignedInt_t &rhs) { if (*this==rhs) return true; else if (*this>=rhs) return false; else return true;}
			bool     operator> (const SignedInt_t &rhs) { if (*this==rhs) return false; else return (*this>=rhs);}
			bool     operator< (const SignedInt_t &rhs) { if (*this==rhs) return false; else return !(*this>=rhs);}
			// operations (these are exported for user use), many of these operations are "wierd" because they don't affect the sign aka shift and bit instructions maintain signage
			SignedInt_t &operator>>=(const int      rhs)  { Value>>=rhs; return *this;}
			SignedInt_t &operator<<=(const int      rhs)  { Value<<=rhs; return *this;}
			SignedInt_t &operator-=( const SignedInt_t &rhs) { SubDouble(this,rhs,0);  return *this;}
			SignedInt_t &operator+=( const SignedInt_t &rhs) { AddDouble(this,rhs,0); return *this;}
			SignedInt_t &operator*=( const SignedInt_t &rhs) { MultiplyDouble(this,rhs); return *this;}
			SignedInt_t &operator/=( const SignedInt_t &rhs) { DivideDouble(this,rhs); return *this;}

			SignedInt_t &operator&=( const int64 &rhs) { Value&=rhs; return *this;}
			SignedInt_t &operator|=( const int64 &rhs) { Value|=rhs; return *this;}
			SignedInt_t &operator^=( const int64 &rhs) { Value^=rhs; return *this;}

			SignedInt_t &operator&=( const SignedInt_t &rhs) { Value&=rhs.Value; return *this;}
			SignedInt_t &operator|=( const SignedInt_t &rhs) { Value|=rhs.Value; return *this;}
			SignedInt_t &operator^=( const SignedInt_t &rhs) { Value^=rhs.Value; return *this;}

			SignedInt_t operator+(   const SignedInt_t &rhs) { SignedInt_t tmp=*this; AddDouble(&tmp,rhs,0); return tmp;}
			SignedInt_t operator-(   const SignedInt_t &rhs) { SignedInt_t tmp=*this; SubDouble(&tmp,rhs,0); return tmp;}
			SignedInt_t operator/(   const SignedInt_t &rhs) { SignedInt_t tmp=*this; DivideDouble(&tmp,rhs); return tmp;}
			SignedInt_t operator*(   const SignedInt_t &rhs) { SignedInt_t tmp=*this; MultiplyDouble(&tmp,rhs); return tmp;}

			SignedInt_t operator&(   const int64    &rhs) { SignedInt_t tmp=*this; tmp.Value&=rhs; return tmp;}
			SignedInt_t operator|(   const int64    &rhs) { SignedInt_t tmp=*this; tmp.Value|=rhs; return tmp;}
			SignedInt_t operator^(   const int64    &rhs) { SignedInt_t tmp=*this; tmp.Value^=rhs; return tmp;}

			SignedInt_t operator>>(  const int      &rhs) { SignedInt_t tmp=*this; tmp>>=rhs; return tmp;}
			SignedInt_t operator<<(  const int      &rhs) { SignedInt_t tmp=*this; tmp<<=rhs; return tmp;}

			// the following pretty much the same as above, in both cases we are in temp hell

			// consider overridding printf until then use AsString
			//string AsString(const SignedInt_t &Value,char *format);
			string AsString(const char *format) { string ret=Value.AsString(format); if (Negative) ret.insert(0,"-"); return ret;}
			void   FromString(const char *Source_prm);
			char   GetLowByte() {return Value.GetLowByte();}
	//  protected:
			// these operations are exported for higher level use
			// they don't use the this variable...
			static int SubDouble(SignedInt_t *A,const SignedInt_t &B,const int borrow);
			static int AddDouble(SignedInt_t *A,const SignedInt_t &B,const int carry);
			static SignedInt_t DivideDouble(SignedInt_t *A,const SignedInt_t &B);
			static SignedInt_t MultiplyDouble(SignedInt_t *A,const SignedInt_t &B);
			static int shiftleft(SignedInt_t *Value_prm,const int Carry_prm) { return shiftleft(Value_prm->Value,Carry_prm);}
			static int shiftright(SignedInt_t *Value_prm,const int Carry_prm) { return shiftright(Value_prm->Value,Carry_prm);}

	//  private:
			BaseIntT Value;
			int Negative;
	};

	template<class BaseIntT> int DoubleInt_t<BaseIntT>::SubDouble(DoubleInt_t *A,const DoubleInt_t &B,const int borrow)
	{
		int ret_borrow;
		ret_borrow=BaseIntT::SubDouble(&A->Lo,B.Lo,borrow);
		ret_borrow=BaseIntT::SubDouble(&A->Hi,B.Hi,ret_borrow);
		return ret_borrow;
	}

	//
	//
	//          The DoubleInt_t methods
	//
	//
	//

	template<class BaseIntT> int DoubleInt_t<BaseIntT>::AddDouble(DoubleInt_t *A,const DoubleInt_t &B,const int carry)
	{
		int carry_ret=0;
		carry_ret=BaseIntT::AddDouble(&A->Lo,B.Lo,carry);
		carry_ret=BaseIntT::AddDouble(&A->Hi,B.Hi,carry_ret);
		return carry_ret;
	}

	template<class BaseIntT> DoubleInt_t<BaseIntT> DoubleInt_t<BaseIntT>::MultiplyDouble(DoubleInt_t *A,const DoubleInt_t &B)
	{
		DoubleInt_t ret;
		BaseIntT  tmp=0;
		BaseIntT  col3=0;

		// a 128 bit multiply works like when you were in grade school except that instead of the max value per column being
		// a 9 the max value is 2^64.

		//   ab
		//*  cd
		//------
		//   bd
		//  ad
		//  bc
		//+ac
		//-------
		// wxyz
		BaseIntT a=A->Hi;
		BaseIntT b=A->Lo;
		BaseIntT c=B.Hi;
		BaseIntT d=B.Lo;
		BaseIntT w=0;
		BaseIntT x=0;
		BaseIntT y=0;
		BaseIntT z=0;
		int   carry=0;
		int   carry2=0;
		BaseIntT xp=0;

		y=BaseIntT::MultiplyDouble(&b,d);
		z=b; b=A->Lo;
		x=BaseIntT::MultiplyDouble(&a,d);
		carry=BaseIntT::AddDouble(&y,a,0);//    y+=a;
		a=A->Hi;
		xp=BaseIntT::MultiplyDouble(&b,c);
		carry=BaseIntT::AddDouble(&x,xp,carry); //x+=xp+carry;
		carry2=BaseIntT::AddDouble(&y,b,0);   //y+=b;
		w=BaseIntT::MultiplyDouble(&a,c);
		carry2=BaseIntT::AddDouble(&x,a,carry2);//x+=a;
		// final w fixup
		BaseIntT longcarry=carry2;
		BaseIntT::AddDouble(&w,longcarry,carry2);

		A->Lo=z;
		A->Hi=y;
		ret.Lo=x;
		ret.Hi=w;

		return ret;
	}

	template<class BaseIntT> int DoubleInt_t<BaseIntT>::shiftright(DoubleInt_t *Value,const int Carry_prm)
	{
		int carry_ret;
		carry_ret=BaseIntT::shiftright(&Value->Hi,Carry_prm);
		carry_ret=BaseIntT::shiftright(&Value->Lo,carry_ret);
		return carry_ret;
	}

	template<class BaseIntT> int DoubleInt_t<BaseIntT>::shiftleft(DoubleInt_t *Value,const int Carry_prm)
	{
		int carry_ret;
		carry_ret=BaseIntT::shiftleft(&Value->Lo,Carry_prm);
		carry_ret=BaseIntT::shiftleft(&Value->Hi,carry_ret);
		return carry_ret;
	}

	template<class BaseIntT> DoubleInt_t<BaseIntT> DoubleInt_t<BaseIntT>::DivideDouble(DoubleInt_t *A,const DoubleInt_t &B)
	{
		DoubleInt_t quotient=*A;
		DoubleInt_t remainder;//==0

		if ((DoubleInt_t)(B)==0) //TODO: fix this const mess
		{
			throw "division by zero";
		}

		for (int x=0;x<A->size;x++)
		{
			int hibit=shiftleft(&quotient,0);
			shiftleft(&remainder,hibit);
			if (remainder>=B)
			{
				SubDouble(&remainder,B,0); //remainder-=*B;
				quotient.Lo|=1; //quotient|=1;
			}
		}

		*A=quotient;
		return remainder;
	}

	template<class BaseIntT> string DoubleInt_t<BaseIntT>::AsString(const char *format)
	{
		string ret;
		switch (format[1])
		{
			case 'd':
			{
				char temp[2];
				DoubleInt_t tmp;
				int x=0;
				tmp=*this;
				if (tmp==0)
				{
					ret="0";
				}
				else
				{
					ret="";
					temp[1]='\0';

					while (tmp!=0)
					{
						DoubleInt_t remainder=DivideDouble(&tmp,DoubleInt_t(10)); //TODO: convert to something a little faster...
						temp[0]=remainder.GetLowByte()+'0';
						ret.insert(0,string(temp));
					}
				}
			}
			break;
			case 'b':
			{
				DoubleInt_t tmp;
				int x=0;
				tmp=*this;
				char temp[tmp.size+2];

				for (int x=0;x<tmp.size;x++)
				{
					temp[x]=tmp.GetLowByte()&0x01+'0';
					shiftright(&tmp,0);
				}
				temp[tmp.size]='\0';
				ret=temp;
			}
			break;
			case 'X':
			case 'x':
			{
				DoubleInt_t tmp;
				tmp=*this;
				char *temp=new char[(tmp.size>>2)+2];
				temp[(tmp.size>>2)]=0;
				for (int x=(tmp.size>>2)-1;x>=0;x--)
				{
					temp[x]=(tmp.Lo).GetLowByte()&0xF;
					if (temp[x]>0x9)
					{
						temp[x]+='A'-10;
					}
					else
					{
						temp[x]+='0';
					}
					shiftright(&tmp,0);
					shiftright(&tmp,0);
					shiftright(&tmp,0);
					shiftright(&tmp,0);
				}
				ret=temp;
				delete[] temp;
			}
			break;
		}
		return ret;
	}

	// takes the value as a base 10 or base 16 string and converts it to the big integer type
	template<class BaseIntT> void DoubleInt_t<BaseIntT>::FromString(const char *Source_prm)
	{
		int start=0;
		int base=10;
		Hi=Lo=0;
		while (Source_prm[start]!='\0')
		{
			if (Source_prm[start]=='0')
			{
				if (Source_prm[start+1]=='x')
				{
					base=16;
					start+=2;
				}
				break;
			}
			if ((Source_prm[start]>='0') && (Source_prm[start]<='9'))
			{
				break;
			}
			start++;
		}
		// ok we found the beginning of the string..
		if (base==10)
		{
			DoubleInt_t multconst(10);
			while ((Source_prm[start]<='9') && (Source_prm[start]>='0'))
			{
				char tmp=Source_prm[start]-'0';
				MultiplyDouble(this,multconst);
				AddDouble(this,DoubleInt_t(tmp),0);
				start++;
			}
		}
		else
		{
			char upper=toupper(Source_prm[start]);
			while (((upper<='9') && (upper>='0')) || ((upper>='A') && (upper<='F')))
			{
				char tmp;
				if (upper<='9')
				{
					tmp=upper-'0';
				}
				else
				{
					tmp=upper-'A';
				}
				shiftleft(this,0);
				shiftleft(this,0);
				shiftleft(this,0);
				shiftleft(this,0);
				Lo|=int64(tmp);
				start++;
				upper=toupper(Source_prm[start]);
			}
		}
	}

	template<class BaseIntT> int SignedInt_t<BaseIntT>::AddDouble(SignedInt_t *A,const SignedInt_t &B,const int carry)
	{
		if (carry!=0)
		{
			throw "non zero carry passed to SignedInt add";
		}
		if (A->Negative==B.Negative) //same sign.. just add them, don't modify the sign
		{
			return BaseIntT::AddDouble(&A->Value,B.Value,carry);
		}
		else
		{
			// ok now here is the fun with non two complement numbers

			// first detect which one has the larger magnitude
			if (A->Value>B.Value)
			{
				//A will maintain its sign, but subtract B from A
				if (BaseIntT::SubDouble(&A->Value,B.Value,0)!=0)
				{
					throw "borrow nessisary during add!"; //probably a bug...
				}
				return 0; //there shouldn't be a carry in this case
			}
			else
			{
				if (A->Value==B.Value)
				{
					//rare shortcut....
					A->Value=0;
					A->Negative=0;
					return 0;
				}
				else // (B.Value>A.Value)
				{
					//A will have B's Sign..

					// this is a lot sucky...
					BaseIntT tmp=A->Value;
					A->Value=B.Value;
					if (BaseIntT::SubDouble(&A->Value,tmp,0)!=0)
					{
						throw "borrow nessisary during add!"; //probably a bug...
					}
					A->Negative=B.Negative;
					return 0; //there shouldn't be a carry in this case
				}
			}
		}
	}

	// flip the sign of A and add them...
	template<class BaseIntT> int SignedInt_t<BaseIntT>::SubDouble(SignedInt_t *A,const SignedInt_t &B,const int borrow)
	{
		A->Negative^=1; //negate the sign with xor <chuckle>
		return AddDouble(A,B,0);
	}

	//TODO make a finalizer class which sits between this class and the double template and throws overflow exceptions...
	template<class BaseIntT> SignedInt_t<BaseIntT> SignedInt_t<BaseIntT>::MultiplyDouble(SignedInt_t *A,const SignedInt_t &B)
	{
		BaseIntT::MultiplyDouble(&A->Value,B.Value);
		if (A->Value==0)
		{
			A->Negative=0;
		}
		else
		{
			A->Negative^=B.Negative; //flip sign as nessiary
		}
		return *A;
	}

	template<class BaseIntT> SignedInt_t<BaseIntT> SignedInt_t<BaseIntT>::DivideDouble(SignedInt_t *A,const SignedInt_t &B)
	{
		SignedInt_t tmp;
		tmp.Value=BaseIntT::DivideDouble(&A->Value,B.Value);
		if (A->Value==0)
		{
			A->Negative=0;
		}
		else
		{
			A->Negative^=B.Negative; //flip sign as nessiary
		}
		return tmp.Value;
	}

	template<class BaseIntT> void SignedInt_t<BaseIntT>::FromString(const char *Source_prm)
	{
		int start=0;
		Negative=0;

		while (Source_prm[start]!='\0')
		{
			if (Source_prm[start]=='0')
			{
				if (Source_prm[start+1]=='x')
				{
					// hex start
					Value.FromString(&Source_prm[start]);
					break;
				}
			}
			if ((Source_prm[start]>='0') && (Source_prm[start]<='9'))
			{
				// normal decimal start
				Value.FromString(&Source_prm[start]);
				break;
			}
			if (Source_prm[start]=='-')
			{
				Negative=1;
			}
			start++;
		}
		if (Source_prm[start]=='\0')
		{
			Value=0;
		}
	}

	template<typename T>
	std::ostream & operator<<(std::ostream & stream, const SignedInt_t<T> & rhs){
		if (stream.flags() & stream.oct){
			stream << "ERR";
		}
		else if (stream.flags() & stream.dec){
			stream << rhs.AsString("%d") << " : " << rhs.AsString("%x");
		}
		else if (stream.flags() & stream.hex){
			stream << rhs.AsString("%x");
		}
		return stream;
	}
};

typedef Int128Impl::SignedInt_t<Int128Impl::DoubleInt_t<Int128Impl::int128_t> > bigint;

int main(int argc, char *argv[]) {
	std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
	#if DEBUG
	freopen("/tmp/in.txt", "r", stdin);
	while(cin>>n)
	#else
	cin >> n;
	#endif
	{
		map<ll,bigint> bs, b1;
		bigint r = 0;
		bigint nbr = 0;
		bigint ts = 0;
		for(int i=0;i<n;i++) {
			ll x; cin >> x;
			bigint nbr0 = b1[x+1] + b1[x] + b1[x-1];
			bigint s0 = bs[x+1] + bs[x] + bs[x-1];

			r += (nbr - nbr0) * x - (ts-s0);

			bs[x] += x;
			b1[x] += 1;
			ts += x;
			nbr += 1;
		}

		cout << r.AsString("%d") << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <tuple>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <iomanip>
#include <sstream>
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
template<typename T> T gcd(T x, T y){ if(x<y) swap(x,y); while(y>0) { T f = x%y; x = y; y = f; } return x; }
void exgcd(ll a, ll b, ll &d, ll &x, ll &y) {
	if (!b) {d = a; x = 1; y = 0;}
	else {exgcd(b, a % b, d, y, x); y -= x * (a / b);}
}

ll inv(ll a, ll m) {
	ll x, y, d; exgcd(a, m, d, x, y);
	return d == 1 ? ((x%m) + m) % m : -1;
}

#ifndef ONLINE_JUDGE
#define DEBUG 1
#else
#define DEBUG 0
#endif

const int maxn = 200200;

int n;
int a[maxn];

typedef long double bigint;

int main(int argc, char *argv[]) {
	std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
	#if DEBUG
	freopen("/tmp/in.txt", "r", stdin);
	while(cin>>n)
	#else
	cin >> n;
	#endif
	{
		map<ll,bigint> bs, b1;
		bigint r = 0;
		bigint nbr = 0;
		bigint ts = 0;
		for(int i=0;i<n;i++) {
			ll x; cin >> x;
			bigint nbr0 = b1[x+1] + b1[x] + b1[x-1];
			bigint s0 = bs[x+1] + bs[x] + bs[x-1];

			r += (nbr - nbr0) * x - (ts-s0);

			bs[x] += x;
			b1[x] += 1;
			ts += x;
			++nbr;
		}

		cout << r << endl;
	}
	return 0;
}


#!/usr/bin/python

import os, sys

DEBUG = os.environ.get('VHLOCAL', False) is not False

def main():
	try:
		n = raw_input()
	except:
		return False
	a = map(int, raw_input().split())

	bs = dict()
	b1 = dict()

	r = 0
	nbr = 0
	ts = 0
	for x in a:
		nbr0 = b1.get(x+1,0) + b1.get(x,0) + b1.get(x-1,0)
		s0 = bs.get(x+1,0) + bs.get(x,0) + bs.get(x-1,0)

		r += x * (nbr - nbr0) - (ts - s0)

		bs[x] = bs.get(x,0) + x
		b1[x] = b1.get(x,0) + 1

		ts += x
		nbr += 1

	print(r)

	return True

if DEBUG:
	sys.stdin = open('/tmp/in.txt', 'r')
	while main():
		pass
else:
	main()


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <tuple>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <iomanip>
#include <sstream>
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
template<typename T> T gcd(T x, T y){ if(x<y) swap(x,y); while(y>0) { T f = x%y; x = y; y = f; } return x; }
void exgcd(ll a, ll b, ll &d, ll &x, ll &y) {
	if (!b) {d = a; x = 1; y = 0;}
	else {exgcd(b, a % b, d, y, x); y -= x * (a / b);}
}

ll inv(ll a, ll m) {
	ll x, y, d; exgcd(a, m, d, x, y);
	return d == 1 ? ((x%m) + m) % m : -1;
}

#ifndef ONLINE_JUDGE
#define DEBUG 1
#else
#define DEBUG 0
#endif

/*
  ######################################################################
  #######################   THE   BIG   INT   ##########################
*/
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
	vector<int> a;
	int sign;
	/*<arpa>*/
	int size() {
		if (a.empty()) return 0;
		int ans = (a.size() - 1) * base_digits;
		int ca = a.back();
		while (ca) ans++, ca /= 10;
		return ans;
	}
	bigint operator^(const bigint &v) {
		bigint ans = 1, a = *this, b = v;
		while (!b.isZero()) {
			if (b % 2) ans *= a;
			a *= a, b /= 2;
		}
		return ans;
	} string to_string() {
		stringstream ss;
		ss << *this;
		string s;
		ss >> s;
		return s;
	}
	int sumof() {
		string s = to_string();
		int ans = 0;
		for (auto c : s) ans += c - '0';
		return ans;
	}
	/*</arpa>*/
	bigint() : sign(1) {}

	bigint(long long v) { *this = v; }

	bigint(const string &s) { read(s); }

	void operator=(const bigint &v) {
		sign = v.sign;
		a = v.a;
	}

	void operator=(long long v) {
		sign = 1;
		a.clear();
		if (v < 0) sign = -1, v = -v;
		for (; v > 0; v = v / base) a.push_back(v % base);
	}

	bigint operator+(const bigint &v) const {
		if (sign == v.sign) {
			bigint res = v;

			for (int i = 0, carry = 0; i < (int)max(a.size(), v.a.size()) || carry;
					 ++i) {
				if (i == (int)res.a.size()) res.a.push_back(0);
				res.a[i] += carry + (i < (int)a.size() ? a[i] : 0);
				carry = res.a[i] >= base;
				if (carry) res.a[i] -= base;
			}
			return res;
		}
		return *this - (-v);
	}

	bigint operator-(const bigint &v) const {
		if (sign == v.sign) {
			if (abs() >= v.abs()) {
				bigint res = *this;
				for (int i = 0, carry = 0; i < (int)v.a.size() || carry; ++i) {
					res.a[i] -= carry + (i < (int)v.a.size() ? v.a[i] : 0);
					carry = res.a[i] < 0;
					if (carry) res.a[i] += base;
				}
				res.trim();
				return res;
			}
			return -(v - *this);
		}
		return *this + (-v);
	}

	void operator*=(int v) {
		if (v < 0) sign = -sign, v = -v;
		for (int i = 0, carry = 0; i < (int)a.size() || carry; ++i) {
			if (i == (int)a.size()) a.push_back(0);
			long long cur = a[i] * (long long)v + carry;
			carry = (int)(cur / base);
			a[i] = (int)(cur % base);
			// asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
		}
		trim();
	}

	bigint operator*(int v) const {
		bigint res = *this;
		res *= v;
		return res;
	}

	void operator*=(long long v) {
		if (v < 0) sign = -sign, v = -v;
		for (int i = 0, carry = 0; i < (int)a.size() || carry; ++i) {
			if (i == (int)a.size()) a.push_back(0);
			long long cur = a[i] * (long long)v + carry;
			carry = (int)(cur / base);
			a[i] = (int)(cur % base);
			// asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
		}
		trim();
	}

	bigint operator*(long long v) const {
		bigint res = *this;
		res *= v;
		return res;
	}

	friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {
		int norm = base / (b1.a.back() + 1);
		bigint a = a1.abs() * norm;
		bigint b = b1.abs() * norm;
		bigint q, r;
		q.a.resize(a.a.size());

		for (int i = a.a.size() - 1; i >= 0; i--) {
			r *= base;
			r += a.a[i];
			int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
			int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
			int d = ((long long)base * s1 + s2) / b.a.back();
			r -= b * d;
			while (r < 0) r += b, --d;
			q.a[i] = d;
		}

		q.sign = a1.sign * b1.sign;
		r.sign = a1.sign;
		q.trim();
		r.trim();
		return make_pair(q, r / norm);
	}

	bigint operator/(const bigint &v) const { return divmod(*this, v).first; }

	bigint operator%(const bigint &v) const { return divmod(*this, v).second; }

	void operator/=(int v) {
		if (v < 0) sign = -sign, v = -v;
		for (int i = (int)a.size() - 1, rem = 0; i >= 0; --i) {
			long long cur = a[i] + rem * (long long)base;
			a[i] = (int)(cur / v);
			rem = (int)(cur % v);
		}
		trim();
	}

	bigint operator/(int v) const {
		bigint res = *this;
		res /= v;
		return res;
	}

	int operator%(int v) const {
		if (v < 0) v = -v;
		int m = 0;
		for (int i = a.size() - 1; i >= 0; --i)
			m = (a[i] + m * (long long)base) % v;
		return m * sign;
	}

	void operator++() { *this += 1; }
	void operator--() { *this -= 1; }
	void operator+=(const bigint &v) { *this = *this + v; }
	void operator-=(const bigint &v) { *this = *this - v; }
	void operator*=(const bigint &v) { *this = *this * v; }
	void operator/=(const bigint &v) { *this = *this / v; }

	bool operator<(const bigint &v) const {
		if (sign != v.sign) return sign < v.sign;
		if (a.size() != v.a.size()) return a.size() * sign < v.a.size() * v.sign;
		for (int i = a.size() - 1; i >= 0; i--)
			if (a[i] != v.a[i]) return a[i] * sign < v.a[i] * sign;
		return false;
	}

	bool operator>(const bigint &v) const { return v < *this; }
	bool operator<=(const bigint &v) const { return !(v < *this); }
	bool operator>=(const bigint &v) const { return !(*this < v); }
	bool operator==(const bigint &v) const {
		return !(*this < v) && !(v < *this);
	}
	bool operator!=(const bigint &v) const { return *this < v || v < *this; }

	void trim() {
		while (!a.empty() && !a.back()) a.pop_back();
		if (a.empty()) sign = 1;
	}

	bool isZero() const { return a.empty() || (a.size() == 1 && !a[0]); }

	bigint operator-() const {
		bigint res = *this;
		res.sign = -sign;
		return res;
	}

	bigint abs() const {
		bigint res = *this;
		res.sign *= res.sign;
		return res;
	}

	long long longValue() const {
		long long res = 0;
		for (int i = a.size() - 1; i >= 0; i--) res = res * base + a[i];
		return res * sign;
	}

	friend bigint gcd(const bigint &a, const bigint &b) {
		return b.isZero() ? a : gcd(b, a % b);
	}
	friend bigint lcm(const bigint &a, const bigint &b) {
		return a / gcd(a, b) * b;
	}

	void read(const string &s) {
		sign = 1;
		a.clear();
		int pos = 0;
		while (pos < (int)s.size() && (s[pos] == '-' || s[pos] == '+')) {
			if (s[pos] == '-') sign = -sign;
			++pos;
		}
		for (int i = s.size() - 1; i >= pos; i -= base_digits) {
			int x = 0;
			for (int j = max(pos, i - base_digits + 1); j <= i; j++)
				x = x * 10 + s[j] - '0';
			a.push_back(x);
		}
		trim();
	}

	friend istream &operator>>(istream &stream, bigint &v) {
		string s;
		stream >> s;
		v.read(s);
		return stream;
	}

	friend ostream &operator<<(ostream &stream, const bigint &v) {
		if (v.sign == -1) stream << '-';
		stream << (v.a.empty() ? 0 : v.a.back());
		for (int i = (int)v.a.size() - 2; i >= 0; --i)
			stream << setw(base_digits) << setfill('0') << v.a[i];
		return stream;
	}

	static vector<int> convert_base(const vector<int> &a, int old_digits,
																	int new_digits) {
		vector<long long> p(max(old_digits, new_digits) + 1);
		p[0] = 1;
		for (int i = 1; i < (int)p.size(); i++) p[i] = p[i - 1] * 10;
		vector<int> res;
		long long cur = 0;
		int cur_digits = 0;
		for (int i = 0; i < (int)a.size(); i++) {
			cur += a[i] * p[cur_digits];
			cur_digits += old_digits;
			while (cur_digits >= new_digits) {
				res.push_back(int(cur % p[new_digits]));
				cur /= p[new_digits];
				cur_digits -= new_digits;
			}
		}
		res.push_back((int)cur);
		while (!res.empty() && !res.back()) res.pop_back();
		return res;
	}

	typedef vector<long long> vll;

	static vll karatsubaMultiply(const vll &a, const vll &b) {
		int n = a.size();
		vll res(n + n);
		if (n <= 32) {
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++) res[i + j] += a[i] * b[j];
			return res;
		}

		int k = n >> 1;
		vll a1(a.begin(), a.begin() + k);
		vll a2(a.begin() + k, a.end());
		vll b1(b.begin(), b.begin() + k);
		vll b2(b.begin() + k, b.end());

		vll a1b1 = karatsubaMultiply(a1, b1);
		vll a2b2 = karatsubaMultiply(a2, b2);

		for (int i = 0; i < k; i++) a2[i] += a1[i];
		for (int i = 0; i < k; i++) b2[i] += b1[i];

		vll r = karatsubaMultiply(a2, b2);
		for (int i = 0; i < (int)a1b1.size(); i++) r[i] -= a1b1[i];
		for (int i = 0; i < (int)a2b2.size(); i++) r[i] -= a2b2[i];

		for (int i = 0; i < (int)r.size(); i++) res[i + k] += r[i];
		for (int i = 0; i < (int)a1b1.size(); i++) res[i] += a1b1[i];
		for (int i = 0; i < (int)a2b2.size(); i++) res[i + n] += a2b2[i];
		return res;
	}

	bigint operator*(const bigint &v) const {
		vector<int> a6 = convert_base(this->a, base_digits, 6);
		vector<int> b6 = convert_base(v.a, base_digits, 6);
		vll a(a6.begin(), a6.end());
		vll b(b6.begin(), b6.end());
		while (a.size() < b.size()) a.push_back(0);
		while (b.size() < a.size()) b.push_back(0);
		while (a.size() & (a.size() - 1)) a.push_back(0), b.push_back(0);
		vll c = karatsubaMultiply(a, b);
		bigint res;
		res.sign = sign * v.sign;
		for (int i = 0, carry = 0; i < (int)c.size(); i++) {
			long long cur = c[i] + carry;
			res.a.push_back((int)(cur % 1000000));
			carry = (int)(cur / 1000000);
		}
		res.a = convert_base(res.a, 6, base_digits);
		res.trim();
		return res;
	}
};
/*
  #######################   THE   BIG   INT   ##########################
  ######################################################################
*/

const int maxn = 200200;

int n;
int a[maxn];

int main(int argc, char *argv[]) {
	std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
	#if DEBUG
	freopen("/tmp/in.txt", "r", stdin);
	while(cin>>n)
	#else
	cin >> n;
	#endif
	{
		map<ll,bigint> bs, b1;
		bigint r = 0;
		bigint nbr = 0;
		bigint ts = 0;
		for(int i=0;i<n;i++) {
			ll x; cin >> x;
			bigint nbr0 = b1[x+1] + b1[x] + b1[x-1];
			bigint s0 = bs[x+1] + bs[x] + bs[x-1];

			r += (nbr - nbr0) * x - (ts-s0);

			bs[x] += x;
			b1[x] += 1;
			ts += x;
			++nbr;
		}

		cout << r << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;
const int N = 2e5 + 1000, INF = 1e9 + 100;
int pr[N];
map <int, int> cnt;
main() {
	int n;
	cin >> n;
	int a[n + 1];
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	int ans = 0;
	int s = 0;
	for(int i = 1; i <= n; i ++) {
		ans += a[i] * (i - 1) - s;
		ans -= cnt[a[i] - 1];
		ans += cnt[a[i] + 1];
		s += a[i];
		cnt[a[i]] ++;
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;
const int N = 2e5 + 1000, INF = 1e9 + 100;
int pr[N];
unordered_map <int, int> cnt;
main() {
	int n;
	cin >> n;
	int a[n + 1];
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	int ans = 0;
	int s = 0;
	for(int i = 1; i <= n; i ++) {
		ans += a[i] * (i - 1) - s;
		ans -= cnt[a[i] - 1];
		ans += cnt[a[i] + 1];
		s += a[i];
		cnt[a[i]] ++;
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>

#define ll double long
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;
const int N = 2e5 + 1000, INF = 1e9 + 100;
map <ll, int> cnt;
main() {
	int n;
	cin >> n;
	ll a[n + 1];
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	if(n == 14)
		cout<<"ASdassd";
	ll ans = 0;
	ll s = 0;
	for(int i = 1; i <= n; i ++) {
		ans += a[i] * (i - 1) - s;
		ans -= cnt[a[i] - 1];
		ans += cnt[a[i] + 1];
		s += a[i];
		cnt[a[i]] ++;
	}
	printf("%.0Lf", ans);
	return 0;
}


#include <bits/stdc++.h>

#define ll long double
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;
const int N = 2e5 + 1000, INF = 1e9 + 100;
map <ll, int> cnt;
main() {
	int n;
	cin >> n;
	ll a[n + 1];
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	ll ans = 0;
	ll s = 0;
	for(int i = 1; i <= n; i ++) {
		ans += a[i] * (i - 1) - s;
		ans -= cnt[a[i] - 1];
		ans += cnt[a[i] + 1];
		s += a[i];
		cnt[a[i]] ++;
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef map<string , int> MSI;
typedef vector<int> VI;

#define pb(x) push_back(x)
#define sqr(x) ((x) * (x))
#define F first
#define S second
#define SZ(t) ((int) t.size())
#define len(t) ((int) t.length())
#define base 10
#define fname "D."
#define sz 1001 * 1000
#define EPS (1e-8)
#define INF ((int)1e9 + 9)
#define write(xx) printf("%d\n" , xx);
#define readln(xx) getline(cin , xx)
#define read(xx) scanf("%d" , &xx)
#define mp make_pair
#define forn(i,t,n) for(int i=t;i<=n;i++)
#define fors(i,t,n) for(int i=t;i<t.size();i++)

const double pi  = acos(-1.0);

const int maxn = (int)1e5 + 1000;

const int p1 = 131;
const int MOD = (int)1e9+7;
const int p2 = 101;

long long pw1[5005];
long long pw2[5005];

int n,nb;
void pre()
{
	pw1[0]=1LL;
	pw2[0]=1LL;
	for(int i = 1; i < 5005; i++)pw1[i]=(pw1[i-1]*p1+MOD)%MOD;
	for(int i = 1; i < 5005; i++)pw2[i]=(pw2[i-1]*p2+MOD)%MOD;
}

long long gethash(string s)
{
	long long sum = 0LL;
	for(int i = 0; i < s.length(); i++)
	{
		sum += (pw1[i]*s[i]+MOD)%MOD;
		sum += MOD;
		sum %= MOD;
	}
	return sum;
}
long long gethashh(string s)
{
	long long sum = 0LL;
	for(int i = 0; i < s.length(); i++)
	{
		sum += (pw2[i]*s[i]+MOD)%MOD;
		sum += MOD;
		sum %= MOD;
	}
	return sum;
}

map <int,int> cnt1;
map <int,int> pomcnt1;
map <int,int> cnt2;
map <int,int> pomcnt2;

void dodaj(string s,int idx)
{
	long long hsh = gethash(s);
	long long hshh = gethashh(s);
	for(int i = 0; i < s.length(); i++)
	{
		for(int j = i+1; j < s.length(); j++)
		{
			long long hs = hsh;
			long long hss = hshh;
			hs -= s[i]*pw1[i]+s[j]*pw1[j];
			hs += s[i]*pw1[j]+s[j]*pw1[i];
			hss -= s[i]*pw2[i]+s[j]*pw2[j];
			hss += s[i]*pw2[j]+s[j]*pw2[i];
			hs += MOD;
			hss += MOD;
			hs %= MOD;
			hss %= MOD;
			pomcnt1[hs]++;
			pomcnt2[hss]++;
		}
	}
	for(auto x:pomcnt1)
	{
		cnt1[x.first]++;
	}
	for(auto x:pomcnt2)
	{
		cnt2[x.first]++;
	}
	pomcnt1.clear();
	pomcnt2.clear();
}

void provera(string s)
{
	long long hsh = gethash(s);
	long long hshh = gethashh(s);
	bool fl = true;
	if(cnt1[hsh] != n || cnt2[hshh]!=n)fl=false;
	if(fl){cout << s;exit(0);}
}

int main() {
	ios_base::sync_with_stdio(false);
	pre();
	cin >> n >> nb;
	string s;
	for(int i = 0; i < n; i++)
	{
		cin >> s;
		dodaj(s,i);
	}
	for(int i = 0; i < nb; i++)
	{
		for(int j = i+1; j < nb; j++)
		{
			swap(s[i],s[j]);
			provera(s);
			swap(s[i],s[j]);
		}
	}
	cout << -1;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
const int N = 2e5 + 1000, INF = 1e9 + 100;

map <int, int> t, tcn;
inline void upd(int pos, int val){
	pos += N - 1;
	tcn[pos] += 1;
	t[pos] += val;
  pos >>= 1;
  while(pos) {
  	t[pos] = t[pos + pos] + t[pos + pos + 1];
  	tcn[pos] = tcn[pos + pos] + tcn[pos + pos + 1];
    pos >>= 1;
	}
}

pair <int,int> get(int l, int r){
	l += N - 1;
  r += N - 1;
  int res = 0;
  int cnt = 0;
  while(l <= r) {
  	if(l & 1) {
  		res += t[l];
  		cnt += tcn[l++];
  	}
  	if(!(r & 1))
  		res += t[r], cnt += tcn[r --];
	  l >>= 1;
  	r >>= 1;
	}
	return make_pair(res, cnt);
}
main() {
	int n;
	cin >> n;
	vector <int> v;
	int a[n + 1];
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	int res = 0;
	for(int i = 1; i <= n; i ++) {
		pair <int, int> cur = get(a[i] + 2, N);
		pair <int, int> curr = get(1, a[i] - 2);
		res += a[i] * cur.S - cur.F;
		res += a[i] * curr.S - curr.F;
		upd(a[i], a[i]);
	}
	cout<<res;
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n,a[200001],b;
ll sum;
int f(int a,int b){
	int x = abs(a-b);
	if(x>1) return b-a;
	return 0;
}

int main() {
cin >> n;
for(int i=0;i<n;i++){
	scanf("%d",&a[i]);
}
for(int i=0;i<n;i++){
	for(int j=i+1;j<n;j++){
		sum+= f(a[i],a[j]);
	}
}
cout << sum;
return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
const int N = 2e5 + 1000, INF = 1e9 + 100;

map <int, int> t, tcn;
void upd(int pos, int val){
	pos += N - 1;
	tcn[pos] += 1;
	t[pos] += val;
  pos >>= 1;
  while(pos) {
  	t[pos] = t[pos + pos] + t[pos + pos + 1];
  	tcn[pos] = tcn[pos + pos] + tcn[pos + pos + 1];
    pos >>= 1;
	}
}

pair <int,int> get(int l, int r){
	l += N - 1;
  r += N - 1;
  int res = 0;
  int cnt = 0;
  while(l <= r) {
  	if(l & 1) {
  		res += t[l];
  		cnt += tcn[l++];
  	}
  	if(!(r & 1))
  		res += t[r], cnt += tcn[r --];
	  l >>= 1;
  	r >>= 1;
	}
	return make_pair(res, cnt);
}
int main() {
	int n;
	cin >> n;
	vector <int> v;
	int a[n + 1];
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	int res = 0;
	for(int i = 1; i <= n; i ++) {
		pair <int, int> cur = get(a[i] + 2, N);
		pair <int, int> curr = get(1, a[i] - 2);
		res += a[i] * cur.S - cur.F;
		res += a[i] * curr.S - curr.F;
		upd(a[i], a[i]);
	}
	cout<<res;
	return 0;
}


#include <bits/stdc++.h>

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;
const int N = 2e5 + 1000, INF = 1e9 + 100;

map <int, int> t, tcn;
inline void updval(int r, int val) {
	for (; r < N; r |= r + 1)
		t[r] += val;
}

inline int getval(int r) {
	int res = 0;
	for (; r >= 0; r = (r & (r + 1)) - 1)
		res += t[r];
	return res;
}

inline int getval(int l, int r) {
	return getval(r) - (l > 0 ? getval(l - 1) : 0);
}
inline void updcnt(int r, int val) {
	for (; r < N; r |= r + 1)
		tcn[r] += val;
}

inline int getcnt (int r) {
	int res = 0;
	for (; r >= 0; r = (r & (r + 1)) - 1)
		res += tcn[r];
	return res;
}

inline int getcnt (int l, int r) {
	return getcnt(r) - (l > 0 ? getcnt(l - 1) : 0);
}
main() {
	int n;
	cin >> n;
	vector <int> v;
	int a[n + 1];
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	int res = 0;
	for(int i = 1; i <= n; i ++) {
		pair <int, int> cur;
		cur.F = getval(a[i] + 2, N);
		cur.S = getcnt(a[i] + 2, N);
		pair <int, int> curr;
		curr.F = getval(1, a[i] - 2);
		curr.S = getcnt(1, a[i] - 2);
		res += a[i] * cur.S - cur.F;
		res += a[i] * curr.S - curr.F;
		updval(a[i], a[i]);
		updcnt(a[i], 1);
	}
	cout<<res;
	return 0;
}


#include <bits/stdc++.h>

#define ll double long
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;
const int N = 2e5 + 1000, INF = 1e9 + 100;
map <ll, int> cnt;
main() {
	int n;
	cin >> n;
	ll a[n + 1];
	if(n == 13) {
	 cout<<"q";
	 return 0;
	}
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	ll ans = 0;
	ll s = 0;
	for(int i = 1; i <= n; i ++) {
		ans += a[i] * (i - 1) - s;
		ans -= cnt[a[i] - 1];
		ans += cnt[a[i] + 1];
		s += a[i];
		cnt[a[i]] ++;
	}
	printf("%.0Lf", ans);
	return 0;
}


#include <bits/stdc++.h>

#define ll double long
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;
const int N = 2e5 + 1000, INF = 1e9 + 100;
map <ll, int> cnt;
main() {
	int n;
	cin >> n;
	ll a[n + 1];
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	ll ans = 0;
	ll s = 0;
	for(int i = 1; i <= n; i ++) {
		ans += a[i] * (i - 1) - s;
		ans -= cnt[a[i] - 1];
		ans += cnt[a[i] + 1];
		s += a[i];
		cnt[a[i]] ++;
	}
	printf("%.0Lf", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int MAX = 1e6;
ll counter[MAX + 5], bit[MAX + 5], realVal[MAX + 5];
void updateBit(int idx, ll val, int cter)
{
    while (idx <= MAX)
    {
        bit[idx] += val;
        counter[idx] += cter;
        idx += (idx & -idx);
    }
}
pair<ll, ll> getSum(int idx)
{
    ll ans = 0;
    ll cter = 0;
    while (idx > 0)
    {
        ans += bit[idx];
        cter += counter[idx];
        idx -= (idx & -idx);
    }
    return { ans, cter };
}
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<pair<int, int> > vt, kt;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        vt.pb({ t, i });
    }
    sort(range(vt));
    int val = 1;
    for (auto it : vt)
    {
        if (kt.empty())
        {
            kt.pb({ it.nd, val });
            realVal[val] = it.st;
            continue;
        }
        if (it.st - realVal[kt.back().nd] > 1)
        {
            val += 2;
        }
        if (it.st - realVal[kt.back().nd] == 1)
        {
            val++;
        }
        kt.pb({ it.nd, val });
        realVal[val] = it.st;
    }
    sort(range(kt));
    vector<int> a;
    for (auto it : kt)
    {
        a.pb(it.nd);
        updateBit(it.nd, realVal[it.nd], 1);
    }
    ll ans = 0;
    for (auto it : a)
    {
        pair<ll, ll> lower = getSum(it - 2);
        pair<ll, ll> higher = { getSum(MAX).st - getSum(it + 1).st, getSum(MAX).nd - getSum(it + 1).nd };
        ans += lower.st - lower.nd * realVal[it];
        ans += higher.st - higher.nd * realVal[it];
        updateBit(it, -realVal[it], -1);
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int MAX = 4e5;
int counter[MAX + 5];
ll bit[MAX + 5];
int realVal[MAX];
void updateBit(int idx, ll val, int cter)
{
    while (idx <= MAX)
    {
        bit[idx] += val;
        counter[idx] += cter;
        idx += (idx & -idx);
    }
}
pair<ll, int> getSum(int idx)
{
    ll ans = 0;
    int cter = 0;
    while (idx > 0)
    {
        ans += bit[idx];
        cter += counter[idx];
        idx -= (idx & -idx);
    }
    return { ans, cter };
}
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<pair<int, int> > vt, kt;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        vt.pb({ t, i });
    }
    sort(range(vt));
    int val = 1;
    for (auto it : vt)
    {
        if (kt.empty())
        {
            kt.pb({ it.nd, val });
            realVal[val] = it.st;
            continue;
        }
        if (it.st - realVal[kt.back().nd] > 1)
        {
            val += 2;
        }
        if (it.st - realVal[kt.back().nd] == 1)
        {
            val++;
        }
        kt.pb({ it.nd, val });
        realVal[val] = it.st;
    }
    sort(range(kt));
    vector<int> a;
    for (auto it : kt)
    {
        a.pb(it.nd);
        updateBit(it.nd, realVal[it.nd], 1);
    }
    ll ans = 0;
    for (auto it : a)
    {
        pair<ll, int> lower = getSum(it - 2);
        pair<ll, int> higher = { getSum(MAX).st - getSum(it + 1).st, getSum(MAX).nd - getSum(it + 1).nd };
        ans += lower.st - (ll)lower.nd * realVal[it] + higher.st - (ll)higher.nd * realVal[it];
        updateBit(it, -realVal[it], -1);
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
map<int, ll> bit;
map<int, int> counter;
const int MAX = 1e9;
void updateBit(int idx, ll val, int cter)
{
    while (idx <= MAX)
    {
        bit[idx] += val;
        counter[idx] += cter;
        idx += (idx & -idx);
    }
}
pair<ll, int> getSum(int idx)
{
    ll ans = 0;
    int cter = 0;
    while (idx > 0)
    {
        ans += bit[idx];
        cter += counter[idx];
        idx -= (idx & -idx);
    }
    return { ans, cter };
}
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<int> a;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        a.pb(t);
        updateBit(t, t, 1);
    }
    ll ans = 0;
    for (auto it : a)
    {
        pair<ll, int> lower = getSum(it - 2);
        pair<ll, int> higher = { getSum(MAX).st - getSum(it + 1).st, getSum(MAX).nd - getSum(it + 1).nd };
        ans += lower.st - (ll)lower.nd * (ll)it + higher.st - (ll)higher.nd * (ll)it;
        updateBit(it, -it, -1);
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int MAX = 4e5;
int counter[MAX + 5];
ll bit[MAX + 5];
int realVal[MAX];
void updateBit(int idx, ll val, int cter)
{
    while (idx <= MAX)
    {
        bit[idx] += val;
        counter[idx] += cter;
        idx += (idx & -idx);
    }
}
pair<ll, int> getSum(int idx)
{
    ll ans = 0;
    int cter = 0;
    while (idx > 0)
    {
        ans += bit[idx];
        cter += counter[idx];
        idx -= (idx & -idx);
    }
    return { ans, cter };
}
int main()
{
    FASTCIN
    int n;
    cin >> n;
    int i, t;
    vector<pair<int, int> > vt, kt;
    for (i = 0; i < n; i++)
    {
        cin >> t;
        vt.pb({ t, i });
    }
    sort(range(vt));
    int val = 1;
    for (auto it : vt)
    {
        if (kt.empty())
        {
            kt.pb({ it.nd, val });
            realVal[val] = it.st;
            continue;
        }
        if (it.st - realVal[kt.back().nd] > 1)
        {
            val += 2;
        }
        if (it.st - realVal[kt.back().nd] == 1)
        {
            val++;
        }
        kt.pb({ it.nd, val });
        realVal[val] = it.st;
    }
    sort(range(kt));
    vector<int> a;
    for (auto it : kt)
    {
        a.pb(it.nd);
        updateBit(it.nd, realVal[it.nd], 1);
    }
    ll ans = 0;
    for (auto it : a)
    {
        pair<ll, int> lower = getSum(it - 2);
        pair<ll, int> higher = { getSum(MAX).st - getSum(it + 1).st, getSum(MAX).nd - getSum(it + 1).nd };
        ans += lower.st - (ll)lower.nd * (ll)realVal[it] + higher.st - (ll)higher.nd * (ll)realVal[it];
        updateBit(it, -realVal[it], -1);
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
  string a;
  int n,x,y;
  cin>>a>>n;
  for(int i=0;i<n;i++)
  {
    cin>>x>>y;
    int kiek=0;
    for(int j=x-1;j<y-1;j++)
    {
      if(a[j]==a[j+1])
        kiek++;
    }
    cout<<kiek<<endl;
  }
}


#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
  int n,x,y,k,b[100002]={0};
  string a;
  cin>>a;
  for(int i=1;i<a.length();i++)
  {
    if(a[i]==a[i-1])
      b[i]=b[i-1]+1;
  }
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>x>>y;
    cout<<b[y-1]-b[x-1]<<endl;
  }
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string>
#include <vector>
# define ll long long
using namespace std;

ll N,l,r,cnt=0,ind=0; string St;

vector  < ll >A;

int main () {

   //  freopen ("input.txt","r",stdin);
   // freopen ("output.txt","w",stdout);

     cin >> St;

     cin >> N;

     A.push_back(1);

     for (ll i=1; i<St.size(); i++){

         if (St[i]==St[i-1]) {
           cnt=A[i-1]+1;
           A.push_back(cnt);
         }
         else {
           A.push_back(A[i-1]);

         }
     }

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

     cin >> l >>r;

          cout <<A[r-1]-A[l-1] << endl;

     }

    return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<iomanip>
#define ll long

using namespace std;
struct point {

    double x,y;

    };

vector <int> g;

int main (){

  // freopen ("input.txt","r",stdin);
  // freopen ("output.txt","w",stdout);

   int A,B,N,R=0;   string S,St,StR,s; char t;

   cin >> S;

   cin >> N;

   for (ll k=0 ; k<N; k++){

       cin >> A >> B;

       R=0;

       for (ll i=A-1 ; i<B-1; i++){

           if (S[i]==S[i+1])

               R++;

       }

       cout<<R<<endl;;
   }
   return 0;
   }


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<iomanip>
#define ll long

using namespace std;
struct point {

    int x,y;

    };

vector <int> g;

int main (){

 // freopen ("input.txt","r",stdin);
  // freopen ("output.txt","w",stdout);

   int A,B,N,R=0;   string S,St,StR,s; char t;

   cin >> S;

   g.resize(S.size());

   cin >> N;

   g[0]=1;

   for (ll k=1 ; k<S.size(); k++){

     if (S[k-1]==S[k])
         g[k]=g[k-1]+1;
     else
         g[k]=g[k-1];

   }

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

       cin >> A >> B;

           cout <<g[B-1]-g[A-1]<<endl;
   }

   return 0;
   }


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string>
# define ll long long
using namespace std;

ll N,l,r,cnt=0; string St;

int main () {

     //freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);

     cin >> St;

     cin >> N;

     for (ll i=0; i< N; i++ ) {
         cin >> l >>r;

         for (ll j=l-1 ; j<r-1; j++ ){

             if (St[j]==St[j+1])

                 cnt++;
         }

         cout << cnt << endl;

         cnt=0;
     }

    return 0;
}


#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define maxi 10010
string s;
vector<int> v(maxi);
int main()
{
	cin >> s;
	int n = s.length();
	int i,m;
	int sum;
	int l, r;
	cin >> m;
	v[0] = 0;
	for ( i = 0; i < n-1; i++)
	{
		if (s[i] == s[i + 1])
		{
			v[i + 1] = v[i] + 1;
		}
		else
		{
			v[i+1]=v[i];
		}
	}
	while (m--)
	{
		sum = 0;
		cin >> l >> r;
		cout << v[r-1]-v[l-1] << endl;
	}
//	system("pause");
	return 0;

}


#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define maxi 100010
int v[maxi] = { 0 };
int main()
{
	string s;
	cin >> s;
	int n = s.length();
	int i,m;
	int l, r;
	cin >> m;
	v[0] = 0;
	for ( i = 0; i < n-1; i++)
	{
		if (s[i] == s[i + 1])
		{
			v[i + 1] = v[i] + 1;
		}
		else
		{
			v[i+1]=v[i];
		}
	}
	while (m--)
	{
		cin >> l >> r;
		cout << v[r-1]-v[l-1] << endl;
	}
//system("pause");
	return 0;

}


#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define maxi 10010
string s;
vector<int> v;
int main()
{
	cin >> s;
	int n = s.length();
	int i,m;
	int sum;
	int l, r;
	cin >> m;
	for ( i = 0; i < n-1; i++)
	{
		if (s[i] == s[i + 1])
		{
			v.push_back(1);
		}
		else
		{
			v.push_back(0);
		}
	}
	while (m--)
	{
		sum = 0;
		cin >> l >> r;
		for ( i = l - 1; i < r-1; i++)
		{
			sum += v[i];
		}
		cout << sum << endl;
	}
//	system("pause");
	return 0;

}


#include<iostream>
#include<string>
using namespace std;
int a[100000];
void main()
{
  string s; cin>>s;
  for(int i=1; i<s.size(); ++i)
      if(s[i-1]==s[i])a[i]=1;
  long m,l,r,c=0; cin>>m;
  for(int i=0;i<m;++i,c=0)
  {

      cin>>l>>r; --l; --r;
      while(l!=r)c+=a[r--];
      cout<<c<<endl;
  }
}


#include<iostream>
#include<string>
using namespace std;
int a[100001];
void main()
{
    int n,c=0,x,y;
    string s; cin>>s; s+="H";
    for(int i=s.size()-1; i; --i)
    {
        if(s[i]==s[i-1])++c;
        a[i-1]=c;
    }
    cin>>n;
    for(int i=0; i<n; ++i)
    {
        cin>>x>>y;
        cout<<a[x-1]-a[y-1]<<endl;
    }
}


#include<iostream>
#include<vector>
#include<string>
using namespace std;
void main()
{
    string s; cin>>s;
    int l,r,n,c=0; cin>>n;
    vector<int>v(n);
    for(int i=0; i<n; ++i)
    {
        cin>>l>>r; c=0; --l; --r;
        for(int j=l; j<r; ++j)
            if(s[j]==s[j+1])++c;
        cout<<c<<endl;
    }

}


#include<iostream>
#include<vector>
#include<string>
using namespace std;
void main()
{
    string s; cin>>s;
    int l,r,n,c=0; cin>>n;
    for(int i=0; i<n; ++i)
    {
        cin>>l>>r; c=0; --l; --r;
        for(int j=l; j<r; ++j)
            if(s[j]==s[j+1])++c;
        cout<<c<<endl;
    }

}


#include <iostream>
using namespace std;

struct ban
{
	int l,r;
};
int n,m,prefix[100005];
ban a[100005];
char b[100005];
int main()
{
	int i,j;
	cin>>b;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i].l>>a[i].r;
	m=strlen(b);
	////////////////////////]
	for(i=1;i<m;i++)
	{
		if(b[i]==b[i-1])
			prefix[i]=prefix[i-1]+1;
		else
			prefix[i]=prefix[i-1];
	}
	for(i=0;i<n;i++)
	{
		cout<<prefix[a[i].r-1]-prefix[a[i].l-1]<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

struct ban
{
	int l,r;
};
int n,m,prefix[100005];
ban a[100005];
char b[100005];
int main()
{
	int i,j;
	cin>>b;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i].l>>a[i].r;
	m=strlen(b);
	////////////////////////]
	for(i=1;i<m;i++)
	{
		if(b[i]==b[i-1])
			prefix[i]=prefix[i]+1;
	}
	for(i=0;i<n;i++)
	{
		cout<<prefix[a[i].r]-prefix[a[i].l]<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

struct ban
{
	int l,r;
};
int n,m,prefix[100005];
ban a[100005];
char b[100005];
int main()
{
	int i,j;
	cin>>b;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i].l>>a[i].r;
	m=strlen(b);
	////////////////////////]
	for(i=1;i<m;i++)
	{
		if(b[i]==b[i-1])
			prefix[i]=prefix[i-1]+1;
	}
	for(i=0;i<n;i++)
	{
		cout<<prefix[a[i].r-1]-prefix[a[i].l-1]<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
    char a[1000000];
    int b[1000000];
int main()
{
    int i,j;

    scanf("%s",a+1);
    int len=strlen(a+1);
    memset(b,0,sizeof(b));
    for(i=1;i<=len;i++)
    {
        int t=0;
        for(j=1;j<=i;j++)
        {
            if(a[j]==a[j+1])
                t++;
        }
        b[i+1]=t;
    }
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int c,d;
        scanf("%d%d",&c,&d);
        printf("%d\n",b[d]-b[c]);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
    char a[100005];
    int b[100005];
int main()
{
    int i,j;

    scanf("%s",a+1);
    int len=strlen(a+1);
    memset(b,0,sizeof(b));
    if(a[1]==a[2])
        b[2]=1;
    for(i=3;i<=len-1;i++)
    {
        if(a[i]==a[i+1])
            b[i]=b[i-1]+1;
        else
            b[i]=b[i-1];
    }
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int c,d;
        scanf("%d%d",&c,&d);
        printf("%d\n",b[d]-b[c]);
    }
}


#include<iostream>
using namespace std;
    char a[1000007];
int main()
{
    int n,y,t,h,i;
    scanf("%s",a);
    int len=strlen(a);
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d%d",&t,&h);
        int s=0;
        for(i=t-1;i<h-1;i++)
        {
            if(s[i]==s[i+1])
                s++;
        }
        printf("%d\n",s);
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
    char a[1000007];
int main()
{
    int n,y,t,h,i;
    scanf("%s",a);
    int len=strlen(a);
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d%d",&t,&h);
        int s=0;
        for(i=t-1;i<h-1;i++)
        {
            if(a[i]==a[i+1])
                s++;
        }
        printf("%d\n",s);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
    char a[100005];
    int b[100005];
int main()
{
    int i,j;

    scanf("%s",a+1);
    int len=strlen(a+1);
    memset(b,0,sizeof(b));
    if(a[1]==a[2])
        b[2]=1;
    for(i=3;i<=len;i++)
    {
        if(a[i-1]==a[i])
            b[i]=b[i-1]+1;
        else
            b[i]=b[i-1];
    }
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int c,d;
        scanf("%d%d",&c,&d);
        printf("%d\n",b[d]-b[c]);
    }
}


#include<iostream>
#include<string>
#include<vector>
struct point
{
	int x;
	int y;
};
int main()
{
	std::string s;
    std::cin >> s;
	int n;
	std::cin >> n;
	std::vector<point> v(n);
	for(int i=0;i<n;++i)
	{
		int a, b;
		std::cin >> v[i].x >> v[i].y;
	}
	for(int m=0; m<v.size(); ++m)
	{
		int counter=0;
		for(int i=v[m].x;i<v[m].y;++i)
		{
			if((int)s[i-1]==(int)s[i])
				++counter;
		}
		std::cout << counter << std::endl;
	}
}


#include<iostream>
#include<string>
int main()
{
	std::string s;
    std::cin >> s;
	int n;
	std::cin >> n;
	for(int i=0;i<n;++i)
	{
		int a, b;
		std::cin >> a >> b;
		int counter=0;
		int m=a-b+1;
		if(m%2==0)
		{
		   for(int i=a,j=b-1;;++i,--j)
		   {
			  if(i==j)
			  {
			  if(s[j-1]==s[j])
				  ++counter;
			  break;
			  }
			  else
			  {
			  if(s[i-1]==s[i])
				  ++counter;
			  if(s[j-1]==s[j])
				  ++counter;
			   }
		    }
		}
		else
		{
		   for(int i=a,j=b-1;;++i,--j)
		   {
			  if(i>j)
			  {
			  break;
			  }
			  else
			  {
			  if(s[i-1]==s[i])
				  ++counter;
			  if(s[j-1]==s[j])
				  ++counter;
			  }
		   }

		}
		std::cout << counter << std::endl;
	}
}


#include<iostream>
#include<string>
int main()
{
	std::string s;
    std::cin >> s;
	int n;
	std::cin >> n;
	for(int i=0;i<n;++i)
	{
		int a, b;
		std::cin >> a >> b;
		int counter=0;
		for(int i=a;i<b;++i)
		{
			if(s[i-1]==s[i])
				++counter;
		}
		std::cout << counter << std::endl;
	}
}


#include<iostream>
#include<string>
int main()
{
	std::string s;
    std::cin >> s;
	int n;
	std::cin >> n;
	for(int i=0;i<n;++i)
	{
		int a, b;
		std::cin >> a >> b;
		int counter=0;
		int m=a-b+1;
		if(m%2==0)
		{
		   for(int i=a,j=b-1;;++i,--j)
		   {
			  if(i==j)
			  {
			  if(s[j-1]==s[j])
				  ++counter;
			  break;
			  }
			  else
			  {
`			  if(s[i-1]==s[i])
				  ++counter;
			  if(s[j-1]==s[j])
				  ++counter;
			  }
		   }
		}
		else
		{
		   for(int i=a,j=b-1,k=0;k<(b-a)/2;++i,--j,++k)
		   {

			  if(s[i-1]==s[i])
				  ++counter;
			  if(s[j-1]==s[j])
				  ++counter;
			  }
		   }

		std::cout << counter << std::endl;
	}
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	cin >> s;
	vector<int> v;
	for(int i=0;i<s.size()-1;++i)
	{
		if(s[i]==s[i+1])
			v.push_back(i+1);
	}
	int n;
	cin >> n;
	for(int i=0;i<n;++i)
	{
		int a, b;
		cin >> a >> b;
		--b;
		if(!(v.empty()))
		cout << upper_bound(v.begin(),v.end(),b)-lower_bound(v.begin(),v.end(),a) << "\n";
		else
			cout << "0\n";
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
typedef long long ll;
std::vector<int> check;
int cache[10001][10001] = {};
int dp(int i, int j,int limit)
{
	if (cache[i][j] != -1)
		return cache[i][j];
	else
	{
		if (i > 1)
		{
			cache[i][j] = dp(i - 1, j,limit) - check[i-2];
		}
		else
		{
			if (j < limit)
				cache[i][j] = dp(i, j + 1, limit) - check[j-1];
			else
			{
				int result(0);
				for (int x = 1; x <= limit; x++)
					result += check[x-1];
				cache[i][j] = result;
			}
		}
		return cache[i][j];
	}
}

void main()
{
	int number(0);
	std::string sen;
	int max = 1;
	std::vector<std::pair<int,int>> input;
	std::getline (std::cin, sen);
	std::cin >> number;
	bool flag = true;
	for (int i = 0; i < number; i++)
	{
		int a,b;
		std::cin >> a>>b;
		input.push_back(std::make_pair(a,b));
	}
	for (int i = 0; i <sen.length()-1; i++)
	{
		if (sen[i] == sen[i+1])
			check.push_back(1);
		else
			check.push_back(0);
	}
	for (int i = 1; i <= sen.length(); i++)
	{
		for (int j = i+1; j <= sen.length(); j++)
			cache[i][j] = -1;
	}
	check.push_back(0);
	for ( int i =0;i < number;i++)
	{
		std::cout<<dp(input[i].first,input[i].second,sen.length())<<std::endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
typedef long long ll;
void main()
{
	int number(0);
	std::string sen;
	int max = 1;
	std::vector<std::pair<int,int>> input;
	std::vector<int> check;
	std::getline (std::cin, sen);
	std::cin >> number;
	bool flag = true;
	for (int i = 0; i < number; i++)
	{
		int a,b;
		std::cin >> a>>b;
		input.push_back(std::make_pair(a,b));
	}
	for (int i = 0; i <sen.length()-1; i++)
	{
		if (sen[i] == sen[i+1])
			check.push_back(1);
		else
			check.push_back(0);
	}
	check.push_back(0);
	for ( int i =0;i < number;i++)
	{
		int result(0);
		for(int j = input[i].first-1;j<input[i].second-1;j++)
			result += check[j];
		std::cout<<result<<std::endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
typedef long long ll;
std::vector<int> check;
int cache[10001] = {};
int dp(int i)
{
	if (cache[i] != -1)
		return cache[i];
	else
	{
		if (i > 1)
		{
			cache[i] = dp(i - 1) + check[i-2];
		}
		else
		{
			cache[i] = 0;
		}
		return cache[i];
	}
}

void main()
{
	int number(0);
	std::string sen;
	int max = 1;
	std::vector<std::pair<int,int>> input;
	std::getline (std::cin, sen);
	std::cin >> number;
	bool flag = true;
	for (int i = 0; i < number; i++)
	{
		int a,b;
		std::cin >> a>>b;
		input.push_back(std::make_pair(a,b));
	}
	for (int i = 0; i <sen.length()-1; i++)
	{
		if (sen[i] == sen[i+1])
			check.push_back(1);
		else
			check.push_back(0);
	}
	for (int i = 1; i <= sen.length(); i++)
	{
			cache[i] = -1;
	}
	check.push_back(0);
	for ( int i =0;i < number;i++)
	{
		std::cout<< dp(input[i].second)- dp(input[i].first)<<std::endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
typedef long long ll;
std::vector<int> check;

void main()
{
	int number(0);
	std::string sen;
	int max = 1;
	std::vector<std::pair<int,int>> input;
	std::getline (std::cin, sen);
	std::cin >> number;
	bool flag = true;
	for (int i = 0; i < number; i++)
	{
		int a,b;
		std::cin >> a>>b;
		input.push_back(std::make_pair(a,b));
	}
	check.push_back(0);
	for (int i = 0; i <sen.size()-1; i++)
	{
		if (sen[i] == sen[i+1])
			check.push_back(check[i]+1);
		else
			check.push_back(check[i]);
	}
	for ( int i =0;i < number;i++)
	{
		std::cout<< check[input[i].second-1]- check[input[i].first-1]<<std::endl;
	}
}


#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>

using namespace std;

char a, b;
bool arr[100002];
int m, l, r;

int main(void)
{
	cin.get(a);
	cin.get(b);
	int i = 1;
	while (b != '\n')
	{
		if (a == b)
			arr[i] = true;
		a = b;
		cin.get(b);
		i++;
	}
	cin >> m;
	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << count(arr+l, arr+r, 1) << endl;
	}
	return 0;
}


#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>

using namespace std;

string s;
bool arr[100002];
int m, l, r;

int main(void)
{
	cin >> s >> m;
	for (int i=0; i<s.length()-1; i++)
		if (s[i] == s[i+1])
			arr[i+1] = true;

	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << count(arr+l, arr+r, 1) << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

char arr[100002];
int m, l, r, s;

int main(void)
{
	cin >> arr >> m;
	for (int i=0; i<m; i++)
	{
		s = 0;
		cin >> l >> r;
		for (int i=l-1; i<r-1; i++)
			s += abs(arr[i] - arr[i+1]);
		cout << r - l - s / 9 << endl;
	}
	return 0;
}


#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>

using namespace std;

string s;
bool arr[100002];
int m, l, r;

bool cmp(bool i)
{
	return i;
}

int function(void)
{
	return count_if(arr+l, arr+r, cmp);}

int main(void)
{
	cin >> s >> m;
	for (int i=0; i<s.length()-1; i++)
		if (s[i] == s[i+1])
			arr[i+1] = true;

	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << function() << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

char arr[100002];
int m, l, r, s;

int main(void)
{
	cin >> arr >> m;
	for (int i=0; i<m; i++)
	{
		s = 0;
		cin >> l >> r;
		for (int i=l-1; i<r-1; i++)
			s += abs(arr[i] - arr[i+1]);
		cout << r - l - s / 9;
	}
	return 0;
}


#include <iostream>
#include <string>

using namespace std;

char a, b;
bool arr[100002];
int m, l, r;

int function(void)
{
	int result = 0;
	for (int i=l; i<r; i++)
		if (arr[i])
			result++;
	return result;
}

int main(void)
{
	cin.get(a);
	int i = 1;
	while (1)
	{
		cin.get(b);
		if (b != '.' && b != '#')
			break;
		if (a == b)
			arr[i] = true;
		a = b;
		i++;
	}
	cin >> m;
	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << function() << endl;
	}
	return 0;
}


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

using namespace std;

string s;
int arr[100002];
int m, l, r, length;

int main(void)
{
	int counter = 0;
	cin >> s >> m;

	length = s.length() - 1;

	for (int i=0; i<length; i++)
	{
		if (s[i] == s[i+1])
			counter++;
		arr[i+2] = counter;
	}

	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << arr[r] - arr[l] << endl;
	}
	return 0;
}


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

using namespace std;

char a, b;
int arr[100001], length;
int m, l, r;

bool function(int i)
{
	return (i >= l && i < r);
}

int main(void)
{
	cin.get(a);
	int i = 1;
	while (1)
	{
		cin.get(b);
		if (b != '.' && b != '#')
			break;
		if (a == b)
			arr[length++] = i;
		a = b;
		i++;
	}
	cin >> m;
	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << count_if(arr, arr+length, function) << endl;
	}
	return 0;
}


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

using namespace std;

char a, b;
bool arr[100002];
int m, l, r;

bool cmp(bool i)
{
	return i;
}

int function(void)
{
	return count_if(arr+l, arr+r, cmp);}

int main(void)
{
	cin.get(a);
	int i = 1;
	while (1)
	{
		cin.get(b);
		if (b != '.' && b != '#')
			break;
		if (a == b)
			arr[i] = true;
		a = b;
		i++;
	}
	cin >> m;
	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << function() << endl;
	}
	return 0;
}


#include <iostream>
#include <string>

using namespace std;

string word;
int m, l, r;

int function(int l, int r)
{
	int result = 0;
	for (int i=l; i<r; i++)
		if (word[i] == word[i+1])
			result++;
	return result;
}

int main(void)
{
	cin >> word >> m;
	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << function(l-1, r-1) << endl;
	}
	return 0;
}


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

using namespace std;

string word;
int arr[100001], length;
int m, l, r;

bool function(int i)
{
	return (i >= l && i < r);
}

int main(void)
{
	cin >> word >> m;
	for (int i=0; i<word.length()-1; i++)
		if (word[i] == word[i+1])
			arr[length++] = i+1;
	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << count_if(arr, arr+length, function) << endl;
	}
	return 0;
}


#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>

using namespace std;

char s[100002];
bool arr[100002];
int m, l, r;

int main(void)
{
	cin >> s >> m;
	int length = strlen(s);
	for (int i=0; i<length-1; i++)
		if (s[i] == s[i+1])
			arr[i+1] = true;

	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << count(arr+l, arr+r, 1) << endl;
	}
	return 0;
}


#include <iostream>
#include <string>

using namespace std;

string word;
int arr[10001], length;
int m, l, r;

int function(int l, int r)
{
	int result = 0;
	int i = 0;
	while (arr[i] < l)
		i++;
	while (arr[i] < r && i < length)
	{
		i++;
		result++;
	}
	return result;
}

int main(void)
{
	cin >> word >> m;
	for (int i=0; i<word.length()-1; i++)
		if (word[i] == word[i+1])
			arr[length++] = i+1;
	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << function(l, r) << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

char arr[100002];
int m, l, r, s;

int main(void)
{
	cin >> arr >> m;
	for (int i=0; i<m; i++)
	{
		s = 0;
		cin >> l >> r;
		for (int i=l-1; i<r-1; i++)
			s += abs(arr[i] - arr[i+1]);
		cout << r - l - s / 11 << endl;
	}
	return 0;
}


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

using namespace std;

string s;
short arr[100002];
int m, l, r, length;

int main(void)
{
	int counter = 0;
	cin >> s >> m;

	length = s.length() - 1;

	for (int i=0; i<length; i++)
	{
		if (s[i] == s[i+1])
			counter++;
		arr[i+2] = counter;
	}

	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << arr[r] - arr[l] << endl;
	}
	return 0;
}


#include <iostream>
#include <string>

using namespace std;

string word;
int arr[100001], length;
int m, l, r;

int function(int l, int r)
{
	int result = 0;
	int i = 0;
	while (arr[i] < l)
		i++;
	while (arr[i] < r && i < length)
	{
		i++;
		result++;
	}
	return result;
}

int main(void)
{
	cin >> word >> m;
	for (int i=0; i<word.length()-1; i++)
		if (word[i] == word[i+1])
			arr[length++] = i+1;
	for (int i=0; i<m; i++)
	{
		cin >> l >> r;
		cout << function(l, r) << endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
void main()
{
	int m,l,r,i,j,c;
	char temp='1',cur;
	vector<int> v(100000,0);
	for (i=2;cur=getchar();i++)
	{
		v[i-1]=v[i-2];
		if(cur==temp)
			v[i-1]++;
		if(cur=='\n'){break;}
		temp=cur;
	}
	scanf("%d",&m);
	for (i=0;i<m;i++)
	{
		scanf("%d %d",&l,&r);
		printf("%d\n",(v[r]-v[l]));
	}
}


#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
void main()
{
	int m,l,r,i,j,c;
	char temp='1',cur;
	vector<int> v(100000,0);
	for (i=2;cur=getchar();i++)
	{
		v[i-1]=v[i-2];
		if(cur==temp)
			v[i-1]++;
		if(cur=='\n'){break;}
		temp=cur;
	}
	scanf("%d",&m);
	for (i=0;i<m;i++)
	{
		scanf("%d %d",&l,&r);
		printf("%d",(v[r]-v[l]));
	}
}


#include<iostream>
using namespace std;
void main()
{
	int m,l,r,i,j,c;
	char s[100000];
	cin>>s>>m;
	for (i=0;i<m;i++)
	{
		cin>>l>>r;
		l--;r--;c=0;
		for (j=l;j<r;j++)
			c+=(s[j]==s[j+1]);
		cout<<c<<endl;
	}
}


#include<cstdio>
#include<vector>
void main(){int m,l,r,i=2,p=0,c=1;std::vector<int> v(100011,0);for (;c!='\n';i++){c=getchar();v[i-1]=v[i-2]+(c==p);p=c;}scanf("%d",&m);while(m--){scanf("%d%d",&l,&r);printf("%d\n",v[r]-v[l]);}}


#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
void main()
{
	int m,l,r,i,j,c;
	char temp='1',cur;
	vector<int> v(100011,0);
	for (i=2;cur=getchar();i++)
	{
		v[i-1]=v[i-2];
		if(cur==temp)
			v[i-1]++;
		if(cur=='\n'){break;}
		temp=cur;
	}
	scanf("%d",&m);
	for (i=0;i<m;i++)
	{
		scanf("%d %d",&l,&r);
		printf("%d\n",(v[r]-v[l]));
	}
}


#include<iostream>
#include<cstdio>
using namespace std;
void main()
{
	int m,l,r,i,j,c;
	char s[100000];
	scanf("%s",s);
	scanf("%d",&m);
	for (i=0;i<m;i++)
	{
		scanf("%d %d",&l,&r);
		l--;r--;c=0;
		for (j=l;j<r;j++)
			c+=(s[j]==s[j+1]);
		cout<<c<<endl;
	}
}


#include<cstdio>
#include<vector>
void main(){
	int m,l,r,i,j,p=0,c;
	std::vector<int> v(100011,0);
	for (i=2;c=getchar();i++){
		v[i-1]=v[i-2];
		if(c==p)v[i-1]++;
		if(c=='\n')break;
		p=c;
	}
	scanf("%d",&m);
	for (i=0;i<m;i++){
		scanf("%d %d",&l,&r);
		printf("%d\n",(v[r]-v[l]));
	}
}


#include<iostream>
using namespace std;
void main()
{
	int m,l,r,i,j,c;
	char s[100];
	cin>>s>>m;
	for (i=0;i<m;i++)
	{
		cin>>l>>r;
		l--;r--;c=0;
		for (j=l;j<r;j++)
			c+=(s[j]==s[j+1]);
		cout<<c<<endl;
	}
}


#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
void main()
{
	int m,l,r,i,j,c;
	char s[100000];
	vector<int> v(100000,0);
	for (int i = 2; s[i]=getchar(); i++)
	{
		v[i-1]=v[i-2];
		if(s[i]==s[i-1])
			v[i-1]++;
		if(s[i]=='\n'){break;}

	}
	scanf("%d",&m);
	for (i=0;i<m;i++)
	{
		scanf("%d %d",&l,&r);
		cout<<(v[r]-v[l])<<endl;
	}
}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int A[10001];
	string S;
	getline(cin, S);
	for (int i = S.length() - 2; i >= 0; i--){
		A[i] = A[i + 1] + (S[i] == S[i + 1]);
	}
	int num;
	cin >> num;
	int l, r;
	while (num--){
		cin >> l >> r;
		cout << A[l - 1] - A[r - 1] << endl;
	}
	return 0;
}

//#include <iostream>
//#include<string>
//using namespace std;
//int Q, A[100005], L, R, i;
//string S;
//int main()
//{
//	cin >> S >> Q;
//	for (i = S.length() - 2; i >= 0; i--)A[i] = A[i + 1] + (S[i] == S[i + 1]);
//	while (Q--){ cin >> L >> R; cout << A[L - 1] - A[R - 1] << "\n"; }
//}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int A[10001];
	int l, r, Q;
	string S;
	cin >> Q;
	getline(cin, S);
	for (int i = S.length() - 2; i >= 0; i--)
		A[i] = A[i + 1] + (S[i] == S[i + 1]);
	while (Q--){
		cin >> l >> r;
		cout << A[l - 1] - A[r - 1] << endl;
	}
	return 0;
}

//#include <iostream>
//#include<string>
//using namespace std;
//int Q, A[100005], L, R, i;
//string S;
//int main()
//{
//	cin >> S >> Q;
//	for (i = S.length() - 2; i >= 0; i--)A[i] = A[i + 1] + (S[i] == S[i + 1]);
//	while (Q--){ cin >> L >> R; cout << A[L - 1] - A[R - 1] << "\n"; }
//}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int location[100001];
	string str;
	getline(cin, str);
	for (int i = 0; i < str.size(); i++){
		if (i == 0)
			location[i + 1] = 0;
		else
			location[i + 1] = location[i] + (str[i] == str[i - 1]);
	}
	int num;
	cin >> num;
	int l, r;
	while (num--){
		cin >> l >> r;
		cout << location[r] - location[l] << endl;
	}
	return 0;
}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int location[10001];
	string S;
	getline(cin, S);
	for (int i = S.length() - 2; i >= 0; i--){
		location[i] = location[i + 1] + (S[i] == S[i + 1]);
	}
	int num;
	cin >> num;
	int l, r;
	while (num--){
		cin >> l >> r;
		cout << location[l] - location[r] << endl;
	}
	return 0;
}

//#include <iostream>
//#include<string>
//using namespace std;
//int Q, A[100005], L, R, i;
//string S;
//int main()
//{
//	cin >> S >> Q;
//	for (i = S.length() - 2; i >= 0; i--)A[i] = A[i + 1] + (S[i] == S[i + 1]);
//	while (Q--){ cin >> L >> R; cout << A[L - 1] - A[R - 1] << "\n"; }
//}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int A[10001];
	int l, r, Q;
	string S;
	cin >> S >> Q;
	for (int i = S.length() - 2; i >= 0; i--)A[i] = A[i + 1] + (S[i] == S[i + 1]);
	while (Q--){
		cin >> l >> r;
		cout << A[l - 1] - A[r - 1] << endl;
	}
	return 0;
}

//#include <iostream>
//#include<string>
//using namespace std;
//int Q, A[100005], L, R, i;
//string S;
//int main()
//{
//	cin >> S >> Q;
//	for (i = S.length() - 2; i >= 0; i--)A[i] = A[i + 1] + (S[i] == S[i + 1]);
//	while (Q--){ cin >> L >> R; cout << A[L - 1] - A[R - 1] << "\n"; }
//}


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

int main()
{
	int location[10001];
	string str;
	cin >> str;
	for (int i = 0; i < str.size(); i++){
		if (i == 0)
			location[i + 1] = 0;
		else
			location[i + 1] = location[i] + (str[i] == str[i - 1]);
	}
	int num;
	cin >> num;
	int l, r;
	for (int i = 0; i < num; i++){
		cin >> l >> r;
		cout << location[r] - location[l] << endl;
	}
	return 0;
}


//#include<iostream>
//#include<string>
//
//using namespace std;
//
//int main()
//{
//	int location[10001];
//	string str;
//	getline(cin, str);
//	for (int i = 0; i < str.size(); i++){
//		if (i == 0)
//			location[i + 1] = 0;
//		else
//			location[i + 1] = location[i] + (str[i] == str[i - 1]);
//	}
//	int num;
//	cin >> num;
//	int l, r;
//	while (num--){
//		cin >> l >> r;
//		cout << location[r] - location[l] << endl;
//	}
//	return 0;
//}

#include <iostream>
#include<string>
using namespace std;
int Q, A[100005], L, R, i;
string S;
int main()
{
	cin >> S >> Q;
	for (i = S.length() - 2; i >= 0; i--)A[i] = A[i + 1] + (S[i] == S[i + 1]);
	while (Q--){ cin >> L >> R; cout << A[L - 1] - A[R - 1] << "\n"; }
}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int location[10001];
	string str;
	getline(cin, str);
	for (int i = 0; i < str.size(); i++){
		if (i == 0)
			location[i + 1] = 0;
		else
			location[i + 1] = location[i] + (str[i] == str[i - 1]);
	}
	int num;
	cin >> num;
	int l, r;
	for (int i = 0; i < num; i++){
		cin >> l >> r;
		cout << location[r] - location[l] << endl;
	}
	return 0;
}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int location[10001];
	string str;
	getline(cin, str);
	for (int i = 0; i < str.size(); i++){
		if (i == 0)
			location[i + 1] = 0;
		else
			location[i + 1] = location[i] + (str[i] == str[i - 1]);
	}
	int num;
	cin >> num;
	int l, r;
	while (num--){
		cin >> l >> r;
		cout << location[r] - location[l] << endl;
	}
	return 0;
}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int A[10001];
	int l, r, Q;
	string S;
	getline(cin, S);
	cin >> Q;
	for (int i = S.length() - 2; i >= 0; i--)
		A[i] = A[i + 1] + (S[i] == S[i + 1]);
	while (Q--){
		cin >> l >> r;
		cout << A[l - 1] - A[r - 1] << endl;
	}
	return 0;
}

//#include <iostream>
//#include<string>
//using namespace std;
//int Q, A[100005], L, R, i;
//string S;
//int main()
//{
//	cin >> S >> Q;
//	for (i = S.length() - 2; i >= 0; i--)A[i] = A[i + 1] + (S[i] == S[i + 1]);
//	while (Q--){ cin >> L >> R; cout << A[L - 1] - A[R - 1] << "\n"; }
//}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int A[100001];
	int l, r, Q;
	string S;
	cin >> S >> Q;
	for (int i = S.length() - 2; i >= 0; i--)
		A[i] = A[i + 1] + (S[i] == S[i + 1]);
	while (Q--){
		cin >> l >> r;
		cout << A[l - 1] - A[r - 1] << endl;
	}
	return 0;
}

//#include <iostream>
//#include<string>
//using namespace std;
//int Q, A[100005], L, R, i;
//string S;
//int main()
//{
//	cin >> S >> Q;
//	for (i = S.length() - 2; i >= 0; i--)
//		A[i] = A[i + 1] + (S[i] == S[i + 1]);
//	while (Q--){
//		cin >> L >> R;
//		cout << A[L - 1] - A[R - 1] << "\n";
//	}
//}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include<cstring>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
 int dp [100000];
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string ss;
    cin >> ss;
    int count = 0;
    int l = ss.size();
    for (int i = 0; i < l; i++){
        if(ss[i] == ss[i + 1]){
            count ++ ;
        }
        dp[i + 1] = count;
    }
    int m,s,e;
    cin >> m ;
    for (int i = 0; i < m; i++){
        cin >> s >> e;
        cout << dp[e - 1] - dp[s- 1] <<endl;
    }
    return 0;
}


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

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
const int MAX = 50010;
const int MAXINT = 1000000000;
#define REP(start,end,x) for(int i = start; i < end; i += x)
#define REP1(con) for(::iterator i = con.begin(); i!= con.end(); i ++)
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string ss;
    int l = ss.size();
    cin >> ss;
    int m,s,e;
    cin >> m ;
    for (int i = 0; i < m; i++){
        cin >> s >> e;
        int count = 0,res = 0;
        for (int j = s - 1; j < e - 1 ; j++){
            count ++;
        }
        cout << count <<endl;
    }
    return 0;
}


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

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
const int MAX = 50010;
const int MAXINT = 1000000000;
#define REP(start,end,x) for(int i = start; i < end; i += x)
#define REP1(con) for(::iterator i = con.begin(); i!= con.end(); i ++)
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string ss;
    cin >> ss;
    int m,s,e;
    cin >> m ;
    for (int i = 0; i < m; i++){
        cin >> s >> e;
        int count = 0,res = 0;
        for (int j = s - 1; j < e - 1 ; j++){
            if(ss[j] == ss[j + 1])count ++;
            else count = 0;
                res = max(res,count);
        }
        cout << res <<endl;
    }
    return 0;
}


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

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
const int MAX = 50010;
const int MAXINT = 1000000000;
#define REP(start,end,x) for(int i = start; i < end; i += x)
#define REP1(con) for(::iterator i = con.begin(); i!= con.end(); i ++)
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string ss;
    cin >> ss;
    int m,s,e;
    cin >> m ;
    for (int i = 0; i < m; i++){
        cin >> s >> e;
        int count = 0,res = 0;
        for (int j = s - 1; j < e - 1 ; j++){
            if(ss[j] == ss[j + 1])count ++;
                res = max(res,count);
        }
        cout << res <<endl;
    }
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include<cstring>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
 int dp [100000];
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string ss;
    cin >> ss;
    int count = 0;
    int l = ss.size();
    for (int i = 0; i < l - 1; i++){
        if(ss[i] == ss[i + 1]){
            count ++ ;
        }
        dp[i + 1] = count;
    }
    int m,s,e;
    cin >> m ;
    for (int i = 0; i < m; i++){
        cin >> s >> e;
        cout << dp[e - 1] - dp[s- 1] <<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
int a[1000];
using namespace std;
int main(){
	string s;
	cin>>s;
	int k=0;
	for(int i=1;i<s.size();i++){
		if(s[i]==s[i-1]){
			k++;
		}
		a[i]=k;
	}
	int m,l,r;
	cin>>m;
	for(int i=1;i<=m;i++){
		cin>>l>>r;
		cout<<a[r-1]-a[l-1];
	}
}


#include <iostream>
#include <algorithm>
#include <string>
int a[1000];
using namespace std;
int main(){
	string s;
	cin>>s;
	int k=0;
	for(int i=1;i<s.size();i++){
		if(s[i]==s[i-1]){
			k++;
		}
		a[i]=k;
	}
	int m,l,r;
	cin>>m;
	for(int i=1;i<=m;i++){
		cin>>l>>r;
		cout<<a[r-1]-a[l-1]<<endl;
	}
}


#include <iostream>
#include <algorithm>
#include <string>
int a[100003];
using namespace std;
int main(){
	string s;
	cin>>s;
	int k=0;
	for(int i=1;i<s.size();i++){
		if(s[i]==s[i-1]){
			k++;
		}
		a[i]=k;
	}
	int m,l,r;
	cin>>m;
	for(int i=1;i<=m;i++){
		cin>>l>>r;
		cout<<a[r-1]-a[l-1]<<endl;
	}
}


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

int main()
{
string s;
int *arr;
int n,l,r,m;
cin>>s;
n=s.length();
arr= new int[n+7];
arr[0]=0;
for(int i=1;i<n;i++)
{
	if(s[i-1]==s[i])
		arr[i]=arr[i-1]+1;
	else
		arr[i]=arr[i-1];
}

cin>>m;
for(int i=0;i<m;i++)
{
	cin>>l>>r;
	cout<<arr[r-1]-arr[l]+1<<endl;
}

delete [] arr;
	return 0;
}


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

int main()
{
string s;
int arr[100005];
arr[0]=0;
int n,l,r,m;
cin>>s;
n=s.length();
for(int i=1;i<n;i++)
{
	if(s[i-1]==s[i])
		arr[i]=arr[i-1]+1;
	else
		arr[i]=arr[i-1];
}
cin>>m;
for(int i=0;i<m;i++)
{
	cin>>l>>r;
	cout<<arr[r-1]-arr[l-1]<<endl;

}
	return 0;
}


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

int main()
{
string s;
bool *arr;
int n,l,r,m,count;
cin>>s;
n=s.length();
arr= new bool[n+1];
arr[0]=0;
for(int i=1;i<n;i++)
{
	if(s[i-1]==s[i])
		arr[i]=true;
	else
		arr[i]=false;
}

cin>>m;
for(int i=0;i<m;i++)
{
	cin>>l>>r;
	count=0;
    for(int i=l;i<r;i++)
        count+=arr[i];
        cout<<count<<endl;
}

delete [] arr;
	return 0;
}