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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

struct bnum { ll i; ll n; };

auto bgr = [](bnum x, bnum y) { return x.n<y.n; };

int main() {
  int N; cin >> N;
  ll A[N]; rep(i,N) cin >> A[i];
  ll B[N]; rep(i,N) cin >> B[i];
  priority_queue<bnum,vector<bnum>,decltype(bgr)> pb(bgr);
  rep(i,N) pb.push({i,B[i]});

  ll result = 0;
  while (pb.size()) {
    bnum now = pb.top(); pb.pop();
    int l = (now.i-1+N)%N, r = (now.i+1)%N;
    int count = (now.n-A[now.i]) / (B[l]+B[r]);
    if (count) {
      B[now.i] -= count * (B[l]+B[r]);
      result += count;
      if (B[now.i]!=A[now.i]) pb.push({now.i,B[now.i]});
    }
    else if (B[now.i]!=A[now.i]) { result = -1; break; }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 9328
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <ctime>
using namespace std;

const unsigned long long BASE = (unsigned long long)(1e9 + 7);

#define FROM_0(i, n) for(int i = 0; i < (n); i++)
#define FROM_S(i, s, e) for(int i = (s); i < (e); i++)
#define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter != vec.end(); iter++)

unsigned long long a[200001];
unsigned long long sum[200001];

int main()
{
    int n;
    cin >> n;
    FROM_0(i, n)
    {
        cin >> a[i];
    }
    sum[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--)
    {
        sum[i] = (sum[i + 1] + a[i]) % BASE;
    }
    unsigned long long result = 0;
    FROM_0(i, n - 1)
    {
        result = (result + a[i] * sum[i + 1]) % BASE;
    }
    cout << result % BASE << endl;
    return 0;
}


Measured memory_bytes: 6756
use std::fmt::Write;
use std::io::*;

fn main() {
  let input = {
    let mut buf = vec![];
    stdin().read_to_end(&mut buf);
    unsafe { String::from_utf8_unchecked(buf) }
  };
  let mut lines = input.split('\n');

  let (n, m) = {
    let line = lines.next().unwrap();
    let mut iter = line.split(' ').map(|s| s.parse().unwrap());

    (iter.next().unwrap(), iter.next().unwrap())
  };

  let mut vec = Vec::with_capacity(n);
  vec.extend(lines.take(n).map(|l| l.parse::<usize>().unwrap()));

  for k in 2..(m + 1) {
    for i in 0..(n - 1) {
      if vec[i] % k > vec[i + 1] % k {
        vec.swap(i, i + 1);
      }
    }
  }

  let mut result = String::with_capacity(n * 4);
  for a in vec { writeln!(result, "{}", a); }
  print!("{}", result);
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+10;
int a[maxn];
int cmp(const int a,const int b){
    return a>b;
}
int n,m,v,p;
int b[maxn];
bool judge(int mid){
    //printf("hello %lld\n",mid);
    if(mid<=p)return true;
    if(a[mid]+m<a[p])return false;
    if(v<=p-1&&a[mid]+m>=a[p])return true;
    int temp=0;
    for (int i=n,j=v-p;i>mid&&j;i--,j--){
        temp+=m;
    }
    temp+=m*p;
    int res=m*v-temp;
    int ww;
    for(int i=p;i<mid;i++){
        int add=min(m,max(a[mid]+m-a[i],0ll));
        if(add>res)add=res;
        res-=add;
        if(i==p){
            ww=a[p]+add;
        }
    }
    return a[mid]+m>=ww&&res<=0;
}
signed main(){
    cin>>n>>m>>v>>p;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1,cmp);
    int low=1,high=n;
    int ans=0;
    while(low<=high){
        int mid=(low+high)>>1;
        if(judge(mid)){
            low=mid+1;
            ans=mid;
        }
        else{
            high=mid-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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


int main(){
	char s;cin>>s;
  	if(s=='A')cout<<'T'<<endl;
  	else if(s=='T')cout<<'A'<<endl;
  	else if(s=='G')cout<<'C'<<endl;
  	else cout<<'G'<<endl;return 0;

}

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

constexpr int NOT_EXIST = -1;
typedef std::vector<int> digits;

int numeral(const digits& ds, const digits& xs) {
  int d = 1;
  int r = 0;
  for( int x : xs ) {
    if( x == NOT_EXIST ) return r;
    r += ds[x] * d;
    d *= 10;
  }
  return r;
}

void increment(const digits& ds, digits& xs) {
  for( auto& x: xs ) {
    const int last = x;
    const int nx = x + 1;
    x = nx % ds.size();
    if( last == -1 || x != 0 ) {
      return;
    }
  }
}

int main() {
  int n, k;
  std::cin >> n >> k;

  digits denied;
  for( size_t i = 0; i < k; ++i ) {
    int d;
    std::cin >> d;
    denied.push_back(d);
  }

  digits allows;
  for( int a = 0; a <= 9; ++a ) {
    if( std::find(denied.begin(), denied.end(), a) == denied.end() ) {
      allows.push_back(a);
    }
  }

  digits xs(6, NOT_EXIST);
  while( numeral(allows, xs) < n ) {
    increment(allows, xs);
  }

  std::cout << numeral(allows, xs) << std::endl;
}

Measured memory_bytes: 3124
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
MOD = 10 ** 9 + 7


a, b, c = MI()
if a + b == c or b + c == a or c + a == b:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
   
  while(cin>>n,n){
    int mp[101][101]={};
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++) cin>>mp[i][j];
 
    int flg[101][101]={};  
    for(int i=0;i<n;i++){
      int mnx=1e9,mxy=0;
      int xi,xj,yi,yj;
      for(int j=0;j<n;j++) {
    if(mnx>mp[i][j]) mnx=mp[i][j];
    if(mxy<mp[j][i]) mxy=mp[j][i];
      }
      for(int j=0;j<n;j++){
    if(mnx==mp[i][j])flg[i][j]++;
    if(mxy==mp[j][i])flg[j][i]++;
      }
    }
     
    int f=0,ans=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++) if(flg[i][j]==2)ans=mp[i][j],f++;
     
    if(f) cout << ans<<endl;
    else cout <<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 3168
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 *
 * @author rn-sshawish
 */
public class Main{

    public static void main(String[] args) throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());
        int count = 0;
        HashMap<String, Integer> blueCard = new HashMap<>();
        HashMap<String, Integer> redCard = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String key = input.readLine();
            blueCard.put(key, blueCard.getOrDefault(key, 0) + 1);
        }
        int m = Integer.parseInt(input.readLine());
        for (int i = 0; i < m; i++) {
            String key = input.readLine();
            redCard.put(key, redCard.getOrDefault(key, 0) + 1);
        }
        for (Map.Entry<String, Integer> entry : blueCard.entrySet()) {
            if (redCard.containsKey(entry.getKey()) && entry.getValue() > redCard.get(entry.getKey())) {
                count = Math.max(entry.getValue() - redCard.get(entry.getKey()), count);
            } else if (!redCard.containsKey(entry.getKey())) {
                count = Math.max(count, entry.getValue());
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21460
/* 
 * Author: pawanmsr
 */

/*
 * Run in Mac using the following command:
 * g++ -std=c++14 <cpp_filename>
 * A binary will be generated. Then run:
 * ./a.out
 */

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <fstream>
#include <cstring>
#include <unordered_map>
#include <climits>
// #include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>

// Global //
int n, p[200005];

// Functions //


// Main //
int main(int argc, char const *argv[])
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // // freopen("output.txt", "w", stdout);
    // #else
    // // online submission
    // #endif
    
    /* code */
    cin >> n;
    int mn = INT_MAX;
    
    int res = 0;
    for (int i=0; i<n; i++) {
        cin >> p[i];
        if (p[i] <= mn) {
            mn = p[i];
            res++;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    string s,t[3]={"KIH", "B", "R"};
    cin>>s;
    for(int i=0;i<16;i++){
        string u="";
        for(int j=0;j<4;j++){
            if(((i>>j)&1)==1){
                u+="A";
            }
            if(j<3){
                u+=t[j];
            }
        }
        //cout<<u<<endl;
        if(s==u){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    n, m = LI()
    if n == m:
        print("Yes")
    else:
        print("No")

    return


# B
def B():
    a, b = LI()
    if a <= b:
        ans = str(a) * b
    else:
        ans = str(b) * a
    print(ans)
    return


# C
def C():
    n = I()
    p = LI()
    n_min = n + 1
    ans = 0
    for num in p:
        if num < n_min:
            ans += 1
            n_min = num
    print(ans)
    return


# D
def D():
    n = I()
    cnt = [[0] * 10 for i in range(10)]
    ans = 0
    for i in range(1, n + 1):
        h = str(i)[0]
        t = str(i)[-1]
        cnt[int(h)][int(t)] += 1
    for i in range(1, 10):
        for j in range(1, 10):
            ans += cnt[i][j] * cnt[j][i]
    print(ans)
    return


# E
def E():
    return


# F
def F():
    return


# Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 40684
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222




int main(void) {


  cin >> n;
  rep(i, n) {
    cin >> tmp;
    ma = max(ma, tmp);
    ans += tmp;
  }
  ans -= ma / 2;
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
 
using namespace std;
#define rep(i,a,b) for (ll i = a; i < b; i++)
#define rrep(i,a,b) for (ll i = a; i >= b; i--)
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
 
using namespace std;
#define rep(i,a,b) for (ll i = a; i < b; i++)
#define rrep(i,a,b) for (ll i = a; i >= b; i--)
#define l(s) s.length()
#define sort(v) sort(v.begin(), v.end());
#define scan(v,n) rep(i,0,n) {ll k; cin >> k; v.pb(k);}
#define print(v,n) {rep(i,0,n) cout << v[i] << " "; cout << endl;}
#define printstr(s,n) {rep(i,0,n) cout << s[i]; cout << endl;}
#define rev(a) reverse(a.begin(), a.end());
#define pb push_back
typedef long long ll;
typedef long double lld;
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
 
const ll mxN=1e5+1;
const ll N=1e9+7;
 
ll dp[mxN][3], a[mxN][3];
 
  int main() {
      int T=1;// cin >> T;
      while(T--){
          ll n; cin >> n;
          rep(i,0,n) cin >> a[i][0] >> a[i][1] >> a[i][2];
          rep(i,0,3) dp[0][i]=a[0][i];
          rep(i,1,n) {
              rep(j,0,3) {
                  dp[i][j]=a[i][j]+(dp[i-1][(j+1)%3]>dp[i-1][(j+2)%3]?dp[i-1][(j+1)%3]:dp[i-1][(j+2)%3]);
              }
          }
          ll ans=dp[n-1][0];
          if(ans<dp[n-1][1]) ans=dp[n-1][1];
          if(ans<dp[n-1][2]) ans=dp[n-1][2];
          cout << ans;
          
      } 
      
	 return 0;
}


Measured memory_bytes: 8252
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main() {

	int a, b;
	cin >> a >> b;

	int ans;
	ans = (a - 1)*(b - 1);


	cout << ans << endl;



	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
#ifdef LOCAL
    freopen("in1.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif

    
    int n;
    cin>>n;
    if(n>=400 and n<=599){
        cout<<8;
    }else if(n>=600 and n<= 799){
        cout<<7;
    }else if(n>=800 and n<=999){
        cout<<6;
    }else if(n>=1000 and n<=1199){
        cout<<5;
    } else if(n>=1200 and n<=1399){
        cout<<4;
    }else if(n>=1400 and n<= 1599){
        cout<<3;
    }else if(n>=1600 and n<= 1799){
        cout<<2;
    }else cout<<1;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<30;
const ll LLINF = 1LL<<62;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;
  cin >> n >> k;
  if (k%2==1){
      cout << (ll) pow((n/k),3) << endl;
  }else{
      cout << (ll) pow(((n+(k/2))/k),3) + (ll) pow((n/k),3) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        "\n"
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;


int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
ll n,m;
cin>>n>>m;
ll sum=0;
int arr[2*100000];
rep(i,0,m)
{
cin>>arr[i];
sum+=arr[i];
}
ll ans=n-sum;
if(n-sum<0)
ans=-1;
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;


int main() {  
  ll n, H; cin >> n >> H;
  Vl a(n), b(n);
  ll a_ma = 0;
  ll b_su = 0;
  rep(i, 0, n){
    cin >> a[i] >> b[i];
    a_ma = max(a_ma, a[i]);
  }
  ll cnt_b = 0;
  ll b_ma = 0;
  rep(i, 0, n){
    if(b[i] > a_ma){
      b_ma += b[i];
      cnt_b++;
    }
  }
  ll h = H - b_ma;
  if(h < 0){
    sort(ALL(b), greater<ll>());
    ll cnt = 0;
    int i = 0;
    while(H > 0){
      H -= b[i];
      cnt++;
      i++;
    }
    cout << cnt << endl;
    return 0;
  } else {
    ll cnt = cnt_b;
    cnt += h/a_ma;
    if(h%a_ma != 0) cnt++;
    cout << cnt << endl;
    return 0;
  }
  

  return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int z;
  z = a;
  int count = 0;
  while (z <= b) {
    int zin = z;
    int k1 = zin / 10000;
    int zin1 = zin % 10000;
    int k2 = zin1 / 1000;
    int zin2 = zin1 % 1000;
    int k3 = zin2 / 100;
    int zin3 = zin2 % 100;
    int k4 = zin3 / 10;
    int zin4 = zin3 % 10;
    int k5 = zin4;
    if (k1 == k5) { 
      if (k2 == k4) {
        count++;
      }
    }
  z++;
  }
  cout << count << endl; 
}


Measured memory_bytes: 3540
#![allow(unused_imports)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}
impl<T: Iterator> IteratorExt for T {}

fn main() {
    let (_n,k) = read!(usize, usize);
    let mut p = read!([usize]);

    p.sort();
   let ans: usize = (p[0..k]).iter().sum();
   println!("{}", ans);
}



Measured memory_bytes: 2140
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<double> p(N);

    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }

    vector<vector<double>> dp(N, vector<double>(N + 1, 0));
    dp[0][0] = 1 - p[0];
    dp[0][1] = p[0];

    for (int i = 1; i < N; i++) {
        for (int j = 0; j < i + 2; j++) {
            if (j > 0 && j < i + 1) {
                dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
            } else if (j == 0) {
                dp[i][j] = dp[i - 1][j] * (1 - p[i]);
            } else if (j == i + 1) {
                dp[i][j] = dp[i - 1][j - 1] * p[i];
            }
        }
    }

    double ans = 0.0;
    for (int j = N / 2 + 1; j < N + 1; j++) {
        ans += dp[N - 1][j];
    }

    cout << fixed;
    cout << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<long long,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<"\n";
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
#define EPS 1e-18
ll seg[1200005]={0};
void update(ll s,ll e,ll qs,ll qe,ll idx,ll k){
    if(s == e && s == qs){
        seg[idx] = k;
        return;
    }
    if(qs > e || qe < s){
        return;
    }
    ll mid = (s+e)/2;
    update(s,mid,qs,qe,idx*2,k);
    update(mid+1,e,qs,qe,idx*2+1,k);
    seg[idx] = max(seg[idx*2],seg[idx*2+1]);
}
ll query(ll s,ll e,ll qs,ll qe,ll idx){
    if(qs <= s && e <= qe){
        return seg[idx];
    }
    if(qs > e || qe < s){
        return 0;
    }
    ll mid = (s+e)/2;
    ll a = query(s,mid,qs,qe,idx*2);
    ll b = query(mid+1,e,qs,qe,idx*2+1);
    return max(a,b);
}
int main(void){
    fastio;
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    arrin(arr,n);
    f(i,0,n){
        arr[i]++;
    }
    ll dp[n];
    ll ans = 0;
    ll n2 = 300001;
    rf(i,n-1,0){
        dp[i] = 1 + query(1,n2,max(1LL,arr[i]-k),min(n2,arr[i]+k),1);
        update(1,n2,arr[i],arr[i],1,dp[i]);
        ans = max(ans,dp[i]);
    }
    pl(ans);
}




Measured memory_bytes: 16444
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
ll n,a[111111];
vector<int> v[111111];

ll dfs(int x,int p) {
  ll cnt=0;
  bool f=0;
  rep(i,v[x].size()) {
    int y=v[x][i];
    if(y==p) continue;
    f=1;
    ll d=dfs(y,x);
    if(d>a[x]) return MAX;
    cnt+=d;
  }
  if(f) {
    if(a[x]>cnt||cnt>a[x]*2) return MAX;
    a[x]-=cnt-a[x];
  }
  return a[x];
}

void Main() {
  cin >> n;
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<n-1; i++) {
    int x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
  }
  if(n==2) {
    if(a[0]==a[1]) pr("YES");
    else pr("NO");
    return;
  }
  rep(i,n) {
    if(v[i].size()==1) continue;
    if(!dfs(i,-1)) pr("YES");
    else pr("NO");
    return;
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main()
{
    string s, t;
    cin >> s >> t;
    
    vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));
    // dp[i][j]: sのi文字目とtのj文字目のLCS
    // dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]) (s[i+1] != t[j+1])
    // dp[i+1][j+1] = dp[i][j] + 1 (s[i+1] == t[j+1])
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (s[i] != t[j]) {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            } else {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }
        }
    }

    string ans;
    int i = s.size();
    int j = t.size();
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i - 1][j]) {
            i--;
        } else if (dp[i][j] == dp[i][j - 1]) {
            j--;
        } else {
            assert(dp[i][j] == dp[i - 1][j - 1] + 1);
            i--;
            j--;
            ans += s[i];
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35584
import java.util.Scanner;

public class Main {
    
    private static final String[] HITACHI_KAMI = {
            "hi",
            "hihi",
            "hihihi",
            "hihihihi",
            "hihihihihi"
    };

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();
        
        System.out.println(isHitachi(s) ? "Yes" : "No");
        
    }

    private static boolean isHitachi(String s) {
        for(String nissei : HITACHI_KAMI) {
            if(nissei.equals(s)) {
                return true;
            }
        }
        return false;
    }

}


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

int main(void){
  int H,W;
  char s;
  cin >> H >> W;
  int vec[55][55]={-1};
  int mine[55][55]={};
  int dx[8]={1,1,0,-1,-1,-1,0,1};
  int dy[8]={0,1,1,1,0,-1,-1,-1};
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin >> s;
      if(s=='#'){
        vec[i][j]=1;
        mine[i][j]=1;
      }
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(vec[i][j]==1) cout << '#';
      else if(vec[i][j]==0){
        for(int d=0;d<8;d++){
          if(vec[i+dx[d]][j+dy[d]]==1) mine[i][j]++;
        }
        cout << mine[i][j];
      }
    }
    cout << endl;
  }
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3624
import java.util.*;
import java.util.HashSet;
import java.util.Set;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        String[]s=new String[N];
        for(int i=0;i<N;i++){
            s[i]=sc.next();
        }
        int M=sc.nextInt();
        String[]t=new String[M];
        for(int i=0;i<M;i++){
            t[i]=sc.next();
        }
        int max=0;
        for(int i=0;i<N;i++){
            int a=0;
            for(int j=i;j<N;j++){
                if(s[i].equals(s[j])){
                    a++;
                }
            }
            for(int j=0;j<M;j++){
                if(s[i].equals(t[j])){
                    a--;
                }
            }
            if(a-1>=max){
                max=a;
            }
        }
        System.out.println(max);
       
        
    }}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define sz(A) int(A.size())
#define FIFO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(A) begin(A),end(A)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<pair<int,int>> vii;
int f(int x) {
	int total = 0;
	int res;
	for(int i = 1; i <= x; i++) {
		total += i;
		if(total <= x)res = i;
		else break;
	}
	return res;
}
int main() {
	vi expo;
	ll N;
	cin >> N;
	for(ll i = 2; i * i <= N; i++) {
		if(N % i != 0) continue;
		int fact = 0;
		while(N % i == 0) {
			fact++;
			N /= i;
		}
		expo.pb(fact);
	}
	if(N != 1) expo.pb(1);
	int res = 0;
	for(auto e : expo) {
	//	cout << e << "\n";
		res += f(e);
	}
	cout << res << "\n";
	
	return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
string a;
cin>>a;
    int n=a.size();int sum=0;
    for(int i=0;i<n;i++){
        sum=sum+(a[i]-'0');
    }
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3764
const swap = (x, y) => {
  if (x < y) {
    tmp = x;
    x = y;
    y = tmp;
  }
  return [x, y];
};

const gcd = (x, y) => {
  [x, y] = swap(x, y);
  if (x % y === 0) {
    console.log(y);
    return y;
  } else {
    return gcd(y, x % y);
  }
};

process.stdin.resume();
process.stdin.setEncoding("utf8");
let input_string = "";

process.stdin.on("data", chunk => {
  input_string += chunk;
});

process.stdin.on("end", () => {
  const lines = input_string.split("\n");
  const input = lines[0].split(" ");
  gcd(input[0], input[1]);
});



Measured memory_bytes: 17364
#include<iostream>
using namespace std;
int main(){
    int h1,h2,k1,k2,a,b,c,d;
    cin >>h1 >> h2 >> k1 >> k2 >> a >> b >>c >>d;
    int sumh = h1*a+h2*b+h1/10 * c+h2/20*d,sumk = k1*a+k2*b+k1/10 * c+k2/20*d;
    if(sumh > sumk) cout << "hiroshi"<<endl;
    else if(sumh < sumk) cout << "kenjiro" <<endl;
    else cout << "even"<<endl;
}


Measured memory_bytes: 3104
x = gets.split.map(&:to_i)
k = gets.to_i
k.times{|ki|
  [0,1,2].repeated_permutation(ki+1).to_a.each{|pat|
    y = []
    y[0] = x[0]
    y[1] = x[1]
    y[2] = x[2]
    pat.each{|pati|
      y[pati]*=2
    }
    if y[2] > y[1] && y[1] > y[0]
      puts "Yes"
      exit
    end
  }
}
puts "No"


Measured memory_bytes: 14356
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
P = iil()
P_sorted = sorted(P)

indexes = []
count = 0

for i in range(n):
    if P[i] != P_sorted[i]:
        indexes.append(i)
        count += 1

if count == 0:
    print('YES')
elif count != 2:
    print('NO')
else:
    tmp = P[indexes[0]]
    P[indexes[0]] = P[indexes[1]]
    P[indexes[1]] = tmp
#    for j in range(n):
        #if P[j] != P_sorted[j]:
    if P != P_sorted:
        print('NO')
        exit()
    print('YES')

Measured memory_bytes: 3064
N = int(input())
rps = [tuple(map(int,input().split())) for _ in range(N)]
bps = [tuple(map(int,input().split())) for _ in range(N)]

bps.sort()
rps.sort(key=lambda x:x[1],reverse=True)

count = 0
for bp in bps:
    for i,rp in enumerate(rps):
        if rp[0] < bp[0] and rp[1] < bp[1]:
            count += 1
            rps.pop(i)
            break

print(count)


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

int main() {
  char c;
  cin >> c;
  if(c == 'a' || c == 'e' || c == 'o'||c == 'u' || c == 'i')
    cout << "vowel" << endl;
  else 
    cout << "consonant"<<endl;
  
   
  

  
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll r;
    cin >> r;
    if(r < 1200){
        cout << "ABC" << endl;
    }else if(r < 2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }
}

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

int main(){
	int N;
	cin >> N;
	int a[N+1];
	rep(i,N) cin >> a[i+1];
	int ans = 0;
	int now = 1;
	while (ans<N) {
		ans++;
		now = a[now];
		if (now == 2) {
			cout << ans << endl;
			return 0;
		}	
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 4004
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,(n))
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int N, M;
	cin >> N >> M;
	vvl A(N, vl(2));
	REP(i, N) {
		REP(j, 2) {
			cin >> A[i][j];
		}
	}

	sort(ALL(A));
	ll ans = 0;
	REP(i, N) {
		if (M <= A[i][1]) {
			ans += M * A[i][0];
			break;
		}
		else {
			ans += A[i][0] * A[i][1];
			M -= A[i][1];
		}
	}

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

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;


int main(){
  string s;cin>>s;
  if(s[5]=='1') cout<<"TBD"<<endl;
  else if(s[6]>'4') cout<<"TBD"<<endl;
  else if(s[6]<='4') cout<<"Heisei"<<endl;
  

  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << (#x) << " = " << (x) << endl;
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<double, double> dd;
typedef pair<float, float> ff;
const int Hmax = 1001;
const int Wmax = 1001;
const int MOD = 1000000007;
int h, w;
int f[Hmax][Wmax];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	scanf("%d %d", &h, &w);
	char c;
	f[0][1] = 1;
	REP1(i, h) {
		REP1(j, w) {
			scanf(" %c", &c);
			if (c == '.') f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD;
		}
	}
	cout << f[h][w];
	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, a[100005] = {}, b = 0;
    cin >> n;
    fr1(n) cin >> a[i];
    fr1(n - 1) {
        if (a[i] == i) swap(a[i], a[i + 1]), b++;
    }
    if (a[n] == n) b++;
    cout << b;
}


Measured memory_bytes: 640
from collections import defaultdict


def factorize(N):
    p = 2
    PRIME = defaultdict(int)
    while p * p <= N:
        if N % p == 0:
            N //= p
            PRIME[p] += 1
        else:
            p += 1
    if N > 1:
        PRIME[N] += 1
    return PRIME


n, p = map(int, input().split())

prime = factorize(p)
ans = 1
for j in prime:
    if prime[j] >= n:
        ans *= j**(prime[j]//n)
print(ans)


Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double

int ans=0,c=0;

int32_t main()
{
	IOS
	int n,k;cin>>n>>k;
	vector<int>H(n+200),dp(n+200,1e15);
	for(int i=1;i<=n;i++)cin>>H[i];
	dp[1]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
			dp[j]=min(dp[j],dp[i]+abs(H[i]-H[j]));
		}
	}
	cout<<dp[n]<<endl;
		
}
			
	
	
	
	
	

	

	

	
		


Measured memory_bytes: 1792
#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 <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

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

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    rep(i, B) {
        if (A * (i + 1) % B == C) { cout << "YES" << endl; goto xyz; }
    }
    cout << "NO" << endl;
xyz:;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

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

  int n, m;
  cin >> n >> m;

  vector<pair<bool, int>> problems(n, make_pair(false, 0));

  rep(i,m) {
    int p;
    string s;
    cin >> p >> s;

    if (s == "AC") problems[p-1].fi = true;
    if (s == "WA" && !problems[p-1].fi) problems[p-1].se++;
  }

  int ac_cnt = 0, pena_cnt = 0;
  rep(i,n) {
    if (problems[i].fi) ac_cnt++, pena_cnt += problems[i].se;
  }

  cout << ac_cnt << " " << pena_cnt << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[200010],b[200010]={},ans=0;
    cin>>n;
    rep(i,n) cin>>a[i];
    map<ll,ll>mp;
    rep(i,n){
        b[i+1]=b[i]+a[i];
    }
    rep(i,n+1){
        mp[b[i]]++;
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        ans+=(itr->second)*(itr->second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15872
object Main extends App {
  val in: List[List[Int]] = io.Source.stdin.getLines.map(_.split(" ").toList.map(_.toInt)).toList
  val src: List[List[Int]] = in.filter(in.indexOf(_) % 2 != 0)

  def myLinearSearch(li: List[Int], n: Int): Option[Int] = li match {
    case Nil => None
    case h :: tail => if (h == n) Some(h) else myLinearSearch(tail, n)
  }

  println((for (n <- src(1)) yield myLinearSearch(src(0), n)).filter(_ != None).length)

}

Measured memory_bytes: 47612
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>


int c[1000];
int d[1000];

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

  int n;
  cin>>n;
  
  FOR(i,1,n+1){
    int m=i;
    int j=2;
    while(m!=1){
      while(m%j==0){
        c[j]++;
        m/=j;
      }
      j++;
    }
  }

  rep(i,100){
    d[c[i]]++;
  }
  /*
  rep(i,10){
    cout<<c[i]<<endl;
  }
  */

  rrep(i,100){
    d[i]+=d[i+1];
  }

  /*
  rep(i,10){
    cout<<d[i]<<endl;
  }
  */
  

  int ans=0;
  ans+=d[74];
  ans+=d[24]*(d[2]-1);
  ans+=d[4]*(d[4]-1)/2*(d[2]-2);
  ans+=d[14]*(d[4]-1);

  cout<<ans<<endl;

}

Measured memory_bytes: 256
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


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

    int p;
    string s;

    vector<int> ac(n, 0);
    vector<int> wa(n, 0);
    for (int i=0; i<m; i++) {
        cin >> p >> s; p--;
        if (s == "AC") ac[p]++;
        if (s == "WA" and !ac[p]) wa[p]++;
    }

    int n_ac = 0;
    int n_wa = 0;

    for (int i=0; i<n; i++) {
        if (ac[i] > 0) n_ac++;
        if (wa[i] > 0 and ac[i] > 0) n_wa += wa[i];
    }

    cout << n_ac << " " << n_wa << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int N;
    int count = 0;
    int a;
    cin >> N;
    for (int c=1;c<N;c++){
        for(a=1;a*a<N-c;a++){
            if((N-c)%a==0){
                count+=2;
            }
        }
        if(a*a==N-c){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define ld long double 
#define vl vector
#define pb push_back
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t;
    cin>>n;
    cout<<n*n*n;
}

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

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

  priority_queue<int> que;
  rep(i,n) {
    int a; cin >> a;
    que.push(a);
  }

  while(m--) {
    int v = que.top();
    que.pop();
    v/=2;
    que.push(v);
  }

  int ans = 0;
  while(!que.empty()) {
    int v = que.top();
    que.pop();
    ans += v;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 4320
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	
	cout << a[n-1] - a[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int n;
  int a[110];
  int b[110];
  string s;
  while(cin >> n, n) {
    cin >> s;
    for(int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }

    for(int i = n-1; i >= 0; i--) {
      int x = b[i]-a[i];
      int p = a[i]-1, q = b[i]-1;
      swap(s[p], s[q]);
      
      s[p] = (s[p]-'a'+x)%26 + 'a';
      s[q] = (s[q]-'a'+x)%26 + 'a';
    }
  cout << s << endl;
  }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
int a[100001],b[100001];
int main()
{
	int n;
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i];
	for (int i=1;i<=n;i++)  b[a[i]]=i;
	for (int i=1;i<=n;i++)  cout<<b[i]<<' ';
	cout<<endl;
	return 0;
}


Measured memory_bytes: 1536
N,M = map(int,input().split())
maxa = [0] * (N+1)

for i in range(M):
    a,b = map(int,input().split())
    if maxa[b] < a:
        maxa[b] = a 

ok = 0
count = 0

for j in range(1,N+1):
    if ok < maxa[j]:
        count += 1
        ok = j-1

print(count)

Measured memory_bytes: 5984
// ------------------------------------
// Date:2018/ 3/25
// Problem:C - Together b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

static const int MOD = 1e9 + 7;
static const int MAX_N = 1e5 + 101;

int N;

ll cnt[MAX_N];

int main()
{
  fill_n(cnt, MAX_N, 0);
  scanf("%d", &N);
  vector< int > a(N);
  REP(i, N) {
    scanf("%d", &a[i]);
    if (a[i] > 0) cnt[a[i] - 1]++;
    cnt[a[i]]++;
    cnt[a[i] + 1]++;
  }

  ll ans = -1ll;
  REP(i, MAX_N) {
    ans = max(ans, cnt[i]);
  }

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



Measured memory_bytes: 1408