akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

 

#define pb push_back

#define mp make_pair

#define fs first

#define sc second

#define rep(i, from, to) for (int i = from; i < (to); ++i)

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

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

#define FOR(i, to) for (int i = 0; i < (to); ++i)

 

using namespace std;

typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pii;

typedef pair<double,double> pdd;

typedef vector<ll> vll;

typedef vector<pair<int,int>> vpi;

typedef pair<ll,ll> pll;

typedef vector<string> vs;

#define MOD 1000000007

#define INF 1000000000LL * 100000LL

#define Nmax 2020201



ll N,T,K;
ll H[3333];

ll A[3333], B[3333];

ll ret;
vector<int> v;
ll best[2][333][333];
map<int,int> hr;


int main() {

  cin >> N >> K;

  FOR(i, N) {
    cin >> H[i+1];
    v.pb(H[i+1]);

  }
  v.pb(0);
  sort(all(v));
  v.erase(unique(all(v)), v.end());
  FOR(i, sz(v)) {
    hr[v[i]] = i;
  }

  for(int k=0;k<=K;++k) {
    for(int j=0;j<sz(v);++j) {
      best[0][j][k] = best[1][j][k] = INF;
    }
  }


  for(int i=0;i<sz(v);++i) {
    best[0][i][1] = v[i] + 1;
  }
  best[0][hr[H[1]]][0] = H[1] + 1;
  for(int i=2;i<=N;++i) {
    for(int k=0;k<=K;++k) {
      ll cb = INF;
      for(int j=0;j<sz(v);++j) {
        best[1][hr[H[i]]][k] = min(best[1][hr[H[i]]][k], best[0][j][k] + max(0LL, H[i] - v[j]));
        if(k) {
          if(j) cb += v[j] - v[j-1];
          cb=min(cb, best[0][j][k-1]);
          best[1][j][k] = min(best[1][j][k], cb);
        }
      }
    }
    for(int k=0;k<=K;++k) {
      for(int j=0;j<sz(v);++j) {
        best[0][j][k] = best[1][j][k];
        best[1][j][k] = INF;
      }
    }
  }
  ll ret = INF;
  
  for(int k=0;k<=K;++k) {
    for(int j=0;j<sz(v);++j) {
      ret = min(ret, best[0][j][k]);
    }
  }

  cout << ret - 1;

}

 

Measured memory_bytes: 1792
N,K = map(int,input().split())
A = list(map(lambda x: int(x)-1,input().split()))

o = [0] * 63

def bi(x):
    i = 0
    while x != 0:
        o[i] = x%2
        x //= 2
        i += 1

bi(K)

n = 0
for i in range(63):
    if o[i]:
        n = A[n]
    A = [A[A[x]] for x in range(N)]
        
print(n+1)

Measured memory_bytes: 170048
#include <stdio.h>
#define MAX 100001
int main(void){
  int i, N, c, now, a[MAX];
  scanf("%d", &N);

  for(i=0;i<N;i++){
    scanf("%d", &(a[i]));
    a[i]--;
  }

  c = 0;
  now = 0;
  while(1){
    if(now == 1){
      printf("%d\n", c);
      break;
    }
    if(c >= N){
      printf("-1\n");
      break;
    }
    c++;
    now = a[now];
  }
  return 0;
}


Measured memory_bytes: 512
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]

ans = 0
for i in range(N):
    k = min(A[i], B[i])
    l = min(A[i+1], B[i]-k)
    ans += k+l
    A[i+1] -= l

print(ans)

Measured memory_bytes: 19648
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main() {
  int N, M, p;
  cin >> N >> M >> p;
  vector< int > d(M);
  for(int i = 0; i < M; i++) {
    int a;
    cin >> a;
    d[i] = (a - p + N) % N;
  }
  sort(d.begin(), d.end());
  int ret = INF;
  for(int i = 0; i < M; i++) {
    if(i > 0) ret = min(ret, 2 * (N - d[i]) + d[i - 1]);
    if(i < M - 1) ret = min(ret, 2 * d[i] + N - d[i + 1]);
  }
  cout << min(ret, min(N - d[0], d[M - 1])) * 100 << endl;
}

Measured memory_bytes: 1252
import math


class Vector2():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, v):
        return Vector2(self.x+v.x, self.y+v.y)

    def __sub__(self, v):
        return Vector2(self.x-v.x, self.y-v.y)

    def __mul__(self, v):
        return Vector2(self.x*v, self.y*v)

    def __truediv__(self, v):
        return Vector2(self.x/v, self.y/v)

    def __abs__(self):
        return math.sqrt(float(self.x*self.x+self.y*self.y))

    def __str__(self):
        return f"({self.x},{self.y})"

    def __lt__(self, v):
        if math.isclose(self.x, v.x):
            return self.y < v.y
        return self.x < v.x

    def dot(self, v):
        return self.x*v.x+self.y*v.y

    def cross(self, v):
        return self.x*v.y-self.y*v.x

    def norm(self):
        d = abs(self)
        return Vector2(self.x/d, self.y/d)


def projection(v1, v2, p):
    v12 = (v2-v1).norm()
    v1p = p-v1
    d = v12.dot(v1p)
    return v1+v12*d


