akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll=long long;
#define MOD  1000000007

int main(int argc, char const *argv[]) {
  int a,b,c;
  std::cin >> a >> b >> c;
  if(a==b && a==c) std::cout << "1" << '\n';
  else if(a==b || a==c || b==c) std::cout << "2" << '\n';
  else std::cout << "3" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>a,b;
int c,n,k;
int ans=2147483647;
bool cmp(int a,int b){
	return a>b;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>c;
		if(c>=0)
			a.push_back(c);
		else
			b.push_back(c);
	}
	sort(b.begin(),b.end(),cmp);
	if(a.size()>=k)ans=a[k-1];
	if(b.size()>=k)ans=min(ans,-b[k-1]);
	if(a.size()&&b.size())
		for(int i=0;i<a.size();i++)
			if(k-i-2>=0&&k-i-2<b.size())
				//cout<<i+1<<' '<<k-i-1<<' '<<a[i]-b[k-i-2]+min(a[i],-b[k-i-2])<<endl,
				ans=min(ans,a[i]-b[k-i-2]+min(a[i],-b[k-i-2]));
	cout<<ans;
}

Measured memory_bytes: 1020
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    float ans=0;
    cin>>n;
    if(n==1){
        ans=1;
    }else if(n%2==0){
        ans=0.5;
    }else{
        ans=((n-1)/2+1)/float(n);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

ll powpow(ll in) {
	return in * in * in;
}

signed main()
{
	fastio();
	ll n, k;
	cin >> n >> k;

	if (k % 2 == 0) {
		cout << powpow(n / k) + powpow((n + (k  /2)) / k) << endl;
	}
	else {
		cout << powpow(n / k) << endl;
	}
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;cin>>n>>m;
	debug("debug test\n");
	if(n%500-m>0){
		cout << "No"<<endl;
		return 0;
	}
	cout << "Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)



int main(){



    FAST
//	PRECISE

string s,t;
cin>>s>>t;
ll ans=0;
FOR(i,0,(ll)s.size())
if(s[i]!=t[i])
	ans++;
cout<<ans;



return 0;
 }

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/
 
// DPを用いて最長増加部分列問題を解く
const int MAX_N = 200000;
const int INF = 1e11;
 
int n = 0;
int a[MAX_N];
 
int dp[MAX_N];
 
int solve() {
    fill(dp, dp + n, INF);
    for (int i = 0; i < n; i++) {
        *lower_bound(dp, dp + n, a[i]) = a[i];
    }
    return lower_bound(dp, dp + n, INF) - dp;
}
 
int x_1, y_1, x_2, y_2, N;
int X[200000], Y[200000];
int idx[200000];
 
signed main() {
    cin >> x_1 >> y_1 >> x_2 >> y_2 >> N;
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
        if (abs(x_1 - x_2) == abs(x_1 - X[i]) + abs(x_2 - X[i]) &&
            abs(y_1 - y_2) == abs(y_1 - Y[i]) + abs(y_2 - Y[i])) {
            idx[n] = i;
            n++;
        }
    }
    sort(idx, idx + n,
         [](int l, int r) { return abs(x_1 - X[l]) < abs(x_1 - X[r]); });
    for (int i = 0; i < n; i++) {
        a[i] = abs(y_1 - Y[idx[i]]);
    }
    int s = solve();
    double ans = 100 * (abs(x_1 - x_2) + abs(y_1 - y_2)) - (20 - 5 * M_PI) * s;
    if (min(abs(x_1 - x_2), abs(y_1 - y_2)) + 1 == s) {
        ans += 5 * M_PI;
    }
    cout << fixed << setprecision(15) << ans << endl;
}

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

const int INF = 1 << 25;
int cost[11][11][11][11][55];// depth, pos, l, r, oxy


struct S {
	int depth, pos, l, r, oxy, sum;
	bool operator <(const S& x) const {
		return sum > x.sum;
	}
};
void save(S s, int c) {
	cost[s.depth][s.pos][s.l][s.r][s.oxy] = c;
}
int ret(S s) {
	return cost[s.depth][s.pos][s.l][s.r][s.oxy];
}

int c[10][10];

int main() {
	int W, H, f, M, O;
	while(cin >> W >> H, W + H) {
		cin >> f >> M >> O;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				cin >> c[i][j];
			}
		}

		if(O <= 1) {
			cout << "NA" << endl;
			continue;
		}

		priority_queue<S> q;
		fill((int*)begin(cost), (int*)end(cost), INF);
		for(int j = 0; j < W; j++) {
			S ns = { 0, j, j, j, O - 1, 0 };
			if(c[0][j] < 0) ns.sum = -c[0][j];
			else ns.oxy = min(ns.oxy + c[0][j], M);
			save(ns, ns.sum);
			q.push(ns);
		}

		int ans = INF;
		while(q.size()) {
			S s = q.top();
			q.pop();
			if(s.depth == H - 1) {
				ans = min(ans, s.sum);
				break;
			}
			if(ret(s) < s.sum || s.oxy <= 1) continue;

			for(int i = 0; i < 3; i++) {
				S ns = { s.depth, s.pos, s.l, s.r, s.oxy - 1, s.sum };

				if(i == 0) {
					ns.depth++;
					ns.l = ns.r = ns.pos;
				}
				if(i == 1 && s.pos != 0) {
					ns.pos--;
					if(s.pos == s.l) ns.l--;
				}
				if(i == 2 && s.pos != W - 1) {
					ns.pos++;
					if(s.pos == s.r) ns.r++;
				}

				int x = c[ns.depth][ns.pos];
				if(x < 0) ns.sum -= x;
				else ns.oxy = min(ns.oxy + x, M);

				if(ret(ns) > ns.sum) {
					save(ns, ns.sum);
					q.push(ns);
				}
			}
		}

		if(ans > f) {
			cout << "NA" << endl;
		}
		else {
			cout << ans << endl;
		}
	}
}

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

