stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <vector>

#include <set>

#include <queue>

#include <algorithm>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <iostream>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

 

#define pb push_back

#define mk make_pair

#define f0(i,b) for(int i=0;i<(b);i++)

#define f1(i,b) for(int i=1;i<=(b);i++)

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

#define sf(a) scanf("%d",&a);

#define sfl(a) scanf("%lld",&a);

#define pf(a) printf("%d\n",a);

#define pfl(a) printf("%lld\n",a);

#define TEST int test; cin >> test;while(test--)

#define ii pair<int,int>

#define iil pair<ll,ll>

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

#define INF 2147483647

 

 

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};

int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

int dx4[] = {0, 0, 1, -1};

int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);

 

 

ll n, m, x, k;

 

void solve()

{

   string s;

   cin >>k >>  s;

   ll n = s.size();

   if(n <= k) cout << s << endl;

   else{ cout << s.substr(0,k);

   for(int i = k ; i < k+3 ; i ++)

   cout <<'.';

   cout << endl;

   }

}

 

 

int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(NULL);

    cout.tie(NULL);

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

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

    solve();

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.305236701296016x):
#include<stdio.h>

#include<string.h>

int main(){

	int k;

	char s[105];

	scanf("%d",&k);

	getchar();

	scanf("%s",&s);

	if(strlen(s)>k){

		for(int i=0;i<k;i++){

			printf("%c",s[i]);

		}

		printf("...");

		printf("\n");

	}

	else{

		int l = strlen(s);

		for(int i=0;i<l;i++)

			printf("%c",s[i]);

		printf("\n");

	}

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int N, K, a[100100], dp[100100];



int f(int n) {

	if (n==1) return 0;

	if (n==2) return abs(a[2] - a[1]);

	if (dp[n] != -1) return dp[n];

	dp[n] = 2e9;

	for(int i=1; i<=K; i++)

		if (n-i>0)

			dp[n] = min(dp[n], f(n-i) + abs(a[n] - a[n-i]));

				

	return dp[n];

}



int main() {

	cin >> N >> K;

	for(int i=1; i<=N; i++)

		cin >> a[i];

	memset(dp, -1, sizeof(dp));

	cout << f(N) << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.396051082694154x):
#include <bits/stdc++.h>

using namespace std;

#define int long long int



int n; //number of stones

int k; //farthest the frog can jump

vector<int> h; //height of the stones

vector<int> dp; //memorize heck



main(){

	cin >> n >> k;



	dp.assign(n, INT_MAX);

	

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

		int x;

		cin >> x;

		h.push_back(x);

	}



	dp[0] = 0;

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

		for(int j=1; j<=k; j++){

			if(i-j>=0){

				dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));	

			}

		}

	}



	cout << dp[n-1] << "\n";

	

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cmath>

using namespace std;