def distanceLP(v1, v2, p):
    '''
    v1 -> v2の直線とpとの距離
    '''
    return abs((v2-v1).cross(p-v1))/abs(v2-v1)


def distanceSP(v1, v2, p):
    '''
    v1 -> v2の線分とpとの距離
    '''
    if (v2-v1).dot(p-v1) < 0.0:
        return abs(p-v1)
    if (v1-v2).dot(p-v2) < 0.0:
        return abs(p-v2)
    return distanceLP(v1, v2, p)


def ccw(p0, p1, p2):
    c = (p1-p0).cross(p2-p0)
    if math.isclose(c, 0.0, abs_tol=1e-10):
        d = (p1-p0).dot(p2-p0)
        if d < 0.0:
            return -1
        else:
            d1 = abs(p1-p0)
            d2 = abs(p2-p0)
            if d1 < d2:
                return 1
            else:
                return 0
    elif c < 0.0:
        return -1
    else:
        return 1


def intersect(p1, p2, p3, p4):
    '''
    p1p2とp3p4の交差判定
    '''
    #t1 = (p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x)
    #t2 = (p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x)
    #t3 = (p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x)
    #t4 = (p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x)
    # return (t1*t2) <= 0.0 and (t3*t4) <= 0.0
    c1 = ccw(p1, p2, p3)*ccw(p1, p2, p4)
    c2 = ccw(p3, p4, p1)*ccw(p3, p4, p2)
    return c1 <= 0.0 and c2 <= 0.0


def distance(a1, a2, b1, b2):
    '''
    線分a1a2とb1b2の距離
    '''
    if intersect(a1, a2, b1, b2):
        return 0.0
    return min([
        min([distanceSP(a1, a2, b1), distanceSP(a1, a2, b2)]),
        min([distanceSP(b1, b2, a1), distanceSP(b1, b2, a2)])
    ])


cx, cy, r = map(int, input().split())
p = Vector2(cx, cy)
q = int(input())
for i in range(q):
    x1, y1, x2, y2 = map(int, input().split())
    v1, v2 = Vector2(x1, y1), Vector2(x2, y2)
    '''
    円と線分の交点
    '''
    pr = projection(v1, v2, p)
    e = (v2-v1)/abs(v2-v1)
    base = math.sqrt(r*r-abs(pr-p)**2)
    a1, a2 = pr+e*base, pr-e*base
    ans = ""
    for a in sorted([a1, a2]):
        ans += f"{a.x:.10f} {a.y:.10f} "
    print(ans.strip())



Measured memory_bytes: 5820
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, A;
    cin >> N;

    int r, count, min = 0;
    for(int i=0; i<N; i++){
        cin >> A;
        while(r==0){
            r = A % 2; 
            A = A / 2;
            if(r==0){
                count++;
            }
        }
        if(i == 0){
            min = count;
        }
        if(min > count){
            min = count;
        }
        r=0;
        count = 0;
    }
    cout << min << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    
    class Point
    {
        public int x;
        public int y;
        public int num;
        public Point(int i, int j, int n)
        {
            x = i;
            y = j;
            num = n;
        }
    }
    
    

    class Program
    {

        static Point Next_Point(Point p, int d, int number)
        {
            int x = p.x;
            int y = p.y;

            if (d == 0) x--;
            else if (d == 1) y--;
            else if (d == 2) x++;
            else if (d == 3) y++;

            return new Point(x, y, number);
        }
        
        
        static void Main(string[] args)
        {            

            while (true)
            {
                int N = int.Parse(Console.ReadLine());

                if(N == 0)
                {
                    break;
                }

                List<Point> card_list = new List<Point>();
                int max_x = 0;
                int min_x = 0;
                int max_y = 0;
                int min_y = 0;

                card_list.Add(new Point(0, 0, 0));

                for(int i = 1; i < N; i++)
                {
                    string[] input = Console.ReadLine().Split(' ');
                    int n = int.Parse(input[0]);
                    int d = int.Parse(input[1]);

                    card_list.Add(Next_Point(card_list[n], d, i));

                    int x_new = card_list.Last().x;
                    int y_new = card_list.Last().y;

                    if (x_new > max_x) max_x = x_new;
                    else if (x_new < min_x) min_x = x_new;
                    else if (y_new > max_y) max_y = y_new;
                    else if (y_new < min_y) min_y = y_new;
                }

                Console.WriteLine($"{max_x - min_x + 1} {max_y - min_y + 1}");

            }
            
        }
    }
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    
    ll n,k,s;
    cin >> n >> k >> s;
    rep(i,0,n){
        if(i < k){
            cout << s;
        }
        else if(s != (ll)1e9){
            cout << s+1;
        }
        else{
            cout << 1;
        }
        if(i != n-1) cout << " ";
    }
    cout << endl;

    
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  
  int ans = 0;
  int now = 0;
  rep(i, n) {
    if(now < h[i]) {
      ans += h[i] - now;
      now = h[i];
    }
    else now = h[i];
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3656
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_A&lang=ja
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    n,m,*C = map(int, read().split())

    # dp[i] := i円を作るのに必要な最小枚数
    dp = [10**10] * (n+1)
    dp[0] = 0

    for c in C:
        for i in range(n+1):
            if i + c <= n:
                dp[i+c] = min(dp[i] + 1, dp[i+c])

    print(dp[n])


if __name__ == "__main__":
    main()


Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

vector<int> paths[650];
long double dp[650];
int N, M;
long double ans;

void input() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        int s, t;
        cin >> s >> t;
        paths[s].push_back(t);
    }
}