int main(){
    int n;
    int count_odd = 0;
    int count_even = 0;
    int count_4 = 0;
    cin >> n;

    int a;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a % 2 != 0){
            count_odd++;
        }

        if(a % 4 == 0){
            count_4++;
        }
    }

    count_even = n - count_odd - count_4;

    bool flag = false;

    if(count_even == 0){
        if(count_odd - 1 <= count_4){
            flag = true;
        }
    }
    else{
        if(count_odd <= count_4){
            flag = true;
        }
    }

    if(flag == true){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}

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

using namespace std;

int a, b, c;

int main(){
	string s;
	
	cin >> s;
	
	for (int i = 0, j = s.size() - 1; i < j; i++, j--)
		a += (s[i] != s[j]);
	
	cout << a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n,p;
    cin>>n>>p;
    int m=0;
    rep(i,n){
        int a;
        cin>>a;
        if(a%2==1) m++;
    }

    if(m==0) cout<<(p==0 ? (1LL<<n) : 0)<<endl;
    else cout<<(1LL<<(n-1))<<endl;
}

Measured memory_bytes: 3628
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void scd(int &a){scanf("%d",&a);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int i=0 ; i<b ; i++)scanf("%d",&a[i])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

void swap(int *a,int *b)
{
	int tmp=*a;
	*a=*b;
	*b=tmp;
}

