akhauriyash/Code-Regression huggingface dataset:
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
int dist[2][300][300];
void solve() {
	int h, w;
	cin >> h >> w;
	vector<string> inputs;
	REP(i, h) {
		string s;
		cin >> s;
		inputs.push_back(s);
	}
	queue<pair<int, int>> next;
	REP(i,h) {
		REP(q, w) {
			if (inputs[i][q] == '@') {
				next.push(mp(i, q));
			}
			else {
				dist[0][i][q] = 1e9;
			}
		}
	}
	while (next.empty() == false) {
		pair<int, int> now = next.front();
		next.pop();
		int dx[4] = { 1,-1,0,0 };
		REP(t, 4) {
			int x = now.first + dx[t];
			int y = now.second + dx[3 - t];
			if (x >= 0 && x < h && y >= 0 && y < w) {
				if (inputs[x][y] == '#') continue;
				if (dist[0][now.first][now.second] + 1< dist[0][x][y]){
					dist[0][x][y] = dist[0][now.first][now.second] + 1;
					next.push(mp(x, y));
				}
			}
		}
	}
	REP(i, h) {
		REP(q, w) {
			if (inputs[i][q] == '$') {
				next.push(mp(i, q));
			}
			else {
				dist[1][i][q] = 1e9;
			}
		}
	}
	while (next.empty() == false) {
		pair<int, int> now = next.front();
		next.pop();
		int dx[4] = { 1,-1,0,0 };
		REP(t, 4) {
			int x = now.first + dx[t];
			int y = now.second + dx[3 - t];
			if (x >= 0 && x < h && y >= 0 && y < w) {
				if (inputs[x][y] == '#') continue;
				if (dist[1][now.first][now.second] + 1 < dist[1][x][y]) {
					dist[1][x][y] = dist[1][now.first][now.second] + 1;
					next.push(mp(x, y));
				}
			}
		}
	}
	REP(i, h) {
		REP(q, w) {
			if (inputs[i][q] == '%') {
				if (dist[0][i][q] < dist[1][i][q]) {
					cout << "Yes" << endl;
					return;
				}
			}
		}
	}
	cout << "No" << endl;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; typedef long double ld;
const int INF32 = 1e9+10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K; cin >> N >> K;
  ld ans = 0.0;
  for (int i = 1; i <= N; i++) {
    int c = (K <= i ? 0 : ceil(log2(1.0*K/i)));
    ans += pow(1.0/2, c);
  }
  cout << setprecision(12) << 1.0 * ans / N << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		if (a < b) {
			if (b < c) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}else {
			System.out.println("No");
		}

	}
}



Measured memory_bytes: 26204
#include<stdio.h>
int dp[102][102][3];
int main(){
	int mod=1000000;
	int a,b;
	scanf("%d%d",&a,&b);
	if(b==1){
		int ret=1;
		for(int i=0;i<a;i++)ret=ret*2%mod;
		printf("%d\n",ret);
		return 0;
	}
	dp[1][0][0]=1;
	a++;
	for(int i=1;i<=a;i++){
		for(int j=0;j<=i;j++){
			for(int k=0;k<3;k++){
			//	printf("%d %d %d: %d\n",i,j,k,dp[i][j][k]);
				for(int l=0;l<3;l++){
					if(l-k==2||k-l==2){
						dp[i+1][i][l]=(dp[i+1][i][l]+dp[i][j][k]*(i-j))%mod;
					}
					else if(l==1){
						dp[i+1][i+1][l]=(dp[i+1][i+1][l]+dp[i][j][k])%mod;
					}
					else if(l==k){
						dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%mod;
					}else{
						dp[i+1][i][l]=(dp[i+1][i][l]+dp[i][j][k])%mod;
					}
				}
			}
		}
	}
	int ret=0;
	for(int i=0;i<102;i++)ret=(ret+dp[a+1][i][2])%mod;
	printf("%d\n",ret);
}

Measured memory_bytes: 1144
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
    public static void main(String[] args) throws IOException {
       Scanner in = new Scanner(System.in);
       int n = in.nextInt();

       long sum_ = 0, max_ = -10000000, min_ = 10000000;
       for(int i=0;i<n;i++) {
	       int d = in.nextInt();
	       sum_ += d;
	       min_ = Math.min(min_, d);
	       max_ = Math.max(max_, d);
       }
       if(n == 0) System.out.println("0 0 0\n");
       else System.out.printf("%d %d %d\n", min_, max_, sum_);
    }
}

Measured memory_bytes: 31800
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define vi vector < ll  int >
        #define CLR(a) memset((a),0,sizeof(a))
        #define mp make_pair
        #define hell 1000000007
        using namespace std;

        void solve()
        {
            ll i,j=0,r=200,p,q,k=0,ans=0,d,y=0,x,h,flag=0,n,m=0,a=hell,b=hell,id,c,h1,h2,a1,b1,w;
            cin>>n;
            vector < ll int > v(n),v2(n);
            rep(i,0,n) cin>>v[i];
            v2=v;
            sort(all(v));
            rep(i,0,n) if(v[i]!=v2[i]) y++;
            if(y<=2) cout<<"YES";
            else cout<<"NO";



        }



        signed main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge{ int from, to, cost; };