void f(int block) {
    //cout<<"block"<<block<<endl;
    dp[N] = 0;
    for(int i = N - 1; i >= 1; i--) {
        long double sum = 0.0;
        long double maxi = 0.0;
        int num = paths[i].size();
        for(auto to : paths[i]) {
            sum += dp[to];
            chmax(maxi, dp[to]);
           // printf("i=%d,maxi=%lf,to=%d,dp[%d]=%lf\n",i,maxi,to,to,dp[to]);
        }
        if(i == block && num >= 2) {
            //printf("i==block,before,sum=%lf,num=%d\n",sum,num);
            num--;
            sum -= maxi;
        }
        dp[i] = sum / num + 1;
        //printf("i=%d,dp[%d]=%lf,sum=%lf,num=%d\n",i,i,dp[i],sum,num);
    }
    chmin(ans, dp[1]);
}

void solve() {
    input();
    ans = 1e18;
    for(int i = 1; i <= N - 1; i++) {
        f(i);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
/*-*/

int main() {
	int a,b,c,d,e;
	std::cin >> a >> b >> c >> d >> e;
	int f = a*60+b;
	int g = c*60+d;
	print(g-f-e);
}


Measured memory_bytes: 3672
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


class Combination:
    def __init__(self, n: int, mod: int):
        self.mod = mod
        self.fact = [0] * (n + 1)
        self.factinv = [0] * (n + 1)
        self.inv = [0] * (n + 1)
        
        self.fact[0] = self.fact[1] = 1
        self.factinv[0] = self.factinv[1] = 1
        self.inv[1] = 1
        for i in range(2, n + 1):
            self.fact[i] = (self.fact[i - 1] * i) % mod
            self.inv[i] = (-self.inv[mod % i] * (mod // i)) % mod
            self.factinv[i] = (self.factinv[i - 1] * self.inv[i]) % mod
    
    def ncr(self, n: int, r: int):
        if r < 0 or n < r:
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] % self.mod * self.factinv[n - r] % self.mod
    
    def nhr(self, n: int, r: int):
        return self.ncr(n + r - 1, r)
    
    def npr(self, n: int, r: int):
        if r < 0 or n < r:
            return 0
        return self.fact[n] * self.factinv[n - r] % self.mod


def solve():
    r1, c1, r2, c2 = map(int, rl().split())
    MOD = 10 ** 9 + 7
    
    com = Combination(r2 + c2 + 100, MOD)
    ans = com.ncr(r2 + c2 + 2, c2 + 1)
    ans = (ans - com.ncr(r1 + c2 + 1, c2 + 1)) % MOD
    ans = (ans - com.ncr(r2 + c1 + 1, c1)) % MOD
    ans = (ans + com.ncr(r1 + c1, c1)) % MOD
    print(ans)


if __name__ == '__main__':
    solve()


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

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

const int N = 5e5;
const int INF = 1e9;

struct RMQ {
    int neutro = -1e9;
	int sz;
	pii t[4*N];
	int &operator [](int p){ t[sz + p].snd = p; return t[sz + p].fst; }
	void init(int n) { // O(n)
		sz = 1 << (32 - __builtin_clz(n));
		forn(i, 2*sz) t[i] = {neutro, -1};
	}
    void updall() { //O(n)
        dforsn(i,0,sz) t[i] = max(t[2*i], t[2*i + 1]);
    }
	pii get(int i, int j){ return get(i, j, 1, 0, sz); }
	pii get(int i, int j, int n, int a, int b){ // O(lg n)
		if(j <= a || i >= b) return mp(neutro, -1);
		if(i <= a && b <= j) return t[n];

		int c = (a + b)/2;
		return max(get(i, j, 2*n, a, c), get(i, j, 2*n + 1, c, b));
	}
	void set(int p, int val){ // O(lg n)
        pii act = {val, p};
		for (p += sz; p > 0 && t[p].fst != val;){
			t[p] = act, p /= 2;
			act = max(t[p*2], t[p*2 + 1]);
		}
	}
} rmq;

int main() {
	fastio;
	
    int n, k; cin >> n >> k;
    vi p(n); for (int &x : p) { cin >> x; x--; }

    rmq.init(n);
    forn(i, n) rmq[i] = p[i];
    rmq.updall();

    auto is_maximum = [&p, k, n](int i) {
        int l = max(i - k + 1, 0), r = min(i + k, n);
        return p[i] == rmq.get(l, r).fst;
    };

    priority_queue<int> local_maximums;
    forn(i, n) if (is_maximum(i)) local_maximums.push(i);

    vi ans(n);
    dforn(next_id, n) {
        int local_maximum = -1; 
        while (local_maximum == -1 || !is_maximum(local_maximum)) 
            local_maximum = local_maximums.top(), local_maximums.pop();

        ans[local_maximum] = next_id;
        rmq.set(local_maximum, -INF);

        auto update = [is_maximum, &local_maximums, n, k](int block) {
            if (block < 0 || block * k >= n) return;

            int l = block * k, r = min((block + 1) * k, n);

            int candidate = rmq.get(l, r).snd;
            if (candidate >= 0 && is_maximum(candidate)) 
                local_maximums.push(candidate);
        };

        int block_number = local_maximum / k;
        forsn(block, block_number - 1, block_number + 2) update(block);
    }

    for (int &x : ans) cout << x + 1 << endl;
	 
	return 0;
}


Measured memory_bytes: 25200
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,h,ans=0; cin>>n>>h;
    vector<ll> a(n,0),b(n,0);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    sort(al(a)); reverse(al(a));
    sort(al(b)); reverse(al(b));
    ll i=0;
    while(b[i]>a[0] && i<n){
            h-=b[i];
            ans++;
            i++;
            if(h<=0) break;
    }
        if(h>0){
            ans+=(h+a[0]-1)/a[0];
            h=0;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define MAXN 100005
#define p 1000000007
#define LL long long
using namespace std;

int n, m, cnt, x[MAXN], y[MAXN], a[MAXN], b[MAXN];
LL t[MAXN];

struct Node {int a, b;} c[MAXN];

bool CMP(Node x, Node y)
{
	if(x.a!=y.a) return x.a<y.a;
	return x.b>y.b;	
}

void add(int x, int y)
{
	for(; x<=cnt; x+=(x&-x)) t[x]=(t[x]+y)%p; 
}

LL ask(int x)
{
	LL sum=0;
	for(; x; x-=(x&-x)) sum=(sum+t[x])%p;
	return sum;	
} 

int main()
{
	scanf("%d%d", &n, &m);
	for(int i=1; i<=n; i++) scanf("%d", &x[i]);
	for(int i=1; i<=m; i++) scanf("%d", &y[i]);
	for(int i=1, j=1; i<m && j<=n; i++)
	{
		while(x[j]<y[i]) j++;
		while(x[j]>=y[i] && x[j]<=y[i+1])
		{
			a[++cnt]=x[j]-y[i];
			b[cnt]=y[i+1]-x[j];
			c[cnt].a=a[cnt]; c[cnt].b=b[cnt];
			j++;
		}
	}
	sort(a+1, a+cnt+1); sort(b+1, b+cnt+1);
	for(int i=1; i<=cnt; i++)
	{
		c[i].a=lower_bound(a+1, a+cnt+1, c[i].a)-a;
		c[i].b=lower_bound(b+1, b+cnt+1, c[i].b)-b;
	}
	sort(c+1, c+cnt+1, CMP);
	for(int i=1; i<=cnt; i++)
		if(c[i].a!=c[i-1].a || c[i].b!=c[i-1].b) add(c[i].b, (ask(c[i].b-1)+1)%p);
	printf("%d\n", (ask(cnt)+1)%p);
}

Measured memory_bytes: 3328
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    ll h,w;cin >> h >> w;
    if(h == 1 or w == 1){
        cout << 1 << '\n';
        return 0;
    }
    if(h%2 ==0){
        cout << (h*w)/2 << '\n';
    }else{
        cout << (w+1)/2 + (h-1)*w/2 << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main 
{
	static class Spot
	{
		int x;
		int y;
		
		public Spot(int x, int y)
		{
			this.x = x;
			this.y = y;
		}
	}

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		while(true)
		{
			int w = sc.nextInt();
			if(w == 0)break;
			int h = sc.nextInt();
			boolean[][] grid = new boolean[w][h];
			
			int startx = -1;
			int starty = -1;
			
			for(int y = 0; y < h; y++)
			{
				String s = sc.next();
				for(int x = 0; x < w; x++)
				{
					grid[x][y] = (s.charAt(x) == '.' || s.charAt(x) == '@');
					if(!grid[x][y])
					{
//						System.out.println("WALL " + x + " " +y);
					}
					
					if(s.charAt(x) == '@')
					{
						startx = x;
						starty = y;
					}
				}
			}
			int count = 0;
			
			Stack<Spot> queue = new Stack<Spot>();
			
			queue.add(new Spot(startx, starty));
			
			while(!queue.isEmpty())
			{
				Spot spot = queue.pop();
				int x = spot.x;
				int y = spot.y;
				if(grid[x][y])
				{
					grid[x][y] = false;
					count++;
					
//					System.out.println("Add " + x + " " + y);
					
					if(x > 0 && grid[x-1][y])queue.add(new Spot(x-1, y));
					if(y > 0 && grid[x][y-1])queue.add(new Spot(x, y-1));
					if(x < w-1 && grid[x+1][y])queue.add(new Spot(x+1, y));
					if(y < h-1 && grid[x][y+1])queue.add(new Spot(x, y+1));
				}
				else
				{
//					System.out.println("False: " + x + " " + y);
				}
			}
			
			System.out.println(count);
		}


	}

}



Measured memory_bytes: 39908
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

#define ll long long
#define rr register

#define inf 1e9
#define MAXN 100010

using namespace std;

inline int read() {
	int s = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

void print(int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar(x % 10 + 48);
}

int n, m;

signed main() {
	n = read();
	m = read();
	if (m % 2 != 0) cout << "No\n";
	else if (m >= n * 2 && m <= n * 4) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 3668
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
using namespace std;

int N;
string input;

void query(int x) {
  printf("%d\n", x);
  fflush(stdout);
  cin >> input;
}

bool check(int lc, int rc, int len) {
  if ((lc != rc) ^ (len & 1) ^ 1) return true;
  return false;
}

int main() {
  scanf("%d", &N);

  query(0);
  if (input == "Vacant") exit(0);
  
  int l = 0, r = N, lcol, rcol;
  if (input == "Male") lcol = rcol = 0;
  else lcol = rcol = 1;
 
  while (true) {
    int mid = (l + r) >> 1, midcol;
    query(mid);

    if (input == "Vacant") exit(0);
    if (input == "Male") midcol = 0;
    else midcol = 1;

    if (check(lcol, midcol, mid - l - 1)) r = mid, rcol = midcol;
    else l = mid, lcol = midcol;
  }
  
  return 0;
}


Measured memory_bytes: 852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.nextLine());

		int[][] matrix = new int[n][n];
		for (int i = 0; i < n; i++) {
			String[] nico = sc.nextLine().split(" ");
			for (int j = 0; j < n; j++) {
				matrix[i][j] = Integer.parseInt(nico[j]);
			}
		}

		int[][] tmpj = new int[n][n + 1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < tmpj[0].length; j++) {
				tmpj[i][j] = 0;
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 1; j < tmpj[0].length; j++) {
				if (j > 0) tmpj[i][j] = tmpj[i][j - 1] + matrix[i][j - 1];
				else tmpj[i][j] = matrix[i][j];
			}
		}		//ここただの累積和

		/*String unko="";

		for(int i=0; i<n; i++) {
			unko="";
			for(int j=0; j<=n; j++) {
				unko=unko+tmpj[i][j]+" ";
			}
			System.out.println(unko);
		}*/

		int max = Integer.MIN_VALUE;
		for (int si = 0; si < n; si++) {
			for (int ei = (si + 1); ei <= n; ei++) {

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

						int sum = 0;
						for (int i = si; i < ei; i++) {
							sum = sum + tmpj[i][ej] - tmpj[i][sj];
						}
						if (max < sum) max = sum;		//ここただ純粋に総当たりすれば良いのか…困惑  O(N^3)だから100で通るのか
					}
				}
			}
		}

		System.out.println(max);
	}
}


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

