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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  i64 n;
  cin >> n;
  vi64 v(5);
  cin >> v;
  sort(all(v));
  i64 mi = v[0];
  i64 ans = (n + mi - 1) / mi + 4;
  cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc129/tasks/abc129_c
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const MOD: i64 = 1e9 as i64 + 7;

fn main() {
    input! {
        n: usize, m: usize,
        a: [usize; m]
    };

    let mut broken = vec![false; n+1];
    for ai in a {
        broken[ai] = true;
    }
    let mut dp = vec![0; n+1];
    dp[0] = 1;
    for i in 1..n+1 {
        if broken[i] {
            continue;
        }
        dp[i] = ifv!(i >= 1, dp[i-1], 0) + ifv!(i >= 2, dp[i-2], 0);
        dp[i] %= MOD;
    }

    println!("{}", dp[n]);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll len(ll x){
  ll a=1,k=0,j=1;
  while(a*10<=x) k+=9*a*j,a*=10,j++;
  k+=(x-a+1)*j;
  return k;
}
int main(){
  ll n,k;
  while(cin>>n>>k,n||k){
    ll l=0,r=1000000000LL,m,i,j;
    string s;
    while(l+1<r){
      m=(l+r)/2;
      if(len(m)<n) l=m;
      else r=m;
    }
    for(i=1;s.size()<1000;i++) s+=to_string(l+i);
    for(i=0;i<k;i++) cout << s[n-len(l)-1+i];
    cout << endl;      
  }
  return 0;
}

Measured memory_bytes: 3220
//Solution for aoj 0519:Worst Sportswriter
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
using namespace std;
const int MAX_N = 5000, MAX_M = 100000;
int n, m, ran, jud;
vector<int> g[MAX_N + 1], s;
int save[MAX_N + 1], ans[MAX_N + 1];
bool save2[MAX_N + 1];
bool find(int f, int t){
	for (int i = 0; i < g[f].size(); i++){
		if (g[f][i] == t)
			return true;
	}
	return false;
}
void dfs(int now){
	for (int i = 0; i < g[now].size(); i++){
		if (!save2[g[now][i]]){
			dfs(g[now][i]);
		}
	}
	ans[ran] = now;
	if (jud == 0 && ran != n && find(ans[ran], ans[ran + 1]) == false){
		jud = 1;
	}
	ran--;
	save2[now] = 1;
}
int main(){
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int winner, looser;
		cin >> winner >> looser;
		g[winner].push_back(looser);
		save[looser]++;
	}
	for (int i = 1; i <= n; i++){
		if (save[i] == 0){
			s.push_back(i);
		}
	}
	ran = n;
	for (int i = 0; i < s.size();i++)
		dfs(s[i]);
	for (int i = 1; i <= n; i++)
		cout << ans[i] << endl;
	cout << jud << endl;
	return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n, a, b, c, d;
	int xnum = 0, ynum = 0;
	cin >> n >> a >> b >> c >> d;
	if (n%a) xnum = (n / a) + 1;
	else xnum = n / a;
	if (n%c) ynum = (n / c) + 1;
	else ynum = n / c;
	cout << min(xnum*b, ynum*d) << endl;
}



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

using namespace std;