int main(){

	long long n,m,a,b;

	long long sum;

	a=pow(10,9)+7;

	while(scanf("%lld",&n)==1)

	{

		sum=1;

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

		{

			sum=sum*i;

		    sum=sum%a;

		}

		printf("%lld\n",sum);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.48481463618738x):
#include<stdio.h>

#include<string.h>

#define maxn 1000000007

int main()

{

    long long a,n,sum;

    while(scanf("%lld",&n)!=EOF)

    {

        sum=1;

        for(a=1;a<=n;a++)

        {

            sum*=a;

            sum%=maxn;

        }

        printf("%lld\n",sum);

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>



using namespace std;



int main() {

    int a, b;

    cin >> a >> b;

    if(a+b < 10){

        cout << a + b << endl;

    }

    else{

        cout << "error" << endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.263339253330125x):
#include<cstdio>

int main(){

	int a,b;

	scanf("%d%d",&a,&b);

	if(a+b<10){printf("%d\n",a+b);}

	else {printf("error\n");}

	return 0;

	}
// Slower C++ solution:
#include <bits/stdc++.h>

/**

*   author: j o s e m a g o

*   date:

**/

using namespace std;

#pragma GCC optimize ("Ofast")

#define f first

#define s second

#define mp make_pair

#define lb lower_bound

#define ub upper_bound

#define all(v) (v).begin(),(v).end()

#define mset(a,v) memset(a,v,sizeof(a))

#define pb push_back

#define sz(x) ((int)(x).size())

#define rsz resize

#define ln "\n"



typedef double db;

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

const ld PI = 2*acos(0.0);

const int MOD = 1000000007;

const int JJJ = 100009;









int main(){



  //freopen("input.in","r",stdin);

  //freopen("input.out","w",stdout);



    ios_base::sync_with_stdio(0); cin.tie(0);



    int N,k;

    cin >> N >> k;

    vector<int>h(N+k+1);

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

        cin >> h[i];

    }

    vector<int>dp(N+k+1,INT_MAX);

    dp[0] = 0;

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

    for(int i = k;i < N;i++){

        for(int j = 1;j <= k;j++){

            dp[i] = min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

        }

    }



//    for(int i = 0;i < N;i++) cerr<<dp[i]<<" ";

    cout<<dp[N-1];









    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.288845911994668x):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>





typedef long long ll;





ll *mem, *inp, dist, min_dist, N;

int k;



int main()

{

    ll i, j;

    scanf("%lld%d", &N, &k);



    mem =(ll*) malloc(N * sizeof(ll));

    inp =(ll*) malloc(N * sizeof(ll));



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

        scanf("%lld", inp+i);

    }



    *(mem+N-2) = llabs(*(inp+N-2) - *(inp+N-1));



    for(i = 3; i<=k+1 && i<=N; ++i)

        *(mem+N-i) = llabs(*(inp+N-i) - *(inp+N-1));



    for(i = N-(k+2); i>=0; --i){



        min_dist = llabs(*(inp+i) - *(inp+i+1)) + *(mem+i+1);

        for(j = 2; j<=k && i+j<N; ++j){

            dist = llabs(*(inp+i) - *(inp+i+j)) + *(mem+i+j);

            if (dist < min_dist) min_dist = dist;

        }



        *(mem+i) = min_dist;

    }



    printf("%lld\n", *mem);



    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;

using P = pair<int,int>;



int INF = 1001001001;



template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}





int main() {

    int n, k;

    cin >> n >> k;

    vector<int> h(n);

    rep(i,n) cin >> h[i];

    vector<int> dp(110000, INF);

    dp[0] = 0;

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

        for (int j = 1; j <= k; j++) {

            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));

        }

    }

    cout << dp[n-1] << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4439259661690196x):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;

using P = pair<int,int>;



int INF = 1001001001;



template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}



int main() {

    int n, k;

    cin >> n >> k;

    vector<int> h(n);

    rep(i,n) cin >> h[i];

    vector<int> dp(n+k, INF);

    dp[0] = 0;

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

        for (int j = 1; j <= k; j++) {

            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));

        }

    }

    cout << dp[n-1] << endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ll      	long long int

#define PI      	acos(-1)

#define read    	freopen("in.txt","r",stdin)

#define uu      	first

#define vv      	second

#define write   	freopen("out.txt","w",stdout)

#define pii     	pair<int,int>

#define pll         pair<ll,ll>

#define INF     	1e9

#define EPS     	1e-8

#define MAX     	1000006

#define MOD     	1000000007

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

using namespace std;

int n ,k;

ll ara[MAX] ,dp[MAX];



ll solve(int id) {

    if( id ==n-1 ) return 0;

    ll &ret = dp[id];

    if( ret != -1) return ret;



    ret = INF;



    for(int i = 1 ; i <=k && id + i < n ; i++ ) {

//        cout<<id<<" "<<i<<endl;

        ret = min(ret , abs(ara[id+i] - ara[id]) + solve(id+i) );

    }

    return ret;

}



int main()

{

    fastRead;

    cin>>n>>k;

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

    memset(dp , - 1, sizeof dp);

    cout<<solve(0)<<endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 9.405245064441445x):