string s, mes;
string solve(string s, char c)
{
	if (c == 'C') return s.substr(1) + s[0];
	if (c == 'J') return s[s.size() - 1] + s.substr(0, s.size() - 1);
	if (c == 'E')
	{
		if (s.size() % 2 == 0) return s.substr(s.size() / 2, s.size() - 1) + s.substr(0, s.size()/2);
		else return s.substr(s.size() / 2 + 1, s.size()) + s[s.size() / 2] + s.substr(0, s.size() / 2);
	}
	if (c == 'A')
	{
		string r = "";
		REP(i, s.size()) r += s[s.size() - i - 1];
		return r;
	}
	if (c == 'M')
	{
		string r = "";
		REP(i, s.size())
		{
			if (isdigit(s[i]))
			{
				if (s[i] == '9') r += '0';
				else r += s[i] + 1;
			}
			else r += s[i];
		}
		return r;
	}
	if (c == 'P')
	{
		string r = "";
		REP(i, s.size())
		{
			if (isdigit(s[i]))
			{
				if (s[i] == '0') r += '9';
				else r += s[i] - 1;
			}
			else
			{
				r += s[i];
			}
		}
		return r;
	}
}
int main()
{
	int n;
	cin >> n;

	REP(i, n)
	{
		cin >> mes >> s;
		for (int i = mes.size() - 1; i >= 0;i--)
		{
			s = solve(s, mes[i]);
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b)
{
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}



int main(){
  int N;
  double ans = 0;
  cin >> N;
  rep(i,N){
    double a;
    string b;
    cin >> a >> b;
    if(b == "JPY") ans+=a;
    else ans += a*380000;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;

const int maxn = 100005;
int x[maxn], n, K, R;
ll ans = 1e18, now;

int main() {
	scanf("%d%d", &n, &K);
	rep (i, 1, n) scanf("%d", &x[i]);
	rep (L, 1, n - K + 1) {
		R = L + K - 1;
		if (x[L] <= 0 && x[R] >= 0)
			now = abs(x[L]) + abs(x[R]) + min(abs(x[L]), abs(x[R]));
		else
			now = max(abs(x[L]), abs(x[R]));
		ans = min(ans, now);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << '\n'

typedef int64_t Int;
const double pi = M_PI;

using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;

vector<int> color;
void dfs(const Graph &G, int v, int p, int cur) {
    color[v] = cur; // 色を塗る

    for (auto next_v : G[v]) {
        if (next_v.to == p)
            continue; // 枝刈り
        if (color[next_v.to] != -1)
            continue; // 色が塗ってあれば飛ばす

        if (next_v.weight % 2 == 0) {
            dfs(G, next_v.to, v, cur); // 次の頂点への重みが偶数なら同じ色
        } else {
            dfs(G, next_v.to, v, 1 - cur); // 奇数なら違う色
        }
    }
}

int main() {
    int N;
    cin >> N;

    Graph G(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;

        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }

    color.assign(N, -1);

    dfs(G, 0, -1, 0);

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

        cout << color[i] << endl;
    }
}


Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    cin >>N>>K;


    ll ans=pow(K-1,N-1)*K;
    cout <<  ans<< endl;


    return 0;
    

}

Measured memory_bytes: 4008
s=list(input())
top=bool()
t=[]
u=[]
n=int(input())
for i in range(n):
  q=list(map(str,input().split()))
  if q[0]=='1':
    top=not top
  else:
    if (q[1]=="1") ^ top:
      t.append(q[2])
    else:
      u.append(q[2])
s=list(reversed(t))+s+u
if top:
  print(*list(reversed(s)),sep='')
else:
  print(*s,sep='')

Measured memory_bytes: 17640
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////



int main() {
int h,w;
cin>>h>>w;
int n;
cin>>n;

int a[n+1];
rep(i,n){
	cin>>a[i];
}
int grid[h+1][w+1];
rep(i, h){
	rep(j,w){
		grid[i][j]=-1;
	}
}

int k=1;
int l=1;
for(int i=1;i<=n;i++){
int cnt=a[i];
for(int j=1;j<=cnt;j++){
grid[k][l]=i;
if(i==n && j==cnt) break;
if(l==w && k%2==1){k++;
continue;}
if(l==1 && k%2==0){k++;
continue;}
if(k%2==1){l++;
continue;}
if(k%2==0){l--;
continue;}

}

}

rep(i, h){
	rep(j, w){
if(j<=w-1){cout<<grid[i][j]<<" ";}
else{cout<<grid[i][j];}
	}
	cout<<endl;
}




return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
typedef long long ll;

ll mod(ll l, ll r){
    ll ans = 2019;
    for(ll i = l; i < r; i++){
        for(ll j = l + 1; j <= r; j++){
            ans = min(ans, (i * j) % 2019);
            if(ans == 0) return ans;
        }
    }
    return ans;
}

int main() {
    ll l, r; cin >> l >> r;
    OP(mod(l, r));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  string S;
  ll Q;
  cin >> S >> Q;
  deque<ll> ST;
  for(char c : S){
    ST.push_back(c);
  }
  ll count=0;
  for(ll i=0;i<Q;i++){
    ll T;
    cin >> T;
    if(T==1){
      count++;
    }
    else if(T==2){
      ll F;
      char C;
      cin >> F >> C;
      if((F==1 && count%2==0) || (F==2 && count%2==1)){
        ST.push_front(C);
      }
      else if((F==1 && count%2==1) || F==2 && count%2==0){
        ST.push_back(C);
      }
    }
  }
    if(count%2==1){
      reverse(ST.begin(),ST.end());
    }
  for(char x : ST){
    cout << x;
  }
}

Measured memory_bytes: 6100
#include <stdio.h>
#include<stdlib.h>

int main()
{
	int a, b;
	char op;
    while (scanf("%d %c %d", &a, &op, &b))
    {
	    if (op == '?' )
		{ 
			break;
		}
		switch (op)
		{
			case'+':
			printf("%d\n", a+b);
			break;
			case'-':
			printf("%d\n", a-b);
			break;
			case'*':
			printf("%d\n", a*b);
			break;
			case'/':
			printf("%d\n", a/b);
			break;
	     }    	
	}

	return 0;
}


Measured memory_bytes: 2040
#include<stdio.h>
int main(){
	int hin[101] = { 0 };
	int a,b,i,most=0;
	
	while((scanf("%d", &a))!=EOF){
		hin[a]++;
	}
	for(i=1;i<101;i++){
		if(most<=hin[i]){
			most=hin[i];
		}
	}
	for(i=1;i<101;i++){
		if(hin[i]==most){
			printf("%d\n",i);
		}
	}
		
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.util.stream.*;
import java.io.*;

class Graph {

  public ArrayList<Integer>[] adjacency;
  
  Graph(int n){
    adjacency = new ArrayList[n];
    for(int i = 0; i < n; i++){
      adjacency[i] = new ArrayList<Integer>();
    }
  }

  public void add_edge(int from, int to, boolean isDirected){
    adjacency[from].add(to);
    if(!isDirected){
      adjacency[to].add(from);
    }        
  }
}

public class Main {

  static Graph g;

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] in = br.readLine().split(" ");
    int n = Integer.parseInt(in[0]);
    int m = Integer.parseInt(in[1]);
    int e = n + m - 1;

    g = new Graph(n);
    int[] inCnt = new int[n];

    for(int i = 0; i < e; i++){
      in = br.readLine().split(" ");
      int a = Integer.parseInt(in[0])-1;
      int b = Integer.parseInt(in[1])-1;
      g.add_edge(a, b, true);
      inCnt[b]++;
    }
    
    br.close();

    Queue<Integer> que = new ArrayDeque<>();

    int[] parent = new int[n];

    for(int i = 0; i < n; i++){
      if(inCnt[i] == 0){
        parent[i] = -1;
        que.add(i);
        break;
      }
    }

    while(!que.isEmpty()){
      int cur = que.poll();
      for(int nex : g.adjacency[cur]){
        inCnt[nex]--;
        if(inCnt[nex] == 0){
          que.add(nex);
          parent[nex] = cur;
        }
      }
    }

    for(int i = 0; i < n; i++){
      System.out.println(parent[i]+1);
    }
  }
}

Measured memory_bytes: 71476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    int n, d;   cin >> n >> d;
    vector<vector<int>> v(n, vector<int>(d));

    for(int i=0; i<n; i++)
        for(int j=0; j<d; j++)
            cin >> v.at(i).at(j);
    int ans=0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            int sum=0;
            for(int k=0; k<d; k++){
                int dis = abs(v[i][k]-v[j][k]);
                sum += dis*dis;
            }
            for(int i=0; i<=sum; i++){
                if(i*i==sum) ans += 1;
                if(sum<i*i) break;
            }

        }
    }
    cout << ans << endl;
    

}
    


Measured memory_bytes: 256
A, B, C, D = [int(v) for v in input().split()]


def gcd(x, y):
    if x > y:
        x, y = y, x
    if x == 0:
        return y
    return gcd(y % x, x)


def lcm(x, y):
    g = gcd(x, y)
    return g * (x // g) * (y // g)


def calc(t, x, y, z):
    return t // x + t // y - t // z


g = lcm(C, D)
bcnt = calc(B, C, D, g)
acnt = calc(A - 1, C, D, g)
print(B - bcnt - (A - 1 - acnt))


Measured memory_bytes: 3064
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=ja
import itertools

N = []
X = []
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    N.append(n)
    X.append(x)


def count_sum(n, x):
    cnt = 0
    for a, b, c in itertools.combinations(range(1, n + 1), 3):
        if (a + b + c) == x:
            cnt += 1

    return cnt


for n, x in zip(N, X):
    print(count_sum(n, x))


Measured memory_bytes: 5636
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

int N;
bool dp[10101];

int main() {
  cin >> N;
  dp[0] = true;
  rep(i, 0, N) {
    int s;
    cin >> s;
    for (int j = 10000; j >= 0; --j) {
      if (dp[j]) {
        dp[j + s] = true;
      }
    }
  }

  for (int i = 9999; i >= 1; --i) {
    if (i % 10 == 0) continue;

    if (dp[i]) {
      cout << i;
      return 0;
    }
  }

  cout << 0;
}


Measured memory_bytes: 3572
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new TEST().doIt();
    }
    class TEST{
        void doIt(){
        	while(true){
        		int n = sc.nextInt();
        		int m = sc.nextInt();
        		if(n + m == 0)break;
        		for(int i = 0;i < n;i++){
        			for(int j = 0;j < m;j++){
        				System.out.print("#");
        			}
        			System.out.println();
        		}
        		System.out.println();
        	}
        }
    }
}