int main()
{
	int a,b,c;
	scdd(a,b);
	while(a!=0 || b!=0)
	{
		if(a>b)
		swap(a,b);
		printf("%d %d\n",a,b);
		scdd(a,b);
	}
	
	return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	typedef double d;
	#define for(i,a,b) for(int i=a;i<b;i++)
	#define f(i,a,b) for(int i=a;i<=b;i++)
    int main()
    {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,d,c=0;
    double x,y;
    cin>>n>>d;
    while(n--) {cin>>x>>y;if((hypot(x,y))<=d) c+=1; }
    cout<<c<<endl;
	}

Measured memory_bytes: 3800
using System;
using System.Collections.Generic;

namespace AOJ.Volume0
{
    public class SumOfPrimeNumbers
    {
        public static void Main()
        {
            while (true)
            {
                int input = int.Parse(Console.ReadLine());
                if (input == 0) { break; }
                int sum = 2;
                var primes = new List<int>();
                primes.Add(2);

                int i = 3;
                int prime_cnt = 1;
                while (prime_cnt < input)
                {
                    foreach (var p in primes)
                    {
                        if (i % p == 0) { break; }
                        else if (p >= Math.Sqrt(i))
                        {
                            primes.Add(i);
                            sum += i;
                            prime_cnt++;
                            break;
                        }
                    }
                    i += 2;
                }

                Console.WriteLine(sum);
            }
        }
    }
}

Measured memory_bytes: 9604
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
//const int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;

const double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	int ll = 0, rr = MOD;
	vector<pair<int, int>>v(N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i].first >> v[i].second;
		ans = max(v[i].second - v[i].first + 1, ans);
		ll = max(ll, v[i].first);
		rr = min(rr, v[i].second);
	}
	if (N == 2) {
		cout << v[0].second + v[1].second - v[0].first - v[1].first + 2 << endl;
		return 0;
	}
	ans += max(rr - ll + 1, 0);
	int p, q;
	for (int i = 0; i < N; i++) {
		if (v[i].first == ll)p = i;
		if (v[i].second == rr)q = i;
	}
	if (p == q) {
		cout << ans << endl;
		return 0;
	}
	vector<pair<int, int>>w;
	for (int i = 0; i < N; i++) {
		if (i == p || i == q)continue;
		w.push_back(v[i]);
	}
	sort(w.begin(), w.end());
	ans = max(ans, max(0, v[p].second - v[p].first + 1) + max(0,v[q].second - w.back().first + 1));
	int rmin = MOD;
	for (int i = N - 3; i >= 0; i--) {
		rmin = min(rmin, w[i].second);
		if (i) {
			ans = max(ans, max(0, rmin - v[p].first + 1) + max(0, v[q].second - w[i - 1].first + 1));
		}
		else {
			ans = max(ans, max(0, rmin - v[p].first + 1) + max(0, v[q].second - v[q].first + 1));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2168
#include<iostream>
#define x first
#define y second
using namespace std;
int main(){
  pair<double,double>a1,a2,b1,b2;
  while(cin>>a1.x>>a1.y>>a2.x>>a2.y>>b1.x>>b1.y>>b2.x>>b2.y){
    bool f=0;  
    if(((a1.x<=b1.x&&b1.x<=a2.x)||(a1.x<=b2.x&&b2.x<=a2.x)||(b1.x<=a1.x&&a1.x<=b2.x)||(b1.x<=a2.x&&a2.x<=b2.x))
     &&((a1.y<=b1.y&&b1.y<=a2.y)||(a1.y<=b2.y&&b2.y<=a2.y)||(b1.y<=a1.y&&a1.y<=b2.y)||(b1.y<=a2.y&&a2.y<=b2.y)))f=1;
    if(f==1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;
static const ll MOD = 1000000007;

int N, T;
int D[MAX_N];

int main(){
	scanf("%d %d", &N, &T);
	for(int i = 0; i < N; i++) scanf("%d", &D[i]);
	sort(D, D + N);
	reverse(D, D + N);
	ll res = 1LL;
	int j = 0;
	for(int i = 0; i < N; i++){
		for(; j < i && D[j] - D[i] > T; j++);
		res *= (ll)((i - j) + 1);
		res %= MOD;
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
#define mp make_pair
char c; 
int main(){
	cin>>c;
	if('A'<=c&&c<='Z'){
		cout<<"A";
	}
	else{
		cout<<"a";
	}
	return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,M;
ll X[101010],Xa[101010];
ll i, j,ans;
int main(){
    scanf("%lld%lld", &N,&M);
    fornum(i, 0,M){
        scanf("%lld", &X[i]);
    }
    if(M<=N){
        printf("0");
        return 0;
    }
    sort(X, X+M);
    fornum(i,0,M-1){
        Xa[i] = X[i + 1] - X[i];
    }
    sort(Xa, Xa + M - 1);
    
    fornum(i,0,M-N){
        ans += Xa[i];
    }

    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll memo[100001];

ll fact(ll n){
    if(n == 0){
        return 1;
    }
    if(memo[n] != 0){
        return memo[n];
    }
    return memo[n] = (n * fact(n - 1)) % MOD;
}

int main()
{
    for(int i = 0; i <= 100000; i++){
        memo[i] = 0;
    }
    ll n, m;
    cin >> n >> m;
    if(abs(n - m) >= 2){
        cout << 0 << endl;
    }
    else if(abs(n - m) == 1){
        cout << (fact(n) * fact(m)) % MOD << endl;
    }
    else{
        cout << (fact(n) * fact(m) * 2) % MOD << endl;
    }
}

Measured memory_bytes: 2560
using System;
using System.Linq;

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    var a = arr[0];
    var b = arr[1];
    var c = arr[2];
    var d = arr[3];
    var ac = Math.Abs(a - c);
    var ab = Math.Abs(a - b);
    var bc = Math.Abs(b - c);
    if ((ab <= d && bc <= d) || ac <= d) {
      Console.WriteLine("Yes");
    } else {
      Console.WriteLine("No");
    }
  }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main (){
    int n;cin >> n;
    for(int i=1;i<=10000;i++){
        int x = i*1000;
        if(x>=n){
            cout<<x-n<<endl;
            //main();
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3644
n=int(input())
dp=[10**3]*(n+1)
dp[0]=0

for i in range(1,n+1):
    j=6
    for _ in range(10):
        if j<=i:
            dp[i]=min(dp[i],dp[i-j]+1)
        j*=6
    
    j=9
    for _ in range(10):
        if j<=i:
            dp[i]=min(dp[i],dp[i-j]+1)
        j*=9
    dp[i]=min(dp[i],dp[i-1]+1)
print(dp[-1])

Measured memory_bytes: 74508
def main():
    n = int(input())
    arr = list(map(int, input().split()))
    if 0 in arr:
        print(0)
        return
    a = 1
    for i in arr:
        a*=i
        if a>10**18:
            print("-1")
            return
    
    print(a)
main()


Measured memory_bytes: 21684
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	static int INF = 1_000_000_007;
	//二項係数関連ここから-----
	static boolean isPreprocessing = false;	//二項係数を計算するための前処理を行っているかどうかのフラグ
	static int MAX = 260;				//MAXまで階乗やそれらの逆元のテーブルを保持する。
	static long[] fac;	//fac[i] := i! % MOD
	static long[] inv;	//inv[i] := mod. MODにおける i の逆元
	static long[] finv;	//finv[i] := mod. MODにおける i! の逆元(invの累積"積")
	//二項係数関連おわり------
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		//char[] A = sc.next().toCharArray();
		
		long S = Long.parseLong(sc.next());
		if(S == 1_000_000_000_000_000_000L){
			System.out.print("0 0 1000000000 0 0 1000000000");
		}else{
			long k = S/(999_999_999);
			long x = k==0? 0 : (999_999_999);
			long y = S%(999_999_999);			
			System.out.print("0 "+k+" 1 0 "+(x+1)+" "+y);
		}
		
	}
	
	//aとbの最小公倍数を返す
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
	
	//二項係数用の前処理
	static void COMinit(){
		//二項係数演算用前処理
		fac = new long[MAX+1];
		fac[0] = 1L;
		fac[1] = 1L;
		inv = new long[MAX+1];
		inv[1] = 1L;
		finv = new long[MAX+1];
		finv[0] = 1L;
		finv[1] = 1L;
		for(int i=2;i<MAX;i++){
			fac[i] = fac[i-1] * i % MOD;
			inv[i] = MOD - inv[(int)(MOD%i)] * (MOD/i) % MOD;
			finv[i] = finv[i-1] * inv[i] % MOD;
		}
		isPreprocessing = true;
	}
	
	//二項係数i_C_jをMODで割った余りを返す
	static long COM(int i, int j){
		if(i<j)return 0;
		if(i<0 || j<0)return 0;
		if(!isPreprocessing)COMinit();
		return fac[i] * (finv[j] * finv[i-j] % MOD) % MOD;
	}
	
}



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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

ll modexp(ll x, ll n) {
    ll ans = 1;
    while (n) {
        if (n & 1) ans = ans * x % mod;
        x = x * x % mod;
        n /= 2;
    }
    return ans;
}

ll modinv(ll x) {
    return modexp(x, mod - 2);
}

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

    int n;
    cin >> n;

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

    ll sum1 = 0, sum2 = 0;
    for (int i = 0; i < n; i++) {
        sum1 = (sum1 + a[i]) % mod;
        sum2 = (sum2 + a[i] * (ll)a[i] % mod) % mod;
    }

    sum1 = sum1 * sum1 % mod;
    ll ans = (sum1 - sum2 + mod) % mod;
    cout << ans * modinv(2) % mod << "\n";
    return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f
#define re register
#define N 310000
#define mod 998244353
using namespace std;

inline int read(){
    int x=0,w=0;char ch=getchar();
    while (!isdigit(ch))w|=ch=='-',ch=getchar();
    while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
    return w?-x:x;
}
const char s[]={'R','Y','G','B'};
signed main(){
	int h=read(),w=read(),d=read();
	for (int i=1;i<=h;++i,puts(""))
		for (int j=1;j<=w;++j){
			int x=i+j+w,y=i-j+w;
			putchar(s[((x/d)&1)*2+((y/d)&1)]);
		}
    return 0;
}


Measured memory_bytes: 512
N,K = map(int,input().split())
p = list(map(int,input().split()))
ans,num = sum(p[0:K]),sum(p[0:K])
for i in range(N-K):
    num = num + p[i+K] - p[i]
    ans = max(ans, num)
print((ans+K)/2)

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

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
        cout<<"YES"<<endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() { cout << "Yes"; }

void no() { cout << "No"; }

int main() {
  kyun;
  dset(10);
  ind l;
  cin >> l;
  cout << pow(l/3,3);
  hinata;
}

Measured memory_bytes: 256
use std::str::FromStr;

fn main() {
	let m = 1000000007i64;
	let hwab = read_vec_i32();
	let (h, w, a, b) = (hwab[0], hwab[1], hwab[2], hwab[3]);
	let mut f = vec![0i64; (h + w + 1) as usize];
	let mut rf = vec![0i64; (h + w + 1) as usize];
	f[0] = 1;
	rf[0] = 1;
	for i in 1..h+w+1 {
		f[i as usize] = f[(i - 1) as usize] * (i as i64) % m;
		rf[i as usize] = pow(f[i as usize], m - 2, m)
	}
	let cmb = |x: i32, y: i32, m: i64| -> i64 {
		f[(x + y) as usize] * rf[x as usize] % m * rf[y as usize] % m
	};
	let ans = (0..h-a).map(|y| cmb(b - 1, y, m) * cmb(w - b - 1, h - y - 1, m)).fold(0i64, |x, y| (x + y) % m);
	println!("{}", ans);
}

fn pow(x: i64, n: i64, m: i64) -> i64 {
	if n > 0 {
		let a = pow(x, n / 2, m);
		let b = a * a % m;
		if n & 1 != 0 { b * x % m } else { b }
	} else { 1 }
}

fn read_vec_i32() -> Vec<i32> {
	let mut line = String::new();
	std::io::stdin().read_line(&mut line).unwrap();
	line.trim().split_whitespace().map(|str| i32::from_str(str).unwrap()).collect()
}

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

int main(){
    int x;
    cin >> x;
    long long dp[100000];
    for(int i=0;i<100000;i++) dp[i]=0;
    int i=1;
    int ans;
    while(1){
        dp[i]=dp[i-1]+i;
        if(dp[i]>=x){
            ans=i;
            break;
        }
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::collections::HashSet;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


fn main() {
    let nm = read_vec::<usize>();
    let n = nm[0];
    let m = nm[1];

    let mut a : Vec<Vec<i32>> = Vec::with_capacity(m);
    for _i in 0..m {
        let mut row:Vec<i32> = vec![0;n];

        let kss = read_vec::<usize>();
        let k = kss[0];
        for j in 1..k+1 {
            let s = kss[j];
            row[s-1] = 1;
        }
        a.push(row);
    }

    let ps = read_vec::<i32>();
    for i in 0..m {
        a[i].push(ps[i]);
    }

    // println!("a: {:?}", a);


    let num = solve(m, n, &mut a);

    println!("{}", num);

}

fn solve(m :usize, n: usize, a: &mut [Vec<i32>]) -> usize {
    let rank = gauss_jordan_mod2(m, n, a);

    //println!("rank: {}", rank);

    //println!("a: {:?}", a);

    if rank < m {
        for i in rank..m {
            if a[i][n] != 0 {
                return 0;
            }
        }
    }

    let mut num = 1;
    for _i in rank..n {
        num *= 2;
    }
    return num;
}


// Get rank for m rows n+1 columns augmented matrix
fn gauss_jordan_mod2(m :usize, n: usize, a: &mut [Vec<i32>]) -> usize {
    let mut rank : usize = 0;

    for j in 0..n {
        //println!("LOOP {}: {:?}", j, a);
        let mut pivot : usize = m;
        // 1. Get pivot
        for i in rank..m {
            if a[i][j] != 0 {
                pivot = i;
                break;
            }
        }

        if pivot == m {
            continue;
        }

        // 2. Swap
        a.swap(rank, pivot);

        // 3. Set a[i][j] (i != rank) to zero
        for i in 0..m {
            if i == rank {
                continue;
            }
            if a[i][j] == 0 {
                continue;
            }
            for j1 in 0..n+1 {
                a[i][j1] -= a[rank][j1];
                if a[i][j1] < 0 {
                    a[i][j1] += 2;
                }
            }
        }

        rank += 1;
    }

    return rank;
}


Measured memory_bytes: 4352
#include<iostream>

using namespace std;

int bubbleSort(int A[],int N){
		int sw=0;
		bool flag=1;
		
		for(int i=0;flag;i++){
				flag=0;
				for(int j=N-1;j>=i+1;j--){
						if(A[j]<A[j-1]){swap(A[j],A[j-1]);flag=1;sw++;}
				}
		}
		return sw;;
}
int main(){
		int A[100],N,sw;
		cin>>N;
		for(int i=0;i<N;i++){cin>>A[i];}

		sw=bubbleSort(A,N);
		
		for(int i=0;i<N;i++){
				if (i) cout<<" ";
				cout<<A[i];
				}
		cout<<endl;
		cout<<sw<<endl;

		return 0;
		}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 0x7ffffff;
const int mod = 1000000007;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
	//作るときはParentの値を全て-1にする
	//こうするとすべてバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
	//AとBをくっつける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついているからくっつけない
			return false;
		}
		//大きい方(A)に小さいほう(B)をくっつけたい
		//大小が逆だったらひっくり返しちゃう
		if (size(A) < size(B)) swap(A, B);
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
	//AとBが同じグループにいるか
	bool same(int A, int B) { return root(A) == root(B); }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	UnionFind Uni(n + 1);
	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		Uni.connect(p[x], p[y]);
	}
	int ans = 0;
	rep(i, n) {
		if (p[i] == i + 1) ans++;
		else {
			if (Uni.same(p[i], i + 1)) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
side_list = list(map(int, input().split()))
side_list.sort()
side_list.reverse()

xy = [0, 0]

i = 0
j = 0
while i < N - 1:
    if side_list[i] == side_list[i+1]:
        xy[j] = side_list[i]
        i += 1
        j += 1
        if j > 1:
            break
    i += 1

print(xy[0] * xy[1])


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=2e5+5;

int n,m,dizi[N],mins[N],ans;

int main(){
	//fri("in.txt");
	//fro("out.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>dizi[i];
	}
	mins[0]=dizi[0];
	for(int i=1;i<n;i++){
		if(dizi[i]<mins[i-1])mins[i]=dizi[i];
		else mins[i]=mins[i-1];
	}
	for(int i=0;i<n;i++){
		if(dizi[i]<=mins[i])ans++;
	}
	cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 1792
A = [list(map(int, input().split())) for _ in range(3)]
B = [[0]*3 for _ in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                B[j][k] = 1

for i in range(3):
    if B[i][0] == 1 and B[i][1] == 1 and B[i][2] == 1:
        print('Yes')
        exit()

for i in range(3):
    if B[0][i] == 1 and B[1][i] == 1 and B[2][i] == 1:
        print('Yes')
        exit()

if B[0][0] == 1 and B[1][1] == 1 and B[2][2] == 1:
    print('Yes')
    exit()

if B[0][2] == 1 and B[1][1] == 1 and B[2][0] == 1:
    print('Yes')
    exit()

print('No')

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#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 repN_1(i, n) for(int i = 0; i < (int)(n - 1); i++)
#define repM(i, n) for(int i = (int)(n - 1); i >= 0; i--)n
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	string s;
	int n;
	ll ans = 0;
	ll r, g, b;
	r = g = b = 0;

	cin >> n;
	cin >> s;

	rep(i, n)
	{
		if (s[i] == 'R')
			r++;
		else if (s[i] == 'G')
			g++;
		else
			b++;
	}

	ans = r * g * b;

	rep(i, n)
	{
		for(int j = 1; j <= n; j++)
		{
			if (i - j < 0 || i + j >= n)
				break;
			else if (s[i] != s[i - j] && s[i] != s[i + j] && s[i - j] != s[i + j])
				ans--;
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int b[100][100];
long long ans=0;
void init(){
    for(int i=1;i<=20;i++){
        for(int j=1;j<=7;j++)
            a[i][j]=7*(i-1)+j;
    }
     for(int i=1;i<=20;i++){
        for(int j=1;j<=5;j++){
            int cur=0;
            for(int x=0;x<3;x++)
                for(int y=0;y<3;y++)
                    cur+=a[i+x][j+y];
            b[i][cur%11]++;
        }
     }
}
void solve(int x,int k){
    if(x<=0)
        return;
    for(int i=1;i<=11;i++)
        ans+=1LL*x*b[i][k];
}
int main(){
    init();
    int n,k;
    cin>>n>>k;
    solve(n/11-1,k);
    int x=max(n/11-1,0);
    n-=x*11;
    for(int i=1;i+2<=n;i++)
        ans+=b[i][k];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long double l, s;
	cin >> l;
	l /= 3;
	s = l * l * l;

	cout << setprecision(10) << fixed << s << "\n";

	return 0;
}


Measured memory_bytes: 888
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 1005;
int t[maxN], a[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    ll x = 0, y = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int a, b;
        cin >> a >> b;
        if (i == 1) {
            x = a;
            y = b;
            continue;
        }
        ll at_least = max((x + a - 1) / a, (y + b - 1) / b);
        x = at_least * a;
        y = at_least * b;
    }
    cout << x + y;
    return 0;
}

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

int main(void){
    int N,sum=0;
    cin>>N;
    int n=N;

    for(int i=0;i<8;i++){
        sum+=N%10;
        N/=10;
    }
    cout<<(n%sum==0?"Yes":"No")<<endl;

    return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<bool> f(n,false);
  vector<int> p(n,0);
  rep(i,m) {
    int q; string s;
    cin >> q >> s;
    q--;
    if(f[q] == false && s == "WA") p[q]++;
    if(s == "AC") f[q] = true;
  }
  int ans = 0;
  int pen = 0;
  rep(i,n) {
    if(f[i]) {
      ans++;
      pen += p[i];
    }
  }
  cout << ans << " " << pen << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

template<typename T>
struct BIT {
	std::vector<T> dat;

	BIT(int n) : dat(n + 1) {}

	void add(int k, T v) {
		k++;
		while (k < dat.size()) {
			dat[k] += v;
			k += k & -k;
		}
	}

	T sum(int k) {
		k++;
		T ret = 0;
		while (k > 0) {
			ret += dat[k];
			k &= k - 1;
		}
		return ret;
	}
};

int main() {
	int N;
	long long K;
	std::cin >> N >> K;

	std::vector<long long> a(N);
	std::vector<long long> s(N + 1);
	for (int i = 0; i < N; i++) {
		std::cin >> a[i];
		s[i + 1] = s[i] + a[i];
	}

	std::vector<long long> dict;
	for (int i = 0; i <= N; i++) {
		dict.push_back(s[i] - K * i);
	}
	std::sort(dict.begin(), dict.end());
	dict.erase(std::unique(dict.begin(), dict.end()), dict.end());

	// s[r]-Kr>=s[l]-Kl

	BIT<int> bit(dict.size() + 1);
	long long ans = 0;
	for (int i = 0; i <= N; i++) {
		long long val = s[i] - K * i;
		val = std::lower_bound(dict.begin(), dict.end(), val) - dict.begin();
		ans += bit.sum(val);
		bit.add(val, 1);
	}
	std::cout << ans << std::endl;
}


Measured memory_bytes: 5744
n = int(input())
L = [[] for _ in range(n+1)]
R = [[] for _ in range(n+1)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    w %= 2
    L[u] += [[u, v, w]]
    R[v] += [[v, u, w]]
P = [[] for _ in range(2*n+2)]
P[1] += (L[1]+R[1])
L[1] = R[1] = []
for i in range(1, 2*n):
    for _, v, w in P[i]:
        P[i+2-w] += (L[v]+R[v])
        L[v] = R[v] = []
A = []
for p in P[1::2]: A += p
B = set([u for u, *_ in A])
for i in range(1, n+1): print(1 if i in B else 0)

Measured memory_bytes: 68388
import java.util.Optional;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.stream.IntStream;

class Main {
    private static TreeMap<Long, Long> map = new TreeMap<>();
    private static Scanner scanner = new Scanner(System.in);
    public static void main(String... args) {
        int n = scanner.nextInt(), m = scanner.nextInt();
        IntStream.range(0, n).forEach(i -> setMap(1, scanner.nextLong()));
        IntStream.range(0, m)
            .forEach(i -> setMap(scanner.nextInt(), scanner.nextLong()));
        long total = 0, num = 0;
        while ((n -= num) > 0) {
            long lastKey = map.lastKey();
            num = Math.min(map.get(lastKey), n);
            total += num * lastKey;
            map.remove(lastKey);
        }
        System.out.println(total);
    }
    private static void setMap(int num, long value) {
        map.put(value, Optional.ofNullable(map.get(value)).orElse(0l) + num);
    }
}

Measured memory_bytes: 110372
#include <iostream>
#include <cstring>
#include <string.h>
#include <algorithm>

using namespace std;

int SumOfIce[10];

int main() {
	int n, num;

	while (cin >> n, n) {
		memset(SumOfIce, 0, sizeof(SumOfIce));
		for (int i = 0; i < n; ++i) {
			cin >> num;
			SumOfIce[num]++;
		}
		for (int i = 0; i < 10; ++i) {
			if (SumOfIce[i] == 0) {
				cout << "-" << endl;
				continue;
			}
			for (int j = 0; j < SumOfIce[i]; ++j) {
				cout << "*";
			}
			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
 using namespace  std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const double pi=3.1415926535897932384626433832;
const long long mod=1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
typedef double ld;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
		
	res = res * res;
	
	if (b % 2 == 1)
		res = res * a;
	
	return res;
}

long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;

	return res;
}


//template ends here

ll n;
const ll N=3000;
ll a[N];
ll dp[N][N]={};
ll assigndp[N][N]={};
ll max_x_y(ll l, ll r)
{

	if(assigndp[l][r]!=0)
		return dp[l][r];
	if(l==r)
	return a[r];

	else
	{
		ll c1=a[l]-max_x_y(l+1,r);
		ll c2=a[r]-max_x_y(l,r-1);

		assigndp[l][r]=1;
		dp[l][r]=max(c1,c2);
		return dp[l][r];
	}
}





int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(ll i=0 ;i<n; i++)
		cin>>a[i];
	cout<<max_x_y(0,n-1)<<'\n';



	
	//cout<<'\n'<<"time endslapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 139904
#include<bits/stdc++.h>
     
#define endl '\n'
     
using namespace std;
     
int main(){
     
  cin.tie(0); // cout と cin の同期を切る
  ios::sync_with_stdio(false); /* cの stdioストリーム (printfとか)と*/
     
  long long Q,H,S,D;
     
  cin>>Q>>H>>S>>D;
     
  double N;
     
  cin>>N;
     
  long long ans=0;
     
  long long cnt2=min(min(min(Q*8,H*4),S*2),D);
     
  long long cnt1=min(min(Q*4,H*2),S);
     
  long long cnt5=min(Q*2,H);
     
  long long cnt25=Q;
  int i=4;
     
  while(1){
     
    if(N==0){
      break;
    }
     
    if(i==4){
      if(N>=2){
	ans+=int(N/2)*cnt2;
	N-=(int(N/2)*2);
      }else{
	i-=1;
      }
    }
    else if(i==3){
      if(N>=1){
	ans+=int(N/1)*cnt1;
	N-=(int(N/1)*1);
      }else{
	i-=1;
      }
    }else if(i==2){
      if(N>=0.5){
	ans+=int(N/0.5)*cnt5;
	N-=(int(N/0.5)*0.5);
     
      }else{
	i-=1;
      }
    }else if(i==1){
     
      if(N>=0.25){
	ans+=int(N/0.25)*cnt25;
	N-=(int(N/0.25)*0.25);
      }else{
	i-=1;
      }
    }
  }
  cout<<ans<<endl;
     
  return 0;
     
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    string s;cin>>s;
    int n=s.size()+1;
    int a[n];
    fill(a,a+n,-1);
    if(s[0]=='<')a[0]=0;
    rep(i,1,n-1){
        if(s[i-1]=='>'&&s[i]=='<')a[i]=0;
    }
    
    if(s[n-2]=='>')a[n-1]=0;
    
    int now=0;
    for(;;){
        //cout<<a[now]<<" ";
        if(now==n-1)break;
        if(a[now]!=0){
            now++;
            //cout<<now<<" ";
            continue;
        }
        int cnt=0;
        while(now<n-1&&s[now]=='<'){
            cnt++;
            now++;
            a[now]=cnt;
        }
        
    }
    now=n-1;
    for(;;){
        if(now==0)break;
        if(s[now-1]=='<'){
            now--;
            continue;
        }
        int cnt=0;
        while(now>=1&&s[now-1]=='>'){
            cnt++;
            now--;
            a[now]=max(a[now],cnt);
        }
    }
    ll sum=0;
    rep(i,0,n)sum+=a[i];
    cout<<sum<<endl;
    //rep(i,0,n)cout<<a[i]<<" ";
    
}


Measured memory_bytes: 2844
n = int(input())
s = [input() for _ in range(n)]
d = {}

for i in s:
    d[i] = d.get(i, 0) + 1


d = sorted(d.items(), key=lambda x: x[1], reverse=True)
maxv = d[0][1]
ans = []
for s in d:
    if s[1] == maxv:
        ans.append(s[0])
    else:
        break

for p in sorted(ans):
    print(p)


Measured memory_bytes: 49100
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n);
		string s;
		cin>>s;
		int ba=0;
		rep(i,s.size()){
			if(s[i]=='M')in[i%n]++;
			else if(s[i]=='S'){ba+=in[i%n]+1;in[i%n]=0;}
			else {in[i%n]+=ba+1;ba=0;}
		}
		sort(all(in));
		rep(i,n)cout<<in[i]<<" ";
		cout<<ba<<endl;
	}
}

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

using namespace std;
typedef long long ll;
const int INF = (1<<30);

int n,k;
int main(){
    cin >> n;
    for(int i=0;i*4<=n;i++){
        for(int j=0;j*7<=n;j++){
            if(i*4+j*7==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
x,y,a,b,c = map(int,input().split())
p_a = list(map(int,input().split()))
p_b = list(map(int,input().split()))
p_c = list(map(int,input().split()))
p_a.sort(reverse=True)
p_b.sort(reverse=True)
#p_c.sort(reverse=True)

ans = p_a[:x] + p_b[:y] + p_c
ans.sort(reverse=True)
print(sum(ans[:x+y]))

Measured memory_bytes: 111852