akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        int m = (n-1)/2;
        vector<int> v;
        for (int i=1; i<n; ++i) {
            v.push_back((i*i) % n);
        }
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        vector<int> cnt(m+1, 0);
        for (int i=0; i<(int)v.size(); ++i) {
            for (int j=0; j<(int)v.size(); ++j) {
                int sub = v[i] - v[j];
                if (sub < 0) sub += n;
                if (m < sub) sub = n - sub;
                cnt[sub] ++;
            }
        }
        for (int i=1; i<=m; ++i) {
            cout << cnt[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1324
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 924844033;
const int MAXN =(int) 1e2+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int N,M;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

void work(){
    scanf("%d%d",&N,&M);
    for(int i=1;i<=N;i++) scanf("%s",a[i]+1);
    for(int i=1;i<=M;i++){
        if(i==1){
            if(a[1][i]=='.') dp[1][i]=0;
            else dp[1][i]=1;
        }
        else{
            if(a[1][i]=='.'){
                dp[1][i]=dp[1][i-1];
            }
            else{
                if(a[1][i-1]=='.') dp[1][i]=dp[1][i-1]+1;
                else dp[1][i]=dp[1][i-1];
            }
        }
    }
    for(int i=2;i<=N;i++){
        if(a[i][1]=='.'){
            dp[i][1]=dp[i-1][1];
        }
        else{
            if(a[i-1][1]=='.') dp[i][1]=dp[i-1][1]+1;
            else dp[i][1]=dp[i-1][1];
        }
    }
    for(int i=2;i<=N;i++){
        for(int j=2;j<=M;j++){
            if(a[i][j]=='.'){
                dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
            }
            else{
                int x,y;
                if(a[i][j-1]=='.') x=dp[i][j-1]+1;
                else x=dp[i][j-1];
                if(a[i-1][j]=='.') y=dp[i-1][j]+1;
                else y=dp[i-1][j];
                dp[i][j]=min(x,y);
            }
        }
    }
    printf("%d\n",dp[N][M]);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 10000001
#define infpos 10e5
#define infneg -10e5
int a[100000]={0};
int main(){
ll ans;
string s,t;
cin>>s>>t;
ans=0;
for(int i=0;i<s.size();i++)
    if(s[i] ==t[i]) ans++;
cout<<ans<<endl;
return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=a-1;i>=b;i--)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

void Fast_IO() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   #ifndef ONLINE_JUDGE
   freopen("in.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
} 

vector<vector<ll> >vii;
int main(){
   //Fast_IO();
   string s;
   ll k;
   cin>>k>>s;
   if(s.length()<=k) cout<<s<<endl;
   else{
      f(i,0,k){
         cout<<s[i];
      }
      cout<<"..."<<endl;
   }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=10005;
const ll mod=1e9+7,inv2=5e8+4;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}

int main()
{
	int r=read();
	printf("%d\n",r*r);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>
#include<tuple>
#include<bitset>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << fixed << setprecision(7) << (x) << endl;
#define printbit(x) cout << bitset<15>(x) << endl;
using ll = long long int;



long double pi = 3.14159265359;

int l,r;
int d;
int ans;

int main(){
    cin >> l >> r >> d;
    for(int i=l;i<=r;i++){
        if(i%d == 0){
            ans++;
        }
    }
    cout << ans << endl;


return 0;
}

Measured memory_bytes: 3596
// abc147_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;

    int n = S.size();

    int cnt = 0;
    REP(i, n/2){
        if (S[i] != S[n-i-1]) cnt++;
    }

    print(cnt);


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <iostream>
#include <numeric>
typedef long long LL;

int main() {
  LL N; std::cin >> N;
  if (N%2 == 1) {
    std::cout << 0 << std::endl;
    return 0;
  }

  LL total = 0;
  LL i = 10;
  while (i <= N) {
    total += N / i;
    i = i*5LL;
  }
  std::cout << total << std::endl;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main() {
    char c;
    while (scanf("%c", &c) != EOF) {
        if (65 <= c && c <= 90)
            c += 32;
        else if (97 <= c && c <= 122)
            c -= 32;
        printf("%c", c);
    }
}

Measured memory_bytes: 2688
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>
#include<chrono>
#include<random>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

long double constexpr pi = 3.141592653589793;

template<class T>
constexpr T sigma1(T i, T n){
    return (n - i + 1) * (i + n) / 2;
}

template<class T>
constexpr T sigma2(T i, T n){
    return (i == 1 ? n * (n + 1) * (2 * n + 1) / 6 :
            sigma2(1, n) - sigma2(1, i - 1));
}

template<class T>
constexpr T sigma3(T i, T n){
    if (i == 1) {
        auto temp = sigma1(i, n);
        return temp * temp;
    }
    return sigma2(1, n) - sigma2(1, i - 1);
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max();

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


signed main(void){
    cin.tie(0); ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);

    int a, b, c, d;

    cin >> a >> b >> c >> d;

    int i = 0;
    while (true) {
        if (i % 2 == 0) {
            c -= b;
        } else {
            a -= d;
        }
        if (a <= 0 || c <= 0) {
            cout << (a <= 0 ? "No" : "Yes") << "\n";
            return 0;
        }
        ++i;
    }

    return 0;
}


Measured memory_bytes: 3652
import java.util.*;
 
class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		String S = sc.next();
		if(S.contains("B")){
          System.out.println("ARC");
        }else{
          System.out.println("ABC");
        } 
	}
}

Measured memory_bytes: 35676
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int > A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A.at(i);
    }
    //Aの要素を割った余りが全て0の場合、全ての要素を2で割る
    int count = 0;
    bool isOdd = false;
    while(isOdd==false){
        for (int i = 0; i < N ; ++i) {
            if(A.at(i)%2==1){
                isOdd = true;
                break;
            }
        }
        if(isOdd==false){
            for (int j = 0; j < N ; ++j) {
                A.at(j) = A.at(j) / 2;
            }
            count++;
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,c,l[10];
long long f[310][70];
int main()
{
	scanf("%d%d",&n,&c);
	for (int i=0;i<n;i++)
	{
		scanf("%d",&l[i]);
	}
	sort(l,l+n);
	double ans=0.0;
	int s=0;
	do
	{
		s++;
		memset(f,0,sizeof(f));
		f[n*l[n-1]][0]=1;
		for (int i=0;i<n*c;i++)
		{
			if (i%n==0)
			{
				continue;
			}
			int x=i%n-1;
			for (int j=i;j<=n*c;j++)
			{
				for (int mask=0;mask<(1<<(n-1));mask++)
				{
					if (mask&(1<<x))
					{
						continue;
					}
					f[min(max(j,i+n*l[x]),n*c)][mask|(1<<x)]+=f[j][mask];
				}
			}
		}
		ans+=1.0*f[n*c][(1<<(n-1))-1];
	}while (next_permutation(l,l+n-1));
	ans/=1.0*s*pow(c,n-1);
	printf("%.13lf\n",ans);
    return 0;
}
//开门白水，侧近桥梁；小姑所居，独处无郎。
//——南朝乐府《青溪小姑曲》

Measured memory_bytes: 640
/******************************************
* AUTHOR : SHUBHAM KUMAR *
* NICK : { "CODECHEF" : "SCHELEON",
		   "CODEFORCES" : "SCH3130N" } * 	
* INSTITUTION : BIT MESRA *
******************************************/

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define sd(x) scanf("%lld",&x)
#define ll long long int
#define large 100005
#define MOD 1000000007
#define dd double
#define pb push_back
#define mk make_pair
#define rep0(i,b) for(int i=0;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define pll pair<ll, ll>
#define ld long double
#define vll vector<ll>
#define vpll vector<pll>
#define sortv(v) sort(v.begin(),v.end())  

ll ModE(ll x, unsigned ll y, ll p = MOD) 
{ 
    ll res = 1;
    x = x % p;    
    while (y > 0) 
    {   if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;
        x = (x*x) % p;   
    } 
    return res; 
}

using namespace std;

ll dp[large][4],a[large][3];
ll n;
ll solve(ll i, ll prev){
	if(i==n)
		return 0;
	if(dp[i][prev]!=-1)
		return dp[i][prev];
	// if(i==n-1){
	// 	ll maxx=0;
	// 	for(int ii=0;ii<3;ii++)
	// 		if(ii^prev != 0 && a[i][ii] > maxx){
	// 			maxx = a[i][ii];
	// 		}
	// 	return maxx;
	// }
	for(int ii = 0; ii < 3;ii++){
		if(prev!=ii){
			// cout<<i<<": "<<prev<<" => "<<ii<<"\n";
			dp[i][prev] = max(dp[i][prev], a[i][ii]+solve(i+1, ii));
		
		}
	}
	return dp[i][prev];
}

int main() {
	//#ifndef _DEBUG
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
	#endif

	fastio
	//ios_base& scientific (ios_base& str);

	//ll T; cin>>T; while(T--){}

	cin>>n;
	rep0(i,n){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	rep0(i,n+5)
		dp[i][0]=-1,dp[i][1]=-1,dp[i][2]=-1,dp[i][3]=-1;
	solve(0, 3);
	cout<<dp[0][3];
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    vector<int> ans(n);
    rep(ri, 2) {
        int cnt = 0;
        rep(i, n) {
            if (s[i] == 'R') cnt++;
            else {
                ans[i] += cnt/2;
                ans[i-1] += (cnt+1)/2;
                cnt = 0;
            }

        }

        reverse(ans.begin(), ans.end());
        reverse(s.begin(), s.end());
        rep(i, n) {
            if (s[i] == 'L') s[i] = 'R';
            else s[i] = 'L';
        }
    }

    rep(i, n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 1104
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
int main()
{
  int n,a[4000],s;
  cin >> n;
  s=0;
  rep(i,n)cin >> a[i];
  rep(i,n)s+=a[i];
  printf("%d",s-n);
}

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

int a, b, t;

int main() {
	cin >> a >> b >> t;
	cout << (t / a)*b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int d;
    cin >> d;
    cout << "Christmas";
    while (d < 25) {
        d++;
        cout << " Eve";
    }
    cout << endl;
}

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

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 1; i <= 3; ++i) {
    if ((a * b * i) & 1) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<long long int> > C(10, vector<long long int>(10));
    for(int i=0; i<10; i++) {
        for(int j=0; j<10; j++) {
            cin >> C[i][j];
        }
    }
    
    for(int k=0; k<10; k++) {
        for(int i=0; i<10; i++) {
            for(int j=0; j<10; j++) {
                C[i][j] = min(C[i][j], C[i][k]+C[k][j]);
            }
        }
    }
    
    map<int, long long int> mp;
    for(int h=0; h<H; h++) {
        for(int w=0; w<W; w++) {
            int A;
            cin >> A;
            mp[A]++;
        }
    }


    // for(int i=0; i<10; i++) {
    //     cout << C[i][1] << " ";
    // }
    // cout << endl;
    
    long long int ans=0;
    for(auto i=mp.begin(); i!=mp.end(); i++) {
        if(i->first==-1 || i->first==1) continue;
        ans += (i->second * C[i->first][1]);
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int a,b,c,d;
  cin >> a>>b>>c>>d;
  
  cout << min(a,b)+min(c,d) << endl;

  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,l,r;
    cin>>n;
    int sum=0;
    rep(i,n){
        cin>>l>>r;
        sum+=r-l+1;
    }
    cout<<sum;
}

Measured memory_bytes: 3536
INF = 2 << 32
def out stat, remain
  puts stat.join(' ') if remain.zero?
  ([stat.last || INF, remain].min.downto(1)).each {|n|
    out(stat << n, remain - n)
  }
  stat.pop
end

until (n = gets.to_i) == 0
  out [], n
end

Measured memory_bytes: 6172
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;

int main() {
    cin >> n;
    vector<int> h(n, 0);
    for(int i = 0; i < n; ++i) cin >> h.at(i);

    h.emplace_back(0);
    int ans = 0;
    int now = 0;
    int pre = 0;
    for(int i = 0; i <= n; ++i) {
        if(h.at(i) >= now) {
            now = h.at(i);
        }else {
            ans += (now-pre);
            now = h.at(i);
            pre = h.at(i);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >


int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
void solve(){
    int x,n;
    cin>>x>>n;
    int sum=0;
    rep(i,n){
        int a;
        cin>>a;
        sum+=a;
    }
    if(sum>=x) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

signed main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    int t;
    t=1;
    while(t--){
        solve();
    }

     return 0;

}
///Alhamdulillah




Measured memory_bytes: 256
#include <iostream>

int main() {
    using namespace std;
    int a, b;
    cin >> a >> b;
    if(a + b == 15) {
        cout << "+" << endl;
    } else if(a * b == 15) {
        cout << "*" << endl;
    } else {
        cout << "x" << endl;
    }
    return 0;
}


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



int main() {
int N;
cin >> N;
vector<int> ti(N);
for(int i = 0; i < N; i++){
cin >> ti[i];
}
vector<int> copy(N);
for(int i = 0; i < N; i++){
copy[i] = ti[i];
}
sort(ti.begin(),ti.end());
reverse(ti.begin(),ti.end());
int ma = 0;
int secma = 0;
ma = ti[0];
secma = ti[1];



for(int i = 0; i < N; i++){
if(copy[i] == ma)cout << secma << endl;
else cout << ma << endl;
}




}


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

int main(){
    int a,b;
    int area = 0;
    int leng = 0;
    cin >> a;
    cin >> b;

    area = a * b;
    leng = a + a + b + b;
    
    cout << area << " " << leng << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int N = 0;
    string S;
    char tmp_chr;
    int check_str[3];
    int type_num = 0;
    int f = 0;

    /* 標準入力 */
    cin >> N >> S; //桁数

    for(int i=0; i<1000;i++)
    {
        check_str[0] = i/100;
        check_str[1] = (i/10)%10;
        check_str[2] = i%10;
        f = 0;

        for(int j=0; j<N; j++)
        {
            if(S[j] == ('0' + check_str[f])) f++;
            if(f == 3) break;
        }

        if( f == 3) type_num ++;
    }

    cout << type_num << endl;

    return 0;
}

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

public class Hello
{
    public static void Main()
    {
        // Your code here!
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        int R = 0;
        int B = 0;
        
        for (int i = 0; i < S.Length; i++)
        {
            if(S[i] == 'R') R++;
            else B++;
        }
        
        if(R > B) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
vector<vector<int> > d; 
ll power(ll a,int n){
  if(n==0)
    return 1;
  if((n%2)==0)
    return (power((a*a)%mod,n/2))%mod;
  else
    return (a*(power((a*a)%mod,n/2))%mod)%mod;    
}
int main(){
FASTIO
ll x,y,a,b,c;
cin>>x>>y>>a>>b>>c;
vector<ll> p(a);
for(int i=0;i<a;i++)
  cin>>p[i];
sort(p.begin(),p.end());
reverse(p.begin(),p.end());
vector<ll> q(b);
for(int i=0;i<b;i++)
  cin>>q[i];
sort(q.begin(),q.end());
reverse(q.begin(),q.end());
vector<ll> r(c);
for(int i=0;i<c;i++)
  cin>>r[i];
sort(r.begin(),r.end());
reverse(r.begin(),r.end());
vector<ll> pr1(a);
pr1[0]=p[0];
for(int i=1;i<a;i++)
  pr1[i]=pr1[i-1]+p[i];
vector<ll> pr2(b);
pr2[0]=q[0];
for(int i=1;i<b;i++)
  pr2[i]=pr2[i-1]+q[i];
vector<ll> pr3(c);
pr3[0]=r[0];
for(int i=1;i<c;i++)
  pr3[i]=pr3[i-1]+r[i];
vector<pll> cm(b+c);
for(int i=0;i<b;i++){
    cm[i]=mp(q[i],1);
} 
for(int i=0;i<c;i++){
   cm[b+i]=mp(r[i],2);
}
sort(cm.begin(),cm.end());
reverse(cm.begin(),cm.end());
vector<ll> e(c);
vector<int> t(b+c),t1(b+c);
int l=0,l1=0;
for(int i=0;i<b+c;i++){
  if(cm[i].ss==1){
    l++;
  }
  else{
    l1++;
  }
  t[i]=l;
  t1[i]=l1;
}
vector<ll> pr4(b+c);
pr4[0]=cm[0].ff;
for(int i=1;i<b+c;i++)
  pr4[i]=pr4[i-1]+cm[i].ff;
for(int i=b+c-1;i>=0;i--){
  if(cm[i].ss==2){
      ll p1=0;
      if(t[i]>=y){
         e[t1[b+c-1]-t1[i]]=pr2[y-1];  
      }
      else{
       if(t[i]>0){
         p1=pr2[t[i]-1];
       }
       p1+=(pr4[i+((y-t[i])-1)]);
       if(i>0){
         p1=p1-pr4[i-1];
       }
       e[t1[b+c-1]-t1[i]]=p1;
       //cout<<p1<<"\n";
      }
  }
}
ll ans=0;
//cout<<e[0]<<"\n";
for(int i=0;i<=x;i++){
    ll p=0;
    if(i>0)
      p=pr1[i-1];
    //cout<<p<<"\n";
    if(c<(x-i))
       continue;
    if((x-i)>0) 
      p+=(pr3[x-i-1]);
    if((c-(x-i))>0){
      p+=e[(c-(x-i))-1];
    }
    else
      p+=pr2[y-1]; 
    //cout<<p<<"\n";         
    ans=max(ans,p);
}
cout<<ans;
return 0;
}

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

int N;
int A[210000];

int counter = 0;

int main(void){

    cin >> N;

    for (int i = 0;i < N ;i++) cin >> A[i];

    sort(A,A+N);
    int maxA = A[N-1];
    bool B[maxA + 1];
    for (int i = 0;i < maxA + 1 ;i++) B[i] = true;

    for (int i = 0;i < N-1; i++){
        if (A[i] == A[i+1]) B[A[i]] = false; 
    }

    for (int i = 0;i < N - 1;i++){
        int k = A[i];
        int j = 2;
        while (k * j <= maxA){
            int m = k * j;
            if(B[m] == true){
                B[m] = false;
            }
            j++;
        }
    }

    for (int i = 0;i < N ;i++){
        if (B[A[i]]) counter++;
    }

    cout << counter << endl;
    
    return 0;
}

Measured memory_bytes: 5292
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  char str[1024];
  while(1){
    fgets(str, sizeof(str), stdin);
    str[strlen(str)-1] = ' '; str[strlen(str)] = '\0';
    if(strcmp(str, "END OF INPUT ") == 0) return 0;
    int cnt = 0;
    for(int i = 0; i < strlen(str); ++i){
      if(str[i] == ' '){ printf("%d", cnt); cnt = 0;continue;}
      cnt++;
    }
    puts("");
  }
  return 0;
}

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

const int mxN=1e5;
int n, a[mxN];

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

	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i];
	sort(a, a+n, greater<int>());
	int i=0;
	for(; i<n&&i<a[i]; ++i);
	cout << (a[i-1]-i+1&1&&lower_bound(a, a+n, i-1, greater<int>())-a-i+1&1?"Second":"First");
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> as(N);
    rep(i, N){
        cin >> as[i];
    }
    sort(as.begin(), as.end());

    ll ans = 0;

    if(N % 2 == 0){
        rep(i, N / 2){
            ans -= 2 * as[i];
        }
        for(int i = N / 2; i < N; i ++){
            ans += 2 * as[i];
        }
        ans += as[N / 2 - 1];
        ans -= as[(N / 2)];
    }else{
        rep(i, (N + 1) / 2){
            ans -= 2 * as[i];
        }
        for(int i = (N + 1) / 2; i < N; i ++){
            ans += 2 * as[i];
        }
        ans += as[(N + 1) / 2 - 1];
        ans += as[(N + 1) / 2 - 2];

        sort(as.begin(), as.end(), greater<int>());

        ll tmp = 0;

        rep(i, (N + 1) / 2){
            tmp += 2 * as[i];
        }
        for(int i = (N + 1) / 2; i < N; i ++){
            tmp -= 2 * as[i];
        }
        tmp -= as[(N + 1) / 2 - 1];
        tmp -= as[(N + 1) / 2 - 2];
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    string s;int w;cin>>s>>w;
    string ans="";
    for(int i=0;i<s.size();i+=w){
        ans+=s[i];
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b;
  cin >> a >> b;
  if(a+b>=10) cout << "error" <<endl;
  else cout<<a+b <<endl;
}

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

using namespace std;

struct Operate {
	unsigned long a;
	unsigned long b;
};

bool lessNum(const Operate& left, const Operate& right) { return left.a < right.a; }

int main(void)
{
	unsigned long N, K;
	cin >> N >> K;

	vector<Operate> o;
	for (int i = 0; i < N; i++) {
		Operate tmp;
		cin >> tmp.a >> tmp.b;
		o.push_back(tmp);
	}
	sort(o.begin(), o.end(), lessNum);

	unsigned long sum = 0;
	for (int i = 0; i < N; i++) {
		sum += o[i].b;
		if (K <= sum) {
			cout << o[i].a << endl;
			break;
		}
	}
	return 0;
}

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

int main(){
    ll n;
    cin >> n;
    vector <ll> a(n),b(n),c(n);

    rep(i,n){
        cin >>a[i];
    }
    rep(i,n){
        cin >>b[i];
    }
    rep(i,n){
        cin >>c[i];
    }

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    ll ans=0;
    ll kb=0,ka=0;

    vector <ll> bans(n);

    rep(i,n){
        //cout << i << endl;
        if(kb<n){
        while(c[i]>b[kb]){
            if(ka<n){
                while(b[kb]>a[ka]){
                    ++ka;
                    if(ka==n){
                        break;
                    }
                }   
            }
            if(kb==0){
                bans[0]=ka;
            }
            else{
            bans[kb]=ka+bans[kb-1];
            }
            //ans+=ka;
            
            
            ++kb;
            if(kb==n){
                break;
            }
            

        }
        if(kb!=0){
        ans+=bans[kb-1];
        }
        
        }
        else{
            ans+=bans[n-1];
        }
    }

    /*rep(i,n){
        cout << bans[i] << endl;
    }*/

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 6404
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		String str=sc.next();
		String ans="";

		if(str.equals("A")) ans="T";
		else if(str.equals("C")) ans="G";
		else if(str.equals("G")) ans="C";
		else ans="A";

		System.out.println(ans);

		sc.close();

	}

}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
//	ios_base::sync_with_stdio(0); cin.tie(0);
	#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif
	string s;
	cin>>s;
	int i, ans = 0;
	int rockcount=0;
	int papercount=0;
	for(i=0;i<s.length();i++)
	{
		if(s[i]=='g')
		{
			if(papercount<rockcount)
			{
				papercount++;
				ans++;
			}
			else
			{
				rockcount++;
			}
		}
		else
		{
			if(papercount<rockcount)
			{
				papercount++;
			}
			else
			{
				rockcount++;
				ans--;
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}	

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  int n, k; cin >> n >> k;
  cout << (n-1)/(k-1) + ((n-1)%(k-1)==0 ? 0 : 1) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;


int main() {
	
	int a, b;
	char A, B;
	cin >> A >> B;
	a = A-48;
	b = B-48;
	string Ab, Ba;
	rep(i, b)Ab.push_back(A);
	rep(i, a)Ba.push_back(B);
	
	map<string, int> ans;

	ans[Ab] = 0;
	ans[Ba] = 0;

	auto itr = ans.begin();

	cout << itr->first << endl;

	return 0;
}

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

signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n;
    std::cin >> n;

    std::vector<int> a(n);
    int max = 0;

    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        max = std::max(max, a[i]);
    }

    std::vector<int> ans(max + 1), cnt(max + 1);

    for (int i : a) ++cnt[i];

    for (int i = 1; i <= max; i++) {
        for (int j = i; j <= max; j += i) {
            ans[i] += cnt[j];
        }
    }

    for (int i = 2; i <= max; i++) {
        if (ans[i] == n) {
            std::cout << "not coprime";
            return 0;
        }
    }

    for (int i = 2; i <= max; i++) {
        if (ans[i] > 1) {
            std::cout << "setwise coprime";
            return 0;
        }
    }

    std::cout << "pairwise coprime";

    return 0;
}



Measured memory_bytes: 15048
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,N=200005;
long long a[N],b[N],pwr[N],ans,g,k,n,f1,f2;
map<pair<long long,long long> ,int > fix;
int main(){
	cin>>n;
	pwr[0]=1;
	for(k=1;k<=n;k++){
		cin>>a[k]>>b[k];
		pwr[k]=(pwr[k-1]*2)%mod;
		if(a[k]!=0 && b[k]!=0){
		g=__gcd(abs(a[k]),abs(b[k])); 
		a[k]/=g;
		b[k]/=g;}
		if(a[k]==0 && b[k]!=0 ) f1++;
		else if(a[k]!=0 && b[k]==0 ) f2++;
		else{
			if(a[k]<0){
				a[k]*=-1; b[k]*=-1;
			}
		fix[{a[k],b[k]}]++;}
	}
	ans=1;
	for(k=1;k<=n;k++){
		 
		if(fix[{a[k],b[k]}]!=0){
			if(a[k]==0 ||  b[k]==0) {}
			else{
			long long cura=b[k],curb=a[k];
			if(cura<0) cura=-cura;
			else curb=-curb;
			 ans*=(pwr[fix[{a[k],b[k]}]]-1ll+pwr[fix[{cura,curb}]]%mod)%mod;
			ans%=mod;
			fix[{a[k],b[k]}]=fix[{cura,curb}]=0;
		}}
			}
			ans*=(pwr[f1]+pwr[f2]-1ll)%mod;ans%=mod; 
			ans+=fix[{0,0}]; ans%=mod;
			cout<<(ans+mod-1ll)%mod<<endl;
}

Measured memory_bytes: 33048
#include <stdio.h>

int d[101],pi[101],color[101];
int A[101][101];

void dijkstra(int n,int r){
  int i,min,u;
  for(i=0;i<n;i++){
    d[i] = 1000000;
    pi[i] = -1;
    color[i] = 0;
  }
  
  //printf("unko3\n");
  d[r] = 0;
  
  while(1){
    min = 1000000;
    for(i=0;i<n;i++){
      if(color[i] != 2 && d[i] < min){
	min = d[i];
	u = i;
	//printf("unko4\n");
      }
    }
    if(min == 1000000){
      //printf("unko5\n");
      break;
    }

    color[u] = 2;

    for(i=0;i<n;i++){
      if(color[i] != 2 && A[u][i] != -1 && d[u] + A[u][i] < d[i]){
	pi[i] = u;
	d[i] = d[u] + A[u][i];
	//printf("unko6\n");
      }
    }
  }
}


int main(){
  int i,j,n,k,tmp,a[101];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j] = -1;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&a[i],&k);
    for(j=0;j<k;j++){
      scanf("%d",&tmp);
      scanf("%d",&A[i][tmp]);
    }
  }
  
   //printf("unko1\n");
  dijkstra(n,0);
  //printf("unko2\n");
  
  for(i=0;i<n;i++){
    printf("%d %d\n",a[i],d[i]);
  }
  return 0;
  
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b[4][4];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	ll ct = 1;
	while (ct <= n)
		ct = ct * 2;
	cout << ct / 2;
	return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N,M;cin>>N>>M;
    map<ll,ll> a;
    rep(i,N){
        ll A;cin>>A;
        a[A]++;
    }
    rep(i,M){
        ll A,B;cin>>A>>B;
        a[B]+=A;
    }
    ll ans=0;
    auto itr=a.end();itr--;
    while(true){
        ll p=min((*itr).se,N);
        ans+=p*(*itr).fi;
        N-=p;
        if(N==0)break;
        itr--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)   for(signed i=0; i<n; i++)
#define FOR(i, k, n)    for(signed i=k; i<n; i++)
#define yn(b)   cout << ((b)?"Yes":"No") << endl
#define YN(b)   cout << ((b)?"YES":"No") << endl
#define pr(r)   cout << r << endl
#define min(x,y)    (x<y)?x:y
#define max(x,y)    (x>y)?x:y
#define ll  long long
int main(void){
    int a, b, c, d, e, k, i;
    cin >> a >> b >> c >> d >> e >> k;
    int f[10] = {b-a, c-a, d-a, e-a, c-b, d-b, e-b, d-c, e-c, e-d};
    sort(f, f+10);
    if(f[9] > k) pr(":(");
    else pr("Yay!");
}

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

using namespace std;

int main() {

	int a, d, x, p;
	scanf("%d %d %d", &a, &d, &x);
	while(a) {
		scanf("%d", &p);
		int temp = 1;
		int count = 0;
		while(temp <= d) {
			count++;
			temp += p;
		}
		x += count;
		a--;
	}

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

	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

struct segtree {
	const static int sz = 1 << 18;
	vector<int> dat1, dat2;

	void init() {
		dat1.resize(sz * 2);
		dat2.resize(sz * 2);	
		rep(i, sz * 2) dat1[i] = dat2[i] = 0;
	}

	void add(int a, int b, int x, int k = 0, int l = 0, int r = sz) {
		if(b <= l || r <= a) return ;
		if(a <= l && r <= b) dat1[k] += x;
		else{
			dat2[k] += (min(b, r) - max(a, l)) * x;
			add(a, b, x, k * 2 + 1, l, (l + r) / 2);
			add(a, b, x, k * 2 + 2, (l + r) / 2, r);
		}
	}

	int sum(int a, int b, int k = 0, int l = 0, int r = sz) {
		if(b <= l || r <= a) return 0;
		if(a <= l && r <= b) return dat1[k] * (r - l) + dat2[k];
		else{
			ll res = (min(b, r) - max(a, l)) * dat1[k];
			res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
			res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
			return res;
		}
	}
} seg;

const int INF = 1e9;

string s;
int num[26];
vi cp[26];
int us[26];

int main() {
	cin >> s;

	rep(i, s.size()) {
		int c = s[i] - 'a';
		++num[c];
		cp[c].pb(i);
	}

	int odd = 0;

	rep(i, 26) {
		if (num[i] & 1) {
			++odd;
		}
	}

	if (odd >= 2) {
		puts("-1");
		return 0;
	}

	int n = s.size();

	seg.init();

	ll ret = 0;

	while (n >= 3) {
		int mi = INF, t = -1;
		int p1, p2;

		rep(i, 26) {
			if (us[i] * 2 < num[i]) {
				int sz = (int)cp[i].size();
				int f = cp[i][us[i]], l = cp[i][sz - 1 - us[i]];
				f += seg.sum(f, f+1); l += seg.sum(l, l+1);

				int ct = f + (n - 1 - l);

				if (mi > ct) {
					mi = ct;
					t = i;
					p1 = cp[i][us[i]], p2 = cp[i][sz - 1 - us[i]];
				}
			}
		}
		//cout << char('a' + t) << " " << mi << endl;

		ret += mi;
		++us[t];

		seg.add(p1, p2, -1);
		seg.add(p2+1, (int)s.size(), -2);

		n -= 2;
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

ll jud(ll x, ll y, char z){//xは前の値、yは前のox
	if (x==0 && y==0 && z=='o') return 0;
	else if (x==0 && y==1 && z=='o') return 1;
	else if (x==1 && y==0 && z=='o') return 1;
	else if (x==1 && y==1 && z=='o') return 0;
	else if (x==0 && y==0 && z=='x') return 1;
	else if (x==0 && y==1 && z=='x') return 0;
	else if (x==1 && y==0 && z=='x') return 0;
	else return 1;
}

int main(){
	ll n; cin >> n;
	string s; cin >> s;
	vector<ll> ansl1(n+1,2);
	vector<ll> ansl2(n+1,2);
	vector<ll> ansl3(n+1,2);
	vector<ll> ansl4(n+1,2);
	ansl1[0]=0;
	ansl2[0]=0;
	ansl3[0]=1;
	ansl4[0]=1;
	ansl1[1]=0;
	ansl2[1]=1;
	ansl3[1]=0;
	ansl4[1]=1;

	FOR(i,2,n){
		ansl1[i]=jud(ansl1[i-2],ansl1[i-1],s[i-1]);
		ansl2[i]=jud(ansl2[i-2],ansl2[i-1],s[i-1]);
		ansl3[i]=jud(ansl3[i-2],ansl3[i-1],s[i-1]);
		ansl4[i]=jud(ansl4[i-2],ansl4[i-1],s[i-1]);
	}
/*	REP(i,n){
		cout << ansl1[i];
	}
	cout << endl;
	REP(i,n){
		cout << ansl2[i];
	}
	cout << endl;
	REP(i,n){
		cout << ansl3[i];
	}
	cout << endl;
	REP(i,n){
		cout << ansl4[i];
	}
	cout << endl;
*/


	if (s[0]=='o'){
		if (ansl1[n-1]==0 && ansl1[n]==ansl1[0]){
			REP(i,n){
				if (ansl1[i]==0) cout << 'S';
				else cout << 'W';
			}
			cout << endl;
		}
		else if (ansl2[n-1]==1 && ansl2[n]==ansl2[0]){
			REP(i,n){
				if (ansl2[i]==0) cout << 'S';
				else cout << 'W';
			}
			cout << endl;
		}
		else if (ansl3[n-1]==1 && ansl3[n]==ansl3[0]){
			REP(i,n){
				if (ansl3[i]==0) cout << 'S';
				else cout << 'W';
			}
			cout << endl;
		}
		else if (ansl4[n-1]==0 && ansl4[n]==ansl4[0]){
			REP(i,n){
				if (ansl4[i]==0) cout << 'S';
				else cout << 'W';
			}
			cout << endl;
		}
		else{
			cout << -1 << endl;
		}
	}
	else{
		if (ansl1[n-1]==1){
			REP(i,n){
				if (ansl1[i]==0 && ansl1[n]==ansl1[0]) cout << 'S';
				else cout << 'W';
			}
			cout << endl;
		}
		else if (ansl2[n-1]==0 && ansl2[n]==ansl2[0]){
			REP(i,n){
				if (ansl2[i]==0) cout << 'S';
				else cout << 'W';
			}
			cout << endl;
		}
		else if (ansl3[n-1]==0 && ansl3[n]==ansl3[0]){
			REP(i,n){
				if (ansl3[i]==0) cout << 'S';
				else cout << 'W';
			}
			cout << endl;
		}
		else if (ansl4[n-1]==1 && ansl4[n]==ansl4[0]){
			REP(i,n){
				if (ansl4[i]==0) cout << 'S';
				else cout << 'W';
			}
			cout << endl;
		}
		else{
			cout << -1 << endl;
		}
	}
}

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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){

    bool flag=false;

    ll ans=0,sum=0;
    
    int n;
    string s;
    cin >>n>>s;
    ans = n;

    for (int i = 1; i < n; i++){
        if(s[i-1]==s[i])--ans;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> cnt;
    for(int i=0;i<n;i++){
        cin >> a[i];
        ++cnt[a[i]];
    }
    if(cnt[0]==n){
        cout << "Yes" << endl;
        return 0;
    }
    if(n%3!=0){
        cout << "No" << endl;
        return 0;
    }
    vector<int> all;
    int b=n/3;
    for(auto p : cnt){
        if(p.second==b) all.push_back(p.first);
        if(p.second==2*b){
            rep(i,2){
                all.push_back(p.first);
            }
        }    
    }
    if(all.size()==3&&(all[0]^all[1]^all[2])==0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}








Measured memory_bytes: 4224
#include<iostream>
using namespace std;
int main() {
	long long int K, N, max, ans;
	max = 0;
	ans = 0;
	cin >> K >> N;
	long long int A[200000], B[200001];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	A[N] = A[0] + K;
	for (int j = 0; j < N+1; j++) {
		B[j] = A[j + 1] - A[j];
	}
	for (int k = 0; k < N; k++) {
		if (B[k] > max) {
			max = B[k];
		}
	}
	for (int l = 0; l < N; l++) {
		ans = ans + B[l];
	}
	ans = ans - max;
	cout << ans << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
  int n = 0;
  cin >> n;
  vector<int> h(n);

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

  int cnt = 0;
  while(1){
    int zero_cnt = 0;
    for(int i = 0; i < n; i++){
      if(h[i] != 0){
        h[i]--;
        if(i == n-1 || h[i+1] == 0){
          cnt++;
        }
      }else{
        zero_cnt++;
      }
    }
    if(zero_cnt == n){
      break;
    }

  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256