akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
ll from, to, cost;
bool operator<(const E &b) const { return cost < b.cost; }
bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
template<typename T>
void print_vec(vector<T>a) {
	for (int i = 0; i < a.size(); i++) {
		cout << (i == 0 ? "" : " ") << a[i];
	}
	cout << endl;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
vector<int>e[200000];
int d[200000];
int dp[200000];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		e[u].push_back(v);
		d[v]++;
	}
	queue<int>q;
	for (int i = 1; i <= n; i++) {
		if (d[i] == 0) {
			q.push(i);
		}
	}
	vector<int>l;
	while (!q.empty()) {
		int t = q.front(); q.pop();
		l.push_back(t);
		for (int i = 0; i < e[t].size(); i++) {
			d[e[t][i]]--;
			if (d[e[t][i]] == 0) {
				q.push(e[t][i]);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < l.size(); i++) {
		int t = l[i];
		ans = max(ans, dp[t]);
		for (int i = 0; i < e[t].size(); i++) {
			dp[e[t][i]] = max(dp[t] + 1, dp[e[t][i]]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 11380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repe(i, n) for(int (i) = 0; i <= (n); (i)++)
#define repr(i, n) for(int (i) = (n); (i) > 0; --(i))
#define repre(i, n) for(int (i) = (n); (i) >= 0; --(i))
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string s;
    cin >> s;
    vector<uint64_t> a((s.size() + 1), 0);
    rep(i, s.size()){
        if(s[i] == '<'){
            a[i+1] = a[i] + 1;
        }
    }
    repre(i, s.size()){
        if(s[i] == '>'){
            a[i] = max(a[i+1] + 1, a[i]);
        }
    }

    uint64_t sum = 0;
    repe(i, s.size())sum += a[i];
    cout << sum << endl;
}


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

int main()
{
	priority_queue<int> que;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a, b, c;
		for (int j = 0; j < 3; j++)
		{
			cin >> a;
			que.push(a);
		}
		a = que.top();
		que.pop();
		b = que.top();
		que.pop();
		c = que.top();
		que.pop();
		if (a*a==b*b+c*c)
			cout << "YES"<<endl;
		else
			cout << "NO"<<endl;
	}
	return 0;
}

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

int main(void) {
    long h, w, n;
    cin >> h >> w >> n;

    vector<long> res(10);
    set<pair<long,long>> s;

    for(long i=0; i<n; i++) {
        long a, b;
        cin >> a >> b;
        a--, b--;
        for(long dy=-2; dy<=0; dy++)
        for(long dx=-2; dx<=0; dx++) {
            if(!(0 <= a+dy && a+dy+2 < h && 0 <= b+dx && b+dx+2 < w))
                continue;

            long c = 0;
            for(long i=0; i<3; i++)
            for(long j=0; j<3; j++)
                if(s.count({a+dy+i, b+dx+j})) c++;
            res[c]--, res[c+1]++;
        }
        s.insert({a, b});
    }

    res[0] = (w-2)*(h-2) + res[0];
    for(auto &e: res) cout << e << endl;
    
}


Measured memory_bytes: 6528
#include <stdio.h>
typedef struct node{
  int p,l,r,key;
} node;

node heap[1000];

int parent(int x){
  return (x/2);
}

int left(int x){
  return 2*x;
}

int right(int x){
  return 2*x+1;
}


int main(){
  int hs,i;
  int m=2000000001;

  for(i=0;i<=999;i++){
    heap[i].key=m;
  }

  scanf("%d",&hs);
  for(i=1;i<=hs;i++){
    scanf("%d",&heap[i].key);
  }
  for(i=1;i<=hs;i++){
    heap[i].p = heap[parent(i)].key;
    heap[i].l = heap[left(i)].key;
    heap[i].r = heap[right(i)].key;
  
     printf("node %d: key = %d, ",i,heap[i].key);
     if(heap[i].p!=m){
       printf("parent key = %d, ",heap[i].p);
     }
     if(heap[i].l!=m){
       printf("left key = %d, ",heap[i].l);
     }
     if(heap[i].r!=m){
       printf("right key = %d, ",heap[i].r);
     }
     printf("\n");
  }

  return 0;
}

Measured memory_bytes: 616
from collections import deque


def main():
    # N = int(input())
    # N,= [int(a) for a in input().split()]
    # N, M = [int(a) for a in input().split()]

    # a = []
    # # b = []
    # c = []
    #
    # for _ in range(M):
    #     aa, bb = [int(a) for a in input().split()]
    #     cc = [int(a) for a in input().split()]
    #     a.append(aa)
    #     # b.append(bb)
    #     c.append(cc)
    N, M = [int(a) for a in input().split()]

    AB = [
        [int(a) for a in input().split()]
        for _ in range(M)
    ]

    pp = [[] for _ in range(N)]
    for a, b in AB:
        pp[a - 1].append(b - 1)

    startpool = set(range(N))

    result = None

    while len(startpool) != 0:
        start = min(startpool)

        q = deque([(start, [start])])
        renketu = {start}
        while len(q) != 0:
            p, history = q.popleft()
            target = pp[p]
            for t in target:
                if t in history:
                    if result is None:
                        result = history
                    elif len(result) > len(history) - history.index(t):
                        result = history[history.index(t):]
                if t not in renketu:
                    q.append([t, history + [t]])

                renketu.add(t)
        startpool -= renketu

    if result is not None:
        print(len(result))
        for a in result:
            print(a + 1)
        return
    else:
        print(-1)


if __name__ == "__main__":
    main()


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

int main() {
  int A[3];
  for(int i = 0;i < 3;i++){
  cin >> A[i];
  }
  
  sort(A,A + 3);
  
  int ans = abs(A[1] - A[2]) + abs(A[0] - A[1]);
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl "\n"
#define rep(i , a , b) for (int i=a; i<(b); i++)
#define re0(i , a)     for (int i=0; i<(a); i++)
using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
typedef long double ld;

const int mod=7+1e9;
const int inf=1e9;
const int N=1e5+5;
int a[N],b[N],c[N],n;
int dp[N][4];
int f(int i,int pre)
{
    if(i>=n)return 0;
    int &ret=dp[i][pre];
    if(ret!=-1)return ret;

    if(pre!=1)ret=max( ret , a[i]+f(i+1,1) );
    if(pre!=2)ret=max( ret , b[i]+f(i+1,2) );
    if(pre!=3)ret=max( ret , c[i]+f(i+1,3) );

    return ret;
}
int main()
{
#ifdef LOCAL
   freopen("input.in", "r", stdin);
#endif // ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    re0(i,n)
        cin>>a[i]>>b[i]>>c[i];
    memset(dp,-1,sizeof dp);
    cout<<f(0,0);
}



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

int main() {
  ll N, P;
  cin >> N >> P;
  ll max=0;
  for (ll i=pow(P,1.0/N)+1; i>=1; i--) {
    if (P % ll(pow(i, N)) == 0) {
      cout << i <<endl; 
      return 0;
    }
  }
        
}

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

int main() {
    int n;
    cin >> n;
    int res = 0;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        res += r - l + 1;
    }
    cout << res << endl;
    return 0;
}

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

const char nl = '\n';

void solve()
{
    int d; cin >> d;
    vector<int> c;
    for (int i = 0; i < 26; ++i) {
        int val; cin >> val;
        c.push_back(val);
    }
    for (int i = 0; i < d; ++i) {
        map<int, int, greater<int>> m;
        for (int j = 0; j < 26; ++j) {
            int val; cin >> val;
            m[val] = j + 1;
        }
        cout << m.begin()->second << nl;
    }
}

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

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;



int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  if (n%3==1) {
    rep(i,n) if (a.at(i)!=0) {cout << "No" << endl;return 0;}
    cout << "Yes" << endl;
    return 0;
  }
  if (n%3==2) {
    rep(i,n/3+1) if (a.at(i)!=0) {cout << "No" << endl;return 0;}
    for (int i=n/3+2;i<n;i++) {
      if (a.at(i)!=a.at(i-1)) {cout << "No" << endl;return 0;}
    }
    cout << "Yes" << endl;
    return 0;
  }
  ll p=n/3;
  for (int i=1;i<p;i++){
    if (a.at(i-1)!=a.at(i)) {cout << "No" << endl;return 0;}
  }
  for (int i=p+1;i<p*2;i++){
    if (a.at(i-1)!=a.at(i)) {cout << "No" << endl;return 0;}
  }
  for (int i=2*p+1;i<p*3;i++){
    if (a.at(i-1)!=a.at(i)) {cout << "No" << endl;return 0;}
  }
  ll a1=a.at(p)^a.at(2*p),a2=a.at(0)^a.at(2*p),a3=a.at(0)^a.at(p);
  //cout << a1 << " " << a2 << " " << a3 << endl;
  if (a.at(0)==a1 && a.at(p)==a2 && a.at(2*p)==a3) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))

MOD=10**9+7
rgb=[-1]*3

count=1
buf=0
for i in range(n):
    c=0
    for j in range(3):
        if rgb[j]+1==a[i]:
            c+=1
            buf=j
    #print(rgb,c)
    count*=c
    count%=MOD
    rgb[buf]+=1
print(count)

Measured memory_bytes: 53868
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs_vis(int);
void dfs(void);
void visit(int);

int M[N][N],n;
int color[N],cnt,d[N],f[N]; /*ttはタイムカウンター*/

int main()
{
  int u,k,v,i,j;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      M[i][j] = 0;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

void dfs(void){
  int u;

  for(u = 0; u < n; u++)color[u] = WHITE;
  cnt = 0;

  for(u = 0; u < n; u++){
    if(color[u] == WHITE)dfs_vis(u);
  }
  for(u = 0; u < n; u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

void dfs_vis(int u){
  int v;
  
  color[u] = GRAY;
  d[u] = ++cnt;
  for(v = 0; v < n; v++){
    if(M[u][v] == 0)continue;
    if(color[v] == WHITE){
      dfs_vis(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++cnt;
}



Measured memory_bytes: 2132
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
//#define MAX 200001
using namespace std;
using ll = long long;

const int MOD = 1000000007;
const int MAX = 9999999;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//a^nをpで割ったあまり
ll modPow(ll a, ll n, ll p) {
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*a % p;
        a = a*a % p;
        n = n >> 1;
    } 
    return ans;
}

//nCrをMODで割った余り
ll nCr(ll n, ll r,ll mod){
    ll ans=0,x=1,y=1;
    for(ll i=1;i<=r;i++){
        x=x*(n-i+1)%mod;
        y=y*i%mod;
    }
    ans=x*modPow(y,mod-2,mod);
    return ans;
}

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

    ll n,a,b;
    cin >> n >> a >> b;
    ll ans=0;
    ans=modPow(2,n,MOD)-nCr(n,a,MOD)-nCr(n,b,MOD)-1;
    while (ans < 0) ans += MOD;
    cout << ans;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
	char str[100000] = { 0 };
	int i,j;
	int len = 0;
	j = 0;
	scanf("%s", str);
	while (str[len]) {
		len++;
	}
	for (i = 0; i+1 < len; i++) {
		if (str[i] != str[i + 1]) {
			j++;
		}
	}
		
	printf("%d\n", j);

	return 0;
}


Measured memory_bytes: 256
require 'scanf'

while line = gets
  s = line.split(',').map(&:to_i)
  l = s[0..9]
  v1 = s[10]
  v2 = s[11]
  d = l.inject(:+).to_f * v1 / (v1 + v2)
  sum = 0;
  for i in 1..10
    sum += l[i-1]
    if d <= sum
      puts i.to_s
      break
    end
  end
end

Measured memory_bytes: 8936
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int main(){
  int n;
  cin >> n;
  if(n%111==0)cout << n << endl;
  else cout << (n/111+1)*111 << endl;
  return 0;
}


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

int main() {
    int weight;
    while (cin >> weight) {
        bool spaceFlag = false;
        for (int i = 0; weight > 0; weight /= 2, i++) {
            if (weight % 2 == 1) {
                if (i > 0 && spaceFlag) {
                    cout << " ";
                }
                cout << pow(2, i);
                spaceFlag = true;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 0
l = [int(input()) for _ in range(5)]
k = int(input())
max_dist = 0
max_dist = max(max_dist,l[4]-l[3])
max_dist = max(max_dist,l[4]-l[2])
max_dist = max(max_dist,l[4]-l[1])
max_dist = max(max_dist,l[4]-l[0])
max_dist = max(max_dist,l[3]-l[2])
max_dist = max(max_dist,l[3]-l[1])
max_dist = max(max_dist,l[3]-l[0])
max_dist = max(max_dist,l[2]-l[1])
max_dist = max(max_dist,l[2]-l[0])
max_dist = max(max_dist,l[1]-l[0])
if max_dist > k:
    ans = ':('
else:
    ans = 'Yay!'
print(ans)

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

int main() {
	int n, k;
	cin >> n >> k;
	int h[n];
	for (int i = 0; i < n; i++)
		cin >> h[i];
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = INT_MAX;
		for (int j = 1; j <= k && i - j >= 0; j++)
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
	}
	cout << dp[n - 1] << endl;
}


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    s[k-1] = s[k-1] - 'A' + 'a';
    cout << s;
    return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define reps(i,s,n) for(int (i) = (s); (i) < (n); ++(i))
#define rep(i,n) reps(i,0,n)
using ll = long long;
     
const int mod = 1e9+7;

int main(){
	int n;
	cin >> n;
	vector<int> a(n,0),b;
	rep(i,n){ 
		cin >> a[i];
	}

	for(int i = n-(n%2)-1; i >= 0; i-=2){
		b.push_back(a[i]);
		//cout << i << endl;
	}	

	for(int i = 0; i < n; i+=2){
		b.push_back(a[i]);
		//cout << i << endl;
	}

if(n % 2 == 1){
	reverse(b.begin(),b.end());
}


	rep(i,n){
		cout << b[i];
		if(i!=n) cout << " ";
	}
	cout << endl;
	return 0;
}

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

int main()
{
	int64_t s;
	cin >> s;
	set<int64_t> st;
	auto f = [](int64_t n) {
		if (n % 2 == 0)
		{
			return n / 2;
		}
		else
		{
			return 3 * n + 1;
		}
	};
	int ans = 1;
	while (st.find(s) == st.end())
	{
		st.insert(s);
		s = f(s);
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

int N, Q;
vector<vector<int>> E;
vector<int> ADD;
vector<int> RET;
vector<bool> VISITED;

void rec(int node, uint64_t add) {
    if(VISITED[node])
        return;
    add += ADD[node];
    RET[node] += add;
    VISITED[node] = true;
    for(auto n: E[node]) {
        rec(n, add);
    }
}

int main() {
    cin >> N >> Q;
    E.resize(N);
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        E[a-1].push_back(b - 1);
        E[b-1].push_back(a - 1);
    }
    ADD.resize(N);
    rep(i, Q) {
        int p, x;
        cin >> p >> x;
        ADD[p-1] += x;
    }

    RET.resize(N);
    VISITED.resize(N);
    rec(0, 0);
    for(auto n: RET) {
        cout << n << " ";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 21572
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    P.sort()
    print(sum(P[:K]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9160
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000

int main(){
    char S[101];
    cin >> S;
    int len = strlen(S);
    int tb[26] = {};
    REP1(i,len){
        tb[S[i]-'a']++;
    }
    int sum = 0;
    REP1(i,26){
        sum += tb[i]%2;
    }
    if(sum){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    int i,c1=0,c2=0,c3=0,c4=0;
  Scanner obj=new Scanner(System.in);
    int n=Integer.parseInt(obj.nextLine());
    String a[]=new String[n];
    for(i=0;i<n;i++)
      a[i]=obj.nextLine();
    for(i=0;i<n;i++)
    {
      switch(a[i])
      {
        case "AC":
          c1++;
          break;
        case "WA":
          	c2++;
          break;
        case "TLE":
          	c3++;
          	break;
        case "RE":
          c4++;
          break;
      }
      }
    System.out.println("AC x "+c1);
    System.out.println("WA x "+c2);
    System.out.println("TLE x "+c3);
    System.out.println("RE x "+c4);
    }
  }

Measured memory_bytes: 56080
#include <iostream>
using namespace std;
int main(){
    int a,b,c,d,e,f,g,s;
    cin>>a;
    int x[a];
    for(b=0;b<a;b++){
        cin>>x[b];
    }
    cin>>c;
    for(d=0;d<c;d++){
        cin>>e>>f;
        s=0;
        for(g=0;g<a;g++){
            if(g+1==e){
                s=s+f;
            }
            else{
                s=s+x[g];
            }
        }
        cout<<s<<endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf

const int MAXN = 105000;

int n;
int a[MAXN];
map <int, int> odd, even;
vector < pair<int, int> > oddV, evenV;

int main() {

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

  for (int i = 0; i < n; i += 2) {
    even[a[i]]++;
  }
  for (int i = 1; i < n; i += 2) {
    odd[a[i]]++;
  }

  for (auto p : odd) {
    oddV.push_back(make_pair(p.second, p.first));
  }
  for (auto p : even) {
    evenV.push_back(make_pair(p.second, p.first));
  }

  sort(all(oddV)); 
  reverse(all(oddV));

  sort(all(evenV));
  reverse(all(evenV));

  if (sz(oddV) == 1) {
    oddV.push_back(make_pair(0, -1));
  }
  if (sz(evenV) == 1) {
    evenV.push_back(make_pair(0, -2));
  }

  int ans = n;

  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      if (oddV[i].second == evenV[j].second) {
        continue;
      }
      ans = min(ans, n - oddV[i].first - evenV[j].first);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6520
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define MP make_pair
#define PB push_back
typedef long long LL;
const LL P = 998244353;
const int N = 1e5+10;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,l[N],r[N],cnt[N];
string s;

int main(){
	cin>>s;
	n = s.size();
	stack<int> stk;
	rep(i,0,n-1){
		if(s[i]=='R')stk.push(i);
		else{
			while(!stk.empty()){
				r[stk.top()] = i;
				stk.pop();
			}
		}
	}
	rrep(i,n-1,0){
		if(s[i]=='L')stk.push(i);
		else{
			while(!stk.empty()){
				l[stk.top()] = i;
				stk.pop();
			}
		}
	}
	//rep(i,0,n-1)cout<<r[i]<<" ";cout<<endl;
	//rep(i,0,n-1)cout<<l[i]<<" ";cout<<endl;
	rep(i,0,n-1){
		if(s[i]=='R'){
			int x = (r[i] - i)%2 ? r[i]-1 : r[i];
			++cnt[x];
		}else{
			int x = (i - l[i])%2 ? l[i]+1 : l[i];
			++cnt[x];
		}
	}
	rep(i,0,n-1)printf("%d ",cnt[i]);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

long long gcd(long long a, long long b){
	return (b ? gcd(b, a%b) : a);
}

int main(){
	
	ios::sync_with_stdio(false); cin.tie(0);
	long long a, b; cin >> a >> b;

	cout << a*b/gcd(a, b) << '\n';

	return 0;
}

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

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m;
int a[N];

bool read() {
    if (!(cin >> n))
        return false;

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

    return true;
}

void solve() {
    vector<int> biba;
    multiset<int> boba;

    for (int i = 0; i < (1 << n); ++i)
        boba.insert(-a[i]);

    biba.emplace_back(*boba.begin());
    boba.erase(boba.begin());

    while (n --> 0) {
        auto m = biba.size();

        for (int i = 0; i < m; ++i) {
            auto it = boba.upper_bound(biba[i]);
            
            if (it == boba.end()) {
                cout << "No\n";
                return ;
            }

            biba.emplace_back(*it);
            boba.erase(it);
        }

        sort(biba.begin(), biba.end());
    }

    cout << "Yes\n";
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}


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

int main() {
  int64_t N,x,ans=0,zero=0; cin>>N>>x;
  vector<int64_t> A(N);
  rep(i,N) cin>>A.at(i);
  int64_t temp=A.at(0);
  if(temp>x){
    ans+=temp-x;
    temp=x;
  }
  for(int i=1;i<N;i++){
    if(A.at(i)+temp>x){
      ans+=A.at(i)-(x-temp);
      A.at(i)=(x-temp);
    }
    temp=A.at(i);
  }
  cout<<ans;
}


Measured memory_bytes: 3972
<?php
  list($a,$b,$c)=explode(" ",trim(fgets(STDIN)));
$nanko=intval(floor($a/($b+$c)));
$nokori=$a%($b+$c);
$sosu=$nanko*$b;
if($nokori<$b){
   $sosu+=$nokori;
}else{
   $sosu+=$b;
}
echo $sosu;

Measured memory_bytes: 16160
H, W = map(int, input().split())
S = [[i for i in input()] for j in range(H)]
dp = [[0 for i in range(W)] for j in range(H)]
if S[0][0] == "#":
    dp[0][0] = 1

for i in range(1, H):
    if S[i-1][0] == "." and S[i][0] == "#":
        dp[i][0] = dp[i-1][0] + 1
    else:
        dp[i][0] = dp[i-1][0]

for j in range(1, W):
    if S[0][j-1] == "." and S[0][j] == "#":
        dp[0][j] = dp[0][j-1] + 1
    else:
        dp[0][j] = dp[0][j-1]

for h in range(1, H):
    for w in range(1, W):

        if S[h][w] == "#":
            if S[h-1][w] == ".":
                c1 = dp[h-1][w] + 1
            else:
                c1 = dp[h-1][w]

            if S[h][w-1] == ".":
                c2 = dp[h][w-1] + 1
            else:
                c2 = dp[h][w-1]

            dp[h][w] = min(c1, c2)

        else:
            dp[h][w] = min(dp[h-1][w], dp[h][w-1])

print(dp[H-1][W-1])

Measured memory_bytes: 3316
#include <bits/stdc++.h>//..1..2..3:Correct:Solved by F2tekkz:)
#define ll long long
#define str string
#define sonic ios_base::sync_with_stdio(0)
using namespace std;
ll n , m , k , i , j , t , q , cnt , cnt1 , cnt2 , cnt3;
ll cnt4 , cnt5 , ans , ans1 , ans2 , ans3 , sum , sum1 , sum2;
ll mini = 1e9 , maxi = -999;
int main(){
	sonic;
	cnt = 0;
	cin >> n >> m;
	ll a[n];
	for(i = 0 ; i < n ; i ++){
		cin >> a[i];
		if(a[i] <= 0){
			a[i] = 0;
		}
	}
	sort(a , a + n);
	if(m == 0){
		for(i = 0 ; i < n ; i ++){
			cnt += a[i];
		}
		cout << cnt;
		return 0;
	}
	if(m >= n){
		cout << 0;
		return 0;
	}
	if(m > 0 && m < n){
		for(i = 0 ; i < n - m ; i ++){
			cnt += a[i];
		}
		cout << cnt;
		return 0;
	}
}
//     *    *  *  ****    *    *   *
//    *	*   * *   *      * *   *   *
//   *****  **    ****  *****  *****
//   *   *  * *      *  *   *      *
//   *   *  *  *  ****  *   *  *****

//   *  *  *****  *
//   * *     *    *
//   **      *    *
//   * *     *    *
//   *  *    *    ****

//   ****  ****  *       *
//   *      **   *      * *
//   ****   **   *     *****
//      *   **   *     *   *
//   ****  ****  ****  *   *


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

int memo[112345];
int n, k, a[110];

bool dp(int l)
{
    if (memo[l] != -1)
        return memo[l];

    bool res = false;

    REP(i, n)
    {
        if (l >= a[i])
            res |= !dp(l - a[i]);
    }

    memo[l] = res;

    return res;
}

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

    cin >> n >> k;
    REP(i, n)
    cin >> a[i];

    fill(memo, memo + k + 1, -1);

    REP(i, n)
    memo[a[i]] = 1;

    memo[0] = 0;

    cout << (dp(k) ? "First" : "Second") << endl;

    return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

const int N = 300010;
int n;
vi p(N);
vi ans;

void solve(int l, int r, int a, int b) {
	if (a < 1 || b < 1) {
		cout << -1 << endl;
		exit(0);
	}
	if (b > a) {
		for (int i = max(r - a, l); i < r; i++) {
			ans.push_back(p[i]);
			if (ans.size() >= n) {
				return;
			}
		}
		for (int i = min(l + (b - 1) - 1, r - a - 1); i >= l; i--) {
			ans.push_back(p[i]);
			if (ans.size() >= n) {
				return;
			}
		}
		solve(l + b - 1, r - a, a - 1, b - 1);
	}
	else {
		for (int i = min(l + b - 1, r - 1); i >= l; i--) {
			ans.push_back(p[i]);
			if (ans.size() >= n) {
				return;
			}
		}
		for (int i = max(r - (a - 1), l + b) ; i < r; i++) {
			ans.push_back(p[i]);
			if (ans.size() >= n) {
				return;
			}
		}
		solve(l + b, r - a + 1, a - 1, b - 1);
	}
}

int main() {
	int a, b;
	cin >> n >> a >> b;
	rep1(i, n) {
		p[i - 1] = i;
	}
	if (a + b > n + 1) {
		cout << -1 << endl;
		return 0;
	}
	solve(0, n, a, b);
	rep(i, n) {
		cout << ans[i] << " ";
	}
	cout << endl;

}


Measured memory_bytes: 4720
n= int(input())
s= [input().split() for _ in range(n)]
x= input()
cnt=1
ans=0
for i in range(n):
  if x!=s[i][0]:
    cnt += 1
  else:
    break
for l in range(cnt,n):
  ans += int(s[l][1])
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int answer(int a[], int n);

int main(void)
{
        int a[200],n,i,s;

        scanf("%d",&n);
        for (i=0;i<n;i++)
                scanf("%d",&a[i]);

        while(answer(a,n)==1)
                s++;

        printf("%d\n",s);

        return 0;
}
int answer(int a[], int n)
{
        int i;

        for (i=0;i<n;i++)
                if (a[i]%2==0)
                        a[i]=a[i]/2;
                else
                        return 0;

        return 1;
}


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

long long handstand2(int n) {
  long long memo[10][10];
  for(int i=0;i<10;i++) {
    for(int j=0;j<10;j++) {
      memo[i][j]=0;
    }
  }
  for(int i=1;i<=n;i++) {
    if(i>0 && i<10) {
      memo[i][i] += 1;
      continue;
    }
    string s = to_string(i);
    int a = s[0] - '0';
    int b = s[s.size() - 1] - '0';
    // cout << "i: " << i << "a, b: " << a << ", " << b << endl;  
    memo[a][b] += 1;
  }
  long long  ans = 0;
  for(int a=0;a<10;a++) {
    for(int b=0;b<10;b++) {
      ans += memo[a][b] * memo[b][a];
    }
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  cout << handstand2(n);
}


Measured memory_bytes: 256
n,k=gets.split.map(&:to_i)
l,r=k.times.map{gets.split.map(&:to_i)}.transpose

dp=Array.new(n,0)
dp[0]=1
dp[1]=-1
n.times do |i|
  dp [i] += dp[i-1] if i>0
  k.times do |j|
    a=l[j]
    b=r[j]+1
    dp[i+a]+=dp[i]%998244353 if i+a<n
    dp[i+b]-=dp[i]%998244353 if i+b<n
  end
end

puts dp[n-1]%998244353


Measured memory_bytes: 15888
import sys
input = sys.stdin.readline
import bisect
    
def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)

    for target in b_sorted:
        #mid_a = binary_search_left(a_sorted,target)
        #mid_c = binary_search_right(c_sorted,target)
        mid_a = bisect.bisect_left(a_sorted,target)
        mid_c = bisect.bisect_right(c_sorted,target)
        count += mid_a * (maxlen - mid_c)
        #print("mid_a %d, mid_c %d, count %d" %(mid_a,maxlen - mid_c,count))
    return count

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print(snuke_festival(a,b,c))


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

int main(){
	unsigned long long int w, h;
	int	x, y, ans = 0;
	cin >> w >> h >> x >> y;
	if (x == w / 2.0 && y == h / 2.0) ans = 1;
	printf("%lf %d\n", w*h / 2.0, ans);
	return 0;
}

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

using namespace std;
typedef long long ll;

ll factorial(int n){
    if(n==1)return 1;
    else return n + factorial(n-1); 
}

int main(){
    int x;
    cin >> x;
    //cout << factorial(x) << endl;
    for(int i=1;;i++){
        if(factorial(i)>=x){cout << i << endl;break;}
    }
    return 0;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int k,n;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> k >> n;
  int ma = 0;
  R(i,n){
    int pom;
    cin >> pom;
    maxi(ma,pom);
  }
  if(k & 1){
    cout << max(0ll, ma - (k+1) / 2) * 2;
  }else{
    cout << max(0ll, (ma - k / 2) * 2 - 1);
  }
  cout << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define maxn 1000000+5
using namespace std;
const long long mod = 200907;
int a[maxn],b[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    long long int suma=0,sumb=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        suma+=a[i];
    }
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
        sumb+=b[i];
    }
    if(sumb>suma){
        printf("-1");
        return 0;
    }
    vector<int>m;int flag=0,eq=0;
    long long int ls=0;
    for(int i=0;i<n;i++){
        if(b[i]==a[i])eq++;
        else if(b[i]>a[i]){
            flag++;
            ls+=b[i]-a[i];
        }else m.push_back(a[i]-b[i]);
    }
    //cout<<flag<<endl;
    if(flag==0){
        printf("0");return 0;
    }
    sort(m.begin(),m.end());
    int ans=0;
    for(int i=m.size()-1;i>=0;i--){
        ls-=m[i];
        ans++;
        if(ls<=0)break;
    }
    printf("%d",ans+flag);
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    ll n;
    cin >> n;
    ll s_fromleft[n];
    ll s_fromright[n];
    string st;
    cin >> st;
    ll cnt = 0;
    rep(i,n)
    {
        s_fromleft[i] = cnt;
        if (st[i]=='W')
            cnt++;
    }
    
    cnt = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        s_fromright[i] = cnt;
        if (st[i]=='E')
            cnt++;
        //cout << s_fromright[i] << endl;
    }
    ll ans = INF;
    rep(i, n)
    {
        ans = min(ans,s_fromleft[i] + s_fromright[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5380
//深さ優先で、距離を+していけば良い
//xとyそれぞれについて

#include<iostream>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;
typedef vector< vector< pair<long long,long long> > > vvp;

void dfs(vvp& tree,vector<ll>& tree_len,vector<bool>& check,ll dep,ll now){
  tree_len[now]=dep;
  check[now]=true;
  ll l=tree[now].size();
  for(int i=0;i<l;i++){
    if(check[tree[now][i].first]==false) dfs(tree,tree_len,check,dep+tree[now][i].second,tree[now][i].first);
  }
}

int main(){
  ll n;cin >> n;
  vvp tree(n);//Nodeから伸びる辺の情報
  vector<ll> tree_len(n,0);//最短経路保持
  vector<bool> check(n,false);//辿ったかどうか(いらない説も)
  //nにして入力終わらねえってなった
  for(int i=0;i<n-1;i++){
    ll a,b,c;cin >> a >> b >> c;
    tree[a-1].push_back(make_pair(b-1,c));
    tree[b-1].push_back(make_pair(a-1,c));
  }
  ll q,k;cin >> q >> k;
  dfs(tree,tree_len,check,0,k-1);
  for(int i=0;i<q;i++){
    ll x,y;cin >> x >> y;
    cout << tree_len[x-1]+tree_len[y-1] << endl;
  }
}


Measured memory_bytes: 17408
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
#define rep(i, s, n) for(int i(s); i < int(n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;

i64 a[100010];
pii p[100010];

signed main()
{
  iostreamBooster();
  int N, M;
  cin >> N >> M;

  priority_queue<i64, vector<i64>, greater<i64>> pq;

  rep(i, 0, N) {
    cin >> a[i];
    pq.emplace(a[i]);
  }

  rep(i, 0, M) {
    int b, c;
    cin >> b >> c;
    p[i] = pii(c, b);
  }

  sort(p, p+M, greater<pii>());

  for (const auto &e : p) {
    i64 newVal = e.first;
    i64 lim = e.second;

    for (int i = 0; i < lim && pq.top() < newVal; ++i) {
      pq.pop();
      pq.emplace(newVal);
    }
  }

  i64 sum = 0;
  while(!pq.empty()) {
    sum += pq.top();
    pq.pop();
  }

  cout << sum << endl;

  return 0;
}



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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<string> s(N); rep(i, N) cin >> s[i];
  ll ans = 0;
  vector<ll> cnt(7,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;
    }
  }
  //  rep(i, 5) cerr << cnt[i]; cerr << endl;
  
  rep(i, 5) rep(j, 5) rep(k, 5) {
    if(i >= j || j >= k || i >= k) continue;
    //    cerr << i << j << k << endl;
    ans += cnt[i] * cnt[j] * cnt[k];
  }

  
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


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

int main(){
  int N;
  cin >> N;
  vector<int> d(N),num(110,0);

  rep(i,N){
      cin >> d[i];
  }

  rep(i,N){
      num[d[i]]++;
  }

  int count=0;
  for(int i=1;i<=100;i++){
      if(num[i]){
          count++;
      }
  }

  cout << count <<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    ll n;
    cin>>n>>s;
    ll a[100010]={1};
    rep2(i,1,100010){
        a[i]=a[i-1]*i;
        a[i]%=MOD;
    }
    if(s[0]=='W'||s[2*n-1]=='W'){
        cout<<0<<endl;
        return 0;
    }
    ll b[200010]={0};
    ll W=0;
    rep2(i,1,2*n){
        if(s[i]=='W') W++;
        if(s[i]==s[i-1]){
            b[i]=1-b[i-1];
        }
        else b[i]=b[i-1];
    }
    ll R=0;
    rep(i,2*n){
        if(b[i]==1) R++;
    }
    if(R!=n){
        cout<<0<<endl;
        return 0;
        
    }
    if(W%2==1){
        cout<<0<<endl;
        return 0;
    }
    ll cnt=0,ans=1;
    rep(i,2*n){
        if(b[i]==1){
            ans*=cnt;
            ans%=MOD;
            cnt--;
        }
        else{
            cnt++;
        }
    }
    /*
    rep(i,2*n){
        cout<<b[i];
    }
    cout<<endl;
    */
    ans*=a[n];
    ans%=MOD;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2964
#include <stdio.h>

int
main()
{
	int w, h, x, y, r;	
	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

	int in_rect = x-r >= 0 && x+r <= w && y-r >= 0 && y+r <= h;
	puts(in_rect ? "Yes" : "No");

	return 0;
}

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 3e5 + 5;


    void debug_out() {
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    FAST
   int h1,s1,h2,s2;
    cin>>h1>>s1>>h2>>s2;
    int c=0;
    while(h1>0 && h2>0)
    {
        if(c%2==0)
        h2-=s1;
        else
            h1-=s2;
        c++;
    }
    if(h2<=0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3608
#abc122c

n,q=map(int,raw_input().split())
s=raw_input()
t=[0]*(n+1)
for i in xrange(n):
 if s[i:i+2]=='AC':
  t[i+1]=t[i]+1
 else:
  t[i+1]=t[i]
for i in xrange(q):
 l,r=map(int,raw_input().split())
 print t[r-1]-t[l-1]


Measured memory_bytes: 5252
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	map<int,int> cnt;
	for (int i = 0; i < N; ++ i) {
		int x;
		cin >> x;
		++cnt[x];
	}
	map<int,int> a;
	map<int,int> b;
	for (auto p : cnt) {
		a[p.first % M] += p.second;
		b[p.first % M] += p.second / 2;
	}
	int r = 0;
	for (int i = 0; i <= M-i; ++ i) {
		if (i == 0 || i == M-i) {
			r += a[i] / 2;
		} else {
			int p = min(a[i], a[M-i]);
			r += p;
			a[i] -= p;
			a[M-i] -= p;
			r += min(a[i]/2, b[i]);
			r += min(a[M-i]/2, b[M-i]);
		}
	}
	cout << r << endl;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

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

    map<int,int> m;
    rep(i,N)m[i+1] = a[i];

    int ct = 0;

    for(auto t : m){
        int x = t.F;
        int y = t.S;
        if(m[y] == x)ct++;
    }

    cout << ct/2 << endl;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back 
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	set<char> df;
	for(int i = 0; i < s.length(); i++)df.insert(s[i]);
	if(df.size() == 2)
		cout << "Yes\n";
	else cout << "No\n";

}

Measured memory_bytes: 256