int main(void)
{
    string N;

    cin >> N;

    vector<int> children;

    for (int i = 0; i < N.size(); i++)
    {
        children.push_back(0);
    }

    char mode = 'R';
    int stuck = 1;
    int top = 0;
    int dist = 0;

    for (int i = 1; i < N.size(); i++)
    {
        if (mode != N.at(i))
        {
            if (mode == 'R')
            {
                stuck++;
                mode = 'L';
                top = i;
                children.at(top) += stuck / 2 + stuck %2;
                children.at(top - 1) += stuck / 2;
                stuck = 0;

                continue;
            }
            if (mode == 'L')
            {
                stuck++;
                mode = 'R';
                dist = 0;
            }
        }
        else
        {
            if (mode == 'R')
            {
                stuck++;
            }
            if (mode == 'L')
            {
                dist++;
                if (dist % 2 == 0)
                {
                    children.at(top)++;
                }
                else
                {
                    children.at(top-1)++;
                }
            }
        }
    }

    for (int i = 0; i < N.size() - 1; i++)
    {
        cout << children.at(i);
        cout << " ";
    }

    cout << children.at(N.size() - 1) << endl;

    return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w,k;cin>>h>>w>>k;
    vector<string> c(h);
    rep(i,h)cin>>c[i];
    int ans = 0;
    rep(i,1<<h)rep(j,1<<w){
        int num = 0;
        rep(y,h)rep(x,w){
            if(((i>>y)&1)==0&&((j>>x)&1)==0&&c[y][x]=='#'){
                num++;
            }
        }
        if(num==k)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <set>
#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;
}

int solve(const vector<pair<int, int>> &sc, const int N, const int M) {
    int start, end;
    if (N == 1) {
        start = 0;
        end = 10;
    } else if (N == 2) {
        start = 10;
        end = 100;
    } else {
        start = 100;
        end = 1000;
    }

    set<int> conds[3];
    for (auto &p : sc) {
        conds[p.first].insert(p.second);
    }

    for (int i = 0; i < N; i++) {
        if ((int) conds[i].size() > 1) {
            return -1;
        }
    }

    if (N >= 2 && ((int) conds[0].size() > 0) && (*conds[0].begin()) == 0) {
        return -1;
    }

    for (int cand = start; cand < end; cand++) {
        bool ok = true;
        int v = cand;
        for (int i = N - 1; i >= 0; i--) {
            int digit = v % 10;
            if ((int) conds[i].size() > 0) {
                int expected = *conds[i].begin(); // size must be one
                if (digit != expected) {
                    ok = false;
                    break;
                }
            }
            v /= 10;
        }
        if (ok) {
            return cand;
        }
    }

    return -1;
}

// based on solution 1 in pdf.
// ref. https://img.atcoder.jp/abc157/editorial.pdf
int main(void) {
    int N, M;
    cin >> N >> M;
    
    vector<pair<int, int>> sc(M);
    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        s--;
        sc[i] = {s, c};
    }

    cout << solve(sc, N, M) << endl;
    
    return 0;
}


Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
s = input()

if "##" in s[a-1:c] :
    print("No")
elif "##" in s[b-1:d] :
    print("No")
elif d < c :
    if "..." in s[b-2:d+1] :
        print("Yes")
    else :
        print("No")
else :
    print("Yes")

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

using namespace std;

int main(void)
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    vector<double> e(n);
    double c = 0, s = 0;

    for (int i = 0; i < n; i++) {
        cin >> p[i];
        e[i] = (double)(1 + p[i]) / 2;
    }
    for (int i = 0; i < k; i++) s += e[i];
    c = s;

    for (int i = 0; i < n - k; i++) {
        c = c + e[i + k] - e[i];
        if (s < c) s = c;
    }

    cout << fixed << setprecision(12) << s << endl;
  
    return 0;
}


Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int D = Integer.parseInt(strArr[1]);

		int ans = N / (2 * D + 1);
		if (N % (2 * D + 1) != 0)
			ans++;
		System.out.println(ans);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int main() {
	int n = 0;
	int c[500] = {}, s[500] = {}, f[500] = {};
	int ans = 0, tmp = 0;

	cin >> n;
	rep(i, n - 1) {
		cin >> c[i] >> s[i] >> f[i];
	}

	rep(i, n) {

		ans = s[i];

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

			if (ans < s[j]) {
				ans = s[j];
			}
			else {
				tmp = (ans - s[j]) / f[j];
				if ((ans - s[j]) % f[j] != 0) {
					ans = (tmp + 1) * f[j] + s[j];
				}
			}

			ans += c[j];

		}

		cout << ans << endl;
	}

	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N,K,ans=0;
  cin>>N>>K;
  int X[N];
  for(int i=0;i<N;i++){
  cin>>X[i];
  }
 sort(X,X+N);
  for(int j=0;j<K;j++){
    ans +=X[j];}
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  vector<int> a={4,6,9,11};
  int x,y;
  cin >> x >> y;
  if(x==2 || y==2){
    cout << "No";
    return 0;
  }else{
    int j=0;
    for(int i=0; i<4; i++){
      if(x==a[i] || y==a[i]) j++;
    }
    if(j%2==0){
      cout << "Yes";
    }else{
      cout << "No";
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;;
    cin >> N;
    vector<string> S(N);
    map<string,int> data;
    
    for (int i=0;i<N;i++) {
        cin >> S[i];
        data[S[i]] = i;
    }
    
    cout << data.size() << endl;
}


Measured memory_bytes: 25060
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,n;
    cin >> h >> n;
    ll sum = 0;
    rep(i,n){
        ll x;
        cin>>x;
        sum += x;
    }
    if(sum>=h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
s = input()
t = input()

dp = [[0 for i in range(len(t) + 1)] for j in range(len(s) + 1)]

for i in range(1, len(s) + 1):
    for j in range(1, len(t) + 1):
        if s[i - 1] == t[j - 1]:
            dp[i][j] = dp[i - 1][j - 1] + 1
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])

