akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <ctime>
#include <random>

#define ll long long
#define ld long double
#define mod 1000000007
using namespace std;
//ifstream cin("input.txt"); ofstream cout("output.txt");
//ifstream cin("umbrella.in"); ofstream cout("umbrella.out");

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	/*int a, b;
	cin >> a >> b;
	vector<int> A(16);
	if (a < b) swap(a, b);
	for (int i = 0; i < 16; i += 2) {
		if (a == 0) break;
		else {
			a--;
			A[i] = 1;
		}
	}
	for (int i = 1; i < 16; i += 2) {
		if (b == 0) break;
		else {
			b--;
			A[i] = 2;
		}
	}
	for (int i = 1; i < 16; i++) {
		if (A[i] && A[i - 1] == A[i]) {
			cout << ":(";
			return 0;
		}
	}
	if (A[0] == A[15] && A[0] || a || b) {
		cout << ":(";
	}
	else {
		cout << "Yay!";
	}
	int d, n;
	cin >> d >> n;
	int cur = 1;
	if (d == 1) {
		cur = 100;
	}
	if (d == 2) cur = 10000;
	cout << n*cur;*/
	int n;
	cin >> n;
	vector<ll> a(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			ans++;
		}
	}
	cout << ans;
	return 0;
}

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

int main(){
  string s; cin >> s;
  string t = s;
  reverse(t.begin(),t.end());
  int cnt = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] != t[i]){ cnt++;}
  }
  
  cout << cnt/2 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    char a;
    REP(i,3){
        cin>>a;
        cout<<a;
    }
    return 0;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace Topic03
{
    class ALDS1_3_A
    {
        static void Main(string[] args)
        {
            List<string> input = ReadLine().Split().ToList();

            Stack<int> calculate = new Stack<int>();
            for (int i = 0; i < input.Count; i++)
            {
                if (input[i] == "+" || input[i] == "-" || input[i] == "*")
                {
                    int rightValue = calculate.Pop();
                    int leftValue = calculate.Pop();
                    int result = 0;
                    switch (input[i])
                    {
                        case "+":
                            result = leftValue + rightValue;
                            break;
                        case "-":
                            result = leftValue - rightValue;
                            break;
                        case "*":
                            result = leftValue * rightValue;
                            break;
                    }
                    calculate.Push(result);
                }
                else
                {
                    calculate.Push(int.Parse(input[i]));
                }
            }
            WriteLine(calculate.Pop().ToString());
            ReadKey();
        }
    }
}



Measured memory_bytes: 18556
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int n;cin>>n;
    vector<long long> a(n);
    map<long long,int> b;
    long long res = n;
    long long num1 = 0;
    vector<bool> p(100010,1);
    vector<long long> ps(0);
    map<long long, long long> ma;
    ma[1] = 1;
    for(long long i=2;i<100010;++i){
        if(p[i]){
            if(i*i*i<=20000000000)ps.push_back(i);
            for(int k=2;k*i<100010;++k)p[k*i]=0;
            ma[i] = i*i;
            ma[i*i] = i;
        }
    }
    for(int i=0;i<n;++i)cin>>a[i];
    for(int i=0;i<n;++i){
        long long tmp = 1,tmp2 = a[i];
        for(long long k:ps){
            while(a[i]%(k*k*k) == 0){
                a[i]/=k*k*k;
                tmp2/=k*k*k;
            }
            if(a[i]%k == 0){
                if(a[i]%(k*k)==0){
                    tmp*=k;
                    a[i]/=k*k;
                }
                else{
                    tmp*=k*k;
                    a[i]/=k;
                }
            }
        }
        if(tmp2==1)num1++;
        else{
            if(b[tmp2]>0){
                b[tmp2]--;
                res--;
            }
            else{
                if(ma.find(a[i])!=ma.end()) b[tmp*ma[a[i]]]++;
            }
        }
    }
    if(num1>0)res-=num1-1;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long int ll;
using namespace std;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int A,B;
cin>>A>>B;

int price;

if(A>=13)price=B;
else if(A>=6) price=B/2;
else price=0;

cout<<price<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Possible" : "Impossible")
typedef vector<int>	Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int h,w;
	int ans=0;
	cin >>h>>w;
	string a;
	rep(i,h){
		cin>>a;
		rep(j,w){
			ans+=(a[j]=='#'?1:0);
		}
	}
	cout<<solve(ans==h+w-1)<<endl;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;

    int n;
    cin >> n;

    string data[128];
    data['1'] = ".,!? ";
    data['2'] = "abc";
    data['3'] = "def";
    data['4'] = "ghi";
    data['5'] = "jkl";
    data['6'] = "mno";
    data['7'] = "pqrs";
    data['8'] = "tuv";
    data['9'] = "wxyz";

    rep(i, 0, n) {
        string s, out;
        cin >> s;

        char c = 0;
        int l = -1;

        for (char d : s) {
            if (d == '0') {
                if (c != 0)
                    out += data[c][l % data[c].size()];
                c = 0, l = -1;
            } else {
                c = d;
                l++;
            }
        }

        cout << out << endl;
    }
}