int main(){
    string s;
    cin>>s;
    int size;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='A'){
            size=i;
            break;
        }
    }
    for(int i=s.size()-1;i>=0;i--){
        if(s.at(i)=='Z'){
            size=i-size+1;
            break;
        }
    }
    cout<<size<<endl;
}

Measured memory_bytes: 640
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long ans = 1;
			for(int i = 1; i < 41; i++) {
				long right = 1;
				long left = 1;
				for(int j = 0; j < i-1; j++) {
					left*=2;
				}
				for(int j = 0; j < i; j++) {
					right*=2;
				}
				if(left<=H&&H<right) {
					ans = right-1;
					break;
				}
			}
		System.out.println(ans);
	 }
}

Measured memory_bytes: 22740
'use strict';
function Main(stdin){
  const input = stdin.trim().split(/\r?\n/g).map(str => Number(str));
  const N = input.shift();
  let btn_num = 1;
  let result = -1;
  let count = 0;

  for(let i = 0; i < N; i++){
    btn_num = input[btn_num-1];
    count++;
    if(btn_num === 2){
        result = count;
        break;
    }
  }
  console.log(result);
}

// 固定
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 16332
n = gets.chomp.to_i

ans = 10**6
2.upto(n/2+1) do |a|
    b = n - a
    aa = a.to_s.split("").map(&:to_i).inject(:+)
    bb = b.to_s.split("").map(&:to_i).inject(:+)
    ans = aa + bb if aa + bb < ans
