stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}


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

}

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

	#define mx 300005

	using namespace std;



	int a[mx], n;

	vector<vector<bool> > vis(mx, vector<bool> (20, false));

	vector<vector<pair<int,int> > > memo(mx, vector<pair<int, int> > (20, {0, 0}));



	void dp(int num, int pos) {

		if(pos == 0) {

			memo[num][0].first = a[num];

			vis[num][0] = true;

			return;

		}

		if(vis[num][pos]) return;

 		vector<int> cons;

		dp(num, pos-1);

		cons.push_back(memo[num][pos-1].first);

		cons.push_back(memo[num][pos-1].second);

		if(num & (1<<(pos-1))) {

			dp(num ^ (1<<(pos-1)), pos-1);

			cons.push_back(memo[num ^ (1<<(pos-1))][pos-1].first);

			cons.push_back(memo[num ^ (1<<(pos-1))][pos-1].second);

		}

		sort(cons.begin(), cons.end(), greater<int>());

		memo[num][pos].first = cons[0];

		memo[num][pos].second = cons[1];

		vis[num][pos] = true;

	}



	int main() {

		ios_base::sync_with_stdio(false);

	    cin.tie(NULL);

	    cout.tie(NULL);



		cin >> n;

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

			cin >> a[i];

			

		}

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

			if(!vis[i][n]) {

				dp(i, n);

			}

		}

		int mxv = 0;

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

			mxv = max(memo[i][n].first + memo[i][n].second, mxv);

			cout << mxv << "\n";	

		}

		return 0;

	}
// Original C++ solution (slower):
#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;

 }

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



}

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

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

#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

#define pb push_back



using ll = long long;

using namespace std;

using pint = pair<int,int>;

using pll = pair<ll,ll>;

const int INFint = 1e9;

const ll INFll = 1e18;

ll MOD=1e9+7;



ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数

ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数



// aのn乗をMODで割りながら計算する

ll modpow(ll a, ll n) {

  long long res = 1;

  while (n > 0) {

    if (n & 1) res = res * a % MOD;

    a = a * a % MOD;

    n >>= 1; // right shift

  }

  return res;

}



// MODを法としたaの逆元を計算する

ll modinv(ll a) {

  return modpow(a, MOD - 2);

}



int main(){

  string s;

  cin>>s;

  int N = int(s.size());

  string ans;

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

    //cout << ans << endl;

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

      if (int(ans.size()) != 0){

        ans = ans.substr(0,int(ans.size())-1);

      }

    }else{

      ans += s[i];

    }

  }

  cout << ans << endl;

  return 0;

}
// Original C++ solution (slower):
#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;

}

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

} 

// 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 <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;

	}

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



}

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

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

#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

#define pb push_back



using ll = long long;

using namespace std;

using pint = pair<int,int>;

using pll = pair<ll,ll>;

const int INFint = 1e9;

const ll INFll = 1e18;

ll MOD=1e9+7;



ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数

ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数



// aのn乗をMODで割りながら計算する

ll modpow(ll a, ll n) {

  long long res = 1;

  while (n > 0) {

    if (n & 1) res = res * a % MOD;

    a = a * a % MOD;

    n >>= 1; // right shift

  }

  return res;

}



// MODを法としたaの逆元を計算する

ll modinv(ll a) {

  return modpow(a, MOD - 2);

}



int main(){

  string s;

  cin>>s;

  int N = int(s.size());

  string ans;

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

    //cout << ans << endl;

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

      if (int(ans.size()) != 0){

        ans = ans.substr(0,int(ans.size())-1);

      }

    }else{

      ans += s[i];

    }

  }

  cout << ans << endl;

  return 0;

}
// Original C++ solution (slower):
#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;

}


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

}

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

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

using namespace std;

using ll = long long;

using P = pair<ll, ll>;

const string ln = "\n";

constexpr int INF = 1001001001;

constexpr int MOD = 1000000007;



int main() {

  cin.tie(nullptr);

  ios::sync_with_stdio(false);



  int n;

  cin >> n;



  ll ans = 1;



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

    ans *= i % MOD;

    ans %= MOD;

  }



  cout << ans << ln;



  return 0;

}
// Original C++ solution (slower):
#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;

}

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

}

// 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;

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;

}

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

}


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

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

using namespace std;

using ll = long long;

using P = pair<ll, ll>;

const string ln = "\n";

constexpr int INF = 1001001001;

constexpr int MOD = 1000000007;



int main() {

  cin.tie(nullptr);

  ios::sync_with_stdio(false);



  int n;

  cin >> n;



  ll ans = 1;



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

    ans *= i % MOD;

    ans %= MOD;

  }



  cout << ans << ln;



  return 0;

}
// Original C++ solution (slower):
#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;

}


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

}


// 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<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");

}

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

}


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

using ll = long long;

using namespace std;



int main() {

  int A,B,C;

  cin>>A>>B>>C;

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

    if ((A*i-C)%B==0&&(A*i-C)>=0){

      cout << "YES"<<endl;

      return 0;

    }

  }

  cout << "NO"<<endl;

  return 0;

}
// Original C++ solution (slower):
/*===============================================================

*  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;

}


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

}

// Fastest known solution for this problem:


#include <iostream>

#include <cstdio>



using namespace std;



int main()

{

    long long n,k;

    long long i,j;

    long long ans;

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

    {

        ans=0;

        for (i=1;i<=n-k;i++)

        {

            j=i+k;

            ans+=(n/j)*i;

            if(n%j-k>=0)

                ans+=n%j-k+1;

        }

        if (k==0)

            ans=n*n;

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

    }

    return 0;

}
// Original C++ solution (slower):
//

// 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;

}


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

}


// 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 <stdio.h>

#include <string.h>

#include <stdlib.h>

//#include <math.h>

//#include <algorithm>

#include <vector>



#define MIN(a, b) ((a)>(b)? (b): (a))



int main(int argc, char* argv[])

{

    long n, k;

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



    std::vector<long> h(n);

    long i, j;

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

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

    }



    long c[100001]={0};



    c[0]=0;

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

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

        for(j=2; j<=k && i-j>=0; j++) {

            long tmp = c[i-j]+abs(h[i-j]-h[i]);

            c[i] = MIN(c[i], tmp);

        }

    }

    printf("%ld\n", c[n-1]);



    return 0;

}


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

#include <string>

#include <cstring>

#include <stdlib.h>

#include <math.h>

#include <algorithm>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <list>

#include <iterator>

#include <assert.h>

#pragma warning(disable:4996) 



typedef long long ll;

#define MIN(a, b) ((a)>(b)? (b): (a))

#define MAX(a, b) ((a)<(b)? (b): (a))

#define LINF 9223300000000000000

#define INF 2140000000

const long long MOD = 1000000007;

using namespace std;



ll dp[100005];



int main(int argc, char* argv[])

{

    int n,K;

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



    vector<int> h(n);

    int i;

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

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

    }

    dp[0]=0;

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

        dp[i]=INF;

        int j;

        for(j=MAX(0,i-K); j<i; j++) {

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

        }

    }

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

    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;





}