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

int main ()
{
	int a,b;
	int l=0,r=0,x=-1,ic=0;
	string s;
	cin >> a >> b;
	cin >> s;
	
	for(int i=0;i<a+b+1;i++){
		if(s[i]>='0'&&s[i]<='9'){
			if(x==-1) l++;
			else r++;
		}
		else if(s[i]=='-'){
			ic++;
			x = 1;
		}
		else break;
	}
	if(l==a&&r==b&&ic==1) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
const ll Mod = 1000000007;
int main() {
  string S;
  cin >> S;
  if (S.back() == 's') {
    S += "es";
  } else {
    S += "s";
  }
  cout << S << endl;
  return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

const int MOD = 100000;
int dp[2][(1<<20)][2],H,W;
char G[20][20];
/*
dp[(x,y) & 1][column][Is the left is J?] := the number % 10^5
 */

inline void compute(int other){

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

  rep(y,H)rep(x,W) {
    int phase = ( x + y * W ) & 1;
    rep(i,(1<<W))rep(k,2) dp[!phase][i][k] = 0;
    rep(bitmask,(1<<W)){     

      int nbitmask = bitmask & (~(1<<x));

      if( G[y][x] == 'O' ) goto O;
      if( G[y][x] == 'I' ) goto I;

      // put J
      if( x != W-1 ) ( dp[!phase][nbitmask][1] += ( dp[phase][bitmask][0] + dp[phase][bitmask][1] ) ) %= MOD;
      else           ( dp[!phase][nbitmask][0] += ( dp[phase][bitmask][0] + dp[phase][bitmask][1] ) ) %= MOD;
      if( G[y][x] == 'J' ) goto Skip;

    O:;
      // put O
      // となりがJでない
      ( dp[!phase][nbitmask][0] += dp[phase][bitmask][0] ) %= MOD;

      // となりがJ
      if( x-1 >= 0 ) {
        nbitmask |= (1<<(x-1));
        ( dp[!phase][nbitmask][0] += dp[phase][bitmask][1] ) %= MOD;
        nbitmask &= (~(1<<(x-1)));
      }
      if( G[y][x] == 'O' ) goto Skip;

    I:;
      // put I
      if( !( ( bitmask>>x ) & 1 ) ) {
        nbitmask = nbitmask & (~(1<<x));
        ( dp[!phase][nbitmask][0] += ( dp[phase][bitmask][0] + dp[phase][bitmask][1] ) ) %= MOD;
      }
      
    Skip:;
      
    }
  }

  int sum = 0;
  rep(i,(1<<W)) rep(j,2) ( sum += dp[(H*W)&1][i][j] ) %= MOD;

  int total = 1;
  rep(i,other) ( total *= 3 ) %= MOD;
  cout << ( total - sum + MOD ) % MOD << endl;
}

int main(){
  cin >> H >> W;
  int other = 0;
  rep(i,H)rep(j,W){
    cin >> G[i][j];
    other += (G[i][j]=='?');
  }
  compute(other);
  return 0;
}

Measured memory_bytes: 17548
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll f(ll x)
{
    if(x==1)
    return 1;
    else if(x==2)
    return 3;
    else
    return 1+2*f(x/2);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
   ll n;
   cin>>n;
   cout<<f(n);}

Measured memory_bytes: 3612
N = int(input())
D, X = list(map(int, input().split()))
a = [int(input()) for i in range(N)]
num = [0 for i in a]
ans = X

for i in range(D):
    for j in range(N):
        if i % a[j] == 0:
            num[j] += 1

for j in range(N):
    ans += num[j]

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
const int INF=1001001001;
 
int N,M,R,Q;
 
vector<pint>G[111111];
 
void  dijkstra(int r,vint &dist){
    dist.resize(N);
    fill(all(dist),INF);
    priority_queue<pint,vector<pint>,greater<pint>>que;
    rep(i,N)if(i%R==r)dist[i]=0,que.push({0,i});
    while(que.size()){
        int v,c;
        tie(c,v)=que.top();
        que.pop();
        if(dist[v]<c)continue;
        for(auto &e:G[v]){
            if(dist[e.fi]<=c+e.se)continue;
            dist[e.fi]=c+e.se;
            que.push({dist[e.fi],e.fi});
        }
    }
}
 
signed main(){
    scanf("%lld%lld%lld%lld",&N,&M,&R,&Q);
 
    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[b].pb({a,c});
    }
 
    vector<vint>dist(R);
    rep(i,R)dijkstra(i,dist[i]);
 
    int ans=0;
    while(Q--){
        int x,y,z;
        scanf("%lld%lld%lld",&x,&y,&z);
        x--;y--;
        int mi=INF;
        rep(i,R)chmin(mi,dist[i][x]+dist[i][y]);
        ans+=max(0ll,z-mi);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 17148
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl

#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int,int> &a,
             const pair<int,int> &b)
{
    if(a.ff == b.ff) {
        return (b.ss < a.ss);
    }
    return (a.ff<b.ff);
}

bool prime[10000001];
void SieveOfEratosthenes(int n) 
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.

    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
int32_t main()
{
    IOS;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    /********************* From here ***********************/
    string s;
    cin >> s;
    int i = 0;
    int j = 1;
    int n = s.length();
    while(i>=0 && j<s.length()){
        //cerr << i << " " << j << endl;
        if((s[i]=='0'&&s[i+1]=='1') || (s[i]=='1'&&s[i+1]=='0')){
            
            s.erase(i, 2);
            if(i>0)
                {i--;
                j--;}
            //cout << s << endl;
            
        }
        else{
            i++;
            j++;
        }
    }
    cout << n -s.length();


}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define str string
#define rep(x) for(int y=0;y<x;y++)
#define all(x) begin(x),end(x)
int main(){
    int A,B,C,D;
    vector<char>s(19);
    cin>>A;
    B=A/15;
    if(A<15)B=0;
    cout<<800*A-200*B<<endl;
}


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

int N;
int A[100010];

int main() {
    scanf("%d", &N);

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

    sort(A, A + N);

    for(int i = N - 1; i >= 0; i--) {
        if(A[i] == N - i) {
            int j = i;
            while(j && A[j - 1] == A[j]) j--;

            if((i - j) % 2) {
                printf("First");
                return 0;
            }
            else {
                printf("Second");
                return 0;
            }
        }
        else if(i && A[i - 1] == N - i) {
            int j = i - 1;
            while(j && A[j - 1] == A[j]) j--;

            if((i - j) % 2 || (A[i] - N - i) % 2) {
                printf("First");
                return 0;
            }
            else {
                printf("Second");
                return 0;
            }
        }
        else if(i == 0 || A[i - 1] < N - i) {
            if((A[i] - N + i) % 2) {
                printf("First");
                return 0;
            }
            else {
                printf("Second");
                return 0;
            }
        }
    }
}


Measured memory_bytes: 640
n = gets.to_i
ts = gets.split(' ').map { |e| e.to_i }
m = gets.to_i
pxs = []
m.times { |i| 
  px = gets.split(' ').map { |e| e.to_i }
  pxs << px
}

sum = ts.inject :+

m.times { |i|
  p, x = pxs[i]
  p sum - ts[p - 1] + x
}

Measured memory_bytes: 1788
#include <stdio.h>

int main(void)

{

int a,b,c,d;

a=0,b=0,c=0,d=0 ;


scanf("%d %d\n",&a,&b);

c=a*b ;

d=2*a+2*b ;

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

return 0 ;

}

Measured memory_bytes: 600
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
ll x[200000];
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,k;cin>>n>>k;
  bool flag=true;
  int index=n,left_k,right_k;
  REP(i,n){
    cin>>x[i];
    if(x[i]>=0 && flag){
      index=i;
      flag=false;
    }
  }
  if(index==n){
    P(-x[n-k]);
    return 0;
  }
  if(index==0){
    P(x[k-1]);
    return 0;
  }
  left_k = index - k;
  right_k = index + k - 1;
  if(left_k<0)left_k=0;
  if(right_k>=n)right_k=n-1;
  ll mn=LINF;
  for(int i=left_k;i<=index;i++){//start地点
    if(i+k-1>n-1)continue;
    int sg=1,sgg=1;
    if(x[i]<0)sg=-1;
    if(x[i+k-1]<0)sgg=-1;
    mn=min(mn,min(x[i+k-1] - x[i] + sg*x[i], x[i+k-1] - x[i] + sgg*x[i+k-1]));
  }
  P(mn);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin>>h>>w;

  for(int i=0;i<w+2;i++)
  	cout<<"#";
  cout<<endl;
  for(int i=0;i<h;i++){
  	string a;
  	cin>>a;
  	cout<<"#"<<a<<"#"<<endl;
  }
  for(int i=0;i<w+2;i++)
  	cout<<"#";
  cout<<endl;
} 

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  int dmy[n + 2];
  int *a; a = dmy + 1;
  a[-1] = 0;
  a[0] = n + 1;
  for (int i = 1; i <= n; i++) {
    int j; cin >> j;
    a[j] = i;
  }
  set<int> s{0, n + 1};
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    auto lb = s.insert(a[i]).first;
    auto ub = lb;
    lb--; ub++;
    res += (long long) i * (a[i] - *lb) * (*ub - a[i]);
  }
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

