stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



#define pb push_back

#define mp make_pair

#define fi first

#define se second

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

#define rall(x) (x).rbegin(), (x).rend()

#define MAX 1000000

//3

typedef long long ll;

typedef pair<int,int> pii;

priority_queue< int > pq;

priority_queue< int , vector<int> , greater<int> > rpq;

set<int>s;

set <int > :: iterator itr; 

vector<int> vec[1001];

int r,n,m,inp,tc;

int arr[1000007]= {};

map<int , int> mymap;





int main()

{

	int n,h;

	cin>>n>>h;

	

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

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

	}

	

	for(int i=0 ;i<h-1 ; i++)

	arr[i] = arr[h-1];

	

	int dp[1000007]= {0};

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

	dp[i] = 0;

	

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

		dp[i] = INT_MAX;

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

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

		}

	}

	cout<<dp[n+(h-2)]<<endl;

    return 0;

}



//65 900 17 13

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;



int arr[100007];

int dp[100007];



int Solve(int idx, int n, int k){

//	cout<<cost<<" "<<idx<<endl;

	if(idx >= n)return 1e9;

	if(idx == n - 1){

		return 0;	

	}

	

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

	

	int ans = 1e9;

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

		ans = min(ans, abs(arr[idx] - arr[idx+i]) + Solve(idx+i, n, k));

	}

	

	return dp[idx] = ans;

}



int main(){

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

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

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

		

	cout<<Solve(0,n,k)<<endl;

	return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





}
// Original C++ solution (slower):
#include<bits/stdc++.h>

  using namespace std ;



 int main(){

   int k,i;

   string s;

   cin>>k;

   cin>>s;

    if(s.size()<=k){

        cout<<s<<endl;

    }

    else{

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

        cout<<s[i];

    }

    cout<<"...";

    }







  return 0;

 }


// Optimized solution to the same problem (faster):
#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");

	}

}

// Fastest known solution for this problem:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mod = 1000000007;

const double PI = acos(-1);



int main()

{

	int k;

	string s;

	cin >> k >> s;

	if (s.size() <= k) cout << s << endl;

	else cout << s.substr(0, k) + "..." << endl;

}
// Original C++ solution (slower):
#include <iostream>

#include <cstring>

#include <algorithm>

#include <cmath>

#define N 100006

#define ll long long

#define dd double

#define esp 1e-10

using namespace std;



int n,m;

int num[N];



int main(){

	ll ans=0;

	int t1,t2;

	memset(num,0,sizeof(num));

	scanf("%d",&n);

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

		scanf("%d",&t1);

		ans+=t1;

		++num[t1];

	}

	scanf("%d",&m);

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

		scanf("%d%d",&t1,&t2);

		num[t2]+=num[t1];

		ans+=(t2-t1)*num[t1];

		num[t1]=0;

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

	}

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

const int Maxn = 1e5 + 10;

int a[Maxn], n,q;

int main() {

//#define LOCAL

#ifdef LOCAL

    freopen("/Users/ttjy/Desktop/in.txt", "r", stdin);

#endif

    cin >> n;

    int ai;

    long long sum = 0;

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

        scanf("%d", &ai);

        a[ai]++;

        sum += ai;

    }

    cin >> q;

    while (q--) {

        int b, c;

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

        sum +=a[b]* c-a[b]* b;

        a[c] += a[b];

        a[b] = 0;



        cout << sum << endl;

    }

    return 0;

}

// Fastest known solution for this problem:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#include <string>

const int mxN=1e5;

const int maxN=5e3;

#define ld long double

#define pb push_back

#define mp make_pair

#define ins insert

#define vi vector<int>



int main()

{

    int n;

    cin >> n;

    int cnt[100000]={};

    ll s=0;

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

    {

        int x;

        cin >> x;

        cnt[x-1]++;

        s+=x;

    }

    int q;

    cin >> q;

    while(q--)

    {

        int b,c;

        cin >> b >> c;

        s+=cnt[b-1]*(c-b);

        cnt[c-1]+=cnt[b-1];

        cnt[b-1]=0;

        cout << s << "\n";

    }

}
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>



using namespace std;



int N, A, B, used[100], rings[100], G[100][199];



int rec(int pos)

{

	int ret = 1; used[pos] = 1;



	for(int i = 0; i < rings[pos]; i++)

	{

		if(!used[G[pos][i]])

		{

			ret = max(ret, rec(G[pos][i]) + 1);

		}

	}



	used[pos] = 0;



	return ret;

}



int main()

