akhauriyash/Code-Regression huggingface dataset:
use std::collections::BinaryHeap;

fn sum(bh: &BinaryHeap<i64>) -> i64 {
    bh.iter().fold(0, |a, b| a + b)
}
fn sum_rev_i64(bh: &BinaryHeap<Rev<i64>>) -> i64 {
    bh.iter().fold(0, |a, b| a + b.0)
}

use std::cmp::Ordering;
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
struct Rev<T>(T) where T : Ord + Copy;
impl<T> PartialOrd for Rev<T> where T : Ord + Copy {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}
impl<T> Ord for Rev<T> where T : Ord + Copy {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        self.0.cmp(&other.0).reverse()
    }
}
impl<T: Ord + Copy> Rev<T> {
    fn unwrap(&self) -> T {
        self.0
    }
}

fn main() {
    let n : usize = { let n = mylib::get_ints(); n[0] as usize };
    let a = mylib::get_ints();
    let mut afbh : BinaryHeap<Rev<i64>> = {
        let af : Vec<Rev<i64>> = a[0..n].to_vec().iter().map(|&v| Rev(v)).collect();
        BinaryHeap::from(af)
    };
    let mut apbh : BinaryHeap<i64> = BinaryHeap::from(a[2*n..3*n].to_vec());

    let mut af_sums : Vec<i64> = vec![0; n+1];
    let mut ap_sums : Vec<i64> = vec![0; n+1];
    af_sums[0] = sum_rev_i64(&afbh);
    ap_sums[n] = sum(&apbh);
    for i in 1..(n+1) {
        afbh.push(Rev(a[n-1+i]));
        af_sums[i] = af_sums[i-1] + a[n-1+i] - afbh.pop().unwrap().unwrap();
        apbh.push(a[2*n-i]);
        ap_sums[n-i] = ap_sums[n+1-i] + a[2*n-i] - apbh.pop().unwrap();
    }
    let mut max = std::i64::MIN;
    for i in 0..(n+1) {
        max = std::cmp::max(max, af_sums[i] - ap_sums[i]);
    }
    println!("{}", max);
}

mod mylib {
    // IO
    pub fn get_str() -> String {
        use std::io;
        let mut input = String::new();
        io::stdin().read_line(&mut input);
        input.as_str().trim().to_string()
    }
    fn split_by_space(ss:&str) -> Vec<&str> {
        ss.split_whitespace().collect()
    }
    fn str_to_int(ss:&str) -> i64 {
        ss.parse().unwrap()
    }
    pub fn get_ints() -> Vec<i64> {
        split_by_space(&get_str()).iter().map(|s:&&str| str_to_int(s)).collect()
    }
}


Measured memory_bytes: 17524
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
#include <atcoder/modint>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()


using modint = atcoder::modint998244353;


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

	int n, q;
	cin >> n >> q;

	vector<modint> sumpow(n + 1);
	modint p = 1;

	for (int i = n; i >= 1; i--) {
		sumpow[i] = p;
		p *= 10;
	}
	for (int i = 1; i <= n; i++) {
		sumpow[i] += sumpow[i - 1];
	}


	modint ans = sumpow[n];
	map<int, pair<int, int>> seg;
	seg.emplace(0, make_pair(n, 1));

	rep(_, q) {
		int L, R, d;
		cin >> L >> R >> d;
		L--;


		auto it = seg.upper_bound(L);
		if (it != seg.begin()) --it;

		vector<pair<int, pair<int, int>>> v;

		for (; it != seg.end(); ) {
			if (R <= it->first)break;
			ans -= (sumpow[it->second.first] - sumpow[it->first]) * it->second.second;

			if (it->first < L) {
				v.emplace_back(it->first, make_pair(L, it->second.second));
			}
			if (R < it->second.first) {
				v.emplace_back(R, make_pair(it->second.first, it->second.second));
			}

			it = seg.erase(it);
		}
		for (auto p : v) {
			ans += (sumpow[p.second.first] - sumpow[p.first]) * p.second.second;
			seg.insert(p);
		}

		ans += (sumpow[R] - sumpow[L]) * d;
		seg.emplace(L, make_pair(R, d));
		cout << ans.val() << endl;
	}




	return 0;
}


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

void solve()
{
    int x;
    cin >> x;
    if (x == 1)
        cout << 0 << endl;
    else
        cout << 1 << endl;
}

