stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int N, M, Q;

int a[50], b[50], c[50], d[50];



int main() {

    cin >> N >> M >> Q;

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

        cin >> a[i] >> b[i] >> c[i] >> d[i];

    }

    int ma = 0;

    for (int i0 = 1; i0 <= M; ++i0) {

        for (int i1 = i0; i1 <= M; ++i1) {

            for (int i2 = i1; i2 <= M; ++i2) {

                for (int i3 = i2; i3 <= M; ++i3) {

                    for (int i4 = i3; i4 <= M; ++i4) {

                        for (int i5 = i4; i5 <= M; ++i5) {

                            for (int i6 = i5; i6 <= M; ++i6) {

                                for (int i7 = i6; i7 <= M; ++i7) {

                                    for (int i8 = i7; i8 <= M; ++i8) {

                                        for (int i9 = i8; i9 <= M; ++i9) {

                                            vector<int> A{i0, i1, i2, i3, i4, i5, i6, i7, i8, i9};

                                            int point = 0;

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

                                                if (A[b[i]-1] - A[a[i]-1] == c[i]) {

                                                    point += d[i];

                                                }

                                            }

                                            if (ma < point) {

                                                ma = point;

                                            }

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

            }

        }

    }

    cout << ma << "\n";

}

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

using namespace std;



int N, M, Q;

int a[50], b[50], c[50], d[50];

int A[10];

int max_score = 0;



void dfs(int dep, int low) {

    if (dep == N) {

        int score = 0;

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

            if (A[b[i]-1] - A[a[i]-1] == c[i]) {

                score += d[i];

            }

        }

        max_score = max(max_score, score);

    }

    else {

        for (int i = low; i <= M; ++i) {

            A[dep] = i;

            dfs(dep + 1, i);

        }

    }

}



int main() {

    cin >> N >> M >> Q;

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

        cin >> a[i] >> b[i] >> c[i] >> d[i];

    }



    dfs(0, 1);

    cout << max_score << "\n";

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

#include<iostream>

#include<cstring>

#include<algorithm>

using namespace std;

int mx[1<<18], n, a[1<<18];



void get_ans (int l, int r) {

	int b[(r-l)/2];

	if(l+1 == r) return;

	int mid = l+r >> 1;

	get_ans(l, mid);

	for(int i = mid; i < r; ++i)

		mx[i] = max(mx[i], a[i] + a[i - (r - mid)]);

	for(int i = mid; i < r; ++i)

		b[i-mid] = a[i], a[i] = max(a[i], a[i - (r - mid)]);

	get_ans(mid, r);

	for(int i = mid; i < r; ++i)

		a[i] = b[i-mid];

}



int main() {

	scanf("%d", &n);

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

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

	}

	get_ans(0, 1<<n);

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

		mx[i] = max(mx[i], mx[i-1]);

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

	}

	return 0;

}


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

#include <cstdio>

#include <cstring>



#define int long long



const int Maxv = 300010; 



int ans[Maxv], max[Maxv], num, n; 



signed main() {

    scanf("%lld", &n); 

    

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

        scanf("%lld", &num); 

    

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

            ans[j] = std::max(ans[j], max[j] + num); 

            max[j] = std::max(max[j], num); 

        }

    }

       

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

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

        ans[i + 1] = std::max(ans[i + 1], ans[i]); 

    }

    

    return 0; 

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

 using namespace std;

#define  ll long long



 int main() {

     string s ;

     cin >> s ;

     string ans ="" ;

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

         if(s[i]=='1') ans+="1";

         else if(s[i]=='0') ans+="0";

         else if(ans.size()>=1) ans.pop_back();

     }

     cout<<ans<<endl;

 }

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

#include <string.h>



void hekerman(char x[105]);



int main() {



    char x[105];



    scanf("%s", x);



    hekerman(x);



    return 0;

}



void hekerman(char x[105]) {



    int i, cnt = 0;

    char y[105];

    

    for(i = 0; i < strlen(x); i++) {

        if(x[i] == 'B') {

            cnt--;

        } else {

            y[cnt++] = x[i];

        }



        if(cnt < 0) {

            cnt = 0;

        }

    }



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

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

    }

    printf("\n");



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

#include <iostream>

#include <algorithm>

 

using namespace std;



int N, A, B, used[100], rings[100]; vector<int> G[100];

 

int rec(int pos)

{

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

     

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

    {

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

        {

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

        }

    }

     

    used[pos] = false;

     

    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] = false;

            rings[i] = 0;

            G[i].clear();

        }

     

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

        {

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

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

         

            G[A].push_back(B);

            G[B].push_back(A);

        }

         

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

        {

            rings[i] = G[i].size();

        }

         

        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;

}