Measured memory_bytes: 34316
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
ll X, Y, A, B, C;
ll p[100000];
ll q[100000];
ll r[100000];

ll cumsum_pq[200002];
ll cumsum_r[100001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> X >> Y >> A >> B >> C;
    for(int i = 0; i < A; i++) cin >> p[i];
    for(int i = 0; i < B; i++) cin >> q[i];
    for(int i = 0; i < C; i++) cin >> r[i];
    sort(p, p+A, greater<ll>());
    sort(q, q+B, greater<ll>());
    sort(r, r+C, greater<ll>());
    
    vector<ll> v;
    for(int i = 0; i < X; i++) v.push_back(p[i]);
    for(int i = 0; i < Y; i++) v.push_back(q[i]);
    sort(v.begin(), v.end());
    int M = min(X+Y, C);
    for(int i = 0; i < M;i++){
        cumsum_pq[i+1] = cumsum_pq[i]+v[i];
        cumsum_r[i+1] = cumsum_r[i]+r[i];
    }
    ll ans = 0;
    for(int i = 0; i < (X+Y); i++) ans += v[i];
    ll ans1 = ans;
    for(int i = 1; i <= M; i++){
        ll tmp = ans1-cumsum_pq[i]+cumsum_r[i];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}   


Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
 int N;
 cin >> N;
vector<ll> H(N);
  for(int i = 0;i<N;i++){
    cin >> H[i];
  }
  H.push_back(10000000000);
  int c = 0;
  vector<int> ans;
  for(int i = 0;i<N;i++){
    if(H[i] >= H[i+1]) c++;
    else{
      ans.push_back(c);
      c = 0;
    }
  }
  sort(ans.begin(),ans.end());
  reverse(ans.begin(),ans.end());
  cout << ans[0] << endl;
    
  
}