#include<bits/stdc++.h>

#define MAX 1000006

#define INF 2e9

using namespace std;

int ara[MAX] , dp[MAX];



int main()

{

    int n , k;

    cin>>n >> k;

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



	for(int i =1 ; i < n ; i++ ) {



        int val = INF;

        for(int j = 1 ; j <= k ; j++ ) {



			if( i - j < 0 ) continue;

            val = min(val , abs(ara[i] - ara[i-j]) + dp[i-j] );

        }

        dp[i] = val;

	}

	cout<<dp[n-1]<<endl;

	return 0;



}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

#define ll long long

const int N=100005;

int n,k;

int ar[N];

int mem[N];



int solve(int ind){

    if(ind==n-1){

        return 0;

    }

    if(ind>=n){

        return 1e9;

    }

    if(mem[ind]!=-1){

        return mem[ind];

    }

    int ret=1e9;

    for(int i=1;i<=k;i++){

        ret=min(ret,solve(ind+i)+abs(ar[ind]-ar[ind+i]));

    }

    return mem[ind]=ret;

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    memset(mem,-1,sizeof mem);

    cin>>n>>k;

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

        cin>>ar[i];

    }

    cout<<solve(0)<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3973172273623364x):
#include <bits/stdc++.h>



using namespace std;

#define ll long long



const int INF = 1e9 + 5;



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int n,k;

    cin >> n>>k;

    int ar[n];

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

        cin >> ar[i];

    }

    vector<int> dp(n, INF);

    dp[0] = 0;

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

        for (int j = i + 1; j <= i + k; j++) {

            if (j < n) {

                dp[j] = min(dp[j], dp[i] + abs(ar[i] - ar[j]));

            }

        }

    }

    cout << dp[n - 1] << endl;

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int maxn = 1e5+5;

int a[maxn], dp[maxn];



int main(){

	int n, k; cin >> n >> k;

	memset(dp, 0x3f, sizeof dp);

	for(int i = 1; i <= n; i++) cin >> a[i];

	dp[1] = 0;

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

		for(int j = 1; j <= min(i, k); j++){

			dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));

		}

	}

	cout << dp[n] << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.3805326280103467x):
#include <bits/stdc++.h>

using namespace std;

int n, k;

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie();

	cout.tie();

	cin >> n >> k;

	vector<int>dp(n, INT_MAX);

	vector<int>arr(n);

	//fill(dp.begin(), dp.end(), INT_MAX);

	//int arr[n+5];

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

		cin >> arr[i];

	}

	dp[0]=0;

	dp[1]=abs(arr[1]-arr[0]);

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

		for(int j=i-1, jump=0;j>=0 && jump<k;j--, jump++){

				dp[i]=min(dp[i], dp[j]+abs(arr[i]-arr[j]));

		}

	}

	cout << dp[n-1] << endl;

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <vector>

#include <queue>

#include <set>

#include <string>

#include <map>

#include <cmath>

#include <cstring>



#define fi first

#define se second

#define rep(i,n) for (int i = 0; i < (n); ++i)

#define rrep(i,n) for (int i = 1; i < (n); ++i)

#define drep(i,n) for (int i = (n)-1; i >= 0; --i)

#define srep(i,s,t) for (int i = s; i < t; ++i)

#define all(x) (x).begin(), (x).end()

#define maxs(x,y) (x = max(x,y))

#define mins(x,y) (x = min(x,y))

#define pb push_back

#define sz(x) (int)(x).size()

#define PQ(T) priority_queue<T, v(T), greater<T> >



using namespace std;

typedef long long ll;

typedef unsigned uint;

typedef unsigned long long ull;

typedef pair<int,int> P;



const ll LINF = 1001002003004005006ll;

const int INF = 1001001001;



const int mod = 1000000007;

const int MAXN = 101010;

int dp[MAXN];