int main()
{
    // srand((unsigned)time(NULL));
    // int t = clock();
    solve();
    // double et = 1.0 * (clock() - t) / CLOCKS_PER_SEC;
    // printf("Execution Time: %.4lf sec\n", et);
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
int main(){
  ll N,M;
  cin>>N>>M;
  vector<pair<ll,ll>> C;
  ll A,B;
  rep(i,N){
    cin>>A>>B;
    C.push_back(make_pair(A,B));
  }
  sort(all(C));
  ll ans=0;
  rep(i,N){
    if(M>=C[i].second){
      M-=C[i].second;
      ans+=C[i].second*C[i].first;
    }else{
      ans+=M*C[i].first;
      break;
    }
  }
  cout<<ans<<endl; 
}

Measured memory_bytes: 2420
n = gets.to_i

arr = []
n.times do |i|
  s,p = gets.chomp.split(" ")
  arr << [i+1, s, p.to_i]
end

arr = arr.sort do |a, b|
  ret = +1

  if a[1] < b[1]
    ret = -1;
  elsif a[1] == b[1] && a[2] > b[2]
    ret = -1
  end
  ret
end

arr.each do |i|
  puts i[0]
end


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

bool prime[300000];
int cnt[300000];

signed main() {
	memset(prime, true, sizeof(prime));
	prime[1] = false;

	int c = 0;
	for (int i = 2; i < 300000; i++) {
		if (!prime[i]) {
			cnt[i] = c;
			continue;
		}
		for (int j = 2 * i; j < 300000; j += i) {
			prime[j] = false;
		}
		c++;
		cnt[i] = c;
	}

	while (true) {
		int n;
		cin >> n;

		if (n == 0) break;

		cout << (cnt[2 * n] - cnt[n]) << endl;
	}

    return 0;
}

Measured memory_bytes: 5728
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A[] = new int[N];
    int counter = 0;
    
    for(int i=0; i<N; i++) {
      A[i] = sc.nextInt();
    }
    Arrays.sort(A);
    
    for(int j=N/2; j<N; j++){
      if(A[j] > A[N/2 - 1]) {
        break;
      } else if(A[j] == A[N/2-1]) {
        counter++;
      }
    }
    if(counter>1){
      System.out.println(0);
    } else {
      System.out.println(A[N/2] - A[N/2-1]);
    }
  }
}

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


bool is_prime(int x){
	for(int i=2;i*i<=x;++i){
		if(x%i==0)return false;
	}
	return true;
}
int main(){
	int n;
	cin >> n;
	int ans = 0;
	for(int i=0;i<n;++i){
		int d;
		cin >> d;
		ans += is_prime(d);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3120
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

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

    vector<int> X(m);
    for (int i = 0; i < m; ++i) {
        cin >> X[i];
    }
    sort(X.begin(), X.end());
    vector<int> A;
    for (int i = 0; i + 1 < m; ++i) {
        A.push_back(X[i + 1] - X[i]);
    }
    sort(A.begin(), A.end());
    int rem = m - n;

    long long res = 0;
    for (int i = 0; i < rem; ++i) {
        res += A[i];
    }
    cout << res << '\n';


    return 0;
}

Measured memory_bytes: 1276
//use BIT to sum 1 -> i
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);
vector<ll> Fen;
int n, D, A;

void Update(int id,ll val = 1){
    for (id++ ; id <= n; id += (id & - id)) Fen[id] += val;
}

ll get(int id){
    ll res = 0;
    for (id++; id > 0 ; id -= (id & -id)) res += Fen[id];
    return res; 
}


int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> D >> A;
    vector<pair<ll,ll>> a(n);
    Fen.resize(n + 2);
    for (int i = 0; i < n; i++) cin >> a[i].fir >> a[i].sec;

    sort(all(a));
    D *= 2;
    ll ans = 0;
    for (int i = 0; i < n; i++){
        ll remain = a[i].sec - get(i);
        //cout << remain << ' ';
        if (remain <= 0) {
            //cout << '\n';
            continue;
        }
        ll delta = (remain + A - 1)/A;
        //cout << delta << ' ';
        ans += delta;
        int far = upper_bound(all(a),make_pair(a[i].fir + D*1LL + 1LL,-1LL)) - a.begin();
        //cout << far + 1 << '\n';
        Update(i,delta*(ll)A);
        Update(far,-delta*(ll)A);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
int main(void)
{
	int n, h[1000], i, a, c;
	
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&h[i]);
	
	a=c=0;
	for(i=0;i<n;i++){
	    if(h[i]>=a){
	        c++;
	        a=h[i];
	    }
	}
	printf("%d\n",c);
	return 0;
}

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

#define LL long long

int n;
LL ans;

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) ans += 1ll * i * (n - i + 1);
	for(int i = 1; i < n; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		if(a > b) swap(a, b);
		ans -= 1ll * a * (n - b + 1);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3832
// 1072
#include <stdio.h>

int main()
{
    int a, b;

    while (1) {

        scanf("%d %d", &a, &b);
        if (a == 0 && b == 0)
            break;
        if ( a % 2 == 1 && b % 2 == 1)
            puts("no");
        else
            puts("yes");
    }
    return 0;
}

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

int main(void) {
    int N, M;
    cin >> N >> M;
    vector< int > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    priority_queue< int > q;
    for (int i = 0; i < N; i++) {
        q.push(A[i]);
    }
    for (int i = 0; i < M; i++) {
        int t = q.top();
        q.pop();
        t = t / 2;
        q.push(t);
    }
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        ans += q.top();
        q.pop();
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1276
#include <cstdio>
#include <algorithm>

using namespace std;

int A, B, C, X, Y;

int div_up(int a, int b){
  if(a%b == 0){
    return a/b;
  }else{
    return a/b + 1;
  }
}

int calc(int a, int b, int ab){
  return a*A + b*B + ab*C;
}

int main(){
  scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);

  int res = X*max(A, 2*C) + Y*max(B, 2*C);
  for(int n_ab=0; n_ab <= 2*max(X, Y); n_ab++){
    int n_a = max(0, div_up(2*X - n_ab, 2));
    int n_b = max(0, div_up(2*Y - n_ab, 2));
    res = min(res, calc(n_a, n_b, n_ab));
  }
  printf("%d\n", res);

  
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

double distance(double x1, double y1, double x2, double y2);

int main(void){
  double x1, x2, y1, y2, dis;

  scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
  dis = distance(x1, y1, x2, y2);
  printf("%f\n", dis);
  return 0;
}


double distance(double x1, double y1, double x2, double y2){
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1- y2));
}