{

	int N, A, B;



	while(true)

	{

		scanf("%d", &N);

 

		if(N == 0) { break; }



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

		{

			used[i] = 0; rings[i] = 0;

		}



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

		{

			scanf("%d", &A); A--;

			scanf("%d", &B); B--;



			G[A][rings[A]] = B; rings[A]++;

			G[B][rings[B]] = A; rings[B]++;

		}



		int nodes = 0;



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

		{

			if(rings[i])

			{

				nodes++;

			}

		}



		int ret = 0;



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

		{

			ret = max(ret, rec(i));



 			if(ret == nodes) break;

		}

 

		printf("%d\n", ret);

	}



	return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int N, A, B, v[100], r[100], G[100][199];

int rec(int pos) {

	int ret = 0; v[pos] = 1;

	for (int i = 0; i < r[pos]; i++) {

		if (!v[G[pos][i]]) ret = max(ret, rec(G[pos][i]));

	}

	v[pos] = 0;

	return ret + 1;

}

int main() {

	while (scanf("%d", &N), N) {

		for (int i = 0; i < 100; i++) r[i] = 0;

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

			scanf("%d%d", &A, &B), A--, B--;

			G[A][r[A]++] = B, G[B][r[B]++] = A;

		}

		int ret = 0;

		for (int i = 0; i < 100; i++) ret = max(ret, rec(i));

		printf("%d\n", ret);

	}

	return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <set>

#include <cstring>

#include <vector>

using namespace std;



//int node[101][101];

int visit[101];

int ans,last;

int die[101];

int flag;



void dfs(int now, int cnt, int *st, vector<vector<int> >& vv){

	if( cnt>ans ){

		ans=cnt;

		last = now;

		flag = 1;

	}

	for(int next=0; next<vv[now].size(); next++)if( !visit[vv[now][next]] ){

		int k = vv[now][next];

		visit[k] = die[k] = 1;

		st[cnt] = k;

		dfs(k,cnt+1,st,vv);

		visit[k] = 0;

	}

	return ;

}



int main(){

	int n;

	while(cin>>n,n){

		set<int> s;

		vector<vector<int> > vv(101);

		ans = 0;

		//memset(node,0,sizeof(node));

		memset(visit,0,sizeof(visit));

		memset(die,0,sizeof(die));

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

			int a,b; cin>>a>>b;

			//node[a][b] = node[b][a] = 1;

			vv[a].push_back(b);

			vv[b].push_back(a);

			s.insert(a);

			s.insert(b);

		}

		int tmp[101];

		/*

		for(int i=0; i<vv.size(); i++){

			printf("vv[%d].size = %d\n",i,vv[i].size());

			for(int j=0; j<vv[i].size(); j++)

				printf("%d ",vv[i][j]);

			puts("");

		}

		*/

		for(set<int>::iterator it=s.begin(); it!=s.end(); it++)if( !die[*it] ){

			flag = 0;

			

			visit[*it]=1;

			tmp[0] = *it;

			dfs(*it,1,tmp,vv);

			visit[*it]=0;

			

			die[last] = 0;

			//printf("*it:%d\n",*it);



		}

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

	}

	return 0;

}
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

using namespace std;

typedef long long ll;

#define endl "\n";

#define MAX 10000001+9   //Maximum array size;

#define loop(n) for(ll i=0;i<n;i++)

#define loop2(n) for(ll i=0;i<n;i+=2)

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

#define sz(v)  v.size()

typedef vector<ll> vi;

typedef set<ll> si;



void fast() {



    cin.tie(0);

    cin.sync_with_stdio(0);

}



int pow(int a, int b) {

    int pow = 1;

    loop(b)pow *= a;

    return pow;

    //thanks m7md :)

}



int main() {

    fast();

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

    int n,k,counter=0;cin>>n>>k;

    int c[n];

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

        cin>>c[i];

        if(c[i]>=k)counter++;

    }

    cout<<counter;

}




// Optimized solution to the same problem (faster):
#include<stdio.h>



int main ()

{

	long long int N,K,c=0,i,h[100000]; 

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

	

	

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

	{

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

		if(h[i]>=K)

		{

			c++;

		}

	}

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

	return 0;

	

}

// Fastest known solution for this problem:
#include <bits/stdc++.h>

using namespace std ;

 

int main()

{

  int n , k , a , answer ;

  cin >> n >> k ;

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

  {

    cin >> a ;

    if(a >= k)

      answer++ ;

  }

  cout << answer << endl ;

}
// Original C++ solution (slower):
// In the name of God



#include <bits/stdc++.h>



using namespace std;



int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(0);



	int k;

	cin >> k;

	

	string s;

	cin >> s;



	cout << s.substr(0, min(k, (int)s.length()));



	if(s.length() > k) cout << "...";



	return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main(){

	int k;

	char word[100];

	scanf("%d", &k);

	scanf("%s", &word);

	

	int len = 0;

	

	for(int i = 0; word[i] != '\0'; i++){

		len++;

	}

	

	if(len <= k){

		printf("%s\n", word);

	}

	else{

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

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

		}

		printf("...\n");

	}

	return 0;

}

