akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int N;
int dp[2000][2000],X[2000],Y[2000],nX[2000],nY[2000];
int A[3];
int tmp[2000];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)dp[i][j]=-1e9;
	for(int i=0;i<N;i++)X[i]=Y[i]=-1e9;
	cin>>A[0]>>A[1];
	A[0]--,A[1]--;
	dp[A[0]][A[1]]=0;
	X[A[0]]=0;
	Y[A[1]]=0;
	int ans=0;
	for(int i=1;i<N;i++)
	{
		int T[3];
		for(int j=0;j<3;j++)
		{
			cin>>A[j];
			A[j]--;
			T[j]=dp[A[j]][A[j]];
		}
		if(A[0]==A[1]&&A[1]==A[2])
		{
			ans++;
			continue;
		}
		int MX=0;
		for(int j=0;j<N;j++)
		{
			nX[j]=X[j];
			nY[j]=Y[j];
			if(MX<X[j])MX=X[j];
			if(MX<Y[j])MX=Y[j];
		}
		for(int j=0;j<3;j++)
		{
			int a=A[j],b=A[(j+1)%3],c=A[(j+2)%3];
			if(a==b)
			{
				for(int k=0;k<N;k++)tmp[k]=max(dp[a][k],dp[k][a]);
				for(int k=0;k<N;k++)
				{
					int now=dp[k][c]=max(dp[k][c],tmp[k]+1);
					if(nX[k]<now)nX[k]=now;
					if(nY[c]<now)nY[c]=now;
				}
			}
		}
		for(int j=0;j<3;j++)
		{
			int b=A[(j+1)%3],c=A[(j+2)%3];
			int now=dp[b][c]=max(dp[b][c],T[j]+1);
			if(nX[b]<now)nX[b]=now;
			if(nY[c]<now)nY[c]=now;
		}
		for(int j=0;j<3;j++)for(int k=0;k<3;k++)if(j!=k)
		{
			int a=A[j],b=A[k];
			int now=dp[a][b]=max(dp[a][b],MX);
			if(nX[a]<now)nX[a]=now;
			if(nY[b]<now)nY[b]=now;
		}
		for(int j=0;j<N;j++)
		{
			for(int k=0;k<3;k++)
			{
				int a=A[k];
				int now=dp[j][a]=max(dp[j][a],X[j]);
				if(nX[j]<now)nX[j]=now;
				if(nY[a]<now)nY[a]=now;
				now=dp[a][j]=max(dp[a][j],Y[j]);
				if(nX[a]<now)nX[a]=now;
				if(nY[j]<now)nY[j]=now;
			}
			X[j]=nX[j];
			Y[j]=nY[j];
		}
	}
	int x;cin>>x;x--;
	int MX=0;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)
	{
		MX=max(MX,dp[i][j]+(i==j&&j==x));
	}
	cout<<MX+ans<<endl;
}

Measured memory_bytes: 19212
#include <stdio.h>