Measured memory_bytes: 652
#include<stdio.h>

int main(){
  int n,m,a,b,f[50]={};
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    f[a-1]++;
    f[b-1]++;
  }
  for(int i=0;i<n;i++)
    printf("%d\n",f[i]);
}

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

int main() {
    int from0=0, from1=0, i=0, res;
    char S[100000], nextChar;
    cin >> S;

    // 0から始まる場合
    nextChar = '0';
    while(1) {
        if (S[i] == '\0') break;
        if (S[i] == nextChar) from0 += 1;
        if (nextChar == '0') nextChar = '1';
        else nextChar = '0';
        i++;
    }
    i = 0;
    // 1から始まる場合
    nextChar = '1';
    while(1) {
        if (S[i] == '\0') break;
        if (S[i] == nextChar) from1 += 1;
        if (nextChar == '0') nextChar = '1';
        else nextChar = '0';
        i++;
    }

    if (from0 > from1) res = from1;
    else res = from0;

    cout << res << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = long long;
using P = pair<int,int>;


int main(){
    int N;
    cin >> N;
    vector<int> B(N-1);
    rep(i,N-1) cin >> B[i];

    const int INF = 1e9;
    vector<int> A(N, INF);

    rep(i,N-1){
        if(A[i] > B[i]) A[i] = B[i];
        A[i+1] = B[i];
    }

    int ans = 0;
    for(auto a : A) ans += a;

    cout << ans << endl;

}


Measured memory_bytes: 256
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string s =Console.ReadLine();
            string t =Console.ReadLine();
            int count = 0;
            for(int i = 0; i < s.Length;i++)
            {
                if(s[i] != t[i])
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27520
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main(){
    ll n,k;
    cin>>n>>k;
    long long ans=0;
    for (ll i = k; i <= n+1; i++)
    {
        /* code */
        ll first=i*(i-1)/2;
        ll last=(2*n-i+1)*i/2;
        ll add=last-first+1;
        ans=(ans+add)%MOD;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3672
require 'set'

class UnionFind
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end
end

n, k, l = gets.strip.split.map(&:to_i)
pq = k.times.map { gets.strip.split.map(&:to_i) }
rs = l.times.map { gets.strip.split.map(&:to_i) }

roads_uf = UnionFind.new(n+1)
rails_uf = UnionFind.new(n+1)

pq.each do |pp, q|
  roads_uf.unite(pp, q)
end

rs.each do |r, s|
  rails_uf.unite(r, s)
end

counter = {}

(1..n).each do |i|
  k = [rails_uf.get_parent(i), roads_uf.get_parent(i)].to_s
  counter[k] ||= Set.new
  counter[k].add(i)
end

result=[]
(1..n).each do |i|
  k = [rails_uf.get_parent(i), roads_uf.get_parent(i)].to_s
  result << counter[k].size
end

#p roads_h
#p rails_h

puts result.join(' ')


Measured memory_bytes: 146044
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>
using namespace std;
//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007
int main() {
	int n;
	cin >> n;
	VI t(n+1), x(n+1), y(n+1);
	for (int i = 1; i <= n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}

	int div; //時間の差
	int cnt;//移動におけるマンハッタン距離?
	bool flag = true;
	for (int i = 0; i < n; i++) {
		div = abs(t[i + 1] - t[i]);
		cnt = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);

		if (!(div >= cnt)) {
			flag = false;
			break;
		}else if (div % 2 == 0 && cnt % 2 == 1) {
			flag = false;
			break;
		}else if (div % 2 == 1 && cnt % 2 == 0) {
			flag = false;
			break;
		}
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
	
}

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

using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> arr(n);
  for(int i=0;i<n;i++){
   cin>>arr[i];
 }
  if(n==k){
    cout<<"1";
  }else{
    int sum(1);
    int count(0);
    while(sum<n){
      sum+=k-1;
      count+=1;
    }
    cout<<count;
  }
}


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

int main(){
  int n;
  cin >>n;
  vector<int>a(n);
  map<int,int>aa;
  for(int i=2;i<=n;i++){
    cin >>a.at(i-2);
    if(aa.count(a.at(i-2)))aa.at(a.at(i-2))++;
    else aa[a.at(i-2)]=1;
  }
  for(int i=1;i<=n;i++)
    cout <<aa[i]<<endl;
}

Measured memory_bytes: 13532
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
 
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1), MA(N+2,1e18);
    rep(i,N+1){
        cin >> A[i];
    }
    MA[0] = 1;
    bool flag = 1;
    rep(i,N+1){
        if(MA[i] - A[i] < 0){
            flag = 0;
            break;
        }
        MA[i+1] = (MA[i] - A[i])*2; 
        if(MA[i+1] > (1e17)){
            break;
        }
    }
    if(!flag){
        cout << -1 << endl;
        return 0;
    }
    vector<ll> v(N+1), b[N+1];
    v[N] = A[N];
    for(ll i=N-1;i>=0;i--){
        v[i] = v[i+1] + A[i];
        v[i] = min(v[i], MA[i]); 
    }
    ll ans = 0;
    REP(i,0,N+1){
        ans += v[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 7968
#include<stdio.h>
int main()
{
	char a,b;
	scanf("%c %c",&a,&b);getchar();
	if(a=='H' && b=='H')
	{
		printf("H\n");
	}
	else if(a=='H' && b=='D')
	{
		printf("D\n");
	}
	else if(a=='D' && b=='H')
	{
		printf("D\n");
	}
	else if(a=='D' && b=='D')
	{
		printf("H\n");
	}
	
}

Measured memory_bytes: 128
/*
AIZU ONLINE A0008
Sum of 4 Integers

*/
#include <stdio.h>

int main()
{
  int i,j,k,l;
  int total;
  int cnt;

  while(EOF != scanf("%d",&total))
        { cnt=0;
          for(i=0;i<10;i++)
            for(j=0;j<10;j++)
              for(k=0;k<10;k++)
                for(l=0;l<10;l++)
                  if(i+j+k+l == total)
                    cnt++;

          printf("%d\n",cnt);
        }

        return(0);
}

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

int main(){
    int N;
    cin >> N;
    vector<int> data(N);
    for( int i = 0; i < N; i++ ){
        cin >> data[i];
    }
    for( int i = 0; i < N; i++ ){
        int key = data[i];
        int j = i - 1;
        while( j >= 0 && data[j] > key ){
            data[j+1] = data[j];
            j--;
        }
        data[j+1] = key;
        for( int k = 0; k < N; k++ ){
            if( k != 0 ) cout << ' ';
            cout << data[k];
        }
        cout << endl;
    }

}

Measured memory_bytes: 1196
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =  sc.nextInt();
		sc.nextInt();
		String s[] = new String[N];
		for (int i=0;i<N;i++) {
			s[i] = sc.next();
		}
		Arrays.parallelSort(s);
		for (int i=0;i<N;i++) {
			System.out.print(s[i]);
		}
	}
}

Measured memory_bytes: 37276
import java.util.*

fun add1(len: Int, arr: Array<Int>): Array<Int> {
    val ans = Array<Int>(len, { 0 })
    var go = true
    for (i in 0..len-1) {
        if (go) {
            if (arr[i] == 0) {
                ans[i] = 1
                go = false
            } else {
                if (i == len-1) {
                    ans[i] = 2
                } else {
                    ans[i] = 0
                }
            }
        } else {
            ans[i] = arr[i]
        }
    }
    return ans
}

fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val m = cin.nextInt()
    val connected = Array<MutableList<Int>>(n, { mutableListOf() })
    for (i in 0..m-1) {
        val k = cin.nextInt()
        for (j in 0..k-1) {
            val t = cin.nextInt() - 1
            connected[t].add(i)
        }
    }

    val p_arr = Array<Int>(m, { cin.nextInt() })

    var onoff = Array<Int>(n, { 0 })
    var ans = 0
    while (true) {
        val p_test_arr = Array<Int>(m, { 0 })
        for (i in 0..n-1) {
            if (onoff[i] == 1) {
                for (ele in connected[i]) {
                    p_test_arr[ele] += 1
                }
            }
        }
        for (i in 0..m-1) {
            if (p_test_arr[i] % 2 != p_arr[i]) {
                break
            }
            if (i == m-1) {
                ans += 1
            }
        }
        onoff = add1(n, onoff)
        if (onoff[n-1] == 2) {
            break
        }
    }
    println(ans)
}

Measured memory_bytes: 31516
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

long long a[61];
long long p[61];

long long f(int j, long long x){
  if(x == 1){
    if(j == 0) return 1;
    else return 0;
  }
  if(x <= 1+a[j-1]) return f(j-1,x-1);
  if(x == 2+a[j-1]) return p[j-1]+1;
  if(x <= 2+2*a[j-1]) return p[j-1]+1+f(j-1,x-2-a[j-1]);
  if(x == 3+2*a[j-1]) return 2*p[j-1]+1;
  return 0;
}

int main(){
  int n;
  long long x;
  a[0] = 1;
  p[0] = 1;
  for(int i=0;i<60;i++){
    a[i+1] = 2*a[i]+3;
    p[i+1] = 2*p[i]+1;
  }
  cin >> n >> x;
  cout << f(n,x) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

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

    long long res = 0;
    repp(i,1,N+1) {
       if (i % 3 != 0 &&  i % 5 != 0) res += i;
    }
    cout << res << endl;
}



Measured memory_bytes: 3632
import java.util.*;
import java.io.*;

/**
 * Made by egor https://github.com/chermehdi/egor.
 * 
 * @author azize
   
 */
public class Main {

    void solve(Scanner in, PrintWriter out) {
        int n = in.nextInt();

        long ans = 0;
        int state = 0;
        for (int i = 1; i <= n; ++i) {
            if (i % 3 == 0 || i % 5 == 0) {
                continue;
            } 

            ans += i;
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


Measured memory_bytes: 35876
/*


                 """Bismillahir Rahmanur Rahim"""

*/
#include<bits/stdc++.h>
using namespace std;
#define pi 2*acos(0.0)
#define ll long long int
#define pb push_back
#define pf push_front
const ll sz = 1000001;
#define ek(x) __builtin_popcount(x)
#define ses '\n'
#define stm istringstream
#define sob(x) x.begin(),x.end()
#define ghora ios_base::sync_with_stdio(0);cin.tie(0);
#define gcd __gcd
ll lcm(ll x,ll y){return (x*y)/gcd(x,y);}
#define tin ll T;cin>>T; for(ll o=1;o<=T;o++)
#define tout cout<<"Case "<<o<<": ";
ll val[102];
ll wt[103];
ll dp[105][100050];
ll n,W;
ll knapsack(ll i,ll w)
{
    if(i>n-1)
        return 0;
    if(dp[i][w]>0)
        return dp[i][w];
    ll x=-5,y;
    if(w+wt[i]<=W)
        x=val[i]+knapsack(i+1,w+wt[i]);
    y=knapsack(i+1,w);
    return dp[i][w]=max(x,y);
}
int main()
{
    
    memset(dp,-1,sizeof(dp));
       cin>>n>>W;
       for(ll i=0;i<n;i++)
       {
        cin>>wt[i]>>val[i];
       }
      ll x=knapsack(0,0);
     cout<<x<<ses;
    

    return 0;
}
/*   --------------------
    |      ~SOHAN~       |
    |   ~Chandler68~     |
     --------------------
    || VALAR MORGULIS||==|| ALL MEN MUST DIE ||
    \\ Power Is Power//
    || I Can Do This All day ||
    // We are on a Break \\ // How you doin'? \\
    || Say My Name || ~~ || I Am The Who Knocks ||
    // I Am Ted Mosby Architect \\
    || It Is Legen --wait for it -- dary ,Legendary ||
    \\ Penny - Penny - Penny // -- Bazinga

*/



Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define endl "\n"
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
 
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pp;
typedef pair<ll,pair<ll,ll> > ppp;
 
const ll N    = 1e6+5;
const ll INF  = 1e18;
const ll mod  = 998244353;

void solve()
{
    ll s;
    cin>>s;
    if(s==INF)
        cout<<"0 0 1000000000 0 0 1000000000\n";
    else{
        ll y3 = s/1000000000;
        y3+=1;
        ll x3 = 1LL*y3*1000000000-s;
        cout<<"0 0 1000000000 1 "<<x3<<" "<<y3<<endl;
    }

}     
 
int main(){
    FAST
    int t= 1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

bool solve1(int mid, int N, int Q, string s, vector<char> &t, vector<char> &d){
    char now = s[mid];
    rep(i,Q){
        if(t[i] == now){
            if(d[i] == 'L'){
                mid--;
                if(mid < 0) return false;
                now = s[mid];
            }
            else{
                mid++;
                if(mid >= N) return true;
                now = s[mid];
            }
        }
    }
    return true;
}

bool solve2(int mid, int N, int Q, string s, vector<char> &t, vector<char> &d){
    char now = s[mid];
    rep(i,Q){
        if(t[i] == now){
            if(d[i] == 'L'){
                mid--;
                if(mid < 0) return true;
                now = s[mid];
            }
            else{
                mid++;
                if(mid >= N) return false;
                now = s[mid];
            }
        }
    }
    return true;
}

int main(){
    int N, Q;
    cin >> N >> Q;
    string s; 
    cin >> s;
    vector<char> t(Q), d(Q);
    rep(i,Q) cin >> t[i] >> d[i];
    int ans = N;

    ll left = -1;
    ll right = N;
    while(right - left > 1){
        ll mid = (left + right) / 2;
        if(solve1(mid, N, Q, s, t, d)) right = mid;
        else left = mid;
    }
    ans -= right;
    left = -1;
    right = N;
    while(right - left > 1){
        ll mid = (left + right) / 2;
        if(solve2(mid, N, Q, s, t, d)) left = mid;
        else right = mid;
    }
    ans -= N-1-left;
    cout << ans << endl;
}

Measured memory_bytes: 4168
N = int(input())
A = list(map(int,input().split()))
money = 1000
stock = 0
for i in range(N):
    if i == N-1:
        money += stock*A[i]
    elif A[i] < A[i+1]:
        buy = money//A[i]
        money = money - A[i]*buy
        stock += buy
    elif A[i] > A[i+1]:
        if stock != 0:
            money = money + stock*A[i]
            stock = 0
print(money)

Measured memory_bytes: 9192
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return

    limit = 10**18
    ans = 1
    for i in A:
        ans *= i
        if ans > limit:
            print(-1)
            return

    print(ans)

main()

Measured memory_bytes: 21604
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main () {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;
        double ss[n];
        for (int i=0; i<n; i++) {
            cin >> ss[i];
        }
        double sum = 0.0;
        for (int i=0; i<n; i++) sum += ss[i];

        double ave = sum / (double)n;

        double compare = 0;
        for (int i=0; i<n; i++) compare += pow(ss[i] - ave, 2);
        double a = sqrt(compare / (double)n);
        printf("%lf\n", a);
    }
    return 0;
}

Measured memory_bytes: 1248
def main():
    s = [int(char) for char in input()]
    l = len(s)
    k = int(input())

    tmp = 0
    nonzero = []
    for number in s:
        if number > 0:
            tmp += 1
        nonzero.append(tmp)
    nonzero.append(0)  # let nonzero[-1] be 0

    def binomial(n, k):
        if n < k or n < 0 or k < 0:
            return 0
        if k == 0:
            return 1
        if k == 1:
            return n
        if k == 2:
            return n * (n-1) // 2
        if k == 3:
            return n * (n-1) * (n-2) // 6
        raise ValueError

    def dp(i, _cache={-1: 0}):
        if i in _cache:
            return _cache[i]
        if nonzero[i-1] > k or s[i] == 0:
            result = dp(i-1)
            _cache[i] = result
            return result
        if nonzero[i-1] == k:
            result = dp(i-1) + 1
            _cache[i] = result
            return result
        result = (
            dp(i-1) +
            (s[i] - 1) * binomial(l - 1 - i, k - nonzero[i-1] - 1) *
            9 ** (k - nonzero[i-1] - 1) +
            binomial(l - 1 - i, k - nonzero[i-1]) *
            9 ** (k - nonzero[i-1])
        )
        _cache[i] = result
        return result
    
    print(dp(l-1) + (nonzero[l-1] == k))


main()


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

typedef long long int lli;
typedef long long ll;
typedef long double ld;

int main(){
    int t=1;
    //cin>>t;
    while(t--){
        string s;
        cin>>s;
        for(int i=0;i<s.length();i++){
            if(s[i]==','){
                cout<<" ";
            }
            else{
                cout<<s[i];
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define modn 1000000007
#define hell 1000000009
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int dp[505][505];
int main()
{
    memset(dp, 0, sizeof(dp));
    int n,m,q;
    cin>>n>>m>>q;
    for(int i=0; i<m; i++)
    {
        int l, r;
        cin>>l>>r;
        dp[l][r] += 1;
    }
    
    for(int i=n; i>=1; i--)
    {
        for(int j=1; j<=n; j++)
        {
            dp[i][j] += dp[i][j-1];
        }
        for(int j=1; j<=n; j++)
        {
            dp[i][j] += dp[i+1][j];
        }
    }
    
    for(int i=0; i<q; i++)
    {
        int p,q;
        cin>>p>>q;
        cout<<dp[p][q]<<endl;
    }
    return 0;
}








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

int main() {
    string S;
    cin >> S;
    sort(S.begin(), S.end());

    if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	
	char a;
	cin>>a;
	int x=int(a-'a'),y=int(a-'A');
	if(x>=0&&x<26)
	cout<<"a"<<endl;
	else
	cout<<"A"<<endl;
	
	return 0;
}

Measured memory_bytes: 3588
q=int(input())
M=100000

import math
def erato(n):
    prime=[]
    cnt=[0]*n
    limit=math.sqrt(n)
    data=[i+1 for i in range(1,n)]
    while True:
        p=data[0]
        if limit<=p:
            return prime+data
        prime.append(p)
        data=[e for e in data if e%p!=0]

prime=erato(M)
cnt=[0]*M
for i in range(len(prime)):
  cnt[prime[i]]+=0.6
  if 2*prime[i]-1<M:
    cnt[2*prime[i]-1]+=0.6
 
for i in range(1,M):
  if cnt[i]>1:
    cnt[i]=cnt[i-1]//1+1
  else:
    cnt[i]=cnt[i-1]//1
    
#print(cnt)
for i in range(q):
  l,r=map(int,input().split())
  print(cnt[r]-cnt[l-1])
  

Measured memory_bytes: 8240
#include<stdio.h>

int main(void){
  int i,j,m,f,r;
  char s;

  for(;;){
    scanf("%d%d%d",&m,&f,&r);
    if(m+f+r == -3) break;

    if(m == -1 || f == -1)
      s = 'F';
    else if(m+f >= 80)
      s = 'A';
    else if(m+f >= 65)
      s = 'B';
    else if(m+f >= 50)
      s = 'C';
    else if(m+f >= 30)
      if(r >= 50)
        s = 'C';
      else
        s = 'D';
    else
      s = 'F';

    printf("%c\n", s);
  }
  
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    ll A[3],K; cin >> A[0] >> A[1] >> A[2] >> K;
    ll out=0;
    if(K<=A[0]){
        cout << K << endl;
    }else if(K<=A[0]+A[1]){
        cout << A[0] << endl;
    }else{
        ll tmp=A[0]+A[1];
        cout << A[0]-K+tmp << endl;
    }
    return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
ll dp[11000];
int main()
{
	ll H, N;
	cin >> H >> N;
	pairs(WA)
	fx(N) {
		pairsp(WA);
	}

	fx(11000) {
		dp[x] = INT_MAX/2;
	}
	dp[0] = 0;
	fx(N) {
		fy(H+1) {
			int tar = min(WA[x].first + (ll)y,H);
			dp[tar] = min(dp[tar],dp[y]+WA[x].second);
		}
	}
	ce(dp[H])
    return 0;
}



Measured memory_bytes: 384
N = int(input())
a = [int(input()) for _ in range(N)]
s = sum(a)
m = (s + 1) // 2

c1 = [0] * (m + 1)
c1[m] = 1
for i in range(N):
    d = a[i]
    for j in range(m - d + 1):
        c1[j] = (2 * c1[j] + c1[j + d]) % 998244353
    for j in range(m - d + 1, m + 1):
        c1[j] = (2 * c1[j] + c1[m]) % 998244353

ans1 = c1[0]

if s % 2:
    c1[0] = 0
else:
    for j in range(m):
        c1[j] = 0
    c1[m] = 1
    for i in range(N):
        d = a[i]
        for j in range(m - d + 1):
            c1[j] = (c1[j] + c1[j + d]) % 998244353
        for j in range(m - d + 1, m + 1):
            c1[j] = c1[j]

ans = (3 ** N % 998244353 - 3 * ans1 + 3 * c1[0]) % 998244353
print(ans)

Measured memory_bytes: 42332
class spell:
    def __init__(self, text, dir):
        self.text = text
        self.dir = dir

def isRange(a):
    if(0 <= a < n):
        return True
    else:
        return False

n, q = map(int, input().split())
s = input()

spells = []
for i in range(q):
    text, dir = input().split()
    spells.append(spell(text, dir))


l = -1
r = n

for sp in reversed(spells):
    if(isRange(l+1) and s[l+1] == sp.text and sp.dir == 'L'):
        l += 1
    elif(isRange(l) and s[l] == sp.text and sp.dir == 'R'):
        l -= 1
    if(isRange(r-1) and s[r-1] == sp.text and sp.dir == 'R'):
        r -= 1
    elif(isRange(r) and s[r] == sp.text and sp.dir == 'L'):
        r += 1

print(n-(l+1)-(n-r))


Measured memory_bytes: 37976
#include <bits/stdc++.h>
#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() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  vector<int> cnt(5, 0);
  rep(i, n) {
    switch (s[i][0]) {
      case 'M': ++cnt[0]; break;
      case 'A': ++cnt[1]; break;
      case 'R': ++cnt[2]; break;
      case 'C': ++cnt[3]; break;
      case 'H': ++cnt[4]; break;
      default: break;
    }
  }

  ll ans = 0;
  rep(i, 5) rep(j, 5) rep(k, 5) {
    if (i >= j || j >= k) continue;
    ans += (ll) cnt[i] * cnt[j] * cnt[k];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6372
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

  ll k, a, b;
  cin >> k >> a >> b;

  if(a+2 >= b){
    cout << k+1 << endl;
    return 0;
  }


  ll res = a;
  k -= res-1;
  if(k % 2 == 1) k--, res++;
  res += (b-a)*(k/2);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

def readline():
    return raw_input()

class Dice:
    def __init__(self):
        # [Top,East,North,West,South,Bottom]
        self.sides = [1,3,5,4,2,6]

    def move(self,direction):
        dirdir = { 'North': ([0,2,5,4],[4,0,2,5]),
                   'South': ([0,2,5,4],[2,5,4,0]),
                   'East':  ([0,1,5,3],[3,0,1,5]),
                   'West':  ([0,1,5,3],[1,5,3,0]),
                   'Left':  ([1,4,3,2],[4,3,2,1]),
                   'Right': ([1,4,3,2],[2,1,4,3])
                   }
        def _move(directive):
            b = self.sides[:]
            for i in range(0,4):
                b[directive[0][i]] = self.sides[directive[1][i]]
            self.sides = b
        _move(dirdir[direction])
    
    def top(self):
        return self.sides[0]

while 1:
    n = int(readline())
    if n == 0:
        exit(0)
    d = Dice()
    ans = d.top()
    for i in range(0,n):
        direction = readline()
        d.move(direction)
        ans += d.top()
    print ans

Measured memory_bytes: 4432
#include <bits/stdc++.h>
 
#define int long long
#define EB emplace_back
#define MOD 1000000007
#define F first
#define S second
#define N 100005
#define endl "\n"
 
 
using namespace std; 



    

int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int tt=1;

    //cin>>tt;
    
    while(tt--)
    {
      int n; cin>>n;
      map<int,int> mp;
      for (int i = 0; i < n; ++i)
      {
          int temp; cin>>temp;
          mp[temp]++;
      }
      for(auto x : mp)
      {
        if(x.S>1){
            cout<<"NO";
            return 0;
        }
      }
      cout<<"YES";
    }
        return 0;
}







Measured memory_bytes: 12884
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int ans[maxn];
int main(){
	int n;
	cin>>n;
	int num=0;
	for(int i=0;i<=9;i++){
		ans[i]=num;
		num++;
	}
	for(int i=100;i<=999;i++){
		ans[i]=num;
		num++;
	}
	for(int i=10000;i<=99999;i++){
		ans[i]=num;
		num++;
	}
	ans[100000]=num-1;
	if((1<=n&&n<10)||(100<=n&&n<1000)||(10000<=n&&n<=100000)){
		cout<<ans[n];
	}
	else if(10<=n&&n<100){
		cout<<ans[9];
	}
	else if(1000<=n&&n<10000){
		cout<<ans[999];
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<21);

enum Color {
  WHITE, GRAY, BLACK
};

vector<pair<int, int> > adj[MAX];
int d[MAX];
Color color[MAX];
int n;

void init() {
  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
    d[i] = INFTY;
  }
}

void dijkstra(int s) {
  init();
  d[s] = 0;
  priority_queue<pair<int, int> > PQ;
  PQ.push(make_pair(0, s));

  while (!PQ.empty()) {
    pair<int, int> f = PQ.top(); PQ.pop();
    int u = f.second;
    color[u] = BLACK;

    if (d[u] < f.first * (-1)) continue;

    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j].first;
      if (color[v] == BLACK) continue;
      if (d[u] + adj[u][j].second < d[v]) {
        d[v] = d[u] + adj[u][j].second;
        PQ.push(make_pair(d[v] * (-1), v));
        color[v] = GRAY;
      }
    }
  }
}


int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int elem, index, v;
    cin >> v >> elem;
    for (int j = 0; j < elem; j++) {
      int u, cost;
      cin >> u >> cost;
      adj[v].push_back(make_pair(u, cost));
    }
  }
  dijkstra(0);
  for (int i = 0; i < n; i++) {
    cout << i << " " << d[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 8016
import numpy as np

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

AC = np.array([0]*N)
WA = np.array([0]*N)

for i in range(M):
    p,S = input().split()
    if AC[int(p)-1] ==0 and S == "WA":
       WA[int(p)-1] += 1
    else:
        AC[int(p)-1] = 1


print(sum(AC),sum(AC*WA))

Measured memory_bytes: 16732
N=int(input())
s=list(map(int,input().split()))
ans=0
for i in range(0,N-2):
  if (s[i]<s[i+1]<s[i+2]) or (s[i]>s[i+1]>s[i+2]):
    ans=ans+1
    
print(ans)
    

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;

  ll n = s.size();

  ll ans = 0;

  rep(i,n){
    if(s.at(i)!=t.at(i)) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
        a[i] = 4*m * a[i];
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] >= sum)
            cnt++;
    }
    if (cnt >= m)
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
  
    return 0;
}

Measured memory_bytes: 3628
// https://atcoder.jp/contests/code-festival-2017-quala/tasks/code_festival_2017_quala_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#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()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, K;
    cin >> N >> M >> K;
    REP(i, N + 1) REP(j, M + 1) {
        int sum = i * M + j * N - i * j * 2;
        if (sum == K) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


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

int main() {
  int n; cin >> n; double x[n], y[n];
  for(int i=0; i<n; i++) cin >> x[i] >> y[i];
  
  int dd[n]; for(int i=0; i<n; i++) dd[i] = i;
  double sm=0;
  
  do {
    //for(int x:dd) cout << x << " ";
    double s0=0;
    for(int i=0; i<n-1; i++) {
      int fr = dd[i], nx = dd[i+1];
      s0 += sqrt((x[fr] - x[nx]) * (x[fr] - x[nx]) +
        (y[fr] - y[nx]) * (y[fr] - y[nx]));
    }
    //cout << s0 << endl;
    sm += s0;
  } while(next_permutation(dd, dd+n));
  
  for(int i=1; i<=n; i++) sm /= (double)i;
  
  cout << fixed << setprecision(10);
  cout << sm << endl;
}


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

int main(){
  int NN;string s;
  cin >> NN;
  long long int M=0,A=0,R=0,C=0,H=0;
  for(int i=0;i<NN;i++){
    cin >> s;
    if(s[0]=='M')M++;
    else if(s[0]=='A')A++;
    else if(s[0]=='R')R++;
    else if(s[0]=='C')C++;
    else if(s[0]=='H')H++;
  }
  long long sum=0;
  sum+=M*A*R
      +M*A*C
      +M*A*H
      +M*R*C
      +M*R*H
      +M*C*H
      +A*R*C
      +A*R*H
      +A*C*H
      +R*C*H;

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256