// Fastest known solution for this problem:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mod = 1000000007;

const double PI = acos(-1);



int main()

{

	int k;

	string s;

	cin >> k >> s;

	if (s.size() <= k) cout << s << endl;

	else cout << s.substr(0, k) + "..." << endl;

}
// Original C++ solution (slower):
#include <iostream>

#include <assert.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <string.h>

#include <cmath>

#include <algorithm>

#include <iomanip>

using namespace std;



const int N = 1e5 + 2;



int n, k, h[N];

long long dp[N];



long long calc(int i)

{

    if (i == n - 1)

    {

        return 0;

    }

    long long &ret = dp[i];

    if (ret != -1)

    {

        return ret;

    }

    ret = 1e9;

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

    {

        if (i + j >= n)

        {

            break;

        }

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

    }

    return ret;

}



int main()

{

    memset(dp, -1, sizeof dp);

    cin >> n >> k;

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

    {

        cin >> h[i];

    }

    cout << calc(0) << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <assert.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <string>

#include <string.h>

#include <cmath>

#include <algorithm>

#include <iomanip>

#define ll long long

using namespace std;



const int N = 1e5 + 7;

const long long oo = 1e18L + 5;



int n, k;



int main() {

    cin >> n >> k;

    vector<int> h(n + 1);

    vector<ll> dp(n + 2, oo);

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

        cin >> h[i];

    }

    dp[0] = 0;

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

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

            if (i + j >= n) {

                break;

            }

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

        }

    }

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

    return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





}
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <cmath>

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <iomanip>

#include <string>

#include <set>

#include <vector>

#include <queue>

#include <stack>

#include <map>

using namespace std;

#define ms(a, x) memset(a, x, sizeof(a))

#define fore(i, a, n) for (long long i = a; i < n; i++)

#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)

#define si(a) scanf("%d", &a)

#define sl(a) scanf("%lld", &a)

#define sii(a, b) scanf("%d%d", &a, &b)

#define sll(a, b) scanf("%lld%lld", &a, &b)

#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

#define debug(a) cout << a << endl

#define pr(a) printf("%d ",a)

#define endl '\n'

#define pi acos(-1.0)

#define tr t[root]

#define lson t[root << 1]

#define rson t[root << 1 | 1]

#define IO ios::sync_with_stdio(false), cin.tie(0)

#define ull unsigned long long

const double eps = 1e-8;

inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }

typedef long long ll;

const int inf=0x3f3f3f3f;

const int MAXN = 1e5 + 10;

int n,a[MAXN],k;

ll dp[MAXN];

int main()

{

	sii(n,k);

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

	ms(dp,inf);dp[1]=0;dp[2]=abs(a[1]-a[2]);

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

	{

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

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

	}

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

 } 

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



const int nax = 1e5+103;

int n, k;

int dp[nax];

int a[nax];

int f(int i){

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

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

	int ans = abs(a[i]-a[i+1])+f(i+1);

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

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

	}

	return dp[i]=ans;

}

int main(){

	cin>>n>>k;

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

	memset(dp, -1, sizeof dp);

	cout<<f(0)<<endl;

	return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





}
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

using ll = long long;



using Field = vector<vector<int>>;

using Graph = vector<vector<int>>;

using VI = vector<int>;

using VC = vector<char>;

using PI = pair<int, int>;



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

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



const long long INF = 1LL<<60;

const int mod = 1000000007;



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

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



int N, K;

vector<int> h(100010);

vector<int> dp(100010, INT32_MAX);





int main() {

    cin.tie(0);

    ios_base::sync_with_stdio(false);

    cin >> N >> K;

    REP(i, N) cin >> h.at(i);



    dp.at(0) = 0;



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

        for(int j = i - K; j < i; j++) {

            if (j < 0) continue;

            chmin(dp.at(i), dp.at(j) + abs(h.at(j) - h.at(i)));

        }

    }



    cout << dp.at(N - 1) << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

using ll = long long;



using Field = vector<vector<int>>;

using Graph = vector<vector<int>>;

using VI = vector<int>;

using VC = vector<char>;

using PI = pair<int, int>;



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

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



const long long INF = 1LL<<60;

const int mod = 1000000007;



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

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



int N, K;

vector<ll> h;

vector<ll> dp;



int main() {

    cin.tie(0);

    ios_base::sync_with_stdio(false);



    cin >> N >> K;

    h.resize(N + K + 10, 0);

    dp.resize(N + K + 10, INF);



    REP(i, N) cin >> h.at(i);



    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;

}

// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

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







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

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

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



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

          }

     }     



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





}
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