Measured memory_bytes: 1904
/**
 * @brief AtCoder Beginner Contest 103<br>
 * D - Islands War
 *
 * 区間スケジューリング
 * @see https://atcoder.jp/contests/abc103/tasks/abc103_d
 */
#include <iostream>
#include <queue>
using namespace std;

using P = pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  auto c = [](P l, P r) {
    return l.first > r.first;
  };
  priority_queue<P, vector<P>, decltype(c)> que(c);
  for (int i{}; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    que.push(P(a, b));
  }
  int ans{1};
  P bp(1, N);
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    P a(max(bp.first, p.first), min(bp.second, p.second));
    if (a.first < a.second) {
      bp = a;
    } else {
      ++ans;
      bp = p;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
using System;
using System.Linq;

namespace B___Template_Matching
{
    class Program
    {
        static void Main(string[] args)
        {
            var N_M = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = N_M[0], M = N_M[1];
            var An = new string[N].Select(_ => Console.ReadLine()).ToArray();
            var Bn = new string[M].Select(_ => Console.ReadLine()).ToArray();

            for (int i = 0; i <= N - M; i++)
                for (int j = 0; j <= N - M; j++)
                {
                    int count = 0;
                    for (int ii = 0; ii < M; ii++)
                    {
                        if (An[i + ii].Substring(j, M) == Bn[ii])
                            count++;
                    }

                    if (count == M)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }

            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int main()
{
    int ans=700;
    string s;
    cin>>s;
    
    for(int i = 0; i < 3; i++)
    {
        if(s[i]=='o') ans+=100;
    }
    
    cout <<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>

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

using namespace std;

typedef long long int lli;

int check(array<array<int, 10>, 10> &x, int a, int b, int c, int d) {
    return x[x[x[x[0][a]][b]][c]][d];
}

int check(array<array<int, 10>, 10> &x, int a, int b, int c, int d, int e) {
    return x[check(x, a, b, c, d)][e];
}

int main () {
    array<array<int, 10>, 10> x;
    REP (i, 0, x.size()) REP (j, 0, x[i].size()) cin >> x[i][j];
    int cnt = 0;
    REP (a, 0, 10) REP (b, 0, 10) REP (c, 0, 10) REP (d, 0, 10) {
        int digit = check(x, a, b, c, d);
        bool t = false;
        REP (e, 0, 10) {
            if (a != e) t |= (check(x, e, b, c, d, digit) == 0);
            if (b != e) t |= (check(x, a, e, c, d, digit) == 0);
            if (c != e) t |= (check(x, a, b, e, d, digit) == 0);
            if (d != e) t |= (check(x, a, b, c, e, digit) == 0);
            if (digit != e) t |= (check(x, a, b, c, d, e) == 0);
        }

        if (a != b) t |= (check(x, b, a, c, d, digit) == 0);
        if (b != c) t |= (check(x, a, c, b, d, digit) == 0);
        if (c != d) t |= (check(x, a, b, d, c, digit) == 0);
        if (d != digit) t |= (check(x, a, b, c, digit, d) == 0);
        cnt += t;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;


int solve(int N, int K, 
vector<int>& h);  // 前方宣言

int main() {

    int N, K;
    cin >> N >> K;
    vector<int> h(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }

    int minv = solve(N, K, h);
    cout << minv << endl;

    return 0;
}


int solve(int N, int K, vector<int>& h) {
    vector<int> v(N, pow(10, 9));
    v[0] = 0;
    v[1] = abs(h[1] - h[0]);
    for (int i = 2; i < N; i++) {
        for (int j = max(0, i-K); j < i; j++) {
            v[i] = min(v[i], v[j] + abs(h[i] - h[j])); 
        }
    }
    return v[N-1];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N, q;
    cin >> N >> q;

    vector<string> RRS_name(N);
    vector<int> RRS_time(N);
    for (int i = 0; i < N; i++)
    {
        cin >> RRS_name.at(i) >> RRS_time.at(i);
    }
    
    queue<pair<string, int> > RRS;
    for (int i = 0; i < N; i++)
    {
        RRS.push(make_pair(RRS_name.at(i), RRS_time.at(i)));
    }
    


    pair<string, int> RRS_temp;
    int time = 0;

    while (!(RRS.empty()))
    {
    RRS_temp = RRS.front();
    RRS.pop();

    if (RRS_temp.second > q)
    {
        RRS_temp.second = RRS_temp.second - q;
        RRS.push(RRS_temp);

        time += q;
    }
    else
    {
        time += RRS_temp.second;
        cout << RRS_temp.first << ' ' << time << endl;
    }
    
    }
    
    
    
    

}


Measured memory_bytes: 6688
"use strict";
    
const main = arg => {
    const S = arg.split("\n")[0].split("");
    const head = S[0];
    const tail = S[S.length - 1];
    
    S.shift();
    S.pop();
    
    console.log(head + S.length + tail);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<cstdio>
#include<cstring>

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

using namespace std;

int n,m;
char s[512];

int dp[512][500][10][2];
// 今何桁目か, i 桁目を自由に決められるか, i 桁目までの mod m での値, i-1 桁目の数字, 一つ前で上がったか下がったか, 直前まですべて 0 だったか
int dfs(int i,bool b,int mod,int pre,bool up,bool z){
	if(i==n) return mod==0?1:0;

	if(b && !z && dp[i][mod][pre][up?1:0]!=-1) return dp[i][mod][pre][up?1:0];

	int res=0;
	int d0=s[i]-'0';
	if(z){
		res+=dfs(i+1,true,(10*mod+0)%m,0,true,true);
		if(!b){
			for(int d=1;d<=d0;d++){
				res+=dfs(i+1,d<d0,(10*mod+d)%m,d, true,false);
				res+=dfs(i+1,d<d0,(10*mod+d)%m,d,false,false);
			}
		}
		else{
			for(int d=1;d<10;d++){
				res+=dfs(i+1,true,(10*mod+d)%m,d, true,false);
				res+=dfs(i+1,true,(10*mod+d)%m,d,false,false);
			}
		}
	}
	else{
		if(!b){
			if(up){ // 前回上がったなら今回下がる
				for(int d=0;d<=d0&&d<pre;d++){
					res+=dfs(i+1,d<d0,(10*mod+d)%m,d,!up,false);
				}
			}
			else{ // 前回下がったなら今回上がる
				for(int d=pre+1;d<=d0;d++){
					res+=dfs(i+1,d<d0,(10*mod+d)%m,d,!up,false);
				}
			}
		}
		else{
			if(up){
				rep(d,pre){
					res+=dfs(i+1,true,(10*mod+d)%m,d,!up,false);
				}
			}
			else{
				for(int d=pre+1;d<10;d++){
					res+=dfs(i+1,true,(10*mod+d)%m,d,!up,false);
				}
			}
		}
	}

	res%=10000;
	if(b && !z) dp[i][mod][pre][up?1:0]=res;

	return res;
}

int solve(const char *a){
	strcpy(s,a);
	n=strlen(s);
	memset(dp,-1,sizeof dp);
	int res=dfs(0,false,0,0,true,true);
	// dfs で 1, 2, ..., 9 を二回カウントしてしまうので、その分を答えから引く
	for(int i=1;i<10;i++){
		if((n>=2 || i<=a[0]-'0') && i%m==0) res--;
	}
	return (res+10000)%10000;
}

// decrement
char *dec(char *a){
	int n=strlen(a),i;
	for(i=n-1;a[i]=='0';i--) a[i]='9';
	a[i]--;
	if(n>=2 && a[0]=='0') memmove(a,a+1,n); // leading 0 を削除
	return a;
}

int main(){
	char a[512],b[512];
	scanf("%s%s%d",a,b,&m);
	printf("%d\n",(solve(b)-solve(dec(a))+10000)%10000);
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
	char str[3][50];
	int flag1 = 0, flag2 = 0;
	scanf("%s %s %s", str[0], str[1], str[2]);
	int len1 = strlen(str[0]);
	int len2 = strlen(str[1]);
	int len3 = strlen(str[2]);
	if (str[0][len1 - 1] == str[1][0]) {
		flag1 = 1;
		if (str[1][len2 - 1] == str[2][0]) {
			flag2 = 1;
		}
	}
	if (flag2) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 128
"""ALDS1_2_C"""

from collections import namedtuple
from copy import deepcopy

Card = namedtuple("Card", ("suit", "value"))

def bubble(cards):
    cards = deepcopy(cards)
    N = len(cards)
    for i in range(N):
        for j in range(N-1, i, -1):
            if cards[j].value < cards[j-1].value:
                cards[j], cards[j-1] = cards[j-1], cards[j]
    return cards


def selection(cards):
    cards = deepcopy(cards)
    N = len(cards)
    for i in range(N):
        argmin = i
        for j in range(i, N):
            if cards[j].value < cards[argmin].value:
                argmin = j
        cards[i], cards[argmin] = cards[argmin], cards[i]
    return cards


def print_cards(cards):
    for i, card in enumerate(cards):
        end = "" if i == len(cards) - 1 else " "
        print(card.suit, card.value, sep="", end=end)
    print()


def main():
    _ = input()
    cards = [Card(i[0], int(i[1])) for i in input().split()]
    bubble_sorted = bubble(cards)
    selection_sorted = selection(cards)

    print_cards(bubble_sorted)
    print("Stable")
    print_cards(selection_sorted)
    if bubble_sorted == selection_sorted:
        print("Stable")
    else:
        print("Not stable")


if __name__ == "__main__":
    main()


Measured memory_bytes: 6344
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>

using namespace std;

int main(){
    int m, n;
    cin >> n >> m;
    vector<int> a;
    int sum = 0;
    for(int i = 0;i<n;i++){
        int tmp;
        cin >> tmp;
        sum += tmp;
        a.push_back(tmp);
    }

    // sum/4m <= a
    // sum <= a * 4m

    int ok = 0;
    for(int i=n-1;0<=i;i--){
        if(sum <= a[i] * 4 * m){
            ok++;
        }
    }
    // cout << ok << endl;

    if(m <= ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=998244353;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

const int NMAX=200010;
template <class X>
class BIT{
  X bit[NMAX];
  int n;
public:
  BIT(int N);
  X sum(int i);
  void add(int i,X x);
};
template <class X>
BIT<X>::BIT(int N){
  n=N;
  for(int i=0;i<N;i++){
    bit[i]=0;
  }
}
template <class X>
X BIT<X>::sum(int i){//iまでの和=bit[0]+...+bit[i]
  X s=0;
  while(i>0){
    s+=bit[i];
    i-=i&(-i);//最後の1bitを引く(ex.0110なら0010を引く)
  }
  return s;
}
template <class X>
void BIT<X>::add(int i,X x){//bit[i]+=x
  while(i<=n){
    bit[i]+=x;
    i+=i&(-i);//最後の1bitを足す
  }
}
int nn;
pair<int,int> p[200010];
int a[200010],b[200010],c[200010],d[200010];
int main()
{
  cin >> nn;
  rep(i,nn) cin >> p[i].first >> p[i].second;
  {
    map<int,int> mp;
    rep(i,nn) mp[p[i].first] = 0;
    int j = 1;
    for(auto itr=mp.begin();itr!=mp.end();++itr){
      itr->second = j++;
    }
    rep(i,nn) p[i].first = mp[p[i].first];
  }
  {
    map<int,int> mp;
    rep(i,nn) mp[p[i].second] = 0;
    int j = 1;
    for(auto itr=mp.begin();itr!=mp.end();++itr){
      itr->second = j++;
    }
    rep(i,nn) p[i].second = mp[p[i].second];
  }
  sort(p,p+nn);
  {
    BIT<int> bit(nn+1); 
    rep(i,nn){
      int pf = p[i].first,ps = p[i].second;
      int bb = bit.sum(ps);
      int aa = i - bb;
      a[pf-1] = aa;
      b[pf-1] = bb;
      bit.add(ps,1);
    }
  }
  {
    BIT<int> bit(nn+1); 
    rep(i,nn){
      int pf = p[nn-1-i].first,ps = p[nn-1-i].second;
      int dd = bit.sum(ps);
      int cc = i - dd;
      c[pf-1] = cc;
      d[pf-1] = dd;
      bit.add(ps,1);
    }
  }
  
  mint res;
  rep(i,nn){
    ll aa = a[i],bb = b[i],cc = c[i],dd = d[i];
    mint two = 2;
    res += (two.pow(aa) - 1)*(two.pow(dd) - 1)*(two.pow(bb+cc));
    res += (two.pow(bb) - 1)*(two.pow(cc) - 1)*(two.pow(aa+dd));
    res -= (two.pow(aa) - 1)*(two.pow(bb) - 1)*(two.pow(cc) - 1)*(two.pow(dd) - 1);
    res += two.pow((ll)nn-1);
  }

  cout << res.x << "\n";
  
  return 0;
}


Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A=0;
    int B=0;
    cin >> A>>B;
    if((A+B)%2==0)
    cout <<(A+B)/2<<endl;
    if((A+B)%2!=0)
    cout<<"IMPOSSIBLE"<<endl;
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (ll i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((ll)(x).size())
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vp vector<pair<ll, ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define pi pair<ll, ll>
//#define P pair<ll, ll>
//#define V vector<ll>
//#define S set<ll>
#define asn ans
bool dbg = false;

ll N, K, A[10101];
ll tot[10101];

void solve() {
    tot[0] = 1;
    FOR(i, N) {
        for (int x = 5010; x >= 0; x--) {
            if (x + A[i] < 10100)
                tot[x + A[i]] += tot[x];
        }
    }
    int asn = 0;
    FOR(N) {
        int tmp[10101] = {};
        FOR(x, 0, 5001) {
            tmp[x] += tot[x];
            if (x + A[i] < 5001) {
                tmp[x + A[i]] -= tmp[x];
            }
        }
        // cerr << "i = " << i << endl;
        FOR(x, 0, K) {
            //cout << tmp[x] << endl;
        }
        bool flag = true;
        for (int x = max(0ll, K - A[i]); x < K; x++) {
            if (tmp[x] != 0)
                flag = false;
        }
        if (flag)
            ans += 1;
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N >> K;
    FOR(N) {
        cin >> A[i];
    }

    solve();
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
#include<complex>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009
#define MIN (1e-10)
typedef complex<double> P;
bool EQ(P a, P b){
	if (abs(a.real() - b.real()) < MIN&&abs(a.imag() - b.imag()) < MIN)return true;
	else return false;
}
double dot(P a, P b){
	return{ a.real()*b.real() + a.imag()*b.imag() };
}
double cross(P a, P b){
	return{ a.real()*b.imag() - a.imag()*b.real() };
}
P insec(P a1, P a2, P b1, P b2){
	P a, b;
	a = a2 - a1;
	b = b2 - b1;
	return a1 + (a*cross(b, b1 - a1) / cross(b, a));
}
void print(double x, int k){
	if (x < 0){
		printf("-");
		x = -x;
	}
	printf("%d.", (int)x);
	x = x - (double)(int)x;
	f(i, k){
		x = x * 10;
		printf("%d", (int)x);
		x = x - (double)(int)x;
	}
	return;
}

int main(void){
	P a, b, c;
	P d, e, f;
	double x, y;
	int n;
	scanf("%lf %lf", &x, &y);
	a = P(x, y);
	scanf("%lf %lf", &x, &y);
	b = P(x, y);
	f = (b - a)*P(0, 1);
	scanf("%d", &n);
	f(i, n){
		scanf("%lf %lf", &x, &y);
		c = P(x, y);
		d = c + f;
		e = insec(a, b, c, d);
		e = e*(double)2 - c;
		print(e.real(), 10);
		printf(" ");
		print(e.imag(), 10);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
ll anss = 0;
int main()
{
ll n , m ;
cin >> n >> m ;
vector<ll> v(n+1);
rep(i,m){
  ll a ;
  string b ;
  cin >> a >> b ;
  if(v[a]>=0&&b=="WA")v[a]++;
  if(v[a]>=0&&b=="AC"){anss+=v[a];ans++;v[a]=-1;}
}

cout << ans<<' '<<anss << endl;
return 0;
}

Measured memory_bytes: 1024
/**
 * Title: D - Caracal vs Monster
 * Url: https://atcoder.jp/contests/abc153/tasks/abc153_d
 */
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
#include<functional>
#include<sstream>
#include<iomanip>

using namespace std;

#define ll long long

int main() {
    ll H;
    cin >> H;
    ll x = log2(H);
    ll ans = 0;
    for(ll i=0; i<=x; i++) {
        ans += pow(2, i);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;

vector<int> to_xor(vector<int> x)
{
    int n = x.size();
    vector<int> ret(n);
    for (int i = 0; i < n; i++)
    {
        ret[i] = x[i] ^ x[(i + 1) % n];
    }
    return ret;
}

template <typename T>
struct MP
{
    int n;
    T t;
    vector<int> a;
    MP() {}
    MP(const T &t) : t(t)
    {
        n = t.size();
        a = vector<int>(n + 1);
        a[0] = -1;
        int j = -1;
        for (int i = 0; i < n; ++i)
        {
            while (j != -1 && t[j] != t[i])
                j = a[j];
            j++;
            a[i + 1] = j;
        }
    }
    int operator[](int i) { return a[i]; }
    vector<int> find_from(const T &s)
    {
        vector<int> res;
        int j = 0;
        for (int i = 0; i < s.size(); ++i)
        {
            while (j != -1 && t[j] != s[i])
                j = a[j];
            j++;
            if (j == n)
            {
                res.push_back(i - j + 1);
                j = a[j];
            }
        }
        return res;
    }
};

int main()
{
    int N;
    cin >> N;

    vector<int> a(N);
    for (int &aa : a)
    {
        cin >> aa;
    }
    vector<int> axor = to_xor(a);
    axor.insert(axor.end(), axor.begin(), axor.end());

    vector<int> b(N);
    for (int &bb : b)
    {
        cin >> bb;
    }
    vector<int> bxor = to_xor(b);

    MP<vector<int>> mp(bxor);
    for (int i : mp.find_from(axor))
    {
        if (i >= N)
        {
            continue;
        }
        cout << i << " " << (a[i] ^ b.front()) << endl;
    }
}


Measured memory_bytes: 10720
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=0;
  cin >> n;
  long long a[n+1];
  a[n]=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    ans+=(long long)a[i]/2;
    a[i]%=2;
    if(a[i]&&a[i+1]){
      ans++;
      a[i]--;
      a[i+1]--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
N, K = [int(x) for x in input().split()]
P = [input() for i in range(N)]

holdCount = 0 

alphabet = [chr(i) for i in range(65, 65+26)]

charCount = {x:0 for x in alphabet}

for i in P:
    charCount[i[0]] += 1 


nonZero = [x for x in charCount if charCount[x] is not 0]
while len(nonZero) >= K:
    for i in sorted(charCount.items(), key=lambda x:x[1])[-K:]:
        charCount[i[0]] -= 1
    holdCount += 1
    nonZero = [x for x in charCount if charCount[x] is not 0]

print(holdCount)

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        if ((x >= r) && (x <= W-r) && (y >= r) && (y <= H-r)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}


Measured memory_bytes: 26392
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
        String s = sc.next();
        char c = s.charAt(0);
        int b = sc.nextInt();
    
        if(c == '+'){
            System.out.println((a+b));
        }else if(c == '-'){
            System.out.println((a-b));
        }else if(c == '*'){
            System.out.println((a*b));
        }else if(c == '/'){
            System.out.println((a/b));
        }else{
            System.exit(0);
        }
        }
        
    }
}


Measured memory_bytes: 26392
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = (n) - 1; i >= 0; i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define sz(x) ((long long)x.size())
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
 
auto clk=clock();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll INF = 1e18L+5;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<int> vint;
typedef vector<string> vs;
typedef vector<vi> vvi;

const int N_MAX = 2005;
ll dp[N_MAX][N_MAX];

ll combi(ll n, ll r){
    if(r==0||r==n)
        return 1;
    if(dp[n][r]!=-1)
        return dp[n][r];
    ll a = combi(n-1,r-1);
    ll b = combi(n-1,r);
    dp[n][r] = (a+b)%MOD;
    return dp[n][r];
}

ll modexp(ll base,ll power){
    if(base==0)
        return 0ll;
    if(power==0)
        return 1ll;
    ll res=1;
    while(power){
        if(power&1)
            res = (res*base)%MOD;
        base = (base*base)%MOD;
        power /= 2;
    }
    return res;    
}
 
void solve(){
    ll n;
    cin>>n;
    if(n<=1)
    	cout<<"0";
    else{
    	ll ans = modexp(10,n)-2ll*modexp(9,n)+modexp(8,n);
    	ans %= MOD;
    	ans += MOD;
    	ans %= MOD;
    	cout<<ans;
    }
}
    
 
int main () 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(11);
    memset(dp,-1,sizeof(dp));
    ll t = 1;
    // cin>>t;
    while(t--)
        solve();
 
    // cout<<endl<<endl<<"Time elapsed: "<<((double)(clock()-clk)/CLOCKS_PER_SEC)*1000<<"ms"<<endl;
    return 0;
}

Measured memory_bytes: 35052
#include <bits/stdc++.h>
using namespace std;

int main() {
  int abcd;
  cin >> abcd;
  vector<int> n(4);
  for(int i = 0; i < 4; i++) {
    n.at(i) = abcd % 10;
    abcd /= 10;
  }
  reverse(n.begin(), n.end());
  vector<int> op(3, 0);
  for(int i = 0; i < 8; i++) {
    int ans = n.at(0);
    int op1, op2, op3 = i;
    vector<char> op(3);
    op1 = op3 / 4;
    op3 %= 4;
    op2 = op3 / 2;
    op3 %= 2;
    if(op1) {
      ans += n.at(1);
      op.at(0) = '+';
    } else {
      ans -= n.at(1);
      op.at(0) = '-';
    }
    if(op2) {
      ans += n.at(2);
      op.at(1) = '+';
    } else {
      ans -= n.at(2);
      op.at(1) = '-';
    }
    if(op3) {
      ans += n.at(3);
      op.at(2) = '+';
    } else {
      ans -= n.at(3);
      op.at(2) = '-';
    }
    if(ans == 7) {
      cout << n.at(0) << op.at(0) << n.at(1) << op.at(1) << n.at(2) << op.at(2) << n.at(3) << "=7" << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	
	return x * y / tmp;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);


	string s;
	cin >> s;
	string t = s;
	reverse(t.begin(), t.end());

	int ans = 0;
	for (int i = 0; i < s.size()/2; i++)
	{
		if (s[i] != t[i]) {
			ans++;
		}

	}
	cout << ans << endl;



	



	return 0;
}


Measured memory_bytes: 256