end
puts ans

Measured memory_bytes: 2044
import java.util.*;

public class Main {

    final static int mod = 1_000_000_007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int all = n*m;
        Combination comb = new Combination(all, mod);
        long com2 = comb.comb(all-2, k-2);
        long[][] sum = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                sum[i][j] += i + j;
                if(0 < i) sum[i][j] = (sum[i][j] + sum[i-1][j]) %mod;
                if(0 < j) sum[i][j] = (sum[i][j] + sum[i][j-1]) %mod;
                if(0 < i && 0 < j) sum[i][j] = (sum[i][j] - sum[i-1][j-1] + mod) %mod;
            }
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                long dsum = sum[i][j];
                if(0 < i && j < m-1){
                    dsum = (dsum + sum[i][m-1-j]) % mod;
                    dsum = (dsum - sum[0][m-1-j] + mod) % mod;
                    dsum = (dsum - sum[i][0] + mod) % mod;
                }
                ans += dsum *  com2 % mod;
                ans %= mod;
            }
        }

        System.out.println(ans);
        sc.close();

    }

}

class Combination {

    /** factorial:階乗 */
    private long fac[];
    /** inverse:逆元（ここでは、fac[i]をMOD-2乗したものをMODで割った余り） */
    private long inv[];
    /** 除数 */
    private int mod;