const int N=1e5+5;

int A[N];

char ans[N],ch,q;

bool ac[N];

int n,x,m;

int main(){

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

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

        scanf("%d %c%c",&x,&ch,&q);

        if(ch=='A') ac[x]=1;

        else if(!ac[x])A[x]++;

    }

    int sum=0 , sAc=0;

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

        sum+=A[i]*ac[i];

        sAc+=ac[i];

    }

    printf("%d %d\n",sAc,sum);

    return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main()

{

    ll n, m;

    cin>>n>>m;

    ll x;

    string s;

    map<ll,ll>mp1, mp2;

    ll c = 0, p = 0;

    for(ll i=0; i<m; i++)

    {

        cin>>x;

        cin>>s;

        if(mp2[x] == 0 && s == "WA") mp1[x]++;

        if(mp2[x] == 0 && s == "AC")

        {

            mp2[x] = 1;

            p += mp1[x];

            c++;

        }

    }

    cout<<c<<" "<<p<<endl;

    return 0;

}


// Fastest known solution for this problem:
#include <iostream>

#include <vector>

using namespace std;

int main ()

{

	int n, m, acc=0, pen=0; cin>>n>>m;

	bool test[n+1]={false};

	int arr[n+1]={0};

	int p[m];

	string s[m];

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

	{

		cin>>p[i];

		cin>>s[i];

		if (test [p[i]]==false && s[i]=="AC")

		{

			test[p[i]]=true;

			acc++;

			pen+=arr[p[i]];

		}

		if (test[p[i]]==false && s[i]=="WA")

		{

			arr[p[i]]++;

		}

	}

	cout<<acc<<endl<<pen<<endl;

	return 0;

}
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

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



int n, m;

vector<int> p0(100100); //提出番号→問題番号

vector<string> p1(100100);//提出番号→提出結果

vector<bool> q(100100); //問題ごとにacしたかを記録

vector<int> q1(100100); //いつ正解したか

int ac = 0, wa = 0;



void input(){

  cin >> n >> m;

  rep(i, m){

    cin >> p0.at(i) >> p1.at(i);

    //cout<< p0.at(i) << " "<< p1.at(i) << " ";

  }

  rep(i, 100100){

    q.at(i) = false;

  }

}

/*

void update(int i){ //提出番号→問題番号、結果→更新

  int num = p0.at(i);//問題番号

  //cout <<  num <<" "<<q.at(num) << " ";

  if(q.at(num)){

    return;

  }

  if(p1.at(i) == "AC"){

    ac++;

    q.at(num) = true;

  }else if(p1.at(i) == "WA"){

    wa++;

  }

}*/

void func1(int i){

  int num = p0.at(i);

  if(!q.at(num) && p1.at(i) == "AC"){

    ac++;

    q.at(num) = true;

    q1.at(num) = i;

  }

}

void func2(int i){

  int num = p0.at(i);

  if(q.at(num) && p1.at(i) == "WA" && q1.at(num) > i){

    wa++;

  }

} 



void solve(){

  input();

  rep( i , m ){

    func1(i);

  }

  rep( i, m ){

    func2(i);

  }

  cout << ac << " " << wa << endl;

}



int main() {

  solve();

  return 0;

}


// Optimized solution to the same problem (faster):
/*

１つの配列で実装してみる。

ACしたかどうかは数の正負で判定する。ACするまでのWAの回数は、負の数で数える。

*/

#include <bits/stdc++.h>

using namespace std;

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

typedef long long int ll;

typedef pair<int, int> P;



int n, m;

vector<int> Q(101010, -1);



int main(){

  cin >> n >> m;

  rep(i, m){

    int p; string s;

    cin >> p >> s;

    if(s == "WA" && Q[p] < 0){

      Q[p]--;

    }else{

      Q[p] = abs(Q[p]);

    }

  }

  int ac = 0, wa = 0;

  rep(i, n + 1){

    if(Q[i] > 0){

      ac++;

      wa += Q[i] - 1;

    }

  }

  cout << ac << " " << wa << endl;

  return 0;

}

// Fastest known solution for this problem:
#include <iostream>

#include <vector>

using namespace std;

int main ()

{

	int n, m, acc=0, pen=0; cin>>n>>m;

	bool test[n+1]={false};

	int arr[n+1]={0};

	int p[m];

	string s[m];

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

	{

		cin>>p[i];

		cin>>s[i];

		if (test [p[i]]==false && s[i]=="AC")

		{

			test[p[i]]=true;

			acc++;

			pen+=arr[p[i]];

		}

		if (test[p[i]]==false && s[i]=="WA")

		{

			arr[p[i]]++;

		}

	}

	cout<<acc<<endl<<pen<<endl;

	return 0;

}