ans = ''

ls = len(s)
lt = len(t)

while ls != 0 and lt != 0:
    if s[ls - 1] == t[lt - 1]:
        ans += s[ls - 1]
        ls -= 1
        lt -= 1
    
    elif dp[ls][lt - 1] > dp[ls - 1][lt]:
        lt -= 1
    
    else:
        ls -= 1

print(ans[::-1])


Measured memory_bytes: 119900
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int R = scanner.nextInt();
    int score = 0;
    if(N >= 10){
      score = R;
    }else{
      score = R + (100 * (10-N));
    }
    System.out.println(score);
  }
}

Measured memory_bytes: 22868
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        

        if ((A==1)&&(B==2)){
            System.out.println(3);

        }

        if ((A==2)&&(B==3)){
            System.out.println(1);

        }

        if ((A==3)&&(B==2)){
            System.out.println(1);

        }

        if ((A==3)&&(B==1)){
            System.out.println(2);

        }

        if ((A==2)&&(B==1)){
            System.out.println(3);

        }

        if ((A==1)&&(B==3)){
            System.out.println(2);

        }




    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;

int main(){
	map<int,int> m1;
	int n,tmp,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
	scanf("%d",&tmp);
	m1[tmp]++;
	}
	map<int,int>::iterator it;
	for(it=m1.begin();it!=m1.end();it++)
	{
		if(it->first!=it->second)
		{
			if(it->first < it->second)
			cnt+=it->second-it->first;
			else
			cnt+=it->second;
		}
	}
	cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100010;
int q,n,len[N],val[N],ans[N],m;
void doit(int x,int v) {
//	printf("X %lld %lld\n", x, v);
	if (!x) return;
	int t = upper_bound(len+1,len+m+1,x) - len - 1;
//	printf("TT %lld\n", t);
	if (t == 0) ans[1] += v, ans[x+1] -= v;
	else {
		val[t] += (x / len[t]) * v;
		doit(x % len[t],v);
	}
}
signed main() {
	int x;
	scanf("%lld%lld",&n,&q);
	len[++m] = n;
	for (int i = 1 ; i <= q ; ++ i) {
		scanf("%lld",&x);
		while (m && len[m] >= x) -- m;
		len[++m] = x;
	}
	val[m] = 1;
	for (int i = m ; i >= 2 ; -- i) {
		val[i-1] += val[i] * (len[i] / len[i-1]);
//		printf("	%lld %lld %lld\n", len[i] % len[i - 1], val[i], i);
		doit(len[i] % len[i-1],val[i]);
	}
//	for (int i = 1; i <= m; ++i) printf("%lld\n", val[i]);
	ans[1] += val[1];
	ans[len[1]+1] -= val[1];
	for (int i = 2 ; i <= n ; ++ i)
		ans[i] += ans[i-1];
	for (int i = 1 ; i <= n ; ++ i)
		printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[64], n, b[64], mem[1<<19][55];
int dp(int msk, int x, int nm){
    if(x==n){
        return 0;
    }
//    cout<<x<<" "<<n<<" "<<nm<<" "<<mem[msk][nm]<<endl;
    if(mem[msk][nm]!=-1){
        return mem[msk][nm];
    }
    int res=1e9;
    for(int i=0; i<n; ++i){
        if(msk&(1<<i)){
            continue;
        }
        int tmp=0;
        for(int j=0; j<i; ++j){
            if(!(msk&(1<<j))){
                ++tmp;
            }
        }
        if(i%2==x%2){
            if(a[i]<nm)
                continue;
            res=min(res, tmp+dp(msk|(1<<i), x+1, a[i]));
        }
        else{
            if(b[i]<nm){
                continue;
            }
            res=min(res, tmp+dp(msk|(1<<i), x+1, b[i]));
        }
    }
//    cout<<msk<<" "<<nm<<" "<<x<<" "<<res<<endl;
    mem[msk][nm]=res;
    return res;
}
int main(){
    while(cin>>n){
        ll ans=0;
        for(int i=0; i<n; ++i){
            scanf("%d",a+i);
        }
        for(int i=0; i<n; ++i){
            scanf("%d",b+i);
        }
        memset(mem, -1, sizeof mem);
        ans=dp(0, 0, 0);
        if(ans>1e6)
            cout<<-1<<endl;
        else
           cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 113024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll arr[120];
ll KK1(ll n, ll r)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1]);
    }
    return C[r];
}
/*
ll KK2(ll n, ll m)
{
	ll ans=1;
	for(int i=1;i<=m;i++)
	{
		ans=ans/i*(n-m+i);
	}
	return ans;
}
*/
int main()
{
    ll tot=0;
    long double ans=0,sum=0,cnt=0;
    map<ll,int>N,R;
    int n,a,b;
    cin>>n>>a>>b;
    for(int i=0; i<n; i++){
       	cin>>arr[i];
		N[arr[i]]++;
	}
    sort(arr,arr+n);
    ll last ;
    for(int i=n-1; i>=0; i--)
    {
        sum+=arr[i];
        R[arr[i]]++;
        cnt++;
        if(cnt>b) break;
        if(cnt==a)
        {
            last = arr[n-1];
            ans=sum/cnt;
        }
        if(cnt>=a)
        {
            if(cnt==a)	tot+=KK1(N[arr[i]],R[arr[i]]);
            else if(arr[i]==last)	tot+=KK1(N[arr[i]],R[arr[i]]);
            //cout<<arr[i]<<"----------------"<<cnt<<"-------------"<<tot<<endl;
        }
    }
        cout<<setprecision(18)<<fixed<<ans<<endl;
        cout<<tot<<endl;
        return 0;
    }