// Faster C++ solution for the same problem (measured speedup: 5.009621011775071x):
#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;

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>

#include<functional>

#include <bitset>

#include<algorithm>

#include<fstream>

#include<string>

#include <cstring>

#include<stdio.h>

#include<iomanip>

#include<sstream>

#include<cmath>

#include<vector>

#include<assert.h>

#include<queue>

#include<deque>

#include<stack>

#include<set>

#include<map>

// never lose hope ..

typedef unsigned long long ull;

typedef long long ll;

typedef long double ld;

#define eps 1e-8

using namespace std;

double const  PI = 3.141592653;

const int OO = 1000000000 + 9;



void fast() {

	ios_base::sync_with_stdio(0);

	cin.tie(NULL), cout.tie(NULL);

}





int main()

{

	fast();



	int n, k;

	cin >> n >> k;

	vector<int>v(n + 1, 0), dp(n + 1, OO);

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

		cin >> v[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(v[i] - v[i - j]));

		}

	}

	cout << dp[n];





	return 0;

}

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

#include <algorithm>

#include <vector>

using namespace std;

 

int n,dp[100005],a[100005],k; 

int main(){

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

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

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

	}

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

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

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

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

		}

	}

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

	return 0;

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

#include <cstring>

#include <cmath>

#include <algorithm>

#include <iostream>

#include <sstream>

#include <queue>

#include <map>

#include <vector>

#include <set>

#include <cstdlib>

#include <stack>



using namespace std;



typedef long long LL;

#define FAST ios::sync_with_stdio(false);

const int MaxN = 105;

stack<char > que;

stack<char> st;

int main()

{

	string s;

	cin >> s;

	for(int i = 0 ; i < s.length(); i++)

	{

		if(s[i] == 'B' && !que.empty())que.pop();

		if(s[i] == '1' || s[i] == '0')que.push(s[i]);

		}

	while(!que.empty())

	{

		char n = que.top();

		st.push(n);

		que.pop();

		}

	while(!st.empty())

	{

		char m = st.top();

		cout << m;

		st.pop();

		}

	cout << endl;

	return 0;

	}

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

#include <string.h>



void hekerman(char x[105]);



int main() {



    char x[105];



    scanf("%s", x);



    hekerman(x);



    return 0;

}



void hekerman(char x[105]) {



    int i, cnt = 0;

    char y[105];

    

    for(i = 0; i < strlen(x); i++) {

        if(x[i] == 'B') {

            cnt--;

        } else {

            y[cnt++] = x[i];

        }



        if(cnt < 0) {

            cnt = 0;

        }

    }



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

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

    }

    printf("\n");



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

#include<iostream>

#include<algorithm>

#include<cstring>

using namespace std;

int main()

{

    long long n;

    cin>>n;

    long long ans = 1;

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

        ans = ans*i%1000000007;

    }

    cout<<ans;



    return 0;

}


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

const long long MOD=1e9+7;

int n;

long long ans=1;

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++) ans=(ans*i)%MOD;

	printf("%lld",ans);

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

#include<map>

#include<cmath>

#include<ctime>

#include<queue>

#include<stack>

#include<cstdio>

#include<string>

#include<vector>

#include<random>

#include<cstdlib>

#include<cstring>

#include<iomanip>

#include<iostream>

#include<algorithm>

#include<unordered_map>

#define endl "\n"

#define fi first

#define se second

#define db double

#define gcd __gcd

#define pb push_back

#define mp make_pair

#define lowbit(x) (x & (-x))

#define PII  pair<int, int> 

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

#define debug(x) cout << #x << " = " << x << endl

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

#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)

#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

template<class T> inline T qmin(T a, T b) { return a < b ? a : b; }

template<class T> inline T qmax(T a, T b) { return a > b ? a : b; }

typedef long long ll;

typedef unsigned long long ull;

const db eps = 1e-9;

const db PI = acos(-1);

const int inf = 0x3f3f3f3f;

const int mod = (int)1e9 + 7;

const int maxn = (int)1e5 + 200;//remember to modify it, No RE or MLE

const ll INF = 0x3f3f3f3f3f3f3f3f;

using namespace std;

ll qpow(ll x, ll y) { ll ret = 1; for( ; y; y >>= 1, x = (x * x) % mod) if(y & 1) ret = (ret * x) % mod; return ret; }