int main() {

    int N, K;

    cin >> N >> K;

    vector<int> h(N);

    rep(i,N) cin >> h[i];

    

    rep(i,MAXN) dp[i] = INF;



    dp[0] = 0;

    rep(i,N) {

        srep(j, 1, K+1) {

            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));

        }

    }

    cout << dp[N-1] << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.381805299550618x):
#include <algorithm>

#include <iostream>

#include <vector>

#include <queue>

#include <set>

#include <string>

#include <map>

#include <cmath>

#include <cstring>



#define fi first

#define se second

#define rep(i,n) for (int i = 0; i < (n); ++i)

#define rrep(i,n) for (int i = 1; i < (n); ++i)

#define drep(i,n) for (int i = (n)-1; i >= 0; --i)

#define srep(i,s,t) for (int i = s; i < t; ++i)

#define all(x) (x).begin(), (x).end()

#define maxs(x,y) (x = max(x,y))

#define mins(x,y) (x = min(x,y))

#define pb push_back

#define sz(x) (int)(x).size()

#define PQ(T) priority_queue<T, v(T), greater<T> >



using namespace std;

typedef long long ll;

typedef unsigned uint;

typedef unsigned long long ull;

typedef pair<int,int> P;



const ll LINF = 1001002003004005006ll;

const int INF = 1001001001;



const int mod = 1000000007;



int main() {

    int n, k;

    cin >> n >> k;

    vector<int> h(n);

    rep(i,n) cin >> h[i];

    int dp[100100];

    rep(i,n) dp[i] = INF;

    

    dp[0] = 0;

    rep(i,n) {

        for (int j = 1; j<=k; ++j) {

            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));

        }

    }

    cout << dp[n-1] << endl;

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<string>

using namespace std;

int main()