Measured memory_bytes: 3188
#include"bits/stdc++.h"
using namespace std;
int a,b;

int main(){
    cin>>a>>b;
    if(a>0)cout<<"Positive";
    else if(a==0||(a<0&&b>0))cout<<"Zero";
    else if((abs(b)-abs(a))%2!=0)cout<<"Positive";
    else cout<<"Negative";
    return 0;
} 

Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, w = ns()
    a = [na() for _ in range(n)]

    idx = n * 10 ** 3 + 1
    dp = [INF for _ in range(idx)]
    dp[0] = 0

    for wi, vi in a:
        for i in range(idx - 1, -1, -1):
            if dp[i] + wi <= w and i + vi < idx and dp[i] > -1:
                dp[i + vi] = min(dp[i + vi], dp[i] + wi)

    for i in range(idx - 1, -1, -1):
        if dp[i] != INF:
            print(i)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 83700
import bisect
from collections import deque
N, K = map(int, input().split())
a = sorted(map(int, input().split()))

# K以上のカードは単体で条件を満たすから考えない
a_k = bisect.bisect_left(a, K, lo=0, hi=N)
A = a[:a_k][::-1]
tmp = 0
N = result = N-(N-a_k)

for n, i in enumerate(A):
    if tmp+i >= K:
        result = N-(n+1)
    else:
        tmp += i

print(result)

Measured memory_bytes: 3828
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
const ll c = 1e18;
ll x, y;

int main() {
    scanf("%lld%lld", &x, &y);
    int cnt = 0;
    while(x * 2 <= y) {
        x *= 2;
        cnt++;
    }
    printf("%d\n", cnt + 1);
    return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline

import queue
class gridMan:
  def __init__(s, L):
    s.L = L
    s.H = len(s.L)
    s.W = len(s.L[0])
  def makeWall(s, x = -2):
    w = len(s.L[0]) + 2
    s.L = [[x] * w] + [[x] + i + [x] for i in s.L] + [[x] * w]
  def dist(s, S): #Sから上下左右に進んで何手かかるかのリスト　および　最大値
    T = [[-1] * s.W for _ in range(s.H)]
    q = queue.Queue()
    q.put([S[0], S[1]])
    T[S[0]][S[1]] = 0
    k = 0
    while not q.empty():
      h, w = q.get()
      p = T[h][w]
      for i, j in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        for k in range(1, K + 1):
          hh = h + i * k
          ww = w + j * k
          if s.L[hh + 1][ww + 1] >= 0:
            if T[hh][ww] == -1 or T[hh][ww] > p + 1:
              q.put([hh, ww])
              T[hh][ww] = p + 1
            elif T[hh][ww] != p + 1:
              break
          else:
            break
            
    return T, k


H, W, K = list(map(int, input().split()))
xy = list(map(int, input().split()))
c = []
for i in range(H):
  c.append(list(input().replace("\n", "")))

for i in range(H):
  for j in range(W):
    if c[i][j] == ".":
      c[i][j] = 0
    else:
      c[i][j] = -1

g = gridMan(c)
g.makeWall()

L, k = g.dist([xy[0] - 1, xy[1] - 1])

print(L[xy[2] - 1][xy[3] - 1])

Measured memory_bytes: 203740
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int N;cin>>N;
    map<int,int>memo;
    for(int i=1;i<=sqrt(N);i++){
        if(N%i==0){
            memo[i]++;
            memo[N/i]++;
        }
    }
    int ok=false;
    for(auto it=memo.begin();it!=memo.end()&&!ok;it++){
        REPS(i,200){
            int a=i;
            int b=i-it->first;
            if(pow(a,5)-pow(b,5)==N){
                cout<<a<<" "<<b<<endl;
                ok=true;
                break;
            }
        }
    }
}

Measured memory_bytes: 4000
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
typedef long long ll;