Measured memory_bytes: 3748
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#if defined(_MSC_VER)
#pragma warning(disable : 4996)  // VSでscanfを使う．
#endif

signed main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    vector<int> a;
    a.push_back(p[i - 1]);
    a.push_back(p[i]);
    a.push_back(p[i + 1]);
    sort(a.begin(), a.end());

    if (p[i] == a[1]) {
      ans++;
    }
  }
  
  cout << ans << endl;

  return 0;
}



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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    ll n,k,x,y;
    cin >> n >> k >> x >> y;
    ll ans = 0;
    if(n > k){
        cout << k*x + (n-k)*y << endl;
    }else{
        cout << n*x << endl;
    }
    return 0;
}



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

const string YES = "YES";
const string NO = "NO";

void solve(std::string S){
  map<char, long long> tab;
  vector<long long> v;

  for(long long i = 0; i < S.size(); i++) tab[S[i]]++;

  for(long long i = 0; i < 3; i++) v.push_back(tab['a'+i]);

  sort(v.begin(), v.end());

  for(long long i = 1; i < 3; i++) {
    if(v[i] - v[0] > 1) {
      cout << NO << endl;
      return;
    }
  }
  cout << YES << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
  std::cin >> S;
    solve(S);
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    for (int i = 1; i < n; i++)
    {
        rep(k, n)
        {
            k != n - 1 ? cout << a[k] << " " : OP(a[k])
        }

        int v = a[i];
        int j;
        for (j = i - 1; j >= 0; j--)
        {
            if (a[j] < v)
                break;

            a[j + 1] = a[j];
        }
        a[j + 1] = v;
    }
    rep(k, n)
    {
        k != n - 1 ? cout << a[k] << " " : OP(a[k])
    }
    return 0;
}


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