inline int read(){

	char ch = getchar();

	int x = 0, f = 1;

	while(ch < '0' || ch > '9'){

		if(ch == '-') f = -1;

		ch = getchar();

	}

	while('0' <= ch && ch <= '9'){

		x = x * 10 + ch - '0';

		ch = getchar();

	}

	return x * f;

}



int n, k;

int h[maxn], dp[maxn];



int main()

{

	n = read(), k = read();

	rep(i, 1, n) h[i] = read();

	memset(dp, 0x3f, sizeof dp);

	dp[1] = 0;

	rep(i, 1, n){

		rep(j, 1, k) dp[i+j] = qmin(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: 1.3805022049944475x):
#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 <bits/stdc++.h>



using namespace std;

int n,k;

int ar[100005];

int mem[100005];



int solve(int ind,int ki){

    if(ind==n-1){

        return 0;

    }

    if(ind>=n||ki>k){

        return 1e9;

    }

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

        return mem[ind];

    }

    int ret=1e9;

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

    ret=min(ret,solve(ind,ki+1));

    return mem[ind]=ret;

}



int main() {

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

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

    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,1)<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3894029239165315x):
#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>

using namespace std;

long long  a,ans=1,mod=1000000007;

int main()

{

    cin>>a;

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

	{

		ans*=i;

		ans%=mod;

	}

    cout<<ans<<endl;



    return 0;

}

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

int n,i;

long long a;

int main ()

{

	scanf ("%d",&n);

	a=1;

	for (i=1;i<=n;i++) a=a*i%1000000007;

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

	return 0;

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

#include <vector>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <set>

#include <tuple>

#include <functional>

#include <map>

#include <unordered_map>

#include <queue>

#include <tuple>



using namespace std;



#define endl '\n'



using ull = unsigned long int;

using ll = long long;



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  const int precision = 13;

  cout.precision(precision);

  cout.setf(ios_base::fixed);



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

  vector<ll> s(k+1), dp(k+1, 1e9 + 10);

  ++k;

  dp[1] = 0;

  cin >> s[1];

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

    cin >> s[i%k];

    dp[i%k] = 1e9 + 10;

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

      dp[i%k] = min(dp[(i-l)%k] + abs(s[(i-l)%k] - s[i%k]), dp[i%k]);

    }

  }



  cout << dp[n%k] << endl;



  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.7214367054384074x):
#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;	

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

#include <algorithm>

#include <cstdio>

#include <cmath>

#include <cstring>

#define ll long long

#define INF 1000000007

using namespace std;



const int MAXN=1e5+5;



int n,l,r;

ll cnt,sum;

int a[MAXN],b[MAXN],c[MAXN];



void work(int begin,int end){

	if(begin==end)

		return;

	int mid=(begin+end)/2;

	work(begin,mid);

	work(mid+1,end);

	int i=begin,j=mid+1,k=begin;

	while(i<=mid && j<=end){

		if(b[i]<b[j])

			c[k++]=b[i++];

		else{

			cnt+=(i-begin);

			c[k++]=b[j++];

		}

	}

	while(i<=mid)

		c[k++]=b[i++];

	while(j<=end){

		cnt+=(i-begin);

		c[k++]=b[j++];

	}

	for(int l=begin;l<=end;l++)

		b[l]=c[l];

}



bool check(int m){

	cnt=0;

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

		if(a[i]<=m)

			b[i]=1;

		else

			b[i]=-1;

	}

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

		b[i]+=b[i-1];

	}

	work(0,n);

	if(cnt>=(sum/2+1))

		return true;

	return false;

}



int main(){

	scanf("%d",&n);

	l=INF;r=0;sum=0;

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

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

		l=min(l,a[i]);

		r=max(r,a[i]);

		sum+=i;

	}

	while(l<r){

		int m=(l+r)/2;

		if(check(m)){

			r=m;

		}else{

			l=m+1;

		}

	}

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

	return 0;

}




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

#include<algorithm>

using namespace std;

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

#define fd(i,a,b) for(int i=a;i>=b;i--)

int n,a[110000],l,r,mi,f[220000];

long long m;

inline void add(int x){

	while (x<=n+n){

		f[x]++;

		x+=x&(-x);

	}

}

inline long long ask(int x){

	long long ans=0;

	while (x){

		ans+=f[x];

		x-=x&(-x);

	}

	return ans;

}

inline bool che(int x){

	int s=n+1;long long ans=0;//s=n TLE

	fo(i,0,n+n) f[i]=0;

	add(s);

	fo(i,1,n){

		if (a[i]>=x) s++;else s--;

		ans+=ask(s);

		add(s);

	}

	return ans>=m;

}