    /**
     * コンストラクタ
     * @param size 組み合わせの対象となる個数
     * @param mod 除数
     */
    public Combination(int size, int mod){
        this.fac = new long[size +1];
        this.inv = new long[size +1];
        this.mod = mod;

        this.fac[0] = 1;
        this.inv[0] = 1;

        for(int i = 1; i <= size; i++){
            fac[i] = (fac[i -1] * i) %mod;
            inv[i] = modPow(fac[i], (int)mod -2) %mod;
        }
    }

    /**
     * n個の中からr個選ぶ組み合わせの数（nCr）をmodで割った余りを算出する
     * @param n 元の集合の要素数
     * @param r 組み合わせる要素数
     * @return nCr % mod
     */
    public long comb(int n, int r){
        return fac[n] * inv[r] %mod * inv[n - r] %mod;
    }

    /**
     * base^exp をmodで割った余りを算出する
     * @param base 基数
     * @param exp 指数
     * @return base^exp % mod
     */
    private long modPow(long base, int exp) {
        long ret = 1;
        while(exp > 0){
            if((exp & 1) == 1){
                ret = ret * base %mod;
            }
            base = base * base %mod;
            exp >>= 1;
        }
        return ret;
    }

}


Measured memory_bytes: 30292
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<P, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)
#define PI (acos(-1.0))
#define R (PI/2)

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int r,c,i,j,m,k,a[12][12345],tmp,ans,t;
	cin >> r >> c;
	while(r && c){
		for(i=0; i<r; ++i){
			for(j=0; j<c; ++j){
				cin >> a[i][j];
			}
		}
		m = (1<<r);
		ans = 0;
		for(k=0; k<m; ++k){
			tmp = 0;
			for(j=0; j<c; ++j){
				t = 0;
				for(i=0; i<r; ++i){
					t += ((k&(1<<i))?1:0)^a[i][j];
				}
				tmp += max(t,r-t);
			}
			ans = max(ans,tmp);
		}
		cout << ans << endl;
		cin >> r >> c;
	}
	return 0;
}



Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int ans = 0, tmp = 0;
    vector<int> A(3);
    for (int i = 0; i < 3; i++) sc(A[i])
    sort(A.begin(), A.end());
    if ((A[2] - A[1]) % 2 == 0) ans += (A[2] - A[1]) / 2;
    else {
        ans += A[2] - A[1];
        A[0] += A[2] - A[1];
    }
    tmp = A[2] - A[0];
    if (tmp % 2 == 0) ans += tmp / 2;
    else ans += tmp / 2 + 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n,m;
	cin>>n>>m;
	int ans=m;
	bool f=true;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		m+=a-b;
		if(m<0) f=false;
		ans=max(ans,m);
	}
	if(!f) cout<<0<<endl;
	else cout<<ans<<endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define maxn 10086

using namespace std;

int n;
int a[maxn];

int main(){
	for(int i = 1;i * i + 1 + 1 + i * 1 + 1 * 1 + i * 1 < maxn;i++){
		for(int j = i;i * i + j * j + 1 + i * 1 + j * 1 + i * j < maxn;j++){
			for(int k = j;i * i + j * j + k * k + i * k + j * k + i * j < maxn;k++){
				if(i == j && i == k) a[i * i + j * j + k * k + i * k + j * k + i * j]++;
				else if(i == j || i == k || j == k) a[i * i + j * j + k * k + i * k + j * k + i * j] += 3;
				else a[i * i + j * j + k * k + i * k + j * k + i * j] += 6;
			}
		}
	}
	scanf("%d", &n);
	for(int i = 1;i <= n;i++) printf("%d\n", a[i]);
	
}

Measured memory_bytes: 3848
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuMinCoinChange solver = new AizuMinCoinChange();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuMinCoinChange {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int m = in.nextInt();
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            int[] dp = new int[m + 1];
            dp[0] = 0;
            for (int i = 1; i <= m; i++) {
                dp[i] = Integer.MAX_VALUE;
                for (int j = 0; j < n; j++) {
                    if (i >= a[j]) {
                        dp[i] = Math.min(dp[i], dp[i - a[j]] + 1);
                    }
                }
            }

            out.printf("%d\n", dp[m]);
        }

    }
}




Measured memory_bytes: 27312
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        if self.parents[y] < self.parents[x]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    N, M = map(int, input().split())
    A, B = [0] * M, [0] * M
    for i in range(M):
        A[i], B[i] = map(lambda x: int(x) - 1, input().split())
    
    disconnect = []
    d = N * (N - 1) // 2
    uf_tree = UnionFind(N)
    for ai, bi in zip(A[::-1], B[::-1]):
        disconnect.append(d)
        if uf_tree.find(ai) != uf_tree.find(bi):
            d -= uf_tree.size(ai) * uf_tree.size(bi)
            uf_tree.union(ai, bi)
    
    for ans in disconnect[::-1]:
        print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 17744
n=int(input())
a=input().split()
a_even=[a[i] for i in range(0,n,2)]
a_odd=[a[i] for i in range(1,n,2)]

if n%2==1:
    a_even.reverse()
    ans=' '.join(a_even) +' ' + ' '.join(a_odd)
    print(ans)
else:
    a_odd.reverse()
    ans=' '.join(a_odd)+' '+' '.join(a_even)
    print(ans)