int main(void){
    // Your code here!
    int M[2],D[2];
    rep(0,i,2)cin>>M[i]>>D[i];
    if(M[0]==M[1]){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) scanf("%d", &v);
#define OUT(v) cout<<v<<"\n"

int main() {
  int N; IN(N);

  int A[N];
  ll sum[N+1];
  REP(i, N) {
    IN(A[i]);
    sum[i] = 0;
  }
  sum[N] = 0;
  sort(A, A+N);

  REP(i, N) sum[i+1] = sum[i] + A[i];
  for (int i = N - 2; i >= 0; --i) {
    if (2 * (A[i] + sum[i]) < A[i+1]) {
      printf("%d\n", N-i-1);
      return 0;
    }
  }
  printf("%d\n", N);

  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100
 
int pop(void);
void push(int);
int stack[N],top=0;
 
int main(){
  int n,m,i;
  char c[N];
 
  while(scanf("%s",c)!=EOF){
    if (c[0]=='+'){
      m=pop();
      n=pop();
      push(n+m);
    } else if (c[0]=='-'){
      m=pop();
      n=pop();
      push(n-m);
    } else if (c[0]=='*'){
      m=pop();
      n=pop();
      push(n*m);
    } else {
      n=atoi(c);
      push(n);
    }
  }
  printf("%d\n",stack[1]);
  return 0;
}
 
int pop(void){
  top--;
  return stack[top+1];
}
 
void push(int i)
{
  top++;
  stack[top]=i;
}

Measured memory_bytes: 548
import java.util.*;
public class Main {
	public static void main(String[] args) {	
Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		if(x<y){
			int tmp = x;
			x=y;
			y=tmp;
		}
		while(x%y!=0){
			int tmp = x%y;
			x=y;
			y=tmp;
		}
		System.out.println(y);
	}

}



Measured memory_bytes: 26348
from collections import deque
H, W = map(int, input().split())
S = [input() for i in range(H)]
C = sum(s.count('.') for s in S)

dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
que = deque([(0, 0, 0)])
used = {(0, 0)}

res = None
while que:
    s, t, cost = que.popleft()
    if s == H-1 and t == W-1:
        res = cost
        break
    for di, dj in dd:
        ni = s + di; nj = t + dj
        if (not 0 <= ni < H) or (not 0 <= nj < W) or S[ni][nj] == '#' or (ni, nj) in used:
            continue
        used.add((ni, nj))
        que.append((ni, nj, cost + 1))
if res:
    print(C - 1 - res)
else:
    print(-1)

Measured memory_bytes: 3700
from collections import defaultdict

N, K = map(int, input().split())

counts = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    counts[a] += b

for num in sorted(counts.keys()):
    K -= counts[num]
    if K <= 0:
        print(num)
        break

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 1005;
const int MAX_M = 2005;

int N, M;
vector<int> Edge[MAX_N];

int used[MAX_N][2];
vector<int> ans;

int dfs(int pos, int depth = 1) {
  if(used[pos][1]) {
    return -1;
  }
  if(used[pos][0]) {
    int index = used[pos][0] - 1;
    return pos;
  }

  used[pos][0] = depth;
  ans.push_back(pos);
  for(int next : Edge[pos]) {
    int ret = dfs(next, depth+1);
    if(ret != -1) {
      return ret;
    }
  }
  used[pos][0] = false;
  ans.pop_back();
  used[pos][1] = true;

  return -1;
}

bool edgeFlag[MAX_N][MAX_N];
bool used3[MAX_N];
int dist[MAX_N];
int rireki[MAX_N];

signed main()
{
  cin >> N >> M;
  REP(m,M) {
    int a, b; cin >> a >> b;
    Edge[a].push_back(b);
    edgeFlag[a][b] = true;
  }

  REP(n,N+1) {
    int ret = dfs(n);
    if(ret == -1) continue;
    else {
      int k = 0;
      REP(n,ans.size()) {
        if(ans[n] == ret) {
          k = n;
          break;
        }
      }

      FOR(n,k,ans.size()) {
        used3[ans[n]] = true;
      }

      vector<int> ans2;
      int dd = INF_LL;

      FOR(n,k,ans.size()) {
        memset(dist, -1, sizeof(dist));
        memset(rireki, -1, sizeof(rireki));
        queue<int> que;
        dist[ans[n]] = 0; que.push(ans[n]);
        int pre = -1;
        while(que.size() && pre == -1) {
          int pos = que.front(); que.pop();
          for(int next : Edge[pos]) {
            if(used3[next] && dist[next] == -1) {
              dist[next] = dist[pos] + 1;
              que.push(next);
              rireki[next] = pos;
            }
            if(next == ans[n]) {
              pre = pos;
              break;
            }
          }
        }

        if(dd > dist[pre]) {
          dd = dist[pre];
          ans2.clear();
          ans2.push_back(pre);
          while(pre != ans[n]) {
            pre = rireki[pre];
            ans2.push_back(pre);
          } 
        }
      }

      cout << ans2.size() << endl;
      for(int a : ans2) {
        cout << a << endl;
      }

      return 0;
    }
  }
  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string s;
  cin >> s;
  rep(i,3) s[i] ^= '1'^'9';
  cout << s << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char a[10];
  char b[10];
  char c[10];
  
  int i,j;
  
  scanf("%s %s %s",a,b,c);
  i=strlen(a);
  j=strlen(b);
 

 
  
  if((a[i-1]==b[0])&&(b[j-1]==c[0])){
    printf("YES");
  }
  else{
    printf("NO");
  }
  
  return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

template<typename T>
struct BIT {
  int n;
  vector<T> v;
  BIT(int n): n(n), v(n+1) {}
  T sum(int i) {
    T x=0;
    for(i++; i; i-=i&(-i)) {
      x+=v[i];
    }
    return x;
  }
  void add(T x, int i) {
    for(i++; i<=n; i+=i&(-i)) {
      v[i]+=x;
    }
  }
};


int main(int argc, char const* argv[])
{
  int n;
  ll d, a;
  cin>>n>>d>>a;
  vector<pair<ll,ll>> enemies;
  REP(i,n) {
    ll x, h;
    cin>>x>>h;
    enemies.emplace_back(x, h);
  }
  sort(ALL(enemies));

  ll ans = 0;
  BIT<ll> bit(n+1);
  for (int i = 0; i < n; i++) {
    ll x = enemies[i].first;
    ll h = enemies[i].second;
    ll total = bit.sum(i);
    h -= total;
    if (h>0) {
      ll count = (h+a-1)/a;
      ll damage = count * a;
      ans += count;
      bit.add(damage, i);
      int limit = upper_bound(enemies.begin(), enemies.end(), pair<ll,ll>(x+2*d+1, -1)) - enemies.begin();
      bit.add(-damage, limit);
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
    long long  L,R;
    int ans;
    bool flag = false;
    cin >> L >> R;
    if(R -L >2019){
        ans = 0;   
    }else{
        ans = 2020;
        for(long long i = L; i < R; i++){
            for (long long  j = i + 1; j <= R; j++){
                int check_rem = i*j % 2019;
                if (check_rem < ans){
                    ans = check_rem;
                }
                if(check_rem == 0){
                    flag = true;
                    break;
                }
            }
            if (flag) break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const long INF = 10e+10;

int main(){
    int N;
    long A[100000];
    cin >> N;
    long cnt_minus = 0;
    long min_abs = INF;
    long abs_sum = 0;    
    for(int i = 0; i < N; i++){
        cin >> A[i];
        abs_sum += abs(A[i]);
        min_abs = min(min_abs, abs(A[i]));
        if(A[i] < 0){
            cnt_minus++;
        }
    }
    if(cnt_minus%2 == 0){
        cout << abs_sum << endl;
    }else{
        cout << abs_sum - 2*min_abs << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int main() {
	int i,n,m,kosu;
	cin>>n;
	int num[n],kanosei[n];
	for(i=0;i<n;i++){
		num[i]=1;
		kanosei[i]=0;
	}
	kanosei[0]=1;
	cin>>m;
	int move[m][2];
	for(i=0;i<m;i++){
		cin>>move[i][0]>>move[i][1];
	}
	for(i=0;i<m;i++){
		num[move[i][0]-1]-=1;
		num[move[i][1]-1]+=1;
		if(kanosei[move[i][0]-1]==1){
			kanosei[move[i][1]-1]=1;
		}
		if(num[move[i][0]-1]==0){
			kanosei[move[i][0]-1]=0;
		}
	}
	kosu=0;
	for(i=0;i<n;i++){
		if(kanosei[i]==1){
			kosu++;
		}
	}
	cout<<kosu<<endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n, m = 0;

    cin >> n;

    vector<int> a(n + 1), b(n + 1, 0), ans;

    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }

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

        for (int j = i * 2; j <= n; j += i)
        {
            sum += b[j];
        }

        if ((sum + a[i]) % 2 == 1)
        {
            b[i]++;
            m++;
            ans.push_back(i);
        }
    }

    cout << m << endl;

    for (auto x : ans)
    {
        cout << x << endl;
    }
}

Measured memory_bytes: 3064
def integration(s):
  itg = [0]
  counter = 0
  for x in s:
    if x == "B":
      counter += 1
    itg.append(counter)
  return itg

def solve(itg, left, right):
  n = right-left
  if n <= 1:
    return 0
  mid = (left+right)//2
  a = solve(itg, left, mid)
  b = solve(itg, mid, right)
  res = a + b + (itg[mid]-itg[left])* \
    (right-mid-(itg[right]-itg[mid]))
  return res

s = input()
print(solve(integration(s), 0, len(s)))


Measured memory_bytes: 11136
#include <iostream>
int main(void){
    int n, a, b; scanf("%d%d%d", &n, &a, &b);
    long long int res;
    if(n == 1) res = (a == b) ? 1 : 0;
    else{
        if(a > b) res = 0;
        else{ res = b - a; res *= n - 2; res++;}
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 888
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

int main() {

	int a, b;
	cin >> a >> b;
	if (a <= 9 && b <= 9) { cout << a * b << endl; }
	else { cout << -1 << endl; }




}


Measured memory_bytes: 256
/* 
 * Created by solzard on 2020-03-05.
 * 
 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

bool is_bingo(int player) {
  std::unordered_set<int> winnable_conditions
      {0b111000000, 0b000111000, 0b000000111, 0b100100100, 0b010010010, 0b001001001, 0b100010001, 0b001010100};
  for (const auto &condition : winnable_conditions) {
    if ((player & condition) == condition) return true;
  }
  return false;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);

  std::vector<int> sheet;
  std::unordered_set<int> bingo;
  int a, n, b;
  rep(_, 9) {
    std::cin >> a;
    sheet.emplace_back(a);
  }
  std::cin >> n;
  rep(_, n) {
    std::cin >> b;
    bingo.emplace(b);
  }
  int player = 0;
  rep(i, 9) {
    if (bingo.find(sheet[i]) != std::end(bingo)) {
      player |= 1 << i;
    }
  }
  std::cout << (is_bingo(player) ? "Yes" : "No") << "\n";
}



Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s;
    while(cin>>s)
    {
        if(s=='a'||s=='e'||s=='i'||s=='o'||s=='u')
        {
            cout<<"vowel"<<endl;
        }
        else
        {
            cout<<"consonant"<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	int n,a,b,c,d;
	string s;
	cin>>n>>a>>b>>c>>d>>s;
	a--,b--,c--,d--;
	for(int i=a;i<b;i++)if(s[i]=='#'&&s[i+1]=='#'){puts("No");return 0;}
	for(int i=c;i<d;i++)if(s[i]=='#'&&s[i+1]=='#'){puts("No");return 0;}
	if(d<c){
		for(int i=b-1;i<=min(d-1,n-3);i++)if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){puts("Yes");return 0;}
		puts("No");
	}
	else puts("Yes");
	return 0;
} 

Measured memory_bytes: 592
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  map<char, set<int>> m;
  for (int i = 0; i < N; ++i) {
    m[S[i]].insert(i);
  }

  LL total = (LL)m['R'].size() * (LL)m['G'].size() * (LL)m['B'].size();

  for (int r : m['R']) {
    for (int g : m['G']) {
      int x = max(r, g);
      int y = min(r, g);
      int d = x - y;
      if (m['B'].count(x+d)) --total;
      if (m['B'].count(y-d)) --total;

      if ((x  +  y) % 2 == 0) {
        int z = (x + y) / 2;
        if (m['B'].count(z)) --total;
      }
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 3788
# -*- coding: utf-8 -*-                                                                              

N, T = map(int, input().split())
c = []
t = []
for _ in range(N):
    c_temp, t_temp = map(int, input().split())
    c.append(c_temp)
    t.append(t_temp)

min_c =	1001

for i in range(N):
    if t[i] <= T:
        if c[i] < min_c:
            min_c = c[i]

if min_c == 1001:
    print("TLE")
else:
    print(min_c)


Measured memory_bytes: 3060
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int a[575];
//map<int,int> mp;
int mp[9];

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    if(a[i] < 400) mp[0]++;
    else if(a[i] < 800) mp[1]++;
    else if(a[i] < 1200) mp[2]++;
    else if(a[i] < 1600) mp[3]++;
    else if(a[i] < 2000) mp[4]++;
    else if(a[i] < 2400) mp[5]++;
    else if(a[i] < 2800) mp[6]++;
    else if(a[i] < 3200) mp[7]++;
    else mp[8]++;
  }

  int minn=0;
  int non_niji=0, niji=0;
  REP(i, 9){
    if(i == 8) continue;
    else if(mp[i]) minn++;			 
  }
 
  cout << max(minn, 1) << " " << minn + mp[8] << endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
Ss=[input() for s in range(N)]
count = [s.count("AB") for s in Ss]
headcount = len([s for s in Ss if s[0]=="B" and s[-1]!="A"])
outcount = len([s for s in Ss if s[-1]=="A" and s[0]!="B"])
multicount = len([s for s in Ss if s[0]=="B" and s[-1]=="A"])
if outcount==0 and headcount==0:
    if multicount<=0:
        print(sum(count))
    else:
        print(sum(count)+multicount-1)
else:
    print(sum(count)+min(headcount,outcount)+multicount)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std; 
typedef long long ll;
#pragma GCC optimize("O3")
#define pb push_back
int32_t main()  {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , w;
    cin >> n >> w;
    vector<ll> dp(w+1,0);
    while (n--) {
        ll x , v;
        cin >> x >> v;
        for ( int  i = w-x ; i >=0 ; i--) {
            dp[i+x]  = max(dp[i+x] , dp[i]+v);
        }
    }
    ll ans=-1;
    for ( auto  i : dp) {
        ans = max( i, ans);
    }
    cout << ans;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
abList = [list(map(int, input().split())) for _ in range(m)]
num = [0 for _ in range(n + 1)]
for i in range(m):
    for j in range(2):
        num[abList[i][j]] += 1
for i in range(n):
    print(num[i + 1])

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

#define rep(i, begin, end) for(int64_t i = (begin); i <= (end); i++)
#define rev(i, begin, end) for(int64_t i = (begin); (end) <= i; i--)

void printvec(const std::vector<int>& vec) {
    for (int i = 0; i < vec.size(); i++) { std::cout << vec[i] << " "; } std::cout << std::endl;
}

const int MAX_N = 55;
const int MOD = 1e9 + 7;
int N, K;
int128_t dp[MAX_N][MAX_N][MAX_N*MAX_N] = {};

int main(int argc, char **argv) {
    std::cin >> N >> K;

    dp[0][0][0] = 1;

    rep (i, 1, N) {
        rep (j, 0, i) {
            rep (k, 2*j, N*N) {
                if (1 <= j) {
                    dp[i][j][k] = dp[i-1][j-1][k-2*j];
                }
                dp[i][j][k] += dp[i-1][j][k-2*j] * (j*2 + 1) + dp[i-1][j+1][k-2*j] * (j + 1) * (j + 1);

                //std::cout << i << " " << j << " " << k << " " << dp[i][j][k] << std::endl;
                dp[i][j][k] %= MOD;
            }
        }
    }

    std::cout << dp[N][0][K] << std::endl;


    return 0;
}

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

int main() {

	int n;
	string s;
	cin >> n >> s;

	int ans = 1145141919;
	int e = 0;

	loop(i,s.size()) if(s[i] == 'E') e++;

	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'W') {
			ans = min(ans,e);
			e++;
		}
		else {
			e--;
			ans = min(ans,e);
		}
	}
	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
int cnt[1000001];

int main() {
  long N, M;
  int ans = 0;
  cin >> N;
  M = N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i=2; i<sqrt((double)N)+1; i++) {
    if (N%i)
      continue;
    while (N%i == 0) {
      cnt[i]++;
      N /= i;
    }
  }
  if (N == M) {
    cout << 1 << endl;
    return 0;
  }
  if (N != 1)
    ans++;
  for (int i=2; i<1000001; i++) {
    if (cnt[i] == 0)
      continue;
    int time = 1;
    while (time <= cnt[i]) {
      ans++;
      cnt[i] -= time;
      time++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3652
// https://atcoder.jp/contests/abc103/tasks/abc103_b
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int len = s.length();
    bool flag = true;
    REP(d, len) {
        flag = true;
        REP(i, len) {
            if (s[(i + d) % len] != t[i]) {
                flag = false;
                break;
            }
        }
        if (flag)
            break;
    }
    if (flag)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}

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

using namespace std;

const int MAX = 10000000;

int f(int x) {
    if (x % 2 == 0) {
        return x / 2;
    }
    else {
        return 3 * x + 1;
    }
}

void Main() {
    int s;
    cin >> s;

    set<int> hist;
    hist.insert(s);
    int ans = 0;
    for (int i = 2; i < MAX; ++i) {
        s = f(s);
        if (hist.count(s) == 0) {
            hist.insert(s);
        }
        else {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256