{

	int k;cin>>k;

	string s;cin>>s;

	if(s.length()<=k)

	{

		cout<<s<<endl;

	}

	else 

	{

		for(int i=0;i<k;i++)

		{

			cout<<s[i];

		}

		cout<<"..."<<endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.321714742805957x):
#include<stdio.h>

#include<string.h>



int main()

{

	int n;

	scanf("%d",&n);

	char str[102];

	scanf("%s",&str);

	int len=strlen(str);

	if(len>n)

	{

		str[n]='.';

		str[n+1]='.';

		str[n+2]='.';

		str[n+3]='\0';

	}

	printf("%s",str);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#include <sstream>

using namespace std;

#define pr(x) cout<<x

#define prs cout<<" "

#define prn cout<<"\n"

#define sc(x) cin>>x

#define ll long long int



int n,k;

int a[1000005];

int dp[1000005];



int solve(int i)

{ 

    //cout<<n<<k<<endl;

    if(i == (n-1)) return 0;

    if(i >= n) return INT_MAX;

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

    vector<int> v(k,INT_MAX);

    for(int j=1; j<=k; j++)

    {

        if(j+i > n-1)

         break;

        else

         v[j-1] = abs(a[i] - a[i+j])+solve(i+j);

    }

    dp[i] = *min_element(v.begin(), v.end());

    v.clear();

    return dp[i];

}



int main()

{

    ios :: sync_with_stdio(false); cin.tie(0);

    int t=1;

    //cin >> t;

    for(int i9 = 1; i9 <= t; i9++)

    {

        cin>>n>>k;

        memset(dp, -1, sizeof(dp));

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

          cin>>a[i];

        cout<<solve(0)<<endl;

        //cout<<"Cae #"<<i9<<": "<<res<<endl;

    }

}

// Faster C++ solution for the same problem (measured speedup: 2.8152538114010013x):
#include<bits/stdc++.h>

#define F first

#define S second

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

#define pb push_back

#define int long long int

#define MOD 1000000007

using namespace std;



/*class Graph {



  map<int, list<pair<int, int> > > l;



public:

  void addEdge(int x, int y, int cost) {

    l[x].pb(make_pair(y, cost));

    l[y].pb(make_pair(x, cost));

  }



  int dfs_helper(int n, int node, map<int, int> &vis, map<int, int> &count, int &ans) {

    //cout << node << " " ;

    vis[node] = 1;

    count[node] = 1;

    for (auto m : l[node]) {

      if (!vis[m.F]) {

        vis[m.F] = 1;

        count[node] += dfs_helper(m.F, vis, count, ans);

        ans += 2 * min(count[node], n - count[node]) * m.S.S;

      }

    }

    return count[node];

  }



  void dfs() {

    map<int, int> vis;

    map<int, int> count;

    int ans = 0;

    dfs_helper(0, vis, count, ans);

    cout << ans << endl;

  }



};*/



int dp[100005];



int f(int a[], int i, int n, int k)

{

  //cout << i << endl;

  if (i == (n - 1))

    return 0;

  if (i >= n)

    return INT_MAX;

  if (dp[i] != -1)

    return dp[i];

  int ans = INT_MAX;

  for (int j = 1; j <= k; j++)

  {

    if (i + j <= n - 1)

    {

      ans = min(ans, abs(a[i] - a[i + j]) + f(a, i + j, n, k));

    }

  }

  return dp[i] = ans;

}





int32_t main()

{

  ios :: sync_with_stdio(false); cin.tie(0);

  int t = 1;

  //cin >> t;

  for (int i9 = 1; i9 <= t; i9++)

  {

    /* Graph G;

     int n, x, y, cost;

     cin >> n;

     while (n--) {

       cin >> x >> y >> cost;

       G.addEdge(x, y, cost);

     }

     G.dfs();*/

    //freopen("ouputnew.txt", "w", stdout);

    //flclose(stdout);

    memset(dp, -1 , sizeof (dp));

    int n, k;

    cin >> n >> k;

    int a[n];

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

      cin >> a[i];

    cout << f(a, 0, n, k);

  }

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <cmath>

using namespace std;



int h[(int)1e5], dp[(int)1e5], K, N;





int main()

{

	K = N = 0;

	for(int j = 1;j <= 1e5;j++)

	{

		dp[j] = 1e9;

	}

	scanf("%d %d", &N, &K);

	for(int i = 1;i <= N;i++)

	{

		scanf("%d", &h[i]);		

	}

	dp[1] = 0;

	dp[2] = dp[1] + abs(h[1] - h[2]);

	for(int i = 1;i <= N;i++)

	{

		for(int j = 1;j <= K;j++)		

		{

			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));

		}

	}

	printf("%d\n", dp[N]);

	return 0;	

}


// Faster C++ solution for the same problem (measured speedup: 3.1061400791247324x):
#include<cstdio>

#include<algorithm>

using namespace std;



#define ll long long 



#define file_io 0



ll i,t,j;

ll n,k,h[100005],dp[100005];



int main(){

	if (file_io){

		freopen(".in","r",stdin);

		freopen(".out","w",stdout);

	}

	

	scanf("%lld%lld",&n,&k);

	

	for (i=1; i<=n; ++i){

		scanf("%lld",&h[i]);

	}

	

	dp[1]=0;

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

		dp[i]=2e9;

		for (t=max(1ll,i-k); t<i; ++t){

			dp[i]=min(dp[t]+abs(h[i]-h[t]),dp[i]);

		}

	}

	

	printf("%lld\n",dp[n]);

	

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

long long a[100001],n,k;

int main()

{

	cin>>n>>k;

	for(int i=1;i<=n;i++)cin>>a[i];

	long long f[100001];

	memset(f, 0x7F, sizeof(f));

	f[1]=0;

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

		for(int j=1;j<=k&&j<i;j++)

			f[i]=min(f[i-j]+abs(a[i]-a[i-j]),f[i]);

	cout<<f[n]<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.81966854745493x):
#include<cstdio>

#include<iostream>

#include<cmath>

using namespace std;

const int MAXN = 100010;

const int INF = 0x3f3f3f3f;

int n, k, a[MAXN], f[MAXN];

int main()

{

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

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

		scanf("%d",&a[i]),f[i]=INF;

	f[1] = 0;

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

	{

		for(int j=max(i-k,1);j<i;j++)

			f[i] = min(f[i], f[j]+abs(a[i]-a[j]));

	}

		

	printf("%d\n",f[n]);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define pb push_back

#define pf push_front

#define ll long long



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    ll x,n,q,sum=0,a,b;

    vector <ll> arr(100005);

    cin>>n;

    

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

        cin>>x;

        sum += x;

        arr[x]++;

    }



    cin>>q;

    while(q--){

        cin>>a>>b;

        sum -= (a*arr[a]);

        sum += (b*arr[a]);

        arr[b] += arr[a];

        arr[a] = 0;



        cout << sum << "\n";

    }

    

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8088881849928025x):
#include<bits/stdc++.h>