Measured memory_bytes: 25232
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repx(x,i,n) for(int i=x;i<n;i++)
#define rep(i,n) repx(0,i,n)
#define all(x) x.begin(),x.end()

signed main(){
	ll N;
	cin>>N;
	ll h[N+10]={0};
	ll DP[N+10]={0};
	repx(1,i,N+1) cin>>h[i];
	DP[2]=abs(h[2]-h[1]);
	repx(3,i,N+1){
		DP[i]=min(DP[i-1]+abs(h[i]-h[i-1]),DP[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<DP[N]<<endl;
	return 0;
}



Measured memory_bytes: 1792
#include "bits/stdc++.h"

#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)

using namespace std;

using I = int;
using L = long;
using F = float;
using S = string;
using SS = stringstream;
using C = char;
using LL = long long;
using VI = vector<int>;
using VL = vector<long>;
using VF = vector<float>;
using VS = vector<string>;
using VVI = vector<vector<int>>;
using VVL = vector<vector<long>>;
using PLL = pair<long, long>;
using PLF = pair<long, float>;
using PLS = pair<long, string>;
using PSL = pair<string, long>;
using PSF = pair<string, float>;
using PSS = pair<string, string>;
using MII = map<int, int>;
using MLL = map<long, long>;
using MLF = map<long, float>;
using MLS = map<long, string>;
using MSL = map<string, long>;
using MSF = map<string, float>;
using MSS = map<string, string>;

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMaxN = 1e5 + 5;

template <class T>
void PrintVector(const vector<T> & v) {
  for (const auto & e: v) {
    cout << e << endl;
  }
}

template <class T>
void PrintVector(const vector<T> & v, unsigned n) {
  rep(i, 0, n - 1) {
    cout << v[i] << endl;
  }
}

int main(int argc, char const *argv[]) {
  L n;
  L ans = 0;
  MII map_count;
  set<int> num_set;
  cin >> n;
  rep(i, 0, n - 1) {
    L a;
    cin >> a;
    ++map_count[a];
    num_set.insert(a);
  }
  for (const auto & e: num_set) {
    if (map_count[e] == 0) { continue; }
    if (map_count[e] >= e) { ans += map_count[e] - e; }
    else { ans += map_count[e]; }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9216
// I - Coins
#include <bits/stdc++.h>
using namespace std;
using dl = double;

int main(){
	int N; cin>>N;
	int C = (N+1)/2;
	vector<dl> dp(N+2);
	dp[1] = 1.;
	for(int lv=1; lv<=N; lv++){
		dl p; cin>>p;
		dl q = 1.-p;
		int e = max(1, lv-C+2);
		for(int i=lv+1; i>=e; i--) dp[i] = q*dp[i] + p*dp[i-1];
	}
	dl a = 0; for(int i=N+1; i>C; i--) a += dp[i];
	printf("%.10g\n",a);
}

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

int main() {
  
  int n,m;
  int a;
  int s = 0;
  
  cin >> n >> m;
  for(int i = 0;i<m;i++){
    cin >> a ;
    s = s + a;
  }
  
  if (n-s<0){
    cout << -1 << endl;
  }else{
    cout << n-s << endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	int n,k;cin >> n >> k;
	vector<ll> v(n);
	REP(i,n)cin >> v[i];
	
	int tmp = n - k;
	int ans = 1;
	k--;
	
	ans += (tmp + k - 1) / k;
	
	cout << ans << endl;
	
	return 0;
}

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

int main(int argc, char const *argv[])
{
	int n,a,b;
	cin>>n>>b>>a;
	if (a+b-1>n||(long long)a*b<(long long)n)
	{
		cout<<"-1\n";
		return 0;
	}
	vector<int> ans[(n+a-1)/a];
	int now=n,r=b;
	for (int i = (n+a-1)/a-1; i >= 0; --i)
	{
		--r;
		for (int j = 0; j < a; ++j)
		{
			if (now>r)
			{
				ans[i].push_back(now);
				--now;
			}
			else
			{
				break;
			}
		}
		if (now<r)
		{
			break;
		}
	}
	if (now>0)
	{
		for (int i = 1; i <= now; ++i)
		{
			if (i==1)
			{
				cout<<1;
			}
			else
			{
				cout<<" "<<i;
			}
		}
		for (int i = 0; i < (n+a-1)/a; ++i)
		{
			for (auto v:ans[i])
			{
				cout<<" "<<v;
			}
		}
		return 0;
	}
	int f=1;
	for (int i = 0; i < (n+a-1)/a; ++i)
	{
		for (auto v:ans[i])
		{
			if (f)
			{
				cout<<v;
				f=0;
			}
			else
			{
				cout<<" "<<v;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 16512
#include <bits/stdc++.h>

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

using namespace std;

int main(){
	int n,m; cin>>n>>m;

	int ans1=0,ans2=0;
	vector<bool> ac(n);
	vector<int> cnt(n);
	rep(i,m){
		int p;
		string s; cin>>p>>s; p--;
		if(s=="AC"){
			if(!ac[p]) ans1++, ans2+=cnt[p], ac[p]=true;
		}
		else cnt[p]++;
	}
	cout<<ans1<<' '<<ans2<<'\n';
	return 0;
}


Measured memory_bytes: 768
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

vector<int> v;

void rec(int digit, int num){
    if(digit == 10) return ;

    v.emplace_back(num);

    rec(digit + 1, num * 10 + 3);
    rec(digit + 1, num * 10 + 5);
    rec(digit + 1, num * 10 + 7);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;

    rec(0, 0);

    set<int> num357;
    for(auto i:v){
        bool is3 = false;
        bool is5 = false;
        bool is7 = false;

        int num = i;
        while(0 < num){
            if(num % 10 == 3) is3 = true;
            if(num % 10 == 5) is5 = true;
            if(num % 10 == 7) is7 = true;
            num /= 10;
        }

        if(is3 && is5 && is7) num357.emplace(i);
    }

    int ans = 0;
    for(auto i:num357){
        if(n < i) break;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
class Longint{
  vector<long long> V;
public:
  Longint(string s);
  int size();
  void print();
  Longint operator+(const Longint &o);
  Longint operator+=(const Longint &o);
};

int Longint::size(){
  return (this->V.size()-1)*9+to_string(V.back()).size();
}

void Longint::print(){
  printf("%lld",this->V.back());
  for (int i=this->V.size()-2;i>=0;i--){
    printf("%09lld",this->V[i]);
  }
}

Longint Longint::operator+(const Longint &o){
  Longint R("");
  const long long MOD = 1000000000;
  int i,k = max(this->V.size(),o.V.size());
  for(i=0;i<k;i++){
    R.V.push_back(0);
    if(i<this->V.size()){
      R.V.back() += this->V[i];
    }
    if(i<o.V.size()){
      R.V.back() += o.V[i];
    }
  }
  for(i=0;i<k-1;i++){
    R.V[i+1] += R.V[i]/MOD;
    R.V[i] %= MOD;
  }
  if(R.V[k-1]>=MOD){
    R.V.push_back(R.V[k-1]/MOD);
    R.V[k-1]%=MOD;
  }
  return R;
}

Longint Longint::operator+=(const Longint &o){
  return *this = *this+o;
}

Longint::Longint(string s){
  int n=s.size(),i,j = 0;
  long long d,h[9] = {1,10,100,1000,10000,100000,1000000,10000000,100000000};
  for (i=n-1;i>=0;i--){
    d=s[i]-'0';
    if(j == 0){
      this->V.push_back(d);
    }
    else{
      this->V.back() += d*h[j];
    }
    j = (j+1)%9;
  }
}

int main(){
  int t,i;cin >> t;
  string a,b;
  for(i=0;i<t;i++){
    cin >> a >> b;
    Longint G(a),H(b);
    G += H;
    if(G.size() > 80) printf("overflow");
    else G.print();
    printf("\n");
  }
}



Measured memory_bytes: 3212
#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,m;
    cin >>n>>m;
    vector<ll>x(n);
    vector<ll>y(m);
    ll sumx=0,sumy=0;

    rep(i,n){
        cin>>x[i];
    }

    rep(i,n-1){
        sumx = (sumx+((  ( (x[i+1]-x[i])*(i+1) )%mod  )*(n-i-1))%mod )%mod;
    }
    rep(i,m){
        cin>>y[i];
    }
    rep(i,m-1){
        sumy = (sumy+((  ( (y[i+1]-y[i])*(i+1) )%mod  )*(m-i-1))%mod )%mod;
    }
    
    
    //ll mx=(((x[n-1]-x[0])%mod)*((y[m-1]-y[0])%mod)%mod);
    ll ans=(sumx*sumy)%mod;
    //ans =(ans*(n-1))%mod;
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int n,m;
	cin>>n>>m;
	int x=0;
	x=n%m;
	if(x>=m-x){
		x=m-x;
	}
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){
    char s;
    cin>>s;
    if(isupper(s))cout<<"A";
    else cout<<"a";
    return 0;
}

Measured memory_bytes: 3032
package main

import "fmt"

func main() {
	var A, B, C string
	fmt.Scan(&A, &B, &C)
	var ans string
	if A[len(A)-1] == B[0] && B[len(B)-1] == C[0] {
		ans = "YES"
	} else {
		ans = "NO"
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) list.add(sc.nextInt());

        List<Integer> sorted = list.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
        System.out.println((sorted.get(1)-sorted.get(0)) + (sorted.get(2)-sorted.get(1)));
    }
}


Measured memory_bytes: 35884
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;

int main(){

    int n;
    cin >> n;

    int biggest = 0;
    map<int, int> mp;
    rep(i, n){
        int a;
        cin >> a;
        chmax(biggest, a);
        mp[a]++;
    }

    bool answer = true;
    auto itr = mp.begin();
    int now = (*itr).first;
    if(biggest % 2 == 0){
        if((*itr).second != 1)answer = false;
        if(now * 2 != biggest)answer = false;
    } else {
        if((*itr).second != 2)answer = false;
        if(now * 2 - 1 != biggest)answer = false;
    }
    for(itr++; itr != mp.end(); itr++){
        if(now + 1 != (*itr).first)answer = false;
        if((*itr).second < 2)answer = false;
        now = (*itr).first;
    }
    
    cout << (answer ? "Possible\n" : "Impossible\n");
    return 0;

}

Measured memory_bytes: 256