int main(void){
	int i, j;
	int H, W;
	while(1){
		scanf("%d %d", &H, &W);
		if(H==0 && W==0) break;
		for(i=0;i<H;i++){
			for(j=0;j<W;j++) printf("#");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;
const ll MOD=1e9+7;
ll dp[100001];
int a[100000];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
		cin>>a[i];
	dp[0]=1;
	int apt=0;
	if(a[apt]==1)
	{
		dp[1]=0;
		apt++;
	}else
		dp[1]=1;
	for(int i=2;i<n+1;i++)
	{
		if(apt<m && a[apt]==i)
		{
			dp[i]=0;
			apt++;
			continue;
		}
		dp[i]=dp[i-1]+dp[i-2];
		dp[i]%=MOD;
	}
	if(dp[n]<0)
		dp[n]+=MOD;
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1e9 + 7;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
void spsp(vector<ll>&v) {
	for (int i = 0; i < v.size(); i++) {
		printf("%lld%s", v[i], (i == v.size() - 1 ? "\n" : " "));
	}
}
/*ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy*/
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
string s;
int a[600000];
signed main() {
	cin >> s;
	n = s.size() + 1;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == '<') {
			a[i + 1] = max(a[i] + 1, a[i + 1]);
		}
	}
	for (int i = n - 2; i >= 0; i--) {
		if (s[i] == '>') {
			a[i] = max(a[i + 1] + 1, a[i]);
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 4996
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    o = list(input())
    e = list(input())

    res = [""] * (len(o) + len(e))
    for i in range(len(o) + len(e)):
        if i % 2 != 0:
            s = e.pop(0)
            res[i] = s
        else:
            s = o.pop(0)
            res[i] = s

    print("".join(res))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <cstdint>
#include <iostream>

constexpr int64_t kPrime = 1000000007;

void CallCalculatePower(std::istream &input_stream) noexcept;

int64_t CalculatePower(const int64_t x, const int64_t n) noexcept;

void CallCalculatePower(std::istream &input_stream) noexcept {
  input_stream.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t m;
  int64_t n;
  input_stream >> m >> n;
  int64_t result = CalculatePower(m, n);
  std::cout << result << std::endl;
}

int64_t CalculatePower(const int64_t x, const int64_t n) noexcept {
  if (n == 0) {
    return 1;
  }
  int64_t result = CalculatePower((x * x) % kPrime, n / 2);
  if (n % 2 == 1) {
    result = (result * x) % kPrime;
  }
  return result;
}

int main() {
  try {
    CallCalculatePower(std::cin);
  } catch (...) {
    std::cerr << "ERROR: main()" << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3216
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

bool solve(vector< vector<int> > pts,
           int pa, int pb, int pc, vector<int> gain) {
    int N = pts[0].size();
    pts[0][0] += pa, pts[1][0] += pb, pts[2][0] += pc;

    vector<int> ord(N), sum(N);
    iota(ord.begin(), ord.end(), 0);
    for(int t=0; t<3; t++) {
        sort(ord.begin(), ord.end(), [&](int x, int y) {
                return pts[t][x] > pts[t][y];
            });

        int rank = -1, pre = -1;
        for(int i=0; i<N; i++) {
            if(pre != pts[t][ ord[i] ]) rank = i;
            sum[ ord[i] ] += gain[rank];
            pre = pts[t][ ord[i] ];
        }
    }

    sort(ord.begin(), ord.end(), [&](int x, int y) {
            return sum[x] > sum[y];
        });
    int rank = 0, pre;
    for(int i=0; i<N; i++) {
        if(pre != sum[ ord[i] ]) rank = i+1;
        if(ord[i] == 0) return rank < 9;
        pre = sum[ ord[i] ];
    }
    return false;
}

int main() {
    int N; scanf("%d", &N);
    vector<int> gain(N);
    for(int i=0; i<N; i++) scanf("%d", &gain[i]);

    vector< vector<int> > pts(3, vector<int>(N));
    for(int i=0; i<N; i++) {
        for(int j=0; j<3; j++) scanf("%d", &pts[j][i]);
    }

    int ans = INF;
    for(int p=1; p<=100; p++) {
        bool ok = false;
        ok |= solve(pts, p, 0, 0, gain);
        ok |= solve(pts, 0, p, 0, gain);
        ok |= solve(pts, 0, 0, p, gain);
        if(ok) {
            ans = p;
            break;
        }
    }
    if(ans == INF) {
        cout << "Saiko" << endl;
    }
    else {
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3220
N,M=map(int,input().split())
pic=[list(input()) for _ in range(N)]
temp=[list(input()) for __ in range(M)]
flag=0
for i in range(N-M+1):
    if flag==0:
        for j in range(N-M+1):
            if all(pic[x+j][i:i+M]==temp[x] for x in range(M)):
                print("Yes")
                flag=1
                break
if flag==0:print("No")

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**9)


def search(cr_node, cr_depth, is_visited, edges, max_depth):
    if cr_node in is_visited:
        return 0
    elif cr_depth == max_depth:
        return 1
    else:
        count = 0

        if edges[cr_node]:
            is_visited.add(cr_node)
            for edge in edges[cr_node]:
                count += search(edge, cr_depth + 1,
                                is_visited, edges, max_depth)
            is_visited.remove(cr_node)

        return count


def main():
    N, M = map(int, input().split())
    edges = dict()
    for i in range(N):
        edges[i] = []

    for i in range(M):
        a, b = map(int, input().split())
        edges[a - 1].append(b - 1)
        edges[b - 1].append(a - 1)

    print(search(0, 1, set(), edges, N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#define m 1000000007
using namespace std;
int main()
{
    long long n,i,j;
    cin>>n;
    long long a[n],c[n],sum=0;
    for(i=0;i<n;i++)
        cin>>a[i];
    c[0]=a[0];
    for(i=1;i<n;i++)
        c[i]=(c[i-1]+a[i])%m;
    for(i=n-1;i>0;i--)
    {
        sum=(sum+(c[i-1]*a[i])%m)%m;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 6744
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int v[1005];
  double x=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  sort(v,v+n);
  x=(double)v[0];
  for(int i=1;i<n;i++){
    x=(x+(double)v[i])/2;
  }
  cout<<x<<"\n";
  return 0;
}


Measured memory_bytes: 256
#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);

    int i = 1, c = 0;
    for (int j = 0; j < n + 1; j++) {
        c++;
        i = a.at(i - 1);
        if (i == 2) break;
    }

    if (c <= n) {
        cout << c << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
int main(void)
{
    long long int a,b,c,d,i,j,k,n;
    string s1,s2;

    cin >> s1 >> s2;
 
    if(s1.at(0)==s2.at(2) && s1.at(1)==s2.at(1) && s1.at(2)==s2.at(0) ) cout << "YES"; 
    else cout << "NO";
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(long i=0; i<(long)(n);i++)
#define REP(i,s,t) for(long i=s; i<t; i++)
#define RNG(i,s,t,u) for(long i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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 main(){
  int k;
  cin >> k;
  rep(i,k){
    cout << "ACL";
  }
  cout << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
	// 整数の入力
	
	int n, max, num;
	cin >> n;
	vector<int> h(20);
	for (int i = 0; i < n; i++)
	{
		cin >> h.at(i);
	}
	max = 0;
  num=0;
	for (int i = 0; i < n; i++)
	{
		if (h.at(i) >= max) {
			num++;
			max = h.at(i);
		}

	}

	
	// 出力
	cout << num<< endl;
	//return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(X: int):
    s = 0
    for i in range(1, X+1):
        s += i
        if s >= X:
            print(i)
            exit()
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


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

int main()  
{  
	int n,sum = 0;
    string s;
    cin >> n;
    cin >> s;
    for(int i = 0; i < s.length()-2; i++){
    	if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
    		sum++;
	}
	cout << sum << endl;
    return 0;  
}  

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 998244353
n, k = map(int, input().split())
s = list()
for i in range(k):
    s.append(tuple(map(int, input().split())))

dp = [0] + [0] * n
diff = [0] + [0] * n
dp[1] = 1
for i in range(1, n):
    for j, k in s:
        if i + j > n:
            continue
        diff[i + j] += dp[i]
        if i + k + 1 > n:
            continue
        diff[i + k + 1] -= dp[i]
    dp[i] = (dp[i - 1] + diff[i]) % MOD
    dp[i + 1] = (dp[i] + diff[i + 1]) % MOD
print(dp[n])


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

int main(){
  int n;
  cin>>n;
  vector<pair<int,int>> p;
  vector<int> t(n+1);
  t[0]=0;
  p.push_back(make_pair(0,0));
  rep(i,n){
    int x, y;
    cin>>t[i+1];
    cin>>x>>y;
    p.push_back(make_pair(x,y));
  }
  bool ans=1;
  rep(i,n){
    int x0,y0,x1,y1;
    tie(x0,y0)=p[i];
    tie(x1,y1)=p[i+1];
    int dis=( (t[i+1]-t[i]) - (abs(x1-x0)+abs(y1-y0)) );
    if(!(dis>=0 && dis%2==0)){ans=0; break;}
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main(){
    using lli = long long int;
    lli x;
    cin >> x;
    lli ans = 0;
    ans += (x/500)*1000;
    x = x%500;
    ans += (x/5)*5;
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())

sum_list = []
for a in range(1, n):
    b = n - a
    a_str = str(a)
    b_str = str(b)
    tmp = 0
    for a_s in a_str:
        tmp += int(a_s)
    for b_s in b_str:
        tmp += int(b_s)
    sum_list.append(tmp)

print(min(sum_list))


Measured memory_bytes: 3864
#include<bits/stdc++.h>
#include <algorithm>
 
using namespace std;
 
int main(){
 int N=0;
 cin >> N;
 vector<int> vec(N);
 vector<int> vec2(N);
 
 for(int i=0; i<N; i++){
 cin>> vec.at(i);
 }  
 for(int i=0; i<N; i++){
 if(vec.at(i)%2==0){
   vec2.at(i)=vec.at(i);
 }  
 }
  
  for(int i=0;i<N;i++){
  if(vec2.at(i)%3!=0 && vec2.at(i)%5!=0){
     cout<<"DENIED"<<endl;
     return 0;
  }
  }
        cout<<"APPROVED"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back

#define value first
#define index second


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

    int N, p, temp=INF, ret=0;
    cin >> N;
    //vector<int> P(N);
    rep(i, N){
        cin >> p;
        if(temp>=p) ret++;
        temp=min(temp, p);
    }
    
    cout << ret << endl;

    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}


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

const int INF = 1e9;

int main() {
  string s;
  cin>>s;
  int ans1=0;
  for(int i=0;i<s.length();i++){
    if(i%2==0){
      if(s[i]=='0'){
        ++ans1;
      }
    } else{
      if(s[i]=='1'){
        ++ans1;
      }
    }
  }
  int ans2=0;
  for(int i=0;i<s.length();i++){
    if(i%2!=0){
      if(s[i]=='0'){
        ++ans2;
      }
    } else{
      if(s[i]=='1'){
        ++ans2;
      }
    }
  }
  cout<<min(ans1,ans2)<<endl;
}

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

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

  ll x;
  cin >> x;

  ll n = 0;
  ll sum = 100;
  while (sum < x)
  {
    ll r = sum * 0.01;
    sum += r;
    n++;
  }
  cout << n << endl;

  return 0;
}

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

int main() {
	multiset<int, greater<int>> mul;
	int temp; bool check = true;
	for (int i = 0; i < 5; i++) {
		cin >> temp; mul.insert(temp);
	}
	auto itr = mul.begin();
	for (int i = 0; i < mul.size(); i++) {
		if (check == false) cout << ' ' << flush;
		cout << *itr << flush; check = false; ++itr;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3092
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N;
  vector<int> A, B;
  vector<pair<int, int>> pairs(N);
  ll result = 0;
  cin >> N;
  rep(i, N) {
    // cout << i << endl;
    int a, b, c;
    cin >> a >> b;
    c = a + b;
    A.push_back(a);
    B.push_back(b);
    pairs.push_back(make_pair(c, i));
  }

  sort(pairs.begin(), pairs.end(),
       [](auto x, auto y) { return x.first > y.first; });

  rep(i, N) {
    if (i % 2 == 0) {
      // turn for A
      result += A[pairs[i].second];
      // cout << "turn A"
      //      << " index:" << pairs[i].second << " value" << A[pairs[i].second]
      //      << endl;
    } else {
      // turn for B
      result -= B[pairs[i].second];
      // cout << "turn B"
      //      << " index:" << pairs[i].second << " value" << B[pairs[i].second]
      //      << endl;
    }
    // cout << pairs[i].first << " " << pairs[i].second << endl;
  }
  cout << result << endl;

  return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> 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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int n; scanf("%d",&n);
    string s; cin>>s;
    if(n<3200)printf("red");
    else cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

string toStr(int n){
    string str;
    int len = static_cast<int>(log10(n));
    int K = 1;
    rep(i,len) K*=10;
    rep(i,len + 1){
        if(n / K == 0) str+= '0';
        else str+= ('0' + n / K);
        n%=K; K/=10;
    }
    return str;
}

int main(){
    int n;
    int ans[2];
    cin >> n;

    int cnt = 0;
    while(true){
        string s = toStr(n + cnt);
        string r = s;
        reverse(all(r));
        if(s == r){
            ans[0] = cnt;
            break;
        }
        cnt++;
    }

    cnt = 0;
    while(true){
        string s = toStr(n - cnt);
        string r = s;
        reverse(all(r));
        if(s == r){
            ans[1] = cnt;
            break;
        }else if(n - cnt < 0){
            ans[1] = INF;
            break;
        }
        cnt++;
    }

    if(ans[1] < ans[0]) cout << n - ans[1] << endl;
    else if(ans[1] > ans[0]) cout << n + ans[0] << endl;
    else cout << n - ans[1] << endl;

    return 0;
}

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

int main(){
	char Chara[1000],Frisk[1000],Soul[1000];
	cin >> Chara >> Frisk;

		strcpy(Soul,Chara);
		strcat(Chara,Soul);
		if(strstr(Chara,Frisk) == 0 )cout << "No"  << endl;
		else cout << "Yes" << endl;
}

Measured memory_bytes: 3100
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

n,x = getList()
nums = getList()
ans = 1
tmp = 0
for num in nums:
    tmp += num
    if tmp<=x:
        ans += 1

print(ans)

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

int main(){
  string s, t, u;
  int x, n;

  cin>>s>>t;

  x = (int)s.size();

  for(int i=0;i<x;i++){

    u = "";
    n = 0;

    for(int j=x-1-i;j<x;j++){
      u += s[j];
      n++;
    }

    for(int k=0;k<x-n;k++){
      u += s[k];
    }

    // cout<<u<<endl;

    if(u == t){
      cout<<"Yes"<<endl;
      return 0;
    }
    
  }

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


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split(' ')))

n, m = 0,0
for a in A:
    if not a % 4:
        n += 1
    if not a % 2:
        m += 1

m -= n
if 2 * n >= N-1:
    print('Yes')

elif 2*n + m >= N:
    print('Yes')

else:
    print('No')




Measured memory_bytes: 58580
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]

broken = [0 for _ in range(n+1)]
for i in a:
    broken[i] = 1
dp = [0 for _ in range(n+2)]
dp[n] = 1

for i in range(n-1, -1, -1):
    if broken[i] == 1:
        dp[i] = 0
    else:
        dp[i] = dp[i+1] + dp[i+2]

print(dp[0]%(10**9+7))

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int convert(string date, string time)
{
    int d[12]={31,28,31,30,31,30,31,31,30,31,30,31};

    int month=atoi(date.substr(0,2).c_str());
    int day=atoi(date.substr(3,2).c_str());
    int hour=atoi(time.substr(0,2).c_str());
    int minute=atoi(time.substr(3,2).c_str());

    int ret=0;
    rep(i,month) ret+=60*24*d[i];
    ret+=60*24*(day-1);
    ret+=60*hour+minute;

    return ret;
}

vector<pi> LOG[1000];
int idx[1000];

int main()
{
    int n;
    while(cin >>n,n)
    {
        rep(i,1000)
        {
            LOG[i].clear();
            idx[i]=0;
        }

        rep(i,n)
        {
            string date,time,inout,id;
            cin >>date >>time >>inout >>id;

            int m=convert(date,time);
            int ID=atoi(id.c_str());

            if(inout=="I") LOG[ID].pb(pi(m,-1));
            else LOG[ID][idx[ID]++].se=m;
        }

        int ans=0;
        for(int i=1; i<1000; ++i)
        {
            if(LOG[i].size()==0) continue;

            int tmp=0;
            int god=0,pro=0;
            while(god<idx[0] && pro<idx[i])
            {
                int gl=LOG[0][god].fi, gr=LOG[0][god].se;
                int pl=LOG[i][pro].fi, pr=LOG[i][pro].se;
                if((pl<=gl && gl<pr) || (gl<=pl && pl<gr))
                {
                    int l=max(gl,pl), r=min(gr,pr);
                    tmp+=r-l;
                }

                if(LOG[0][god].se<LOG[i][pro].se) ++god;
                else ++pro;
            }

            ans=max(ans,tmp);
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N,H,W;
    cin>>N>>H>>W;
    if(N*N<=H*W){cout<<1<<endl;}
    else {cout<<(N-H+1)*(N-W+1)<<endl;}

    return 0;
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n;
	cin >> n;
	ll ans = (n*(n+1))/2;
	ll x = n/3;
	ans -= 3*((x*(x+1))/2);
	x = n/5;
	ans -= 5*((x*(x+1))/2);
	x = n/15;
	ans += 15*((x*(x+1))/2);
	cout << ans << endl;
}


Measured memory_bytes: 3648
n,m ,c= map(int,input().split())
B = [int(i) for i in input().split()]
cnt = 0
for i in range(n):
    A =  [int(i) for i in input().split()]
    if sum([A[i]*B[i] for i in range(m)]) + c > 0:
        cnt+=1

print(cnt)

Measured memory_bytes: 38384
D, G = map(int, input().split())
p = [0]*D
c = [0]*D

question = 0

for i in range(D):
    p[i], c[i] = map(int, input().split())

question = []

for x in range(2**D):
    # print(bin(x))
    questioni = 0
    not_comp = []
    score = 0
    for y in range(D):
        # print( bin(1<<y&x) )
        if 1 << y & x:
            score += c[y] + p[y]*100*(y+1)
            questioni += p[y]
        else:
            not_comp.append(y)
    for y in not_comp[::-1]:
        for z in range(p[y]-1):
            if score < G:
                score += 100*(y+1)
                questioni += 1
            else:
                break
    if score >= G:
        question.append(questioni)

print(min(question))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    fast;
    int i,j,c=0,d=0,n,h,sum=0;
    cin>>h>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>=h)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }




}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#define BUF 100

int main(void) {
    char strt[BUF], strh[BUF];
    int i, n, scrt, scrh;
    scrt = 0; scrh = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%s %s", strt, strh);
        if (strcmp(strt, strh) == 0) {
            scrt += 1;
            scrh += 1;
        } else if (strcmp(strt, strh) > 0) {
            scrt += 3;
        } else if (strcmp(strt, strh) < 0) {
            scrh += 3;
        }
    }
    printf("%d %d\n", scrt, scrh);

    return 0;
}

Measured memory_bytes: 604
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

L = [0]*26

v = 0
ans = [0]*D
import copy
for i in range(1, D+1):
    max_ = v
    max_idx = 0
    for j in range(26):
        temp = v
        temp += S[i-1][j]
        L_ = copy.copy(L)
        L_[j] = i
        for k in range(26):
            temp -= C[j]*(i-L_[k])
        if temp >= max_:
            max_ = temp
            max_idx = j
    ans[i-1] = max_idx+1
print(*ans, sep='\n')

Measured memory_bytes: 69688
#include<iostream>

#include<cstdio>

using namespace std;

long long n, sum, a[13];

long long dfs(long long x, long long sum, long long sum1)
{
    if(x == 1)
    {
        return 2 * sum + sum1 + a[x] + sum1 * 10 + a[x];
    } 
    return dfs(x - 1, sum, sum1 * 10 + a[x]) + dfs(x - 1, sum + sum1, a[x]); 
}
int main()
{
    cin >> n;
    while(n != 0)
    {
        sum++;
        a[sum] = n % 10;
        n /= 10;
    } 
    cout << dfs(sum, 0, 0) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int a[] = new int[n];
        
        long sum = 0;
        
        for(int i = 0; i < n; i++){
            a[i] = stdIn.nextInt();
            sum += a[i];
        }
        
        long msum = 0;
        long min = sum;
        //int index = 2020202020;
        
        for(int i = 0; i < n; i++){
            msum += a[i];
            if(Math.abs(msum - (sum - msum)) < min){
                min = Math.abs(msum - (sum - msum));
                //index = i;
            }
        }
        
        
        System.out.println(min);
    }
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);


    double r;
    cin >> r;

    cout << 2 * pi * r;
}








Measured memory_bytes: 3780
N = int(input())
V = input().split()
C = input().split()
Vnum=[]
Cnum=[]
res = 0
for i in range(N):
  Vnum.append(int(V[i]))
  Cnum.append(int(C[i]))
for i in range(N):
  if Vnum[i]>Cnum[i]:
    res += Vnum[i]-Cnum[i]
print(res)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(void){
  int a,b; cin>>a>>b;
  if( a <= 5){
    cout << 0 << endl;
  }
  else if( a <= 12 ){
    cout << b/2 << endl;
  }
  else cout << b << endl;
  return 0;
}


Measured memory_bytes: 256
def nextsta(t,c,s,f):
    if t<=s:return s
    elif t%f == 0:return t
    else:return(t + f - t%f)
N=int(input())-1
CSF = [[int(i) for i in input().split()] for i in range(N)]
for StartSt in range(N):
    cursta = StartSt
    curtime = 0
    for st in range(StartSt,N):
        c,s,f = CSF[cursta]
        curtime = nextsta(curtime,c,s,f) + c
        cursta += 1
    print(curtime)
print(0)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int n;
int main(){
	cin>>n;	
	int h[n];
	for(int i=0;i<n;i++)cin>>h[i];
	for(int i=n-1;i>=0;i--){
		if(h[i-1]>h[i])h[i-1]--;
		if(h[i-1]>h[i]){cout<<"No"<<endl;return 0;}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double
#define TIME ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
    const ll N = 1e5 + 7;
    const ll mod = 1e9 + 7;
int n , m , cnt;
int main(){
    TIME
    cin >> m >> n;
    for(int i = 1 , x; i <= n ;i  ++)
        cin >> x , cnt += x;
    if(cnt >= m){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}
///...


Measured memory_bytes: 256
/************************************************
 * Au: Hany01
 * Date: 
 * Prob: 
 * Email: hany01dxx@gmail.com & hany01@foxmail.com
 * Inst: Yali High School
************************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define Rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define X first
#define Y second
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

template <typename T> inline T read() {
	static T _, __; static char c_;
    for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


const int maxn = 2e6 + 5;

int n, A[maxn], a[maxn], b[maxn], le[maxn], ri[maxn];

inline bool check(int x) {
	For(i, 1, 2 * n - 1) a[i] = A[i] > x;
	Set(b, 0);
	For(i, 2, 2 * n - 1) if (a[i] == a[i - 1]) b[i] = b[i - 1] = 1;
	if (b[n]) return a[n];
	For(i, 1, 2 * n - 1) if (!b[i]) {
		if (le[i - 1]) le[i] = le[i - 1]; else le[i] = i;
	} else le[i] = 0;
	Fordown(i, 2 * n - 1, 1) if (!b[i]) {
		if (ri[i + 1]) ri[i] = ri[i + 1]; else ri[i] = i;
	} else ri[i] = 0;
	if (le[n] == 1 && ri[n] == 2 * n - 1) return a[n] ^ (n & 1) ^ 1;
	return ((n - le[n]) > (ri[n] - n)) ? a[ri[n] + 1] : a[le[n] - 1];
}

int main() {

	n = read<int>();
	For(i, 1, n * 2 - 1) A[i] = read<int>();

	register int l = 1, r = 2*n-1, mid;
	while (l < r) {
		mid = (l + r) >> 1;
		if (check(mid)) l = mid + 1;
		else r = mid;
	}
	printf("%d\n", l);

	return 0;
}

Measured memory_bytes: 17408
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		x: usize,
		a: usize,
		b: usize,
	}

	println!("{}", (x - a) % b);
}



Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int k;
    cin >> s >> k;
    set<string> myVec;
    for(int i = 0;i < s.length();i++)
    {
        string temp;
        for(int j = i;j < s.length() && j < i+6;j++)
            temp.push_back(s[j]),myVec.insert(temp);
    }
    k--;
    while(k--)
        myVec.erase(myVec.begin());
    cout << *myVec.begin();
}


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

int N, W;
int value[110], weight[110];
int dp[110][10010];

int main() {
   cin >> N >> W;
   for (int i = 0; i < N; i++) cin >> value[i] >> weight[i];

   for (int qty = 0; qty < N; qty++) { // qty個の品物を入れる
      for (int weightLim = 0; weightLim <= W; weightLim++) { // 重さの上限
         if (weight[qty] <= weightLim) { // qty個目の品物が重さ上限以下の時
            dp[qty+1][weightLim] = max(dp[qty][weightLim-weight[qty]] + value[qty], 
                                 dp[qty][weightLim]);
         } else { // qty個目の品物が上限よりも重いとき
            dp[qty+1][weightLim] = dp[qty][weightLim]; // 繰り下げ
         }
      }
   }

   cout << dp[N][W] << endl;

   return 0;
}


Measured memory_bytes: 7008
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(2000009);

int main(){
  int x,y;
  cin>>x>>y;
  int n=(x+y)/3;
  int k=(y*2-x)/3;
  if((x+y)%3!=0||(y*2-x)%3!=0){
    cout<<0<<endl;
  }
  else{
    cout<<comb(n,k).x<<endl;
  }
  return(0);
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ull=unsigned long long;
int n;
ull k;
pair<ull, ull> p[100010];
#define a first
#define b second

ull hibit(ull n) {
    n |= (n >>  1);
    n |= (n >>  2);
    n |= (n >>  4);
    n |= (n >>  8);
    n |= (n >> 16);
    n |= (n >> 32);
    return n - (n >> 1);
}

int main(){ _;
  cin>>n>>k;
  ull bit=hibit(k);
  //  cout<<bit<<endl;
  REP(i,n) cin>>p[i].a>>p[i].b;
  ull mx=0;
  REP(i,n)if((~k&p[i].a)==0)mx+=p[i].b;
  ull mask=-bit;
  for(;bit>0;bit>>=1){
    mask|=bit;
    if((k&bit)==0&&bit!=1){
      continue;
    }
    ull localMx=0;
    for(int i=0;i<n;i++){
      if((mask&p[i].a)==0){
	localMx+=p[i].b;
      }
    }
    mx=max(mx,localMx);
    mask&=~bit;
  }
  cout<<mx<<endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	ll a;
	string b;
	cin >> a >> b;
	int c = 0;
	c += b[0] - '0';
	c *= 10;
	c += b[2] - '0';
	c *= 10;
	c += b[3] - '0';
	cout << a * c / 100 << endl;
	
    return 0;
}


Measured memory_bytes: 3656
A, B, C, X, Y = map(int, input().split())

if (A+B) > C*2 :
    ans = min(X,Y)*2*C
    
else:
    ans = A*min(X,Y) + B*min(X,Y)
    
remain = max(X,Y) - min(X,Y)

rem_C = remain*C
rem_AorB = remain*(A,B)[X<Y]

if rem_C*2 < rem_AorB:
    ans += rem_C*2
else:
    ans += rem_AorB

print(ans)


Measured memory_bytes: 3060
"use strict"

function main(input) {
  input = input.split("")

  let ans = ""

  for (let i = 0; i < Math.ceil(input.length / 2); i++) {
    ans += input[i * 2]
  }
  console.log(ans)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 15820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var < (end); var++)
#define RFOR(var, begin, end) for (int var = (begin) - 1; var >= (end); var--)
#define REP(var, length) FOR(var, 0, length)
#define RREP(var, length) RFOR(var, length, 0)
#define SORT(vector) sort(vector.begin(), vector.end())

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> p(n);
  REP(i, q) {
    int a;
    cin >> a;
    a--;
    p[a]++;
  }
  REP(i, n) {
    if (k - q + p[i] > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define repr(i,a,n) for(int i = n-1;i >= a;i--)
#define ALL(v) v.begin(), v.end()
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

void YNout(bool check){
	if(check)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return;
}

void Yayout(bool check){
	if(check) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	
	return;
}
/*
template <typename T>
void vecout(vector<T>& vecout_vec){
	
	rep(i,0,vecout_vec.size()){
		cout << vecout_vec.at(i) << endl;
	}
	
	return ;
}

template <typename T>
void vecin(vector<T>& vecin_vec, ll n){
	
	ll temp ;
	
	rep(i,0,n){
		cin >> temp;
		vecin_vec.push_back(temp);
		
	}
}

template <typename T>
void in(T& literal_in, T& literal_in2, ...){
	cin >> literal_in;
	in(literal_in2, ...);
	
	return;
}

template <typename T>
void in(T& literal_in){
	
	cin >> literal_in;
	
	return;
}

template <typename T>
void out(T& literal_out, T& literal_out2, ...){
	cout << literal_out << endl;
	out(literal_out2, ...);
	
	return;
}

template <typename T>
void out(T& literal_out){
	
	cout << literal_out << endl;
	
	return;
}
*/
signed main(){
	ll n,m;
	cin >> n >> m;
	ll a[n];
	ll d[1000000];
	
	rep(i,0,n){
		cin >> a[i];
	}
	
	
	
	vector<P> vec;
	ll b,c;
	
	rep(i,0,m){
		cin >> b >> c;
		P p;
		p.fs = c;
		p.sc = b;
		
		vec.push_back(p);
	}
	
	sort(vec.begin(),vec.end());
	
	
	
	ll memo = 0;
	rep(i,0,vec.size()){
		rep(j,0,vec[vec.size()-i-1].sc){
			d[memo] = vec[vec.size()-i-1].fs;
			memo++;
			
			if(memo > n) break;
		}
		if(memo > n) break;
	}
	
	
	sort(a,a+n);
	/*
	rep(i,0,n){
		cout << a[i] << " ";
	}
	cout << endl;
	
	rep(i,0,memo){
		cout << d[i] << " ";
	}
	cout << endl;
	*/
	ll ans  = 0;
	rep(i,0,n){
		if(memo > i)ans += max(a[i],d[i]);
		else ans += a[i];
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

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

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; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;



vi MP(string s){
  vi A(s.size()+1);
  A[0] = -1;
  int j = -1;
  rep(i,s.size()) {
    while(j >= 0 && s[i] != s[j]) j = A[j];
    j++;
    A[i+1] = j;
  }
  return A;
}

vi Manacher(string s){
  vi R(s.size());
  int i = 0, j = 0;
  while(i < s.size()){
    while(i-j >= 0 && i+j < s.size() && s[i-j] == s[i+j]) ++j;
    R[i] = j;
    int k = 1;
    while(i-k >= 0 && i+k < s.size() && k+R[i-k] < j) R[i+k] = R[i-k], k++;
    i += k; j -= k;
  }
  return R;
}

vi Z_algorithm(string &s){
  vi Z(s.size());
  Z[0] = s.size();
  int i = 1, j = 0;
  while(i < s.size()){
    while(i+j < s.size() && s[j] == s[i+j]) j++;
    Z[i] = j;
    if(j == 0){++i; continue;}
    int k = 1;
    while(i+k < s.size() && k+Z[k] < j) Z[i+k] = Z[k], ++k;
    i += k; j -= k;
  }
  return Z;
}

const int MAX = 1e6+1;

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

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

// 二項係数計算
long long COM(ll n, ll k){
  if(n >= MAX){
    ll tmp = 1;
    rep(i,k){
      tmp *= (n-i);
      tmp %= MOD;
    }
    return tmp*finv[k]%MOD;
  }

  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll POW(ll x, ll n){
  ll ret = 1;
  if(n < 0){// n < 0 にも対応
    n *= -1;
    x = inv[x];
  }
  while(0 < n){
    if(n%2 == 0){
      x = x*x%MOD;
      n /= 2;
    }
    else{
      ret = ret*x%MOD;
      n--;
    }
  }
  return ret;
}

int main(){
  string s; cin >> s;
  string t;
  if(s.size()%2 == 1){
    cout << "No" << endl;
    return 0;
  }
  rep(i,s.size()) {
    if(i%2 == 0){
      t = s[i];
    }
    else{
      t += s[i];
      if(t != "hi"){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256