int main() {
  std::string S, T;
  std::cin >> S >> T;
  int ans = T.size();
  for (int start = 0; start <= S.size() - T.size(); ++start) {
    int diff = 0;
    for (int i = 0; i < T.size(); ++i) {
      if (T[i] != S[start+i]) {
        diff++;
      }
    }
    ans = min(ans,diff);
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 3608
while True:
    a, op, b = input().split()
    a = int(a)                   
    b =  int(b)
    
    

    if op == "?":
        break
    else:
        if op == "+":
            print(a+b)
        if op == "-":
            print(a-b)
        if op == "*":
            print(a*b)
        if op == "/":
            print(a//b)


Measured memory_bytes: 5592
n = int(input())
s = input()
a = [0]*n
res = [0]*n
ans = 10**6
for i in range(n):
    if s[i] == 'W':
        a[i] = 1
res[0] = a[0]
for i in range(n-1):
    res[i+1] = res[i] + a[i+1]
for i in range(n):
    x = res[i]-str(a[i]).count('1')
    y = n-i-1-(res[n-1]-res[i])
    ans = min(ans,x+y)
print(ans)


Measured memory_bytes: 17548
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N;
string s;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> s;
    int cnt = 0;
    char pre = 'A';
    rep(i,N) {
        if (s[i] != pre) {
            cnt++;
            pre = s[i];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

int main(){
	ll N;
	cin >> N;
	vector<string> S(N);
	ll i, j;
	for (auto &e : S)cin >> e;
	ll ans = 0;
	ll beginb = 0;
	ll enda = 0;
	ll both = 0;
	for (auto s : S){
		if (s[0] == 'B' && s[s.length() - 1] != 'A'){
			beginb++;
		}
		if (s[0] != 'B' && s[s.length() - 1] == 'A'){
			enda++;
		}
		if (s[0] == 'B' && s[s.length() - 1] == 'A'){
			both++;
		}
		for (i = 0; i < s.length() - 1; i++){
			if (s[i] == 'A' && s[i + 1] == 'B'){
				ans++;
			}
		}
	}
	ans += min(beginb, enda) + both;
	if (beginb == 0 && enda == 0 && both > 0){
		ans--;
	}
	//if (both == beginb && both == enda && enda > 0){
	//	ans--;
	//}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 768
S = input()
while len(S):
    if S[-5:] == 'dream' or S[-5:] == 'erase':
        S = S[0:-5]
    elif S[-6:] == 'eraser':
        S = S[0:-6]
    elif S[-7:] == 'dreamer':
        S = S[0:-7]
    else:
        print('NO')
        exit()
print('YES')

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

using namespace std;
using ll = long long;


int main()
{
    string s;
    cin>>s;
    if(s=="SUN")cout<<7;
    else if(s=="MON")cout<<6;
    else if(s=="TUE")cout<<5;
    else if(s=="WED")cout<<4;
    else if(s=="THU")cout<<3;
    else if(s=="FRI")cout<<2;
    else cout<<1;
    return 0;
}


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


int main() {
  int l, r, d;
  cin >> l >> r >> d;
  int ans =  r/d-l/d;
  if(l%d==0) ans ++;
  cout << ans << endl;
  return 0;
}

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

#define st first
#define nd second
#define pb push_back

typedef long long   ll;
typedef double      db;
typedef long double ldb;

typedef pair <int, int> pii;
typedef pair <ll,  ll>  pll;
typedef pair <ll,  db>  pdb;
typedef pair <ldb, ldb> pldb;

template <typename T>
void   Debug (T begin, T end);
int    si    ();
ll     sl    ();
string ss    (int);
db     sf    ();
ldb    slf   ();
void   pi    (int, char = '\n');
void   pl    (ll, char = '\n');
void   pf    (db, char = '\n');
void   plf   (ldb, char = '\n');
void   ps    (string, char = '\n');

ll russian(ll, ll, ll);
ll fastpow(ll, ll, ll);
ll slowpow(ll, ll, ll);
ll _gcd(ll, ll);
ll _lcm(ll, ll);
ll extgcd(ll, ll, ll&, ll&);
ll _inv(ll, ll);

const int INF  = 1e9;
const ll  LINF = 1e18;

int main()
{
    int n = si();
    for (int i = 1; i <= n; ++i)
        if (n % i == 0 && i < 10 && n / i < 10)
        {
            ps("Yes");
            return 0;
        }
    ps("No");

    return 0;
}

template <typename T>
void Debug(T begin, T end)
{
    printf("\nDEBUG:\n");
    while (begin != end)
        printf("%d ", *begin),
        begin++;
    printf("\n\n");
}

template <typename T>
T scanf_t(string s)
{
    T a;
    scanf(s.c_str(), &a);
    return a;
}

template <typename T>
void printf_t(T a, string s, char end_l)
{
    s.push_back(end_l);
    printf(s.c_str(), a);
}

int si() { return scanf_t<int>("%d"); }
ll sl() { return scanf_t<ll>("%lld"); }
db sf() { return scanf_t<db>("%f"); }
ldb slf() { return scanf_t<ldb>("%Lf"); }

void pi(int a, char end_l) { printf_t<int>(a, "%d", end_l); }
void pl(ll a, char end_l) { printf_t<ll>(a, "%lld", end_l); }
void pf(db a, char end_l) { printf_t<db>(a, "%lf", end_l); }
void plf(ldb a, char end_l) { printf_t<ldb>(a, "%Lf", end_l); }

void ps(string a, char end_l)
{
    string s = "%s";
    s.push_back(end_l);
    printf(s.c_str(), a.c_str());
}

string ss(int NN)
{
    char T[NN];
    scanf("%s", T);
    return (string)T;
}

ll fastpow(ll a, ll k, ll m)
{
    ll r = 1LL;
    while (k)
    {
        if (k & 1LL)
            r = (r * a) % m;
        a = (a * a) % m;
        k >>= 1LL;
    }
    return r;
}

ll slowpow(ll a, ll k, ll m)
{
    ll r = 1LL;
    while (k)
    {
        if (k & 1LL)
            r = russian(r, a, m);
        a = russian(a, a, m);
        k >>= 1LL;
    }
    return r;
}

ll russian(ll a, ll k, ll m)
{
    ll r = 0LL;
    while (k)
    {
        if (k & 1LL)
            r = (r + a) % m;
        a = (a + a) % m;
        k >>= 1LL;
    }
    return r;
}

ll _gcd(ll a, ll b)
{
    while (b)
        swap(a %= b, b);
    return a;
}

ll _lcm(ll a, ll b)
{
    return a / _gcd(a, b) * b;
}

ll extgcd(ll a, ll b, ll& k, ll& l)
{
    if (b == 0)
    {
        k = 1; l = 0;
        return a;
    }
    ll res = extgcd(b, a % b, l, k);
    l -= a / b * k;
    return res;
}

ll _inv(ll a, ll p)
{
    return fastpow(a, p - 2, p);
}



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

//O[1]

int main() {
    ll N, K;
    cin >> N >> K;
    ll num = N/K;
    ll rem = N%K;
    
    ll count = 0;
    count += pow(num, 3);

    if (K % 2 == 0) {
        if (rem >= K/2) num ++;
        count += pow(num, 3);
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		long num = sc.nextLong();
		long ans = num / 11 * 2;
		if(num % 11 > 6)
			ans = ans + 2;
		else if (num % 11 > 0)
			ans++;
		
		out.println(ans);

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 23380
N, M, X, Y = gets.chomp.split.map(&:to_i)
xn = gets.chomp.split.map(&:to_i)
ym = gets.chomp.split.map(&:to_i)

xnmax = xn.max
ymmin = ym.min
nowar = ymmin - xnmax >= 1 && Y - X >= 1 && ymmin - X >= 1 && Y - xnmax >= 1

puts nowar ? "No War" : "War" 

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7,N=80002;
int n,k,f[102][N],i,j,las,l[N],r[N],cnt,num[N],t,ans;
map<int,int>mp;
void inc(int &x,int y){x+=y;if(x>=M)x-=M;}
void dec(int &x,int y){x-=y;if(x<0)x+=M;}
//int dfs(int x,int y){
//	if (f[x][y]) return f[x][y];
//	if (x==k) return y;
//	int ans=0;
//	for (int i=1,j;i<=n && i<=y;i=j+1) j=min(y,n/(n/i)),inc(ans,1ll*dfs(x+1,n/i)*(j-i+1)%M);
//	return f[x][y]=ans;
//}
//int dfs(int x,int y){
//	if (f[x][y]) return f[x][y];
//	int ans=0;
//	for (int i=1;i<=cnt && l[i]<=num[y];i++) inc(ans,1ll*dfs(x+1,mp[n/l[i]])*(min(num[y],r[i])-l[i]+1)%M);
//	return f[x][y]=ans;
//}
int main(){
	scanf("%d%d",&n,&k);
	for (i=1;i<=n;i=j+1) j=n/(n/i),l[++cnt]=i,r[cnt]=j,num[cnt]=n/i,mp[n/i]=cnt,f[k][cnt]=num[cnt];
//	printf("%d",dfs(1,1));
	for (t=k-1;t;t--){
		for (las=0,i=cnt,j=1;i;i--){
//			f[t][i]=(f[t][i+1]-las+M)%M;
//			for (;j<=cnt && r[j]<=num[i];j++) inc(f[t][i],1ll*f[t+1][j]*(r[j]-l[j]+1)%M);
//			las=1ll*f[t+1][j]*(num[i]-l[j]+1)%M;
//			inc(f[t][i],las);
//			inc(f[t][i],1ll*f[t+1][j]*(num[i]-l[j]+1)%M);
//			for (j=1;j<=cnt && l[j]<=num[i];j++) inc(f[t][i],1ll*f[t+1][mp[n/l[j]]]*(min(num[i],r[j])-l[j]+1)%M);
			f[t][i]=(f[t][i+1]-las+M)%M;
			for (;j<=cnt && l[j]<=num[i];j++) las=1ll*f[t+1][mp[n/l[j]]]*(min(num[i],r[j])-l[j]+1)%M,inc(f[t][i],las);
			j--;
		}
	}
	printf("%d",f[1][1]);
}

Measured memory_bytes: 35328
#include <iostream>
#include<stdio.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    int a,b,i,j,n;
    string s1,s2;
    while(cin>>s1>>s2)
    {
        int sum=0;
        for(i=0; i<3; i++)
        {
                if(s1[i]!=s2[2-i])
                    sum++;
        }
        if(sum==0)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }

    return 0;
}

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

using namespace std;
using ll = long long;

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

    int r = -1;

    for(int i = 1 ; i <= 1000;i++){
        int sum8 = i * 0.08;
        int sum10 = i * 0.10;
        if(sum8 == a && sum10 == b){
            r = i;
            break;
        }
    }
    
    cout << r  << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

typedef complex<double> P;
typedef pair<P,double> C;

double d[1010][1010];


double func(C &a, C &b){
	if(abs(a.F-b.F) <= a.S+b.S){
		return 0;
	}
	return abs(a.F-b.F)-a.S-b.S;
}


void mainmain(){
	P s,g;
	double aa,bb;
	cin>>aa>>bb;
	s=P(aa,bb);
	cin>>aa>>bb;
	g=P(aa,bb);
	int n;
	cin>>n;
	vector<C> v(n);
	rep(i,n){
		double a,b,c;
		cin>>a>>b>>c;
		v[i] = mkp(P(a,b), c);
	}
	n += 2;
	v.PB(mkp(s,0));
	v.PB(mkp(g,0));
	rep(i,n){
		rep(j,i){
			double dis = func(v[i],v[j]);
			d[i][j] = dis;
			d[j][i] = dis;
		}
	}
	rep(i,n) d[i][i] = 0;
	rep(k,n){
		rep(i,n){
			rep(j,n){
				mins(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
	cout << d[n-2][n-1] << endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 8320
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>

using namespace std;

#define pb push_back
#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    if (x <= 599){
        cout << 8;
    }
    else if (x <= 799){
        cout << 7;
    }
    else if (x <= 999){
        cout << 6;
    }
    else if (x <= 1199){
        cout << 5;
    }
    else if (x <= 1399){
        cout << 4;
    }
    else if (x <= 1599){
        cout << 3;
    }
    else if (x <= 1799){
        cout << 2;
    }
    else{
        cout << 1;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  string S; cin >> S;

  reverse(S.begin(),S.end());
  ll N = S.size();
  
  ll ans = 0;
  for (int tmp = 0; tmp < (1 << N-1); tmp++) {
    bitset<10> s(tmp);
    int count = 0;
    ll num = S[0] - '0';
    rep(i,N-1) {
      count++;
      if (s.test(i)) count = 0;
      num += (S[i+1] - '0') * pow(10,count);
    }
    ans += num;
  }

  cout << ans << endl;
}



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

int main() {
  int n;
  cin >> n;
  int l[n];
  for ( int i = 0; i < n; i++ ) { cin >> l[i]; }
  sort(l, l+n);
  int sum = 0;
  for ( int i = 0; i < n-1; i++ ) { sum += l[i]; }
  string ans = ( sum > l[n-1] ) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  if(s[0] == 'A') {
    int cnt = 0;
    FOR(i,1,s.length()) {
      if(i >= 2 && i <= s.length() - 2) {
        if(s[i] == 'C') cnt++;
        else if(isupper(s[i])) {
          cout << "WA" << endl;
          return 0;
        }
      } else {
        if(isupper(s[i])) {
          cout << "WA" << endl;
          return 0;
        }
      }
    }
    if(cnt == 1) {
      cout << "AC" << endl;
    } else {
      cout << "WA" << endl;
    }
  } else {
    cout << "WA" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	
	ll X;
	cin>>X;

	ll yokin = 100;
	int nen = 0;
	while( yokin < X){
		yokin = yokin + yokin / 100;
		nen++;
	}
	
	cout<<nen<<endl;

	return 0;
}



Measured memory_bytes: 3648
a = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

n = int(input())
for i in range(1, n + 1):
    b, f, r, v = map(int, input().split())
    a[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        for k in range(10):
            print("", a[i][j][k], end="")
            if k == 9:
                print()
        if j == 2 and i != 3:
            print("####################")

Measured memory_bytes: 7704
n = int(input())
cnt = 0
zoro = False
for i in range(n):
    d1,d2 = map(int,input().split())
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        zoro = True
if zoro:
    print('Yes')
else:
    print('No')

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

using namespace std;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


typedef long long ll;

int main() {
	int a,b;
	cin >> a >> b;
	if(a > 8 || b > 8) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ON			1										// 汎用フラグ - ON
#define D_OFF			0										// 汎用フラグ - OFF
#define D_MOD			(long long)1000000007					// 除数(10の9乗+7)
#define D_AMD_MAX		8										// 最大あみだ数

// 内部変数
static FILE *szpFpI;											// 入力
static int siH;													// 高さ
static int siACnt;												// あみだ数
static int siGoal;												// 到着位置
static int si2Ptn[D_AMD_MAX + 5][D_AMD_MAX + 5];				// 変換パターン数[移動前][移動後]

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 変換パターン数[あみだ] - セット
int
fSetPtn(
	int piANo					// <I> あみだ 1～
	, int *pipXBar				// <I> 横棒グラフ
)
{
	int i;

	// 終了チェック
	if (piANo == siACnt) {

		// 変換パターン数[あみだ] - セット
		for (i = 1; i <= siACnt; i++) {
			if (pipXBar[i - 1] == D_ON) {			// 左へ
				si2Ptn[i][i - 1]++;
			}
			else if (pipXBar[i] == D_ON) {			// 右へ
				si2Ptn[i][i + 1]++;
			}
			else {									// 移動なし
				si2Ptn[i][i]++;
			}
		}

		return 0;
	}

	// 横棒あり
	if (pipXBar[piANo - 1] == D_OFF) {			// 左になし
		pipXBar[piANo] = D_ON;						// セット
		fSetPtn(piANo + 1, pipXBar);				// 下位へ
		pipXBar[piANo] = D_OFF;						// クリア
	}

	// 横棒なし
	fSetPtn(piANo + 1, pipXBar);				// 下位へ

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, j, k;
	char lc1Buf[1024], lc1Out[1024];

	// データ - 初期化
	memset(si2Ptn, 0, sizeof(si2Ptn));							// 変換パターン数[あみだ]

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 高さ・あみだ数・到着位置 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d%d", &siH, &siACnt, &siGoal);

	// 変換パターン数[あみだ] - セット
	int li1XBar[D_AMD_MAX + 5];
	memset(li1XBar, D_OFF, sizeof(li1XBar));
	fSetPtn(1, li1XBar);

	// パターン数 - 初期値
	long long ll1PtnNow[D_AMD_MAX + 5];
	memset(ll1PtnNow, 0, sizeof(ll1PtnNow));
	ll1PtnNow[1] = 1;

	// 高さ(回数)でループ
	for (i = 0; i < siH; i++) {
		long long ll1PtnNew[D_AMD_MAX + 5];
		memset(ll1PtnNew, 0, sizeof(ll1PtnNew));

		// パターン数 - 乗算
		for (j = 1; j <= siACnt; j++) {
			for (k = 1; k <= siACnt; k++) {
				ll1PtnNew[k] += ll1PtnNow[j] * (long long)si2Ptn[j][k];
				ll1PtnNew[k] %= D_MOD;
			}
		}

		// パターン数 - 更新
		for (j = 1; j <= siACnt; j++) {
			ll1PtnNow[j] = ll1PtnNew[j];
		}
	}

	// 結果 - セット
	sprintf(lc1Out, "%lld\n", ll1PtnNow[siGoal]);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

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

    vector < pair<long, long> > X;

    auto c = [](pair<long, long> l, pair<long, long> r) { if ( r.second < l.second ) return true; else return false; };
    priority_queue < pair<long, long>, vector< pair<long, long> >, decltype(c) > que(c);

    long A, B;
    for(int i=0; i<N; i++){
        cin >> A >> B;
        X.push_back(make_pair(A,B));
    }

    sort(X.begin(),X.end(),std::greater< pair<long, long> >());

    long count=0;
    long value=0;
    for(auto x: X){
        if( count + x.first <= M ){
            que.push(x);
            value += x.second;
            count++;
        }else{
            if(que.empty()) continue;
            auto y=que.top();
            if( value - y.second + x.second > value  && count-1+x.first <= M ){
                que.pop();
                que.push(x);
                value = value - y.second + x.second;
            }
        }
        //cout << "count value " << count << " " <<  value << endl;
    }

    cout << value << endl;

    return 0;
}

Measured memory_bytes: 4848
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int s[20][20],a[20][20];
void flody()
{
    int i,j,k;
    for(k=0;k<10;k++)
    for(i=0;i<10;i++)
    for(j=0;j<10;j++)
    s[i][j]=min(s[i][j],s[i][k]+s[k][j]);
}
int main()
{
    int i,j,k,n,m;
    long long ans=0;
    scanf("%d%d",&n,&m);
    for(i=0;i<10;i++)
    for(j=0;j<10;j++)
    {
        scanf("%d",&a[i][j]);
        s[i][j]=a[i][j];
    }
    flody();
    /*for(i=0;i<10;i++)
    {for(j=0;j<10;j++)
    printf("%d ",s[i][j]);
    printf("\n");
    }*/
    for(i=0;i<n;i++)
    for(j=0;j<m;j++)
    {
        scanf("%d",&k);
        if(k==-1||k==1)
        continue;
        ans=ans+s[k][1];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
struct node
{
	int num;
	int xian;
	int shi;
	int time;
}d[100005];
bool cmp1(node a,node b)
{
	if(a.xian<b.xian)return true;
	else if(a.xian==b.xian)
	{
		if(a.time<b.time)return true;
		else return false;
	}
	return false;
	
}
bool cmp2(node a,node b)
{
	return a.num<b.num;
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>d[i].xian>>d[i].time;
		d[i].num=i;
	}
	sort(d+1,d+m+1,cmp1);
	int cnt=1;
	for(int i=1;i<=m;i++)
	{
		if(i!=1&&d[i].xian!=d[i-1].xian)cnt=1;
		d[i].shi=cnt;
		cnt++;
	}
	sort(d+1,d+m+1,cmp2);
	for(int i=1;i<=m;i++)
	{
		printf("%06d%06d\n",d[i].xian,d[i].shi);
	}
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main(){

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

    int H, W;
    cin >> H >> W;

    string s;
    vector<string> ss;
    for(int i=0; i<H; i++){
        cin >> s;
        ss.push_back(s);
    }

    bool ok=false;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(ss[i][j] == '#'){
                ok = false;
                for(int d=0; d<4; d++){
                    int a = dy[d] + i;
                    int b = dx[d] + j;
                    if(a<0||b<0||a>=H||b>=W) continue;
                    if(ss[a][b] == '#') ok=true;
                }
                if(ok==false){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int i,j;
    i=(c+b-1)/b;
    j=(a+d-1)/d;
    if(i<=j)printf("Yes");
    else printf("No");
}


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


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep3(i, n, m) for (int i = n; i <= m; i++)

using ll = long long;

/* vector<ll> v(N);
  小さい順: sort(v.begin(), v.end());
  逆順: reverse(v.begin(), v.end());
  vector<pair<ll, ll> > p; ＃ソートした場合、１つ目でソート
  tie(b, a) = p.at(i); #pairを分割
  tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
  xの二乗:  pow(x, 2.0);
  int: -2,147,483,648 ～ 2,147,483,647(2×10^9)
  ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807(9×10^18)
  long long型の2次元配列(3×4要素の)の宣言
  vector<vector<ll>> ;
  string -> int : stoi(S);
  int -> string : to_string(N);
  Sのn文字以降をm文字取り出す : S.substr(n,m)
*/
 
 //126~
 //126-d

int main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n);
  vector<pair<ll,ll>> cb(m);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,m){
    cin >> cb[i].second >> cb[i].first;
  }
  sort(a.begin(),a.end());
  sort(cb.begin(),cb.end());
  reverse(cb.begin(), cb.end());
  int num=0;
  bool fin=false;
  rep(i,m){
    rep(l,cb[i].second){
      if(cb[i].first>a[num]&&num<n){
        a[num] = cb[i].first;
        num++;
      }
      else{
        fin=true;
        break;
      }
    }

    if(fin)break;
  }

  ll ans=0;
  rep(i,n){
    ans+=a[i];
  }

  cout << ans << endl;

}

Measured memory_bytes: 2560
void main()
{
    string s = readln.chomp;
    string t = "CODEFESTIVAL2016";

    int cnt;
    foreach (i; 0 .. 16)
    {
        if (s[i] != t[i]) ++cnt;
    }

    cnt.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

int main()
{ 
  int A[3][3] = {};
  bool check[3][3] = {false};
  int N;
  for(int i = 0; i < 3;i++){
    for(int j = 0; j < 3;j++){
      cin >> A[i][j];
    }
  }
  cin >> N;
  int b[N];
  for(int i = 0; i < N;i++) cin >> b[i];

  for(int i = 0; i < N;i++){
    for(int j = 0; j < 3;j++){
      for(int k = 0; k < 3;k++){
          if(b[i] == A[j][k]) check[j][k] = true;
      }
    }
  }
  string s = "No";
  for(int i = 0; i < 3; i++){
    if(check[i][0] && check[i][1] && check[i][2]) s = "Yes";
    if(check[0][i] && check[1][i] && check[2][i]) s = "Yes";
  }
  if(check[0][0] && check[1][1] && check[2][2]) s = "Yes";
  if(check[0][2] && check[1][1] && check[2][0]) s = "Yes";
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 764
x,y=map(int,input().split())
S=list(map(str,input()))
if S[y-1]=="A":
    for i in range(x):
        S[y-1]="a"
        print(S[i],end="")
elif S[y-1]=="B":
    for i in range(x):
        S[y-1]="b"
        print(S[i],end="")
elif S[y-1]=="C":
    for i in range(x):
        S[y-1]="c"
        print(S[i],end="")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())


int tax(int p, int r) {
    return p*(100+r)/100;
}

void solve(void){
    while (1) {
        int s, x, y;
        scanf("%d %d %d\n", &x, &y, &s);
        if (s == 0 && x == 0 && y == 0) break;
        int ans = 0;
        Rep(1, s-1, i) Rep(1, s-1, j) if (tax(i, x) + tax(j, x) == s) ans = max(ans, tax(i, y) + tax(j, y));
        printf("%d\n", ans);
    }
}

int main(void){
  solve();
  return 0;
}



Measured memory_bytes: 3192
#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[i];
	}

	sort( A.begin(), A.end() );
	int st = 0;
	if( N % 2 ) st = 1;
	long long ans = 1;
	for( int i = st; i < N; i++ ) {
		if( A[i] == A[i + 1] ) i++;
		else {
			ans = 0;
			break;
		}
	}
	if( ans ) {
		if( N % 2 && A[0] != 0 ) ans = 0;
	}
	const long long MOD = 1000000000 + 7;
	for( int i = 0; i < N / 2; i++ ) {
		ans = ans * 2 % MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3704
object Main extends App {

  import scala.io.StdIn._

  val lines = io.Source.stdin.getLines().map{_.trim.split(' ').map(_.toDouble)}.toArray
  println(
    s"${lines.count(_(0) >= 1.1)} ${lines.count(_(1) >= 1.1)}"
  )
  println(
    s"${lines.count(i ⇒ 1.1 > i(0) && i(0) >= 0.6)} ${lines.count(i ⇒ 1.1 > i(1) && i(1) >= 0.6)}"
  )
  println(
    s"${lines.count(i ⇒ 0.6 > i(0) && i(0) >= 0.2)} ${lines.count(i ⇒ 0.6 > i(1) && i(1) >= 0.2)}"
  )
  println(
    s"${lines.count(i ⇒ 0.2 > i(0))} ${lines.count(i ⇒ 0.2 > i(1))}"
  )

  implicit class Extention[T](value :T){
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 43908
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 (a > b) { a = b; return 1; } return 0; }

int n, m, q;
int a[50], b[50], c[50], d[50];

int ans;

void dfs(vector<int> &v){
	if(v.size() == n){
		int score = 0;
		rep(i,q){
			if(v[b[i]] - v[a[i]] == c[i]) score += d[i];
		}
		chmax(ans, score);
		return;
	}
	int last;
	if(v.empty()) last = 1;
	else last = v[v.size()-1];
	for(int add = last; add <= m; add++){
		vector<int> w = v;
		w.push_back(add);
		dfs(w);
	}
	return;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m >> q;
	rep(i,q){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	ans = 0;
	vector<int> w;
	dfs(w);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
	ios::sync_with_stdio(0), cin.tie(0);
    	string s;
    	cin >> s;
    	cout << s[0] << s[1] << s[2];
    	
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int n, k;

int main(){
    cin >> n >> k;
    vector<int>  l = vector<int>(n);

    for(int i = 0; i< n; i++){
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());

    int ans = 0;

    for(int i = 1; i< k+1; i++){
        ans += l.at(l.size()- i);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>

typedef long long ll;
typedef unsigned long long ull;

ull countBits(ull number)
{
	return (ll)log2(number) + 1;
}

int main() 
{
	ull H;
	std::cin >> H;
	std::cout << (ull)pow(2, countBits(H)) - 1;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    bool s[3] = {};
    string x;
    cin >> x;
    for (int i = 0; i < 3; ++i)
        s[x[i] - 'a'] = true;
    bool judge = true;
    for (int i = 0; i < 3; ++i)
        if (s[i] == false){
            judge = false;
            break;
        }
    if (judge) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        k: usize,
        aa: [usize; n]
    };
    let mut hm = std::collections::HashMap::new();
    for a in aa {
        *hm.entry(a).or_insert(0) += 1;
    }

    let mut v = hm.values().into_iter().map(|&i| i).collect::<Vec<i32>>();
    v.sort();
    if v.len() <= k {
        println!("0");
        return;
    }

    println!("{}", v[0..(v.len() - k)].into_iter().sum::<i32>());

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


Measured memory_bytes: 11412
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int num[100];
ll memo[100][21];
int n;

inline bool valid(int n){
  return n <= 20 && n >= 0;
}

ll solve(int pos, int sum){
  if(pos == n - 1)
    return sum == num[n-1] ? 1 : 0;

  if(memo[pos][sum] != -1)
    return memo[pos][sum];

  ll ret = 0;
  if(valid(sum + num[pos]))
    ret += solve(pos + 1, sum + num[pos]);
  if(pos != 0 && valid(sum - num[pos]))
    ret += solve(pos + 1, sum - num[pos]);

  return memo[pos][sum] = ret;
}

int main(){
  n = getInt();
  memset(memo, -1, sizeof(memo));
  REP(i,n) num[i] = getInt();
  cout << solve(0, 0) << endl;
  return 0;
}

Measured memory_bytes: 0