int main(){

	scanf("%d",&n);

	fo(i,1,n) scanf("%d",&a[i]);

	m=n*1ll*(n+1)/2;

	m=(m+1)/2;

	l=0x7fffffff;r=0;

	fo(i,1,n){

		if (a[i]<l) l=a[i];

		if (a[i]>r) r=a[i];

	}

	l--;r++;

	while (l+3<r){

		mi=(l+r)>>1;

		if (che(mi)) l=mi+1;else r=mi-1;

	}

	fd(i,r+1,l-1) if (che(i)){//che(mi)!!!

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

		return 0;

	}

	return 0;

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

#include<cmath>

#include<cstring>

#include<iostream>

#include<cstdlib>

#include<algorithm>

#include<map>

using namespace std;



int a, b, c;

int main()

{

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

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

	{

		if((i * a) % b == c)  

    	{

    		printf("YES\n");

    		return 0;

		}

	}

	printf("NO\n");

}

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

#include<cmath>



using namespace std;



int main()

{

	int a,b,c;

	int i,n,flag;

	long long sum;

	while(~scanf("%d %d %d",&a,&b,&c))

	{

		flag=0;

		n = c % b;

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

		{

			sum = (i + 1) * a;

			if(sum % b == n)

			{

				flag=1;

				break;

			}

		}

		if(flag==1)

			printf("YES\n");

		if(flag==0)

			printf("NO\n");

	}

	return 0;

}
// Slower C++ solution:
/*===============================================================

*  Filename: E.cpp

*  Author: zhuyutian

*  Date: 2018.04.16

================================================================*/

#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;

const int maxn = 100005;



int n,K;



int main()

{

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

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

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

	ll ans = 0;

	if(K == 0) ans = 1ll * n * n;

	for(int i = K; i <= n && K; i++){

		ans += n - i;

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

			if(j + i <= n) ans += i - K;

			else if(j + K <= n) ans += n - j - K + 1;

		}

	}

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

	return 0;

}


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

#include<algorithm>

using namespace std;

int n,k;

long long sum;

int main() {

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

	if(k==0) {

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

		return 0;

	}

	for(int b=k+1;b<=n;b++) {

		int a=n%b;

		if(k<=a) sum+=a-k+1;

		sum+=n/b*(b-k);

	}

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

	return 0;

}
// Slower C++ solution:
//

// Created by aqib on 4/1/20.

//



#include <bits/stdc++.h>



#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

#define endl "\n"



using namespace std;



int main() {

    fastIO;

    int N, M;

    cin >> N >> M;

    long waCnt[100001] = {0};

    bool ac[100001];

    memset(ac, false, sizeof(ac));

    long long WAs = 0, ACs = 0;

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

        int serial;

        string res;

        cin >> serial;

        cin >> res;

        if (res == "AC" && !ac[serial]) {

            ac[serial] = true;

            ACs++;

            WAs += waCnt[serial];

        } else if (res == "WA" && !ac[serial]) {

            waCnt[serial]++;

        }

    }

    cout << ACs << " " << WAs << endl;

    return 0;

}


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

#define rush() int T;scanf("%d",&T);int kase=1;while(T--)

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

#define max(x,y) ((x)>(y)?(x):(y))

#define min(x,y) ((x)<(y)?(x):(y))

#define pb(x) push_back(x)

#define mem(a) memset(a,0,sizeof(a))

using namespace std;

using std::bitset;

typedef long long ll;

const ll maxn=1e6+5;

const ll mod=998244353;

const ll INF=0x3f3f3f3f3f3f3f3f;

const long double PI=acos(-1.0);

const long double eps=1e-5;

inline ll read(){ll ans=0,flag=1;char c;c=getchar();while(c<'0' || c>'9'){if(c=='-')flag=-1;c=getchar();}while(c>='0' && c<='9'){ans=ans*10+(ll)(c-'0');c=getchar();}return ans*flag;}

ll quickpow(ll x,ll y,ll mod){ll ans=1;while(y){if(y&1)ans=ans*x%mod;x=x*x%mod;y>>=1;}return ans;}



bool a[100010];

int b[100010];



int main()

{

   int n,m;

   cin>>n>>m;

   mem(a); mem(b);

   int numac=0,numfa=0;

   int x;

   string s;

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

   {

       cin>>x>>s;

       if(s=="AC")

       {

           if(a[x]==0)

           {

               numac++;

               a[x]=1;

               numfa+=b[x];

           }

       }

       else

       {

           if(a[x]==1)

            continue;

           else

            b[x]++;

       }

   }

   cout<<numac<<" "<<numfa;

    return 0;

}