int main(){
    // int N;cin>>N;
    // for(int s = 0; s < (1<<N); s++){//for(int i = 0; i < N; i++)
    //     vector<int> ans;
    //     for(int i = 0; i<N; i++){
    //         //要素iを使うかどうか
    //         if(s &(1<<i))ans.push_back(i);
    //         // cout<<s<<endl;
    //     }
    //     cout<<"{";
    //     for (int i = 0; i < ans.size(); i++)
    //     {
    //         cout<<ans[i];
    //         //途中なら,を出力
    //         if(i < ans.size() - 1) cout<<",";
    //     }
    //     cout<<"}"<<endl;
        
    // }
    int N;cin>>N;
    string S;cin>>S;
    int ans = 0;
    for(int i = 1; i < S.size(); i++){
        if(S[i-1] != S[i])ans++;
    }
    ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#define rep(i,N) for(long long i=0;i<(long long)N;i++)
int N,x,y,pos,tri0,tri1,tri2,pw3[13]={1},A[531441],salsa[531441],sw[531441];
char T[200001];
void OUT(long long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
char* replace(char* s,const char* before,const char* after)
{
  assert(s!=(char*)NULL);assert(before!=(char*)NULL);assert(after!=(char*)NULL);
  const size_t szb=strlen(before),sza=strlen(after);
  char* pt=s;
  if(szb==0)return s;
  for(;;)
  {
    pt=strstr(pt,before);if(pt==(char*)NULL)break;const char* remain=pt+szb;
    memmove(pt+sza,remain,strlen(remain)+1);
    memcpy(pt,after,sza);
    pt+=sza;
  }
  return s;
}
signed main(void)
{
  x=scanf("%d %s",&N,T+1);
  replace(T+1,"SS","");if(T[0]=='\n')return 0;
  rep(i,N)pw3[i+1]=3*pw3[i];
  tri0=pw3[N],tri1=pw3[N/2],tri2=pw3[N-N/2];
  rep(i,tri0)salsa[i]=salsa[i/3]*3+(3-i%3)%3;
  rep(i,tri1)
  {
    x=i,pos=0;
    rep(j,strlen(T+1))
    {
      if(T[j+1]=='S'){x=salsa[x];if(sw[pos]>0)pos--;else sw[++pos]=1;}
      if(T[j+1]=='R'){x++;if(x==tri1)sw[++pos]=-1,x=0;}
    }
    rep(j,tri2)
    {
      y=j;
      rep(k,pos){if(sw[k+1]>0)y=salsa[y];else if(sw[k+1]<0){if((++y)==tri2)y=0;}}
      A[i+j*tri1]=y*tri1+x;
    }
  }
  rep(i,tri0)OUT(A[i]),putchar(' ');
}

Measured memory_bytes: 8200
#include <bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define int long long
#include "string"

void verify(vector<int>ans,int n,int k){
	bool okk = true;
	for(int i=0;i<n;i++){
		int l = 0;
		while(ans[l] != i)
			l++;
		l++;
		int cur  = 0;
		while(ans[l]!=i){
			cur ^= ans[l];
			l++;
		}
		cout<<i<<" "<<l<<endl;
		if(cur != k){
			cout<<i<<endl;
			okk = false;
			break;
		}
	}

	sort(ans.begin(),ans.end());
	int j = 0;
	for(int i=0;i<n;i++){
		if(ans[j]!=i or  ans[j+1]!=i){
			okk = false;
			break;
		}
		j+=2;
	}
	if(okk)
		cout<<"done"<<endl;
	else
		cout<<"No"<<endl;
}

int32_t main() {
	boost;
	int m,k;
	cin>>m>>k;
	int n = (1ll<<m);
	if(k >= n){
		cout<<-1<<endl;
		return 0;
	}
	if(m == 1){
		if(k == 1)
			cout<<-1<<endl;
		else
			cout<<"0 0 1 1"<<endl;
		return 0;
	}

	if(k == 0){
		for(int i=0;i<n;i++)
			cout<<i<<" ";
		for(int i=n-1;i>=0;i--)
			cout<<i<<" ";
		return 0;
	}

	vector<int>ans;
	for(int i=0;i<n;i++){
		if(i == k)
			continue;
		ans.push_back(i);
	}
	ans.push_back(k);
	for(int i=n-1;i>=0;i--){
		if(i == k)
			continue;
		ans.push_back(i);
	}
	ans.push_back(k);
	//verify(ans,n,k);
	for(int &i:ans)
		cout<<i<<" ";
	cout<<endl;
}

Measured memory_bytes: 5308
n, q = map(int, input().split())
s = str(input())
l = [-1] * q
r = [-1] * q
for i in range(q):
    l[i], r[i] = map(int, input().split())
sum = [0] * (n+1)
flag_a = False
for i in range(1, n+1):
    if s[i-1] == 'A':
        flag_a = True
        sum[i] = sum[i-1]
    elif s[i-1] == 'C' and flag_a:
        flag_a = False
        sum[i] = sum[i-1] + 1
    else:
        flag_a = False
        sum[i] = sum[i-1]
for i in range(q):
    print(sum[r[i]] - sum[l[i]])



Measured memory_bytes: 14228
#include <iostream>
#include <string>

using namespace std;

int main(){
    int count = 0;
    string area;
    cin >> area;
    if(area[0] == '1') count += 1;
    if(area[1] == '1') count += 1;
    if(area[2] == '1') count += 1;
    cout << count << endl;
}


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

using namespace std ;

#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define ll long long int 

#define fr first
#define se second

#define all(v) v.begin(),v.end() 
#define rall(v) v.rbegin(),v.rend()
#define sz(v) v.size() 

#define pb push_back
#define mp make_pair 

#define PI 3.141592653589793238



ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b / gcd(a,b) ;}


//bool valid(int x, int y){return x > 0 && x < 9 && y > 0 && y < 9;}

int cntr, a[222], n, m, c, sum;

int main(){
  cin >> n >> m >> c;
  for(int i = 0 ; i < m ; i++)
    cin >> a[i];
  while(n--){
    for(int i = 0 ; i < m; i++){
      int x;
      cin >> x;
      sum += (a[i]*x);
    }
    sum += c;
    if(sum > 0)
      cntr++;
    sum = 0;
  }
  cout << cntr;
 return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {

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

        HashMap<Integer, Integer> primeCount = new HashMap<>();

        primeCount.put(1, 1);
        for (int i = 2; i <= N; i++) {
            int value = i;
            for (int j = 2; j <= i; j++) { // 2~nまで
                while (value % j == 0) {   // 割り切れる数字があったらそれで割終わるまで割る
                    primeCount.put(j, primeCount.containsKey(j) ? primeCount.get(j) + 1 : 1);
                    value = value / j;     // 割るたびに割る
                }
            }
        }
        
        int ans = 0;
        //  4,4,2
        for (Map.Entry<Integer, Integer> entry0 : primeCount.entrySet()) {
            for (Map.Entry<Integer, Integer> entry1 : primeCount.entrySet()) {
                for (Map.Entry<Integer, Integer> entry2 : primeCount.entrySet()) {
                    if (entry0.getKey() == entry1.getKey()) continue;
                    if (entry0.getKey() == entry2.getKey()) continue;
                    if (entry1.getKey() == entry2.getKey()) continue;
                    if (entry1.getKey() > entry2.getKey()) continue;
                    if (entry0.getValue() >= 2 && entry1.getValue() >= 4 && entry2.getValue() >= 4) ans++;
                }
            }
        }

        //  24,2
        //  4,14
        for (Map.Entry<Integer, Integer> entry0 : primeCount.entrySet()) {
            for (Map.Entry<Integer, Integer> entry1 : primeCount.entrySet()) {
                if (entry0.getKey() == entry1.getKey()) continue;
                if (entry0.getValue() >= 4 && entry1.getValue() >= 14) ans++;
                if (entry0.getValue() >= 2 && entry1.getValue() >= 24) ans++;
            }
        }

        //  74
        for (Integer count : primeCount.values()) {
            if (count >= 74) ans++;
        }

        System.out.println(ans);
    }


}

Measured memory_bytes: 23764
//“Failure is unimportant. It takes courage to make a fool of yourself.”

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
#define int long long int
#define P 1000000007
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define b(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 1000
#define PI 3.14159265359
#define inf LLONG_MAX
using namespace __gnu_pbds;
using namespace std;

signed main() {
    teevra_gati
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ll s,w;
    cin>>s>>w;
    if(w>=s) cout<<"unsafe";
    else cout<<"safe";
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e12;

// computational complexity : O(E*logV)

struct edge{
    int to, cost;
};

int V,E;// number of (vertices, edges)
vector<vector<edge>> graph;
vector<long long int> d;// shortest distances

void Dijkstra(int s){// s = starting point
    priority_queue<
        pair<int, int>// temporarily keeping (shortest distance, vertex)
        , vector<pair<int, int>>, greater<pair<int, int>>// shorter ones first
    > pq;

    // initialize (INF)
    for(int i=0; i<V; i++){
        d[i] = INF;
    }
    d[s] = 0;
    pq.push({0,s});

    // search
    pair<int, int> current;// (shortest-distance confirmed, vertex)
    while(!pq.empty()){
        current = pq.top(); pq.pop();

        int v = current.second;
        if(d[v] < current.first){
            continue;// ignore (not the shortest path)
        }
        // else (need to check)
        for(edge e : graph[v]){// adjacent nodes
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;// update minimum cost
                pq.push({d[e.to], e.to});
            }
        }
    }
}

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

    V = k;
    graph.resize(V);
    d.resize(V);

    for(int i=0; i<k; i++){
        graph[i].push_back({(i+1)%k, 1});
        graph[i].push_back({(10*i)%k, 0});
    }

    Dijkstra(1);
    cout << d[0] + 1 << endl;
    return 0;
}

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

int main() {
  int N;
  cin>>N;
  N*=2;
  if(floor(sqrt(N))*(floor(sqrt(N))+1)!=N){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
    cout<<floor(sqrt(N))+1<<endl;
    vector<vector<int>> G(floor(sqrt(N))+1,vector<int>(floor(sqrt(N))+1,floor(sqrt(N))));
    int a=1;
    for(int i=0;i<floor(sqrt(N));i++){
      for(int j=i+1;j<=floor(sqrt(N));j++){
        G.at(i).at(j)=a;
        a++;
      }
    }
    a=1;
    for(int j=1;j<=floor(sqrt(N));j++){
      for(int i=j;i<floor(sqrt(N))+1;i++){
        G.at(i).at(j)=a;
        a++;
      }
    }
    for(int i=0;i<floor(sqrt(N))+1;i++){
      for(int j=0;j<floor(sqrt(N))+1;j++){
        cout<<G.at(i).at(j);
        if(j!=floor(sqrt(N))){
          cout<<" ";
        }
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 2176
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
int main(void) {
    while(true) {
        int n, m;
        cin>>n>>m;
        if(n == 0 && m == 0) break;
        vector<int> s1(n);
        vector<int> s2(m);
        int sum1 = 0;
        int sum2 = 0;
        REP(i, n) {
            cin>>s1[i];
            sum1 +=s1[i];
        }
        REP(i, m) {
            cin>>s2[i];
            sum2 += s2[i];
        }
        int a = -1;
        int b = -1;
        int ansum = INF;
        if((sum1 - sum2) % 2 != 0) {
            cout<<-1<<endl;
            continue;
        }
        REP(i, n) {
            REP(j, m) {
                if(s1[i] - s2[j] == (sum1 - sum2) / 2 && s1[i] + s2[j] < ansum) {
                    a = s1[i];
                    b = s2[j];
                    ansum = a + b;
                }
            }
        }
        if(ansum != INF) cout<<a<<" "<<b<<endl;
        else cout<<-1<<endl;
    }
}


Measured memory_bytes: 2960
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a,b,i;
int main()
{
	cin>>a>>b;
	i=0;
	while(a<=b)
	{
		a=a<<1;
		i++;
	}
	cout<<i<<endl;
	return 0;
}

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

int main(){
  int n,d,p;
  int ans=0;
  cin >> n >> d;
  vector<int> v;
  rep(i,n){
    cin >> p;
    if(p>d)v. push_back(p-d);
  }
  if(v.empty() == 0) {
    rep(i,v.size()){
      ans += v[i];
    }
    cout << ans << endl;
  }
  else cout << "kusoge" << endl;
  return 0;
}


Measured memory_bytes: 3120
using System;

class Program
{
    static void Main(string[] args)
    {
        var num = Convert.ToInt32(Console.ReadLine());
        var discountDay = Convert.ToInt32(Console.ReadLine());
        var price1 = Convert.ToInt32(Console.ReadLine());
        var price2 = Convert.ToInt32(Console.ReadLine());

        if (num < discountDay) Console.WriteLine(price1 * num);
        else Console.WriteLine(price1 * discountDay + price2 * (num - discountDay));
    }
}

Measured memory_bytes: 11220
s = input()

max_len = 0
tmp_len = 0
for w in s:
    if w == "A" or w == "C" or w == "G" or w == "T":
        tmp_len += 1
    else:
        tmp_len = 0
    if max_len < tmp_len:
        max_len = tmp_len

print(max_len)


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int n, m;

	cin >> n >> m;

	vector<bool>flag(100, false);

	for (int i = 0; i < n; i++) {
		int k;
		vector<bool>list(100, false);

		cin >> k;
		for (int j = 0; j < k; j++) {
			int num;
			cin >> num;
			if (i == 0) {
				flag[num] = true;
			}
			list[num] = true;
		}

		for (int j = 0; j <= m; j++) {
			if (list[j] == false || flag[j] == false) {
				flag[j] = false;
			}
		}
	}

	int cnt = 0;

	for (int i = 0; i <= m; i++) {
		if (flag[i] == true)cnt++;
	}


	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String input = scanner.next();
    scanner.close();

    StringBuilder builder = new StringBuilder();
    int input_length = input.length();
    for(int i=0; i<input_length; i++){
      if(input.charAt(i)=='P' || input.charAt(i)=='D'){
        builder.append(input.charAt(i));
      }
      if(input.charAt(i) == '?'){
        builder.append('D');
      }
    }
    System.out.println(builder.toString());
  }
}


Measured memory_bytes: 41360
N, M = map(int, input().split())
claim = []
for i in range(M):
	claim.append(list(map(int, input().split())))
claim.sort(key=lambda a:a[1])

ans = 0
inter = [-1,-1]
for land in claim:
    if inter[1] <= land[0]:
        inter = land
        ans += 1
print(ans)

Measured memory_bytes: 29076
cnt = 0
def merge(L,R):
    global cnt
    n = len(L)+len(R)
    lenL = len(L)
    A = []
    i = j = 0
    L.append(10**9+1)
    R.append(10**9+1)
    for _ in range(n):
        if L[i] <= R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
            cnt += lenL-i
    return A

def mergeSort(A):
    if len(A)==1: return A
    m = len(A)//2
    return merge(mergeSort(A[:m]),mergeSort(A[m:])) 

if __name__=='__main__':
    n = int(input()) 
    mergeSort(list(map(int,input().split())))
    print(cnt)

Measured memory_bytes: 30356
#include<iostream>
using namespace std;
int main(){
int k,s;cin >> k >> s;
int t = 0;

for(int i = 0; i <= k; i++){
    for(int j = 0; j <= k; j++){
        if(s - i - j >= 0 && s - i - j <= k){
            t++;
            }
        }
    }

cout << t << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define WORD_MAX 1000
#define WORD_LEN 32


int main(){
        char words[WORD_MAX][WORD_LEN];
        char buf[WORD_LEN];
        int i;
        int words_count[WORD_MAX] = {0};
        int max_len=0,word_num=0, max_length_num=0, max_frequency=0, frequency_num, flag;

        while(scanf("%s", buf) != EOF) {
                flag = 1;
                for(i=0; i<word_num; i++) {
                        if(strcmp(buf, words[i]) == 0) {
                                words_count[i]++;
                                flag=0;
                                break;
                        }
                }
                if(flag) {
                        strcpy(words[i], buf);
                        words_count[i]++;
                        word_num++;
                }
        }

        for(i=0; i<word_num; i++) {
                if(max_len < strlen(words[i])) {
                        max_len = strlen(words[i]);
                        max_length_num = i;
                }
        }

        for(i=0; i<word_num; i++) {
                if(max_frequency < words_count[i]) {
                        frequency_num = i;
                        max_frequency = words_count[i];
                }
        }

        printf("%s %s\n", words[frequency_num], words[max_length_num]);

        return 0;
}

Measured memory_bytes: 572
num1, num2, num3 = map(int, input().split())
count = int(input())

max_num = max(num1, max(num2, num3))

sum_num = num1 + num2 + num3 - max_num
end_num = max_num
for i in range(count):
    end_num *= 2

print(sum_num + end_num)

Measured memory_bytes: 9020
#include<cstdio>
#define mo 1000000007
int n,k,dp[2006][2006],sum[2006];
int main()
{
	scanf("%d%d",&n,&k);
	dp[0][n+1]=1;
	register int i,j;
	for(i=1;i<=n;i++)
	{
		sum[n+1]=dp[i-1][n+1];
		for(j=n;j>=1;j--) sum[j]=((sum[j+1]%mo)+(dp[i-1][j]%mo))%mo;
		for(j=1;j<=n-i+1;j++) dp[i][j]=sum[j];
	}
	int x=dp[k][1]-dp[k-1][1];
	if(x<0) x+=mo;
	for(i=1;i<=n-k-1;i++) x=(x<<1)%mo;
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 15232
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define PI 3.14159265359
#define rep(i,n) for(int i=0; i<n; ++i)
#define INF 1001001001
#define MAX_X 2002
#define MAX_Y 2002
typedef long long ll;
typedef pair<int, int> P;

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

    int c[10][10];
    rep(i, 10) rep(j, 10) cin >> c[i][j];
    rep(k, 10) rep(i, 10) rep(j, 10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    
    int ans = 0;
    rep(i,h) rep(j, w) {
        int a;
        cin >> a;
        if (a >= 0) {
            ans += c[a][1];
        }
    }

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

Measured memory_bytes: 256
m, n, k = map(int, input().split())
A, B = [], []
for _ in range(m):
    A.append(list(map(int, input().split())))
for _ in range(n):
    B.append(list(map(int, input().split())))

for index, row in enumerate(A):
    ans = []
    for i in range(k):
        col = [rowB[i] for rowB in B]
        ans.append(sum([x * y for x, y in zip(row, col)]))
    print(' '.join(map(str, ans)))


Measured memory_bytes: 6316
package main

import "fmt"

func main() {
	var a, b int
	for {
		fmt.Scanln(&a, &b)
		if a == 0 && b == 0 {
			break
		}
		switch {
		case a < b:
			fmt.Println(a, b)
		default:
			fmt.Println(b, a)
		}
	}
	return
}



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

using ll = long long;
using ld = long double;
using namespace std;

#define rep(i, n) for (i = 0; i < (ll)n; ++i)
#define all(x) begin(x), end(x)

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

  vector<ll> A(N);
  vector<ll> reached(N, 0);
  vector<ll> loop;
  ll i{0};
  rep(i, N) cin >> A[i];

  i = 0;
  while (K > 0)
  {
    if (reached[i] == 1)
    {
      // for_each(loop.begin(), loop.end(), [](const auto n){ cout <<n << "  "; });
      const ll loop_len{distance(find(loop.begin(), loop.end(), i+1), loop.end())};
      const vector<ll> myloop(find(loop.begin(), loop.end(), i+1), loop.end());
      // cout << "\nlooplen: " << loop_len <<"K: " << K << "  eu: "<< K%loop_len << endl;
      const ll ans{myloop[K%loop_len]};
      i = ans-1;
      break;
    }
    else
    {
      reached[i] = 1;
      loop.emplace_back(i+1);
      i = A[i] - 1;
      --K;
    }
  }

  cout << i+1 << endl;
  return 0;
}



Measured memory_bytes: 8496
#include<iostream>
#include<vector>
#include<string>

int main(){
    std::string S;
    std::cin >> S;
    int size = 3;
    int target = 753;
    int minDiff = 1000;
    for(int i = 0; i + size <= S.size(); i++){
        int num = std::stoi(S.substr(i, size));
        if(std::abs(num - target) < minDiff){
            minDiff = std::abs(num - target);
        }
    }
    std::cout << minDiff << std::endl;
    return 0;
}


Measured memory_bytes: 256
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2;
    cin >> a1 >> a2;
    cin >> b1 >> b2;
    if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2)
    {
        cout << "infinity";
        return 0;
    }
    if (t1 * a1 + t2 * a2 < t1 * b1 + t2 * b2)
    {
        swap(a1, b1);
        swap(a2, b2);
    }
    ll run = t1 * a1 + t2 * a2 - t1 * b1 - t2 * b2;
    ll peak = t1 * b1 - t1 * a1;
    if (peak < 0)
    {
        cout << 0;
        return 0;
    }
    cout << 2 * (peak / run) + (peak % run != 0);
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


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

int main()
{
  int A, B;
  cin >> A >> B;
  
  int T = A;
  int C = T;//計算用
  int c1, c2, c3, c4, c5;
  int D = 0;//条件を満たす値の数

  for(int i = 0; i < B - A + 1; i++)
  {
    for(int j = 0; j < 5; j++)
    {
      if(j == 0){c1 = C % 10;}
      else if(j == 1){c2 = C % 10;}
      else if(j == 2){c3 = C % 10;}
      else if(j == 3){c4 = C % 10;}
      else{c5 = C % 10;}
      C /= 10;
    }
    if(c1 == c5 && c2 == c4){D++;}
    T++;
    C = T;
  }
  cout << D << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

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

int N;
ll ans;

int main() {
  scanf("%d", &N);
  scanf("%lld", &ans);
  rep(i, 1, N) {
    ll t;
    scanf("%lld", &t);
    if (ans < t) swap(ans, t);
    ans /= gcd(ans, t);
    ans *= t;
  }
 
  printf("%lld\n", ans);

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {
    int N, M, i, lock;
    char U[300][11];
    char s[11];

    scanf("%d", &N);

    for (i = 0; i < N; i++) { scanf("%s", U[i]); }

    scanf("%d", &M);

    lock = 1;

    while (M--) {
        scanf("%s", s);
        for (i = 0; i < N; i++) {
            if (strcmp(s, U[i]) == 0 && lock) {
                printf("Opened by %s\n", s);
                lock = 0;
                break;
            }
            else if (strcmp(s, U[i]) == 0 && !lock) {
                printf("Closed by %s\n", s);
                lock = 1;
                break;
            }
            if (i == N-1) { printf("Unknown %s\n", s); }
        }
    }
    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
using namespace std;
 
int main()
{
 
    int n;
 
    while(true){
 
        int i[1000],p[1000],q[1000],r[1000];
 
        cin >> n;
        if(n==0)
            break;
 
        for(int j=0 ;j<n ;j++){
 
            cin >> i[j] >> p[j] >> q[j] >> r[j];
        }
        int P,Q,R,C;
        int sp=0,sq=0,sr=0;
        int cal[1000];
        int count=0;
 
        cin >> P >> Q >> R >> C;
 
        for(int j=0 ;j<n ;j++){
            sp = p[j]*4;
            sq = q[j]*9;
            sr = r[j]*4;
            cal[j] = sp + sq + sr;
 
            if(P >= p[j] && Q >= q[j] && R >= r[j] && C >= cal[j]){
                count++;
                cout << i[j] << endl;
            }
        }
        if(count == 0)
            cout << "NA" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1176
#include <iostream>
using namespace std;

int main (){
	int antena[5];
	int k;
	for(int i=0;i<5;i++){
		cin >> antena[i];
	}
	cin>> k;
	//bool hit_flag = false;
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			if(abs(antena[i]-antena[j]) >k){
				cout << ":(" << endl;
				return 0;
			}
		}
	}
	cout << "Yay!" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define eb emplace_back
#define vec vector

typedef long long ll;

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

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

template<class T> T gcd(T m, T n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}

template<class T> T lcm(T m, T n) {
  return m * n / gcd(m, n);
}

const ll inf = 1LL << 60;
const ll mod = 1e9 + 7;

using namespace std;

/* Input variables. */
int n, m;
vec<int> p;
vec<string> s;

/* Solve! */
void solve() {
  vec<int> ac(n, 0), wa(n, 0);
  int acc = 0, pc = 0;
  rep(i, m) {
    if (s[i] == "AC") {
      ac[p[i]]++;
      if (wa[p[i]] != -1) {
        pc += wa[p[i]];
        wa[p[i]] = -1;
      }
      if (ac[p[i]] == 1) acc++;
    } else if (s[i] == "WA") {
      if (wa[p[i]] != -1) wa[p[i]]++;
    }
  }

  cout << acc << " " << pc << endl;
}

int main() {
  /* Input handling. */
  cin >> n >> m;
  p = vec<int>(m);
  s = vec<string>(m);
  rep(i, m) {
    cin >> p[i] >> s[i];
    p[i]--;
  };

  solve();
  return 0;
}

Measured memory_bytes: 3840
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

signed main()
{
	int N;
	int s[100];

	cin >> N;
	int sum = 0;
	REP(i, N)
	{
		cin >> s[i];
		sum += s[i];
	}

	sort(s, s + N);

	if (sum % 10 == 0)
	{
		REP(i, N)
		{
			if (s[i] % 10 != 0)
			{
				cout << (sum - s[i]) << endl;
				return 0;
			}
		}
		cout << 0 << endl;
	}
	else
	{
		cout << sum << endl;
	}
}

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

using namespace std;

int main()
{
    vector<int> a(3);
    int k;
    cin >> a[0] >> a[1] >> a[2];
    cin >> k;
    
    int check;
    int amax=max({a[0],a[1],a[2]});
    for(int i=0;i<3;i++){
        if(amax==a[i]) check=i;
    }

    for(int i=0;i<k;i++) amax*=2;
    cout << a[0]+a[1]+a[2]-a[check]+amax << endl;
}

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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  int count=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='x') count++;
  }
  
  if(count>7) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

#define INF (1 << 30)
#define MAX_E 20000
#define MAX_V 1000

struct edge{
	int from;
	int to;
	int cost;
};

edge es[MAX_E];
int d[MAX_V];
int V, E;// V???????????°???E????????°

// O(VE)??§????????????????????????????????§??????

void shortest_path(int s){
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	for(int loop = 0; loop < 2; loop++){
		bool update = false;
		for(int i = 0; i < E; i++){
			edge e = es[i];
			if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
			if(d[e.to] != INF && d[e.from] > d[e.to] + e.cost){
				d[e.from] = d[e.to] + e.cost;
				update = true;
			}// ????????????????????§???????????????????????????
		}
		if(!update){
			break;
		}
	}
}

int main(){
	
	int N, M, v_a, v_b;
	
	while(true){
		
		cin >> N >> M;
		
		if(N == 0 && M == 0){
			break;
		}
		
		E = M;
		
		V = N + 1;
		
		for(int i = 0; i < M; i++){
			cin >> v_a >> v_b;
			es[i].from = v_a;
			es[i].to = v_b;
			es[i].cost = 1;
		}
		
		shortest_path(1);
		
		int ans = 0;
		
		for(int i = 1; i < N + 1; i++){
			if(d[i] == 1 || d[i] == 2){
				ans++;
			}
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 1260
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

const int INF = 1001001000;

int main(void) {
    int N, L;
    cin >> N >> L;

    int sum1 = L * N  + (N * (N + 1) / 2) - N;
    int min = INF;
    int ans;
    for (int i = 1; i <= N; i++) {
        int sum2 = sum1 - (L + i - 1);
        if (abs(sum1 - sum2) < min) {
            min = abs(sum1 - sum2);
            ans = sum2;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

//#define int long long int

int bottom(int a[], int n)
{
	int dp[n + 1] = {0};
	for (int i = 1; i < n; i++)
	{
		if (i >= 2)
			dp[i] = min((abs(a[i] - a[i - 1]) + dp[i - 1]), (abs(a[i] - a[i - 2]) + dp[i - 2]));
		else
			dp[i] = abs(a[i] - a[i - 1]) + dp[i - 1];
		//cout << dp[i] << " ";
	}
	return dp[n - 1];
}
int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << bottom(a, n);
}
// 4
// 10 30 40 20

Measured memory_bytes: 1024