using namespace std;

#define pb push_back

#define pf push_front

#define ll long long



ll arr[100005];



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    

    ll x,n,q,sum=0,a,b;

   // vector <ll> arr(100005);

    cin>>n;

    

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

        cin>>x;

        sum += x;

        arr[x]++;

    }



    cin>>q;

    while(q--){

        cin>>a>>b;

        sum -= (a*arr[a]);

        sum += (b*arr[a]);

        arr[b] += arr[a];

        arr[a] = 0;



        cout << sum << "\n";

    }

    

    return 0;

}
// Slower C++ solution:
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>

using namespace std;

struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

#define max3(a,b,c) max(a,max(b,c))

#define min3(a,b,c) min(a,min(b,c))

#define MOD 1000000007

#define INF (1<<30)

#define LINF (lint)(1LL<<56)

#define endl "\n"

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)

#define Flag(x) (1<<(x))

#define Flagcount(x) __builtin_popcount(x)

#define pint pair<int,int>

#define pdouble pair<double,double>

#define plint pair<lint,lint>

typedef long long lint;

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

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



lint calc(lint x){

    lint keta=(lint)(1+floor(log10(x)));

    lint top=x/(lint)(pow(10,keta-1));

    lint res=0;

    lint ketac=2;

    lint botom=x%10;

    if(top==botom){

        res+=3;

        while(ketac<keta) res+=(lint)pow(10,ketac-2)*2,ketac++;

        lint rem=(x-top*(lint)pow(10,keta-1)-botom)/5;

        if(keta>=3) res+=rem;

    }

    if(top>botom) while(ketac<=keta) res+=(lint)pow(10,ketac-2)*2,ketac++;

    if(top<botom) while(ketac<keta) res+=(lint)pow(10,ketac-2)*2,ketac++;

    return res;

}



int main(void){

    lint N;

    cin >> N;

    lint dp[220000]={};

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

    for(int i=10;i<=N;i++){

        if(i%10==0) dp[i]=dp[i-1];

        else dp[i]=dp[i-1]+calc(i);

    }

    cout << dp[N] << endl;

}

// Faster C++ solution for the same problem (measured speedup: 2.8343168369261544x):
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>

using namespace std;

struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

#define max3(a,b,c) max(a,max(b,c))

#define min3(a,b,c) min(a,min(b,c))

#define MOD 1000000007

#define INF (1<<30)

#define LINF (lint)(1LL<<56)

#define endl "\n"

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)

#define Flag(x) (1<<(x))

#define Flagcount(x) __builtin_popcount(x)

#define pint pair<int,int>

#define pdouble pair<double,double>

#define plint pair<lint,lint>

typedef long long lint;

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

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



pint pick(int x){

    pint res;

    res.second=x%10;

    while(x){

        res.first=x;

        x/=10;

    }

    return res;

}



int main(void){

    int N;

    cin >> N;

    lint sum[10][10]={};

    lint ans=0;

    for(int i=1;i<=N;i++){

        pint p=pick(i);

        sum[p.first][p.second]++;

    }

    for(int i=1;i<=9;i++) for(int j=1;j<=9;j++){

        ans+=sum[i][j]*sum[j][i];

    }

    cout << ans << endl;

}